@vivliostyle/print 2.39.1 → 2.41.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 +119 -65
- package/dist/index.cjs.js.map +4 -4
- package/dist/index.es6.js +119 -65
- package/dist/index.es6.js.map +4 -4
- package/package.json +2 -2
package/dist/index.es6.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var Gd=Object.create;var za=Object.defineProperty;var jd=Object.getOwnPropertyDescriptor;var Xd=Object.getOwnPropertyNames;var qd=Object.getPrototypeOf,Yd=Object.prototype.hasOwnProperty;var Kd=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Zd=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Xd(t))!Yd.call(e,s)&&s!==i&&za(e,s,{get:()=>t[s],enumerable:!(n=jd(t,s))||n.enumerable});return e};var Jd=(e,t,i)=>(i=e!=null?Gd(qd(e)):{},Zd(t||!e||!e.__esModule?za(i,"default",{value:e,enumerable:!0}):i,e));var Ud=Kd((I0,Vd)=>{"use strict";var Qd=Object.create,Dn=Object.defineProperty,ep=Object.getOwnPropertyDescriptor,tp=Object.getOwnPropertyNames,ip=Object.getPrototypeOf,np=Object.prototype.hasOwnProperty,mh=e=>{throw TypeError(e)},sp=(e,t,i)=>t in e?Dn(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,rp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),op=(e,t)=>{for(var i in t)Dn(e,i,{get:t[i],enumerable:!0})},wh=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of tp(t))!np.call(e,s)&&s!==i&&Dn(e,s,{get:()=>t[s],enumerable:!(n=ep(t,s))||n.enumerable});return e},ap=(e,t,i)=>(i=e!=null?Qd(ip(e)):{},wh(t||!e||!e.__esModule?Dn(i,"default",{value:e,enumerable:!0}):i,e)),lp=e=>wh(Dn({},"__esModule",{value:!0}),e),c=(e,t,i)=>sp(e,typeof t!="symbol"?t+"":t,i),Wo=(e,t,i)=>t.has(e)||mh("Cannot "+i),X=(e,t,i)=>(Wo(e,t,"read from private field"),i?i.call(e):t.get(e)),ue=(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),mt=(e,t,i,n)=>(Wo(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Ee=(e,t,i)=>(Wo(e,t,"access private method"),i),hp=rp((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}),bh={};op(bh,{CoreViewer:()=>zd,HOOKS:()=>qs,Navigation:()=>Dd,PageProgression:()=>Go,PageSide:()=>xh,PageViewMode:()=>f0,Profiler:()=>Eh,ReadyState:()=>Sh,UserAgentBaseCss:()=>wu,UserAgentCounterStylesCss:()=>vu,UserAgentPageCss:()=>mu,UserAgentTocCss:()=>bu,UserAgentXml:()=>gu,ValidationTxt:()=>fu,VivliostylePolyfillCss:()=>yu,VivliostyleViewportCss:()=>pu,VivliostyleViewportScreenCss:()=>du,ZoomType:()=>p0,getHooksForName:()=>It,isDebug:()=>An,pageProgressionOf:()=>vh,plugin:()=>cp,printHTML:()=>m0,profile:()=>gp,profiler:()=>ct,registerHook:()=>Ct,removeHook:()=>kh,setDebug:()=>yh});Vd.exports=lp(bh);var An=!1;function yh(e){An=e}var Go=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Go||{});function vh(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var xh=(e=>(e.LEFT="left",e.RIGHT="right",e))(xh||{}),Sh=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(Sh||{}),Ch=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(Ch||{}),up=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=Qn(arguments);this.consoleDebug(es(t)),this.triggerListeners(1,t)}info(...e){let t=Qn(arguments);this.consoleInfo(es(t)),this.triggerListeners(2,t)}warn(...e){let t=Qn(arguments);this.consoleWarn(es(t)),this.triggerListeners(3,t)}error(...e){let t=Qn(arguments);this.consoleError(es(t)),this.triggerListeners(4,t)}};function Qn(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function es(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 Mp=Object.create;var ml=Object.defineProperty;var _p=Object.getOwnPropertyDescriptor;var Dp=Object.getOwnPropertyNames;var zp=Object.getPrototypeOf,Vp=Object.prototype.hasOwnProperty;var Up=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Hp=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Dp(t))!Vp.call(e,r)&&r!==i&&ml(e,r,{get:()=>t[r],enumerable:!(n=_p(t,r))||n.enumerable});return e};var $p=(e,t,i)=>(i=e!=null?Mp(zp(e)):{},Hp(t||!e||!e.__esModule?ml(i,"default",{value:e,enumerable:!0}):i,e));var Fp=Up((I0,Rp)=>{"use strict";var Wp=Object.create,pr=Object.defineProperty,Gp=Object.getOwnPropertyDescriptor,jp=Object.getOwnPropertyNames,Xp=Object.getPrototypeOf,qp=Object.prototype.hasOwnProperty,Kh=e=>{throw TypeError(e)},Yp=(e,t,i)=>t in e?pr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i,Zp=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Kp=(e,t)=>{for(var i in t)pr(e,i,{get:t[i],enumerable:!0})},Jh=(e,t,i,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of jp(t))!qp.call(e,r)&&r!==i&&pr(e,r,{get:()=>t[r],enumerable:!(n=Gp(t,r))||n.enumerable});return e},Jp=(e,t,i)=>(i=e!=null?Wp(Xp(e)):{},Jh(t||!e||!e.__esModule?pr(i,"default",{value:e,enumerable:!0}):i,e)),Qp=e=>Jh(pr({},"__esModule",{value:!0}),e),c=(e,t,i)=>Yp(e,typeof t!="symbol"?t+"":t,i),ka=(e,t,i)=>t.has(e)||Kh("Cannot "+i),V=(e,t,i)=>(ka(e,t,"read from private field"),i?i.call(e):t.get(e)),ne=(e,t,i)=>t.has(e)?Kh("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,i),Oe=(e,t,i,n)=>(ka(e,t,"write to private field"),n?n.call(e,i):t.set(e,i),i),Ce=(e,t,i)=>(ka(e,t,"access private method"),i),ef=Zp((e,t)=>{var i=-1,n=1,r=0;function s(C,_,k,O,E){if(C===_)return C?[[r,C]]:[];if(k!=null){var T=fe(C,_,k);if(T)return T}var L=l(C,_),z=C.substring(0,L);C=C.substring(L),_=_.substring(L),L=d(C,_);var H=C.substring(C.length-L);C=C.substring(0,C.length-L),_=_.substring(0,_.length-L);var K=o(C,_);return z&&K.unshift([r,z]),H&&K.push([r,H]),P(K,E),O&&f(K),K}function o(C,_){var k;if(!C)return[[n,_]];if(!_)return[[i,C]];var O=C.length>_.length?C:_,E=C.length>_.length?_:C,T=O.indexOf(E);if(T!==-1)return k=[[n,O.substring(0,T)],[r,E],[n,O.substring(T+E.length)]],C.length>_.length&&(k[0][0]=k[2][0]=i),k;if(E.length===1)return[[i,C],[n,_]];var L=p(C,_);if(L){var z=L[0],H=L[1],K=L[2],ee=L[3],Q=L[4],ge=s(z,K),re=s(H,ee);return ge.concat([[r,Q]],re)}return a(C,_)}function a(C,_){for(var k=C.length,O=_.length,E=Math.ceil((k+O)/2),T=E,L=2*E,z=new Array(L),H=new Array(L),K=0;K<L;K++)z[K]=-1,H[K]=-1;z[T+1]=0,H[T+1]=0;for(var ee=k-O,Q=ee%2!==0,ge=0,re=0,se=0,_e=0,De=0;De<E;De++){for(var pe=-De+ge;pe<=De-re;pe+=2){var le=T+pe,me;pe===-De||pe!==De&&z[le-1]<z[le+1]?me=z[le+1]:me=z[le-1]+1;for(var we=me-pe;me<k&&we<O&&C.charAt(me)===_.charAt(we);)me++,we++;if(z[le]=me,me>k)re+=2;else if(we>O)ge+=2;else if(Q){var oe=T+ee-pe;if(oe>=0&&oe<L&&H[oe]!==-1){var q=k-H[oe];if(me>=q)return h(C,_,me,we)}}}for(var Ze=-De+se;Ze<=De-_e;Ze+=2){var oe=T+Ze,q;Ze===-De||Ze!==De&&H[oe-1]<H[oe+1]?q=H[oe+1]:q=H[oe-1]+1;for(var at=q-Ze;q<k&&at<O&&C.charAt(k-q-1)===_.charAt(O-at-1);)q++,at++;if(H[oe]=q,q>k)_e+=2;else if(at>O)se+=2;else if(!Q){var le=T+ee-Ze;if(le>=0&&le<L&&z[le]!==-1){var me=z[le],we=T+me-le;if(q=k-q,me>=q)return h(C,_,me,we)}}}}return[[i,C],[n,_]]}function h(C,_,k,O){var E=C.substring(0,k),T=_.substring(0,O),L=C.substring(k),z=_.substring(O),H=s(E,T),K=s(L,z);return H.concat(K)}function l(C,_){if(!C||!_||C.charAt(0)!==_.charAt(0))return 0;for(var k=0,O=Math.min(C.length,_.length),E=O,T=0;k<E;)C.substring(T,E)==_.substring(T,E)?(k=E,T=k):O=E,E=Math.floor((O-k)/2+k);return S(C.charCodeAt(E-1))&&E--,E}function u(C,_){var k=C.length,O=_.length;if(k==0||O==0)return 0;k>O?C=C.substring(k-O):k<O&&(_=_.substring(0,k));var E=Math.min(k,O);if(C==_)return E;for(var T=0,L=1;;){var z=C.substring(E-L),H=_.indexOf(z);if(H==-1)return T;L+=H,(H==0||C.substring(E-L)==_.substring(0,L))&&(T=L,L++)}}function d(C,_){if(!C||!_||C.slice(-1)!==_.slice(-1))return 0;for(var k=0,O=Math.min(C.length,_.length),E=O,T=0;k<E;)C.substring(C.length-E,C.length-T)==_.substring(_.length-E,_.length-T)?(k=E,T=k):O=E,E=Math.floor((O-k)/2+k);return R(C.charCodeAt(C.length-E))&&E--,E}function p(C,_){var k=C.length>_.length?C:_,O=C.length>_.length?_:C;if(k.length<4||O.length*2<k.length)return null;function E(re,se,_e){for(var De=re.substring(_e,_e+Math.floor(re.length/4)),pe=-1,le="",me,we,oe,q;(pe=se.indexOf(De,pe+1))!==-1;){var Ze=l(re.substring(_e),se.substring(pe)),at=d(re.substring(0,_e),se.substring(0,pe));le.length<at+Ze&&(le=se.substring(pe-at,pe)+se.substring(pe,pe+Ze),me=re.substring(0,_e-at),we=re.substring(_e+Ze),oe=se.substring(0,pe-at),q=se.substring(pe+Ze))}return le.length*2>=re.length?[me,we,oe,q,le]:null}var T=E(k,O,Math.ceil(k.length/4)),L=E(k,O,Math.ceil(k.length/2)),z;if(!T&&!L)return null;L?T?z=T[4].length>L[4].length?T:L:z=L:z=T;var H,K,ee,Q;C.length>_.length?(H=z[0],K=z[1],ee=z[2],Q=z[3]):(ee=z[0],Q=z[1],H=z[2],K=z[3]);var ge=z[4];return[H,K,ee,Q,ge]}function f(C){for(var _=!1,k=[],O=0,E=null,T=0,L=0,z=0,H=0,K=0;T<C.length;)C[T][0]==r?(k[O++]=T,L=H,z=K,H=0,K=0,E=C[T][1]):(C[T][0]==n?H+=C[T][1].length:K+=C[T][1].length,E&&E.length<=Math.max(L,z)&&E.length<=Math.max(H,K)&&(C.splice(k[O-1],0,[i,E]),C[k[O-1]+1][0]=n,O--,O--,T=O>0?k[O-1]:-1,L=0,z=0,H=0,K=0,E=null,_=!0)),T++;for(_&&P(C),y(C),T=1;T<C.length;){if(C[T-1][0]==i&&C[T][0]==n){var ee=C[T-1][1],Q=C[T][1],ge=u(ee,Q),re=u(Q,ee);ge>=re?(ge>=ee.length/2||ge>=Q.length/2)&&(C.splice(T,0,[r,Q.substring(0,ge)]),C[T-1][1]=ee.substring(0,ee.length-ge),C[T+1][1]=Q.substring(ge),T++):(re>=ee.length/2||re>=Q.length/2)&&(C.splice(T,0,[r,ee.substring(0,re)]),C[T-1][0]=n,C[T-1][1]=Q.substring(0,Q.length-re),C[T+1][0]=i,C[T+1][1]=ee.substring(re),T++),T++}T++}}var g=/[^a-zA-Z0-9]/,m=/\s/,w=/[\r\n]/,b=/\n\r?\n$/,x=/^\r?\n\r?\n/;function y(C){function _(re,se){if(!re||!se)return 6;var _e=re.charAt(re.length-1),De=se.charAt(0),pe=_e.match(g),le=De.match(g),me=pe&&_e.match(m),we=le&&De.match(m),oe=me&&_e.match(w),q=we&&De.match(w),Ze=oe&&re.match(b),at=q&&se.match(x);return Ze||at?5:oe||q?4:pe&&!me&&we?3:me||we?2:pe||le?1:0}for(var k=1;k<C.length-1;){if(C[k-1][0]==r&&C[k+1][0]==r){var O=C[k-1][1],E=C[k][1],T=C[k+1][1],L=d(O,E);if(L){var z=E.substring(E.length-L);O=O.substring(0,O.length-L),E=z+E.substring(0,E.length-L),T=z+T}for(var H=O,K=E,ee=T,Q=_(O,E)+_(E,T);E.charAt(0)===T.charAt(0);){O+=E.charAt(0),E=E.substring(1)+T.charAt(0),T=T.substring(1);var ge=_(O,E)+_(E,T);ge>=Q&&(Q=ge,H=O,K=E,ee=T)}C[k-1][1]!=H&&(H?C[k-1][1]=H:(C.splice(k-1,1),k--),C[k][1]=K,ee?C[k+1][1]=ee:(C.splice(k+1,1),k--))}k++}}function P(C,_){C.push([r,""]);for(var k=0,O=0,E=0,T="",L="",z;k<C.length;){if(k<C.length-1&&!C[k][1]){C.splice(k,1);continue}switch(C[k][0]){case n:E++,L+=C[k][1],k++;break;case i:O++,T+=C[k][1],k++;break;case r:var H=k-E-O-1;if(_){if(H>=0&&U(C[H][1])){var K=C[H][1].slice(-1);if(C[H][1]=C[H][1].slice(0,-1),T=K+T,L=K+L,!C[H][1]){C.splice(H,1),k--;var ee=H-1;C[ee]&&C[ee][0]===n&&(E++,L=C[ee][1]+L,ee--),C[ee]&&C[ee][0]===i&&(O++,T=C[ee][1]+T,ee--),H=ee}}if(A(C[k][1])){var K=C[k][1].charAt(0);C[k][1]=C[k][1].slice(1),T+=K,L+=K}}if(k<C.length-1&&!C[k][1]){C.splice(k,1);break}if(T.length>0||L.length>0){T.length>0&&L.length>0&&(z=l(L,T),z!==0&&(H>=0?C[H][1]+=L.substring(0,z):(C.splice(0,0,[r,L.substring(0,z)]),k++),L=L.substring(z),T=T.substring(z)),z=d(L,T),z!==0&&(C[k][1]=L.substring(L.length-z)+C[k][1],L=L.substring(0,L.length-z),T=T.substring(0,T.length-z)));var Q=E+O;T.length===0&&L.length===0?(C.splice(k-Q,Q),k=k-Q):T.length===0?(C.splice(k-Q,Q,[n,L]),k=k-Q+1):L.length===0?(C.splice(k-Q,Q,[i,T]),k=k-Q+1):(C.splice(k-Q,Q,[i,T],[n,L]),k=k-Q+2)}k!==0&&C[k-1][0]===r?(C[k-1][1]+=C[k][1],C.splice(k,1)):k++,E=0,O=0,T="",L="";break}}C[C.length-1][1]===""&&C.pop();var ge=!1;for(k=1;k<C.length-1;)C[k-1][0]===r&&C[k+1][0]===r&&(C[k][1].substring(C[k][1].length-C[k-1][1].length)===C[k-1][1]?(C[k][1]=C[k-1][1]+C[k][1].substring(0,C[k][1].length-C[k-1][1].length),C[k+1][1]=C[k-1][1]+C[k+1][1],C.splice(k-1,1),ge=!0):C[k][1].substring(0,C[k+1][1].length)==C[k+1][1]&&(C[k-1][1]+=C[k+1][1],C[k][1]=C[k][1].substring(C[k+1][1].length)+C[k+1][1],C.splice(k+1,1),ge=!0)),k++;ge&&P(C,_)}function S(C){return C>=55296&&C<=56319}function R(C){return C>=56320&&C<=57343}function A(C){return R(C.charCodeAt(0))}function U(C){return S(C.charCodeAt(C.length-1))}function G(C){for(var _=[],k=0;k<C.length;k++)C[k][1].length>0&&_.push(C[k]);return _}function Z(C,_,k,O){return U(C)||A(O)?null:G([[r,C],[i,_],[n,k],[r,O]])}function fe(C,_,k){var O=typeof k=="number"?{index:k,length:0}:k.oldRange,E=typeof k=="number"?null:k.newRange,T=C.length,L=_.length;if(O.length===0&&(E===null||E.length===0)){var z=O.index,H=C.slice(0,z),K=C.slice(z),ee=E?E.index:null;e:{var Q=z+L-T;if(ee!==null&&ee!==Q||Q<0||Q>L)break e;var ge=_.slice(0,Q),re=_.slice(Q);if(re!==K)break e;var se=Math.min(z,Q),_e=H.slice(0,se),De=ge.slice(0,se);if(_e!==De)break e;var pe=H.slice(se),le=ge.slice(se);return Z(_e,pe,le,K)}e:{if(ee!==null&&ee!==z)break e;var me=z,ge=_.slice(0,me),re=_.slice(me);if(ge!==H)break e;var we=Math.min(T-me,L-me),oe=K.slice(K.length-we),q=re.slice(re.length-we);if(oe!==q)break e;var pe=K.slice(0,K.length-we),le=re.slice(0,re.length-we);return Z(H,pe,le,oe)}}if(O.length>0&&E&&E.length===0)e:{var _e=C.slice(0,O.index),oe=C.slice(O.index+O.length),se=_e.length,we=oe.length;if(L<se+we)break e;var De=_.slice(0,se),q=_.slice(L-we);if(_e!==De||oe!==q)break e;var pe=C.slice(se,T-we),le=_.slice(se,L-we);return Z(_e,pe,le,oe)}return null}function ue(C,_,k,O){return s(C,_,k,O,!0)}ue.INSERT=n,ue.DELETE=i,ue.EQUAL=r,t.exports=ue}),Qh={};Kp(Qh,{CoreViewer:()=>Ip,HOOKS:()=>Os,Navigation:()=>Ap,PageProgression:()=>Ea,PageSide:()=>iu,PageViewMode:()=>f0,Profiler:()=>ou,ReadyState:()=>nu,UserAgentBaseCss:()=>rc,UserAgentCounterStylesCss:()=>ac,UserAgentPageCss:()=>nc,UserAgentTocCss:()=>sc,UserAgentXml:()=>ic,ValidationTxt:()=>tc,VivliostylePolyfillCss:()=>oc,VivliostyleViewportCss:()=>ec,VivliostyleViewportScreenCss:()=>Qu,ZoomType:()=>p0,getHooksForName:()=>Ft,isDebug:()=>rr,pageProgressionOf:()=>tu,plugin:()=>nf,printHTML:()=>m0,profile:()=>af,profiler:()=>wt,registerHook:()=>kt,removeHook:()=>su,setDebug:()=>eu});Rp.exports=Qp(Qh);var rr=!1;function eu(e){rr=e}var Ea=(e=>(e.LTR="ltr",e.RTL="rtl",e))(Ea||{});function tu(e){switch(e){case"ltr":return"ltr";case"rtl":return"rtl";default:throw new Error(`unknown PageProgression: ${e}`)}}var iu=(e=>(e.LEFT="left",e.RIGHT="right",e))(iu||{}),nu=(e=>(e.LOADING="loading",e.INTERACTIVE="interactive",e.COMPLETE="complete",e))(nu||{}),ru=(e=>(e[e.DEBUG=1]="DEBUG",e[e.INFO=2]="INFO",e[e.WARN=3]="WARN",e[e.ERROR=4]="ERROR",e))(ru||{}),tf=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=Nr(arguments);this.consoleDebug(Tr(t)),this.triggerListeners(1,t)}info(...e){let t=Nr(arguments);this.consoleInfo(Tr(t)),this.triggerListeners(2,t)}warn(...e){let t=Nr(arguments);this.consoleWarn(Tr(t)),this.triggerListeners(3,t)}error(...e){let t=Nr(arguments);this.consoleError(Tr(t)),this.triggerListeners(4,t)}};function Nr(e){let t=Array.from(e),i=null;return t[0]instanceof Error&&(i=t.shift()),{error:i,messages:t}}function Tr(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=pr,this.registerStartTiming=this.registerStartTiming=Da,this.registerEndTiming=this.registerEndTiming=dp}isEnabled(){return this.registerStartTiming===Da}};function Si(){}function pr(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 Da(e,t){this.registerTiming(e,"start",t)}function dp(e,t){this.registerTiming(e,"end",t)}var pp={now:Date.now},fp=window&&window.performance,ct=new Eh(fp||pp);ct.forceRegisterStartTiming("load_vivliostyle");var gp={profiler:{registerStartTiming:ct.registerStartTiming,registerEndTiming:ct.registerEndTiming,printTimings:ct.printTimings,disable:ct.disable,enable:ct.enable}},Nh=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",Is=/^[\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",mp={};function jo(e){return JSON.parse(e)}function Dt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function wp(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Gi=window.location.href;function Va(e){Gi=e}var Qt=window.location.href;function Ua(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=wp(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 Ha(e){return e==null?e:e.toString()}var bp=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}},Ph=["","-webkit-","-moz-"],ki={};function hs(e,t){return CSS.supports(e+t,"unset")}function yp(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(hs("-webkit-","text-combine")&&!hs("","text-combine-upright"))return ki[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of Ph)if(hs(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=yp(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 Or(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 Th(e){return`\\${e.charCodeAt(0).toString(16)} `}function ei(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,Th)}function Vn(e){return e.replace(/[\u0000-\u001F"\\]/g,Th)}function $a(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Wa(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function vp(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function Ih(e,t){function i(n){return vp(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function qt(e){return Ih(e)}function xp(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function Sp(e,t){t=typeof t=="string"?t:"\\u";function i(s){return xp(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 Ah(e,t){return e-t}function Ga(e,t){let i={};for(let n of e){let s=t(n);s&&!i[s]&&(i[s]=n)}return i}function Cp(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function fr(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 kp(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Xo=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 Rh(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function Ep(e){return`^${e}`}function ja(e){return e.replace(/[\[\]\(\),=;^]/g,Ep)}function Np(e){return e.substr(1)}function _r(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Np)}function Pp(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=_r(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function Xa(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Pp(i[2]),e=e.substr(i[0].length)}return t}var qa=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Ya=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!=Rh(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}},Ka=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(ja(this.textBefore)),e.append(","),this.textAfter&&e.append(ja(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Za=class Fh{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=Xa(i[4]),r.push(new Ya(a,l,Ha(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=_r(l));let h=i[7];h&&(h=_r(h)),o=Xa(i[10]),r.push(new Ka(a,l,h,Ha(o.s)));break}case"!":s++,r.push(new qa);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 Fh,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 Ka(i,a,l,s)),s=null);o&&!(!o||o.nodeType==9);){let h=n?null:Rh(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;r.push(new Ya(u,h,s)),s=null,t=o,o=o.parentNode,n=!1}r.reverse(),this.steps?(r.push(new qa),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 Lh(){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 Bh(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 Tp=Lh(),Ja={PENDING:{}};function Oh(e,t,i,n){let s=Math.min((e-0)/i,(t-0)/n);return`matrix(${s},0,0,${s},0,0)`}function gr(e){return`"${Vn(`${e}`)}"`}function Ip(e){return ei(`${e}`)}function Mr(e,t){return e?`${ei(e)}.${ei(t)}`:ei(t)}var _h=0,zr=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${_h++}`,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=Oh,i["css-string"]=gr,i["css-name"]=Ip,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 gr(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return gr(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 Ap(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function Mh(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 Rp(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Fp(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 zh(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 Dr=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=Tp}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(Mh(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=`_${_h++}`}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===Ja.PENDING?!1:n;{i[this.key]=Ja.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}},Dh=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)}},Ys=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)}},Vh=class extends Ys{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Ji=class extends Ys{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},Uh=class extends Ys{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},qo=class extends Ys{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},ti=class extends Dh{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},Lp=class extends ti{constructor(e,t){super(e,t)}getOp(){return"not "}},Ri=class extends Dh{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Yo=class extends Vh{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},Bp=class extends Yo{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Ko=class extends Vh{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},Op=class extends Ko{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},_p=class extends Ko{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},Mp=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},zp=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},Dp=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},Vr=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Zo=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},Vp=class extends Ji{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},Hh=class extends Uh{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},$h=class extends Uh{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},Jo=class extends qo{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Wh=class extends qo{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Gh=class extends qo{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)}},Qa=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 Up(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function Hp(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 jh extends Et{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),Up(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=Hp(t,this.params,i);return n===this.params?this:new jh(this.scope,this.qualifiedName,n)}},$p=class Xh 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 Xh(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}},el=class qh 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 qh(this.scope,this.name,n)}},Wp=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)}},Yh=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 Yo(e,t,i)}function Y(e,t,i){return t===e.zero?i:i===e.zero?t:new Hh(e,t,i)}function pe(e,t,i){return t===e.zero?new Ri(e,i):i===e.zero?t:new $h(e,t,i)}function us(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new Jo(e,t,i)}function Ur(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Wh(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}},Kh=class Zh extends Ze{static get instance(){return this.empty||(this.empty=new Zh),this.empty}constructor(){super()}toExpr(t,i){return new $e(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};c(Kh,"empty");var Gp=Kh,j=Gp.instance,Jh=class Qh extends Ze{static get instance(){return this.slash||(this.slash=new Qh),this.slash}constructor(){super()}toExpr(t,i){return new $e(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};c(Jh,"slash");var jp=Jh,Ks=jp.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)}},Hr={},ae=class extends Ze{constructor(e){if(super(),this.name=e,Hr[e])throw new Error("E_INVALID_CALL");Hr[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=Hr[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 Jo(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)}},eu=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)}},tu=class extends Ze{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Qo(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){Qo(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){Qo(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("("),Qo(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 iu(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")},tl=new I(100,"%"),Hn=new I(100,"pvw"),$n=new I(100,"pvh"),ke=new I(0,"px"),y0=new tu("U+0-10FFFF"),il={"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 nl(e,t){let i=il[e]||Number.MAX_VALUE,n=il[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}},mr=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},sl=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 Xp(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Zs=class nu{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 sl(r,a,1,i):l=new sl(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 nu(n)}};function rl(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 Zs(s)}function ea(e,t,i,n){return new Zs([new Zt(e,t),new Zt(i,t),new Zt(i,n),new Zt(e,n)])}var ts=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function ol(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 qp(e,t,i,n){let s,r,o,a;t.high.y<i&&H.warn("Error: inconsistent segment (1)"),t.low.y<=i?(s=ol(t,i),r=t.winding):(s=t.low.x,r=0),t.high.y>=n?(o=ol(t,n),a=t.winding):(o=t.high.x,a=0),s<o?(e.push(new ts(s,r,t.shapeId,-1)),e.push(new ts(o,a,t.shapeId,1))):(e.push(new ts(o,a,t.shapeId,-1)),e.push(new ts(s,r,t.shapeId,1)))}function Yp(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 Kp(e,t){return t?Math.ceil(e/t)*t:e}function al(e,t){return t?Math.floor(e/t)*t:e}function Zp(e){return new Zt(e.y,-e.x)}function As(e){return new wt(e.y1,-e.x2,e.y2,-e.x1)}function su(e){return new wt(-e.y2,e.x1,-e.y1,e.x2)}function ll(e){return new Zs(e.points.map(t=>Zp(t)))}function Jp(e,t,i,n,s,r){r&&(e=As(e),t=t.map(b=>ll(b)),i=i.map(b=>ll(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(Xp);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(Kp(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(al(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=al(p.low.y,s);V<b&&(b=V);break}}let E=[];for(d=0;d<v.length;d++)qp(E,v[d],g,b);E.sort((V,D)=>V.x-D.x||V.lowOrHigh-D.lowOrHigh);let A=Yp(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 ru(e,l),l}function ru(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 ou(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 Qp(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 ef(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 tf(e,t,i,n){let s=i.y1,r=i.x2-i.x1,o=i.y2-i.y1,a=ou(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 nf(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=ou(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););}ru(e,t)}var sf=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 rf(e){if(e){let t=new sf;try{return e.visit(t),t.propSet}catch(i){H.warn(i,"toSet:")}}return{}}var of=class extends Xt{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function hl(e,t){if(e){let i=new of(t);try{return e.visit(i),i.value}catch(n){H.warn(n,"toInt: ")}}return t}var af=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 Zs(o)}break;case"rectangle":if(r.length==4)return ea(e+r[0],t+r[1],e+r[0]+r[2],t+r[1]+r[3]);break;case"ellipse":if(r.length==4)return rl(e+r[0],t+r[1],r[2],r[3]);break;case"circle":if(r.length==3)return rl(e+r[0],t+r[1],r[2],r[2]);break}}return null}};function au(e,t,i,n,s,r){if(e){let o=new af;try{return e.visit(o),o.getShape(t,i,n,s,r)}catch(a){H.warn(a,"toShape:")}}return ea(t,i,t+n,i+s)}var lf=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 lf(t);try{e.visit(i)}catch(n){H.warn(n,"toCounters:")}return i.counters}var hf=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 wr(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 uf=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}},cf=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()}},df=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(Is);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(Ah),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)}},pf=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 cf(this,e)}createCounterResolver(e,t,i){return new df(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=wr(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=wr(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 uf(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let r=wr(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(vr,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(xr,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?br:yr,e.key),r}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${yr}]`);for(let s of t){let r=s.getAttribute(yr),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(`[${vr}]`);for(let s of i)s.setAttribute(ul,!0);let n=e.querySelectorAll(`[${xr}]`);for(let s of n)s.setAttribute(cl,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${br}]`),n=e.contentContainer.childElementCount;for(let o of i){let a=o.getAttribute(br),l=this.pagesCounterExprs.findIndex(h=>h.expr.key===a);l>=0,o.textContent=this.pagesCounterExprs[l].format([n])}let s=e.root.querySelectorAll(`[${ul}]`);for(let o of s){let a=o.getAttribute(vr),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(`[${cl}]`);for(let o of r){let a=o.getAttribute(xr),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 ff(this,e)}},br="data-vivliostyle-pages-counter",yr="data-vivliostyle-page-counter",vr="data-vivliostyle-target-counter",xr="data-vivliostyle-target-text",ul="data-vivliostyle-target-counter-in-running",cl="data-vivliostyle-target-text-in-running",ff=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 gf(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,gf)}var mf=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 wf=[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 lu=[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];lu[NaN]=35;var hu=[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];hu[NaN]=45;var $r=[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];$r[NaN]=37;var Wr=[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];Wr[NaN]=38;var hi=We(35,[61,36]),bf=We(35,[58,77]),yf=We(35,[61,36,124,50]),vf=We(35,[38,51]),xf=We(35,[42,54]),Sf=We(39,[42,55]),Cf=We(54,[42,55,47,56]),kf=We(62,[62,82]),Ef=We(35,[61,36,33,70]),Nf=We(62,[45,71]),Pf=We(63,[45,81]),Sr=We(76,[10,72,13,72]),Tf=We(39,[39,46,10,72,13,72,92,48]),If=We(39,[34,46,10,72,13,72,92,49]),Af=We(39,[39,47,10,74,13,74,92,48]),Rf=We(39,[34,47,10,74,13,74,92,49]),dl=We(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Ff=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]),Lf=We(39,[39,68,10,74,13,74,92,75,NaN,67]),Bf=We(39,[34,68,10,74,13,74,92,75,NaN,67]),Of=We(72,[9,39,10,39,13,39,32,39,41,69]),_f=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=_f,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new mf}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=$r;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=Tf;continue;case 34:a=2,l=++r,n=If;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=vf;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=lu;continue;case 16:l=r++,n=wf;continue;case 78:l=r++,a=9,n=Rt;continue;case 17:l=r++,a=19,n=xf;continue;case 18:l=r++,a=18,n=bf;continue;case 77:r++,a=50;break;case 19:l=r++,a=17;break;case 20:l=r++,a=38,n=Ef;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=Sr;continue;case 30:l=r++,a=33,n=hi;continue;case 31:l=r++,a=34,n=yf;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=Wr;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=Sr;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=Af;continue;case 49:f=r,r+=2,n=Rf;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=dl;continue}a=6}break;case 53:if(h=li(s.substring(l,r)),a==1){if(r++,h.toLowerCase()=="url"){n=dl;continue}a=6}break;case 54:n=Sf,r++;continue;case 55:n=Cf,r++;continue;case 56:n=_t,r++;continue;case 57:n=kf,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=$r,r++;continue;case 59:a=4,n=Wr,r++;continue;case 60:a=1,n=Rt,r++;continue;case 61:a=1,n=Sr,f=r++;continue;case 62:r--;break;case 63:r-=2;break;case 64:l=r++,n=Ff;continue;case 65:l=++r,n=Lf;continue;case 66:l=++r,n=Bf;continue;case 67:a=8,h=li(s.substring(l,r)),r++;break;case 69:r++;break;case 70:n=Nf,r++;continue;case 71:n=Pf,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=Of;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=hu;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,Gr=null;function jr(){return Oe}function B(e){if(!Oe)throw new Error("E_TASK_NO_CONTEXT");Oe.name||(Oe.name=e);let t=Oe,i=new Js(t,t.top,e);return t.top=i,i.state=1,i}function Mf(e){return new Vf(e||new Df)}function N(e){return new Xr(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 zf(e,t){return(Oe?Oe.getScheduler():Gr||Mf()).run(e,t)}var Df=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Vf=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 bp,Gr||(Gr=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 Uf(this,t||"");i.top=new Js(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}},uu=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}},Uf=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 uu(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 W=new tf,Os=(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.PAGINATION_PROGRESS="PAGINATION_PROGRESS",e))(Os||{}),hs={};function kt(e,t,i){if(!Os[e])W.warn(new Error(`Skipping unknown plugin hook '${e}'.`));else{let n=hs[e];n||(n=hs[e]=[]),i?n.unshift(t):n.push(t)}}function su(e,t){if(!Os[e])W.warn(new Error(`Ignoring unknown plugin hook '${e}'.`));else{let i=hs[e];if(i){let n=i.indexOf(t);n>=0&&i.splice(n,1)}}}function Ft(e){return hs[e]||[]}var nf={registerHook:kt,removeHook:su},ou=class{constructor(e){this.performanceInstance=e,c(this,"timestamps",{}),c(this,"registerTiming"),c(this,"registerStartTiming"),c(this,"registerEndTiming"),this.registerTiming=$i,this.registerStartTiming=this.registerStartTiming=$i,this.registerEndTiming=this.registerEndTiming=$i}forceRegisterStartTiming(e,t){Qs.call(this,e,"start",t)}forceRegisterEndTiming(e,t){Qs.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
|
+
`}}),W.info(t)}disable(){this.registerTiming=$i,this.registerStartTiming=this.registerStartTiming=$i,this.registerEndTiming=this.registerEndTiming=$i}enable(){this.registerTiming=Qs,this.registerStartTiming=this.registerStartTiming=wl,this.registerEndTiming=this.registerEndTiming=rf}isEnabled(){return this.registerStartTiming===wl}};function $i(){}function Qs(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 wl(e,t){this.registerTiming(e,"start",t)}function rf(e,t){this.registerTiming(e,"end",t)}var sf={now:Date.now},of=window&&window.performance,wt=new ou(of||sf);wt.forceRegisterStartTiming("load_vivliostyle");var af={profiler:{registerStartTiming:wt.registerStartTiming,registerEndTiming:wt.registerEndTiming,printTimings:wt.printTimings,disable:wt.disable,enable:wt.enable}},Pa=navigator.userAgent.includes("Chrome")?"chromium":navigator.userAgent.includes("Firefox")?"firefox":navigator.userAgent.includes("AppleWebKit")?"webkit":"unknown",us=/^[\s\p{Zs}\p{P}\p{Mn}]*[\p{L}\p{N}]\p{Mn}*(?:[\s\p{Zs}]*\p{P}\p{Mn}*)*/u,$t="data-adapt-eloff",lf={};function Na(e){return JSON.parse(e)}function Wt(e){let t=e.match(/^([^#]*)/);return t?t[1]:e}function hf(e){let t=e.match(/^([^#?]*)/);return t?t[1]:e}var Di=window.location.href;function yl(e){Di=e}var fi=window.location.href;function bl(e){fi=e}function Ee(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=hf(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 Ir(e,t){return e.match(/^#/)&&t?Wt(t)+e:Ee(e,t)}function pn(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 vl(e){return e==null?e:e.toString()}var uf=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}},au=["","-webkit-","-moz-"],ji={};function Vr(e,t){return CSS.supports(e+t,"unset")}function cf(e){let t=ji[e];if(t||t===null)return t;switch(e){case"behavior":case"template":case"ua-list-item-count":case"x-first-pseudo":return ji[e]=null,null;case"text-combine-upright":if(Vr("-webkit-","text-combine")&&!Vr("","text-combine-upright"))return ji[e]=["-webkit-text-combine"],["-webkit-text-combine"];break}for(let i of au)if(Vr(i,e))return t=[i+e],ji[e]=t,t;return W.warn("Property not supported by the browser: ",e),ji[e]=null,null}function I(e,t,i){let n=e?.style;if(!n)return;if(t.startsWith("--")){n.setProperty(t,i||" ");return}let r=cf(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 ci(e,t,i){try{let n=ji[t];return e.style.getPropertyValue(n?n[0]:t)}catch{}return i||""}function vo(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 lu(e){return`\\${e.charCodeAt(0).toString(16)} `}function gi(e){return e.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,lu)}function fr(e){return e.replace(/[\u0000-\u001F"\\]/g,lu)}function xl(e){return e.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function Sl(e){return!!e.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function df(e,t){return t=typeof t=="string"?t:"\\u",t+(65536|e.charCodeAt(0)).toString(16).substr(1)}function hu(e,t){function i(n){return df(n,t)}return e.replace(/[^-a-zA-Z0-9_]/g,i)}function ai(e){return hu(e)}function pf(e,t){return t=typeof t=="string"?t:"\\u",e.indexOf(t)===0?String.fromCharCode(parseInt(e.substring(t.length),16)):e}function ff(e,t){t=typeof t=="string"?t:"\\u";function i(r){return pf(r,t)}let n=new RegExp(`${ai(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 r=i+n>>1;t(r)?n=r:i=r+1}}function uu(e,t){return e-t}function Cl(e,t){let i={};for(let n of e){let r=t(n);r&&!i[r]&&(i[r]=n)}return i}function gf(e){let t={};for(let i=0;i<e.length;i++)t[e[i]]=!0;return t}function eo(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 mf(e,t){let i={};for(let n in e)i[n]=t(e[n],n);return i}var Ta=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)}}},Oi={audio:!0,canvas:!0,embed:!0,iframe:!0,img:!0,math:!0,object:!0,picture:!0,svg:!0,video:!0};function cu(){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 du(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 wf=cu(),kl={PENDING:{}};function pu(e,t,i,n){let r=Math.min((e-0)/i,(t-0)/n);return`matrix(${r},0,0,${r},0,0)`}function yf(e){return`"${fr(`${e}`)}"`}function bf(e){return gi(`${e}`)}function xo(e,t){return e?`${gi(e)}.${gi(t)}`:gi(t)}var fu=0,So=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${fu++}`,this.zero=new Ye(this,0),this.one=new Ye(this,1),this._true=new Ye(this,!0),this._false=new Ye(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=pu,i["css-string"]=yf,i["css-name"]=bf,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 this.pubTitle?this.pubTitle:""}),this.defineBuiltInName("doc-title",function(){return this.docTitle?this.docTitle:""})}}defineBuiltInName(e,t){this.values[e]=new Ie(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 vf(e){switch(e?.toLowerCase()){case"px":case"in":case"pt":case"pc":case"cm":case"mm":case"q":return!0;default:return!1}}function gu(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 xf(e){switch(e?.toLowerCase()){case"em":case"rem":case"lh":case"rlh":return!0;default:return!1}}function Sf(e){switch(e?.toLowerCase()){case"rem":case"rlh":return!0;default:return!1}}var _t={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 mu(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 Co=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=wf}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(gu(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:_t[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 Ye(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}},Ot=class{constructor(e){this.scope=e,c(this,"key"),this.scope=e,this.key=`_${fu++}`}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===kl.PENDING?!1:n;{i[this.key]=kl.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}},wu=class extends Ot{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)}},Bs=class extends Ot{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)}},yu=class extends Bs{constructor(e,t,i){super(e,t,i)}getPriority(){return 1}},Nn=class extends Bs{constructor(e,t,i){super(e,t,i)}getPriority(){return 2}},bu=class extends Bs{constructor(e,t,i){super(e,t,i)}getPriority(){return 3}},Ia=class extends Bs{constructor(e,t,i){super(e,t,i)}getPriority(){return 4}},mi=class extends wu{constructor(e,t){super(e,t)}getOp(){return"!"}evalPrefix(e){return!e}},Cf=class extends mi{constructor(e,t){super(e,t)}getOp(){return"not "}},rn=class extends wu{constructor(e,t){super(e,t)}getOp(){return"-"}evalPrefix(e){return-e}},Aa=class extends yu{constructor(e,t,i){super(e,t,i)}getOp(){return"&&"}evaluateCore(e){return this.lhs.evaluate(e)&&this.rhs.evaluate(e)}},kf=class extends Aa{constructor(e,t,i){super(e,t,i)}getOp(){return" and "}},Ra=class extends yu{constructor(e,t,i){super(e,t,i)}getOp(){return"||"}evaluateCore(e){return this.lhs.evaluate(e)||this.rhs.evaluate(e)}},Ef=class extends Ra{constructor(e,t,i){super(e,t,i)}getOp(){return", "}},Pf=class extends Ra{constructor(e,t,i){super(e,t,i)}getOp(){return" or "}},Nf=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return"<"}evalInfix(e,t){return e<t}},Tf=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return"<="}evalInfix(e,t){return e<=t}},If=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return">"}evalInfix(e,t){return e>t}},ko=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return">="}evalInfix(e,t){return e>=t}},Fa=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return"=="}evalInfix(e,t){return e==t}},Af=class extends Nn{constructor(e,t,i){super(e,t,i)}getOp(){return"!="}evalInfix(e,t){return e!=t}},vu=class extends bu{constructor(e,t,i){super(e,t,i)}getOp(){return"+"}evalInfix(e,t){return e+t}},xu=class extends bu{constructor(e,t,i){super(e,t,i)}getOp(){return" - "}evalInfix(e,t){return e-t}},La=class extends Ia{constructor(e,t,i){super(e,t,i)}getOp(){return"*"}evalInfix(e,t){return e*t}},Su=class extends Ia{constructor(e,t,i){super(e,t,i)}getOp(){return"/"}evalInfix(e,t){return e/t}},Cu=class extends Ia{constructor(e,t,i){super(e,t,i)}getOp(){return"%"}evalInfix(e,t){return e%t}},gr=class extends Ot{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(gi(this.unit))}evaluateCore(e){return this.num*e.queryUnitSize(this.unit,!1)}},je=class extends Ot{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 Ot{constructor(e,t,i){super(e),this.not=t,this.name=i}appendTo(e,t){this.not&&e.append("not "),e.append(gi(this.name))}evaluateCore(e){return e.evalMediaName(this.name,this.not)}isMediaName(){return!0}},Ie=class extends Ot{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 Rf(e,t){e.append("(");for(let i=0;i<t.length;i++)i&&e.append(","),t[i].appendTo(e,0);e.append(")")}function Ff(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 Yn=class ku extends Ot{constructor(t,i,n){super(t),this.qualifiedName=i,this.params=n}appendTo(t,i){t.append(this.qualifiedName),Rf(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=Ff(t,this.params,i);return n===this.params?this:new ku(this.scope,this.qualifiedName,n)}},Lf=class Eu extends Ot{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 Eu(this.scope,n,r,s)}},Ye=class extends Ot{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(fr(this.val)),e.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}}evaluateCore(e){return this.val}},Pl=class Pu extends Ot{constructor(t,i,n){super(t),this.name=i,this.value=n}appendTo(t,i){t.append("("),t.append(fr(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 Pu(this.scope,this.name,n)}},Of=class extends Ot{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)}},Nu=class extends Ot{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 At(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 Aa(e,t,i)}function ie(e,t,i){return t===e.zero?i:i===e.zero?t:new vu(e,t,i)}function ye(e,t,i){return t===e.zero?new rn(e,i):i===e.zero?t:new xu(e,t,i)}function Ur(e,t,i){return t===e.zero||i===e.zero?e.zero:t===e.one?i:i===e.one?t:new La(e,t,i)}function Eo(e,t,i){return t===e.zero?e.zero:i===e.one?t:new Su(e,t,i)}var oi=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}},Vi=class extends oi{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?Y:t===e.values?e:new te(t)}visitCommaList(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new tt(t)}visitFunc(e){let t=this.visitValues(e.values);return this.error?Y:t===e.values?e:new Ui(e.name,t)}visitExpr(e){return e}},it=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}},Tu=class Iu extends it{static get instance(){return this.empty||(this.empty=new Iu),this.empty}constructor(){super()}toExpr(t,i){return new Ye(t,"")}appendTo(t,i){}visit(t){return t.visitEmpty(this)}};c(Tu,"empty");var Bf=Tu,Y=Bf.instance,Au=class Ru extends it{static get instance(){return this.slash||(this.slash=new Ru),this.slash}constructor(){super()}toExpr(t,i){return new Ye(t,"/")}appendTo(t,i){t.append("/")}visit(t){return t.visitSlash(this)}};c(Au,"slash");var Mf=Au,Tn=Mf.instance,j=class extends it{constructor(e){super(),this.str=e}toExpr(e,t){return new Ye(e,this.str)}appendTo(e,t){t?(e.append('"'),e.append(fr(this.str)),e.append('"')):e.append(this.str)}visit(e){return e.visitStr(this)}},Po=Object.create(null),de=class extends it{constructor(e){if(super(),this.name=e,Po[e])throw new Error("E_INVALID_CALL");Po[e]=this}toExpr(e,t){return new Ye(e,this.name)}appendTo(e,t){t?e.append(gi(this.name)):e.append(this.name)}visit(e){return e.visitIdent(this)}isIdent(){return!0}};function B(e){let t=Po[e];return t||(t=new de(e)),t}var F=class extends it{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 La(e,t,new Ye(e,this.num/100)):new gr(e,this.num,this.unit)}appendTo(e,t){e.append(this.num.toString()),e.append(this.unit)}visit(e){return e.visitNumeric(this)}isNumeric(){return!0}},vt=class extends it{constructor(e){super(),this.num=e}toExpr(e,t){return this.num==0?e.zero:this.num==1?e.one:new Ye(e,this.num)}appendTo(e,t){e.append(this.num.toString())}visit(e){return e.visitNum(this)}isNum(){return!0}},Be=class extends vt{constructor(e){super(e)}visit(e){return e.visitInt(this)}},Fu=class extends it{constructor(e){super(),this.hex=e}appendTo(e,t){e.append("#"),e.append(this.hex)}visit(e){return e.visitHexColor(this)}},ot=class extends it{constructor(e){super(),this.url=e}appendTo(e,t){e.append('url("'),e.append(fr(this.url)),e.append('")')}visit(e){return e.visitURL(this)}},Lu=class extends it{constructor(e){super(),this.urangeText=e}appendTo(e,t){e.append(this.urangeText)}visit(e){return e.visitURange(this)}};function Oa(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 te=class extends it{constructor(e){super(),this.values=e}appendTo(e,t){Oa(e,this.values," ",t)}visit(e){return e.visitSpaceList(this)}isSpaceList(){return!0}},tt=class extends it{constructor(e){super(),this.values=e}appendTo(e,t){Oa(e,this.values,",",t)}visit(e){return e.visitCommaList(this)}},Ui=class extends it{constructor(e,t){super(),this.name=e,this.values=t}appendTo(e,t){e.append(gi(this.name)),e.append("("),Oa(e,this.values,",",t),e.append(")")}visit(e){return e.visitFunc(this)}},$=class extends it{constructor(e){super(),this.expr=e}toExpr(){return this.expr}appendTo(e,t){this.expr instanceof Ye||this.expr instanceof gr?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}},Xi=class extends it{constructor(e){super(),this.text=e}appendTo(e,t){e.append(this.text||" ")}};function nt(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 Ou(e,t){return new F(nt(e,t),"px")}var v={absolute:B("absolute"),all:B("all"),always:B("always"),anywhere:B("anywhere"),auto:B("auto"),avoid:B("avoid"),balance:B("balance"),balance_all:B("balance-all"),block:B("block"),block_end:B("block-end"),block_start:B("block-start"),both:B("both"),bottom:B("bottom"),border_box:B("border-box"),break_all:B("break-all"),break_word:B("break-word"),clip:B("clip"),crop:B("crop"),cross:B("cross"),column:B("column"),discard:B("discard"),exclusive:B("exclusive"),_false:B("false"),fixed:B("fixed"),flex:B("flex"),flow_root:B("flow-root"),footnote:B("footnote"),footer:B("footer"),grid:B("grid"),header:B("header"),hidden:B("hidden"),horizontal_tb:B("horizontal-tb"),inherit:B("inherit"),initial:B("initial"),inline:B("inline"),inline_block:B("inline-block"),inline_end:B("inline-end"),inline_start:B("inline-start"),inside:B("inside"),keep:B("keep"),landscape:B("landscape"),left:B("left"),line:B("line"),list_item:B("list-item"),ltr:B("ltr"),manual:B("manual"),max_content:B("max-content"),min_content:B("min-content"),none:B("none"),normal:B("normal"),oeb_page_foot:B("oeb-page-foot"),oeb_page_head:B("oeb-page-head"),outside:B("outside"),padding_box:B("padding-box"),page:B("page"),relative:B("relative"),revert:B("revert"),right:B("right"),same:B("same"),scale:B("scale"),snap_block:B("snap-block"),snap_inline:B("snap-inline"),solid:B("solid"),spread:B("spread"),_static:B("static"),rtl:B("rtl"),table:B("table"),table_caption:B("table-caption"),table_cell:B("table-cell"),table_footer_group:B("table-footer-group"),table_header_group:B("table-header-group"),table_row:B("table-row"),top:B("top"),transparent:B("transparent"),unset:B("unset"),vertical_lr:B("vertical-lr"),vertical_rl:B("vertical-rl"),visible:B("visible"),_true:B("true")},Nl=new F(100,"%"),mr=new F(100,"pvw"),wr=new F(100,"pvh"),Ne=new F(0,"px"),b0=new Lu("U+0-10FFFF"),Tl={"font-size":1,"line-height":2,color:3};function J(e){return e===v.inherit||e===v.initial||e===v.revert||e===v.unset}function Il(e,t){let i=Tl[e]||Number.MAX_VALUE,n=Tl[t]||Number.MAX_VALUE;return i-n}function jt(e){return e?.length>2&&e.startsWith("--")}var qi,Yi,Zi,Bu=class qt{constructor(t,i,n){ne(this,qi),ne(this,Yi),ne(this,Zi),Oe(this,qi,Math.round(Math.max(0,Math.min(t,qt.MAX)))),Oe(this,Yi,Math.round(Math.max(0,Math.min(i,qt.MAX)))),Oe(this,Zi,Math.round(Math.max(0,Math.min(n,qt.MAX))))}static fromInt(t,i,n){return new qt(t,i,n)}offset(t,i,n){return new qt(V(this,qi)+t,V(this,Yi)+i,V(this,Zi)+n)}toKey(){return JSON.stringify([V(this,qi),V(this,Yi),V(this,Zi)])}toColorFunc(t){return new Ui("color",[new te([B("srgb"),new vt(V(this,qi)/qt.MAX),new vt(V(this,Yi)/qt.MAX),new vt(V(this,Zi)/qt.MAX),...t!==null?[Tn,new vt(t)]:[]])])}};qi=new WeakMap,Yi=new WeakMap,Zi=new WeakMap,c(Bu,"MAX",1e4);var Zt=Bu;function _f(e){return Array.isArray(e)?e.every(t=>{if(!Array.isArray(t)||t.length!==2)return!1;let[i,n]=t;if(!i||typeof i!="object"||Array.isArray(i)||!n||typeof n!="object"||Array.isArray(n))return!1;let r=i,s=n;return Number.isFinite(r.r)&&Number.isFinite(r.g)&&Number.isFinite(r.b)&&Number.isFinite(s.c)&&Number.isFinite(s.m)&&Number.isFinite(s.y)&&Number.isFinite(s.k)}):!1}var Ti,Ii,Ai,zt,Mu=class lt{constructor(t,i,n,r){ne(this,Ti),ne(this,Ii),ne(this,Ai),ne(this,zt),Oe(this,Ti,Math.round(Math.max(0,Math.min(t,lt.MAX)))),Oe(this,Ii,Math.round(Math.max(0,Math.min(i,lt.MAX)))),Oe(this,Ai,Math.round(Math.max(0,Math.min(n,lt.MAX)))),Oe(this,zt,Math.round(Math.max(0,Math.min(r,lt.MAX))))}static fromInt(t,i,n,r){return new lt(t,i,n,r)}static fromNumber(t,i,n,r){return new lt(t*lt.MAX,i*lt.MAX,n*lt.MAX,r*lt.MAX)}toSRGB(){let t=lt.MAX-V(this,zt);return Zt.fromInt(Zt.MAX-Math.min(Zt.MAX,Math.round(V(this,Ti)*t/lt.MAX)+V(this,zt)),Zt.MAX-Math.min(Zt.MAX,Math.round(V(this,Ii)*t/lt.MAX)+V(this,zt)),Zt.MAX-Math.min(Zt.MAX,Math.round(V(this,Ai)*t/lt.MAX)+V(this,zt)))}equals(t){return V(this,Ti)===V(t,Ti)&&V(this,Ii)===V(t,Ii)&&V(this,Ai)===V(t,Ai)&&V(this,zt)===V(t,zt)}toJSON(){return{c:V(this,Ti),m:V(this,Ii),y:V(this,Ai),k:V(this,zt)}}};Ti=new WeakMap,Ii=new WeakMap,Ai=new WeakMap,zt=new WeakMap,c(Mu,"MAX",1e4);var _u=Mu;function Wi(e){return e instanceof vt?Math.max(0,Math.min(1,e.num)):e instanceof F&&e.unit==="%"?Math.max(0,Math.min(1,e.num/100)):null}function Du(e){if(e.name!=="device-cmyk"&&e.name!=="cmyk")return null;let t=e.values.length===1&&e.values[0]instanceof te?e.values[0].values:e.values;if(t.length<4||t.length>6)return null;let i=Wi(t[0]),n=Wi(t[1]),r=Wi(t[2]),s=Wi(t[3]);if(i===null||n===null||r===null||s===null)return null;let o=null;if(t.length>=5){if(t[4]===Tn){if(t.length!==6)return null;o=Wi(t[5])}else{if(t.length!==5)return null;o=Wi(t[4])}if(o===null)return null}return{cmyk:_u.fromNumber(i,n,r,s),alpha:o}}function*Df(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 ui,cs,zu,Al,Vu=class{constructor(){ne(this,cs),ne(this,ui,new Map)}registerDeviceCmyk(e){let t=Du(e);return t?Ce(this,cs,zu).call(this,t.cmyk).toColorFunc(t.alpha):null}registerCmykReserveMap(e){for(let[t,i]of e){let n=Zt.fromInt(t.r,t.g,t.b),r=_u.fromInt(i.c,i.m,i.y,i.k);V(this,ui).set(n.toKey(),r)}}toJSON(){let e={};return V(this,ui).forEach((t,i)=>{e[i]=t.toJSON()}),e}};ui=new WeakMap,cs=new WeakSet,zu=function(e){let t=e.toSRGB(),i=t.toKey(),n=V(this,ui).get(i);return n?n.equals(e)?t:Ce(this,cs,Al).call(this,e,t):(V(this,ui).set(i,e),t)},Al=function(e,t){for(let i=1;i<=Zt.MAX;i++)for(let[n,r,s]of Df(i)){let o=t.offset(n,r,s),a=o.toKey();if(!V(this,ui).has(a))return V(this,ui).set(a,e),o}return W.warn(`CmykStore: Exceeded trackable color limit for ${JSON.stringify(e.toJSON())}`),t};var Hr,zn,Vn,Uu=class extends Vi{constructor(e){super(),ne(this,Hr),ne(this,zn,new Map),ne(this,Vn,!1),Oe(this,Hr,e??new Vu)}reset(){Oe(this,Vn,!1)}hadDeviceCmyk(){return V(this,Vn)}recordConversion(e,t){V(this,zn).set(e,t)}getConversions(){if(V(this,zn).size===0)return null;let e={};return V(this,zn).forEach((t,i)=>{e[i]=t}),e}visitFunc(e){let t=V(this,Hr).registerDeviceCmyk(e);return t?(Oe(this,Vn,!0),t):super.visitFunc(e)}};Hr=new WeakMap,zn=new WeakMap,Vn=new WeakMap;function Hu(e){if(e.nodeType==1){let t=e.getAttribute("id");if(t)return t}return null}function zf(e){return`^${e}`}function Rl(e){return e.replace(/[\[\]\(\),=;^]/g,zf)}function Vf(e){return e.substr(1)}function No(e){return e&&e.replace(/\^[\[\]\(\),=;^]/g,Vf)}function Uf(e){let t=[];do{let i=e.match(/^(\^,|[^,])*/),n=No(i[0]);if(e=e.substr(i[0].length+1),!e&&!t.length)return n;t.push(n)}while(e);return t}function Fl(e){let t={};for(;e;){let i=e.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!i)return t;t[i[1]]=Uf(i[2]),e=e.substr(i[0].length)}return t}var Ll=class{appendTo(e){e.append("!")}applyTo(e){return!1}},Ol=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!=Hu(e.node))){let o=t.ownerDocument.getElementById(this.id);o?e.node=o:W.warn("E_CFI_ID_MISMATCH:",this.id)}return e.sideBias=this.sideBias,!0}},Bl=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(Rl(this.textBefore)),e.append(","),this.textAfter&&e.append(Rl(this.textAfter))),this.sideBias&&(e.append(";s="),e.append(this.sideBias)),e.append("]"))}},Ml=class $u{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),h=i[3];o=Fl(i[4]),s.push(new Ol(a,h,vl(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),h=i[4];h&&(h=No(h));let l=i[7];l&&(l=No(l)),o=Fl(i[10]),s.push(new Bl(a,h,l,vl(o.s)));break}case"!":r++,s.push(new Ll);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 $u,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="",h="";for(;t;){switch(t.nodeType){case 3:case 4:case 5:{let l=t.textContent,u=l.length;n?(i+=u,a||(a=l)):(i>u&&(i=u),n=!0,a=l.substr(0,i),h=l.substr(i)),t=t.previousSibling;continue}case 8:t=t.previousSibling;continue}break}for((i>0||a||h)&&(a=this.trim(a,!1),h=this.trim(h,!0),s.push(new Bl(i,a,h,r)),r=null);o&&!(!o||o.nodeType==9);){let l=n?null:Hu(t),u=n?1:0;for(;t;)t.nodeType==1&&(u+=2),t=t.previousSibling;s.push(new Ol(u,l,r)),r=null,t=o,o=o.parentNode,n=!1}s.reverse(),this.steps?(s.push(new Ll),this.steps=s.concat(this.steps)):this.steps=s}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")}},Ct=class{constructor(e,t,i,n){this.x1=e,this.y1=t,this.x2=i,this.y2=n}},di=class{constructor(e,t){this.x=e,this.y=t}},to=class{constructor(e,t,i,n){this.left=e,this.top=t,this.right=i,this.bottom=n}},_l=class{constructor(e,t,i,n){this.low=e,this.high=t,this.winding=i,this.shapeId=n}},Qt=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 Hf(e,t){return e.low.y-t.low.y||e.low.x-t.low.x}var Ms=class Wu{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],h;s.y<a.y?h=new _l(s,a,1,i):h=new _l(a,s,-1,i),t.push(h),s=a}}withOffset(t,i){let n=[];for(let r of this.points)n.push(new di(r.x+t,r.y+i));return new Wu(n)}};function Dl(e,t,i,n){let r=[];for(let s=0;s<20;s++){let o=s*2*Math.PI/20;r.push(new di(e+i*Math.sin(o),t+n*Math.cos(o)))}return new Ms(r)}function Ba(e,t,i,n){return new Ms([new di(e,t),new di(i,t),new di(i,n),new di(e,n)])}var Ar=class{constructor(e,t,i,n){this.x=e,this.winding=t,this.shapeId=i,this.lowOrHigh=n}};function zl(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 $f(e,t,i,n){let r,s,o,a;t.high.y<i&&W.warn("Error: inconsistent segment (1)"),t.low.y<=i?(r=zl(t,i),s=t.winding):(r=t.low.x,s=0),t.high.y>=n?(o=zl(t,n),a=t.winding):(o=t.high.x,a=0),r<o?(e.push(new Ar(r,s,t.shapeId,-1)),e.push(new Ar(o,a,t.shapeId,1))):(e.push(new Ar(o,a,t.shapeId,-1)),e.push(new Ar(r,s,t.shapeId,1)))}function Wf(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=[],h=!1,l=e.length;for(let u=0;u<l;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}}h!=p&&(a.push(d.x),h=p)}return a}function Gf(e,t){return t?Math.ceil(e/t)*t:e}function Vl(e,t){return t?Math.floor(e/t)*t:e}function jf(e){return new di(e.y,-e.x)}function ds(e){return new Ct(e.y1,-e.x2,e.y2,-e.x1)}function Gu(e){return new Ct(-e.y2,e.x1,-e.y1,e.x2)}function Ul(e){return new Ms(e.points.map(t=>jf(t)))}function Xf(e,t,i,n,r,s){s&&(e=ds(e),t=t.map(x=>Ul(x)),i=i.map(x=>Ul(x)));let o=t.length,a=i?i.length:0,h=[],l=[],u,d,p;for(u=0;u<o;u++)t[u].addSegments(l,u);for(u=0;u<a;u++)i[u].addSegments(l,u+o);let f=l.length;l.sort(Hf);let g=0;for(;l[g].shapeId>=o;)g++;let m=l[g].low.y;m>e.y1&&h.push(new Qt(e.y1,m,e.x2,e.x2));let w=0,b=[];for(;w<f&&(p=l[w]).low.y<m;)p.high.y>m&&b.push(p),w++;for(;w<f||b.length>0;){let x=e.y2,y=Math.min(Gf(Math.ceil(m+n),r),e.y2);for(d=0;d<b.length&&x>y;d++)p=b[d],p.low.x==p.high.x?p.high.y<x&&(x=Math.max(Vl(p.high.y,r),y)):p.low.x!=p.high.x&&(x=y);for(x>e.y2&&(x=e.y2);w<f&&(p=l[w]).low.y<x;){if(p.high.y<m){w++;continue}if(p.low.y<y)p.low.y==p.high.y&&p.low.y==m||(b.push(p),x=y),w++;else{let R=Vl(p.low.y,r);R<x&&(x=R);break}}let P=[];for(d=0;d<b.length;d++)$f(P,b[d],m,x);P.sort((R,A)=>R.x-A.x||R.lowOrHigh-A.lowOrHigh);let S=Wf(P,o,a);if(S.length==0)h.push(new Qt(m,x,e.x2,e.x2));else{let R=0,A=e.x1;for(d=0;d<S.length;d+=2){let U=Math.max(e.x1,S[d]),G=Math.min(e.x2,S[d+1])-U;G>R&&(R=G,A=U)}R==0?h.push(new Qt(m,x,e.x2,e.x2)):h.push(new Qt(m,x,Math.max(A,e.x1),Math.min(A+R,e.x2)))}if(x==e.y2)break;for(m=x,d=b.length-1;d>=0;d--)b[d].high.y<=x&&b.splice(d,1)}return ju(e,h),h}function ju(e,t){let i=t.length-1,n=new Qt(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 Xu(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 qf(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 Ct(t.x1,i,t.x2,s)}function Yf(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 Ct(t.x1,s,t.x2,i)}function Zf(e,t,i,n){let r=i.y1,s=i.x2-i.x1,o=i.y2-i.y1,a=Xu(t,r);for(;;){let h=r+o;if(h>e.y2)return!1;let l=e.x1,u=e.x2;for(let d=a;d<t.length&&t[d].y1<h;d++){let p=t[d];p.x1>l&&(l=p.x1),p.x2<u&&(u=p.x2)}if(l+s<=u||a>=t.length)return n=="left"?(i.x1=l,i.x2=l+s):(i.x1=u-s,i.x2=u),i.y2+=r-i.y1,i.y1=r,!0;r=t[a].y2,a++}}function Kf(e,t,i,n,r){for(n||(n=[new Qt(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 Qt(o,e.y2,e.x1,e.x2));let a=Xu(t,n[0].y1);for(let h of n){if(a==t.length)break;for(t[a].y1<h.y1&&(s=t[a],a++,t.splice(a,0,new Qt(h.y1,s.y2,s.x1,s.x2)),s.y2=h.y1);a<t.length&&(s=t[a++],s.y2>h.y2&&(t.splice(a,0,new Qt(h.y2,s.y2,s.x1,s.x2)),s.y2=h.y2),h.x1!=h.x2&&(r=="left"?s.x1=Math.min(h.x2,e.x2):s.x2=Math.max(h.x1,e.x1)),s.y2!=h.y2););}ju(e,t)}var Jf=class extends oi{constructor(){super(),c(this,"propSet",{})}visitIdent(e){return this.propSet[e.name]=!0,e}visitSpaceList(e){return this.visitValues(e.values),e}};function Qf(e){if(e){let t=new Jf;try{return e.visit(t),t.propSet}catch(i){W.warn(i,"toSet:")}}return{}}var eg=class extends oi{constructor(e){super(),this.value=e}visitInt(e){return this.value=e.num,e}};function Hl(e,t){if(e){let i=new eg(t);try{return e.visit(i),i.value}catch(n){W.warn(n,"toInt: ")}}return t}var tg=class extends oi{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 F(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 h=a%2==0?i:n;a==3&&this.name=="circle"&&(h=Math.sqrt((i*i+n*n)/2)),s.push(o.num*h/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 di(e+s[a],t+s[a+1]));return new Ms(o)}break;case"rectangle":if(s.length==4)return Ba(e+s[0],t+s[1],e+s[0]+s[2],t+s[1]+s[3]);break;case"ellipse":if(s.length==4)return Dl(e+s[0],t+s[1],s[2],s[3]);break;case"circle":if(s.length==3)return Dl(e+s[0],t+s[1],s[2],s[2]);break}}return null}};function qu(e,t,i,n,r,s){if(e){let o=new tg;try{return e.visit(o),o.getShape(t,i,n,r,s)}catch(a){W.warn(a,"toShape:")}}return Ba(t,i,t+n,i+r)}var ig=class extends oi{constructor(e,t){super(),this.reset=e,this.defaultValue=t,c(this,"counters",Object.create(null)),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)+this.defaultValue,e}visitInt(e){return this.name&&(this.counters[this.name]+=e.num-(this.reset?0:this.defaultValue)),e}visitSpaceList(e){return this.visitValues(e.values),e}};function fn(e,t){var i,n;let r=(i=t?.reset)!=null?i:!1,s=(n=t?.defaultValue)!=null?n:r?0:1,o=new ig(r,s);try{e.visit(o)}catch(a){W.warn(a,"toCounters:")}return o.counters}var ng=class extends Vi{constructor(e,t){super(),this.baseUrl=e,this.transformer=t}visitURL(e){return new ot(this.transformer.transformURL(e.url,this.baseUrl))}};function Ci(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function rg(e){return e.replace(/\\([0-9a-fA-F]{1,6})\s?|\\(.)/g,(t,i,n)=>i?String.fromCodePoint(parseInt(i,16)):n)}function sn(e,t){var i,n;if(t==="content"){let r=e.cloneNode(!0);return r.querySelectorAll("[data-adapt-pseudo]").forEach(s=>s.remove()),r.textContent||""}else if(t==="marker"){let r=e.querySelector('[data-adapt-pseudo="marker"], [data-adapt-pseudo="footnote-marker"]');if(r)return r.textContent||"";let s=(n=(i=e.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(e))==null?void 0:n.getPropertyValue("--viv-marker-content");if(s){let o=s.match(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g);if(o&&o.length>0)return o.map(a=>rg(a.substring(1,a.length-1))).join("")}return""}else{let r=e.querySelector(`[data-adapt-pseudo="${t}"]`);return r&&r.textContent||""}}var sg=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}},og=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()}},ag=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",Object.create(null)),c(this,"runningElements",Object.create(null))}setStyler(e){this.styler=e}getFragment(e){let t=e.match(/^[^#]*#(.*)$/);return t?t[1]:null}getTransformedId(e){let t=this.counterStore.documentURLTransformer.transformURL(Ee(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 Ie(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 Ie(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}getTargetPageDocCounters(e){return this.counterStore.currentPage.elementsById[e]?this.counterStore.currentPageDocCounters:this.counterStore.pageDocCountersById[e]||null}adjustCountersForCrossScope(e,t,i,n){if(!this.counterStore.isPageControlledCounter(e)||!i)return t;let r=i[e]||[],s=r.length?r[r.length-1]:0,o=n?.[e]||[],a=o.length?o[0]:0;return t.length?[s+(t[0]-a),...t.slice(1)]:[s]}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"?sn(n,t):sn(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=new Ie(this.pageScope,()=>{let o=this.getTargetCounters(n,r,!0);if(o)if(o[t]){let a=o[t],h=this.getTargetPageCounters(r),l=this.getTargetPageDocCounters(r),u=this.adjustCountersForCrossScope(t,a,h,l);return h&&this.counterStore.resolveReference(r),i(u[u.length-1]||null)}else{let a=this.getTargetPageCounters(r);if(a)if(this.counterStore.resolveReference(r),a[t]){let h=a[t];return i(h[h.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,s,r),s}getTargetCountersVal(e,t,i){let n=this.getFragment(e),r=this.getTransformedId(e);return new Ie(this.pageScope,()=>{let s=this.getTargetPageCounters(r);if(s){this.counterStore.resolveReference(r);let o=this.getTargetCounters(n,r,!0),a=o?.[t]||[],h=this.getTargetPageDocCounters(r),l=this.adjustCountersForCrossScope(t,a,s,h);if(l.length)return i(l);let u=s[t]||[];return i(u)}else return this.counterStore.saveReferenceOfCurrentPage(r,!1),"??"},`target-counters-${t}-of-${e}`)}getTargetTextVal(e,t){let i=this.getTransformedId(e),n=new Ie(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 h=(s??"")+(o??"")+(a??"");this.counterStore.resolveReference(i);let l=h.match(us);return l?l[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 Ie(this.pageScope,()=>this.getRunningValue(this.namedStringValues,e,t),`named-string-${t}-${e}`)}getRunningElementVal(e,t){return new Ie(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(uu),s=this.counterStore.currentPage;if(!s)return"";let o=s.isBlankPage?s.offset-1:s.offset,a=s.isBlankPage?o:Math.max(o,...Array.from(s.container.querySelectorAll(`[${$t}]`)).map(p=>parseInt(p.getAttribute($t),10))),h=-1,l=-1,u=-1,d=-1;for(let p=0;p<r.length;p++){let f=r[p],g=p>0?r[p-1]:-1,m=p<r.length-1?r[p+1]:-1;if(f>a)break;if(f>=o){if(h<0&&(h=f,d=-1),l<0)if(f===o)l=f;else{g<h&&(l=g);let w=s.container.querySelector(`[${$t}="${f}"]`);if(!w)l<0&&(l=f);else{let b=s.container.querySelector(`[${$t}="${o}"]`);if(b||(b=s.container.querySelector(`[${$t}="0"]`)),b){for(let x=b;x;x=x.firstElementChild)if(x===w){l=f;break}}}}u=f}else(m>a||m<0)&&(h=l=u=d=f)}return n[{first:h,start:l,last:u,"first-except":d}[i]]||""}setNamedString(e,t,i){let n=this.namedStringValues[e]||(this.namedStringValues[e]=Object.create(null));n[i]=t}setRunningElement(e,t){let i=this.runningElements[e]||(this.runningElements[e]=Object.create(null));i[t]=String(t)}},lg=class{constructor(e){this.documentURLTransformer=e,c(this,"countersById",Object.create(null)),c(this,"pageCountersById",Object.create(null)),c(this,"pageDocCountersById",Object.create(null)),c(this,"pageTextById",Object.create(null)),c(this,"currentPageDocCounters",null),c(this,"previousPageDocCounters",null),c(this,"currentPageDocCounterChanges",Object.create(null)),c(this,"currentPageDocCounterChangeTypes",Object.create(null)),c(this,"currentPageCounters",Object.create(null)),c(this,"previousPageCounters",Object.create(null)),c(this,"currentPageCountersStack",[]),c(this,"pageIndicesById",Object.create(null)),c(this,"currentPage",null),c(this,"newReferencesOfCurrentPage",[]),c(this,"referencesToSolve",[]),c(this,"referencesToSolveStack",[]),c(this,"unresolvedReferences",Object.create(null)),c(this,"resolvedReferences",Object.create(null)),c(this,"pageControlledCounterNames",Object.assign(Object.create(null),{page:!0})),c(this,"pagesCounterExprs",[]),c(this,"pageCounterExprs",[]),c(this,"targetCounterExprs",[]),c(this,"targetTextExprs",[]),this.currentPageCounters.page=[0]}createCounterListener(e){return new og(this,e)}createCounterResolver(e,t,i){return new ag(this,e,t,i)}setCurrentPage(e){this.currentPage=e}setCurrentPageDocCounters(e,t,i){this.previousPageDocCounters=this.currentPageDocCounters?Ci(this.currentPageDocCounters):null,this.currentPageDocCounters=e?Ci(e):null,this.currentPageDocCounterChanges=Object.create(null),this.currentPageDocCounterChangeTypes=i?{...i}:Object.create(null),t&&t.forEach(n=>{this.currentPageDocCounterChanges[n]=!0})}setPageControlledCounterNames(e){let t=Object.assign(Object.create(null),{page:!0});e.forEach(i=>{t[i]=!0}),this.pageControlledCounterNames=t}isPageControlledCounter(e){return!!this.pageControlledCounterNames[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=Ci(this.currentPageCounters);let i=this.currentPageDocCounterChanges||{},n=this.currentPageDocCounterChangeTypes||{},r=Object.create(null);if(this.currentPageDocCounters){let g=this.previousPageDocCounters||{};for(let m in this.currentPageDocCounters){if(!i[m])continue;let w=this.currentPageDocCounters[m],b=w.length?w[w.length-1]:0,x=g[m]||[],y=x.length?x[x.length-1]:0,P=b-y,S=n[m],R=S==="reset"||S==="set";r[m]={delta:P,reset:R,value:b}}}let s=Object.create(null),o,a=e["counter-reset"];if(a){let g=a.evaluate(t);g&&(o=fn(g,{reset:!0}))}o&&"pages"in o&&delete o.pages;let h,l=e["counter-set"];if(l){let g=l.evaluate(t);g&&(h=fn(g,{defaultValue:0}))}h&&"pages"in h&&delete h.pages;let u=[];if(o)for(let g in o)u.push(g);if(h)for(let g in h)u.push(g);let d,p=e["counter-increment"];if(p){let g=p.evaluate(t);g&&(d=fn(g))}d&&"pages"in d&&delete d.pages,d?!("page"in d)&&!(r.page&&r.page.reset)&&(d.page=1):(d=Object.create(null),r.page&&r.page.reset||(d.page=1));for(let g in d)u.push(g);this.setPageControlledCounterNames(u);let f=Ci(this.previousPageCounters);if(this.currentPageDocCounters)for(let g in this.currentPageDocCounters){if(this.isPageControlledCounter(g)){let m=r[g];if(m){if(m.reset)f[g]=[m.value],s[g]=!0;else if(m.delta!==0){f[g]||(f[g]=[0]);let w=f[g];w[w.length-1]+=m.delta}}continue}f[g]=Array.from(this.currentPageDocCounters[g])}if(this.currentPageCounters=f,o)for(let g in o)this.definePageCounter(g,o[g]);if(h)for(let g in h)if(!this.currentPageCounters[g])this.definePageCounter(g,h[g]);else{let m=this.currentPageCounters[g];m[m.length-1]=h[g]}for(let g in d){if(s[g])continue;this.currentPageCounters[g]||this.definePageCounter(g,0);let m=this.currentPageCounters[g];m[m.length-1]+=d[g]}}pushPageCounters(e){this.currentPageCountersStack.push(this.currentPageCounters),this.currentPageCounters=Ci(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 sg(e,t);this.newReferencesOfCurrentPage.push(i)}}finishPage(e,t){let i=Object.keys(this.currentPage.elementsById);if(i.length>0){let s=Ci(this.currentPageCounters),o=this.currentPageDocCounters?Ci(this.currentPageDocCounters):null;i.forEach(a=>{this.pageCountersById[a]=s,o&&(this.pageDocCountersById[a]=o);let h=this.currentPage.elementsById[a];if(h&&h.length>0){let u=h[0];this.pageTextById[a]={content:sn(u,"content"),before:sn(u,"before"),after:sn(u,"after"),marker:sn(u,"marker")}}let l=this.pageIndicesById[a];if(l&&l.pageIndex<t){let u=this.resolvedReferences[a];if(u){let d=this.unresolvedReferences[a];d||(d=this.unresolvedReferences[a]=[]);let p;for(;p=u.shift();)p.unresolve(),d.push(p)}}this.pageIndicesById[a]={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}adjustPageCountersOfLaterSpines(e,t){if(t<=0)return;let i=new Set;for(let n of Object.keys(this.pageIndicesById))if(this.pageIndicesById[n].spineIndex>e){let r=this.pageCountersById[n];r&&r.page&&!i.has(r)&&(i.add(r),r.page=r.page.map(s=>s+t))}}updateTargetCounterNodesInPages(e){for(let t of e){if(!t||!t.container)continue;let i=t.container.querySelectorAll(`[${On}]`);for(let n of i){let r=n.getAttribute(On),s=this.targetCounterExprs.find(o=>o.expr.key===r);if(s&&s.transformedId){let o=this.pageCountersById[s.transformedId];if(o){let a=o[s.name];a&&(n.textContent=s.format(a[a.length-1]))}}}}}getPageCountersForPage(e,t){let i=Object.keys(e.elementsById);for(let n of i){let r=this.pageCountersById[n];if(r)return r}return t||null}updatePageCounterNodesInPages(e,t){var i;for(let n=0;n<e.length;n++){let r=e[n];if(!(r!=null&&r.container))continue;let s=this.getPageCountersForPage(r,t?.[n]);if(!s)continue;let o=r.container.querySelectorAll(`[${Ln}]`);for(let a of o){let h=a.getAttribute(Ln),l=this.pageCounterExprs.find(f=>f.expr.key===h);if(!l)continue;let u=(i=l.expr)==null?void 0:i.str,d=u?.replace(/^page-counters?-/,""),p=s[d];p&&(a.textContent=l.format(p))}}}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 Ie){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(`[${$t}="${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(On,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(no,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?io:Ln,e.key),s}else return null}fixPageCounterInRunningElement(e){let t=e.querySelectorAll(`[${Ln}]`);for(let r of t){let s=r.getAttribute(Ln),o=this.pageCounterExprs.find(u=>u.expr.key===s),a=(o?.expr).str,h=a?.replace(/^page-counters?-/,""),l=this.currentPageCounters[h];l&&(r.textContent=o.format(l))}let i=e.querySelectorAll(`[${On}]`);for(let r of i)r.setAttribute($l,!0);let n=e.querySelectorAll(`[${no}]`);for(let r of n)r.setAttribute(Wl,!0)}finishLastPage(e){var t;let i=e.root.querySelectorAll(`[${io}]`),n=e.contentContainer.childElementCount;for(let o of i){let a=o.getAttribute(io),h=this.pagesCounterExprs.findIndex(l=>l.expr.key===a);h>=0,o.textContent=this.pagesCounterExprs[h].format([n])}let r=e.root.querySelectorAll(`[${$l}]`);for(let o of r){let a=o.getAttribute(On),h=this.targetCounterExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageCountersById[h.transformedId];if(l){let u=l[h.name];u&&(o.textContent=h.format(u[u.length-1]))}}}let s=e.root.querySelectorAll(`[${Wl}]`);for(let o of s){let a=o.getAttribute(no),h=this.targetTextExprs.find(l=>l.expr.key===a);if(h&&h.transformedId){let l=this.pageTextById[h.transformedId];l&&(o.textContent=(t=l[h.pseudoElement])!=null?t:"")}}}createLayoutConstraint(e){return new hg(this,e)}},io="data-vivliostyle-pages-counter",Ln="data-vivliostyle-page-counter",On="data-vivliostyle-target-counter",no="data-vivliostyle-target-text",$l="data-vivliostyle-target-counter-in-running",Wl="data-vivliostyle-target-text-in-running",hg=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 ug(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 ki(e){return e.replace(/\\([0-9a-fA-F]{1,6}(\r\n|[ \n\r\t\f])?|[^0-9a-fA-F\n\r])/g,ug)}var cg=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 Xe(e,t){let i=Array(128),n;for(n=0;n<128;n++)i[n]=e;for(i[NaN]=e==35?35:72,n=0;n<t.length;n+=2)i[t[n]]=t[n+1];return i}var Yt=[72,72,72,72,72,72,72,72,72,1,1,72,1,1,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,72,1,4,34,6,7,8,9,33,10,11,12,13,14,15,16,17,2,2,2,2,2,2,2,2,2,2,18,19,20,21,22,23,24,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,25,29,26,30,3,72,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,27,31,28,32,72];Yt[NaN]=80;var Vt=[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];Vt[NaN]=43;var dg=[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];Vt[NaN]=43;var Yu=[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];Yu[NaN]=35;var Zu=[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];Zu[NaN]=45;var To=[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];To[NaN]=37;var Io=[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];Io[NaN]=38;var Ei=Xe(35,[61,36]),pg=Xe(35,[58,77]),fg=Xe(35,[61,36,124,50]),gg=Xe(35,[38,51]),mg=Xe(35,[42,54]),wg=Xe(39,[42,55]),yg=Xe(54,[42,55,47,56]),bg=Xe(62,[62,82]),vg=Xe(35,[61,36,33,70]),xg=Xe(62,[45,71]),Sg=Xe(63,[45,81]),ro=Xe(76,[10,72,13,72]),Cg=Xe(39,[39,46,10,72,13,72,92,48]),kg=Xe(39,[34,46,10,72,13,72,92,49]),Eg=Xe(39,[39,47,10,74,13,74,92,48]),Pg=Xe(39,[34,47,10,74,13,74,92,49]),Gl=Xe(64,[9,39,32,39,34,66,39,65,41,72,10,39,13,39]),Ng=Xe(39,[41,67,9,79,10,79,13,79,32,79,92,75,40,72,91,72,93,72,123,72,125,72,NaN,67]),Tg=Xe(39,[39,68,10,74,13,74,92,75,NaN,67]),Ig=Xe(39,[34,68,10,74,13,74,92,75,NaN,67]),Ag=Xe(72,[9,39,10,39,13,39,32,39,41,69]),Rg=15,Xt=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=Rg,this.buffer=Array(this.indexMask+1);for(let i=0;i<=this.indexMask;i++)this.buffer[i]=new cg}token(){return this.tail==this.curr&&this.fillBuffer(),this.buffer[this.curr]}nthToken(e){return(this.tail-this.curr&this.indexMask)<=e&&this.fillBuffer(),this.buffer[this.curr+e&this.indexMask]}consume(){this.curr=this.curr+1&this.indexMask}fillBuffer(){let e=this.tail,t=this.curr,i=this.indexMask;if(e>=t?t+=i:t--,t==e)throw new Error("F_CSSTOK_INTERNAL");let n=Yt,r=this.input,s=this.position,o=this.buffer,a=0,h=0,l="",u=0,d=!1,p=o[e],f=-9;for(;;){let g=r.charCodeAt(s);switch(n[g]||n[65]){case 72:l=r.substring(h,s),isNaN(g)?a=0:a=54,n=Yt;break;case 1:s++,d=!0;continue;case 2:h=s++,n=To;continue;case 3:a=1,h=s++,n=Vt;continue;case 4:h=s++,a=31,n=Ei;continue;case 33:a=2,h=++s,n=Cg;continue;case 34:a=2,h=++s,n=kg;continue;case 6:h=++s,a=7,n=Vt;continue;case 7:h=s++,a=32,n=Ei;continue;case 8:h=s++,a=21;break;case 9:h=s++,a=32,n=gg;continue;case 10:h=s++,a=10;break;case 11:h=s++,a=11;break;case 12:h=s++,a=36,n=Ei;continue;case 13:h=s++,a=23;break;case 14:h=s++,a=16;break;case 15:a=24,h=s++,n=Yu;continue;case 16:h=s++,n=dg;continue;case 78:h=s++,a=9,n=Vt;continue;case 17:h=s++,a=19,n=mg;continue;case 18:h=s++,a=18,n=pg;continue;case 77:s++,a=50;break;case 19:h=s++,a=17;break;case 20:h=s++,a=38,n=vg;continue;case 21:h=s++,a=39,n=Ei;continue;case 22:h=s++,a=37,n=Ei;continue;case 23:h=s++,a=22;break;case 24:h=++s,a=20,n=Vt;continue;case 25:h=s++,a=14;break;case 26:h=s++,a=15;break;case 27:h=s++,a=12;break;case 28:h=s++,a=13;break;case 29:h=s++,f=h,a=1,n=ro;continue;case 30:h=s++,a=33,n=Ei;continue;case 31:h=s++,a=34,n=fg;continue;case 32:h=s++,a=35,n=Ei;continue;case 35:break;case 36:s++,a=a+41-31;break;case 37:a=5,u=parseInt(r.substring(h,s),10);break;case 38:a=4,u=parseFloat(r.substring(h,s));break;case 39:s++;continue;case 40:a=3,u=parseFloat(r.substring(h,s)),h=s++,n=Vt;continue;case 41:a=3,u=parseFloat(r.substring(h,s)),l="%",h=s++;break;case 42:s++,n=Io;continue;case 43:if(l=ki(r.substring(h,s)),a===27&&g===63||a===1&&l.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=ro;continue;case 45:l=ki(r.substring(h,s));break;case 46:l=r.substring(h,s),s++;break;case 47:l=ki(r.substring(h,s)),s++;break;case 48:f=s,s+=2,n=Eg;continue;case 49:f=s,s+=2,n=Pg;continue;case 50:s++,a=25;break;case 51:s++,a=26;break;case 52:if(l=r.substring(h,s),a==1){if(s++,l.toLowerCase()=="url"){n=Gl;continue}a=6}break;case 53:if(l=ki(r.substring(h,s)),a==1){if(s++,l.toLowerCase()=="url"){n=Gl;continue}a=6}break;case 54:n=wg,s++;continue;case 55:n=yg,s++;continue;case 56:n=Yt,s++;continue;case 57:n=bg,s++,r[s]!==">"&&(a=1,n=Vt);continue;case 81:a=51,l=r.substring(h,++s),n=Yt;break;case 82:a=52,l=r.substring(h,++s),n=Yt;break;case 58:a=5,n=To,s++;continue;case 59:a=4,n=Io,s++;continue;case 60:a=1,n=Vt,s++;continue;case 61:a=1,n=ro,f=s++;continue;case 62:s--;break;case 63:s-=2;break;case 64:h=s++,n=Ng;continue;case 65:h=++s,n=Tg;continue;case 66:h=++s,n=Ig;continue;case 67:a=8,l=ki(r.substring(h,s)),s++;break;case 69:s++;break;case 70:n=xg,s++;continue;case 71:n=Sg,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,l=ki(r.substring(h,s)),s++,n=Ag;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,l="E_CSS_UNEXPECTED_NEWLINE",n=Yt;break;case 73:if(s-f<9&&r.substring(f+1,s+1).match(/^[0-9a-fA-F]{0,6}[ \t]$/)){s++,n=Vt;continue}l=ki(r.substring(h,s));break;case 75:f=s++;continue;case 76:s++,n=Zu;continue;default:if(n!==Yt){a=54,l="E_CSS_UNEXPECTED_STATE";break}h=s,a=0}if(p.type=a,p.precededBySpace=d,p.num=u,p.text=l,p.position=h,e++,e>=t)break;n=Yt,d=!1,p=o[e&i]}this.position=s,this.tail=e&i}},Ue=null,Ao=null;function Ro(){return Ue}function M(e){if(!Ue)throw new Error("E_TASK_NO_CONTEXT");Ue.name||(Ue.name=e);let t=Ue,i=new _s(t,t.top,e);return t.top=i,i.state=1,i}function Fg(e){return new Bg(e||new Og)}function N(e){return new Fo(e)}function bn(e,t,i){let n=M(e);n.handler=i;try{t(n)}catch(r){n.task.raise(r,n)}return n.result()}function Lg(e,t){return(Ue?Ue.getScheduler():Ao||Fg()).run(e,t)}var Og=class{currentTime(){return new Date().valueOf()}setTimeout(e,t){return setTimeout(e,t)}clearTimeout(e){clearTimeout(e)}},Bg=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 uf,Ao||(Ao=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){W.error(e)}this.inTimeSlice=!1,this.queue.length()&&this.arm()}run(e,t){let i=new Mg(this,t||"");i.top=new _s(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){W.error(o)}};try{e().then(s=>{i.result=s,r()})}catch(s){i.raise(s),r()}});let n=Ue;return Ue=i,this.schedule(i.top.suspend("bootstrap")),Ue=n,i}},Ku=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=Ue;return Ue=e,e.top.finish(this.result),Ue=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!==Ue&&this.continuation){this.continuation.cancel();let t=new Ku(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=M("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&&W.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}}},Fo=class Ju{constructor(t){this.value=t}then(t){t(this.value)}thenAsync(t){return t(this.value)}thenReturn(t){return new Ju(t)}thenFinish(t){t.finish(this.value)}isPending(){return!1}get(){return this.value}},_g=class{constructor(e){this.frame=e}then(e){this.frame.then(e)}thenAsync(e){if(this.isPending()){let t=new _s(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 Fo(e)):new Fo(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}},_s=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(!Ue)throw new Error("F_TASK_NO_CONTEXT");if(this!==Ue.top)throw new Error("F_TASK_NOT_TOP_FRAME")}result(){return new _g(this)}finish(e){this.checkEnvironment(),Ue&&!Ue.exception&&(this.res=e),this.state=2;let t=this.parent;if(Ue&&(Ue.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=M("Frame.timeSlice");return e.getScheduler().isTimeSliceOver()?(W.debug("-- time slice --"),e.suspend().schedule(!0)):e.finish(!0),e.result()}sleep(e){let t=M("Frame.sleep");return t.suspend().schedule(!0,e),t.result()}loop(e){let t=M("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=Ue;if(!t)throw new Error("E_TASK_NO_CONTEXT");return this.loop(()=>{let i;do{let n=new Dg(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 Ku(this.task);return this.task.continuation=t,Ue=null,this.task.waitTarget=e||null,t}},Dg=class extends _s{constructor(e,t){super(e,t,"loop")}continueLoop(){this.finish(!0)}breakLoop(){this.finish(!1)}},yr=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=Ro().getScheduler().run(()=>{let e=M("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){W.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}},vn=e=>{if(e.length==0)return N(!0);if(e.length==1)return e[0].get().thenReturn(!0);let t=M("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()},Qu=`
|
|
8
8
|
@media screen {
|
|
9
9
|
[data-vivliostyle-viewer-viewport] {
|
|
10
10
|
background: #aaaaaa;
|
|
@@ -45,7 +45,7 @@ var Gd=Object.create;var za=Object.defineProperty;var jd=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 Gd=Object.create;var za=Object.defineProperty;var jd=Object.getOwnPropertyDe
|
|
|
73
73
|
transform-origin: center top;
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
`,
|
|
76
|
+
`,ec=`
|
|
77
77
|
[data-vivliostyle-layout-box] {
|
|
78
78
|
position: absolute;
|
|
79
79
|
left: 0;
|
|
@@ -88,8 +88,12 @@ var Gd=Object.create;var za=Object.defineProperty;var jd=Object.getOwnPropertyDe
|
|
|
88
88
|
[data-vivliostyle-debug] [data-vivliostyle-layout-box] {
|
|
89
89
|
right: auto;
|
|
90
90
|
bottom: auto;
|
|
91
|
-
overflow: visible;
|
|
92
91
|
z-index: auto;
|
|
92
|
+
overflow: visible;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
[data-vivliostyle-layout-box] [data-vivliostyle-page-container] {
|
|
96
|
+
margin: 0 auto 0 0;
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
[data-vivliostyle-spread-container] {
|
|
@@ -191,22 +195,8 @@ var Gd=Object.create;var za=Object.defineProperty;var jd=Object.getOwnPropertyDe
|
|
|
191
195
|
[data-vivliostyle-spread-container] [data-vivliostyle-page-container]:not(:last-child) {
|
|
192
196
|
break-after: page;
|
|
193
197
|
}
|
|
194
|
-
|
|
195
|
-
/* Gecko-only hack, see https://bugzilla.mozilla.org/show_bug.cgi?id=267029#c17 */
|
|
196
|
-
@-moz-document url-prefix() {
|
|
197
|
-
[data-vivliostyle-spread-container] [data-vivliostyle-page-container]:nth-last-child(n + 2) {
|
|
198
|
-
top: -1px;
|
|
199
|
-
margin-top: 1px;
|
|
200
|
-
margin-bottom: -1px;
|
|
201
|
-
}
|
|
202
|
-
/* Workaround Gecko problem on page break */
|
|
203
|
-
[data-vivliostyle-spread-container] [data-vivliostyle-page-container] {
|
|
204
|
-
break-after: auto !important;
|
|
205
|
-
height: 100% !important;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
198
|
}
|
|
209
|
-
`,
|
|
199
|
+
`,tc=`
|
|
210
200
|
/*
|
|
211
201
|
* Copyright 2013 Google, Inc.
|
|
212
202
|
* Copyright 2015 Daishinsha Inc.
|
|
@@ -642,6 +632,7 @@ background-blend-mode = COMMA( BLEND_MODE+ );
|
|
|
642
632
|
|
|
643
633
|
/* CSS GCPM */
|
|
644
634
|
string-set = COMMA( SPACE( IDENT CONTENT_LIST )+ | none );
|
|
635
|
+
footnote-display = block | inline | compact;
|
|
645
636
|
footnote-policy = auto | line;
|
|
646
637
|
|
|
647
638
|
/* CSS Repeated Headers and Footers */
|
|
@@ -838,7 +829,7 @@ word-wrap = overflow-wrap;
|
|
|
838
829
|
[adapt,webkit]start = inline-start;
|
|
839
830
|
[adapt,webkit]end = inline-end;
|
|
840
831
|
|
|
841
|
-
`,
|
|
832
|
+
`,ic=`
|
|
842
833
|
<!DOCTYPE html>
|
|
843
834
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://www.pyroxy.com/ns/shadow">
|
|
844
835
|
<head>
|
|
@@ -861,7 +852,7 @@ word-wrap = overflow-wrap;
|
|
|
861
852
|
<s:template id="table-cell"><div data-vivliostyle-flow-root="true" class="-vivliostyle-table-cell-container"><s:content/></div></s:template>
|
|
862
853
|
|
|
863
854
|
</body>
|
|
864
|
-
</html>`,
|
|
855
|
+
</html>`,nc=`
|
|
865
856
|
@namespace "http://www.w3.org/1999/xhtml";
|
|
866
857
|
|
|
867
858
|
:root {
|
|
@@ -874,14 +865,10 @@ word-wrap = overflow-wrap;
|
|
|
874
865
|
break-before: right;
|
|
875
866
|
}
|
|
876
867
|
|
|
877
|
-
|
|
878
|
-
display: block;
|
|
868
|
+
@footnote {
|
|
879
869
|
margin-block-start: 0.5em;
|
|
880
|
-
margin-block-end: 0.5em;
|
|
881
870
|
}
|
|
882
|
-
|
|
883
|
-
@-adapt-footnote-area ::before {
|
|
884
|
-
display: block;
|
|
871
|
+
@footnote ::before {
|
|
885
872
|
border-block-start-width: 1px;
|
|
886
873
|
border-block-start-style: solid;
|
|
887
874
|
border-block-start-color: black;
|
|
@@ -988,7 +975,7 @@ word-wrap = overflow-wrap;
|
|
|
988
975
|
margin: 10%;
|
|
989
976
|
}
|
|
990
977
|
}
|
|
991
|
-
`,
|
|
978
|
+
`,rc=String.raw`
|
|
992
979
|
@namespace "http://www.w3.org/1999/xhtml";
|
|
993
980
|
@namespace m "http://www.w3.org/1998/Math/MathML";
|
|
994
981
|
@namespace epub "http://www.idpf.org/2007/ops";
|
|
@@ -1185,6 +1172,10 @@ sub {
|
|
|
1185
1172
|
sup {
|
|
1186
1173
|
vertical-align: super;
|
|
1187
1174
|
}
|
|
1175
|
+
sub,
|
|
1176
|
+
sup {
|
|
1177
|
+
line-height: 1;
|
|
1178
|
+
}
|
|
1188
1179
|
table {
|
|
1189
1180
|
box-sizing: border-box;
|
|
1190
1181
|
border-spacing: 2px;
|
|
@@ -1330,34 +1321,66 @@ m|math[display="block"] {
|
|
|
1330
1321
|
display: block math;
|
|
1331
1322
|
}
|
|
1332
1323
|
|
|
1333
|
-
|
|
1324
|
+
/* CSS GCPM footnotes */
|
|
1325
|
+
::footnote-marker {
|
|
1326
|
+
content: counter(footnote) ". ";
|
|
1327
|
+
list-style-position: inside;
|
|
1328
|
+
}
|
|
1329
|
+
::footnote-call {
|
|
1330
|
+
content: counter(footnote);
|
|
1331
|
+
font-size: 0.75em;
|
|
1332
|
+
vertical-align: super;
|
|
1333
|
+
line-height: 0;
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
/* EPUB/DPUB footnotes */
|
|
1334
1337
|
|
|
1335
1338
|
a[epub|type="noteref"],
|
|
1336
|
-
a[epub
|
|
1339
|
+
a[epub\:type="noteref"],
|
|
1340
|
+
a[role="doc-noteref"] {
|
|
1337
1341
|
font-size: 0.75em;
|
|
1338
1342
|
vertical-align: super;
|
|
1339
|
-
line-height: 0
|
|
1343
|
+
line-height: 0;
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
sup > a[epub|type="noteref"],
|
|
1347
|
+
a[epub|type="noteref"] > sup,
|
|
1348
|
+
sup > a[epub\:type="noteref"],
|
|
1349
|
+
a[epub\:type="noteref"] > sup,
|
|
1350
|
+
sup > a[role="doc-noteref"],
|
|
1351
|
+
a[role="doc-noteref"] > sup {
|
|
1352
|
+
font-size: unset;
|
|
1353
|
+
vertical-align: unset;
|
|
1354
|
+
line-height: unset;
|
|
1340
1355
|
}
|
|
1341
1356
|
|
|
1342
1357
|
a[epub|type="noteref"]:href-epub-type(footnote, aside),
|
|
1343
|
-
a[epub
|
|
1358
|
+
a[epub\:type="noteref"]:href-epub-type(footnote, aside),
|
|
1359
|
+
a[role="doc-noteref"]:href-role-type(doc-footnote, aside) {
|
|
1344
1360
|
-adapt-template: footnote;
|
|
1345
1361
|
text-decoration: none;
|
|
1346
1362
|
}
|
|
1347
1363
|
|
|
1348
|
-
aside[epub|type="footnote"],
|
|
1349
|
-
aside[epub
|
|
1364
|
+
aside[epub|type="footnote"][data-vivliostyle-footnote-referenced],
|
|
1365
|
+
aside[epub\:type="footnote"][data-vivliostyle-footnote-referenced],
|
|
1366
|
+
aside[role="doc-footnote"][data-vivliostyle-footnote-referenced] {
|
|
1350
1367
|
display: none;
|
|
1351
1368
|
}
|
|
1352
1369
|
|
|
1353
1370
|
aside[epub|type="footnote"]:footnote-content,
|
|
1354
|
-
aside[epub
|
|
1371
|
+
aside[epub\:type="footnote"]:footnote-content,
|
|
1372
|
+
aside[role="doc-footnote"]:footnote-content {
|
|
1355
1373
|
display: block;
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1374
|
+
font-size: 0.9em;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
aside[epub|type="footnote"]:footnote-content a[epub|type="backlink"],
|
|
1378
|
+
aside[epub\:type="footnote"]:footnote-content a[epub\:type="backlink"],
|
|
1379
|
+
aside[role="doc-footnote"]:footnote-content a[role="doc-backlink"] {
|
|
1380
|
+
text-decoration: none;
|
|
1359
1381
|
}
|
|
1360
1382
|
|
|
1383
|
+
/* EPUB-specific */
|
|
1361
1384
|
epub|trigger {
|
|
1362
1385
|
display: none;
|
|
1363
1386
|
}
|
|
@@ -1385,7 +1408,7 @@ epub|case[required-namespace::supported] ~ epub|case {
|
|
|
1385
1408
|
epub|case[required-namespace::supported] ~ epub|default {
|
|
1386
1409
|
display: none;
|
|
1387
1410
|
}
|
|
1388
|
-
`,
|
|
1411
|
+
`,sc=`
|
|
1389
1412
|
@namespace "http://www.w3.org/1999/xhtml";
|
|
1390
1413
|
|
|
1391
1414
|
*:not([data-vivliostyle-role=doc-toc],
|
|
@@ -1415,7 +1438,7 @@ epub|case[required-namespace::supported] ~ epub|default {
|
|
|
1415
1438
|
[data-vivliostyle-role=doc-toc]:is(ol,ul) {
|
|
1416
1439
|
-adapt-behavior: toc-container;
|
|
1417
1440
|
}
|
|
1418
|
-
`,
|
|
1441
|
+
`,oc=`
|
|
1419
1442
|
[data-viv-margin-discard~="block-start"] {
|
|
1420
1443
|
margin-block-start: 0 !important;
|
|
1421
1444
|
}
|
|
@@ -1536,29 +1559,60 @@ span[data-viv-leader] {
|
|
|
1536
1559
|
}
|
|
1537
1560
|
|
|
1538
1561
|
/* ::marker */
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1562
|
+
[style*="--viv-marker-content"]::marker {
|
|
1563
|
+
content: var(--viv-marker-content);
|
|
1564
|
+
unicode-bidi: isolate;
|
|
1565
|
+
font-variant-numeric: tabular-nums;
|
|
1566
|
+
white-space: pre;
|
|
1567
|
+
text-transform: none;
|
|
1543
1568
|
}
|
|
1544
|
-
|
|
1569
|
+
/* ::footnote-marker inherits --viv-marker-content from the footnote element */
|
|
1570
|
+
.-vivliostyle-footnote-content::marker {
|
|
1571
|
+
content: var(--viv-marker-content);
|
|
1545
1572
|
unicode-bidi: isolate;
|
|
1546
1573
|
font-variant-numeric: tabular-nums;
|
|
1547
1574
|
white-space: pre;
|
|
1548
1575
|
text-transform: none;
|
|
1549
1576
|
}
|
|
1550
|
-
[
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
font-weight: normal;
|
|
1577
|
+
[style*="--viv-footnote-inline-separator"]::after {
|
|
1578
|
+
content: var(--viv-footnote-inline-separator);
|
|
1579
|
+
white-space: normal;
|
|
1554
1580
|
}
|
|
1555
|
-
[
|
|
1556
|
-
|
|
1557
|
-
text-indent: 0;
|
|
1581
|
+
[style*="--viv-footnote-white-space"] {
|
|
1582
|
+
white-space: var(--viv-footnote-white-space);
|
|
1558
1583
|
}
|
|
1559
|
-
[
|
|
1560
|
-
|
|
1561
|
-
|
|
1584
|
+
[style*="--viv-marker-color"]::marker {
|
|
1585
|
+
color: var(--viv-marker-color);
|
|
1586
|
+
}
|
|
1587
|
+
[style*="--viv-marker-font-size"]::marker {
|
|
1588
|
+
font-size: var(--viv-marker-font-size);
|
|
1589
|
+
}
|
|
1590
|
+
[style*="--viv-marker-font-family"]::marker {
|
|
1591
|
+
font-family: var(--viv-marker-font-family);
|
|
1592
|
+
}
|
|
1593
|
+
[style*="--viv-marker-font-style"]::marker {
|
|
1594
|
+
font-style: var(--viv-marker-font-style);
|
|
1595
|
+
}
|
|
1596
|
+
[style*="--viv-marker-font-weight"]::marker {
|
|
1597
|
+
font-weight: var(--viv-marker-font-weight);
|
|
1598
|
+
}
|
|
1599
|
+
[style*="--viv-marker-font-variant"]::marker {
|
|
1600
|
+
font-variant: var(--viv-marker-font-variant);
|
|
1601
|
+
}
|
|
1602
|
+
[style*="--viv-marker-unicode-bidi"]::marker {
|
|
1603
|
+
unicode-bidi: var(--viv-marker-unicode-bidi);
|
|
1604
|
+
}
|
|
1605
|
+
[style*="--viv-marker-direction"]::marker {
|
|
1606
|
+
direction: var(--viv-marker-direction);
|
|
1607
|
+
}
|
|
1608
|
+
[style*="--viv-marker-white-space"]::marker {
|
|
1609
|
+
white-space: var(--viv-marker-white-space);
|
|
1610
|
+
}
|
|
1611
|
+
[style*="--viv-marker-text-transform"]::marker {
|
|
1612
|
+
text-transform: var(--viv-marker-text-transform);
|
|
1613
|
+
}
|
|
1614
|
+
[style*="--viv-marker-text-combine-upright"]::marker {
|
|
1615
|
+
text-combine-upright: var(--viv-marker-text-combine-upright);
|
|
1562
1616
|
}
|
|
1563
1617
|
|
|
1564
1618
|
/* initial-letter */
|
|
@@ -1566,7 +1620,7 @@ span[data-viv-leader] {
|
|
|
1566
1620
|
-webkit-initial-letter: var(--viv-initialLetter);
|
|
1567
1621
|
initial-letter: var(--viv-initialLetter);
|
|
1568
1622
|
}
|
|
1569
|
-
`,
|
|
1623
|
+
`,ac=String.raw`
|
|
1570
1624
|
@counter-style decimal-leading-zero {
|
|
1571
1625
|
system: extends decimal;
|
|
1572
1626
|
pad: 2 '0';
|
|
@@ -1790,12 +1844,12 @@ span[data-viv-leader] {
|
|
|
1790
1844
|
@counter-style upper-russian {
|
|
1791
1845
|
system: alphabetic;
|
|
1792
1846
|
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 er(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=xu([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 xu(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function Wf(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 Gf(e){return URL.createObjectURL(e)}var ta=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(gu)}`),er(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 jf(e,t){let i=e.responseText;return N(i?jo(i):null)}function Xf(){return new ta(jf,"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 pl=0,qf=16777216,Su=33554432,Cu=50331648,ku=67108864,Yf=83886080,Kf=100663296,ia=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 pl;case"User":return Kf;default:return Yf}}getBaseSpecificity(){switch(this.flavor){case"UA":return pl;case"User":return qf;default:return Su}}},Zf=class extends ia{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)}},fl=class extends ia{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 fl{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new fl(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=[],Rs=[],me=[],Ne=[],vt=[],rt=[],Ie=[],Ue=[],ge=[],Ge=[],et=[],Ve=[],Te=[],Pi=55,Ti=56,is=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,Rs[1]=46,Rs[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 Op(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(),Mr(h,l),a),e=0;continue}}if(o==10){s.isMediaName()&&(s=new el(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==-is)s=new Lp(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 Yo(n.getScope(),r,s);break;case Pi:s=new Bp(n.getScope(),r,s);break;case Ti:s=new _p(n.getScope(),r,s);break;case 25:s=new Ko(n.getScope(),r,s);break;case 38:s=new Mp(n.getScope(),r,s);break;case 37:s=new Dp(n.getScope(),r,s);break;case 48:s=new zp(n.getScope(),r,s);break;case 47:s=new Vr(n.getScope(),r,s);break;case 39:case 49:s=new Zo(n.getScope(),r,s);break;case 41:s=new Vp(n.getScope(),r,s);break;case 23:s=new Hh(n.getScope(),r,s);break;case 24:s=new $h(n.getScope(),r,s);break;case 36:s=new Jo(n.getScope(),r,s);break;case 19:s=new Wh(n.getScope(),r,s);break;case 21:s=new Gh(n.getScope(),r,s);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),s=new $p(n.getScope(),i.pop(),r,s);break;case 10:if(r.isMediaName())s=new el(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 Wp(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 eu(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 tu(h.text)),a.consume();continue;case 22:this.valStackReduce(",",h),l.push(","),a.consume();continue;case 23:l.push(Ks),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?Rs: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(),Mr(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 Qa(o.getScope(),!0,u.text))):(h.text.toLowerCase()=="only"&&(a.consume(),h=u),l.push(new Qa(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(-is),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 Yh(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]!==-is?(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]!==-is?(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}},Eu=class extends ia{constructor(e){super(null),this.scope=e}error(e,t){H.warn(e,t.toString())}getScope(){return this.scope}};function Jf(e,t,i,n,s){let r=B("parseStylesheet"),o=new jn(Ae,e,t,i),a=null;return s&&(a=eg(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 Nu(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 na(e,t,i,n,s){return ji("parseStylesheetFromText",r=>{let o=new At(e,t);Jf(o,t,i,n,s).thenFinish(r)},(r,o)=>{H.warn(o,`Failed to parse stylesheet text: ${e}`),r.finish(!1)})}function Nu(e,t,i,n){return ji("parseStylesheetFromURL",s=>{er(e).then(r=>{r.responseText?na(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 Eu(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function Qf(e,t,i){new jn(Rs,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function eg(e,t,i){let n=new jn(Ue,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var tg={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function ig(e){return!!tg[e]}function ng(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 ig(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 Pu(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 Tu(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 Iu={"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"}]}},sg=Pu(Iu,!0);function Au(e,t,i){return Tu(e,t,i||null,sg)}var rg=Pu(Iu,!1);function Ru(e,t,i){return Tu(e,t,i||null,rg)}var og={"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 ag(e,t){let i=og[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 sa(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 Fu(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function Lu(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function ft(e,t){let i=Fu(e);i.includes(t)||(i.push(t),Lu(e,i))}function lg(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function hg(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Cr(e,t){let i=lg(e);i.includes(t)||(i.push(t),hg(e,i))}function ug(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 qr={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function tt(e){return!!qr[e]}var cg={left:!0,right:!0,recto:!0,verso:!0};function Fn(e){return!!cg[e]}var dg={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Fs(e){return!!dg[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:Fs(t)?t:Fs(e)?e:t}}else return e;else return t}function gl(e){return tt(e)?e:"auto"}Ct("SIMPLE_PROPERTY",ug);var xn=ap(hp());function pg(e,t){return(0,xn.default)(e,t,0)}function ml(e){return e.reduce((t,i)=>i[0]===xn.default.DELETE?t:t+i[1],"")}function fg(e,t){return Bu(e,t,1)}function gg(e,t){return Bu(e,t,-1)}function Bu(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 Yr;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Yr||(Yr={}));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 Ls;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Ls||(Ls={}));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 mg={transform:!0,"transform-origin":!0},wg={top:!0,bottom:!0,left:!0,right:!0},ra=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},bg={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 yg(e,t){let i=bg[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Kr=class cn extends Xo{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=yg(a,o.action);if(h)for(let u=0;u<l.length;u++)l[u].addEventListener(o.event,h,!1)}}}};c(Kr,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),c(Kr,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Ou=Kr,ot=Wt.Whitespace;function _u(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 vg=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,c(this,"forcedBreakOffsets",[]),c(this,"formattingContext",null)}},xg=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 Sg(e,t){return e.top-t.top}function Cg(e,t){return t.right-e.right}function Mu(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&&Jr(e.shadowContext,t.shadowContext)&&Jr(e.nodeShadow,t.nodeShadow)&&Mu(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(!Mu(e.steps[i],t.steps[i]))return!1;return!0}function kg(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 Bs(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 Os(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?Os(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var yt=Wt.ShadowType,Zr=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&&Jr(this.parentShadow,e.parentShadow):!1}};function Jr(e,t){return e===t||!!e&&!!t&&e.equals(t)}var Eg=class{constructor(e,t){this.outer=e,this.count=t}},dn=class zu{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 zu(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?gg(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 Du{constructor(t){this.primary=t,c(this,"floats",null)}clone(){let t=new Du(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}},Ng=class Vu{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new Vu(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Pg=class Uu{constructor(){c(this,"positions",[]),c(this,"startBreakType",null),c(this,"breakAfter",null)}clone(){let t=new Uu,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}},Tg=class Hu{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 Hu;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}},$u=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):ea(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 au(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)}},_s=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 Ig(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 wl(e,t,i,n){let s=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=Ru(e,s,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let r=Au(e,s,i),o=ag(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 Wu=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}},Ag=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}},Gu=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}},bl=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 Ag;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 Ru(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Au(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=su(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?As(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(Qp,A)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(ef,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=sa(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}`)}},Rg=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 Wu(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 Gu(r.floatReference,t,i,e,n,s)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){}forbid(e,t){}};Xi.register(new Rg);var Fg=Gu,Qr=class ju extends Wu{constructor(t,i,n,s,r){super(t,i,"block-end",null,n,r),this.footnotePolicy=s}isAllowedToPrecede(t){return!(t instanceof ju)}},yl=class extends Fg{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof Qr?!0:this.getOrder()<e.getOrder()}},Lg=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!ri(t,this.footnote.nodePosition)}},Bg=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof Qr}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 Qr(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 yl(r.floatReference,e,n,s)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof yl);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 Lg(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Xi.register(new Bg);var Og="data-vivliostyle-flow-root";function _g(e){return e.getAttribute(Og)==="true"}function vl(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 oa(e){return e===y.absolute||e===y.fixed}function eo(e){return e instanceof en&&e.name==="running"}function Xu(e,t,i,n){return e===y.none||(oa(t)?(i=y.none,e=vl(e)):(i&&i!==y.none&&!K(i)||n)&&(e=vl(e))),{display:e,position:t,float:i}}function qu(e,t,i,n){return Xu(e,t,i,n).display===y.block}function tr(e){return e instanceof ae||e instanceof Q||typeof e=="string"}function Lt(e){if(!tr(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 tr(e)?e.toString().includes("list-item"):!1}function Mg(e){if(!tr(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 Yu(e){if(!tr(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 zg(e,t,i,n,s,r,o){return s=s||r||y.horizontal_tb,!!o||!!i&&i!==y.none&&!K(i)||oa(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 Dg(e){return e===y.relative||e===y.absolute||e===y.fixed}var Ft=1e5;function aa(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 Ku(e){let t=e.element.style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function Zu(e){return e.element.style.columnCount==="1"}function Vg(e){e.element.setAttribute("data-vivliostyle-column","true")}function Ug(e){return e.element.hasAttribute("data-vivliostyle-column")}function Ms(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Ft)}function to(e,t){let i=Ms(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 Ju(e,t){for(let i=0;i<e.length;i++)to(e[i],t)}function Nt(e,t,i){var n;let s=e.getElementClientRect(t),r=to(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=to(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 Hg(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 la(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 $g(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=la(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 Ju(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 io(e,t,i){let n=Zu(t);n&&Ku(t);let s=t.clientLayout.getElementClientRect(e);n&&aa(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 Qu(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 ha(e){return!!e.getAttribute(qi)}function Bi(e){var t;if(e?.nodeType!==1)return!1;let i=e;if(ha(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&&ha(t)}function Wg(e){return e!=="inline"&&(Lt(e)||Yu(e))}function xl(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 ua=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 ua{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(Fs(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;Qu(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)}},ca=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){}},da=new _i,Gg=Yr.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&&qu(i,n,s,r)?new ca(o?o.formattingContext:null):null});Ct("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof ca?da:null);var pa=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)}},jg=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){}},no=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 jg{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)))}},so=[];function Xg(){so=[]}function ec(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var qg=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},Yg=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},tc=class cs{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let s=cs.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){cs.fragmentIndices={}}matches(){let t=cs.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&ec(t.fragmentIndex,this.a,this.b)}};c(tc,"fragmentIndices",{});var ir=tc,ns=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new ir(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new Yg(e)}static buildAnyMatcher(e){return new qg(e)}},ic={"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},Kg=["image-resolution","orphans","widows"];function Zg(){return It("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(Kg))}var Jg={"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},ro=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],Qg=["max-%","min-%","%"],Sl=(()=>{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<ro.length;i++)for(let n=0;n<e.length;n++){let s=ro[i].replace("%",e[n]);t[s]=!0}return t})();function nn(e,t){let i={};for(let n of ro)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 Qg)for(let s in t){let r=n.replace("%",s),o=n.replace("%",t[s]);i[r]=o,i[o]=r}return i}var nc=nn({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),sc=nn({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),em=nn({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),tm=nn({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),im=nn({inside:"right",outside:"left"},{}),nm=nn({inside:"left",outside:"right"},{}),_=class oo{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 oo(i,this.priority)}increaseSpecificity(t){return t==0?this:new oo(this.value,this.priority+t)}evaluate(t,i,n,s){return i&&$t(i)?this.value:Ds(t,this.value,i,n,s)}isEnabled(t){return!0}},ao=class lo 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 lo(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new lo(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){H.warn(i)}return!1}};function ho(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 rc={"region-id":!0,"fragment-selector-id":!0};function sm(e){return!!rc[e]}function uo(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Hi(e){return e.charAt(0)!=="_"&&!rc[e]}function Cn(e){return!!ic[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 oc=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function ac(e,t){return e[t]}function lc(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function zs(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=oc(t);t={},h.push({styles:t,matcher:o})}for(let h in i)if(!uo(h))if(sm(h)){let u=ac(i,h),d=lc(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 rm(e,t){let i={};for(let n=0;n<t.length;n++)zs(e,i,t[n],0,null,null,null);return i}function fa(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 om=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(!Ap(t.unit))throw new Error("Unexpected state");return t.num*Pt[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?co(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?ga(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Ds(this.context,e,this.propName).visit(this):e}};function ga(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 co(e,t,i){e=ga(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 am([this,e])}clone(){return this}},ss=class extends sn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},am=class hc 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 hc([].concat(this.list))}},ma=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){zs(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}},lm=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}},hm=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}},Cl=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}},um=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}},cm=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)}}}},dm=class extends ve{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function nr(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 kl=class extends ve{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){nr(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},pm=class extends ve{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){nr(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}},fm=class extends ve{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){nr(e.currentElement,this.ns,this.name,(t,i,n)=>!!Jg[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){nr(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)}},gm=class extends ve{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},El=class extends ve{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},mm=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 ec(e,this.a,this.b)}},wm=class extends xi{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},po=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}},fo=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}},go=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}},bm=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}},ym=class extends ve{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},vm=class extends ve{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},xm=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}},uc=class cc extends sn{constructor(){super(),c(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new cc;return t.applied=this.applied,t}},wa=class extends ve{constructor(e){super(),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new uc;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}},Sm=class extends wa{positive(){return!1}},Cm=class extends wa{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}},dc=class extends xi{constructor(e,t,i){super(e,t),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new uc;for(let n of i)this.firstActions.push(fa(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}},km=class extends dc{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}},sr=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)}},Em=class pc extends sr{constructor(t,i,n){super(t,i,n)}fresh(t){return new pc(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}},Nm=class fc extends sr{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):i==1&&this.decrement(t),!1}pop(t,i){return i==0?(this.decrement(t),!0):(i==1&&this.increment(t),!1)}},Pm=class gc extends sr{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new gc(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)}},Tm=class mc extends sr{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&&(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}},Im=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}},Am=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}},Rm=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}},Fm=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 mo=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(Is);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 kr(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 Lm=(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=la(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(Mg(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+kr(R,i.clientLayout,b),0);if(w!=="after"){let k=kr(at,i.clientLayout,b),R=kr(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",Lm);var ba=1/1048576;function Ci(e,t){for(let i in e)t[i]=e[i].clone()}var Bm=class wc{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 wc;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 Om(this,t,i,n,s,r)}nextOrder(){return this.order+=ba}},Om=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=ns.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]:ns.buildAnyMatcher([].concat(s)):null}).filter(n=>n);return i.length<=0?t:t===null?i.length===1?i[0]:ns.buildAllMatcher(i):ns.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=Er,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 mo(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 mo(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=Er;let h=t.getAttributeNS("http://www.idpf.org/2007/ops","type");h?this.currentEpubTypes=h.split(/\s+/):this.currentEpubTypes=Er;let u=Or(t);u&&(this.stack[this.stack.length-1].push(new Am(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 Rm(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 _m){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 Im(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 Fm(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 jm(e,t,i),l=32,h={};for(let u in o)if(uo(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,ho(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,ho(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 Nc(t);for(let n in e)if(uo(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()}},Er=[],_m=["before","transclusion-before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","transclusion-after","after"],wo=null;function Mm(e){wo=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:wo?wo.clone():new Bm,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 um(e,t.toLowerCase())):t?this.chain.push(new Cl(t.toLowerCase())):this.chain.push(new dm(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 lm(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new ym);break;case"disabled":this.chain.push(new vm);break;case"checked":this.chain.push(new xm);break;case"root":case"scope":this.chain.push(new mm);break;case"link":this.chain.push(new Cl("a")),this.chain.push(new kl("","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 cm(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 gm(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=zm[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 El);break;case"last-child":this.chain.push(new fo(0,1));break;case"first-of-type":this.chain.push(new po(0,1));break;case"last-of-type":this.chain.push(new go(0,1));break;case"only-child":this.chain.push(new El),this.chain.push(new fo(0,1));break;case"only-of-type":this.chain.push(new po(0,1)),this.chain.push(new go(0,1));break;case"empty":this.chain.push(new bm);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 hm(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let s;switch(i){case 0:s=new kl(e,t);break;case 39:s=new pm(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 fm(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${rs++}`;this.processChain(new ss(new Em(e,this.viewConditionId,null))),this.chain=[new Ye(e)],this.viewConditionId=null}childSelector(){let e=`c${rs++}`;this.processChain(new ss(new Nm(e,this.viewConditionId,null))),this.chain=[new Ye(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${rs++}`;this.processChain(new ss(new Pm(e,this.viewConditionId,null))),this.chain=[new Ye(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${rs++}`;this.processChain(new ss(new Tm(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 ma(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new ao(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===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 ao(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 Dm(this);break;case"where":i=new Vm(this);break;case"has":i=new Um(this);break;case"nth-child":t&&t.length>=2&&(i=new yc(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new Hm(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},zm={"nth-child":wm,"nth-of-type":po,"nth-last-child":fo,"nth-last-of-type":go},rs=0,Yi=class bc 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 Cm(this.selectorTexts):this.positive()?new wa(this.chains):new Sm(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 bc;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}},Dm=class extends Yi{positive(){return!1}forgiving(){return!1}},Vm=class extends Yi{increasingSpecificity(){return!1}},Um=class extends Yi{relational(){return!0}},yc=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 dc(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ye("")),this.owner.popHandler()}forgiving(){return!0}},Hm=class extends yc{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new km(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Ye("")),this.owner.popHandler()}},$m=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+=ba;let s=this.condition?new ao(t,n,this.condition):new _(t,n);Gt(this.elementStyle,e,s)}},Wm=class extends Eu{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?ku:Cu;n+=this.order,this.order+=ba;let s=new _(t,n);Gt(this.elementStyle,e,s)}};function vc(e,t){let i=oc(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function bo(e,t,i){vc(i,n=>{En(e,n,t)})}function Gm(e,t,i,n){let s=new Wm(e,t),r=new At(n,s);try{Qf(r,s,i)}catch(o){H.warn(o,"Style attribute parse error:")}return s.elementStyle}function xc(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 Sc(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 Cc(e,t,i,n,s){let r={};for(let o in e)Hi(o)&&(r[o]=_e(e,o));return bo(r,t,e),kc(e,i,n,(o,a)=>{En(r,a,t),bo(r,t,a)}),r}function kc(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]=ho(i,r,s)}}var Ec=(e,t,i,n,s,r)=>{var o,a;let l=i?n?em:nc:n?tm:sc,h=s?im:nm;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=Sl[p]?p:Sl[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)}},jm=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)))}},Nc=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&&(Mh(e.unit)||Fp(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 Ds(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:ng(e,t.expr,i);if(t instanceof I||t instanceof en||t instanceof Q||t instanceof Ke)return t.visit(new Nc(e,!0,n,s))}catch(r){return H.warn(r),j}return t}var Nl={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function Pl(e){let t=e instanceof Ze?e:typeof e=="string"?F(e):y.none;if(t===y.none)return Nl;let i=t instanceof Q?t.values:[t],n=Object.create(Nl);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 Tl(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var Xm={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},Il={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},Al={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function Rl(e){let t=e instanceof Ze?e:typeof e=="string"?F(e):y.normal;if(t===y.normal)return Il;if(t===y.auto)return Al;let i=t instanceof Q?t.values:[t],n=Object.create(Il);for(let s of i)if(s instanceof ae)switch(s.name){case"trim-both":case"trim-auto":return Al;case"space-all":return Xm;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 Nr={ideographAlpha:!1,ideographNumeric:!1},qm={ideographAlpha:!0,ideographNumeric:!0};function Fl(e){let t=e instanceof Ze?e:typeof e=="string"?F(e):y.normal;if(t===y.normal||t===y.auto)return qm;if(t===y.none)return Nr;let i=t instanceof Q?t.values:[t],n=Object.create(Nr);for(let s of i)if(s instanceof ae)switch(s.name){case"no-autospace":return Nr;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function Ll(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function Bl(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 Ym=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=Bl(s);let o=Fl(t),a=Rl(i),l=Pl(n);if(Tl(l)&&Ll(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=Bl((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=Fl(b.inheritedProps["text-autospace"]),D=Rl(b.inheritedProps["text-spacing-trim"]),te=Pl(b.inheritedProps["hanging-punctuation"]);if(Tl(te)&&Ll(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=Ms(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=Ms(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)}},ya=new Ym;ya.registerHooks();function Km(e){ya.preprocessForTextSpacing(e)}function Zm(e,t,i,n,s,r){ya.processGeneratedContent(e,t,i,n,s,r)}var ds=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Jm=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],va="data-adapt-pseudo";function Mi(e){return e.getAttribute(va)||""}function yo(e,t){e.setAttribute(va,t)}var Ol=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 _s(e.classList.contains("_viv-marker-outside")&&e.firstElementChild||e,this.context,s,this.exprContentListener)),Km(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"]}},v0=Ls.isInstanceOfAfterIfContinuesLayoutConstraint,Qm=ir.registerFragmentIndex,x0=ir.clearFragmentIndices,ew=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new xa(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=ds.createElementNS("http://www.w3.org/1999/xhtml","div");yo(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 Zr(this.sourceNode,e,null,null,null,Wt.ShadowType.ROOTED,this.styler)}},tw=class Pc{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 iw(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Pc?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},iw=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 Tc(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=sw(e,t,n);return t.fragmentLayoutConstraints.push(new tw(e,i,s)),N(e)})}function Ic(e,t){return e.thenAsync(i=>Tc(i,t))}function nw(e,t){let i=B("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let s=Tc(n,t);return n=n.parent,s.thenReturn(!0)}else return N(!1)}).then(()=>{i.finish(!0)}),i.result()}function sw(e,t,i){let n=e.viewNode;n.appendChild(i);let s=io(i,t,e.vertical);return n.removeChild(i),s}var rw=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},ps=class extends ua{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]}},Vs=class Ac extends $u{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===Ac&&Vg(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=Os(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?fg(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(Is),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(Is);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(Ms(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 Ic(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 mr(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 mr(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 mr(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=wl(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=As(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}tf(p,this.bands,f,s),this.vertical&&(l=su(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=As(p)),nf(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 lw(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 bl(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=sa(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=Bs(t,0),l=this.setFloatAnchorViewNode(t),h=n.findPageFloatFragment(o,i),u=new bl(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=xl(l);if(u){if(((r=this.breakPositions)==null?void 0:r[0])instanceof ps&&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,Us.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:ha(p)?u=!l:!p.firstChild||gi[p.localName]||/^r(uby|[bt]c?)$/.test(p.localName)||Wg(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);Ju(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?Cg:Sg);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(Ah),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=da.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)?wl(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!!(Gg(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=Fs(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?xl(h):this.breakPositions[this.breakPositions.length-1]instanceof ps)&&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)&&Hg(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=Jp(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 ps(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);Ug(this)&&aa(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 ow(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(Ls.isInstanceOfAfterIfContinuesLayoutConstraint(n)){let s=n.getRepetitiveElements();t.push(s)}si.isInstanceOfTableRowLayoutConstraint(n)&&n.getElementsOffsetsForTableCell(this).forEach(s=>{t.push(s)})});return t}},xa=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 Vs.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}},Us=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+_l(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&&Wa(s)&&Wa(r)?_l(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};c(Us,"instance");Us.instance=new Us;function _l(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var ow=class extends pa{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 aw(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||Xg()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Qu(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}},aw=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=B("DefaultLayoutMode.doLayout");return nw(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}},lw=class extends Vs{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||so.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new hw(e,this.rootSourceNode),so.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},hw=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=Bs(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=Bs(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=io(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=io(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 xa(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}},Rc=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}},Fc=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},uw=class extends Rc{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},cw=class extends Fc{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new Sa(e)),this.processor.doLayout(e,t)}},Sa=class Lc{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 mw(n,r,i).thenAsync(()=>ww(n,r,i).thenAsync(()=>(s.prepareLayoutFragment(),N(!0))))}getRepetitiveElements(){return zt(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof Lc?zt(this.nodeContext.formattingContext)===zt(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},dw=class extends pa{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 uw(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new cw(this.formattingContext,this.processor))}},pw=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)}},fw=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&&Bc(e.parent,t),e.belongsTo(n)?_i.prototype.layout.call(this,e,t,i):new dw(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=bw(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 pw(i,t);return new no(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=zt(e.formattingContext),n=B("doLayout"),s=t.layoutContext.nextInTree(e,!1);return Ic(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 gw(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 Bc(e,t){e&&gw(e.after?e.parent:e,(i,n)=>{si.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new Sa(n))})}function mw(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 ww(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 bw(e){let t=e.formattingContext;return!t||!(t instanceof vi)?null:t}function zt(e){return e instanceof vi,e}var yw=new fw;Ct("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof vi&&!si.isInstanceOfTableFormattingContext(e)?yw:null);var Oc=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))}},vw=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}},xw=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Sw=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,c(this,"pseudoColumn"),c(this,"empty",!1),this.pseudoColumn=new xa(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}},Cw=class{constructor(e,t){this.viewNode=e,this.side=t}},kw=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)}},Ew=class extends ua{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 ps&&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 Oc(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 xw(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 Nw(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}},Nw=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 Pw(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Tw(e){return e==="table"||e==="inline-table"}function Ml(e){return Pw(e)||Tw(e)}function _c(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"&&!Ml(r)||s==="table-cell"&&r!=="table-row"&&!Ml(r)||n.formattingContext instanceof $i&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,N(!0))):null}var Iw=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=_c(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 Cw(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 Oc(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 vw(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=[]}},Mc=class zc 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 Sw(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=Os(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=Os(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);Qm(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=Bs(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=_c(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 Ew(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&&zc.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(Mc,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Aw=Mc,Bn=[];function Rw(e){let t=Bn.findIndex(n=>n.root===e),i=Bn[t];return i?i.tableLayoutOption:null}function Fw(e){let t=Bn.findIndex(i=>i.root===e);t>=0&&Bn.splice(t,1)}var Dc=class{layoutEntireTable(e,t){let i=xt(e.formattingContext),n=new Iw(i,t);return new no(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=Rw(e.sourceNode);Fw(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 _w(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 Aw(i,t),o=new no(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&&Bc(e.parent,t),o=new Bw(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 kw(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return Pr(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(()=>{Lw(d,s,p),h.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),Pr(t),s.finishFragment(),a.finish(!0)}),a.result()}}return Pr(t),s.finishFragment(),da.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){_i.prototype.clearOverflownViewNodes(e,t,i,n)}};function Lw(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 Pr(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 Bw=class extends pa{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new Ow(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new zw(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()}},Ow=class extends Rc{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},_w=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 Mw(this.position.sourceNode))}},Mw=class Vc{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 Vc&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},zw=class extends Fc{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new Dw(e);t.fragmentLayoutConstraints.some(s=>n.equalsTo(s))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},Dw=class Uc extends Sa{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 Dc().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 Uc?xt(this.nodeContext.formattingContext)===xt(t.nodeContext.formattingContext):!1}},Vw=new Dc;function Uw(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 Hw(e){return e instanceof $i?Vw:null}Ct("RESOLVE_FORMATTING_CONTEXT",Uw);Ct("RESOLVE_LAYOUT_PROCESSOR",Hw);function zl(e){return e.reduce((t,i)=>t+i,0)/e.length}function $w(e){let t=zl(e);return zl(e.map(i=>{let n=i-t;return n*n}))}var Ww=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 Hc=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 Ww(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)}},vo=1;function $c(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+vo}function Wc(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+vo))-vo;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 Gw=class extends Hc{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 Dl(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return $c(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!Dl(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):On(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Wc(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,On(this.layoutContainer)+this.originalContainerBlockSize*.1);_n(this.layoutContainer,t)}}};function Dl(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 jw=class extends Hc{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 $w(t)}hasNextCandidate(e){return $c(e)}updateCondition(e){Wc(e,this.layoutContainer)}};function Xw(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 Gw(i,n,s,e):t===y.balance_all?new jw(i,n,s):(y.balance,null)}}var qw=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],Yw=new Set(qw);function Kw(e){return!(e.toLowerCase()==="none"||Yw.has(e))}var Zw=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Jw=new Set(Zw),Qw=["fixed","extends"],eb=new Set(Qw),S0=Symbol();function Yn(e){return e instanceof ae&&e.name.toLowerCase()!=="none"}function Gc(e){return e.name}function tb(e){if(e instanceof ae)return Jw.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 eb.has(n)&&(n==="fixed"&&i instanceof Re||n==="extends"&&Yn(i))}}return!1}function ib(e){let t=it(e,"system");return t instanceof ae&&t.name==="cyclic"}function nb(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 sb(e){let t=it(e,"system");return t instanceof ae?1:t.values[1].num}function rb(e){let t=it(e,"system");return t instanceof ae&&t.name==="alphabetic"}function ob(e){let t=it(e,"system");return t instanceof ae&&t.name==="numeric"}function ab(e){let t=it(e,"system");return t instanceof ae&&t.name==="additive"}function lb(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 hb(e){let t=it(e,"system");return Gc(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 jc(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 ub(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 Vl(e){return e instanceof Re||e instanceof ae&&e.name==="infinite"}function Hs(e,t){return e instanceof Re?e.num:t?-1/0:1/0}var C0=Symbol();function xo(e){if(!(e instanceof Q&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(Vl(t)&&Vl(i)))return!1;let n=Hs(t,!0),s=Hs(i,!1);return!(n>s)}function cb(e){return{lower:Hs(e.values[0],!0),upper:Hs(e.values[1],!1)}}function Xc(e){return e instanceof ae&&e.name==="auto"||xo(e)||e instanceof Ke&&e.values.length>=1&&e.values.every(t=>xo(t))}function db(e){return e instanceof ae?null:(xo(e)?[e]:e.values).map(t=>cb(t))}var k0=Symbol();function $s(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 Ws(e){let[t,i]=e.values;return t instanceof Re?[t.num,Ut(i)]:[i.num,Ut(t)]}function qc(e){return $s(e)}function pb(e){let[t,i]=Ws(e);return{minLength:t,symbol:i}}function Yc(e){return kt(e)||e instanceof Q&&e.values.length>=1&&e.values.every(t=>kt(t))}function fb(e){return kt(e)?[Ut(e)]:e.values.map(t=>Ut(t))}var E0=Symbol();function Kc(e){if($s(e))return!0;if(e instanceof Ke&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!$s(i))return!1;let[n]=Ws(i);if(n>=t)return!1;t=n}return!0}return!1}function gb(e){if($s(e)){let[t,i]=Ws(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=Ws(t);return{weight:i,symbol:n}})}var mb=["auto","bullets","numbers","words","spell-out"],wb=new Set(mb);function bb(e){return e instanceof ae&&wb.has(e.name)||Yn(e)}function yb(e,t){switch(e){case"system":return tb(t);case"negative":return jc(t);case"prefix":case"suffix":return kt(t);case"range":return Xc(t);case"pad":return qc(t);case"fallback":return Yn(t);case"symbols":return Yc(t);case"additive-symbols":return Kc(t);case"speak-as":return bb(t);default:return!0}}function it(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function vb(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 fs,gs,ms,ws,bs,ys,vs,xs,So,Co,ko,Eo,No,Po,To,st,Tr,Zc,Jc,Ul,Hl,Ir,$l,gn,Yt=class di{constructor(t,i){ue(this,st),c(this,"_store"),ue(this,fs),ue(this,gs),ue(this,ms),ue(this,ws),ue(this,bs),ue(this,ys),ue(this,vs),ue(this,xs),this._store=t;let n=it(i,"negative");mt(this,fs,n&&jc(n)?ub(n):null);let s=it(i,"prefix");mt(this,gs,s&&kt(s)?Ut(s):null);let r=it(i,"suffix");mt(this,ms,r&&kt(r)?Ut(r):null);let o=it(i,"range");mt(this,ws,o&&Xc(o)?db(o):null);let a=it(i,"pad");mt(this,bs,a&&qc(a)?pb(a):null);let l=it(i,"fallback");mt(this,ys,l&&Yn(l)?Gc(l):null);let h=it(i,"symbols");mt(this,vs,h&&Yc(h)?fb(h):null);let u=it(i,"additive-symbols");mt(this,xs,u&&Kc(u)?gb(u):null)}static create(t,i){return ib(i)?new ui(t,i):nb(i)?new xb(t,i):rb(i)?new Cb(t,i):ob(i)?new Wl(t,i):ab(i)?new kb(t,i):lb(i)?new Eb(t,i):new Sb(t,i)}static createDecimal(t){return new Wl(t,X(di,So))}static createDisc(t){return new ui(t,X(di,Co))}static createSquare(t){return new ui(t,X(di,ko))}static createCircle(t){return new ui(t,X(di,Eo))}static createDisclosureOpen(t){return new ui(t,X(di,No))}static createDisclosureClosed(t){return new ui(t,X(this,Po))}static createNone(t){return new ui(t,X(di,To))}static get CHINESE_LONGHAND_NAMES(){return Gl.NAMES}static createChineseLonghand(t,i){return new Gl(t,i)}static createEthiopicNumeric(t){return new Pb(t)}_getNegative(){return X(this,fs)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return X(this,gs)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return X(this,ms)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return X(this,ws)}static _getRangeFrom(t){return t._getRange()}_getPad(){return X(this,bs)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(X(this,ys)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return X(this,vs)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return X(this,xs)}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,Zc).call(this)+this.format(t)+Ee(this,st,Jc).call(this)}};fs=new WeakMap,gs=new WeakMap,ms=new WeakMap,ws=new WeakMap,bs=new WeakMap,ys=new WeakMap,vs=new WeakMap,xs=new WeakMap,So=new WeakMap,Co=new WeakMap,ko=new WeakMap,Eo=new WeakMap,No=new WeakMap,Po=new WeakMap,To=new WeakMap,st=new WeakSet,Tr=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},Zc=function(){var e;return(e=this._getPrefix())!=null?e:""},Jc=function(){var e;return(e=this._getSuffix())!=null?e:". "},Ul=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},Hl=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},Ir=function(){var e;return(e=this._getFallback())!=null?e:Ki(this._store)},$l=function(e,t){let{minLength:i,symbol:n}=Ee(this,st,Hl).call(this);if(i===0||n==="")return e;let{prefix:s,suffix:r}=Ee(this,st,Tr).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),!vb(e,Ee(this,st,Ul).call(this))){let h=Ee(this,st,Ir).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,Ir).call(this);return Ee(s=h,st,gn).call(s,e,t)}let l=Ee(this,st,$l).call(this,a,r);if(r){let{prefix:h,suffix:u}=Ee(this,st,Tr).call(this);l=h+l+(u??"")}return l},ue(Yt,So,{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,Co,{system:new _(F("cyclic"),0),symbols:new _(new G("\u2022"),0),suffix:new _(new G(" "),0)}),ue(Yt,ko,{system:new _(F("cyclic"),0),symbols:new _(new G("\u25AA"),0),suffix:new _(new G(" "),0)}),ue(Yt,Eo,{system:new _(F("cyclic"),0),symbols:new _(new G("\u25E6"),0),suffix:new _(new G(" "),0)}),ue(Yt,No,{system:new _(F("cyclic"),0),symbols:new _(new G("\u25BE"),0),suffix:new _(new G(" "),0)}),ue(Yt,Po,{system:new _(F("cyclic"),0),symbols:new _(new G("\u25B8"),0),suffix:new _(new G(" "),0)}),ue(Yt,To,{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]}},Ss,xb=class extends he{constructor(e,t){super(e,t),ue(this,Ss),mt(this,Ss,sb(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,Ss);return(t=i[n])!=null?t:null}};Ss=new WeakMap;var Sb=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)}},Cb=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}},Wl=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}},kb=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,Qc=class extends he{constructor(t,i){super(t,i),ue(this,ut),ue(this,Nn);let n=hb(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 Qc?Ee(t=i,ut,gt).call(t,e):i:Ki(this._store)};var Eb=Qc,Nb=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],Ar,Rr,os,Fr,Io,Cs,bt=class ed extends he{constructor(t,i){let{chars:n,descriptors:s}=X(ed,Io).get(i);super(t,s),ue(this,Cs),mt(this,Cs,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=X(this,Cs);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}};Ar=new WeakMap,Rr=new WeakMap,os=new WeakMap,Fr=new WeakMap,Io=new WeakMap,Cs=new WeakMap,ue(bt,Ar,{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,Rr,{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,os,{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,Fr,{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(Nb)),ue(bt,Io,new Map([["simp-chinese-informal",X(bt,Ar)],["simp-chinese-formal",X(bt,Rr)],["trad-chinese-informal",X(bt,os)],["trad-chinese-formal",X(bt,Fr)],["cjk-ideographic",X(bt,os)]]));var Gl=bt,Ao,Ro,Gs,Fo,Lo,Ai=class pi extends he{constructor(t){super(t,X(pi,Ao))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return X(pi,Gs)[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,Ro)[u]+X(pi,Gs)[d]}l?a!==0&&(r+=X(pi,Fo)):o!==0&&(r+=X(pi,Lo))}return r}};Ao=new WeakMap,Ro=new WeakMap,Gs=new WeakMap,Fo=new WeakMap,Lo=new WeakMap,ue(Ai,Ao,{range:new _(new Q([new Re(1),F("infinite")]),0),suffix:new _(new G("/ "),0)}),ue(Ai,Ro,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ue(Ai,Gs,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ue(Ai,Fo,"\u137B"),ue(Ai,Lo,"\u137C");var Pb=Ai,Ce,Tb=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(!Kw(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 Lr=class{constructor(e,t,i){c(this,"endStuckFixed"),c(this,"endFixed"),c(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},Ib=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 Lr(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 Lr(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new Lr(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)}},Ab=class Bo{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 Bo(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 Bo(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=qu(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==y.none&&!eo(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}},Rb=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 Ab(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=_u(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!")}},jl=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 Ib;let h=e.getElementOffset(this.root);this.lastOffset=h,this.boxStack=new Rb(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,Su))}}}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<Xl.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,Xl[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 Gm(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=rf(h.evaluate(this.context,"flow-options"));o=!!g.exclusive,a=!!g.static,l=!!g.last}let u=t["flow-linger"];u&&(r=hl(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(s=hl(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 vg(e,g)}let m=new xg(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){}},Xl=["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 td{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 td;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(ql);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(ql);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]}},Fb=1,id=2,nd=4,fi=8,ks=16,Oo=32,Es=64,sd=128,mn=256,wn=512,_o=1024,rd=2048,od=4096,ad=8192,ld=class extends Xt{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Le=class hd extends ld{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Fb?t:null}visitSlash(t){return this.allowed&rd?t:null}visitStr(t){return this.allowed&id?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&nd||this.allowed&Es&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&wn)?t.unit=="%"&&this.allowed&_o?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&ks?t:null}visitInt(t){return t.num==0?this.allowed&wn?t:null:t.num<=0&&!(this.allowed&mn)?null:this.allowed&(Oo|ks)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&Es&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&sd?t:null}visitURange(t){return this.allowed&od?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){return this.allowed&Es&&CSS.supports("color",t.toString())||this.allowed&ad&&CSS.supports("background-image",t.toString())||t.name==="calc"&&this.allowed&(fi|ks|Oo|mn|wn|_o)?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 hd(this.allowed|t.allowed,i,n)}},re={},ql=new Le(0,re,re),Ca=class extends ld{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 ka&&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 Ca{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 ka){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)}},ka=class extends Ca{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}},Lb=class extends Ca{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}},ud=class{tryParse(e,t,i){return t}success(e,t){}},cd=class extends ud{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}},Bb=class extends cd{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}},Ob=class extends ud{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Ks){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}},Ea=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 cd(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 Ea{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}},dd=class extends Ea{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 Bb(this.validatorSet,this.propList)}},_b=class extends Ea{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Ks){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}},Mb=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}},zb=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]===Ks){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}},Db=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)}},Vb=["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"],Ub=class extends rn{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)Vb.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},Yl={SIMPLE:rn,INSETS:dd,INSETS_SLASH:_b,COMMA:Mb,FONT:zb,TEXT_SPACING:Db,ALL:Ub},Hb=["initial-letter"],$b=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 eu(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 ka(t);break;case"SPACE":i=new Pn(t);break;default:i=new Lb(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Le(Es,re,re)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Le(ad,re,re)),this.namedValidators.POS_INT=this.primitive(new Le(Oo,re,re)),this.namedValidators.POS_NUM=this.primitive(new Le(ks,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(_o,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(sd,re,re)),this.namedValidators.URANGE=this.primitive(new Le(od,re,re)),this.namedValidators.IDENT=this.primitive(new Le(nd,re,re)),this.namedValidators.STRING=this.primitive(new Le(id,re,re)),this.namedValidators.SLASH=this.primitive(new Le(rd,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&&Yl[i.text]?(n=new Yl[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 dd){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 Ob(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"||Gb(t)){n.simpleProperty(e,t,i);return}if(s==="counter-style"){yb(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&&!Ph.includes(`-${r}-`)||n.unknownProperty(o,t);return}else if(Hb.includes(e)&&!Object.keys(l).some(u=>hs(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 pd(){let e=new $b;return e.initBuiltInValidators(),e.parse(fu),e}var Wb=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 Gb(e){let t=new Wb;return e.visit(t),t.varFound}var P0=`OTTO${new Date().valueOf()}`;function Na(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function jb(e){let t=new ii;for(let i of Na(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function Xb(e,t){let i={};for(let n in e)i[n]=_e(e,n).evaluate(t,n);return i}var fd=class{constructor(e){this.properties=e,c(this,"fontTraitKey"),c(this,"src"),c(this,"blobURLs",[]),c(this,"blobs",[]),c(this,"family"),this.fontTraitKey=jb(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 {
|
|
1847
|
+
}`;function Ds(e,t,i){let n=M("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 h;if(o.status=a.status,o.url=a.url,o.statusText=a.statusText,o.contentType=(h=a.headers.get("Content-Type"))==null?void 0:h.replace(/;.*$/,"").toLowerCase(),!a.ok)throw new Error(`HTTP ${a.status}${a.statusText?` ${a.statusText}`:""}`);return t==="blob"?a.blob():t==="arraybuffer"?a.arrayBuffer():t==="json"?a.json():/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?(o.contentType="text/html",a.arrayBuffer().then(l=>new TextDecoder("Shift_JIS").decode(l))):(/^data:,(<|%3c)/i.test(e)&&(o.contentType="text/html"),a.text())}).then(a=>{t==="blob"&&a instanceof Blob?o.responseBlob=a:t==="arraybuffer"&&a instanceof ArrayBuffer?o.responseBlob=lc([a]):t==="json"?o.responseText=JSON.stringify(a):typeof a=="string"&&(o.responseText=a),s.schedule(o)}).catch(a=>{o.status>=400?W.warn(`Error fetching ${e} (${o.status}${o.statusText?" "+o.statusText:""})`):W.warn(a,`Error fetching ${e}`),s.schedule(o)}),n.result()}function lc(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function zg(e){let t=M("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 Ma=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=M("fetch"),r=e.endsWith("?viv-toc-box");r&&(e=e.replace("?viv-toc-box",""));let s=Ee("user-agent.xml",fi),o=!r&&e===s;return o&&(e=`data:application/xml,${encodeURIComponent(ic)}`),Ds(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(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Wt(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new yr(()=>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 Ug(e,t){let i=e.responseText;return N(i?Na(i):null)}function Hg(){return new Ma(Ug,"text")}function Ut(e,t,i){let n=new yr(()=>{let r=M("loadElement"),s=r.suspend(e),o=!1,a=null,h=l=>{o||(o=!0,a!==null&&(clearTimeout(a),a=null),s.schedule(l?l.type:"timeout"))};if(e.addEventListener("load",h,!1),e.addEventListener("error",h,!1),e.addEventListener("abort",h,!1),e.namespaceURI=="http://www.w3.org/2000/svg")t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),a=setTimeout(h,300);else if(e.localName==="script")a=setTimeout(h,3e3);else if(t)if(e.localName==="img"){let l=e;l.loading==="lazy"&&(l.loading="eager"),l.src=t,i&&(l.alt=i),l.complete?setTimeout(()=>h(new Event("load")),0):a=setTimeout(h,3e4)}else e.src=t,i&&(e.alt=i);return r.result()},`loadElement ${t||e.localName}`);return n.start(),n}var jl=0,$g=16777216,hc=33554432,uc=50331648,cc=67108864,Wg=83886080,Gg=100663296,_a=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 jl;case"User":return Gg;default:return Wg}}getBaseSpecificity(){switch(this.flavor){case"UA":return jl;case"User":return $g;default:return hc}}},jg=class extends _a{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;W.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)}},Xl=class extends _a{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()}},In=class extends Xl{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new Xl(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())}},Le=[],ps=[],xe=[],Ae=[],Nt=[],ct=[],Fe=[],We=[],ve=[],qe=[],rt=[],$e=[],Re=[],Ki=55,Ji=56,Rr=57;Le[1]=28,Le[36]=29,Le[7]=29,Le[9]=29,Le[14]=29,Le[18]=29,Le[50]=29,Le[20]=30,Le[13]=27,Le[0]=200,ps[1]=46,ps[0]=200,ct[1]=2,ct[36]=4,ct[7]=6,ct[9]=8,ct[14]=10,ct[18]=14,ct[50]=42,xe[37]=11,xe[23]=12,xe[35]=56,xe[1]=1,xe[36]=3,xe[7]=5,xe[9]=7,xe[14]=9,xe[12]=13,xe[18]=55,xe[50]=58,xe[16]=41,Ae[37]=11,Ae[23]=12,Ae[35]=56,Ae[1]=1,Ae[36]=3,Ae[7]=5,Ae[9]=7,Ae[14]=9,Ae[18]=55,Nt[1]=2,Nt[36]=4,Nt[7]=6,Nt[9]=8,Nt[18]=14,Nt[50]=42,Nt[14]=10,Nt[12]=13,Fe[1]=15,Fe[7]=16,Fe[4]=17,Fe[5]=18,Fe[3]=19,Fe[2]=20,Fe[8]=21,Fe[27]=57,Fe[16]=22,Fe[19]=23,Fe[6]=24,Fe[11]=25,Fe[17]=26,Fe[13]=48,Fe[31]=47,Fe[23]=54,Fe[0]=44,We[1]=31,We[4]=32,We[5]=32,We[3]=33,We[2]=34,We[10]=40,We[6]=38,We[31]=36,We[24]=36,We[32]=35,ve[1]=45,ve[16]=37,ve[37]=37,ve[38]=37,ve[47]=37,ve[48]=37,ve[39]=37,ve[49]=37,ve[41]=37,ve[26]=37,ve[25]=37,ve[23]=37,ve[24]=37,ve[19]=37,ve[21]=37,ve[36]=37,ve[18]=37,ve[22]=37,ve[11]=39,ve[12]=43,ve[17]=49,qe[0]=200,qe[12]=50,qe[13]=51,qe[14]=50,qe[15]=51,qe[10]=50,qe[11]=51,qe[17]=53,rt[0]=200,rt[12]=50,rt[13]=52,rt[14]=50,rt[15]=51,rt[10]=50,rt[11]=51,rt[17]=53,$e[0]=200,$e[12]=50,$e[13]=51,$e[14]=50,$e[15]=51,$e[10]=50,$e[11]=51,Re[11]=0,Re[16]=0,Re[22]=1,Re[18]=1,Re[26]=2,Re[25]=2,Re[38]=3,Re[37]=3,Re[48]=3,Re[47]=3,Re[39]=3,Re[49]=3,Re[41]=3,Re[23]=4,Re[24]=4,Re[36]=5,Re[19]=5,Re[21]=5,Re[0]=6,Re[Ki]=2,Re[Ji]=2;var br=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(Y)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,r=0,s;do if(s=i[--n],e===")"&&s instanceof Xi){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 te(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=rt);let h=new Ui(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,h),h.name==="var"){let l=h.values[0]instanceof de&&h.values[0].name;(!jt(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=rt)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=rt,null;if(o>1)return new tt(this.extractVals(",",n+1));let a=i[0];return a instanceof it?a:a?new Xi(a.toString()):Y}exprError(e,t){this.actions=this.propName?rt:qe,W.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 h=a.shift(),l=a.shift(),u=new Ef(n.getScope(),h,l);a.unshift(u)}return i.push(new $(a[0])),!0}else if(o=="("){let h=i.pop(),l=i.pop();r=new Yn(n.getScope(),xo(l,h),a),e=0;continue}}if(o==10){r.isMediaName()&&(r=new Pl(n.getScope(),r,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)r=new mi(n.getScope(),r);else if(o==-24)r=new rn(n.getScope(),r);else if(o==-Rr)r=new Cf(n.getScope(),r);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(Re[e]>Re[o]){i.push(o);break}switch(s=i.pop(),o){case 26:r=new Aa(n.getScope(),s,r);break;case Ki:r=new kf(n.getScope(),s,r);break;case Ji:r=new Pf(n.getScope(),s,r);break;case 25:r=new Ra(n.getScope(),s,r);break;case 38:r=new Nf(n.getScope(),s,r);break;case 37:r=new If(n.getScope(),s,r);break;case 48:r=new Tf(n.getScope(),s,r);break;case 47:r=new ko(n.getScope(),s,r);break;case 39:case 49:r=new Fa(n.getScope(),s,r);break;case 41:r=new Af(n.getScope(),s,r);break;case 23:r=new vu(n.getScope(),s,r);break;case 24:r=new xu(n.getScope(),s,r);break;case 36:r=new La(n.getScope(),s,r);break;case 19:r=new Su(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 Lf(n.getScope(),i.pop(),s,r);break;case 10:if(s.isMediaName())r=new Pl(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 h=o.position,l=t&&r==="selector"&&a>0?"":i.input.substring(n,h).trim();return new Of(this.handler.getScope(),r,l,t)}readPseudoParams(){let e=[];for(;;){let t=this.tokenizer.token();switch(t.type){case 1:e.push(t.text);break;case 23:e.push("+");break;case 4:case 5:e.push(t.num);break;default:return e}this.tokenizer.consume()}}readNthPseudoParams(){let e=!1,t=this.tokenizer.token();if(t.type===23)e=!0,this.tokenizer.consume(),t=this.tokenizer.token();else if(t.type===1&&(t.text==="even"||t.text==="odd"))return this.tokenizer.consume(),[2,t.text==="odd"?1:0];switch(t.type){case 3:if(e&&t.num<0)return null;case 1:if(e&&t.text.charAt(0)==="-")return null;if(t.text==="n"||t.text==="-n"){if(e&&t.precededBySpace)return null;let i=t.text==="-n"?-1:1;t.type===3&&(i=t.num);let n=0;this.tokenizer.consume(),t=this.tokenizer.token();let 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=At(i,t,new mi(i,new je(i,"pref-horizontal")));break;case"horizontal":t=At(i,t,new je(i,"pref-horizontal"));break;case"day":t=At(i,t,new mi(i,new je(i,"pref-night-mode")));break;case"night":t=At(i,t,new je(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new $(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":case"footnote":return!0}return!1}runParser(e,t,i,n,r,s){let o=this.handler,a=this.tokenizer,h=this.valStack,l,u,d,p,f,g,m,w=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),r&&w===null&&(w=l.position-1,a.input[w]==="("&&w++),this.actions===Fe&&this.errorBrackets.length>0&&(l.type===this.errorBrackets[this.errorBrackets.length-1]||l.type===17||l.type===31)){if(l.type===this.errorBrackets[this.errorBrackets.length-1]&&(this.errorBrackets.pop(),l.type===11&&this.valStackReduce(")",l))){a.consume();continue}h.push(new Xi(l.toString())),a.consume();continue}switch(this.actions[l.type]){case 28:if(!this.inStyleDeclaration||a.nthToken(1).type!=18){this.isInsidePropertyOnlyRule()?(o.error("E_CSS_COLON_EXPECTED",a.nthToken(1)),this.actions=rt):(this.actions=ct,o.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Fe,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=rt,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=Fe,h.splice(0,h.length);continue;case 29:this.actions=ct,o.startSelectorRule();continue;case 1:if(!l.precededBySpace){this.actions=$e,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 2:if(a.nthToken(1).type==34)if(a.consume(),a.consume(),d=this.namespacePrefixToURI[l.text],d!=null)switch(l=a.token(),l.type){case 1:o.tagSelector(d,l.text),r?this.actions=Ae:this.actions=xe,a.consume();break;case 36:o.tagSelector(d,null),r?this.actions=Ae:this.actions=xe,a.consume();break;default:this.actions=qe,o.error("E_CSS_NAMESPACE",l)}else this.actions=qe,o.error("E_CSS_UNDECLARED_PREFIX",l);else o.tagSelector(this.defaultNamespaceURI,l.text),r?this.actions=Ae:this.actions=xe,a.consume();continue;case 3:if(!l.precededBySpace){this.actions=$e,o.error("E_CSS_SPACE_EXPECTED",l);continue}o.descendantSelector();case 4:if(a.nthToken(1).type==34)switch(a.consume(),a.consume(),l=a.token(),l.type){case 1:o.tagSelector(null,l.text),r?this.actions=Ae:this.actions=xe,a.consume();break;case 36:o.tagSelector(null,null),r?this.actions=Ae:this.actions=xe,a.consume();break;default:this.actions=qe,o.error("E_CSS_NAMESPACE",l)}else o.tagSelector(this.defaultNamespaceURI,null),r?this.actions=Ae:this.actions=xe,a.consume();continue;case 5:l.precededBySpace&&o.descendantSelector();case 6:if(!l.text){o.error("E_CSS_SYNTAX",l),a.consume();continue}o.idSelector(l.text),r?this.actions=Ae:this.actions=xe,a.consume();continue;case 7:l.precededBySpace&&o.descendantSelector();case 8:o.classSelector(l.text),r?this.actions=Ae:this.actions=xe,a.consume();continue;case 55:l.precededBySpace&&o.descendantSelector();case 14:a.consume(),l=a.token();e:switch(l.type){case 1:o.pseudoclassSelector(l.text,null),a.consume(),r?this.actions=Ae:this.actions=xe;continue;case 6:switch(p=l.text,a.consume(),p){case"is":case"not":case"where":case"has":this.actions=ct,o.startFuncWithSelector(p),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,p==="has")?this.actions=xe:this.actions=$e;continue;case"lang":case"href-epub-type":case"href-role-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),(p==="href-epub-type"||p==="href-role-type")&&a.token().type===16&&(a.consume(),l=a.token(),l.type===1&&(m.push(l.text),a.consume()));break}else break e;case"nth-child":case"nth-of-type":case"nth-last-child":case"nth-last-of-type":case"nth":if(m=this.readNthPseudoParams(),m)if(p==="nth-child"||p==="nth-last-child"){if(u=a.nthToken(0),u.type===1&&u.text==="of"){a.consume(),this.actions=ct,o.startFuncWithSelector(p,m),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,!1)?r?this.actions=Ae:this.actions=xe:this.actions=$e;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)m.push(u.text),a.consume();else break e;break}else break;else break e;default:m=this.readPseudoParams()}if(l=a.token(),l.type==11){o.pseudoclassSelector(p,m),a.consume(),r?this.actions=Ae:this.actions=xe;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=qe;continue;case 58:l.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:o.pseudoelementSelector(l.text,null),r?this.actions=Ae:this.actions=xe,a.consume();continue;case 6:if(p=l.text,a.consume(),p=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){o.pseudoelementSelector(p,m),r?this.actions=Ae:this.actions=xe,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=qe;continue;case 9:l.precededBySpace&&o.descendantSelector();case 10:if(a.consume(),l=a.token(),l.type==1)p=l.text,a.consume();else if(l.type==36)p=null,a.consume();else if(l.type==34)p="";else{this.actions=$e,o.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(d=p&&this.namespacePrefixToURI[p],d===void 0){this.actions=$e,o.error("E_CSS_UNDECLARED_PREFIX",l),a.consume();continue}if(a.consume(),l=a.token(),l.type!=1){this.actions=$e,o.error("E_CSS_ATTR_NAME_EXPECTED",l);continue}p=l.text,a.consume(),l=a.token()}else d="";switch(l.type){case 39:case 45:case 44:case 43:case 42:case 46:case 50:f=l.type,a.consume(),l=a.token();break;case 15:o.attributeSelector(d,p,0,null),r?this.actions=Ae:this.actions=xe,a.consume();continue;default:this.actions=$e,o.error("E_CSS_ATTR_OP_EXPECTED",l);continue}switch(l.type){case 1:case 2:o.attributeSelector(d,p,f,l.text),a.consume(),l=a.token();break;default:this.actions=$e,o.error("E_CSS_ATTR_VAL_EXPECTED",l);continue}if(l.type!=15){this.actions=$e,o.error("E_CSS_ATTR",l);continue}r?this.actions=Ae:this.actions=xe,a.consume();continue;case 11:o.childSelector(),this.actions=Nt,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=Nt,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=Nt,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=Le,a.consume();continue;case 41:o.nextSelector(),this.actions=ct,a.consume();continue;case 15:h.push(B(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new Fu(l.text)),a.consume();continue;case 17:h.push(new vt(l.num)),a.consume();continue;case 18:h.push(new Be(l.num)),a.consume();continue;case 19:h.push(new F(l.num,l.text)),a.consume();continue;case 20:h.push(new j(l.text)),a.consume();continue;case 21:h.push(new ot(Ee(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new Lu(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(Tn),a.consume();continue;case 24:p=l.text.toLowerCase(),p=="-epubx-expr"||p=="env"?(this.actions=We,this.exprContext=0,h.push("{")):(h.push(p),h.push("("),this.errorBrackets.length>0&&this.errorBrackets.push(11)),a.consume();continue;case 25:this.valStackReduce(")",l),a.consume();continue;case 47:if(a.consume(),l=a.token(),u=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(u.type==17||u.type==0||u.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(u=a.nthToken(1),u.type){case 4:case 3:case 5:if(!u.precededBySpace){a.consume();continue}}h.push(new Xi("+")),a.consume();continue;case 26:a.consume();case 48:g=this.valStackReduce(";",l),g&&this.propName&&o.property(this.propName,g,this.propImportant),this.actions=i?ps:Le;continue;case 44:for(a.consume();h.length>0;){let b=h.length;if(g=this.valStackReduce(";",l),!g||h.length===b)break}return t?(this.result=g,!0):(this.propName&&g&&o.property(this.propName,g,this.propImportant),!0);case 31:if(u=a.nthToken(1),u.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,u.text,"("),a.consume()):(h.push(new je(o.getScope(),xo(l.text,u.text))),this.actions=ve),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new El(o.getScope(),!0,u.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=u),h.push(new El(o.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==Ki&&h[h.length-1]!==Ji&&(u.type===10||u.type===6)){h.push(-Rr),a.consume();continue}else h.push(new je(o.getScope(),l.text));this.actions=ve}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=ve;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new Ye(o.getScope(),l.num)),a.consume(),this.actions=ve;continue;case 33:p=l.text,p=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?p="vh":p="vw"),h.push(new gr(o.getScope(),l.num,p)),a.consume(),this.actions=ve;continue;case 34:h.push(new Ye(o.getScope(),l.text)),a.consume(),this.actions=ve;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new Nu(o.getScope(),l.num)),a.consume(),this.actions=ve);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=We,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==Ji&&h[h.length-2]!==-Rr?(this.actions=We,this.exprStackReduce(Ki,l),h.push(Ki),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==Ki&&h[h.length-2]!==-Rr?(this.actions=We,this.exprStackReduce(Ji,l),h.push(Ji),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=Fe),a.consume();continue;case 43:this.exprStackReduce(11,l)&&(this.propName||this.exprContext==3?this.exprError("E_CSS_UNEXPECTED_BRC",l):(this.exprContext==1?o.startWhenRule(h.pop()):o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Le)),a.consume();continue;case 49:if(this.exprStackReduce(11,l))return this.propName||this.exprContext!=3?(this.exprError("E_CSS_UNEXPECTED_SEMICOL",l),this.actions=Le,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=Le,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let b=this.readSupportsTest(l);if(b){h.push(b),this.actions=ve;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=Le,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=l.text.toLowerCase(),p){case"import":if(a.consume(),l=a.token(),l.type==2||l.type==8){if(this.importURL=l.text,a.consume(),l=a.token(),l.type==17||l.type==0)return this.importReady=!0,a.consume(),!1;this.propName=null,this.exprContext=3,this.actions=We,h.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",l),this.actions=qe;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(p=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[p]=l.text,a.consume(),a.consume();continue}break;case 2:case 8:if(a.nthToken(1).type==17){this.defaultNamespaceURI=l.text,a.consume(),a.consume();continue}break}o.error("E_CSS_NAMESPACE_SYNTAX",l),this.actions=qe;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){p=l.text.toLowerCase(),p!="utf-8"&&p!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${p}`,l),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",l),this.actions=qe;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"-epubx-region":a.consume(),o.startRegionRule(),this.regionRule=!0,this.actions=ct;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=Nt;continue;case"-adapt-footnote-area":case"footnote":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){let b=l.text;a.consume(),a.consume(),o.startFootnoteRule(b),this.ruleStack.push(p==="footnote"?"footnote":"-adapt-footnote-area"),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}break;case"top-left-corner":case"top-left":case"top-center":case"top-right":case"top-right-corner":case"right-top":case"right-middle":case"right-bottom":case"bottom-right-corner":case"bottom-right":case"bottom-center":case"bottom-left":case"bottom-left-corner":case"left-bottom":case"left-middle":case"left-top":if(a.consume(),l=a.token(),l.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=We,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=We,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=We,h.push("{");continue;case"-epubx-flow":if(a.nthToken(1).type==1&&a.nthToken(2).type==12){o.startFlowRule(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),this.ruleStack.push(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(),l=a.token();let b=null,x=null,y=[];for(l.type==1&&(b=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(x=a.nthToken(1).text,a.consume(),a.consume(),l=a.token());l.type==6&&l.text.toLowerCase()=="class"&&a.nthToken(1).type==1&&a.nthToken(2).type==11;)y.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),p){case"-epubx-page-master":o.startPageMasterRule(b,x,y);break;case"-epubx-partition":o.startPartitionRule(b,x,y);break;case"-epubx-partition-group":o.startPartitionGroupRule(b,x,y);break}this.ruleStack.push(p),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${p}`,l),this.actions=$e;continue;default:o.error(`E_CSS_AT_UNKNOWN ${p}`,l),this.actions=qe;continue}o.error(`E_CSS_AT_SYNTAX ${p}`,l),this.actions=qe;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Le;continue}case 51:if(r&&this.errorBrackets.length==0&&l.type==11)return a.consume(),o.endFuncWithSelector(),!0;this.errorBrackets.length>0&&this.errorBrackets[this.errorBrackets.length-1]==l.type&&this.errorBrackets.pop(),this.errorBrackets.length==0&&l.type==13&&(this.actions=Le),a.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Le),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(r){switch(l.type){case 16:case 11:if(this.actions===ct)o.error("E_CSS_SYNTAX",l);else{let b=a.input.substring(w,l.position);o.pushSelectorText(b),w=l.position+1}if(l.type===16){o.nextSelector(),this.actions=ct,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(s){this.actions=xe;continue}break;case 12:case 14:case 10:this.errorBrackets.push(l.type+1);break}o.error("E_CSS_SYNTAX",l),a.consume(),this.actions=$e;continue}if(this.actions!==qe&&this.actions!==$e&&this.actions!==rt){if(l.type==54)o.error("E_CSS_SYNTAX",l);else if(this.actions===Fe){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Xi(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==We&&h.length>0){o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Le,a.consume();continue}else{if(l.type===17&&this.actions==We)return this.actions=Le,a.consume(),!1;o.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=rt:this.actions=$e;continue}a.consume();continue}}return!1}},dc=class extends _a{constructor(e){super(null),this.scope=e}error(e,t){W.warn(e,t.toString())}getScope(){return this.scope}};function Xg(e,t,i,n,r){let s=M("parseStylesheet"),o=new br(Le,e,t,i),a=null;return r&&(a=Yg(new Xt(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 l=Ee(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let u=M("parseStylesheet.import");return pc(l,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,u.finish(!0)}),u.result()}let h=s.timeSlice();if(h.isPending)return h}return N(!1)}).then(()=>{a&&t.endRule(),s.finish(!0)}),s.result()}function Da(e,t,i,n,r){return bn("parseStylesheetFromText",s=>{let o=new Xt(e,t);Xg(o,t,i,n,r).thenFinish(s)},(s,o)=>{W.warn(o,`Failed to parse stylesheet text: ${e}`),s.finish(!1)})}function pc(e,t,i,n){return bn("parseStylesheetFromURL",r=>{Ds(e).then(s=>{s.responseText?Da(s.responseText,t,e,i,n).then(o=>{o||W.warn(`Failed to parse stylesheet from ${e}`),r.finish(!0)}):r.finish(!0)})},(r,s)=>{W.warn(s,"Exception while fetching and parsing:",e),r.finish(!0)})}function vr(e,t,i){let n=new br(Fe,t,new dc(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function qg(e,t,i){new br(ps,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function Yg(e,t,i){let n=new br(We,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var Zg={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function Kg(e){return!!Zg[e]}function Jg(e,t,i){if(t instanceof Ie&&t.str==="viv-leader")return new $(t);if(i==="content"&&t instanceof Ie)return new $(t);let n=t.evaluate(e);switch(typeof n){case"number":return Kg(i)?n==Math.round(n)?new Be(n):new vt(n):new F(n,"px");case"string":return n?i==="content"?new j(n):vr(t.scope,new Xt(n,null),""):Y;case"boolean":return n?v._true:v._false;case"undefined":return Y}throw new Error("E_UNEXPECTED")}function fc(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 h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function gc(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 mc={"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"}]}},Qg=fc(mc,!0);function wc(e,t,i){return gc(e,t,i||null,Qg)}var em=fc(mc,!1);function yc(e,t,i){return gc(e,t,i||null,em)}var tm={"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 im(e,t){let i=tm[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 za(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",h=a?"height":"width",l=a?"width":"height";function u(p,f){r.style[p]=f;let g=o(p);return r.style[p]=s[p],g}let d={};for(let p of i){let f;switch(p){case"max-content inline size":f=u(h,"max-content");break;case"min-content inline size":f=u(h,"min-content");break;case"fit-content inline size":f=u(h,"fit-content");break;case"max-content block size":f=u(l,"max-content");break;case"min-content block size":f=u(l,"min-content");break;case"fit-content block size":f=u(l,"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 on(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 bc(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function vc(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function gt(e,t){let i=bc(e);i.includes(t)||(i.push(t),vc(e,i))}function nm(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function rm(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function so(e,t){let i=nm(e);i.includes(t)||(i.push(t),rm(e,i))}function sm(e){let t=e.name,i=e.value;switch(t){case"page-break-before":case"page-break-after":case"page-break-inside":return{name:t.replace(/^page-/,""),value:i===v.always?v.page:i,important:e.important};default:return e}}var Lo={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ge(e){return!!Lo[e]}var om={left:!0,right:!0,recto:!0,verso:!0};function xn(e){return!!om[e]}function ql(e){return Ge(e)&&e!=="column"&&e!=="region"}var am={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function fs(e){return!!am[e]}function et(e,t){if(e)if(t){if(xn(t))return t;if(xn(e))return e;{let i=Ge(e),n=Ge(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:fs(t)?t:fs(e)?e:t}}else return e;else return t}function Yl(e){return Ge(e)?e:"auto"}kt("SIMPLE_PROPERTY",sm);var Zn=Jp(ef());function lm(e,t){return(0,Zn.default)(e,t,0)}function Zl(e){return e.reduce((t,i)=>i[0]===Zn.default.DELETE?t:t+i[1],"")}function hm(e,t){return xc(e,t,1)}function um(e,t){return xc(e,t,-1)}function xc(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 Zn.default.INSERT:n++;break;case Zn.default.DELETE:n--,r++;break;case Zn.default.EQUAL:r++;break}if(r>t)return!0}return!1}),Math.max(Math.min(t,r-1)+n,0)}var Oo;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(Oo||(Oo={}));var gn;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(gn||(gn={}));var gs;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(gs||(gs={}));var Mi;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||bi.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||bi.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(Mi||(Mi={}));var bi;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(bi||(bi={}));var ri;(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={}))})(ri||(ri={}));var cm={transform:!0,"transform-origin":!0},dm={top:!0,bottom:!0,left:!0,right:!0},Va=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},pm={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 fm(e,t){let i=pm[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Bo=class Un extends Ta{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(Un.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Un.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Un.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Un.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||I(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],h=this.elementsById[o.observer];if(a&&h){let l=fm(a,o.action);if(l)for(let u=0;u<h.length;u++)h[u].addEventListener(o.event,l,!1)}}}};c(Bo,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),c(Bo,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var Sc=Bo,dt=ri.Whitespace;function Cc(e){switch(e){case"normal":case"nowrap":return dt.IGNORE;case"pre-line":return dt.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return dt.PRESERVE;default:return null}}function Me(e,t){return e?e.nodeType==1?!1:kc(e.textContent,t):!0}function kc(e,t){switch(t){case dt.PRESERVE:return e.length==0;case dt.NEWLINE:return!!e.match(/^[ \t]*$/);case dt.IGNORE:default:return!!e.match(/^[ \t\r\n\f]*$/)}}var gm=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,c(this,"forcedBreakOffsets",[]),c(this,"formattingContext",null)}},mm=class{constructor(e,t,i,n,r,s,o,a,h){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=h,c(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function wm(e,t){return e.top-t.top}function ym(e,t){return t.right-e.right}function Ec(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===ri.ShadowType.ROOTLESS&&t.shadowType===ri.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Mo(e.shadowContext,t.shadowContext)&&Mo(e.nodeShadow,t.nodeShadow)&&Ec(e.shadowSibling,t.shadowSibling)}function vi(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(!Ec(e.steps[i],t.steps[i]))return!1;return!0}function bm(e){return{steps:[{node:e,shadowType:ht.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function ms(e,t){return{steps:[{node:e.sourceNode,shadowType:ht.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:e.formattingContext,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function ws(e,t){let i=new Qi(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?ws(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var ht=ri.ShadowType,$r=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&&Mo(this.parentShadow,e.parentShadow):!1}};function Mo(e,t){return e===t||!!e&&!!t&&e.equals(t)}var vm=class{constructor(e,t){this.outer=e,this.count=t}},Qi=class Pc{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,"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=ht.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=gn.FloatReference.INLINE,this.whitespace=i?i.whitespace:dt.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=gn.FloatReference.INLINE,this.floatSide=null,this.clearSide=null,this.floatMinWrapBlock=null,this.columnSpan=null,this.flexContainer=!1,this.whitespace=this.parent?this.parent.whitespace:dt.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 Pc(this.sourceNode,this.parent,this.boxOffset);return t.offsetInNode=this.offsetInNode,t.after=this.after,t.nodeShadow=this.nodeShadow,t.shadowType=this.shadowType,t.shadowContext=this.shadowContext,t.shadowSibling=this.shadowSibling,t.inline=this.inline,t.breakPenalty=this.breakPenalty,t.display=this.display,t.floatReference=this.floatReference,t.floatSide=this.floatSide,t.clearSide=this.clearSide,t.floatMinWrapBlock=this.floatMinWrapBlock,t.columnSpan=this.columnSpan,t.captionSide=this.captionSide,t.inlineBorderSpacing=this.inlineBorderSpacing,t.blockBorderSpacing=this.blockBorderSpacing,t.establishesBFC=this.establishesBFC,t.containingBlockForAbsolute=this.containingBlockForAbsolute,t.flexContainer=this.flexContainer,t.whitespace=this.whitespace,t.hyphenateCharacter=this.hyphenateCharacter,t.breakWord=this.breakWord,t.breakBefore=this.breakBefore,t.breakAfter=this.breakAfter,t.viewNode=this.viewNode,t.clearSpacer=this.clearSpacer,t.firstPseudo=this.firstPseudo,t.vertical=this.vertical,t.overflow=this.overflow,t.preprocessedTextContent=this.preprocessedTextContent,t.formattingContext=this.formattingContext,t.repeatOnBreak=this.repeatOnBreak,t.pluginProps=Object.create(this.pluginProps),t.fragmentIndex=this.fragmentIndex,t.afterIfContinues=this.afterIfContinues,t.footnotePolicy=this.footnotePolicy,t}modify(){return this.shared?this.cloneItem():this}copy(){let t=this;do{if(t.shared)break;t.shared=!0,t=t.parent}while(t);return this}clone(){let t=this.cloneItem(),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===ri.ShadowType.ROOTLESS&&(r.floatReference!==gn.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?um(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}},xi=class Nc{constructor(t){this.primary=t,c(this,"floats",null)}clone(){let t=new Nc(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(!vi(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(!vi(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},xm=class Tc{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new Tc(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},Sm=class Ic{constructor(){c(this,"positions",[]),c(this,"startBreakType",null),c(this,"breakAfter",null)}clone(){let t=new Ic,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}},Cm=class Ac{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 Ac;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}},Rc=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,I(this.element,"top",`${e}px`),I(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,I(this.element,"left",`${e}px`),I(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):Ba(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 Ct(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 Ct(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return qu(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 Ct(e,t,e+i,t+n)}},sr=class extends oi{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 ot)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"){this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof Ie&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Rt(e){return e!=null&&e!==Y&&e!==v.normal&&e!==v.none&&!J(e)}var Te=gn.FloatReference;function km(e){switch(e){case"inline":return Te.INLINE;case"column":return Te.COLUMN;case"region":return Te.REGION;case"page":return Te.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function wi(e){switch(e){case Te.INLINE:return!1;case Te.COLUMN:case Te.REGION:case Te.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function oo(e,t,i,n){let r=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=yc(e,r,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let s=wc(e,r,i),o=im(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"&&(W.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var Fc=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),c(this,"insidePageFloatArea",!1),c(this,"parentPageFloat",null)}getOrder(){if(this.order===null)throw new Error("The page float is not yet added");return this.order}getId(){if(!this.id)throw new Error("The page float is not yet added");return this.id}isAllowedOnContext(e){return e.isAnchorAlreadyAppeared(this.getId())?!0:this.insidePageFloatArea&&this.parentPageFloat?!!e.findPageFloatFragment(this.parentPageFloat):!1}isAllowedToPrecede(e){return!1}},Em=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=>vi(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(n=>vi(n.nodePosition,e));if(t>=0)return this.floats[t];let i=e?.steps;if(i!=null&&i.length){let n=this.floats.findIndex(r=>{let s=r.nodePosition.steps;if(!(s!=null&&s.length)||s.length===i.length||r.nodePosition.offsetInNode!==e.offsetInNode||r.nodePosition.after!==e.after)return!1;let o=Math.min(s.length,i.length);for(let a=0;a<o;a++)if(s[a].node!==i[a].node)return!1;return!0});if(n>=0)return this.floats[n]}return null}findPageFloatById(e){let t=this.floats.findIndex(i=>i.id===e);return t>=0?this.floats[t]:null}},Lc=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}},Kl=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&vi(this.nodePosition,e.nodePosition):!1}},en=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),c(this,"outerContext",null),e&&e.children.push(this),this.writingMode=!J(s)&&s||e&&e.writingMode||v.horizontal_tb,this.direction=!J(o)&&o||e&&e.direction||v.ltr,this.floatStore=e?e.floatStore:new Em;let a=this.getPreviousSibling();this.floatsDeferredFromPrevious=a?[].concat(a.floatsDeferredToNext):[]}get effectiveParent(){var e;return(e=this.parent)!=null?e:this.outerContext}getParent(e){if(this.parent)return this.parent;if(this.outerContext)return this.outerContext;throw new Error(`No PageFloatLayoutContext for ${e}`)}setOuterContext(e){this.outerContext=e,this.floatStore=e.floatStore}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&&vi(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 Sn().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===Te.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 yc(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return wc(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(h=>h.includes("block"))?(n.push("snap-block"),r=!0):n.push(a)):a.includes("inline")&&(s||(i.slice(o+1).some(h=>h.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,s=!0){this.container;let o=this.toLogical(e),a=this.toPhysical(e),h=t&&this.toLogical(t),l=t&&this.toPhysical(t),u=this.getLimitValueInner(o,h,i,n,r);if(s&&this.parent&&this.parent.container){let d=this.parent.getLimitValue(a,l,i,n,r,s);switch(a){case"top":return Math.max(u,d);case"left":return Math.max(u,d);case"bottom":return Math.min(u,d);case"right":return Math.min(u,d);default:}}return u}getLimitValueInner(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){var s,o,a,h;this.container;let l=this.container.originX,u=this.container.originY,d=this.container.getPaddingRect(),p={top:d.y1-u,left:d.x1-l,bottom:d.y2-u,right:d.x2-l,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};if(this.container.vertical){let m=parseFloat((o=(s=this.container.element)==null?void 0:s.style)==null?void 0:o.width);isFinite(m)&&m>this.container.width&&(p.right+=m-this.container.width)}else{let m=parseFloat((h=(a=this.container.element)==null?void 0:a.style)==null?void 0:h.height);isFinite(m)&&m>this.container.height&&(p.bottom+=m-this.container.height)}function f(m,w,b){return m.unit==="%"?b*m.num/100:e.convertLengthToPx(m,w,t)}let g=this.floatFragments;return g.length>0&&(p=g.reduce((m,w)=>{if(i&&!i(w,this))return m;let[b,x]=this.toLogicalFloatSides(w.floatSide);if(x&&(n&&x.includes("block")===n.includes("block")&&x!==n||r&&x.includes("block")===r.includes("block")&&x!==r))return m;let y=w.area,P=w.continuations[0].float.floatMinWrapBlock,S=y.vertical?y.left+y.getInsetLeft()+y.width+y.getInsetRight():y.top+y.getInsetTop()+y.height+y.getInsetBottom(),R=y.vertical?y.top+y.getInsetTop()+y.height+y.getInsetBottom():y.left+y.getInsetLeft()+y.width+y.getInsetRight(),A=m.top,U=m.left,G=m.bottom,Z=m.right,fe=m.floatMinWrapBlockStart,ue=m.floatMinWrapBlockEnd;switch(b){case"inline-start":y.vertical?A=Math.max(A,R):U=Math.max(U,R);break;case"block-start":y.vertical?(P&&y.left<Z&&(fe=f(P,y.rootViewNodes[0],d.x2-d.x1)),Z=Math.min(Z,y.left)):(P&&S>A&&(fe=f(P,y.rootViewNodes[0],d.y2-d.y1)),A=Math.max(A,S));break;case"inline-end":y.vertical?G=Math.min(G,y.top):Z=Math.min(Z,y.left);break;case"block-end":y.vertical?(P&&S>U&&(ue=f(P,y.rootViewNodes[0],d.x2-d.x1)),U=Math.max(U,S)):(P&&y.top<G&&(ue=f(P,y.rootViewNodes[0],d.y2-d.y1)),G=Math.min(G,y.top));break;default:throw new Error(`Unknown logical float side: ${b}`)}return{top:A,left:U,bottom:G,right:Z,floatMinWrapBlockStart:fe,floatMinWrapBlockEnd:ue}},p)),p.left+=l,p.right+=l,p.top+=u,p.bottom+=u,p}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 h=a.find(S=>S.includes("inline")&&o[S==="inline-start"?"inline-end":"inline-start"]),l=a.find(S=>S.includes("block")),u=this.getLimitValue("block-start",h,e.layoutContext,e.clientLayout),d=this.getLimitValue("block-end",h,e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-start",l,e.layoutContext,e.clientLayout),f=this.getLimitValue("inline-end",l,e.layoutContext,e.clientLayout),g=e.vertical?e.originX:e.originY,m=e.vertical?e.originY:e.originX;u=e.vertical?Math.min(u,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+g):Math.max(u,e.top+g),d=e.vertical?Math.max(d,e.left+g):Math.min(d,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+g);function w(S,R){let A=S(e.bands,R);return A?(e.vertical&&(A=Gu(A)),u=e.vertical?Math.min(u,A.x2):Math.max(u,A.y1),d=e.vertical?Math.max(d,A.x1):Math.min(d,A.y2),!0):s}let b,x,y,P;if(r){let S=e.vertical?ds(new Ct(d,p,u,f)):new Ct(p,u,f,d);if((a[0]==="block-start"||a[0]==="snap-block"||a[0]==="inline-start"||a[0]==="snap-inline")&&!w(qf,S)||(a[0]==="block-end"||a[0]==="snap-block"||a[0]==="inline-end"||a[0]==="snap-inline")&&!w(Yf,S)||(y=(d-u)*e.getBoxDir(),b=y-e.getInsetBefore()-e.getInsetAfter(),P=(f-p)*e.getInlineDir(),x=P-e.getInsetStart()-e.getInsetEnd(),!s&&(b<=0||x<=0)))return null}else{let S=e.getContentBlockMarginAfter();b=Math.max(0,e.computedBlockSize+Math.min(0,S)),y=b+e.getInsetBefore()+e.getInsetAfter();let R=(d-u)*e.getBoxDir();if(a[0]==="snap-block"){if(n===null)a[0]="block-start";else{let U=this.container.getPaddingRect(),G=this.container.getBoxDir()*(n-(this.container.vertical?U.x2:U.y1)),Z=this.container.getBoxDir()*((this.container.vertical?U.x1:U.y2)-n-y);G<=Z?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&&R<y)return null;a[0]==="inline-start"||a[0]==="inline-end"||a[1]?x=za(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?x=e.getContentInlineSize():x=e.vertical?e.height:e.width,P=x+e.getInsetStart()+e.getInsetEnd();let A=(f-p)*e.getInlineDir();if(!s&&A<P)return null}return u-=g,d-=g,p-=m,f-=m,a.some(S=>S==="inline-start"||S==="snap-inline")||a.length===1&&(a[0]==="block-start"||a[0]==="snap-block")?e.setInlinePosition(p,x):(a.some(S=>S==="inline-end")||a.length===1&&a[0]==="block-end")&&e.setInlinePosition(f-P*e.getInlineDir(),x),a.some(S=>S==="block-start"||S==="snap-block")||a.length===1&&(a[0]==="inline-start"||a[0]==="snap-inline")?e.setBlockPosition(u,b):(a.some(S=>S==="block-end")||a.length===1&&a[0]==="inline-end")&&e.setBlockPosition(d-y*e.getBoxDir(),b),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)}getBlockEndEdgeOfBlockStartFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(s=>s.floatSide.includes("block-start")).filter(s=>{if(!isFinite(e))return!0;let o=s.getOuterRect();return n?o.y1<=e&&e<=o.y2:o.x1<=e&&e<=o.x2}).forEach(s=>{let o=s.getOuterRect(),a=n?o.x1:o.y2;r=isFinite(r)?n?Math.min(r,a):Math.max(r,a):a}),this.parent){let s=this.parent.getBlockEndEdgeOfBlockStartFloats(e);isFinite(s)&&(r=isFinite(r)?n?Math.min(r,s):Math.max(r,s):s)}return r}getBlockStartEdgeOfBlockEndFloats(e){let t=this,i=null;for(;t&&!i;)i=t.container,t=t.parent;let n=!!(i!=null&&i.vertical),r=NaN;if(this.floatFragments.filter(s=>s.floatSide.includes("block-end")).filter(s=>{if(!isFinite(e))return!0;let o=s.getOuterRect();return n?o.y1<=e&&e<=o.y2:o.x1<=e&&e<=o.x2}).forEach(s=>{let o=s.getOuterRect(),a=n?o.x2:o.y1;r=isFinite(r)?n?Math.max(r,a):Math.min(r,a):a}),this.parent){let s=this.parent.getBlockStartEdgeOfBlockEndFloats(e);isFinite(s)&&(r=isFinite(r)?n?Math.max(r,s):Math.min(r,s):s)}return r}getPageFloatClearEdge(e,t){function i(l){return u=>l.isAnchorAlreadyAppeared(u.float.getId())}function n(l,u){return e==="inline-start"&&(l.floatSide.includes("inline-end")||l.floatSide==="block-end")||e==="inline-end"&&(l.floatSide.includes("inline-start")||l.floatSide==="block-start")?!1:l.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(l){return l.floatFragments.some(u=>n(u,l))||l.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 h=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:h}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 h(d){return p=>(!d||p.floatSide.includes(d))&&p.getOrder()<a}function l(d,p){return d.children.some(f=>f.floatFragments.some(h(p))||l(f,p))}function u(d,p){let f=d.parent;return!!f&&(f.floatFragments.some(h(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(h(null))||l(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]=!l(this,d);break;case"block-end":n[d]=!u(this,d);break;case"inline-start":case"inline-end":n[d]=!this.floatFragments.some(h(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=[],Sn=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}`)}},Pm=class{appliesToNodeContext(e){return wi(e.floatReference)}appliesToFloat(e){return!0}createPageFloat(e,t,i){let n=e.floatReference;e.floatSide;let r=e.floatSide,s=e.toNodePosition(),o=!!t.generatingNodePosition;return i.resolveFloatReferenceFromColumnSpan(n,e.columnSpan,e).thenAsync(a=>{n=a,t.flowName;let h=new Fc(s,n,r,e.clearSide,t.flowName,e.floatMinWrapBlock);if(h.insidePageFloatArea=o,o){let l=t.generatingNodePosition;l&&(h.parentPageFloat=t.findPageFloatByNodePosition(l))}return t.addPageFloat(h),N(h)})}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new Lc(s.floatReference,t,i,e,n,r)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){return N(void 0)}forbid(e,t){}};Sn.register(new Pm);var Nm=Lc,_o=class Oc extends Fc{constructor(t,i,n,r,s){super(t,i,"block-end",null,n,s),this.footnotePolicy=r}isAllowedToPrecede(t){return!(t instanceof Oc)}},Jl=class extends Nm{constructor(e,t,i,n){super(e,"block-end",null,t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof _o?!0:this.getOrder()<e.getOrder()}},Tm=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!vi(t,this.footnote.nodePosition)}},Im=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof _o}createPageFloat(e,t,i){let n=Te.REGION,r=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Te.PAGE).hasSameContainerAs(r)&&(n=Te.PAGE);let s=!!t.generatingNodePosition;s&&n!==Te.PAGE&&(n=Te.PAGE);let o=e.toNodePosition();t.flowName;let a=new _o(o,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);if(a.insidePageFloatArea=s,s){let h=t.generatingNodePosition;h&&(a.parentPageFloat=t.findPageFloatByNodePosition(h))}return t.addPageFloat(a),N(a)}createPageFloatFragment(e,t,i,n,r){let s=e[0].float;return new Jl(s.floatReference,e,n,r)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof Jl);return i.length<=1,i[0]||null}adjustPageFloatArea(e,t,i){e.isFootnote=!0,e.adjustContentRelativeSize=!1;let n=e.element;return i.layoutContext.applyFootnoteStyle(t.vertical,i.layoutContext.nodeContext&&i.layoutContext.nodeContext.direction==="rtl",n).thenAsync(r=>(e.vertical=r,e.convertPercentageSizesToPx(n),i.setComputedInsets(n,e),i.setComputedWidthAndHeight(n,e),N(void 0)))}forbid(e,t){let i=e;switch(i.footnotePolicy){case v.line:{let n=new Tm(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Sn.register(new Im);var Am="data-vivliostyle-flow-root";function Rm(e){return e.getAttribute(Am)==="true"}function Ql(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"initial":case"unset":case"inline":case"table-row-group":case"table-column":case"table-column-group":case"table-header-group":case"table-footer-group":case"table-row":case"table-cell":case"table-caption":case"inline-block":i="block";break;default:i=t}return B(i)}function zs(e){return e===v.absolute||e===v.fixed}function ys(e){return e instanceof Ui&&e.name==="running"}function Bc(e,t,i,n){return e===v.none||(zs(t)?(i=v.none,e=Ql(e)):(i&&i!==v.none&&!J(i)||n)&&(e=Ql(e))),{display:e,position:t,float:i}}function Mc(e,t,i,n){return Bc(e,t,i,n).display===v.block}function Vs(e){return e instanceof de||e instanceof te||typeof e=="string"}function Mt(e){if(!Vs(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 Hn(e){return Vs(e)?e.toString().includes("list-item"):!1}function Fm(e){if(!Vs(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 _c(e){if(!Vs(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 Lm(e,t,i,n,r,s,o){return r=r||s||v.horizontal_tb,!!o||!!i&&i!==v.none&&!J(i)||zs(t)||e===v.inline_block||e===v.table_cell||e===v.table_caption||e==v.flex||e==v.grid||e==v.flow_root||(e===v.block||e===v.list_item)&&!!n&&n!==v.visible&&n!==v.clip&&!J(n)||!!s&&r!==s}function Om(e){return e===v.relative||e===v.absolute||e===v.fixed}var Ht=1e5;function Ua(e){let t=e.element.style;t.columnGap=`${Ht-(e.vertical?e.height:e.width)}px`,t.columnFill="auto",t.columnCount="1",t.columnWidth="0"}function Us(e){let t=("element"in e?e.element:e).style;t.columnWidth="",t.columnCount="",t.columnGap="",t.columnFill=""}function bs(e){return e.element.style.columnCount==="1"}function Bm(e){e.element.setAttribute("data-vivliostyle-column","true")}function or(e,t){let i=t?e.bottom:Math.max(Math.abs(e.left),Math.abs(e.right));return Math.round(i/Ht)}function Dc(e,t){let i=or(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/Ht),s=r*Ht,o=i*Ht;return t?(e.top-=s,e.bottom-=o,e.bottom<e.top&&(e.bottom+=Ht),e.right-=s,e.left-=o):e.left<-Ht/2?(e.right+=s,e.left+=o,e.left>e.right&&(e.left-=Ht),e.top+=s,e.bottom+=o):(e.left-=s,e.right-=o,e.right<e.left&&(e.right+=Ht),e.top+=s,e.bottom+=o),e.width=e.right-e.left,e.height=e.bottom-e.top,r}function Do(e,t){for(let i=0;i<e.length;i++)Dc(e[i],t)}function It(e,t,i){let n=e.getElementClientRect(t);if(Dc(n,i)>0&&e.getElementComputedStyle(t).display.startsWith("table")&&!Hs(t)){let r=t.closest("[data-vivliostyle-column]");if(r)return Us(r),e.getElementClientRect(t)}return n}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 Hs(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 _m(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=Hs(i);if(!a)return;let h=a.ownerDocument.defaultView.getComputedStyle(a),{writingMode:l,direction:u,columnGap:d,fontSize:p}=h,f=l==="vertical-rl"||l==="vertical-lr",g=u==="rtl",m=(parseFloat(d)||parseFloat(p)||16)/2,w=a.getBoundingClientRect(),b=i.getBoundingClientRect();(f?b.top>w.bottom+m:g?b.right<w.left-m:b.left>w.right+m)&&(r&&(n.breakBefore=""),o&&s&&(s.style.breakAfter=""),n.marginBlockStart=`${Ht}px`)}function Fr(e){let t=e.element.lastElementChild,i=t&&e.clientLayout.getElementClientRect(t);return i?or(i,e.vertical):0}function zc(e,t){if(e.getAttribute("data-viv-saved-column-fill")!=="auto"||Fr(t))return;let i=t.clientLayout.getElementComputedStyle(e),n=parseFloat(i.blockSize);e.style.columnFill="auto";let r=parseFloat(i.blockSize),s=NaN;if(e.style.blockSize=`${r}px`,Fr(t)){if(e.style.blockSize=`${n}px`,!Fr(t)){let o=1/(t.clientLayout.pixelRatio||1),a=n,h=r;for(;h-a>o;){let l=(a+h)/2;e.style.blockSize=`${l}px`,Fr(t)?h=l:a=l}s=a,e.style.blockSize=`${s}px`}}else if(s=parseFloat(i.blockSize),s<r){let o=1/t.clientLayout.layoutUnitPerPixel;s=r+o,e.style.blockSize=`${s}px`}if(isNaN(s)){e.style.blockSize="",e.style.columnFill="balance";return}e.removeAttribute("data-viv-saved-column-fill")}function Dm(e){let t=e.element.querySelectorAll('[data-viv-saved-column-fill="auto"]');for(let i of t)zc(i,e)}function tn(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==="wbr"||o&&Mt(o.display)&&/^([\d\.]|super|(text-)?top)/.test(o.verticalAlign))return NaN}if(r===s){if(s.localName==="br"){let o=s.ownerDocument.createElement("span");s.parentNode.insertBefore(o,s);let a=t.getElementClientRect(o);if(o.remove(),a){let h=[a];Do(h,n);let l=h[0],u=n?l.left:l.bottom;if(!isNaN(u)&&u!==0)return u}return NaN}if(e.after||!e.inline){if(e.after&&!e.inline&&s.querySelector("ruby")){let a=s.parentNode,h=s.nextSibling;a.removeChild(s),a.insertBefore(s,h)}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(),h=r.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(r,i),a.setEnd(r,i+1);let l=t.getRangeClientRects(a);Do(l,n);let u=l.filter(d=>d.right>d.left&&d.bottom>d.top);if(u.length>0)l=u;else{let d=s?t.getElementComputedStyle(s).whiteSpace:"";l=d==="pre"||d==="pre-wrap"||d==="pre-line"||d==="break-spaces"?l.filter(p=>n?p.right>p.left:p.bottom>p.top):[]}return l.length?(n?o=Math.min.apply(null,l.map(d=>d.left)):o=Math.max.apply(null,l.map(d=>d.bottom)),o):NaN}}function zo(e,t,i){let n=bs(t);n&&Us(t);let r=t.clientLayout.getElementClientRect(e);n&&Ua(t);let s=t.getComputedMargin(e);return i?r.width+s.left+s.right:r.height+s.top+s.bottom}function an(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function Vc(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 Cn="data-adapt-spec";function Ha(e){return!!e.getAttribute(Cn)}function hi(e){return e?.nodeType!==1?!1:Ha(e)?!0:Uc(e)}function Uc(e){var t,i;if(e?.nodeType!==1)return!1;let n=e,r=(t=n.style)==null?void 0:t.position;if(r==="absolute"||r==="fixed")return!0;let s=(i=n.style)==null?void 0:i.float;return s==="left"||s==="right"||s==="inline-start"||s==="inline-end"}function eh(e){var t;return e?.nodeType!==1?!1:((t=e.style)==null?void 0:t.position)==="fixed"}function ln(e){let t=e?.viewNode;return t?.nodeType===1&&Ha(t)}function zm(e){return e!=="inline"&&(Mt(e)||_c(e))}function th(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}function Vm(e){let t=e;for(;t;){if(t.nodeType===Node.TEXT_NODE&&t.textContent.length>0)return t;if(t.lastChild)t=t.lastChild;else{for(;t&&!t.previousSibling;)if(t=t.parentNode,t===e||!t)return null;t=t?.previousSibling||null}}return null}var $a=class{calculateOffset(e){return mn(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function mn(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var xr=class extends $a{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(fs(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=tn(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 h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===r&&!s)&&(o+=e.parseComputedLength(l.paddingBlockEnd)),h===r&&!s&&(o+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),s?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===r)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===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(!Mi.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Mn=class{find(e){let t=Ft("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()}`)}},hn=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 xr(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===ri.ShadowType.ROOTLESS&&ln(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;Vc(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)}},Wa=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){}},Ga=new hn,Um=Oo.isInstanceOfBlockFormattingContext;kt("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&&Mc(i,n,r,s)?new Wa(o?o.formattingContext:null):null});kt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Wa?Ga:null);var ja=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=M("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)}},Hm=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){}},Vo=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=M("LayoutIterator");return n.loopWithFrame(r=>{let s;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Me(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()}},Kn=class extends Hm{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&&Ge(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=et(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=et(e.breakAtTheEdge,e.nodeContext.breakAfter)),N(!0)))}},Uo=[];function $m(){Uo=[]}function Hc(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var Wm=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},Gm=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},$c=class Wr{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let r=Wr.fragmentIndices;(!r[t]||r[t].priority<=n)&&(r[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){Wr.fragmentIndices={}}matches(){let t=Wr.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&Hc(t.fragmentIndex,this.a,this.b)}};c($c,"fragmentIndices",{});var $s=$c,Lr=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new $s(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new Gm(e)}static buildAnyMatcher(e){return new Wm(e)}},Wc={"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},jm=["image-resolution","orphans","widows"];function Xm(){return Ft("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(jm))}var qm={"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},Ho=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],Ym=["max-%","min-%","%"],ih=(()=>{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<Ho.length;i++)for(let n=0;n<e.length;n++){let r=Ho[i].replace("%",e[n]);t[r]=!0}return t})();function An(e,t){let i={};for(let n of Ho)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 Ym)for(let r in t){let s=n.replace("%",r),o=n.replace("%",t[r]);i[s]=o,i[o]=s}return i}var Gc=An({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),jc=An({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),Zm=An({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),Km=An({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),Jm=An({inside:"right",outside:"left"},{}),Qm=An({inside:"left",outside:"right"},{}),D=class $o{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 $o(i,this.priority)}increaseSpecificity(t){return t==0?this:new $o(this.value,this.priority+t)}evaluate(t,i,n,r){return i&&jt(i)?this.value:Cs(t,this.value,i,n,r)}isEnabled(t){return!0}},Wo=class Go extends D{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new D(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new Go(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new Go(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){W.warn(i)}return!1}};function jo(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Dt(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 Xc={"region-id":!0,"fragment-selector-id":!0},qc="data-viv-footnote-counter";function Yc(e){let t=e.getAttribute(qc);if(!t)return Object.create(null);let i;try{i=JSON.parse(t)}catch{return Object.create(null)}if(!i||typeof i!="object"||Array.isArray(i))return Object.create(null);let n=Object.create(null);return Object.entries(i).forEach(([r,s])=>{if(Array.isArray(s)){let o=s.filter(a=>typeof a=="number"&&isFinite(a));n[r]=o}else typeof s=="number"&&isFinite(s)&&(n[r]=[s])}),n}function ew(e,t,i){let n=Yc(e);n[t]=i,e.setAttribute(qc,JSON.stringify(n))}function tw(e){return!!Xc[e]}function Gr(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function Bi(e){return e.charAt(0)!=="_"&&!Xc[e]}function un(e){return!!Wc[e]||jt(e)}function ke(e,t){return e[t]}function yi(e,t,i){i?e[t]=i:delete e[t]}function bt(e,t){return e[t]}function ei(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Zc=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Kc(e,t){return e[t]}function Jc(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function vs(e,t,i,n,r,s,o){var a,h;if([{id:r,styleKey:"_pseudos"},{id:s,styleKey:"_regions"}].forEach(l=>{if(l.id){let u=ei(t,l.styleKey);t=u[l.id],t||(t={},u[l.id]=t)}}),o){let l=Zc(t);t={},l.push({styles:t,matcher:o})}for(let l in i)if(!Gr(l))if(tw(l)){let u=Kc(i,l),d=Jc(t,l);Array.prototype.push.apply(d,u)}else{let u=ke(i,l);if(!u.isEnabled(e))continue;let d=u.increaseSpecificity(n);Dt(t,l,d,e);let p=(h=(a=e.style)==null?void 0:a.validatorSet.shorthands[l])==null?void 0:h.propList;if(p)for(let f of p){let g=new D(Y,d.priority);Dt(t,f,g,e)}}}function iw(e,t){let i={};for(let n=0;n<t.length;n++)vs(e,i,t[n],0,null,null,null);return i}function Xa(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 nw=class extends Vi{constructor(e,t){super(),this.props=e,this.context=t,c(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=ke(this.props,"font-size");if(!e.value.isNumeric())return _t.em;let t=e.value;if(!vf(t.unit))throw new Error("Unexpected state");return t.num*_t[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?Xo(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?qa(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Cs(this.context,e,this.propName).visit(this):e}};function qa(e,t,i){let n=e.unit,r=e.num;return n==="em"?new F(r*t,"px"):n==="rem"?new F(r*i.fontSize(),"px"):n==="rlh"?new F(r*i.rootLineHeight,"px"):e}function Xo(e,t,i){e=qa(e,t,i);let n=e.unit,r=e.num;return n==="px"?e:n==="%"?new F(r/100*t,"px"):new F(r*i.queryUnitSize(n,!1),"px")}var Rn=class{apply(e){}mergeWith(e){return new rw([this,e])}clone(){return this}},Or=class extends Rn{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},rw=class Qc extends Rn{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 Qc([].concat(this.list))}},Ya=class extends Rn{constructor(e,t,i,n,r){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=r}apply(e){vs(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},Se=class extends Rn{constructor(){super(),c(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},sw=class extends Se{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}},ow=class extends Se{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}},nh=class extends Se{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}},aw=class extends Se{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}},lw=class extends Se{constructor(e,t,i=!1){super(),this.epubTypePatt=e,this.targetLocalName=t,this.useRoleAttr=i}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=this.useRoleAttr?n.getAttribute("role"):n.getAttributeNS("http://www.idpf.org/2007/ops","type")||n.getAttribute("epub:type");r&&r.match(this.epubTypePatt)&&this.chained.apply(e)}}}},hw=class extends Se{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function Ws(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 rh=class extends Se{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){Ws(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},uw=class extends Se{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){Ws(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}},cw=class extends Se{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){Ws(e.currentElement,this.ns,this.name,(t,i,n)=>!!qm[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},_n=class extends Se{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){Ws(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)}},dw=class extends Se{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},sh=class extends Se{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},pw=class extends Se{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},Hi=class extends Se{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return Hc(e,this.a,this.b)}},fw=class extends Hi{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},qo=class extends Hi{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}},Yo=class extends Hi{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}},Zo=class extends Hi{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}},gw=class extends Se{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}},mw=class extends Se{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},ww=class extends Se{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},yw=class extends Se{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},Qe=class extends Se{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}},ed=class td extends Rn{constructor(){super(),c(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new td;return t.applied=this.applied,t}},Za=class extends Se{constructor(e){super(),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new ed;for(let t of e)this.firstActions.push(Xa(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 Se?e.getPriority():0))}positive(){return!0}relational(){return!1}},bw=class extends Za{positive(){return!1}},vw=class extends Za{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}},id=class extends Hi{constructor(e,t,i){super(e,t),c(this,"checkAppliedAction"),c(this,"firstActions",[]),this.checkAppliedAction=new ed;for(let n of i)this.firstActions.push(Xa(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 h=1,l=e.previousElementSibling;for(;l;)h++,l=l.previousElementSibling;t.currentSiblingOrder=h;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}},xw=class extends id{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}},Gs=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)}},Sw=class nd extends Gs{constructor(t,i,n){super(t,i,n)}fresh(t){return new nd(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}},Cw=class rd extends Gs{constructor(t,i,n){super(t,i,n)}fresh(t){return new rd(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)}},kw=class sd extends Gs{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new sd(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)}},Ew=class od extends Gs{constructor(t,i,n){super(t,i,n),c(this,"fired",!1)}fresh(t){return new od(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}},Pw=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}},Nw=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}},Tw=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}},Iw=class extends Vi{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new ot(e):new ot("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 te){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 xs(e,t){if(Rt(e)){if(e instanceof j)return e.stringValue();if(e instanceof $&&t){let i=e.expr.evaluate(t);return typeof i=="string"?i:typeof i=="number"?String(i):""}if(e instanceof te)return e.values.map(i=>xs(i,t)).join("")}return""}var Ss=class extends Vi{constructor(e,t,i,n){super(),this.cascade=e,this.element=t,this.counterResolver=i,this.pseudoName=n}getCounterStore(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.counterStore)!=null?t:null}getPageScope(){var e,t;return(t=(e=this.cascade.context)==null?void 0:e.style)==null?void 0:t.pageScope}evaluateAndGetString(e){if(!e)return"";let t=this.cascade.quoteDepth,i=e.visit(this),n=xs(i,this.cascade.context);return this.cascade.quoteDepth=t,n}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)}formatCounterList(e,t,i){if(!e.length)return this.format(0,i);let n=new ii;for(let r=0;r<e.length;r++)r>0&&n.append(t),n.append(this.format(e[r],i));return n.toString()}formatLastValue(e,t){let i=e.length?e[e.length-1]:0;return this.format(i,t)}buildCounterText(e,t,i,n,r){var s,o,a,h,l,u;let d=typeof r=="string",p=w=>d?this.formatCounterList(w,r,i):this.formatLastValue(w,i),f=w=>{this.pseudoName==="footnote-call"&&this.element&&ew(this.element,t,w)};if(this.pseudoName==="footnote-marker"&&this.element){let w=Yc(this.element)[t];if(w)return p(w)}let g;if(t==="pages")return p([]);if(!this.element){let w=((s=e.currentPageCounters)==null?void 0:s[t])||[];if(w.length)return g=w,f(g),p(g)}let m=this.element?n:((o=e.currentPageDocCounters)==null?void 0:o[t])||n;if((a=e.isPageControlledCounter)!=null&&a.call(e,t)){let w=((h=e.currentPageDocCounters)==null?void 0:h[t])||[],b=((l=e.currentPageCounters)==null?void 0:l[t])||[],x=b.length?b[b.length-1]:0,y=w.length?w[0]:0,P=m.length?m[0]:0,S=x+(P-y);return g=m.length?[S,...m.slice(1)]:b.length?b:[0],f(g),p(g)}return m.length?(g=m,f(g),p(g)):(g=((u=e.currentPageCounters)==null?void 0:u[t])||[],f(g),p(g))}visitFuncCounter(e){var t;let i=e[0].toString(),n=e.length>1?e[1].stringValue():"decimal",r=(this.cascade.counters[i]||[]).slice(),s=this.getCounterStore();if(s){let a=i==="pages"||((t=s?.isPageControlledCounter)==null?void 0:t.call(s,i)),h=this.getPageScope(),l=new Ie(h,()=>this.buildCounterText(s,i,n,r),a?`page-counter-${i}`:`counter-${i}`);if(a&&s!=null&&s.registerPageCounterExpr){let u=d=>this.formatLastValue(d,n);s.registerPageCounterExpr(i,u,l)}return new $(l)}let o=this.cascade.counters[i];if(o&&o.length){let a=o&&o.length&&o[o.length-1]||0;return new j(this.format(a,n))}else{let a=new $(this.counterResolver.getPageCounterVal(i,h=>this.format(h||0,n)));return new te([a])}}visitFuncCounters(e){var t;let i=e[0].toString(),n=e[1].stringValue(),r=e.length>2?e[2].stringValue():"decimal",s=(this.cascade.counters[i]||[]).slice(),o=this.getCounterStore();if(o){let u=i==="pages"||((t=o?.isPageControlledCounter)==null?void 0:t.call(o,i)),d=this.getPageScope(),p=new Ie(d,()=>this.buildCounterText(o,i,r,s,n),u?`page-counters-${i}`:`counters-${i}`);return u&&o!=null&&o.registerPageCounterExpr&&o.registerPageCounterExpr(i,f=>this.formatCounterList(f,n,r),p),new $(p)}let a=this.cascade.counters[i],h=new ii;if(a&&a.length)for(let u=0;u<a.length;u++)u>0&&h.append(n),h.append(this.format(a[u],r));let l=new $(this.counterResolver.getPageCountersVal(i,u=>{let d=[];if(u.length)for(let f=0;f<u.length;f++)d.push(this.format(u[f],r));let p=h.toString();return p.length&&d.push(p),d.length?d.join(n):this.format(0,r)}));return new te([l])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof ot?i=t.url:i=t.stringValue();let n=e[1].toString(),r=e.length>2?e[2].stringValue():"decimal",s=new $(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,r)));return new te([s])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof ot?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 $(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,s));return h.length?h.join(r):this.format(0,s)}));return new te([o])}visitFuncTargetText(e){let t=e[0],i;t instanceof ot?i=t.url:i=t.stringValue();let n=e.length>1?e[1].stringValue():"content",r=new $(this.counterResolver.getTargetTextVal(i,n));return new te([r])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new $(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 $(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,r,s,o,a,h;let l=e.length>0?e[0].stringValue():"text",u="";switch(l){case"text":u=this.element.textContent;break;case"before":case"after":case"marker":{let d=(t=this.element)==null?void 0:t.querySelectorAll(`[data-adapt-pseudo="${l}"]`),p=null;if(d&&this.element)for(let f=0;f<d.length;f++){let g=d[f];if(g.parentElement===this.element){p=g;break}}if(p)u=p.textContent||"";else{let f=bt(this.cascade.currentStyle,"_pseudos"),g=(n=(i=f?.[l])==null?void 0:i.content)==null?void 0:n.value;if(g)u=this.evaluateAndGetString(g);else if(l==="marker"){let m=(r=this.cascade.currentStyle["--viv-marker-content"])==null?void 0:r.value;u=xs(m,this.cascade.context)}}}break;case"first-letter":{let d=bt(this.cascade.currentStyle,"_pseudos"),p=(o=(s=d?.before)==null?void 0:s.content)==null?void 0:o.value,f=(h=(a=d?.after)==null?void 0:a.content)==null?void 0:h.value,g=(this.evaluateAndGetString(p)||this.element.textContent||this.evaluateAndGetString(f)).match(us);u=g?g[0]:""}break}return new j(u)}visitFuncLeader(e){let t="";if(e[0]instanceof de)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 $(new Ie(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 ao(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(h=>h.after&&h.viewNode.nodeType===1&&h.viewNode.getAttribute("data-viv-leader"));for(let h of n){let l=function(E){y==="rtl"?g.textContent=(E.startsWith("\u200F")?"":"\u200F")+E+(E.endsWith("\u200F")?"":"\u200F"):g.textContent=E},u=function(){let E=i.clientLayout.getElementClientRect(m);return x==="vertical-rl"||x==="vertical-lr"?y==="rtl"?E.top-=C:E.bottom+=C:y==="rtl"?E.left-=C:E.right+=C,A.left>E.left||A.right<E.right||A.top>E.top||A.bottom<E.bottom},d=function(){let E,T,L=b.repeat(1e4);if(l(L),u())E=1,T=1e4;else return;for(let z=0;z<16;z++){let H="",K=Math.floor((E+T)/2);for(let ee=0;ee<K;ee++)H+=b;if(l(H),u())T=K;else{if(E==K)return;E=K}}l(b)},p=function(E){let T=0,L=m.parentElement;for(;L&&L!==f.viewNode;)T+=i.getComputedInsets(L)[E],L=L.parentElement;return T};var r=l,s=u,o=d,a=p;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,m=g.parentElement,w=m.getAttribute("data-adapt-pseudo"),b=g.getAttribute("data-viv-leader-value"),{writingMode:x,direction:y,marginInlineEnd:P}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(b),m.style.display="inline-block",m.style.textIndent="0";let S=Hs(f.viewNode),R=S?.style.columnFill||null;S&&(S.style.columnFill="auto");let A=i.clientLayout.getElementClientRect(f.viewNode),U=i.clientLayout.getElementClientRect(m),G=i.parseComputedLength(P),Z=[],fe=m.parentElement;for(;fe.parentElement&&fe.parentElement!==f.viewNode;)fe=fe.parentElement;let ue=fe.nextSibling;for(;ue;){if(ue.nodeType===1){let E=ue,{display:T,float:L,position:z}=i.clientLayout.getElementComputedStyle(E);if(L!=="none"||z==="absolute"||z==="fixed"){ue=ue.nextSibling;continue}if(Mt(T))Z.push(E);else if(Fm(T))break}else if(ue.nodeType===3){let E=ue;E.length>0&&Z.push(E)}ue=ue.nextSibling}let C=Z.reduce((E,T)=>E+ao(T,i.clientLayout,x),0);if(w!=="after"){let E=ao(fe,i.clientLayout,x),T=ao(m,i.clientLayout,x);C+=E-T}x==="vertical-rl"||x==="vertical-lr"?(y==="rtl"?A.top+=G:A.bottom-=G,A.top=Math.min(U.top,A.top),A.bottom=Math.max(U.bottom,A.bottom)):(y==="rtl"?A.left+=G:A.right-=G,A.left=Math.min(U.left,A.left),A.right=Math.max(U.right,A.right)),d();let _=i.clientLayout.getElementClientRect(m);y=="rtl"?m.style.float="left":m.style.float="right";let k=i.clientLayout.getElementClientRect(m),O=0;y=="rtl"?x=="vertical-rl"||x=="vertical-lr"?O=_.top-k.top-p("top"):O=_.left-k.left-p("left"):x=="vertical-rl"||x=="vertical-lr"?O=k.bottom-_.bottom-p("bottom"):O=k.right-_.right-p("right"),O-=C,O=Math.max(0,O-.1),m.style.float="",g.style.marginInlineStart=`${O}px`,S&&(R?S.style.columnFill=R:S.style.removeProperty("column-fill"))}};kt("POST_LAYOUT_BLOCK",Aw);var Ka=1/1048576;function Gi(e,t){for(let i in e)t[i]=e[i].clone()}var Rw=class ad{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 ad;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return Gi(this.tags,t.tags),Gi(this.nstags,t.nstags),Gi(this.epubtypes,t.epubtypes),Gi(this.classes,t.classes),Gi(this.ids,t.ids),Gi(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 Fw(this,t,i,n,r,s,o)}nextOrder(){return this.order+=Ka}},ld=class hd{constructor(t,i,n,r,s,o,a){this.context=i,this.counterListener=n,this.counterResolver=r,this.counterStyleStore=o,this.cmykStore=a,c(this,"code"),c(this,"stack",[[],[]]),c(this,"conditions",Object.create(null)),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,"pageTypePageIndices",Object.create(null)),c(this,"isFirst",!0),c(this,"isRoot",!0),c(this,"counters",Object.create(null)),c(this,"lastCounterChanges",[]),c(this,"lastCounterChangeTypes",Object.create(null)),c(this,"counterScoping",[Object.create(null)]),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",Object.create(null)),c(this,"dependentConditions",[]),c(this,"elementStack"),this.code=t,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(t){this.stack[this.stack.length-1].push(t)}increment(t,i){this.conditions[t]=(this.conditions[t]||0)+1,i&&(this.viewConditions[t]?this.viewConditions[t].push(i):this.viewConditions[t]=[i])}decrement(t,i){this.conditions[t]--,this.viewConditions[t]&&(this.viewConditions[t]=this.viewConditions[t].filter(n=>n!==i),this.viewConditions[t].length===0&&delete this.viewConditions[t])}buildViewConditionMatcher(t){let i=null;t&&(this.currentElementOffset,i=Lr.buildViewConditionMatcher(this.currentElementOffset,t));let n=this.dependentConditions.map(r=>{let s=this.viewConditions[r];return s&&s.length>0?s.length===1?s[0]:Lr.buildAnyMatcher([].concat(s)):null}).filter(r=>r);return n.length<=0?i:i===null?n.length===1?n[0]:Lr.buildAllMatcher(n):Lr.buildAllMatcher([i].concat(n))}applyAction(t,i){let n=t[i];n&&n.apply(this)}pushRule(t,i,n){this.currentElement=null,this.currentElementOffset=null,this.currentStyle=n,this.currentNamespace="",this.currentLocalName="",this.currentId="",this.currentXmlId="",this.currentClassNames=t,this.currentNSTag="",this.currentEpubTypes=lo,this.currentPageType=i,this.applyActions()}defineCounter(t,i){let n=this.counterScoping[this.counterScoping.length-1];n||(n=Object.create(null),this.counterScoping[this.counterScoping.length-1]=n),this.counters[t]?(n[t]&&this.counters[t].pop(),this.counters[t].push(i)):this.counters[t]=[i],n[t]=!0}pushCounters(t){var i,n,r,s,o,a,h;let l=new Set,u=Object.create(null),d=v.inline,p=t.display;if(p&&(d=p.evaluate(this.context)),d===v.none){this.currentElement.setAttribute("data-viv-display-none","true"),this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}else if(this.currentElement.closest("[data-viv-display-none]")){this.lastCounterChanges=[],this.lastCounterChangeTypes=Object.create(null),this.counterScoping.push(null);return}let f=v.inline,g=t.float;g&&(f=g.evaluate(this.context));let m=null,w=null,b=null,x=t["counter-reset"];if(x){let S=x.evaluate(this.context);S&&(m=fn(S,{reset:!0}))}let y=t["counter-set"];if(y){let S=y.evaluate(this.context);S&&(b=fn(S,{defaultValue:0}))}let P=t["counter-increment"];if(P){let S=P.evaluate(this.context);S&&(w=fn(S))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(m||(m=Object.create(null)),m["list-item"]=((n=(i=this.currentElement)==null?void 0:i.start)!=null?n:1)-1),Hn(d)&&(w||(w=Object.create(null)),w["list-item"]=(r=w["list-item"])!=null?r:1,/^\s*[-+]?\d/.test((o=(s=this.currentElement)==null?void 0:s.getAttribute("value"))!=null?o:"")&&(b||(b=Object.create(null)),b["list-item"]=this.currentElement.value)),((a=this.currentElement)==null?void 0:a.parentNode.nodeType)===Node.DOCUMENT_NODE&&(m||(m=Object.create(null)),m.footnote===void 0&&(m.footnote=0)),f===v.footnote&&(w||(w=Object.create(null)),w.footnote===void 0)){let S=(h=this.currentStyle["counter-increment"])==null?void 0:h.value;(!S||!(S===v.footnote||S instanceof te&&S.values.includes(v.footnote)))&&(w.footnote=1)}if(m)for(let S in m)l.add(S),u[S]="reset";if(w)for(let S in w)l.add(S),u[S]||(u[S]="increment");if(b)for(let S in b)l.add(S),u[S]="set";if(this.lastCounterChanges=Array.from(l),this.lastCounterChangeTypes=u,m)for(let S in m)this.defineCounter(S,m[S]);if(w)for(let S in w){this.counters[S]||this.defineCounter(S,0);let R=this.counters[S];R[R.length-1]+=w[S]}if(b)for(let S in b)if(!this.counters[S])this.defineCounter(S,b[S]);else{let R=this.counters[S];R[R.length-1]=b[S]}if(Hn(d)){let S=this.counters["list-item"],R=S[S.length-1];t["ua-list-item-count"]=new D(new vt(R),0);let A=ei(t,"_pseudos");A.marker||(A.marker={})}this.counterScoping.push(null)}popCounters(){let t=this.counterScoping.pop();if(t)for(let i in t){let n=this.counters[i];n&&(n.length==1?delete this.counters[i]:n.pop())}}setNamedStrings(t){let i=t["string-set"];if(!i)return;i=i.filterValue(new Ss(this,this.currentElement,this.counterResolver));let n=i.value instanceof tt?i.value.values:[i.value];for(let r of n)if(r instanceof te){let s=r.values[0].stringValue(),o=r.values.slice(1).map(a=>xs(a,this.context)).join("");this.counterResolver.setNamedString(s,o,this.currentElementOffset)}delete t["string-set"]}setRunningElement(t){let i=t.position;if(i?.value instanceof Ui&&i.value.name==="running"){let n=i.value.values[0].stringValue();this.counterResolver.setRunningElement(n,this.currentElementOffset)}}processPseudoelementProps(t,i,n){this.pushCounters(t);let r=t.content;r&&(t.content=r.filterValue(new Ss(this,i,this.counterResolver,n))),this.popCounters()}pushElement(t,i,n,r){var s,o,a;this.currentPageType=null,this.currentElement=i,this.currentElementOffset=r,this.currentStyle=n,this.currentNamespace=i.namespaceURI,this.currentLocalName=i.localName;let h=this.code.nsPrefix[this.currentNamespace];h?this.currentNSTag=h+this.currentLocalName:this.currentNSTag="",this.currentId=i.getAttribute("id"),this.currentXmlId=i.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let l=i.getAttribute("class");l?this.currentClassNames=l.split(/\s+/):this.currentClassNames=lo;let u=i.getAttributeNS("http://www.idpf.org/2007/ops","type");u?this.currentEpubTypes=u.split(/\s+/):this.currentEpubTypes=lo;let d=vo(i);d&&(this.stack[this.stack.length-1].push(new Nw(this.lang)),this.lang=d.toLowerCase());let p=this.isRoot,f=this.siblingOrderStack;this.currentSiblingOrder=++f[f.length-1],f.push(0);let g=this.siblingTypeCountsStack,m=this.currentSiblingTypeCounts=g[g.length-1],w=m[this.currentNamespace];w||(w=m[this.currentNamespace]={}),w[this.currentLocalName]=(w[this.currentLocalName]||0)+1,g.push({});let b=this.followingSiblingOrderStack;b[b.length-1]!==null?this.currentFollowingSiblingOrder=--b[b.length-1]:this.currentFollowingSiblingOrder=null,b.push(null);let x=this.followingSiblingTypeCountsStack,y=this.currentFollowingSiblingTypeCounts=x[x.length-1];y&&y[this.currentNamespace]&&y[this.currentNamespace][this.currentLocalName]--,x.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],t,i),this.applyCalcFilter(this.currentStyle,this.context),this.applyCmykFilter(this.currentStyle,this.currentElement),this.applyAttrFilter(i);let P=n.quotes,S=null;if(P){let U=P.evaluate(this.context);U&&(S=new Tw(this.quotes),U===v.none?this.quotes=[new j(""),new j("")]:U===v.auto||U===v.initial?this.quotes=[new j("\u201C"),new j("\u201D"),new j("\u2018"),new j("\u2019")]:U instanceof te&&(this.quotes=U.values))}this.pushCounters(this.currentStyle);let R=this.currentId||this.currentXmlId||i.getAttribute("name")||"";if(p||R){let U=Object.create(null);Object.keys(this.counters).forEach(G=>{U[G]=Array.from(this.counters[G])}),this.counterListener.countersOfId(R,U)}let A=bt(this.currentStyle,"_pseudos");if(A){let U=!0;for(let G of Lw){G||(U=!1);let Z=A[G];if(Z)if((G==="before"||G==="after")&&!(Rt((s=Z.content)==null?void 0:s.value)||this.hasNonTrivialViewConditionalPseudoContent(Z))||G==="marker"&&!Hn((o=ke(this.currentStyle,"display"))==null?void 0:o.value)||(G==="footnote-call"||G==="footnote-marker")&&((a=ke(this.currentStyle,"float"))==null?void 0:a.value)!==v.footnote)delete A[G];else if(U){if(this.processPseudoelementProps(Z,i,G),G==="marker")this.processMarkerPseudoelementProps(Z,i,t),delete A[G];else if(G==="footnote-marker")this.resolvePseudoelementInheritedPropertyValue(Z,"list-style-position",t,i)===v.outside&&(this.processMarkerPseudoelementProps(Z,i,t),this.currentStyle.display=new D(B("list-item"),0),this.currentStyle["list-style-position"]=new D(v.outside,0),this.currentStyle["list-style-type"]=new D(v.none,0),this.currentStyle["list-style-image"]=new D(v.none,0),delete A[G]);else if(G==="first-letter"&&Z["initial-letter"]){let fe=Z["initial-letter"].evaluate(this.context);fe!==v.normal&&!J(fe)&&(this.currentStyle["--viv-initialLetter"]=new D(fe,0)),delete Z["initial-letter"]}}else this.stack[this.stack.length-2].push(new Pw(Z,i))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),S&&this.stack[this.stack.length-2].push(S)}hasNonTrivialViewConditionalPseudoContent(t){let i=t._viewConditionalStyles;return!i||i.length<=0?!1:i.some(n=>{var r;return Rt((r=n.styles.content)==null?void 0:r.value)})}processMarkerPseudoelementProps(t,i,n){var r,s,o,a,h;let l=Hn((r=this.currentStyle.display)==null?void 0:r.value);if(!Rt((s=t.content)==null?void 0:s.value)&&l){let d=this.getInheritedPropertyValue("list-style-type",n,i),p=this.getInheritedPropertyValue("list-style-image",n,i);if(p instanceof ot)t.content=new D(new te([p,new j(" ")]),0);else if(d instanceof j)t.content=new D(d,0);else if(d instanceof de&&d!==v.none){let f=(a=(o=this.currentStyle["ua-list-item-count"])==null?void 0:o.value)==null?void 0:a.num;if(f!=null){let g=d.name.toLowerCase();g==="disc"||g==="circle"||g==="square"||g==="disclosure-open"||g==="disclosure-closed"||(t.content=new D(new j(this.counterStyleStore.formatMarker(d.name,f)),0))}}}let u=t.content;if(u){let d=u.value;if(Rt(d)){let p=this.resolveMarkerContentVal(d);this.currentStyle["--viv-marker-content"]=new D(p,0)}}for(let d of hd.markerAllowedProps){let p=t[d];if(p){let f=p.evaluate(this.context,d);f&&!J(f)&&(this.currentStyle[`--viv-marker-${d}`]=new D(f,0))}}if(!Mt((h=ke(this.currentStyle,"display"))==null?void 0:h.value)){let d=this.getInheritedPropertyValue("list-style-position",n,i);d&&d!==v.outside&&!J(d)&&(this.currentStyle["list-style-position"]=new D(d,0))}}resolveMarkerContentVal(t){if(t instanceof $){let i=t.expr.evaluate(this.context);return typeof i=="string"?new j(i):typeof i=="number"?new j(String(i)):t}if(t instanceof te){let i=t.values.map(n=>this.resolveMarkerContentVal(n));return new te(i)}return t}getInheritedPropertyValue(t,i,n){var r;for(let o=n;o;o=o.parentElement){let a=(o===this.currentElement?this.currentStyle:i.getStyle(o,!1))[t];if(a){let h=a.evaluate(this.context,t);if(h===v.inherit||h===v.unset||h===v.revert)continue;if(h===v.initial)break;return h}}let s=i.validatorSet;return(r=s?.defaultValues[t])!=null?r:null}resolvePseudoelementInheritedPropertyValue(t,i,n,r){var s;let o=t[i];if(o){let a=o.evaluate(this.context,i);if(a!==v.inherit&&a!==v.unset&&a!==v.revert){if(a===v.initial){let h=n.validatorSet;return(s=h?.defaultValues[i])!=null?s:null}return a}}return this.getInheritedPropertyValue(i,n,r)}applyAttrFilterInner(t,i){for(let n in i)Bi(n)&&!jt(n)&&(i[n]=i[n].filterValue(t))}applyAttrFilter(t){let i=new Iw(t),n=this.currentStyle,r=bt(n,"_pseudos");for(let s in r)this.applyAttrFilterInner(i,r[s]);this.applyAttrFilterInner(i,n)}applyVarFilter(t,i,n){var r,s,o;let a=t[0],h=new $w(t,i,n),l=32,u={};for(let d in a)if(Gr(d)){let p=bt(a,d);for(let f in p)this.applyVarFilter([p[f],...t],i,n)}else if(Bi(d)){let p=ke(a,d),f=p.value;for(let g=0;;g++){if(g>=l){f=Y;break}let m=f.visit(h);if(h.error){f=Y,h.error=!1;break}if(m===f)break;f=m}if(f!==p.value){let g=i.validatorSet,m=(r=g?.shorthands[d])==null?void 0:r.clone();if(m)if(J(f)){for(let w of m.propList){let b=new D(f,p.priority),x=ke(a,w);yi(u,w,jo(this.context,x,b))}delete a[d]}else{let w=vr(i.scope,new Xt(f.toString(),null),"");if(w&&(w.visit(m),!m.error)){for(let b of m.propList){let x=new D((o=(s=m.values[b])!=null?s:g.defaultValues[b])!=null?o:v.initial,p.priority),y=ke(a,b);yi(u,b,jo(this.context,y,x))}delete a[d]}}else a[d]=new D(f,p.priority)}if(u[d]){let g=ke(a,d);g&&g.value!==Y&&Dt(u,d,g,this.context)}}for(let d in u)a[d]=u[d]}applyCalcFilter(t,i){let n=new wd(i);for(let r in t)if(Gr(r)){let s=bt(t,r);for(let o in s)this.applyCalcFilter(s[o],i)}else if(Bi(r)&&!jt(r)){let s=ke(t,r),o=s.value.visit(n);o!==s.value&&(t[r]=new D(o,s.priority))}}applyCmykFilter(t,i){let n=new Uu(this.cmykStore);if(this.applyCmykFilterInternal(t,n,""),i){let r=n.getConversions();r&&i.setAttribute("data-viv-device-cmyk",JSON.stringify(r))}}applyCmykFilterInternal(t,i,n){for(let r in t)if(Gr(r)){let s=bt(t,r);for(let o in s)this.applyCmykFilterInternal(s[o],i,`::${o}:`)}else if(Bi(r)&&!jt(r)){let s=ke(t,r),o=s.value.toString();i.reset();let a=s.value.visit(i);a!==s.value&&(i.hadDeviceCmyk()&&i.recordConversion(n+r,o),t[r]=new D(a,s.priority))}}applyActions(){let t;for(t=0;t<this.currentClassNames.length;t++)this.applyAction(this.code.classes,this.currentClassNames[t]);for(t=0;t<this.currentEpubTypes.length;t++)this.applyAction(this.code.epubtypes,this.currentEpubTypes[t]);this.applyAction(this.code.ids,this.currentId),this.applyAction(this.code.tags,this.currentLocalName),this.currentLocalName!=""&&this.applyAction(this.code.tags,"*"),this.applyAction(this.code.nstags,this.currentNSTag),this.currentPageType!==null&&(this.applyAction(this.code.pagetypes,this.currentPageType),this.applyAction(this.code.pagetypes,"*")),this.stack.push([]);for(let i=1;i>=-1;--i){let n=this.stack[this.stack.length-i-2];for(t=0;t<n.length;)n[t].push(this,i)?n.splice(t,1):t++}this.isFirst=!0,this.isRoot=!1}pop(){for(let t=1;t>=-1;--t){let i=this.stack[this.stack.length-t-2],n=0;for(;n<i.length;)i[n].pop(this,t)?i.splice(n,1):n++}this.stack.pop(),this.isFirst=!1}popRule(){this.pop()}popElement(t){this.siblingOrderStack.pop(),this.siblingTypeCountsStack.pop(),this.followingSiblingOrderStack.pop(),this.followingSiblingTypeCountsStack.pop(),this.pop(),this.popCounters()}};c(ld,"markerAllowedProps",["color","font-family","font-size","font-style","font-weight","font-variant","unicode-bidi","direction","white-space","text-transform","text-combine-upright"]);var Fw=ld,lo=[],Lw=["before","footnote-call","footnote-marker","marker","inner","first-letter","first-line","","after"],Ko=null;function Ow(e){Ko=e}var ar=class extends In{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:Ko?Ko.clone():new Rw,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Xa(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 aw(e,t.toLowerCase())):t?this.chain.push(new nh(t.toLowerCase())):this.chain.push(new hw(e)))}invalidSelector(e){W.warn(e),this.chain.push(new Qe("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof kn;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 sw(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new mw);break;case"disabled":this.chain.push(new ww);break;case"checked":this.chain.push(new yw);break;case"root":case"scope":this.chain.push(new pw);break;case"link":this.chain.push(new nh("a")),this.chain.push(new rh("","href"));break;case"href-epub-type":case"href-role-type":if(t&&t.length>=1&&typeof t[0]=="string"){let i=t[0],n=new RegExp(`(^|\\s)${ai(i)}($|\\s)`),r=t[1];this.chain.push(new lw(n,r,e==="href-role-type"))}else this.chain.push(new Qe(""));break;case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Qe(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new dw(new RegExp(`^${ai(i.toLowerCase())}($|-)`)))}else this.chain.push(new Qe(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=Bw[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new Qe(""));break}case"first-child":this.chain.push(new sh);break;case"last-child":this.chain.push(new Yo(0,1));break;case"first-of-type":this.chain.push(new qo(0,1));break;case"last-of-type":this.chain.push(new Zo(0,1));break;case"only-child":this.chain.push(new sh),this.chain.push(new Yo(0,1));break;case"only-of-type":this.chain.push(new qo(0,1)),this.chain.push(new Zo(0,1));break;case"empty":this.chain.push(new gw);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 Qe(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new Qe(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new ow(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let r;switch(i){case 0:r=new rh(e,t);break;case 39:r=new uw(e,t,n);break;case 45:!n||n.match(/\s/)?r=new Qe(""):r=new _n(e,t,new RegExp(`(^|\\s)${ai(n)}($|\\s)`));break;case 44:r=new _n(e,t,new RegExp(`^${ai(n)}($|-)`));break;case 43:n?r=new _n(e,t,new RegExp(`^${ai(n)}`)):r=new Qe("");break;case 42:n?r=new _n(e,t,new RegExp(`${ai(n)}$`)):r=new Qe("");break;case 46:n?r=new _n(e,t,new RegExp(ai(n))):r=new Qe("");break;case 50:if(n=="supported")r=new cw(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${Br++}`;this.processChain(new Or(new Sw(e,this.viewConditionId,null))),this.chain=[new Qe(e)],this.viewConditionId=null}childSelector(){let e=`c${Br++}`;this.processChain(new Or(new Cw(e,this.viewConditionId,null))),this.chain=[new Qe(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${Br++}`;this.processChain(new Or(new kw(e,this.viewConditionId,null))),this.chain=[new Qe(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${Br++}`;this.processChain(new Or(new Ew(e,this.viewConditionId,null))),this.chain=[new Qe(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 Ya(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new Wo(t,0,this.condition):i=new D(t,0),Jc(this.elementStyle,e).push(i)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){this.report(`E_INVALID_PROPERTY_VALUE ${e}: ${t.toString()}`)}unknownProperty(e,t){this.report(`E_INVALID_PROPERTY ${e}: ${t.toString()}`)}simpleProperty(e,t,i){e=="display"&&(t===v.oeb_page_head||t===v.oeb_page_foot)&&(this.simpleProperty("flow-options",new te([v.exclusive,v._static]),i),this.simpleProperty("flow-into",t,i),t=v.block),Ft("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 Wo(t,n,this.condition):new D(t,n);Dt(this.elementStyle,e,r)}finish(){return this.cascade}startFuncWithSelector(e,t){let i;switch(e){case"is":i=new kn(this);break;case"not":i=new Mw(this);break;case"where":i=new _w(this);break;case"has":i=new Dw(this);break;case"nth-child":t&&t.length>=2&&(i=new cd(this,t[0],t[1]));break;case"nth-last-child":t&&t.length>=2&&(i=new zw(this,t[0],t[1]));break}i&&(i.startSelectorRule(),this.owner.pushHandler(i))}},Bw={"nth-child":fw,"nth-of-type":qo,"nth-last-child":Yo,"nth-last-of-type":Zo},Br=0,kn=class ud extends ar{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 vw(this.selectorTexts):this.positive()?new Za(this.chains):new bw(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Qe("")),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 ud;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}},Mw=class extends kn{positive(){return!1}forgiving(){return!1}},_w=class extends kn{increasingSpecificity(){return!1}},Dw=class extends kn{relational(){return!0}},cd=class extends kn{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 id(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Qe("")),this.owner.popHandler()}forgiving(){return!0}},zw=class extends cd{endFuncWithSelector(){this.chain&&this.chains.push(this.chain),this.chains.length>0?(this.maxSpecificity=Math.max(this.maxSpecificity,this.specificity),this.parentChain.push(new xw(this.a,this.b,this.chains)),this.parent.specificity+=256+this.maxSpecificity):this.parentChain.push(new Qe("")),this.owner.popHandler()}},Vw=class extends In{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 gr(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,r))}}},jr=class extends In{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?W.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){W.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){W.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=Ka;let r=this.condition?new Wo(t,n,this.condition):new D(t,n);Dt(this.elementStyle,e,r)}},Uw=class extends dc{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){W.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){W.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?cc:uc;n+=this.order,this.order+=Ka;let r=new D(t,n);Dt(this.elementStyle,e,r)}};function dd(e,t){let i=Zc(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function Jo(e,t,i){dd(i,n=>{Jn(e,n,t)})}function Hw(e,t,i,n){let r=new Uw(e,t),s=new Xt(n,r);try{qg(s,r,i)}catch(o){W.warn(o,"Style attribute parse error:")}return r.elementStyle}function pd(e,t,i){let n=e["writing-mode"];if(n){let r=n.evaluate(t,"writing-mode");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.vertical_rl}return i}function fd(e,t,i){let n=e.direction;if(n){let r=n.evaluate(t,"direction");if(r&&r!==v.inherit&&r!==v.revert&&r!==v.unset)return r===v.rtl}return i}function Qo(e,t,i,n,r){let s={};for(let o in e)Bi(o)&&(s[o]=ke(e,o));return Jo(s,t,e),gd(e,i,n,(o,a)=>{Jn(s,a,t),Jo(s,t,a)}),s}function gd(e,t,i,n){let r=bt(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 Jn(e,t,i){for(let n in t)if(Bi(n)){let r=ke(t,n),s=e[n];e[n]=jo(i,s,r)}}var md=(e,t,i,n,r,s)=>{var o,a;let h=i?n?Zm:Gc:n?Km:jc,l=r?Jm:Qm;for(let u in e){let d=e[u];if(!d)continue;let p=(o=h[u])!=null?o:h[l[u]],f=(a=l[u])!=null?a:l[h[u]],g=p??f,m;if(g){let w=e[g];if(w&&w.priority>d.priority||p&&f&&p!==f&&(g=f,w=e[g],w&&w.priority>d.priority))continue;m=ih[p]?p:ih[f]?f:u}else m=u,u.startsWith("text-align")&&(d.value===v.inside||d.value===v.outside)&&(d=new D(r===(d.value===v.inside)?v.right:v.left,d.priority));t[m]=s(u,d)}},$w=class extends Vi{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 h=(n=a[e])==null?void 0:n.value;if(h)return h}this.element&&(o=this.element.parentElement)}for(;o;o=o.parentElement){let a=(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 de&&e.values[0].name;return!t||!jt(t)?(this.error=!0,Y):this.getVarValue(t)||(e.values.length<2?(this.error=!0,Y):e.values.length===2?e.values[1]:new tt(e.values.slice(1)))}},wd=class extends Vi{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=vr(this.context.rootScope,new Xt(i,null),"");if(n instanceof $)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 F(r,"px"):/\d[a-z]/i.test(i)||(t=new vt(r)))}catch(r){W.warn(r)}return t}visitNumeric(e){return this.resolveViewportUnit&&gu(e.unit)||this.context.rootFontSize!=null&&Sf(e.unit)?new F(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new F(e.num*this.percentRef/100,"px"):e}};function Cs(e,t,i,n,r){try{if(t instanceof $)return t.expr instanceof Ie&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:Jg(e,t.expr,i);if(t instanceof F||t instanceof Ui||t instanceof te||t instanceof tt)return t.visit(new wd(e,!0,n,r))}catch(s){return W.warn(s),Y}return t}var oh={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function ah(e){let t=e instanceof it?e:typeof e=="string"?B(e):v.none;if(t===v.none)return oh;let i=t instanceof te?t.values:[t],n=Object.create(oh);for(let r of i)if(r instanceof de)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 lh(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var Ww={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},hh={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},uh={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function ch(e){let t=e instanceof it?e:typeof e=="string"?B(e):v.normal;if(t===v.normal)return hh;if(t===v.auto)return uh;let i=t instanceof te?t.values:[t],n=Object.create(hh);for(let r of i)if(r instanceof de)switch(r.name){case"trim-both":case"trim-auto":return uh;case"space-all":return Ww;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 ho={ideographAlpha:!1,ideographNumeric:!1},Gw={ideographAlpha:!0,ideographNumeric:!0};function dh(e){let t=e instanceof it?e:typeof e=="string"?B(e):v.normal;if(t===v.normal||t===v.auto)return Gw;if(t===v.none)return ho;let i=t instanceof te?t.values:[t],n=Object.create(ho);for(let r of i)if(r instanceof de)switch(r.name){case"no-autospace":return ho;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function ph(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function fh(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 jw=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=fh(r);let o=dh(t),a=ch(i),h=ah(n);if(lh(h)&&ph(o,a))return;this.preprocessForTextSpacing(e);let l=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 g=!d,m=!d||/\n$/.test(d.textContent),w=!p||/^\n/.test(p.textContent),b=!p;this.processTextSpacing(f,g||m,g,m,w,b,d,p,o,a,h,r,s),d=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,r,s,o,a,h,l;let u=!e||e.fragmentIndex===1&&f(),d=u||g();function p(x){var y;if(x?.nodeType!==1)return!1;let P=x;if(P.hasAttribute(Cn))return!0;let{position:S,float:R}=(y=P.style)!=null?y:{};return S==="absolute"||S==="fixed"||R&&R!=="none"}function f(){let x=t[0];for(let y=x;;y=y.parent)if(!y||!y.inline){if(y?.fragmentIndex!==1)return!1;break}if(!x.inline)return!0;for(let y=x.viewNode.previousSibling;y;y=y.previousSibling)if(!Me(y,x.whitespace)&&!p(y))return!1;return!0}function g(){var x,y;let P=t[0],S;for(;P&&P.inline&&(S=(x=P.viewNode)==null?void 0:x.previousSibling,!(S&&(S.nodeType===Node.TEXT_NODE&&/^[ \t\r\n\f]*$/.test(S.textContent)&&P.whitespace!==dt.PRESERVE&&(S=S.previousSibling),S)));)P=P.parent;for(;S;){if(S.nodeType===Node.ELEMENT_NODE){if(S.localName==="br")return!0;let R=(y=S.style)==null?void 0:y.display;if(R&&R!=="inline")return!/^(inline|ruby)\b/.test(R)}else if(S.nodeType===Node.TEXT_NODE){if(P.whitespace===dt.PRESERVE){if(/\n$/.test(S.textContent))return!0}else if(P.whitespace===dt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(S.textContent))return!0}S=S.lastChild}return!1}let m=-1;for(let x=0;x<t.length;x++){let y=t[x];if(!y.after&&y.inline&&!y.display&&y.parent&&y.viewNode.parentNode&&y.viewNode.nodeType===Node.TEXT_NODE&&!Me(y.viewNode,y.whitespace)){let P=function(E){var T,L,z;if(((T=E.viewNode)==null?void 0:T.nodeType)===Node.ELEMENT_NODE)return E.viewNode.localName==="br";if(((L=E.viewNode)==null?void 0:L.nodeType)===Node.TEXT_NODE){let H=E.viewNode;if(E.whitespace===dt.PRESERVE){if(/\n$/.test(H.textContent))return!0}else if(E.whitespace===dt.NEWLINE&&/\n[ \t\r\n\f]*$/.test(H.textContent))return!0;if(((z=H.previousElementSibling)==null?void 0:z.localName)==="br")return Me(H,E.whitespace)}return!1},S=function(E){var T,L,z;if(((T=E.viewNode)==null?void 0:T.nodeType)===Node.ELEMENT_NODE)return E.viewNode.localName==="br";if(((L=E.viewNode)==null?void 0:L.nodeType)===Node.TEXT_NODE){let H=E.viewNode;if(E.whitespace===dt.PRESERVE){if(/^\n/.test(H.textContent))return!0}else if(E.whitespace===dt.NEWLINE&&/^[ \t\r\n\f]*\n/.test(H.textContent))return!0;if(((z=H.nextElementSibling)==null?void 0:z.localName)==="br")return Me(H,E.whitespace)}return!1};var w=P,b=S;m<0&&(m=x);let R=fh((s=(n=(i=y.lang)!=null?i:y.parent.lang)!=null?n:e?.lang)!=null?s:(r=e?.parent)==null?void 0:r.lang),A=dh(y.inheritedProps["text-autospace"]),U=ch(y.inheritedProps["text-spacing-trim"]),G=ah(y.inheritedProps["hanging-punctuation"]);if(lh(G)&&ph(A,U)||/\b(flex|grid)\b/.test(y.parent.display))continue;let Z=null,fe=null,ue=x===m,C=x===m&&u,_=x===m&&d,k=!1,O=!1;for(let E=x-1;E>=0;E--){let T=t[E];if(P(T)){_=!0;break}if(!T.display&&T.viewNode.nodeType===Node.TEXT_NODE&&T.viewNode.textContent.length>0){Z=T.viewNode;break}if(((o=T.viewNode)==null?void 0:o.nodeType)===Node.ELEMENT_NODE&&Kt(T.viewNode)==="footnote-call"){if(T.viewNode.contains(y.viewNode))continue;let L=Vm(T.viewNode);if(L){Z=L;break}}if(T.display&&!/^(inline|ruby)\b/.test(T.display)||((a=T.viewNode)==null?void 0:a.nodeType)===Node.ELEMENT_NODE&&(T.viewNode.localName==="br"||Oi[T.viewNode.localName]))break;E===0&&(ue=!0,u&&(C=!0,_=!0))}for(let E=x+1;E<t.length;E++){let T=t[E];if(S(T)){k=!0;break}if(T.viewNode!==y.viewNode&&!T.display&&T.viewNode.nodeType===Node.TEXT_NODE&&T.viewNode.textContent.length>0){fe=T.viewNode;break}if(T.display&&!/^(inline|ruby)\b/.test(T.display)||((h=T.viewNode)==null?void 0:h.nodeType)===Node.ELEMENT_NODE&&(T.viewNode.localName==="br"||Oi[T.viewNode.localName])){E===t.length-1&&p(T.viewNode)&&(O=!0);break}if(E===t.length-1){k=!0,O=!0;for(let L=T.viewNode.nextSibling;L;L=L.nextSibling)if(!p(L)){O=!1;break}}}if(((l=y.parent)==null?void 0:l.display)==="inline-block"){if(!C){let E=y.parent.viewNode.firstChild;for(;Me(E,y.whitespace);)E=E.nextSibling;y.viewNode===E&&(C=!0)}if(!O){let E=y.parent.viewNode.lastChild;for(;Me(E,y.whitespace);)E=E.previousSibling;y.viewNode===E&&(O=!0)}}if(this.processTextSpacing(y.viewNode,ue,C,_,k,O,Z,fe,A,U,G,R,y.vertical)>0)break}}}processTextSpacing(e,t,i,n,r,s,o,a,h,l,u,d,p){let f=e.textContent,g=e.ownerDocument,m=0,w,b,x;function y(){if(t)return!0;if(!o)return!1;w||(w=g.createRange(),w.selectNode(e));let k=w.getClientRects()[0];if(!k)return!1;b||(b=g.createRange(),b.selectNode(o));let O=b.getClientRects(),E=O[O.length-1];return E?(m||(m=or(E,p)),p?k.top<E.top+E.height-k.width||k.left+k.width<E.left+k.width/10||k.left>E.left+E.width-k.width/10:k.left<E.left+E.width-k.height||k.top>E.top+E.height-k.height/10||k.top+k.height<E.top+k.height/10):!1}function P(){if(!a)return!1;w||(w=g.createRange(),w.selectNode(e));let k=w.getClientRects()[0];if(!k)return!1;m||(m=or(k,p)),x||(x=g.createRange(),x.selectNode(a));let O=x.getClientRects()[0];return O?p?k.top+k.height>O.top+k.width||k.left>O.left+O.width-k.width/10||k.left+k.width<O.left+k.width/10:k.left+k.width>O.left+k.height||k.top+k.height<O.top+k.height/10||k.top>O.top+O.height-k.height/10:!1}let S=!1,R=!1,A=!1,U=!1,G;if(i&&u.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(G="viv-ts-open",S=!0,R=!0):s&&u.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(G="viv-ts-close",S=!0,A=!0):(u.forceEnd||u.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(G="viv-ts-close",S=!0,U=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(G="viv-ts-open",S=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||d==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||d!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(G="viv-ts-close",S=!0),S){let k=function(z){let H=parseFloat(g.defaultView.getComputedStyle(z).fontSize)*.7;return(p?z.offsetHeight:z.offsetWidth)>H},O=function(){return p?E.offsetLeft:E.offsetTop};var Z=k,fe=O;if(e.parentElement.localName==="viv-ts-inner")return 0;let E=g.createElement(G),T=g.createElement("viv-ts-inner");E.appendChild(T),e.parentNode.insertBefore(E,e),T.appendChild(e);let L=k(T);if(L||R||A||U){if(G==="viv-ts-open"){if(R)E.className="viv-hang-first";else if(i||n)l.trimStart?E.className="viv-ts-trim":E.className="viv-ts-space";else if(!(l.trimStart||l.spaceFirst)&&y())E.className="viv-ts-space";else if(l.trimAdjacent&&o&&/[\p{Ps}\p{Pi}\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]\p{M}*$/u.test(o.textContent)&&(!/[\p{Pe}\p{Pf}]\p{M}*$/u.test(o.textContent)||o.parentElement.localName==="viv-ts-inner"&&k(o.parentElement)))E.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&y()){let z=O();E.className="viv-ts-auto",z===O()&&!y()&&(E.className="viv-ts-trim")}}else if(G==="viv-ts-close"){if(A)E.className=L?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(s||r){let z=O();U?(E.className=L?u.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",u.allowEnd&&z===O()&&(l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-hang-end",z===O()&&(E.className="")):E.className="viv-ts-space")):l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-ts-auto",z===O()&&(E.className="")):E.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))L&&l.trimAdjacent&&(E.className="viv-ts-trim");else if(U){let z=P(),H=z&&u.allowEnd;H||(E.className=L?"viv-hang-end":"viv-hang-end viv-hang-hw"),L?H&&l.trimEnd?E.className="viv-ts-auto":!H&&!P()?E.className="":!z&&u.allowEnd&&(l.trimEnd?(E.className="viv-ts-auto",P()||(E.className="viv-hang-end")):(E.className="viv-ts-space",P()||(l.allowEnd?(E.className="viv-ts-auto",P()||(E.className="viv-hang-end")):E.className="viv-hang-end"))):!z&&!P()&&(E.className="")}else if(l.trimEnd||l.allowEnd)if(P())l.allowEnd?E.className="viv-ts-space":E.className="viv-ts-auto";else{let z=O();E.className="viv-ts-auto",z===O()&&(E.className="")}}}}let ue=!1;function C(k){var O;let E=(O=k?.ownerDocument.defaultView)==null?void 0:O.getComputedStyle(k);return!!E&&(E.textOrientation==="upright"||E.textCombineUpright==="all"||E["-webkit-text-combine"]==="horizontal")}function _(k,O){if(k.nodeType===Node.ELEMENT_NODE){let L=g.defaultView.getComputedStyle(k);if(parseFloat(L.marginInlineEnd)||parseFloat(L.borderInlineEndWidth)||parseFloat(L.paddingInlineEnd))return!0}let E=k.parentElement;if(E&&!E.contains(O))return _(E,O);if(O.nodeType===Node.ELEMENT_NODE){let L=g.defaultView.getComputedStyle(O);if(parseFloat(L.marginInlineStart)||parseFloat(L.borderInlineStartWidth)||parseFloat(L.paddingInlineStart))return!0}let T=O.parentElement;return T&&!T.contains(k)?_(k,T):!1}return(h.ideographAlpha||h.ideographNumeric)&&(o&&/^(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]/u.test(f)&&(h.ideographAlpha&&/(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}\p{M}*$/u.test(o.textContent)||h.ideographNumeric&&/(?![\uFF01-\uFF60])\p{Nd}\p{M}*$/u.test(o.textContent))&&!(p&&C(o.parentElement))&&!_(o,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),ue=!0),a&&/(?!\p{P})[\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF]\p{M}*$/u.test(f)&&(h.ideographAlpha&&/^(?![\p{sc=Han}\u3041-\u30FF\u31C0-\u31FF\uFF01-\uFF60])\p{L}/u.test(a.textContent)||h.ideographNumeric&&/^(?![\uFF01-\uFF60])\p{Nd}/u.test(a.textContent))&&!(p&&C(a.parentElement))&&!_(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),ue=!0)),m}registerHooks(){kt("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),kt("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),kt("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},Ja=new jw;Ja.registerHooks();function Xw(e){Ja.preprocessForTextSpacing(e)}function qw(e,t,i,n,r,s){Ja.processGeneratedContent(e,t,i,n,r,s)}var $n=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),Yw=["footnote-marker","marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],Qa="data-adapt-pseudo";function Kt(e){return e.getAttribute(Qa)||""}function Xr(e,t){e.setAttribute(Qa,t)}var uo=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=Kt(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=bt(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 D(new Be(s),0)}return r}processContent(e,t,i){let n=Kt(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let r=t.content;Rt(r)&&(r.visit(new sr(e,this.context,r,this.exprContentListener)),Xw(e))}}},v0=gs.isInstanceOfAfterIfContinuesLayoutConstraint,Zw=$s.registerFragmentIndex,x0=$s.clearFragmentIndices,Kw=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new el(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 I(s,"display","block"),N(s)})}createNodePositionForPseudoElement(){let e=$n.createElementNS("http://www.w3.org/1999/xhtml","div");Xr(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 xi(i)}createShadowContext(e){return new $r(this.sourceNode,e,null,null,null,ri.ShadowType.ROOTED,this.styler)}},Jw=class yd{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 Qw(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof yd?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},Qw=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 bd(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=ty(e,t,n);return t.fragmentLayoutConstraints.push(new Jw(e,i,r)),N(e)})}function vd(e,t){return e.thenAsync(i=>bd(i,t))}function ey(e,t){let i=M("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let r=bd(n,t);return n=n.parent,r.thenReturn(!0)}else return N(!1)}).then(()=>{i.finish(!0)}),i.result()}function ty(e,t,i){let n=e.viewNode;n.appendChild(i);let r=zo(i,t,e.vertical);return n.removeChild(i),r}var iy=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},qr=class extends $a{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]}},ks=class extends Rc{constructor(e,t,i,n,r){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=r,c(this,"last"),c(this,"viewDocument"),c(this,"flowRootFormattingContext",null),c(this,"isNonFirstColumn",!1),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,"lastLineStride",0),c(this,"breakAtTheEdgeBeforeFloat",null),Bm(this),this.last=e.lastChild,this.viewDocument=e.ownerDocument,r.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}almostEquals(e,t,i=1.5/(this.clientLayout.pixelRatio||1)){return Math.abs(e-t)<i}isOverflown(e){return this.almostEquals(e,this.footnoteEdge)?!1:this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let t=M("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,r=null;return t.loop(()=>{for(;n>=0;){let s=r,o=i[n];if(r=ws(o,s),n===i.length-1&&!r.formattingContext&&(r.formattingContext=this.flowRootFormattingContext),n==0&&(r.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),r.after=e.after,r.preprocessedTextContent=e.preprocessedTextContent,r.after))break;let a=this.layoutContext.setCurrent(r,n==0&&r.offsetInNode==0);if(n--,a.isPending())return a}return N(!1)}).then(()=>{t.finish(r)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?hm(e.preprocessedTextContent,e.offsetInNode):e.offsetInNode}maybePeelOff(e,t){var i,n;if(e.firstPseudo&&e.inline&&!e.after&&e.firstPseudo.count==0&&e.viewNode.nodeType!=1){let r=e.viewNode.textContent,s=r.match(us),o=s?s[0].length:0;if(!s&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&r===e.sourceNode.textContent){let a=r+e.sourceNode.nextSibling.textContent,h=a.match(us);if(h){let l=h[0];o=l.length,e.sourceNode.textContent=l,e.viewNode.textContent=l,e.sourceNode.nextSibling.textContent=a.substr(o)}}return this.layoutContext.peelOff(e,o)}return N(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=M("buildViewToNextBlockEdge");return n.loopWithFrame(r=>{var s;if(e.viewNode&&!ln(e)&&((s=e.viewNode.parentElement)==null?void 0:s.namespaceURI)==="http://www.w3.org/1999/xhtml"&&(t.push(e.copy()),t.length>1e3)){let o=e.viewNode.nodeType===1?e.viewNode:e.viewNode.parentElement,a=this.clientLayout.getElementClientRect(o);if(or(a,this.vertical)>=2){r.breakLoop();return}}this.maybePeelOff(e,0).then(o=>{let a=o;a!==e&&(e=a,ln(e)||t.push(e.copy())),this.nextInTree(e).then(h=>{if(e=h,!e){r.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(wi(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(l=>{if(e=l,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()}):e.inline?r.continueLoop():r.breakLoop()})})}).then(()=>{n.finish(e)}),n.result()}nextInTree(e,t){let i=this.layoutContext.nextInTree(e,t);return vd(i,this)}buildDeepElementView(e){if(!e.viewNode)return N(e);let t=[],i=e.sourceNode,n=M("buildDeepElementView");return n.loopWithFrame(r=>{e.viewNode&&e.inline&&!ln(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(s=>{let o=s;if(o!==e){let a=o;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=o,r.breakLoop();return}ln(o)||t.push(o.copy())}this.nextInTree(o).then(a=>{if(e=a,!e||e.sourceNode==i){r.breakLoop();return}if(!this.layoutConstraint.allowLayout(e)&&(e=e.modify(),e.overflow=!0,this.stopAtOverflow)){r.breakLoop();return}if(this.isFloatNodeContext(e)&&(wi(e.floatReference)||e.floatSide==="footnote")){this.layoutFloatOrFootnote(e).then(h=>{if(e=h,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){r.breakLoop();return}r.continueLoop()});return}r.continueLoop()})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let r=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),I(r,"height",`${i}px`),I(r,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),I(r,"width",`${i}px`),I(r,"height",`${n}px`)),I(r,"float",t),I(r,"clear",t),this.element.insertBefore(r,e),r}killFloats(){let e=this.element.firstChild;for(;e;){let t=e.nextSibling;if(e.nodeType==1){let i=e,n=i.style.cssFloat;if(n=="left"||n=="right"||n==="none")this.element.removeChild(i);else break}e=t}}createFloats(){let e=this.element.firstChild,t=this.bands,i=this.vertical?this.getTopEdge():this.getLeftEdge(),n=this.vertical?this.getBottomEdge():this.getRightEdge(),r=this.vertical?-this.getRightEdge():this.getTopEdge(),s=this.vertical?-this.getLeftEdge():this.getBottomEdge(),o=null;for(let d of t)this.almostEquals(d.x1,i)?d.x1=i:this.almostEquals(d.x1,n)&&(d.x1=n),this.almostEquals(d.x2,n)?d.x2=n:this.almostEquals(d.x2,i)&&(d.x2=i),this.almostEquals(d.y1,r)?d.y1=r:this.almostEquals(d.y1,s)&&(d.y1=s),this.almostEquals(d.y2,s)?d.y2=s:this.almostEquals(d.y2,r)&&(d.y2=r);let a=1/(this.clientLayout.pixelRatio||1),h=Pa==="webkit"?Math.floor:Math.round,l=t.map(d=>(h(d.y2/a)-h(d.y1/a))*a),u=.01;for(let d=0;d<t.length;d++){let p=d<t.length-1?t[d+1].x1:i,f=d<t.length-1?t[d+1].x2:n,g=p-t[d].x1,m=t[d].x2-f,w=0,b=0;g>u?w=1:g<-u&&(w=-1),m>u?b=1:m<-u&&(b=-1);let x=w!==0&&b!==0?w===b?w:0:w||b;if(x!==0){let y=x*a;l[d]+y>=0&&(d>=t.length-1||l[d+1]-y>=0)&&(l[d]+=y,d<t.length-1&&(l[d+1]-=y))}}for(let d=0;d<t.length;d++){let p=t[d];p.left=this.createFloat(e,"left",p.x1-i,l[d]),p.right=this.createFloat(e,"right",n-p.x2,l[d]),p.x1<n&&p.x2>i?o=p:o||I(p.right,"float","none")}if(o){let d=t[t.length-1];if(o!==d&&d.y2>=s&&(this.footnoteEdge=this.vertical?-o.y2:o.y2,o.x1===i&&o.x2===n))for(let p=t.indexOf(o);p<t.length;p++){let f=t[p];this.element.removeChild(f.left),this.element.removeChild(f.right),f.left=null,f.right=null}}this.adjustColumnBlockSizeForBlockEndFloats()}adjustColumnBlockSizeForBlockEndFloats(){var e;if(this.element.hasAttribute("data-vivliostyle-in-column-balancing")||(e=this.element.parentElement)!=null&&e.hasAttribute("data-vivliostyle-in-column-balancing"))return;let t=this.vertical?this.width:this.height,i=this.getBoxDir()*(this.footnoteEdge-this.beforeEdge);if(i>0&&i<t&&!this.almostEquals(i,t)){let n=this.vertical?"width":"height";if(I(this.element,n,`${i}px`),this.vertical){let r=this.left+(t-i);I(this.element,"left",`${r}px`)}this.element.setAttribute("data-vivliostyle-column-block-size-adjusted","true")}}calculateEdge(e,t,i,n){let r;if(e&&an(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(r=tn(e,this.clientLayout,0,this.vertical),!isNaN(r)))return r;e=t[i];let s=n-e.boxOffset;for(;;){if(r=tn(e,this.clientLayout,s,this.vertical),!isNaN(r))return r;if(s>0){s--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(s=e.viewNode.textContent.length)}}parseComputedLength(e){let t=e.match(/^(-?[0-9]*(\.[0-9]*)?)px$/);return t?this.clientLayout.adjustLengthValue(parseFloat(t[0])):0}getComputedMargin(e){let t=this.clientLayout.getElementComputedStyle(e),i=new to(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.marginLeft),i.top=this.parseComputedLength(t.marginTop),i.right=this.parseComputedLength(t.marginRight),i.bottom=this.parseComputedLength(t.marginBottom)),i}getComputedPaddingBorder(e){let t=this.clientLayout.getElementComputedStyle(e),i=new to(0,0,0,0);return t&&(i.left=this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)),i}getComputedInsets(e){let t=this.clientLayout.getElementComputedStyle(e),i=new to(0,0,0,0);if(t){if(t.boxSizing=="border-box")return this.getComputedMargin(e);i.left=this.parseComputedLength(t.marginLeft)+this.parseComputedLength(t.borderLeftWidth)+this.parseComputedLength(t.paddingLeft),i.top=this.parseComputedLength(t.marginTop)+this.parseComputedLength(t.borderTopWidth)+this.parseComputedLength(t.paddingTop),i.right=this.parseComputedLength(t.marginRight)+this.parseComputedLength(t.borderRightWidth)+this.parseComputedLength(t.paddingRight),i.bottom=this.parseComputedLength(t.marginBottom)+this.parseComputedLength(t.borderBottomWidth)+this.parseComputedLength(t.paddingBottom)}return i}setComputedInsets(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.marginLeft=this.parseComputedLength(i.marginLeft),t.borderLeft=this.parseComputedLength(i.borderLeftWidth),t.paddingLeft=this.parseComputedLength(i.paddingLeft),t.marginTop=this.parseComputedLength(i.marginTop),t.borderTop=this.parseComputedLength(i.borderTopWidth),t.paddingTop=this.parseComputedLength(i.paddingTop),t.marginRight=this.parseComputedLength(i.marginRight),t.borderRight=this.parseComputedLength(i.borderRightWidth),t.paddingRight=this.parseComputedLength(i.paddingRight),t.marginBottom=this.parseComputedLength(i.marginBottom),t.borderBottom=this.parseComputedLength(i.borderBottomWidth),t.paddingBottom=this.parseComputedLength(i.paddingBottom))}setComputedWidthAndHeight(e,t){let i=this.clientLayout.getElementComputedStyle(e);i&&(t.width=this.parseComputedLength(i.width),t.height=this.parseComputedLength(i.height))}layoutUnbreakable(e){return this.buildDeepElementView(e)}layoutFloat(e){let t=M("layoutFloat"),i=e.viewNode,n=oo(e.floatSide,e.vertical,e.direction,this.layoutContext.page.side);return I(i,"float","none"),I(i,"display","inline-block"),I(i,"vertical-align","top"),this.buildDeepElementView(e).then(r=>{let s=It(this.clientLayout,i,this.vertical),o=this.getComputedMargin(i),a=new Ct(s.left-o.left,s.top-o.top,s.right+o.right,s.bottom+o.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,u=e.parent;for(;u&&u.inline;)u=u.parent;if(u){let y=u.viewNode.ownerDocument.createElement("div");y.style.left="0px",y.style.top="0px",this.vertical?(y.style.bottom="0px",y.style.width="1px"):(y.style.right="0px",y.style.height="1px"),u.viewNode.appendChild(y);let P=It(this.clientLayout,y,this.vertical);h=Math.max(this.rtl?this.getEndEdge(P):this.getStartEdge(P),h),l=Math.min(this.rtl?this.getStartEdge(P):this.getEndEdge(P),l),u.viewNode.removeChild(y);let S=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+S):h=Math.min(h,l-S),u!==e.parent&&!e.firstPseudo&&(u.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let d=new Ct(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),p=a;this.vertical&&(p=ds(a));let f=this.getBoxDir();if(p.y1<this.bottommostFloatTop*f){let y=p.y2-p.y1;p.y1=this.bottommostFloatTop*f,p.y2=p.y1+y}if(e.clearSide){let y=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(e.clearSide)?oo(e.clearSide,e.vertical,e.direction,this.layoutContext.page.side):e.clearSide==="same"?n:e.clearSide,P=this.beforeEdge;y!=="right"&&(P=f*Math.max(P*f,this.leftFloatEdge*f)),y!=="left"&&(P=f*Math.max(P*f,this.rightFloatEdge*f));let S=P*f;if(p.y1<S){let R=p.y2-p.y1;p.y1=S,p.y2=p.y1+R}}d.y2+=1/(this.clientLayout.pixelRatio||1),Zf(d,this.bands,p,n),this.vertical&&(a=Gu(p));let g=this.getComputedInsets(i);I(i,"width",`${a.x2-a.x1-g.left-g.right}px`),I(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),I(i,"position","absolute"),e.display,I(i,"display",e.display);let m,w=null;if(u&&(u.containingBlockForAbsolute?w=u:w=u.getContainingBlockForAbsolute()),w){let y=w.viewNode.ownerDocument.createElement("div");y.style.position="absolute",w.vertical?y.style.right="0":y.style.left="0",y.style.top="0",w.viewNode.appendChild(y),m=It(this.clientLayout,y,this.vertical),w.viewNode.removeChild(y)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(w?w.vertical:this.vertical)?I(i,"right",`${m.right-a.x2}px`):I(i,"left",`${a.x1-m.left}px`),I(i,"top",`${a.y1-m.top}px`),e.clearSpacer&&(e.clearSpacer.parentNode.removeChild(e.clearSpacer),e.clearSpacer=null);let b=this.vertical?a.x1:a.y2,x=this.vertical?a.x2:a.y1;!this.isOverflown(b)||this.breakPositions.length==0?(this.killFloats(),d=new Ct(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(d=ds(d)),Kf(d,this.bands,p,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=b:this.rightFloatEdge=b,this.bottommostFloatTop=x,this.updateMaxReachedAfterEdge(b),t.finish(r)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,r,s){let o=this.pageFloatLayoutContext,a=o.getContainer(t),h=e.element;a.element.parentNode.appendChild(h),e.isFloat=!0,e.originX=a.originX,e.originY=a.originY,e.vertical=a.vertical,e.rtl=a.rtl,e.marginLeft=e.marginRight=e.marginTop=e.marginBottom=0,e.borderLeft=e.borderRight=e.borderTop=e.borderBottom=0,e.paddingLeft=e.paddingRight=e.paddingTop=e.paddingBottom=0,e.exclusions=(a.exclusions||[]).concat(),e.forceNonfitting=!o.hasFloatFragments(),e.innerShape=null;let l=a.getPaddingRect();return e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),r.adjustPageFloatArea(e,a,this).thenAsync(()=>{e.init();let u=!!o.setFloatAreaDimensions(e,t,i,n,!0,!o.hasFloatFragments(),s);return u?(e.killFloats(),e.init()):a.element.parentNode.removeChild(h),N(u)})}createPageFloatArea(e,t,i,n,r){let s=this.element.ownerDocument.createElement("div");I(s,"position","absolute");let o=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new en(null,Te.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null);a.setOuterContext(this.pageFloatLayoutContext);let h=o.getContainer(),l=new sy(t,s,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,r).thenAsync(u=>N(u?l:null))}layoutSinglePageFloatFragment(e,t,i,n,r,s,o){let a=this.pageFloatLayoutContext;e=(o?o.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),u={floatArea:null,pageFloatFragment:null,newPosition:null},d=M("layoutSinglePageFloatFragment");return this.createPageFloatArea(h,t,s,r,l).then(p=>{if(u.floatArea=p,!p){d.finish(u);return}let f=!1,g=0;d.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let w=e[g],b=new xi(w.nodePosition);p.layout(b,!0).then(x=>{u.newPosition=x,!x||n?(g++,m.continueLoop()):(f=!0,m.breakLoop())})}).then(()=>{if(!f){p.isFootnote&&p.applyCompactFootnoteDisplay();let m=a.setFloatAreaDimensions(p,h.floatReference,t,s,!1,n,l);if(!m)f=!0;else{let w=r.createPageFloatFragment(e,m,i,p,!!u.newPosition);a.addPageFloatFragment(w,!0),u.pageFloatFragment=w}}d.finish(u)})}),d.result()}layoutPageFloatInner(e,t,i,n){let r=this.pageFloatLayoutContext,s=e.float,o=new Set;for(let l=r;l;l=l.effectiveParent)for(let u of l.floatFragments)u.continuations.some(d=>d.float.insidePageFloatArea)&&o.add(u);r.stashEndFloatFragments(s);function a(l,u){u?r.removePageFloatFragment(u,!0):l&&l.element.parentNode.removeChild(l.element);let d=[];for(let p=r;p;p=p.effectiveParent)for(let f of p.floatFragments)!o.has(f)&&f.continuations.some(g=>g.float.insidePageFloatArea)&&d.push(f);for(let p of d)r.removePageFloatFragment(p,!0);r.restoreStashedFragments(s.floatReference),r.deferPageFloat(e)}let h=M("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],s.floatSide,s.clearSide,!r.hasFloatFragments(),t,i,n).then(l=>{let u=l.floatArea,d=l.pageFloatFragment,p=l.newPosition;d?this.layoutStashedPageFloats(s.floatReference,[n]).then(f=>{if(f){let g=!!r.generatingNodePosition;if(r.addPageFloatFragment(d,g),r.discardStashedFragments(s.floatReference),p){let m=new Kl(s,p.primary);r.deferPageFloat(m)}h.finish(!0)}else a(u,d),h.finish(!1)}):(a(u,d),h.finish(!1))}),h.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),r=[],s=[],o=!1,a=M("layoutStashedPageFloats"),h=0;return a.loopWithFrame(l=>{if(h>=n.length){l.breakLoop();return}let u=n[h];if(t.includes(u)){h++,l.continueLoop();return}let d=new Sn().findByFloat(u.continuations[0].float);this.layoutSinglePageFloatFragment(u.continuations,u.floatSide,u.clearSide,!1,d,null).then(p=>{let f=p.floatArea;f&&r.push(f);let g=p.pageFloatFragment;g?(s.push(g),h++,l.continueLoop()):(o=!0,l.breakLoop())})}).then(()=>{o?(s.forEach(l=>{i.removePageFloatFragment(l,!0)}),r.forEach(l=>{let u=l.element;u&&u.parentNode&&u.parentNode.removeChild(u)})):n.forEach(l=>{let u=l.area.element;u&&u.parentNode&&u.parentNode.removeChild(u)}),a.finish(!o)}),a.result()}findFootnoteCallElement(e){let t=e.previousSibling;for(;t;){if(t.nodeType===Node.ELEMENT_NODE&&Kt(t)==="footnote-call")return t;t=t.previousSibling}return null}setFloatAnchorViewNode(e){let t=e.viewNode.parentNode,i=t.ownerDocument.createElement("span");if(i.setAttribute(Cn,"1"),e.floatSide==="footnote"){let r=this.findFootnoteCallElement(e.viewNode);r?i=r:t.insertBefore(i,e.viewNode)}else t.appendChild(i);t.removeChild(e.viewNode);let n=e.modify();return n.after=!0,n.viewNode=i,e.floatSide==="footnote"&&(n.display="inline"),n}resolveFloatReferenceFromColumnSpan(e,t,i){let n=M("resolveFloatReferenceFromColumnSpan"),r=this.pageFloatLayoutContext,s=r.getPageFloatLayoutContext(Te.REGION);return r.getContainer().width<s.getContainer().width&&e===Te.COLUMN?t===v.auto?this.buildDeepElementView(i.copy()).then(o=>{let a=o.viewNode,h=za(this.clientLayout,a,["min-content inline size"])["min-content inline size"],l=this.getComputedMargin(a);this.vertical?h+=l.top+l.bottom:h+=l.left+l.right,h>this.width?n.finish(Te.REGION):n.finish(e)}):t===v.all?n.finish(Te.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Sn().findByNodeContext(e),n,r=t.findPageFloatByNodePosition(e.toNodePosition());return r?n=N(r):n=i.createPageFloat(e,t,this),n.thenAsync(s=>{let o=ms(e,0),a=this.setFloatAnchorViewNode(e),h=i.findPageFloatFragment(s,t),l=new Kl(s,o);if(h&&h.hasFloat(s))return t.registerPageFloatAnchor(s,a.viewNode),N(a);if(t.isForbidden(s)||t.hasPrecedingFloatsDeferredToNext(s))return t.deferPageFloat(l),t.registerPageFloatAnchor(s,a.viewNode),N(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return N(null);{let u=tn(a,this.clientLayout,0,this.vertical);return this.isOverflown(u)?N(a):this.layoutPageFloatInner(l,i,u,h).thenAsync(d=>d?e.floatSide==="footnote"||t.generatingNodePosition?N(a):N(null):(t.registerPageFloatAnchor(s,a.viewNode),N(a)))}})}processLineStyling(e,t,i){let n=M("processLineStyling"),r=i.concat([]);i.splice(0,i.length);let s=0,o=e.firstPseudo;return o.count==0&&(o=o.outer),n.loopWithFrame(a=>{if(!o){a.breakLoop();return}let h=this.findLinePositions(r),l=o.count-s;if(h.length<=l){a.breakLoop();return}let u=this.findAcceptableBreakInside(r,h[l-1],!0);if(u==null){a.breakLoop();return}this.finishBreak(u,!1,!1).then(()=>{s+=l,this.layoutContext.peelOff(u,0).then(d=>{e=d,o=e.firstPseudo,r=[],this.buildViewToNextBlockEdge(e,r).then(p=>{t=p,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,r),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&Oi[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let r=e[n];if(!r||!r.after||!r.viewNode||r.viewNode.nodeType!=1)break;let s=this.getComputedMargin(r.viewNode),o=this.vertical?-s.left:s.bottom;o>0?t=Math.max(t,o):i=Math.min(i,o)}return t+i}layoutBreakableBlock(e){let t=M("layoutBreakableBlock"),i=[];return this.buildViewToNextBlockEdge(e,i).then(n=>{let r=i.length-1;if(r<0){t.finish(n);return}this.postLayoutBlock(n,i);let s=this.suppressOpenAncestorBlockEndInset(n??e),o=this.calculateEdge(n,i,r,i[r].boxOffset);s();let a=!1;if(!n||!an(n.viewNode)){let l=mn(n,this.collectElementsOffset());a=this.isOverflown(o+(this.vertical?-1:1)*l.minimum),this.isOverflown(o+(this.vertical?-1:1)*l.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(o+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(o);let h;e.firstPseudo?h=this.processLineStyling(e,n,i):h=N(n),h.then(l=>{i.length>0&&(this.saveBoxBreakPosition(i),a&&!this.isLoneImage(i)&&l&&(l=l.modify(),l.overflow=!0)),t.finish(l)})}),t.result()}postLayoutBlock(e,t){Ft("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,r=0,s=t[0].boxOffset,o=r,a=t.length-1,h=t[a].boxOffset,l;for(;s<h;){l=s+Math.ceil((h-s)/2),o=r;let u=a;for(;o<u;){let p=o+Math.ceil((u-o)/2);t[p].boxOffset>l?u=p-1:o=p}let d=this.calculateEdge(null,t,o,l);if(this.vertical?d<=n:d>=n){for(h=l-1;t[o].boxOffset==l;)o--;a=o}else i&&this.updateMaxReachedAfterEdge(d),s=l,r=o}return{nodeContext:t[o],index:s,checkPointIndex:o}}findAcceptableBreakInside(e,t,i){var n,r,s;let o=this.findEndOfLine(t,e,!0),a=o.nodeContext;if(o.checkPointIndex===0&&o.index===a.boxOffset)return null;let h=a.viewNode;if(h.nodeType!=1&&((n=h.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let l=h;a=this.resolveTextNodeBreaker(a).breakTextNode(l,a,o.index,e,o.checkPointIndex,i)}else{let l=th(a);if(l){if(((r=this.breakPositions)==null?void 0:r[0])instanceof qr&&l!=null&&l.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;for(a=l;!a.after&&a.inline&&a.parent;){let u=(s=a.viewNode)==null?void 0:s.previousSibling;for(;u&&(Me(u,a.parent.whitespace)||hi(u));)u=u.previousSibling;if(u)break;a=a.parent}}}return this.clearOverflownViewNodes(a,!1),a}resolveTextNodeBreaker(e){return Ft("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Es.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),r=!1,s=e,o=null,a=!1,h=!0;for(;h;){let l=!0;do{let u=null;s==t&&(t.nodeType===1?h=!(!t.firstChild||r):h=!1);let d=s.nodeType===1?s:null;d?r?r=!1:Ha(d)?l=!a:!d.firstChild||Oi[d.localName]||/^r(uby|[bt]c?)$/.test(d.localName)||zm(this.clientLayout.getElementComputedStyle(d).display)?(l=!a,l?(d.localName==="ruby"&&s.firstChild&&(s=s.firstChild),n.setStartBefore(s),a=!0,o=s):/^r(uby|tc?)$/.test(d.localName)||(o=s),s.contains(t)&&(h=!1)):u=s.firstChild:(a||(s.parentNode==null?h=!1:(n.setStartBefore(s),a=!0)),o=s),u||(u=s.nextSibling,u||(r=!0,u=s.parentNode)),s=u}while(l&&h);if(a){n.setEndAfter(o);let u=this.clientLayout.getRangeClientRects(n);Do(u,this.vertical);for(let d=0;d<u.length;d++)i.push(u[d]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?ym:wm);let n=0,r=0,s=0,o=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],u=1;if(o>0){let d=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?u=h*(this.getAfterEdge(l)-n)/d:h*this.getAfterEdge(l)>h*r?u=h*(r-this.getBeforeEdge(l))/d:u=1}if(o==0||u>=.6||u>=.2&&this.getStartEdge(l)>=s-1){s=this.getEndEdge(l),this.vertical?(n=o==0?l.right:Math.max(n,l.right),r=o==0?l.left:Math.min(r,l.left)):(n=o==0?l.top:Math.min(n,l.top),r=o==0?l.bottom:Math.max(r,l.bottom)),o++,a++;continue}}if(o>0&&(t.push(r),o=0),a>=i.length)break}return t.sort(uu),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&on(i.viewNode)){let n=this.getComputedPaddingBorder(i.viewNode);t+=i.vertical?-n.left:n.bottom,i.display==="table"&&(t+=(i.vertical?-1:1)*i.blockBorderSpacing)}return t}getOffsetByRepetitiveElements(e){let t;return e?t=e.calculateOffset(this):t=mn(null,this.collectElementsOffset()),t.current}findBoxBreakPosition(e,t){let i=this.element.parentNode,n=this.element.nextSibling;i.removeChild(this.element),i.insertBefore(this.element,n);let r=e.checkPoints,s=r[0];for(;s.parent&&s.inline;)s=s.parent;let o,a;t?(o=1,a=1):(o=Math.max((s.inheritedProps.widows||2)-0,1),a=Math.max((s.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(s),l=this.findLinePositions(r),u=this.footnoteEdge-h,d=this.getBoxDir(),p=this.getOffsetByRepetitiveElements(e);u-=d*p;let f=this.findFirstOverflowingEdgeAndCheckPoint(r);isNaN(f.edge)&&(f.edge=d*(1/0));let g=ni(l.length,x=>{let y=l[x];return this.vertical?y<u||y<=f.edge:y>u||y>=f.edge}),m=g<=0;m&&(g=ni(l.length,x=>this.vertical?l[x]<u:l[x]>u));let w=r[r.length-1].viewNode;if(w?.parentElement.localName==="viv-ts-inner"&&(w=w.parentElement.parentElement),(g===l.length&&w.nextSibling||g>=l.length-1&&w.parentElement.querySelector(".MJXc-display"))&&(o=0,a=1),g=Math.min(l.length-o,g),g<a)return null;u=l[g-1];let b;if(m?b=f.checkPoint:b=this.findAcceptableBreakInside(e.checkPoints,u,t),b){let x=this.getAfterEdgeOfBlockContainer(b);if(!isNaN(x)&&d*(u-x)>0&&(u=x),this.computedBlockSize=d*(u-this.beforeEdge)+p,l.length>=2){let y=Math.max(1,Math.min(g-1,l.length-1));this.lastLineStride=Math.abs(l[y]-l[y-1])}}return b}getAfterEdgeOfBlockContainer(e){let t=e;do t=t.parent;while(t&&t.inline);return t?(t=t.copy().modify(),t.after=!0,tn(t,this.clientLayout,0,this.vertical)):NaN}findFirstOverflowingEdgeAndCheckPoint(e){let t=e.findIndex(n=>n.overflow);if(t<0)return{edge:NaN,checkPoint:null};let i=e[t];return{edge:this.calculateEdge(null,e,t,i.boxOffset),checkPoint:i}}findEdgeBreakPosition(e){return this.computedBlockSize=e.computedBlockSize+this.getOffsetByRepetitiveElements(e),e.position}finishBreak(e,t,i){e.formattingContext;let n=new Mn().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=Ga.finishBreak(this,e,t,i)),n}findAcceptableBreakPosition(){let e=null,t=null,i=0,n=0;do{i=n,n=Number.MAX_VALUE;for(let r=this.breakPositions.length-1;r>=0&&!t;--r){e=this.breakPositions[r],t=e.findAcceptableBreak(this,i);let s=e.getMinBreakPenalty();s>i&&(n=Math.min(n,s))}}while(n>i&&!t&&this.forceNonfitting);return{breakPosition:t?e:null,nodeContext:t}}doFinishBreak(e,t,i,n){if(this.pageFloatLayoutContext.isInvalidated()||this.pageBreakType||!t)return N(e);let r=M("doFinishBreak"),s=!1;if(!e){if(this.forceNonfitting)return W.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(o=>{o?(o=o.modify(),o.overflow=!1,this.finishBreak(o,s,!0).then(()=>{r.finish(o)})):r.finish(o)}),r.result();e=i,s=!0,this.computedBlockSize=n}return this.finishBreak(e,s,!0).then(()=>{r.finish(e)}),r.result()}isBreakable(e){for(let t=e;t;t=t.parent)if(hi(t.viewNode))return!1;if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}isZeroLength(e){let t=e.trim();return t===""||/^0+(?:\.0+)?(?:[a-z%]*)$/i.test(t)}hasNonZeroBlockStartInset(e){return this.vertical?!(this.isZeroLength(e.paddingRight)&&this.isZeroLength(e.borderRightWidth)):!(this.isZeroLength(e.paddingTop)&&this.isZeroLength(e.borderTopWidth))}hasNonZeroBlockEndInset(e){return this.vertical?!(this.isZeroLength(e.paddingLeft)&&this.isZeroLength(e.borderLeftWidth)):!(this.isZeroLength(e.paddingBottom)&&this.isZeroLength(e.borderBottomWidth))}suppressOpenAncestorBlockEndInset(e){if(!bs(this))return()=>{};let t=[];for(let i=e?.parent;i;i=i.parent){if(i.after||i.inline)continue;let n=i.viewNode;if(!n||n.nodeType!==1||on(n))continue;let r=this.clientLayout.getElementComputedStyle(n);if(r&&!this.hasNonZeroBlockEndInset(r))continue;let s=n.getAttribute("data-viv-box-break");gt(n,"block-end"),t.push({element:n,original:s})}return()=>{for(let{element:i,original:n}of t)n===null?i.removeAttribute("data-viv-box-break"):i.setAttribute("data-viv-box-break",n)}}checkOverflowAndSaveEdge(e,t){if(!e)return!1;for(let o=e;o;o=o.parent)if(hi(o.viewNode))return!1;if(an(e.viewNode))return!1;let i=this.suppressOpenAncestorBlockEndInset(e),n=tn(e,this.clientLayout,0,this.vertical);i();let r=mn(e,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=e;else if(t){let o=n+this.getTrailingMarginEdgeAdjustment(t),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(e,t,i,n){if(!e||an(e.viewNode))return!1;let r=this.checkOverflowAndSaveEdge(e,t);return(i||!r)&&this.saveEdgeBreakPosition(e,n,r),r}applyClearance(e){if(!e.viewNode.parentNode||e.floatReference!==Te.INLINE||e.floatSide)return!1;let t=this.getComputedMargin(e.viewNode),i=e.viewNode.ownerDocument.createElement("div");this.vertical?(i.style.bottom="0px",i.style.width="1px",i.style.marginRight=`${t.right}px`):(i.style.right="0px",i.style.height="1px",i.style.marginTop=`${t.top}px`),e.viewNode.parentNode.insertBefore(i,e.viewNode);let n=It(this.clientLayout,i,this.vertical),r=this.getBeforeEdge(n),s=this.getBoxDir(),o=e.clearSide==="same"?e.floatSide:e.clearSide,a=/^(top|bottom|inside|outside|(block|inline)-(start|end))$/.test(o)?oo(o,e.vertical,e.direction,this.layoutContext.page.side):o,h=a==="left"||a==="right"?e.direction==="rtl"==(a==="left")?"inline-end":"inline-start":a,l=this.pageFloatLayoutContext.getPageFloatClearEdge(h,this),u=l;switch(a){case"left":l=s*Math.max(l*s,this.leftFloatEdge*s);break;case"right":l=s*Math.max(l*s,this.rightFloatEdge*s);break;default:l=s*Math.max(l*s,Math.max(this.rightFloatEdge*s,this.leftFloatEdge*s))}let d=1/(this.clientLayout.pixelRatio||1),p=l*s>u*s;l=s*(Math.ceil(l*s/d)+(p?1:0))*d;let f=d;if(r*s+f>l*s)return e.viewNode.parentNode.removeChild(i),!1;{let g=Math.max(1,(l-r)*s);this.vertical?i.style.width=`${g}px`:i.style.height=`${g}px`,n=It(this.clientLayout,i,this.vertical);let m=this.getAfterEdge(n);if(!e.floatSide)if(this.vertical){let w=m-t.right-l;w>0==t.right>=0&&(w+=t.right),i.style.marginLeft=`${w}px`}else{let w=l-(m+t.top);w>0==t.top>=0&&(w+=t.top),i.style.marginBottom=`${w}px`}return e.clearSpacer=i,!0}}isBFC(e){return!!(Um(e)||Mi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}hasFixedPositionAncestor(e){for(let t=e;t;t=t.parent)if(eh(t.viewNode))return!0;return!1}skipEdges(e,t,i){var n;let r=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(r&&!this.isBFC(r))return N(e);let s=M("skipEdges"),o=this,a=!i&&t&&e&&e.after,h=i,l=null,u=[],d=[],p=!1;function f(P){var S,R;if(!(!t||o.isNonFirstColumn||i||!ql(h))){for(let A=P;A;A=A.parent)if(A.breakBefore==="column"&&(A.breakBefore=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let U=A.viewNode;((R=U.style)==null?void 0:R.breakBefore)==="column"&&(U.style.breakBefore="")}}}function g(P){var S,R;if(!(!t||!o.isNonFirstColumn||i||h!=="column")){for(let A=P;A;A=A.parent)if(A.breakBefore==="column"&&(A.breakBefore=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let U=A.viewNode;((R=U.style)==null?void 0:R.breakBefore)==="column"&&(U.style.breakBefore="")}h=null}}function m(P){var S,R;if(!(i||!ql(h))){for(let A=P;A;A=A.parent)if(A.breakAfter==="column"&&(A.breakAfter=null),((S=A.viewNode)==null?void 0:S.nodeType)===1){let U=A.viewNode;((R=U.style)==null?void 0:R.breakAfter)==="column"&&(U.style.breakAfter="")}}}function w(P){h=et(h,P)}function b(){return i?!0:Ge(h)?t?o.isNonFirstColumn&&h!=="column"&&h!=="region":!x():!1}function x(){var P;if(!l||!e||e.floatSide)return!1;for(let S=l;S!=null&&S.parent;S=S.parent){if(S.parent.viewNode&&hi(S.parent.viewNode))continue;let R=S.after?S.viewNode:(P=S.viewNode)==null?void 0:P.previousSibling;for(;R&&(Me(R,S.parent.whitespace)||hi(R));)R=R.previousSibling;if(R)return!1}return!0}let y=()=>{e=u[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=h};return s.loopWithFrame(P=>{for(var S;e;){e.formattingContext;let R=new Mn().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Me(e.viewNode,e.whitespace)||this.hasFixedPositionAncestor(e))break;if(!e.after){b()?y():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)?(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0):(!l&&!t&&u.length===0&&this.saveEdgeBreakPosition(e,h,!1),e=e.modify(),e.breakBefore=h),P.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=fs(h)?h:null),R&&R.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),h,!1),!e.inline&&!e.repeatOnBreak&&(l?th(l):this.breakPositions[this.breakPositions.length-1]instanceof qr||!t&&u.length===0)&&this.saveEdgeBreakPosition(e.copy(),h,!1),!this.isBFC(e.formattingContext)||Mi.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Me(e.sourceNode.firstChild,e.whitespace)){u.push(e.copy()),w(e.breakBefore),f(e),g(e),b()?y():(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),P.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let U=e.viewNode,G=U.style;if(e.after){zc(U,this),e.floatSide&&(h=h??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let Z=e.sourceNode;if(Z.localName==="svg"||Z.localName==="math"||Z.getAttribute("data-math-typeset")==="true"){p=!1,l=e.copy(),d.push(l),h=null,w(e.breakAfter),m(e),this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h);break}if(e.inline||R&&R.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(eh(e.viewNode))break;if(b()){y(),P.breakLoop();return}u=[],t=!1,a=!1,h=null}p=!1,Uc(e.viewNode)||(l=e.copy(),d.push(l)),w(e.breakAfter),m(e),G&&!hi(e.viewNode)&&this.hasNonZeroBlockEndInset(G)&&(d=l?[l]:[])}else{if(u.push(e.copy()),w(e.breakBefore),f(e),g(e),l&&Ge(h)&&Mm(l.viewNode,e.viewNode),(e.pageType!=((S=e.parent)==null?void 0:S.pageType)||!Ge(h))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!this.stopAtOverflow,h),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){P.breakLoop();return}let Z=e.viewNode.localName;if(Oi[Z]){b()?y():this.checkOverflowAndSaveEdgeAndBreakPosition(l,null,!0,h)&&(e=(this.stopAtOverflow&&l||e).modify(),e.overflow=!0),P.breakLoop();return}G&&this.hasNonZeroBlockStartInset(G)&&(a=!1,d=[]),p=!0}}while(!1);let A=this.nextInTree(e,a);if(A.isPending()){A.then(U=>{e=U,P.continueLoop()});return}else e=A.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(l,d,!this.stopAtOverflow,h)?l&&this.stopAtOverflow&&(e=l.modify(),e.overflow=!0):Ge(h)&&(this.pageBreakType=h),P.breakLoop()}).then(()=>{l&&(this.lastAfterPosition=l.toNodePosition()),s.finish(e)}),s.result()}skipTailEdges(e){let t=e.copy(),i=M("skipEdges"),n=null,r=!1;return i.loopWithFrame(s=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Me(e.viewNode,e.whitespace))break;if(!e.after){Ge(n)&&(this.pageBreakType=n),s.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=et(n,e.breakBefore),Ge(n)&&(this.pageBreakType=n),s.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(r){if(Ge(n)){this.pageBreakType=n,s.breakLoop();return}n=null}r=!1,n=et(n,e.breakAfter)}else{n=et(n,e.breakBefore);let h=e.viewNode.localName;if(Oi[h]){Ge(n)&&(this.pageBreakType=n),s.breakLoop();return}if(a&&this.hasNonZeroBlockStartInset(a)){s.breakLoop();return}}r=!0}while(!1);let o=this.layoutContext.nextInTree(e);if(o.isPending()){o.then(a=>{e=a,s.continueLoop()});return}else e=o.get()}t=null,s.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){if(wi(e.floatReference)||e.floatSide==="footnote"){let t=this.pageFloatLayoutContext.generatingNodePosition;if(t&&e.sourceNode===t.steps[0].node){let i=e.modify();return i.floatSide=null,i.floatReference=Te.INLINE,i.clearSide=null,this.isBreakable(i)?this.layoutBreakableBlock(i):this.layoutUnbreakable(i)}return this.layoutPageFloat(e)}else return this.layoutFloat(e)}layoutNext(e,t,i){let n=M("layoutNext");return this.skipEdges(e,t,i||null).then(r=>{if(e=r,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let s=e.formattingContext;new Mn().find(s).layout(e,this,t).thenFinish(n)}}),n.result()}clearOverflownViewNodes(e,t){if(e)for(let i=e.parent;e;e=i,i=i?i.parent:null){let n=(i||e).formattingContext;new Mn().find(n).clearOverflownViewNodes(this,i,e,t),t=!1}}initGeom(){let e=this.element.ownerDocument.createElement("div");e.style.position="absolute",e.style.top=`${this.paddingTop}px`,e.style.right=`${this.paddingRight}px`,e.style.bottom=`${this.paddingBottom}px`,e.style.left=`${this.paddingLeft}px`,this.element.appendChild(e);let t=this.clientLayout.getElementClientRect(e);this.element.removeChild(e);let i=this.originX+this.left+this.getInsetLeft(),n=this.originY+this.top+this.getInsetTop();this.box=new Ct(i,n,i+this.width,n+this.height),this.startEdge=t?this.vertical?this.rtl?t.bottom:t.top:this.rtl?t.right:t.left:0,this.endEdge=t?this.vertical?this.rtl?t.top:t.bottom:this.rtl?t.left:t.right:0,this.beforeEdge=t?this.vertical?t.right:t.top:0,this.afterEdge=t?this.vertical?t.left:t.bottom:0,this.leftFloatEdge=this.beforeEdge,this.rightFloatEdge=this.beforeEdge,this.bottommostFloatTop=this.beforeEdge,this.footnoteEdge=this.afterEdge,this.bands=Xf(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],I(this.element,"width",`${this.width}px`),I(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null,this.lastLineStride=0}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),r=new Mn().find(e.formattingContext),s=this.calculateClonedPaddingBorder(n),o=r.createEdgeBreakPosition(n,t,i,this.computedBlockSize+s);this.breakPositions.push(o)}saveBoxBreakPosition(e){let t=e[0].breakPenalty;if(t){let n=e[0];for(;n.parent&&n.inline;)n=n.parent;t=n.breakPenalty}let i=new qr(e,t);this.breakPositions.push(i)}updateMaxReachedAfterEdge(e){if(!isNaN(e)){let t=this.getBoxDir()*(e-this.beforeEdge);this.computedBlockSize=Math.max(t,this.computedBlockSize)}}layout(e,t,i){if(this.chunkPositions.push(e),e.primary.after&&(this.lastAfterPosition=e.primary),this.stopAtOverflow&&this.overflown)return N(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?N(null):N(e);Ua(this);let n=M("layout");return this.openAllViews(e.primary).then(r=>{let s=null;if(r.viewNode)s=r.copy();else{let a=h=>{h.nodeContext.viewNode&&(s=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let o=new ny(t,i);o.layout(r,this).then(a=>{this.doFinishBreak(a,o.context.overflownNodeContext,s,o.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=N(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(bs(this)&&(Dm(this),Us(this)),this.element.hasAttribute("data-vivliostyle-column-block-size-adjusted")&&(this.vertical?(I(this.element,"width",`${this.width}px`),I(this.element,"left",`${this.left}px`)):I(this.element,"height",`${this.height}px`),this.element.removeAttribute("data-vivliostyle-column-block-size-adjusted")),this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let u=new xi(h.toNodePosition());n.finish(u)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=M("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((r,s)=>r.getPriorityOfFinishBreak()-s.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):N(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=M("doLayout"),r=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(s=>{for(;e;){let o=!0;if(this.layoutNext(e,t,i||null).then(a=>{if(t=!1,i=null,this.nodeContextOverflowingDueToRepetitiveElements&&this.stopAtOverflow?(this.pageBreakType=null,e=this.nodeContextOverflowingDueToRepetitiveElements,e.overflow=!0):e=a,this.pageFloatLayoutContext.isInvalidated())s.breakLoop();else if(this.pageBreakType)s.breakLoop();else if(e&&this.stopByOverflow(e)){r=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),s.breakLoop()}else o?o=!1:s.continueLoop()}),o){o=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),s.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:r})}),n.result()}redoLayout(){let e=this.chunkPositions,t=this.element.lastChild;for(;t!=this.last;){let o=t.previousSibling;this.element===t.parentNode&&this.layoutContext.isPseudoelement(t)||this.element.removeChild(t),t=o}this.killFloats(),this.init();let i=M("redoLayout"),n=0,r=null,s=!0;return i.loopWithFrame(o=>{if(n<e.length){let a=e[n++];this.layout(a,s).then(h=>{s=!1,h?(r=h,o.breakLoop()):o.continueLoop()});return}o.breakLoop()}).then(()=>{i.finish(r)}),i.result()}saveDistanceToBlockEndFloats(){let e=this.pageFloatLayoutContext.getBlockStartEdgeOfBlockEndFloats();e>0&&isFinite(e)&&(this.blockDistanceToBlockEndFloats=this.getBoxDir()*(e-this.beforeEdge-this.computedBlockSize))}collectElementsOffset(){let e=[];for(let t=this;t;t=t.pseudoParent)t.fragmentLayoutConstraints.forEach(i=>{if(Mi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(gs.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}bi.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},el=class{constructor(e,t,i){c(this,"startNodeContexts",[]),c(this,"column"),c(this,"flowRootSourceNode"),this.flowRootSourceNode=i.sourceNode,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 ks.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 xr(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 vi(e.toNodePosition(),this.column.lastAfterPosition)||this.isEffectivelyLastAfterNodeContext(e)}isEffectivelyLastAfterNodeContext(e){var t;let i=this.flowRootSourceNode,n=e.sourceNode;if(!i||!n||!e.after||i!==n&&!((t=i.contains)!=null&&t.call(i,n)))return!1;if(n.nodeType===Node.TEXT_NODE){let r=n;if(e.offsetInNode<r.length){let s=r.data.slice(e.offsetInNode);if(!kc(s,e.whitespace))return!1}}for(let r=n;r&&r!==i;r=r.parentNode)for(let s=r.nextSibling;s;s=s.nextSibling)if(!Me(s,e.whitespace))return!1;return!0}getColumnElement(){return this.column.element}getColumn(){return this.column}},Es=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+gh(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&&Sl(r)&&Sl(s)?gh(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};c(Es,"instance");Es.instance=new Es;function gh(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var ny=class extends ja{constructor(e,t){super(),this.leadingEdge=e,c(this,"breakAfter"),c(this,"initialPageBreakType",null),c(this,"initialComputedBlockSize",0),c(this,"initialOverflown",!1),c(this,"initialLastLineStride",0),c(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new ry(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||$m()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&Vc(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,this.initialLastLineStride=t.lastLineStride}restoreState(e,t){super.restoreState(e,t),t.pageBreakType=this.initialPageBreakType,t.computedBlockSize=this.initialComputedBlockSize,t.overflown=this.initialOverflown,t.lastLineStride=this.initialLastLineStride}},ry=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=M("DefaultLayoutMode.doLayout");return ey(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}},sy=class extends ks{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 h=ci(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),u=o*l/100;I(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=>{ci(e,s)==="auto"&&I(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=ci(t,"height");n!==""&&n!=="auto"&&I(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=ci(t,"width");n!==""&&n!=="auto"&&I(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}))}getContentBlockMarginAfter(){return this.rootViewNodes.length===0?0:Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=this.floatMargins[t];return this.vertical?i.left:i.bottom}))}applyCompactFootnoteDisplay(){let e=this.layoutContext,t=e?.styler,i=e?.xmldoc,n=this.rootViewNodes.filter(h=>{var l,u,d;let p=h.getAttribute($t);if(!p||!t||!i)return!1;let f=i.getNodeByOffset(parseInt(p,10));if(!f||f.nodeType!==Node.ELEMENT_NODE)return!1;let g=t.getStyle(f,!1),m=(u=(l=ke(g,"footnote-display"))==null?void 0:l.value)==null?void 0:u.toString(),w=!!((d=ke(g,"--viv-marker-content"))!=null&&d.value);return m==="compact"&&!w});if(n.length===0){this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea();return}let r=this.element.getBoundingClientRect(),s=this.vertical?r.height:r.width;n.forEach(h=>{I(h,"display","inline"),h.style.setProperty("--viv-footnote-white-space","nowrap")});let o=1.5/(this.clientLayout.pixelRatio||1),a=h=>{let l=h.cloneNode(!0);l.style.removeProperty("--viv-footnote-inline-separator"),I(l,"display","inline-block"),I(l,"position","absolute"),I(l,"visibility","hidden"),I(l,"white-space","nowrap"),I(l,"max-width","none"),I(l,"left","0"),I(l,"top","0"),this.element.appendChild(l);let u=l.getBoundingClientRect();return this.element.removeChild(l),this.vertical?u.height:u.width};n.forEach(h=>{a(h)>s+o&&(I(h,"display","block"),h.style.removeProperty("--viv-footnote-white-space"))}),this.updateInlineFootnoteSeparators(),this.updateComputedBlockSizeForFootnoteArea()}updateComputedBlockSizeForFootnoteArea(){if(this.rootViewNodes.length===0){this.computedBlockSize=0;return}let e=this.getBoxDir();this.computedBlockSize=Math.max(0,...this.rootViewNodes.map(t=>{let i=It(this.clientLayout,t,this.vertical),n=this.getComputedMargin(t),r=this.vertical?n.left:n.bottom;return e*(this.getAfterEdge(i)-this.beforeEdge)+Math.max(0,r)}))}updateInlineFootnoteSeparators(){this.rootViewNodes.forEach((e,t)=>{var i,n;let r=e,s=(i=r.ownerDocument.defaultView)==null?void 0:i.getComputedStyle(r).display,o=this.rootViewNodes[t+1],a=(n=o?.ownerDocument.defaultView)==null?void 0:n.getComputedStyle(o).display;s==="inline"&&a==="inline"?r.style.setProperty("--viv-footnote-inline-separator",'" "'):r.style.removeProperty("--viv-footnote-inline-separator")})}},zi=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||Uo.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new oy(e,this.rootSourceNode),Uo.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},oy=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=ms(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=ms(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=zo(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=zo(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 el(n,o,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new xi(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,s.removeChild(o),this.moveChildren(o,s,i),a.getColumn().pageBreakType=h,N(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(Cn,"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}},xd=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}},Sd=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},ay=class extends xd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},ly=class extends Sd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new tl(e)),this.processor.doLayout(e,t)}},tl=class Cd{constructor(t){c(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),c(this,"nodeContext");let i=Jt(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||an(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=Jt(this.nodeContext.formattingContext),r=this.getRepetitiveElements();if(!r)return N(!0);let s=this.nodeContext;return py(n,s,i).thenAsync(()=>fy(n,s,i).thenAsync(()=>(r.prepareLayoutFragment(),N(!0))))}getRepetitiveElements(){return Jt(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof Cd?Jt(this.nodeContext.formattingContext)===Jt(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},hy=class extends ja{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 ay(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new ly(this.formattingContext,this.processor))}},uy=class extends Kn{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 Kn.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):Kn.prototype.afterNonInlineElementNode.call(this,e)}},cy=class extends hn{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=Jt(e.formattingContext);return n.getRootViewNode(e)?(i&&kd(e.parent,t),e.belongsTo(n)?hn.prototype.layout.call(this,e,t,i):new hy(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=gy(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=Jt(e.formattingContext),n=M("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=Jt(e.formattingContext),n=new uy(i,t);return new Vo(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=Jt(e.formattingContext),n=M("doLayout"),r=t.layoutContext.nextInTree(e,!1);return vd(r,t).then(s=>{let o=s;n.loopWithFrame(a=>{for(;o;){let h=!0;if(t.layoutNext(o,!1).then(l=>{o=l,t.pageFloatLayoutContext.isInvalidated()||t.pageBreakType||o&&t.stopByOverflow(o)||o&&o.after&&o.sourceNode==i.rootSourceNode?a.breakLoop():h?h=!1:a.continueLoop()}),h){h=!1;return}}a.breakLoop()}).then(()=>{n.finish(o)})}),n.result()}finishBreak(e,t,i,n){return hn.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){hn.prototype.clearOverflownViewNodes(e,t,i,n)}};function dy(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof zi&&!i.belongsTo(n)&&t(n,i)}}function kd(e,t){e&&dy(e.after?e.parent:e,(i,n)=>{bi.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new tl(n))})}function py(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 fy(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 gy(e){let t=e.formattingContext;return!t||!(t instanceof zi)?null:t}function Jt(e){return e instanceof zi,e}var my=new cy;kt("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof zi&&!bi.isInstanceOfTableFormattingContext(e)?my:null);var Ed=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,c(this,"cells",[]),c(this,"breakBefore",null),c(this,"breakAfter",null)}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},wy=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}},yy=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},by=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,c(this,"pseudoColumn"),c(this,"empty",!1),this.pseudoColumn=new el(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&I(e,"vertical-align","top"),i&&i!=="normal"&&I(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return I(e,"vertical-align",t),i&&i!=="normal"&&I(e,"align-content",i),n}},vy=class{constructor(e,t){this.viewNode=e,this.side=t}},xy=class extends xr{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)?this.hasUnfinishedCells()?null:i:null}hasUnfinishedCells(){let e=this.getRowIndex(),t=this.formattingContext.getCellsFallingOnRow(e);for(let i of t){if(i.rowIndex+i.rowSpan-1>e)continue;let n=this.formattingContext.getCellFragmentOfCell(i);if(n){let r=n.findAcceptableBreakPosition();if(r.nodeContext&&!n.pseudoColumn.isLastAfterNodeContext(r.nodeContext))return!0}}return!1}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)}},Sy=class extends $a{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,h=s.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});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 qr&&n[o].cellNodeContext.sourceNode.rowSpan>1);return i.forEach((s,o)=>{let a=s.breakPosition.getMinBreakPenalty();r&&s.breakPosition instanceof xr&&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)}},wn=class extends zi{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){var i;if(!t)return t;switch(e.display){case"table-row":return this.cellBreakPositions.length===0&&e.fragmentIndex<=1;case"table-cell":return e.fragmentIndex>1||((i=e.parent)==null?void 0:i.display)==="table-row"&&e.parent.fragmentIndex>1?!1:!this.cellBreakPositions.some(n=>n.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 Ed(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 yy(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 Cy(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(Mi.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}bi.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=[].concat(e)}},Cy=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=mn(e,n);i=Math.max(i,t(r))}),i}};function Tt(e){return e instanceof wn,e}function ky(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Ey(e){return e==="table"||e==="inline-table"}function mh(e){return ky(e)||Ey(e)}function Pd(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 wn)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof wn){o=a.formattingContext===t;break}}return o||r==="table-row"&&!mh(s)||r==="table-cell"&&s!=="table-row"&&!mh(s)||n.formattingContext instanceof wn&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,N(!0))):null}function Nd(e,t){let i=t.nodeContext;return!(i!=null&&i.floatSide)||!(wi(i.floatReference)||i.floatSide==="footnote")?null:e.layoutFloatOrFootnote(i).thenAsync(n=>(n&&(t.nodeContext=n),N(!0)))}var Py=class extends Kn{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=Pd(e,t,this.column);if(i)return i;this.postLayoutBlockContents(e);let n=Nd(this.column,e);if(n)return n;let r=e.nodeContext,s=r.display,o=t.getRepetitiveElements();switch(s){case"table":t.inlineBorderSpacing=r.inlineBorderSpacing;break;case"table-caption":{let a=new vy(r.viewNode,r.captionSide);t.captions.push(a);break}case"table-header-group":return o.isHeaderRegistered()||(this.inHeaderOrFooter=!0,o.setHeaderNodeContext(r)),N(!0);case"table-footer-group":return o.isFooterRegistered()||(this.inHeaderOrFooter=!0,o.setFooterNodeContext(r)),N(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,r.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new Ed(this.rowIndex,r.sourceNode)),r.breakBefore&&(t.rows[this.rowIndex].breakBefore=r.breakBefore),o.firstContentSourceNode||(o.firstContentSourceNode=r.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":if(!this.inHeaderOrFooter){t.lastRowViewNode=i.viewNode,this.inRow=!1;let s=t.rows[this.rowIndex];s&&i.breakAfter&&(s.breakAfter=et(s.breakAfter,i.breakAfter))}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 wy(this.rowIndex,this.columnIndex,s)),this.columnIndex++;let o=t.rows[this.rowIndex];o&&(i.breakBefore&&(o.breakBefore=et(o.breakBefore,i.breakBefore)),i.breakAfter&&(o.breakAfter=et(o.breakAfter,i.breakAfter)))}break}return super.afterNonInlineElementNode(e)}startNonElementNode(e){this.registerCheckPoint(e)}afterNonElementNode(e){this.registerCheckPoint(e)}startInlineElementNode(e){this.registerCheckPoint(e)}afterInlineElementNode(e){this.registerCheckPoint(e)}registerCheckPoint(e){let t=e.nodeContext;t&&t.viewNode&&!ln(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},Td=class Id extends Kn{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}startNonInlineElementNode(t){return Nd(this.column,t)||super.startNonInlineElementNode(t)}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;o>1&&(I(a,"box-sizing","border-box"),I(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let h=a.ownerDocument.createElement("div");a.appendChild(h);let l=new by(this.column,h,i);return this.formattingContext.addCellFragment(r,s,l),n.primary.steps.length===1&&n.primary.after&&(l.empty=!0),l.pseudoColumn.layout(n,!0).thenReturn(!0)}findBrokenCellAtSlot(t,i){let n=this.formattingContext.cellBreakPositions;for(let r=0;r<n.length;r++){let s=n[r];if(s.cell.anchorSlot.columnIndex===t&&s.cellNodePosition.steps[0].node===i)return{position:s,index:r}}return null}extractRowSpanningCellBreakPositions(){let t=this.formattingContext.cellBreakPositions;if(t.length===0)return[];let i=[],n=0;do{let r=t[n],s=r.cell,o=s.rowIndex;if(o<this.currentRowIndex&&o+s.rowSpan>this.currentRowIndex){let a=i[o];a||(a=i[o]=[]),a.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=M("layoutRowSpanningCellsFromPreviousFragment"),h=N(!0),l=0,u=[];return n.forEach(d=>{h=h.thenAsync(()=>{let p=ws(d[0].cellNodePosition.steps[1],o.parent);return s.setCurrent(p,!1).thenAsync(()=>{let f=N(!0),g=0;function m(w){for(;g<w;){if(!u.includes(g)){let b=p.viewNode.ownerDocument.createElement("td");I(b,"padding","0"),p.viewNode.appendChild(b)}g++}}return d.forEach(w=>{f=f.thenAsync(()=>{let b=w.cell;m(b.anchorSlot.columnIndex);let x=w.cellNodePosition,y=ws(x.steps[0],p);return y.offsetInNode=x.offsetInNode,y.after=x.after,y.fragmentIndex=x.steps[0].fragmentIndex+1,s.setCurrent(y,!1).thenAsync(()=>{let P=w.breakChunkPosition;for(let S=0;S<b.colSpan;S++)u.push(g+S);return g+=b.colSpan,this.layoutCell(b,y,P).thenAsync(()=>(y.viewNode.rowSpan=b.rowIndex+b.rowSpan-this.currentRowIndex+r-l,N(!0)))})})}),f.thenAsync(()=>(m(i.getColumnCount()),l++,N(!0)))})})}),h.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(()=>{var r;this.registerCellFragmentIndex();let s=t.breakAtTheEdge;if(this.currentRowIndex>0){let a=n.rows[this.currentRowIndex-1];a!=null&&a.breakAfter&&(s=et(s,a.breakAfter))}let o=n.rows[this.currentRowIndex];return o!=null&&o.breakBefore&&(s=et(s,o.breakBefore)),!t.leadingEdge&&Ge(s)?(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,s),(r=i.viewNode)!=null&&r.parentNode&&i.viewNode.parentNode.removeChild(i.viewNode),t.lastAfterNodeContext&&this.column.layoutContext.processFragmentedBlockEdge(t.lastAfterNodeContext),this.column.pageBreakType=s,this.resetColumn(),t.break=!0,N(!0)):(this.column.checkOverflowAndSaveEdgeAndBreakPosition(t.lastAfterNodeContext,null,!0,s)&&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.find(n=>n.cell===t);if(i){let n=i.cellNodePosition.steps[0],r=this.column.layoutContext.xmldoc.getElementOffset(n.node);Zw(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=M("startTableCell"),o,a=this.findBrokenCellAtSlot(n.anchorSlot.columnIndex,i.sourceNode);if(a){let h=a.position;this.formattingContext.cellBreakPositions.splice(a.index,1),i.fragmentIndex=h.cellNodePosition.steps[0].fragmentIndex+1,o=N(h.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(h=>{h.viewNode&&i.viewNode.removeChild(h.viewNode);let l=ms(h,0);return N(new xi(l))});return o.then(h=>{this.layoutCell(n,i,h).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,s.finish(!0)})}),s.result()}startNonInlineBox(t){let i=Pd(t,Tt(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 Sy(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)):I(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)):I(i.viewNode,"display","table-row-group")),r&&Id.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(Td,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Ny=Td,lr=[];function Ty(e){let t=lr.findIndex(n=>n.root===e),i=lr[t];return i?i.tableLayoutOption:null}function Iy(e){let t=lr.findIndex(i=>i.root===e);t>=0&&lr.splice(t,1)}var Ad=class{layoutEntireTable(e,t){let i=Tt(e.formattingContext),n=new Py(i,t);return new Vo(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let r=e.ownerDocument,s=r.createElement("tr"),o=[];for(let h=0;h<t;h++){let l=r.createElement("td");s.appendChild(l),o.push(l)}e.parentNode.insertBefore(s,e.nextSibling);let a=o.map(h=>{let l=It(n,h,i),u=i?l.height:l.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),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,o,t),l.forEach((u,d)=>{I(u,n?"height":"width",`${a[d]}px`)}),h.forEach(u=>{s.appendChild(u.cloneNode(!0))}),e.colGroups=s}doInitialLayout(e,t){let i=Tt(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Ty(e.sourceNode);Iy(e.sourceNode);let r=M("TableLayoutProcessor.doInitialLayout"),s=e.copy();return this.layoutEntireTable(e,t).then(o=>{let a=o.viewNode,h=It(t.clientLayout,a,t.vertical),l=t.vertical?h.left:h.bottom;if(l+=(t.vertical?-1:1)*mn(e,t.collectElementsOffset()).current,!t.isOverflown(l)&&(!n||!n.calculateBreakPositionsInside)&&!this.hasForcedBreakInRows(i)){t.breakPositions.push(new Ly(s)),r.finish(o);return}this.normalizeColGroups(i,a,t),i.updateCellSizes(t.clientLayout),r.finish(null)}),r.result()}hasForcedBreakInRows(e){for(let t=0;t<e.rows.length;t++){let i=e.rows[t];if(i&&(t>0&&Ge(i.breakBefore)||t<e.rows.length-1&&Ge(i.breakAfter)))return!0}return!1}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),I(t,"table-layout","fixed"),I(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=Tt(e.formattingContext),n=i.getRootViewNode(e),r=n.firstChild;this.addCaptions(i,n,r),this.addColGroups(i,n,r);let s=new Ny(i,t),o=new Vo(s,t.layoutContext),a=M("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=Tt(e.formattingContext);return n.getRootViewNode(e)?(i&&kd(e.parent,t),new Ry(n,this).layout(e,t)):t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new xy(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return co(e),!1}finishBreak(e,t,i,n){let r=Tt(t.formattingContext);if(t.display==="table-row"){t.sourceNode;let s=r.findRowIndexBySourceNode(t.sourceNode),o;if(t.after?o=r.getRowSpanningCellsOverflowingTheRow(s):o=r.getCellsFallingOnRow(s),r.cellBreakPositions=r.cellBreakPositions.filter(a=>!o.includes(a.cell)),o.length){let a=M("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===o.length){l.breakLoop();return}let u=o[h++],d=r.getCellFragmentOfCell(u),p=d.findAcceptableBreakPosition().nodeContext,f=d.cellNodeContext,g=f.toNodePosition(),m=new xi(p.toNodePosition());r.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,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?l.continueLoop():d.pseudoColumn.finishBreak(p,!1,!0).then(()=>{Ay(d,r,p),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),co(t),r.finishFragment(),a.finish(!0)}),a.result()}}return co(t),r.finishFragment(),Ga.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){hn.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,h=It(s.clientLayout,a,r),l=s.getComputedPaddingBorder(a);if(r){let u=h.right-s.footnoteEdge-n.calculateOffset(i)-l.right;I(o,"max-width",`${u}px`)}else{let u=s.footnoteEdge-n.calculateOffset(i)-h.top-l.top;I(o,"max-height",`${u}px`)}}function co(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(),g=e.vertical?f.width:f.height;return d+g},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 h=a.getBoundingClientRect(),l=e.vertical?h.width:h.height,u=n+l;I(a,e.vertical?"width":"height",`${u}px`)}var Ry=class extends ja{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new Fy(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new By(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()}},Fy=class extends xd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},Ly=class extends xr{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 Oy(this.position.sourceNode))}},Oy=class Rd{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,lr.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return N(!0)}equalsTo(t){return t instanceof Rd&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},By=class extends Sd{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new My(e);t.fragmentLayoutConstraints.some(r=>n.equalsTo(r))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},My=class Fd extends tl{constructor(t){super(t),c(this,"flagmentLayoutConstraintType","TableRow"),c(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let r=this.getRepetitiveElements();return!r||n.pseudoParent||an(this.nodeContext.viewNode)||!r.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=Tt(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=Tt(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 Ad().removeColGroups(s,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,r)}finishBreak(t,i){let n=Tt(this.nodeContext.formattingContext),r=M("finishBreak"),s=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.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=Tt(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof Fd?Tt(this.nodeContext.formattingContext)===Tt(t.nodeContext.formattingContext):!1}},_y=new Ad;function Dy(e,t,i,n,r,s){if(!t)return null;if(i===v.table){let o=e.parent;return new wn(o?o.formattingContext:null,e.sourceNode)}return null}function zy(e){return e instanceof wn?_y:null}kt("RESOLVE_FORMATTING_CONTEXT",Dy);kt("RESOLVE_LAYOUT_PROCESSOR",zy);function wh(e){return e.reduce((t,i)=>t+i,0)/e.length}function Vy(e){let t=wh(e);return wh(e.map(i=>{let n=i-t;return n*n}))}var Uy=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function hr(e){return e.vertical?e.width:e.height}function ur(e,t){e.vertical?e.width=t:e.height=t}var Ld=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,c(this,"originalContainerBlockSize"),this.originalContainerBlockSize=hr(e)}balanceColumns(e){let t=M("ColumnBalancer#balanceColumns");this.layoutContainer.element.setAttribute("data-vivliostyle-in-column-balancing","true"),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.layoutContainer.element.removeAttribute("data-vivliostyle-in-column-balancing"),this.restoreContents(n.layoutResult),this.tightenColumnBlockSizes(n.layoutResult.columns),this.postBalance(),t.finish(n.layoutResult)}),t.result()}createTrialResult(e){let t=this.calculatePenalty(e);return new Uy(e,t)}preBalance(e){}postBalance(){ur(this.layoutContainer,this.originalContainerBlockSize)}tightenColumnBlockSizes(e){if(e.length<=1)return;let t=Math.max.apply(null,e.map(i=>i.computedBlockSize));if(!(t<=0))for(let i of e)if(i.vertical){let n=parseFloat(i.element.style.width),r=parseFloat(i.element.style.left);if(isFinite(n)&&isFinite(r)&&n>t){let s=r+n-t;I(i.element,"width",`${t}px`),I(i.element,"left",`${s}px`),i.width=t,i.left=s}}else{let n=parseFloat(i.element.style.height);isFinite(n)&&n>t&&(I(i.element,"height",`${t}px`),i.height=t)}}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)}},ea=1;function Od(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+ea}function Bd(e,t){let i=e[e.length-1].layoutResult.columns,n=Math.max.apply(null,i.map(r=>isNaN(r.blockDistanceToBlockEndFloats)?r.computedBlockSize:r.computedBlockSize-r.blockDistanceToBlockEndFloats+ea))-ea;n<hr(t)?ur(t,n):ur(t,hr(t)-1)}var Hy=class extends Ld{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);ur(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 yh(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return Od(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!yh(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):hr(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)Bd(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,hr(this.layoutContainer)+this.originalContainerBlockSize*.1);ur(this.layoutContainer,t)}}};function yh(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize,i=e.slice(0,e.length-1),n=Math.max(...e.map(s=>s.lastLineStride||0)),r=n>0?n/2:6;return i.every(s=>t>s.computedBlockSize+r)}var $y=class extends Ld{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 Vy(t)}hasNextCandidate(e){return Od(e)}updateCondition(e){Bd(e,this.layoutContainer)}};function Wy(e,t,i,n,r,s,o){if(t===v.auto)return null;{let a=o.positions.length===0,h=s[s.length-1],l=!!(h&&h.pageBreakType);return a||l?new Hy(i,n,r,e):t===v.balance_all?new $y(i,n,r):(v.balance,null)}}var Gy=["decimal","disc","square","circle","disclosure-open","disclosure-closed"],jy=new Set(Gy);function Xy(e){return!(e.toLowerCase()==="none"||jy.has(e))}var qy=["cyclic","numeric","alphabetic","symbolic","additive","fixed"],Yy=new Set(qy),Zy=["fixed","extends"],Ky=new Set(Zy),S0=Symbol();function Sr(e){return e instanceof de&&e.name.toLowerCase()!=="none"}function Md(e){return e.name}function Jy(e){if(e instanceof de)return Yy.has(e.name);if(e instanceof te&&e.values.length===2){let t=e.values[0],i=e.values[1];if(t instanceof de){let n=t.name;return Ky.has(n)&&(n==="fixed"&&i instanceof Be||n==="extends"&&Sr(i))}}return!1}function Qy(e){let t=st(e,"system");return t instanceof de&&t.name==="cyclic"}function eb(e){let t=st(e,"system");if(t instanceof de&&t.name==="fixed")return!0;if(t instanceof te&&t.values.length===2){let[i,n]=t.values;return i instanceof de&&i.name==="fixed"&&n instanceof Be}return!1}function tb(e){let t=st(e,"system");return t instanceof de?1:t.values[1].num}function ib(e){let t=st(e,"system");return t instanceof de&&t.name==="alphabetic"}function nb(e){let t=st(e,"system");return t instanceof de&&t.name==="numeric"}function rb(e){let t=st(e,"system");return t instanceof de&&t.name==="additive"}function sb(e){let t=st(e,"system");if(t instanceof te&&t.values.length===2){let[i,n]=t.values;return i instanceof de&&i.name==="extends"&&Sr(n)}return!1}function ob(e){let t=st(e,"system");return Md(t.values[1])}function Lt(e){return e instanceof j||e instanceof de}function ti(e){return e instanceof j?e.str:e.name}function _d(e){if(Lt(e))return!0;if(e instanceof te&&e.values.length===2){let t=e.values[0],i=e.values[1];return Lt(t)&&Lt(i)}return!1}function ab(e){if(Lt(e))return{prefix:ti(e),suffix:null};{let t=e.values[0],i=e.values[1];return{prefix:ti(t),suffix:ti(i)}}}function bh(e){return e instanceof Be||e instanceof de&&e.name==="infinite"}function Ps(e,t){return e instanceof Be?e.num:t?-1/0:1/0}var C0=Symbol();function ta(e){if(!(e instanceof te&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];if(!(bh(t)&&bh(i)))return!1;let n=Ps(t,!0),r=Ps(i,!1);return!(n>r)}function lb(e){return{lower:Ps(e.values[0],!0),upper:Ps(e.values[1],!1)}}function Dd(e){return e instanceof de&&e.name==="auto"||ta(e)||e instanceof tt&&e.values.length>=1&&e.values.every(t=>ta(t))}function hb(e){return e instanceof de?null:(ta(e)?[e]:e.values).map(t=>lb(t))}var k0=Symbol();function Ns(e){if(!(e instanceof te&&e.values.length===2))return!1;let t=e.values[0],i=e.values[1];return t instanceof Be&&t.num>=0&&Lt(i)||Lt(t)&&i instanceof Be&&i.num>=0}function Ts(e){let[t,i]=e.values;return t instanceof Be?[t.num,ti(i)]:[i.num,ti(t)]}function zd(e){return Ns(e)}function ub(e){let[t,i]=Ts(e);return{minLength:t,symbol:i}}function Vd(e){return Lt(e)||e instanceof te&&e.values.length>=1&&e.values.every(t=>Lt(t))}function cb(e){return Lt(e)?[ti(e)]:e.values.map(t=>ti(t))}var E0=Symbol();function Ud(e){if(Ns(e))return!0;if(e instanceof tt&&e.values.length>=1){let t=1/0;for(let i of e.values){if(!Ns(i))return!1;let[n]=Ts(i);if(n>=t)return!1;t=n}return!0}return!1}function db(e){if(Ns(e)){let[t,i]=Ts(e);return[{weight:t,symbol:i}]}else return e.values.map(t=>{let[i,n]=Ts(t);return{weight:i,symbol:n}})}var pb=["auto","bullets","numbers","words","spell-out"],fb=new Set(pb);function gb(e){return e instanceof de&&fb.has(e.name)||Sr(e)}function mb(e,t){switch(e){case"system":return Jy(t);case"negative":return _d(t);case"prefix":case"suffix":return Lt(t);case"range":return Dd(t);case"pad":return zd(t);case"fallback":return Sr(t);case"symbols":return Vd(t);case"additive-symbols":return Ud(t);case"speak-as":return gb(t);default:return!0}}function st(e,t){var i;let n=(i=e[t])==null?void 0:i.value;return n??null}function wb(e,t){return t.some(({lower:i,upper:n})=>e>=i&&e<=n)}function En(e){let t=e.get("decimal");return t||(t=ce.createDecimal(e),e.set("decimal",t)),t}var Yr,Zr,Kr,Jr,Qr,es,ts,is,ia,na,ra,sa,oa,aa,la,ut,po,Hd,$d,vh,xh,fo,Sh,Wn,li=class Ri{constructor(t,i){ne(this,ut),c(this,"_store"),ne(this,Yr),ne(this,Zr),ne(this,Kr),ne(this,Jr),ne(this,Qr),ne(this,es),ne(this,ts),ne(this,is),this._store=t;let n=st(i,"negative");Oe(this,Yr,n&&_d(n)?ab(n):null);let r=st(i,"prefix");Oe(this,Zr,r&&Lt(r)?ti(r):null);let s=st(i,"suffix");Oe(this,Kr,s&&Lt(s)?ti(s):null);let o=st(i,"range");Oe(this,Jr,o&&Dd(o)?hb(o):null);let a=st(i,"pad");Oe(this,Qr,a&&zd(a)?ub(a):null);let h=st(i,"fallback");Oe(this,es,h&&Sr(h)?Md(h):null);let l=st(i,"symbols");Oe(this,ts,l&&Vd(l)?cb(l):null);let u=st(i,"additive-symbols");Oe(this,is,u&&Ud(u)?db(u):null)}static create(t,i){return Qy(i)?new Pi(t,i):eb(i)?new yb(t,i):ib(i)?new vb(t,i):nb(i)?new Ch(t,i):rb(i)?new xb(t,i):sb(i)?new Sb(t,i):new bb(t,i)}static createDecimal(t){return new Ch(t,V(Ri,ia))}static createDisc(t){return new Pi(t,V(Ri,na))}static createSquare(t){return new Pi(t,V(Ri,ra))}static createCircle(t){return new Pi(t,V(Ri,sa))}static createDisclosureOpen(t){return new Pi(t,V(Ri,oa))}static createDisclosureClosed(t){return new Pi(t,V(this,aa))}static createNone(t){return new Pi(t,V(Ri,la))}static get CHINESE_LONGHAND_NAMES(){return kh.NAMES}static createChineseLonghand(t,i){return new kh(t,i)}static createEthiopicNumeric(t){return new kb(t)}_getNegative(){return V(this,Yr)}static _getNegativeFrom(t){return t._getNegative()}_getPrefix(){return V(this,Zr)}static _getPrefixFrom(t){return t._getPrefix()}_getSuffix(){return V(this,Kr)}static _getSuffixFrom(t){return t._getSuffix()}static _getAutoRangeFrom(t){return t._getAutoRange()}_getRange(){return V(this,Jr)}static _getRangeFrom(t){return t._getRange()}_getPad(){return V(this,Qr)}static _getPadFrom(t){return t._getPad()}_getFallback(){var t;return(t=this._store.get(V(this,es)))!=null?t:null}static _getFallbackFrom(t){return t._getFallback()}_getSymbols(){return V(this,ts)}static _getSymbolsFrom(t){return t._getSymbols()}_getAdditiveSymbols(){return V(this,is)}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 Ce(this,ut,Wn).call(this,t,new Set)}formatMarker(t){return Ce(this,ut,Hd).call(this)+this.format(t)+Ce(this,ut,$d).call(this)}};Yr=new WeakMap,Zr=new WeakMap,Kr=new WeakMap,Jr=new WeakMap,Qr=new WeakMap,es=new WeakMap,ts=new WeakMap,is=new WeakMap,ia=new WeakMap,na=new WeakMap,ra=new WeakMap,sa=new WeakMap,oa=new WeakMap,aa=new WeakMap,la=new WeakMap,ut=new WeakSet,po=function(){var e;return(e=this._getNegative())!=null?e:{prefix:"-",suffix:null}},Hd=function(){var e;return(e=this._getPrefix())!=null?e:""},$d=function(){var e;return(e=this._getSuffix())!=null?e:". "},vh=function(){var e;return(e=this._getRange())!=null?e:this._getAutoRange()},xh=function(){var e;return(e=this._getPad())!=null?e:{minLength:0,symbol:""}},fo=function(){var e;return(e=this._getFallback())!=null?e:En(this._store)},Sh=function(e,t){let{minLength:i,symbol:n}=Ce(this,ut,xh).call(this);if(i===0||n==="")return e;let{prefix:r,suffix:s}=Ce(this,ut,po).call(this),o=t?[...r].length+(s?[...s].length:0):0,a=i-[...e].length-o;if(a<=0)return e;let h=[...n].length,l=Math.ceil(a/h);return n.repeat(l)+e},Wn=function(e,t){var i,n,r;if(t.has(this))return Ce(i=En(this._store),ut,Wn).call(i,e,new Set);if(t.add(this),!wb(e,Ce(this,ut,vh).call(this))){let l=Ce(this,ut,fo).call(this);return Ce(n=l,ut,Wn).call(n,e,t)}let s=this._usesNegativeSign(e),o=s?Math.abs(e):e,a=this._generateInitialRepresentation(o);if(a===null){let l=Ce(this,ut,fo).call(this);return Ce(r=l,ut,Wn).call(r,e,t)}let h=Ce(this,ut,Sh).call(this,a,s);if(s){let{prefix:l,suffix:u}=Ce(this,ut,po).call(this);h=l+h+(u??"")}return h},ne(li,ia,{system:new D(B("numeric"),0),symbols:new D(new te([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)}),ne(li,na,{system:new D(B("cyclic"),0),symbols:new D(new j("\u2022"),0),suffix:new D(new j(" "),0)}),ne(li,ra,{system:new D(B("cyclic"),0),symbols:new D(new j("\u25AA"),0),suffix:new D(new j(" "),0)}),ne(li,sa,{system:new D(B("cyclic"),0),symbols:new D(new j("\u25E6"),0),suffix:new D(new j(" "),0)}),ne(li,oa,{system:new D(B("cyclic"),0),symbols:new D(new j("\u25BE"),0),suffix:new D(new j(" "),0)}),ne(li,aa,{system:new D(B("cyclic"),0),symbols:new D(new j("\u25B8"),0),suffix:new D(new j(" "),0)}),ne(li,la,{system:new D(B("cyclic"),0),symbols:new D(new j(""),0),suffix:new D(new j(""),0)});var ce=li,Pi=class extends ce{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]}},ns,yb=class extends ce{constructor(e,t){super(e,t),ne(this,ns),Oe(this,ns,tb(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-V(this,ns);return(t=i[n])!=null?t:null}};ns=new WeakMap;var bb=class extends ce{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)}},vb=class extends ce{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}},Ch=class extends ce{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}},xb=class extends ce{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}},Qn,mt,St,Wd=class extends ce{constructor(t,i){super(t,i),ne(this,mt),ne(this,Qn);let n=ob(i),r=n.toLowerCase();r==="disc"||r==="circle"||r==="square"||r==="disclosure-open"||r==="disclosure-closed"?Oe(this,Qn,r):Oe(this,Qn,n)}_getNegative(){var t;return(t=super._getNegative())!=null?t:ce._getNegativeFrom(Ce(this,mt,St).call(this))}_getPrefix(){var t;return(t=super._getPrefix())!=null?t:ce._getPrefixFrom(Ce(this,mt,St).call(this))}_getSuffix(){var t;return(t=super._getSuffix())!=null?t:ce._getSuffixFrom(Ce(this,mt,St).call(this))}_getAutoRange(){return ce._getAutoRangeFrom(Ce(this,mt,St).call(this))}_getRange(){var t;return(t=super._getRange())!=null?t:ce._getRangeFrom(Ce(this,mt,St).call(this))}_getPad(){var t;return(t=super._getPad())!=null?t:ce._getPadFrom(Ce(this,mt,St).call(this))}_getFallback(){var t;return(t=super._getFallback())!=null?t:ce._getFallbackFrom(Ce(this,mt,St).call(this))}_getSymbols(){var t;return(t=super._getSymbols())!=null?t:ce._getSymbolsFrom(Ce(this,mt,St).call(this))}_getAdditiveSymbols(){var t;return(t=super._getAdditiveSymbols())!=null?t:ce._getAdditiveSymbolsFrom(Ce(this,mt,St).call(this))}_usesNegativeSign(t){return ce._useNegativeSignFrom(Ce(this,mt,St).call(this),t)}_generateInitialRepresentation(t){return super._getSymbols()||super._getAdditiveSymbols()?null:ce._generateInitialRepresentationFrom(Ce(this,mt,St).call(this),t)}};Qn=new WeakMap,mt=new WeakSet,St=function(e=new Set){var t;if(e.has(this))return En(this._store);e.add(this);let i=this._store.get(V(this,Qn));return i?i instanceof Wd?Ce(t=i,mt,St).call(t,e):i:En(this._store)};var Sb=Wd,Cb=["simp-chinese-informal","simp-chinese-formal","trad-chinese-informal","trad-chinese-formal","cjk-ideographic"],go,mo,Mr,wo,ha,rs,Pt=class Gd extends ce{constructor(t,i){let{chars:n,descriptors:r}=V(Gd,ha).get(i);super(t,r),ne(this,rs),Oe(this,rs,n)}_getAutoRange(){return[{lower:-9999,upper:9999}]}_usesNegativeSign(t){return t<0}_generateInitialRepresentation(t){let i=V(this,rs);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="",h=!1;for(let l=0;l<n.length;l++){let{digit:u,position:d}=n[l],p=l===n.length-1;u===0?!p&&!h&&(h=!0):(h&&(a+=i.digits[0],h=!1),o&&d===1?a+=i.markers[d]:(a+=i.digits[u],d>0&&(a+=i.markers[d])))}return a}};go=new WeakMap,mo=new WeakMap,Mr=new WeakMap,wo=new WeakMap,ha=new WeakMap,rs=new WeakMap,ne(Pt,go,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new D(new j("\u3001"),0),fallback:new D(B("cjk-decimal"),0),range:new D(new te([new Be(-9999),new Be(9999)]),0),negative:new D(new j("\u8D1F"),0)}}),ne(Pt,mo,{chars:{digits:["\u96F6","\u58F9","\u8D30","\u53C1","\u8086","\u4F0D","\u9646","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new D(new j("\u3001"),0),fallback:new D(B("cjk-decimal"),0),range:new D(new te([new Be(-9999),new Be(9999)]),0),negative:new D(new j("\u8D1F"),0)}}),ne(Pt,Mr,{chars:{digits:["\u96F6","\u4E00","\u4E8C","\u4E09","\u56DB","\u4E94","\u516D","\u4E03","\u516B","\u4E5D"],markers:["","\u5341","\u767E","\u5343"],informal:!0},descriptors:{suffix:new D(new j("\u3001"),0),fallback:new D(B("cjk-decimal"),0),range:new D(new te([new Be(-9999),new Be(9999)]),0),negative:new D(new j("\u8CA0"),0)}}),ne(Pt,wo,{chars:{digits:["\u96F6","\u58F9","\u8CB3","\u53C3","\u8086","\u4F0D","\u9678","\u67D2","\u634C","\u7396"],markers:["","\u62FE","\u4F70","\u4EDF"],informal:!1},descriptors:{suffix:new D(new j("\u3001"),0),fallback:new D(B("cjk-decimal"),0),range:new D(new te([new Be(-9999),new Be(9999)]),0),negative:new D(new j("\u8CA0"),0)}}),c(Pt,"NAMES",new Set(Cb)),ne(Pt,ha,new Map([["simp-chinese-informal",V(Pt,go)],["simp-chinese-formal",V(Pt,mo)],["trad-chinese-informal",V(Pt,Mr)],["trad-chinese-formal",V(Pt,wo)],["cjk-ideographic",V(Pt,Mr)]]));var kh=Pt,ua,ca,Is,da,pa,nn=class Fi extends ce{constructor(t){super(t,V(Fi,ua))}_getAutoRange(){return[{lower:1,upper:1/0}]}_usesNegativeSign(t){return!1}_generateInitialRepresentation(t){if(t<1)return null;if(t===1)return V(Fi,Is)[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],h=o%2===1,l=o===r-1;if(!(a===0||l&&a===1||h&&a===1)){let u=Math.floor(a/10),d=a%10;s+=V(Fi,ca)[u]+V(Fi,Is)[d]}h?a!==0&&(s+=V(Fi,da)):o!==0&&(s+=V(Fi,pa))}return s}};ua=new WeakMap,ca=new WeakMap,Is=new WeakMap,da=new WeakMap,pa=new WeakMap,ne(nn,ua,{range:new D(new te([new Be(1),B("infinite")]),0),suffix:new D(new j("/ "),0)}),ne(nn,ca,["","\u1372","\u1373","\u1374","\u1375","\u1376","\u1377","\u1378","\u1379","\u137A"]),ne(nn,Is,["","\u1369","\u136A","\u136B","\u136C","\u136D","\u136E","\u136F","\u1370","\u1371"]),ne(nn,da,"\u137B"),ne(nn,pa,"\u137C");var kb=nn,Pe,Eb=class{constructor(){ne(this,Pe),Oe(this,Pe,new Map),V(this,Pe).set("none",ce.createNone(V(this,Pe))),V(this,Pe).set("decimal",ce.createDecimal(V(this,Pe))),V(this,Pe).set("disc",ce.createDisc(V(this,Pe))),V(this,Pe).set("square",ce.createSquare(V(this,Pe))),V(this,Pe).set("circle",ce.createCircle(V(this,Pe))),V(this,Pe).set("disclosure-open",ce.createDisclosureOpen(V(this,Pe))),V(this,Pe).set("disclosure-closed",ce.createDisclosureClosed(V(this,Pe)));for(let e of ce.CHINESE_LONGHAND_NAMES)V(this,Pe).set(e,ce.createChineseLonghand(V(this,Pe),e));V(this,Pe).set("ethiopic-numeric",ce.createEthiopicNumeric(V(this,Pe)))}define(e,t){if(!Xy(e))return null;let i=ce.create(V(this,Pe),t);return V(this,Pe).set(e,i),i}getStyle(e){var t;return(t=V(this,Pe).get(e))!=null?t:null}format(e,t){var i;return((i=this.getStyle(e))!=null?i:En(V(this,Pe))).format(t)}formatMarker(e,t){var i;return((i=this.getStyle(e))!=null?i:En(V(this,Pe))).formatMarker(t)}};Pe=new WeakMap;var yo=class{constructor(e,t,i){c(this,"endStuckFixed"),c(this,"endFixed"),c(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},Pb=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 yo(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 yo(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new yo(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)}};function Nb(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}var Tb=class fa{constructor(t,i,n,r,s,o,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=r,this.flowChunk=s,this.atBlockStart=o,this.atFlowStart=a,this.isParentBoxDisplayed=h,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 l=i._pseudos;if(l&&l.before){let u=new fa(t,l.before,n,!1,s,this.isBlock(),a,!0),d=u.styleValue("content");Rt(d)&&(this.beforeBox=u,this.breakBefore=u.breakBefore)}}this.breakBefore=et(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ge(this.breakBefore)&&(s.breakBefore=et(s.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let r=this.style._pseudos;if(r&&r.after){let s=new fa(this.context,r.after,t,!1,this.flowChunk,i,n,!0),o=s.styleValue("content");Rt(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",v.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=Mc(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==v.none&&!ys(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}},Ib=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()!==v.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(),h=new Tb(this.context,e,t,i,s,o||this.atBlockStart,o,a);return this.stack.push(h),this.atBlockStart=h.hasBox()?!h.beforeBox&&h.isBlock():this.atBlockStart,this.atFlowStart=h.hasBox()?!h.beforeBox&&o:this.atFlowStart,h}encounteredTextNode(e){let t=this.lastBox();if((e.nodeType===Node.TEXT_NODE||e.nodeType===Node.CDATA_SECTION_NODE)&&(this.atBlockStart||this.atFlowStart)&&t.hasBox()){let i=t.styleValue("white-space",v.normal).toString(),n=Cc(i);n&&!Me(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=et(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!")}},Eh=class{constructor(e,t,i,n,r,s,o,a,h,l){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,"counterSnapshots",[]),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,h,l),this.offsetMap=new Pb;let u=e.getElementOffset(this.root);this.lastOffset=u,this.boxStack=new Ib(n),this.offsetMap.addStuckRange(u);let d=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,d,u),this.recordCounterSnapshot(u,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes),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 D(r,hc))}}}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)un(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&&!J(n)||r&&!J(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&&!J(n.value)){let a=n.evaluate(this.context);if(a instanceof F){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*_t.lh/_t.em;break;default:{let l=_t[a.unit];l&&(h*=l),r=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=r}}let s=(i=this.context.rootFontSize)!=null?i:this.context.initialFontSize,o=e["line-height"];if(o&&!J(o.value)){let a=o.evaluate(this.context);if(a instanceof vt)this.context.rootLineHeight=a.num*s;else if(a instanceof F){let h=a.num;switch(a.unit){case"em":case"rem":h*=s;break;case"%":h*=s/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*this.context.pref.lineHeight;break;default:{let l=_t[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}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 Hw(this.scope,this.validatorSet,this.xmldoc.url,t)}return{}}recordCounterSnapshot(e,t,i=[],n){let r={offset:e,counters:Nb(t),changes:Array.from(i||[]),changeTypes:n?{...n}:void 0},s=this.counterSnapshots[this.counterSnapshots.length-1];if(s&&s.offset===e){this.counterSnapshots[this.counterSnapshots.length-1]=r;return}this.counterSnapshots.push(r)}getCounterSnapshotAtOffset(e){if(!this.counterSnapshots.length)return null;let t=ni(this.counterSnapshots.length,n=>e<this.counterSnapshots[n].offset),i=t===0?0:t-1;return this.counterSnapshots[i]||null}getLastCounterSnapshot(){return this.counterSnapshots.length?this.counterSnapshots[this.counterSnapshots.length-1]:null}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);if(!this.cascade.firstPageType){let l=s.page,u=l&&!J(l.value)&&l.value.toString();u&&u.toLowerCase()!=="auto"&&(this.cascade.firstPageType=u)}let o=ke(s,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,s,this.root,i);this.boxStack.empty()&&this.boxStack.push(s,i,!0,h)}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),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,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,h=!1,l=t["flow-options"];if(l){let m=Qf(l.evaluate(this.context,"flow-options"));o=!!m.exclusive,a=!!m.static,h=!!m.last}let u=t["flow-linger"];u&&(s=Hl(u.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let d=t["flow-priority"];d&&(r=Hl(d.evaluate(this.context,"flow-priority"),0));let p=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[e]=new gm(e,m)}let g=new mm(e,i,n,r,s,o,a,h,p);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(Ge(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]=et(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 h=o.afterBox.getBreakValue("before");this.registerForcedBreakOffset(h,o.afterBox.atBlockStart?this.boxStack.nearestBlockStartOffset(o):o.afterBox.offset,o.flowName),a=o.afterBox.getBreakValue("after")}a=et(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),this.cascade.lastCounterChanges.length>0&&this.recordCounterSnapshot(this.lastOffset,this.cascade.counters,this.cascade.lastCounterChanges,this.cascade.lastCounterChangeTypes);let h=o.getAttribute("id")||o.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");h&&h===this.idToReach&&(this.idToReach=null),!this.bodyReached&&o.localName=="body"&&o.parentNode==this.root&&(this.postprocessTopStyle(a,!0),this.bodyReached=!0);let l,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],l=this.boxStack.push(a,this.lastOffset,o===this.root,f)}else l=this.boxStack.push(a,this.lastOffset,o===this.root),o===this.xmldoc.body&&(l.breakBefore=et(l.flowChunk.breakBefore,l.breakBefore));let d=this.boxStack.nearestBlockStartOffset(l);if(d===0||o===this.xmldoc.body){let p=a.page,f=p&&!J(p.value)&&p.value.toString();!this.cascade.firstPageType&&f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,d,l.flowName),l.beforeBox){let p=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(p,l.beforeBox.atBlockStart?d:l.offset,l.flowName)}if(this.primary&&l.displayValue()===v.none&&(this.primary=!1),this.styleMap[`e${this.lastOffset}`]=a,this.lastOffset++,this.primary?this.offsetMap.addStuckRange(this.lastOffset):this.offsetMap.addSlippedRange(this.lastOffset),this.bodyReached&&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"],cn=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)}},Ni=class{constructor(e,t){this.where=e,this.success=t,c(this,"what",-1)}},Dn=class jd{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 jd;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],r=new cn(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 Ni(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 cn(Nh);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 Ni(r,!0),a=new Ni(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 cn(Nh);i.markAsStartAlternate(t),this.nodes.push(i);let n=new Ni(0,!0),r=new Ni(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 cn(t));let n=new Ni(i,!0),r=new Ni(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 ze}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]}},Ab=1,Xd=2,qd=4,Li=8,ss=16,ga=32,os=64,Yd=128,Gn=256,jn=512,ma=1024,Zd=2048,Kd=4096,Jd=8192,Qd=class extends oi{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},ze=class ep extends Qd{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&Ab?t:null}visitSlash(t){return this.allowed&Zd?t:null}visitStr(t){return this.allowed&Xd?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&qd||this.allowed&os&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&jn)?t.unit=="%"&&this.allowed&ma?t:null:t.num<0&&!(this.allowed&Gn)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&jn?t:null:t.num<=0&&!(this.allowed&Gn)?null:this.allowed&ss?t:null}visitInt(t){return t.num==0?this.allowed&jn?t:null:t.num<=0&&!(this.allowed&Gn)?null:this.allowed&(ga|ss)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&os&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&Yd?t:null}visitURange(t){return this.allowed&Kd?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){if(this.allowed&os){if(t.name==="device-cmyk"||t.name==="cmyk")return CSS.supports("color","color(srgb 0 0 0)")&&Du(t)!==null?t:null;if(CSS.supports("color",t.toString()))return t}if(this.allowed&Jd){let i=t.visit(new Uu);if(CSS.supports("background-image",i.toString()))return t}return t.name==="calc"&&this.allowed&(Li|ss|ga|Gn|jn|ma)?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 ep(this.allowed|t.allowed,i,n)}},ae=Object.create(null),Nh=new ze(0,ae,ae),il=class extends Qd{constructor(e){super(),c(this,"successTerminal"),c(this,"failureTerminal"),c(this,"first"),this.successTerminal=new cn(null),this.failureTerminal=new cn(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 h=e[s],l=h;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 er&&this instanceof er){if(l=new te(e).visit(r.validator),l){s=e.length,r=r.success;continue}}else if(s==0&&!t&&r.validator instanceof nl&&this instanceof er){if(l=new tt(e).visit(r.validator),l){s=e.length,r=r.success;continue}}else l=h.visit(r.validator);if(!l){r=r.failure;continue}if(l!==h&&e===n){n=[];for(let u=0;u<s;u++)n[u]=e[u]}e!==n&&(n[s-i]=l),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}},er=class extends il{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new te(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof nl){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new tt(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},nl=class extends il{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 tt(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}},Rb=class extends il{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 Ui(e.name,t):null}},tp=class{tryParse(e,t,i){return t}success(e,t){}},ip=class extends tp{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 te(n):n[0];return this.success(s,i),t+r}return t}success(e,t){t.values[this.name]=e}},Fb=class extends ip{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}},Lb=class extends tp{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==Tn){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}},rl=class extends oi{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 ip(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:v.initial,e);return!0}return!1}propagateDefaultingValue(e,t,i){for(let n of this.propList)i.simpleProperty(n,e,t)}validateList(e){return this.error=!0,0}validateSingle(e){return this.validateList([e]),null}visitEmpty(e){return this.validateSingle(e)}visitStr(e){return this.validateSingle(e)}visitIdent(e){return this.validateSingle(e)}visitNumeric(e){return this.validateSingle(e)}visitNum(e){return this.validateSingle(e)}visitInt(e){return this.validateSingle(e)}visitHexColor(e){return this.validateSingle(e)}visitURL(e){return this.validateSingle(e)}visitSpaceList(e){return this.validateList(e.values),null}visitCommaList(e){return this.error=!0,null}visitFunc(e){return this.validateSingle(e)}visitExpr(e){return this.validateSingle(e)}},Fn=class extends rl{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}},np=class extends rl{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 Fb(this.validatorSet,this.propList)}},Ob=class extends rl{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===Tn){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}},Bb=class extends Fn{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:v.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 tt?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 tt(t[i]);return null}},Mb=class extends Fn{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]===Tn){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 te(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 tt(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}},_b=class extends Fn{validateList(e){if(e.length===1&&e[0]instanceof de)switch(e[0].name.toLowerCase()){case"normal":e=[this.validatorSet.defaultValues["text-autospace"],this.validatorSet.defaultValues["text-spacing-trim"]];break;case"auto":e=[v.auto,v.auto];break;case"none":e=[B("no-autospace"),B("space-all")];break}return super.validateList(e)}},Db=["unicode-bidi","direction","margin-block-start","margin-block-end","margin-inline-start","margin-inline-end","padding-block-start","padding-block-end","padding-inline-start","padding-inline-end","border-block-start-color","border-block-end-color","border-inline-start-color","border-inline-end-color","border-block-start-style","border-block-end-style","border-inline-start-style","border-inline-end-style","border-block-start-width","border-block-end-width","border-inline-start-width","border-inline-end-width","block-start","block-end","inline-start","inline-end","block-size","inline-size","max-block-size","max-inline-size","min-block-size","min-inline-size","behavior","bleed","conflicting-partitions","crop-offset","crop-marks-line-color","enabled","flow-consume","flow-from","flow-into","flow-linger","flow-options","flow-priority","font-display","font-size-adjust","font-stretch_css3","font-variant_css2","glyph-orientation-vertical","marks","min-page-height","min-page-width","repeat-on-break","required","required-partitions","ruby-align","shape-inside","snap-height","snap-width","src","template","text-decoration-skip","text-justify","text-zoom","unicode-range","utilization","wrap-flow"],zb=class extends Fn{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)Db.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},Th={SIMPLE:Fn,INSETS:np,INSETS_SLASH:Ob,COMMA:Bb,FONT:Mb,TEXT_SPACING:_b,ALL:zb},Vb=["initial-letter"],Ub=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 F(t.num,t.text);else if(t.type==7)i=new Fu(t.text);else if(t.type==1)i=B(t.text);else throw new Error("unexpected replacement");if(e.isPrimitive()){let n=e.nodes[0].validator.idents;for(let r in n)n[r]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Dn;if(e=="||"){for(let r=0;r<t.length;r++){let s=new Dn;s.startClause(r),s.addGroup(t[r],1),s.endClause(r),i.addGroup(s,r==0?1:4)}let n=new Dn;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 Dn;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 Dn;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new nl(t);break;case"SPACE":i=new er(t);break;default:i=new Rb(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new ze(os,ae,ae)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new ze(Jd,ae,ae)),this.namedValidators.POS_INT=this.primitive(new ze(ga,ae,ae)),this.namedValidators.POS_NUM=this.primitive(new ze(ss,ae,ae)),this.namedValidators.POS_PERCENTAGE=this.primitive(new ze(Li,ae,{"%":Y})),this.namedValidators.NEGATIVE=this.primitive(new ze(Gn,ae,ae)),this.namedValidators.ZERO=this.primitive(new ze(jn,ae,ae)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new ze(ma,ae,ae)),this.namedValidators.POS_LENGTH=this.primitive(new ze(Li,ae,{em:Y,ex:Y,ch:Y,rem:Y,lh:Y,rlh:Y,vw:Y,vh:Y,vi:Y,vb:Y,vmin:Y,vmax:Y,pvw:Y,pvh:Y,pvi:Y,pvb:Y,pvmin:Y,pvmax:Y,cm:Y,mm:Y,in:Y,px:Y,pt:Y,pc:Y,q:Y})),this.namedValidators.POS_ANGLE=this.primitive(new ze(Li,ae,{deg:Y,grad:Y,rad:Y,turn:Y})),this.namedValidators.POS_TIME=this.primitive(new ze(Li,ae,{s:Y,ms:Y})),this.namedValidators.FREQUENCY=this.primitive(new ze(Li,ae,{Hz:Y,kHz:Y})),this.namedValidators.RESOLUTION=this.primitive(new ze(Li,ae,{dpi:Y,dpcm:Y,dppx:Y})),this.namedValidators.URI=this.primitive(new ze(Yd,ae,ae)),this.namedValidators.URANGE=this.primitive(new ze(Kd,ae,ae)),this.namedValidators.IDENT=this.primitive(new ze(qd,ae,ae)),this.namedValidators.STRING=this.primitive(new ze(Xd,ae,ae)),this.namedValidators.SLASH=this.primitive(new ze(Zd,ae,ae));let e={"font-family":B("sans-serif")};this.systemFonts.caption=e,this.systemFonts.icon=e,this.systemFonts.menu=e,this.systemFonts["message-box"]=e,this.systemFonts["small-caption"]=e,this.systemFonts["status-bar"]=e}isBuiltIn(e){return!!e.match(/^[A-Z_0-9]+$/)}readNameAndPrefixes(e,t){let i=e.token();if(i.type==0)return null;let n={"":!0};if(i.type==14){do{if(e.consume(),i=e.token(),i.type!=1)throw new Error("Prefix name expected");n[i.text]=!0,e.consume(),i=e.token()}while(i.type==16);if(i.type!=15)throw new Error("']' expected");e.consume(),i=e.token()}if(i.type!=1)throw new Error("Property name expected");if(t==2?i.text=="SHORTHANDS":i.text=="DEFAULTS")return e.consume(),null;let 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)},h=u=>{if(o)throw new Error(`'${u}': unexpected`);if(r&&r!=u)throw new Error(`mixed operators: '${u}' and '${r}'`);r=u,o=!0},l=null;for(;!l;){e.consume();let u=e.token();switch(u.type){case 1:if(o||h(" "),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()]=B(u.text),i.push(this.primitive(new ze(0,d,ae)))}o=!1;break;case 5:{let d={};d[`${u.num}`]=new Be(u.num),i.push(this.primitive(new ze(0,d,ae))),o=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:o||h(" "),n.push({vals:i,op:r,b:"["}),r="",i=[],o=!0;break;case 6:o||h(" "),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(l=a(),n.length>0)throw new Error(`unclosed '${n.pop().b}'`);break;default:throw new Error("unexpected token")}}e.consume(),this.isBuiltIn(t)?this.namedValidators[t]=l:l.isSimple()?this.validators[t]=l.nodes[0].validator:this.validators[t]=new er(l)}}parseDefaults(e){for(;;){let t=this.readNameAndPrefixes(e,2);if(!t)return;let i=[];for(;;){e.consume();let n=e.token();if(n.type==17){e.consume();break}switch(n.type){case 1:i.push(B(n.text));break;case 4:i.push(new vt(n.num));break;case 5:i.push(new Be(n.num));break;case 3:i.push(new F(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new te(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&Th[i.text]?(n=new Th[i.text],e.consume()):n=new Fn,n.setOwner(this);let r=!1,s=[],o=!1,a=[],h=[];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("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof np){let l=this.shorthands[i.text];s.push(l.createSyntaxNode()),h.push(...l.propList)}else throw new Error(`'${i.text}' is neither a simple property nor an inset shorthand`);break;case 19:if(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 l=new Lb(s,o),u=a.pop();s=u.syntax,o=u.slash,s.push(l);break}case 17:r=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(s,h),this.shorthands[t]=n}}parse(e){let t=new Xt(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:v.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){let r=n.ruleType;if(jt(e)||r==="font-face"||$b(t)){n.simpleProperty(e,t,i);return}if(r==="counter-style"){mb(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 h=this.prefixes[e];if(!h||!h[s]){CSS.supports(o,t.toString())?n.simpleProperty(o,t,i):s&&!au.includes(`-${s}-`)||n.unknownProperty(o,t);return}else if(Vb.includes(e)&&!Object.keys(h).some(u=>Vr(u?`-${u}-`:"",e))){n.unknownProperty(o,t);return}let l=this.validators[e];if(l){let u=J(t)||t.isExpr()?t:t.visit(l);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();J(t)?u.propagateDefaultingValue(t,i,n):(t.visit(u),u.finish(i,n)||n.invalidPropertyValue(o,t))}}};function rp(){let e=new Ub;return e.initBuiltInValidators(),e.parse(tc),e}var Hb=class extends oi{constructor(){super(...arguments),c(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function $b(e){let t=new Hb;return e.visit(t),t.varFound}var N0=`OTTO${new Date().valueOf()}`;function sl(e){return Object.keys(e).filter(t=>!["src","font-family","font-display"].includes(t)).sort()}function Wb(e){let t=new ii;for(let i of sl(e))t.append(`${i}:${e[i].toString()};`);return t.toString()}function Gb(e,t){let i={};for(let n in e)i[n]=ke(e,n).evaluate(t,n);return i}var sp=class{constructor(e){this.properties=e,c(this,"fontTraitKey"),c(this,"src"),c(this,"blobURLs",[]),c(this,"blobs",[]),c(this,"family"),this.fontTraitKey=Wb(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
1848
|
font-family: `),i.append(this.family),i.append(`;
|
|
1795
|
-
`);for(let n of
|
|
1796
|
-
`);if(t){i.append('src: url("');let n=
|
|
1849
|
+
`);for(let n of sl(this.properties))i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
|
|
1850
|
+
`);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
1851
|
}
|
|
1798
|
-
`),i.toString()}},qb=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}}},Yb=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 Na(e.properties))r[h]=e.properties[h];let o=this.getViewFontFamily(e,i);r["font-family"]=F(o);let a=new fd(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?er(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 Qs(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()}},Kb=1,rr=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${Kb++}`,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})}},Zb=class extends rr{constructor(e){super(e,null,null,[],null),this.specified.width=new _(Hn,0),this.specified.height=new _($n,0)}},Kl=class extends zr{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}}},gd=class md extends rr{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 Kl||(this._scope=new Kl(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 Ta(t,this)}clone(t){let i=new md(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}},wd=class bd extends rr{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 ty(t,this)}clone(t){let i=new bd(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Kn=class yd extends rr{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 yd(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Jb(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 Qb(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 Zl(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 vd(e,t,i){return!t||K(t)?i:t===y._true?e._true:t===y._false?e._false:t.toExpr(e,e.zero)}var or=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?nc:sc;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 Yh(i,0),s=this.resolveName("column-count"),r=this.resolveName("column-width"),o=this.resolveName("column-gap");t=pe(i,us(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=vd(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 Zo(e,n,o))}let s=fe(e,t["min-page-width"],e.zero);s&&(i=St(e,i,new Vr(e,new ze(e,"page-width"),s)));let r=fe(e,t["min-page-height"],e.zero);r&&(i=St(e,i,new Vr(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=us(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=us(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=Qb(e,t["column-gap"],null);r||(r=new Un(e,1,"em")),n&&!s&&(s=new yn(e,"floor",[Ur(e,Y(e,i,r),Y(e,n,r))]),s=new yn(e,"max",[e.one,s])),s||(s=e.one),n=pe(e,Ur(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=Cc(this.cascaded,e,s,!1,null);this.vertical=xc(r,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=Sc(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 La&&e.currentLayoutPosition&&new ze(i,"left-page").evaluate(e));Ec(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=Ds(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=Ds(e,s,t,r)}return Qe(s,e)}getSpecial(e,t){let i=ac(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()&&zh(s.unit)&&(s=iu(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 ra(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<Jl.length;r++)this.propagateProperty(e,t,Jl[r],n)}transferContentProps(e,t,i,n){for(let s=0;s<eh.length;s++)this.propagateProperty(e,t,eh[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<th.length;r++){let o=th[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&&Zu(n);u&&Ku(n),h=r.getElementClientRect(n?n.element:t.element),u&&aa(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<Ql.length;u++)this.propagateProperty(e,t,Ql[u],o);for(let u=0;u<ih.length;u++)this.propagateDelayedProperty(e,t,ih[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==Pa)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 mo(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)}},Jl=["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"],Ql=["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"],eh=["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"],th=["width","height","image-resolution","object-fit","object-position"],ih=["transform","transform-origin"],Pa="background-host",ey=class extends or{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)}},Ta=class extends or{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){}},ty=class extends or{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Zi=class extends or{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=Mr(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=vd(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let s=Jb(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 Ed||(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)}},Ia=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?Cu:ku)}},xd=class extends Ia{constructor(e,t,i,n){super(e,t,i,n)}},iy=class Sd extends Ia{constructor(t,i,n,s){super(t,i,n,s),n.specified.width=new _(tl,0),n.specified.height=new _(tl,0)}startPartitionRule(t,i,n){let s=new Kn(this.scope,t,i,n,this.target),r=new xd(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(t,i,n){let s=new wd(this.scope,t,i,n,this.target),r=new Sd(this.scope,this.owner,s,this.validatorSet);this.owner.pushHandler(r)}},ny=class extends Ia{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 xd(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(e,t,i){let n=new wd(this.scope,e,t,i,this.target),s=new iy(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(s)}};function Cd(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 sy={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")}},ry=new I(.24,"pt"),T0=new I(3,"mm"),oy=new I(10,"mm"),ay=new I(13,"mm");function js(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&&sy[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=ay):l.isNumeric()&&(t.cropOffset=l),t}function nh(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 kd(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 Mo=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(Mo||{});function ly(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=kd(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 hy(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=kd(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 uy(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(ry,n),d=Math.max(0,t.bleedOffset-Qe(oy,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],m=f&&!K(f.value)?f.value:y.auto;s&&Object.keys(Mo).forEach(g=>{let w=Mo[g],v=ly(h,w,u,m,p,a,d);l.appendChild(v)}),r&&Object.keys(Mn).forEach(g=>{let w=Mn[g],v=hy(h,w,u,m,p,d);l.appendChild(v)})}var zo=(()=>{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})(),Aa={"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"}},cy=(()=>{let e=Aa;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),Ra="vivliostyle-page-rule-master",zn="_marginBoxes",Ed=class extends gd{constructor(e,t,i){super(e,null,Ra,[],t,null,0),c(this,"pageMarginBoxes",{});let n=js(i),s=new dy(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[zn];t&&cy.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new fy(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)!zo[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new Wi(e,this)}},dy=class extends Kn{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let s=new py(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 zo)zo.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new my(e,this)}},py=class extends Kn{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new _(F("body"),0)}createInstance(e){return new Nd(e,this)}},fy=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];(ic[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 Pd(e,this)}},Wi=class extends Ta{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=Aa[C];if(E){let A=e[C],V=this.pageMarginBoxInstances[C],D=new Ns(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 sh(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 sh(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 gy(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 Ns&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof Ns&&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)}},Ns=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=sa(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()}},gy=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}},sh=class extends Ns{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()}},my=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=us(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)}},Nd=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}},Pd=class extends Zi{constructor(e,t){super(e,t),c(this,"boxInfo"),c(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=Aa[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,Ur(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=Zl(n,i[`margin-${r}`],l),u=Zl(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"))}}},wy=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 Zo(e,new Gh(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||Cd(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===Pa?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 Ed(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:Ra}),n=i.specified,s=e.size;if(s&&!K(s.value)){let o=js(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}},by=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}},yy=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}},vy=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}},xy=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}},Sy=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}},Cy=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}},ky=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}},Ey=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}},Ny=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}},Py=class extends ma{constructor(e,t){super(e,t,null,null,null)}apply(e){Ty(e.context,e.currentStyle,this.style,this.specificity,e)}};function Ty(e,t,i,n,s){zs(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),zs(e,l,r[a],n,null,null,null)}}}var Iy=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 by(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 Ny(this.scope,i,n,s)),this.specificity+=256}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Ey(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 yy(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new vy(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new xy(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new Sy(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new Cy(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new ky(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 Py(this.elementStyle,e)}startPageMarginBoxRule(e){let t=qn(this.elementStyle,zn),i=t[e];i||(i={},t[e]=i);let n=new Ay(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},Ay=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 Ry(e){jt=e}var yi=[];function rh(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function Td(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 Fa(e,t,i){if(!jt||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&Td(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(Id(t)||(t.onload=null),h)return yi.some(d=>rh(d,e))||yi.push(e),N(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&rh(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),Qs([d])}else return t.document.head.appendChild(u),N(!0)}function Fy(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 ma)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 Ly(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=Fy(e,i),s.textContent=e.documentElement.textContent,t.document.body.appendChild(s),s}function By(e,t,i){if(!jt)return N(!1);let n=Td(e);if(n.length===0)return N(!1);let s=n.some(u=>!(u.async||u.defer||u.type==="module")),r=s?Ly(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 Fa(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 Oy(e){if(!jt)return N(!1);let t=B("loadScripts");return t.loop(()=>yi.length===0?N(!1):Fa(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 Id(e){return jt?yi.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}var _y=(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)}`),My={};function zy(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 Ad=class Do extends Xo{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 Do(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=ds.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=p;for(let g of Jm){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=ds.createElementNS("http://www.w3.org/1999/xhtml","span"),yo(w,g)}else w=ds.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(w),g.match(/^first-/)&&(f=w)}if(!d.length)return l;let m=new Ol(t,n,r,o,this.exprContentListener);return new Zr(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),bo(h,r,o[l]),kc(o[l],i,n,(u,d)=>{En(h,d,r),vc(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 Zr(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=Cc(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=xc(a,o,t);let u=!l&&t!==h;i=Sc(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(Ec(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(eo(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=Xu(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||Or(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 om(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(nl);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=Or(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Zg().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);ir.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)?Ig(f.value.toString()):null;if(this.nodeContext.parent&&(eo(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 Fa(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=_g(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=zg(w,C,E,u.overflow,V,D,at||te),this.nodeContext.containingBlockForAbsolute=Dg(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)||Yu(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(),qr[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(),qr[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 Eg(M,z.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,h,l,this.context);let $=u["white-space"];if($){let M=_u($.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(va)&&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,Oa;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"&&zy(M);let Zn=this.nodeContext.inheritedProps["image-resolution"],ar=[],lr=u.width,hr=u.height,Hd=a.getAttribute("width"),$d=a.getAttribute("height"),ur=lr===y.auto||!lr&&!Hd,cr=hr===y.auto||!hr&&!$d,_a=a.attributes,Wd=_a.length,Jn=null,Ma=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<Wd;Xe++){let pt=_a[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"&&ur&&cr){let qe=new Image,ai=Ni(qe,De);Se.push(ai),ar.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=_y(De,this.xmldoc.url,this.documentURLTransformer)),ht){let qe=My[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")Ma=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,Ma);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};!ur&&!cr&&!(()=>{let oe=this.nodeContext.vertical?lr:hr;return oe instanceof I&&oe.unit==="%"})()&&!ht()?this.page.fetchers.push(pt):(ur&&cr&&Zn&&Zn!==1&&ar.push({image:Xe,element:M,fetcher:pt}),Se.push(pt))}delete u.content;let dr=u["list-style-image"];if(dr&&dr instanceof Je){let Xe=dr.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(!oa(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)&&Cr(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"),Cr(M,"block-start")}if(x&&M.setAttribute("value",u["ua-list-item-count"].stringValue()),M.classList.contains("_viv-marker-outside-content")&&mi((Oa=(lt=this.nodeContext.parent)==null?void 0:lt.parent)==null?void 0:Oa.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?Qs(Se).then(()=>{Zn>0&&this.modifyElemDimensionWithImageResolution(ar,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&&la(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 Ol(t,i,n,s,this.exprContentListener);this.nodeContext.afterIfContinues=new ew(t,o)}}isSVGUrlAttribute(t){return Do.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=ml(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=pg(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()&&Fu(u).includes("block-start")&&ft(u,"text-start"),u.appendChild(this.viewNode),$g(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=ml(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(nl);let u,d;for(let p of h){if(Vy[p])continue;let f=i[p];if(!(!f||f===j&&!$t(p))){if(f=f.visit(new hf(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 zh(f.unit)&&(f=iu(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))`))),mg[p]||a&&wg[p]){this.page.delayedItems.push(new ra(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=co(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=co(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 _s(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");yo(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?Lu(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"),Cr(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(Rp(r)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,ga(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(Ad,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]);var Dy=Ad,Vy={"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},Uy=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}},Xs=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),Nh){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)}},Rd=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 Ld([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}},Vo=(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))(Vo||{});function as(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 Hy(e){let t=e.contentType;if(t){let n=Object.keys(Vo);for(let s=0;s<n.length;s++)if(Vo[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 Fd(e,t){let i=e.responseXML;if(!i){let s=new DOMParser,r=e.responseText;if(r){let o=Hy(e);if(i=as(r,o||"application/xml",s),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=as(r,"text/html",s):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=as(r,"image/svg+xml",s))}i||(i=as(r,"text/html",s))}}let n=i?new Rd(t,e.url,i):null;return N(n)}function $y(){return new ta(Fd,"document")}var Wy=class Uo{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new Uo(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new Uo(n=>{if(!this.check(n))return!1;let s=new Ld([n]);return s=s.child(t),i&&(s=s.predicate(i)),s.size()>0})}},oh=new Wy(e=>!0),Ld=class Ho{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 Ho(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 Ho(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)}},Gy=new Wn(()=>{let e=B("uaStylesheetBase"),t=pd(),i=Pe("user-agent-base.css",Qt),n=new Ln(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Mm(n.cascade),na(wu,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function jy(){return Gy.get()}var Xy=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}`)}},qy=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 Dr(this.rootScope,e,t,i),r=rm(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}}},La=class extends Dr{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 qb(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 jl(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=Cd(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let s=this.style.rootBox;this.rootPageBoxInstance=new ey(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 wy(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=Xb(l.properties,this),u=new fd(h);o.push(u)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{By(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=nh(js(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 Dr(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 jl(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 Pg,i.flowPositions[e.flowName]=n);let s=kg(e.element),r=new oi(s),o=new Ng(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 Bd(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=gl(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===Ra)continue;let o=1;s.pageBox.pseudoName===Pa&&!(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 ca(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=gl(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 rw([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 Vs(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 Vs(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 Nd||t instanceof Ta&&!(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=Xw(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=au(w,0,0,a.width,a.height,this),b=new Dy(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 Pd?"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 $u(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 _s(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 _s(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"&&Zm(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 Tg,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=nh(js(l),this);this.setPageSizeAndBleed(g,e),uy(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`}},Yy=class $o 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 gd(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new ny(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 $o(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new $m(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 Xy(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 Iy(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 $o(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},Bd=class extends Zf{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 Tb),c(this,"footnoteProps",{}),c(this,"flowProps",{}),c(this,"viewportProps",[]),c(this,"pageProps",{}),this.rootScope=new zr(null),this.pageScope=new zr(this.rootScope),this.rootBox=new Zb(this.rootScope),this.cascadeParserHandler=new Yy(this,null,null,null),this.slave=this.cascadeParserHandler}};function Ky(e,t){return t.parseOPSResource(e)}var Zy=class extends ta{constructor(e){super(Ky,"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=pd(),jy().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 Fd(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:mu,flavor:"UA",classes:null,media:null}),l.push({url:Pe("user-agent-counter-styles.css",Qt),text:vu,flavor:"UA",classes:null,media:null}),n)l.push({url:Pe("user-agent-toc.css",Qt),text:bu,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 Bd(this.validatorSet);return p.loop(()=>{if(f<l.length){let g=l[f++];return m.startStylesheet(g.flavor),g.text!==null?na(g.text,m,g.url,g.classes,g.media).thenReturn(!0):Nu(g.url,m,g.classes,g.media)}return N(!1)}).then(()=>{let g=m.cascadeParserHandler.finish();u=new qy(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",ah="\u25BE",Jy="\u25B9";function Ba(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 Qy(e){let t=Ba(e),i=[];for(let n of t)for(let s of n.querySelectorAll("li a[href]"))i.push(s);return i}var e0=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=Bh(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",t0,!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=Jy,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 Ou(e,e);this.page=o;let a=Dt(this.url)+"?viv-toc-box";return this.store.load(a).then(l=>{for(let f of Ba(l.document))f.setAttribute("data-vivliostyle-role","doc-toc");let h=this.store.getStyleForDoc(l),u=h.sizeViewport(i,1e5,s);t=new Xs(t.window,u.fontSize,0,t.root,u.width,u.height);let d=this.makeCustomRenderer(l),p=new La(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 t0(e){let t=e.target,i=t.textContent==In;t.textContent=i?ah: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==ah){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 lh=class extends Zy{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=$y(),this.jsonStore=Xf()}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 er(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 Ps(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 Ps(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 Ps(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=jo(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&&Ba(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""}},hh=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=mp}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=Cp(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 i0(e){return e.id}function n0(e){return t=>{let i=B("deobfuscator");return s0("SHA-1",e).then(n=>{let s=t.slice(0,1040),r=t.slice(1040,t.size);Wf(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(xu([a,r]))})}),i.result()}}function s0(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 r0(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 o0(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=fr(r,d=>d.refines),a=d=>kp(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=fr(w,b=>b.name);g.r=a(v)}return g})),l=a(fr(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(r0(p,h));for(let m=0;m<f.length;m++){let g=f[m].r;g&&u(g)}}};return u(l),l}function a0(){let e=window.MathJax;return e?e.Hub:null}var uh={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},Br="viv-id-",Ps=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 Br+Ih(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(Br)===0&&(n=n.substring(Br.length));let s=Sp(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 hh,u=l;h.initWithElement(u,e.url);let d=u.getAttribute("fallback");return d&&!uh[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=Ga(this.items,i0),this.itemMapByPath=Ga(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(uh[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=vh(r));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(oh.withChild("EncryptionMethod",oh.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[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=n0(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 Rd(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let s=new hh;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 Qy(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 Za;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 Za;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()}},ls=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),l0=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=Bh(n),this.clientLayout=new Uy(t),this.counterStore=new pf(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:ls(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(ls(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(ls(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(ls(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 Ou(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=Oh(this.viewport.width,this.viewport.height,i.width,i.height),a=tn(null,new At(o,null),"");r.delayedItems.push(new ra(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=$a(s),h=$a(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=a0();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 Xs(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 La(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 e0(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()}},ch="data-vivliostyle-viewer-status",h0="data-vivliostyle-spread-view",Od=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(Od||{}),u0=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",du),r("vivliostyle-viewport-css",pu),r("vivliostyle-polyfill-css",yu),t.setAttribute("data-vivliostyle-viewer-viewport",!0),An&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(ch,"loading"),this.fontMapper=new Yb(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=Lh(),this.pageSizes=[],this.pixelRatioLimit=Nh==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=Ch;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(ch,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 lh;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 lh;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 Ps(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"&&(Va(e.userAgentRootURL.replace(/resources\/?$/,"")),Ua(e.userAgentRootURL)),typeof e.rootURL=="string"&&(Va(e.rootURL),Ua(`${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&&(Ry(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?Qs(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 Xs(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new Xs(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(h0,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 l0(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 dh),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=jr().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&&Id(this.window)?Oy(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 dh)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=ph(e),i=null,n=this;zf(()=>{let s=B("commandLoop"),r=jr().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=ph(s),n.kick(),!0),this.window.adapt_command=n.sendCommand}},_d=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(_d||{}),dh=class Md extends Error{constructor(){super(),c(this,"name","RenderingCanceledError"),c(this,"message","Page rendering has been canceled"),c(this,"stack"),Object.setPrototypeOf(this,Md.prototype),this.stack=new Error().stack}};function ph(e){return typeof e=="string"?jo(e):e}var fh=Go;function c0(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function gh(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 zd=class{constructor(e,t){this.settings=e,c(this,"initialized",!1),c(this,"adaptViewer_"),c(this,"options"),c(this,"eventTarget"),c(this,"readyState"),yh(e.debug),this.adaptViewer_=new u0(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=c0(),t&&this.setOptions(t),this.eventTarget=new Xo,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},gh(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:d0(e)||t,document:s.documentObject,fragment:s.fragment,authorStyleSheet:o,userStyleSheet:a},gh(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()===fh.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===fh.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 d0(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 Dd=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(Dd||{}),p0=_d,f0=Od;ct.forceRegisterEndTiming("load_vivliostyle");var g0=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=`
|
|
1852
|
+
`),i.toString()}},jb=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 tt){let t=e.values,i=[];for(let n of t){let r=this.familyMap[n.stringValue()];r&&i.push(B(r)),i.push(n)}return new tt(i)}else{let t=this.familyMap[e.stringValue()];return t?new tt([B(t),e]):e}}},Xb=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=M("initFont"),r=e.src,s={};for(let l of sl(e.properties))s[l]=e.properties[l];let o=this.getViewFontFamily(e,i);s["font-family"]=B(o);let a=new sp(s),h=this.head.ownerDocument.createElement("style");return h.textContent=a.makeAtRule(r,t),this.head.appendChild(h),W.debug("Load font:",r),n.finish(a),n.result()}loadFont(e,t){let i=e.src,n=e.family+";"+i+";"+e.fontTraitKey,r=this.srcURLMap[n];return r?r.piggyback(s=>{t.registerFamily(e,s),W.debug("Found already-loaded font:",i)}):(r=new yr(()=>{let s=M("loadFont"),o=i.replace(/^url\("([^"]+)"\).*$/,"$1"),a=t.deobfuscator?t.deobfuscator(o):null;return a?Ds(o,"blob").then(h=>{if(!h.responseBlob){s.finish(null);return}a(h.responseBlob).then(l=>{this.initFont(e,l,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){W.warn("E_FONT_FACE_INVALID");continue}i.push(this.loadFont(n,t))}return vn(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=M("waitFontLoading");return i.loop(()=>i.sleep(20).thenAsync(()=>e.status==="loading"?N(!0):N(!1))).thenFinish(i),i.result()}},qb=1,js=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${qb++}`,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})}},Yb=class extends js{constructor(e){super(e,null,null,[],null),this.specified.width=new D(mr,0),this.specified.height=new D(wr,0)}},Ih=class extends So{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 h=this.lookupInstance(a);if(h)return s?h.resolveFunc(o[2]):h.resolveName(o[2])}}return null}}},op=class ap extends js{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 Ih||(this._scope=new Ih(t,this)),this.pageMaster=this,this.specified.width=new D(mr,0),this.specified.height=new D(wr,0),this.specified["wrap-flow"]=new D(v.auto,0),this.specified.position=new D(v.relative,0),this.specified.overflow=new D(v.visible,0)}createInstance(t){return new al(t,this)}clone(t){let i=new ap(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}},lp=class hp extends js{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 D(v.auto,0)}createInstance(t){return new Qb(t,this)}clone(t){let i=new hp(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}},Cr=class up extends js{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 Pn(t,this)}clone(t){let i=new up(t.parent.scope,this.name,this.pseudoName,this.classes,t.parent);return this.copySpecified(i),this.cloneChildren(i),i}};function Zb(e,t,i){return!t||J(t)?new Ye(e,i):t.toExpr(e,e.zero)}function be(e,t,i){return!t||t===v.auto||J(t)?null:t.toExpr(e,i)}function Kb(e,t,i){return!t||t===v.normal||J(t)?null:t.toExpr(e,i)}function yt(e,t,i){return!t||t===v.auto||J(t)?e.zero:t.toExpr(e,i)}function Ah(e,t,i){return!t||J(t)?e.zero:t===v.auto?null:t.toExpr(e,i)}function Gt(e,t,i,n){return!t||i===v.none||J(t)?e.zero:t.toExpr(e,n)}function cp(e,t,i){return!t||J(t)?i:t===v._true?e._true:t===v._false?e._false:t.toExpr(e,e.zero)}var Xs=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 ie(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?Gc:jc;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 Nu(i,0),r=this.resolveName("column-count"),s=this.resolveName("column-width"),o=this.resolveName("column-gap");t=ye(i,Ur(i,new Yn(i,"min",[n,r]),ie(i,s,o)),o);break}}return t&&(this.namedFuncs[e]=t),t}initEnabled(){let e=this.pageBox.scope,t=this.style,i=cp(e,t.enabled,e._true),n=be(e,t.page,e.zero);if(n){let o=new je(e,"page-number");i=At(e,i,new Fa(e,n,o))}let r=be(e,t["min-page-width"],e.zero);r&&(i=At(e,i,new ko(e,new je(e,"page-width"),r)));let s=be(e,t["min-page-height"],e.zero);s&&(i=At(e,i,new ko(e,new je(e,"page-height"),s))),i=this.boxSpecificEnabled(i),t.enabled=new $(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=be(e,t.left,i),r=be(e,t["margin-left"],i),s=Gt(e,t["border-left-width"],t["border-left-style"],i),o=yt(e,t["padding-left"],i),a=be(e,t.width,i),h=be(e,t["max-width"],i),l=yt(e,t["padding-right"],i),u=Gt(e,t["border-right-width"],t["border-right-style"],i),d=be(e,t["margin-right"],i),p=be(e,t.right,i),f=ie(e,s,o),g=ie(e,s,l);if(n&&p&&a){let b=ye(e,i,ie(e,a,ie(e,ie(e,n,f),g)));r?d?p=ye(e,b,d):d=ye(e,b,ie(e,p,r)):(b=ye(e,b,p),d?r=ye(e,b,d):(r=Ur(e,b,new Ye(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 b=ye(e,i,ie(e,ie(e,r,f),ie(e,d,g)));this.isAutoWidth&&(h||(h=ye(e,b,n||p)),!this.vertical&&(be(e,t["column-width"],null)||be(e,t["column-count"],null))&&(a=h,this.isAutoWidth=!1)),n?a?p||(p=ye(e,b,ie(e,n,a))):a=ye(e,b,ie(e,n,p)):n=ye(e,b,ie(e,p,a))}let m=t["snap-width"]||(this.parentInstance?this.parentInstance.style["snap-width"]:null),w=yt(e,m,i);t.left=new $(n),t["margin-left"]=new $(r),t["border-left-width"]=new $(s),t["padding-left"]=new $(o),t.width=new $(a),t["max-width"]=new $(h||a),t["padding-right"]=new $(l),t["border-right-width"]=new $(u),t["margin-right"]=new $(d),t.right=new $(p),t["snap-width"]=new $(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=be(e,t.top,n),s=be(e,t["margin-top"],i),o=Gt(e,t["border-top-width"],t["border-top-style"],i),a=yt(e,t["padding-top"],i),h=be(e,t.height,n),l=be(e,t["max-height"],n),u=yt(e,t["padding-bottom"],i),d=Gt(e,t["border-bottom-width"],t["border-bottom-style"],i),p=be(e,t["margin-bottom"],i),f=be(e,t.bottom,n),g=ie(e,o,a),m=ie(e,d,u);if(r&&f&&h){let x=ye(e,n,ie(e,h,ie(e,ie(e,r,g),m)));s?p?f=ye(e,x,s):p=ye(e,x,ie(e,f,s)):(x=ye(e,x,f),p?s=ye(e,x,p):(s=Ur(e,x,new Ye(e,.5)),p=s))}else{s||(s=e.zero),p||(p=e.zero),!r&&!f&&!h&&(r=e.zero),!r&&!h?(h=this.autoHeight,this.isAutoHeight=!0):!r&&!f?r=e.zero:!h&&!f&&(h=this.autoHeight,this.isAutoHeight=!0);let x=ye(e,n,ie(e,ie(e,s,g),ie(e,p,m)));this.isAutoHeight&&(l||(l=ye(e,x,r||f)),this.vertical&&(be(e,t["column-width"],null)||be(e,t["column-count"],null))&&(h=l,this.isAutoHeight=!1)),r?h?f||(f=ye(e,x,ie(e,r,h))):h=ye(e,x,ie(e,f,r)):r=ye(e,x,ie(e,f,h))}let w=t["snap-height"]||(this.parentInstance?this.parentInstance.style["snap-height"]:null),b=yt(e,w,i);t.top=new $(r),t["margin-top"]=new $(s),t["border-top-width"]=new $(o),t["padding-top"]=new $(a),t.height=new $(h),t["max-height"]=new $(l||h),t["padding-bottom"]=new $(u),t["border-bottom-width"]=new $(d),t["margin-bottom"]=new $(p),t.bottom=new $(f),t["snap-height"]=new $(b)}initColumns(){let e=this.pageBox.scope,t=this.style,i=be(e,t[this.vertical?"height":"width"],null),n=be(e,t["column-width"],i),r=be(e,t["column-count"],null),s=Kb(e,t["column-gap"],null);s||(s=new gr(e,1,"em")),n&&!r&&(r=new Yn(e,"floor",[Eo(e,ie(e,i,s),ie(e,n,s))]),r=new Yn(e,"max",[e.one,r])),r||(r=e.one),n=ye(e,Eo(e,ie(e,i,s),r),s),t["column-width"]=new $(n),t["column-count"]=new $(r),t["column-gap"]=new $(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=Qo(this.cascaded,e,r,!1,null);this.vertical=pd(s,e,this.parentInstance?this.parentInstance.vertical:!1),this.rtl=fd(s,e,this.parentInstance?this.parentInstance.rtl:!1),this.borderBoxSizing=((t=s["box-sizing"])==null?void 0:t.value)===v.border_box;let o=!!(e instanceof dl&&e.currentLayoutPosition&&new je(i,"left-page").evaluate(e));md(s,n,this.vertical,this.rtl,o,(a,h)=>h.value),this.autoWidth=new Ie(i,()=>this.calculatedWidth,"autoWidth"),this.autoHeight=new Ie(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&&un(t)&&this.pageMasterInstance instanceof yn&&(t==="font-size"&&e.isRelativeRootFontSize&&e.rootFontSize?r=new F(e.rootFontSize,"px"):r=(n=((i=e.styler)==null?void 0:i.rootStyle)[t])==null?void 0:n.value),r&&(r=Cs(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=Cs(e,r,t,s)}return nt(r,e)}getSpecial(e,t){let i=Kc(this.cascaded,t);if(i){let n=[];for(let r=0;r<i.length;r++){let s=i[r].evaluate(e,"");s&&s!==Y&&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()&&mu(r.unit)&&(r=Ou(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),I(t,i,r.toString()))}propagateDelayedProperty(e,t,i,n){let r=this.getProp(e,i);r&&n.push(new Va(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),I(t.element,"margin-left",`${n}px`),I(t.element,"padding-left",`${r}px`),I(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(I(t.element,"margin-right",`${r}px`),I(t.element,"padding-right",`${s}px`),I(t.element,"border-right-width",`${o}px`),t.marginRight=r,t.borderRight=o,this.vertical&&n>0){let a=i+t.getInsetRight(),h=a-Math.floor(a/n)*n;h>0&&(t.snapOffsetX=n-h,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(),h=a-Math.floor(a/i)*i;h>0&&(t.snapOffsetY=i-h,s+=t.snapOffsetY)}t.paddingTop=s,I(t.element,"top",`${n}px`),I(t.element,"margin-top",`${r}px`),I(t.element,"padding-top",`${s}px`),I(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;I(t.element,"height",`${s}px`),I(t.element,"margin-bottom",`${i}px`),I(t.element,"padding-bottom",`${n}px`),I(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){I(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,I(t.element,"height",`${i}px`))}sizeWithMaxWidth(e,t){I(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");I(t.element,"right",`${n}px`),I(t.element,"width",`${i}px`)}}prepareContainer(e,t,i,n,r){(!this.parentInstance||this.vertical!=this.parentInstance.vertical)&&I(t.element,"writing-mode",this.vertical?"vertical-rl":"horizontal-tb"),(!this.parentInstance||this.rtl!=this.parentInstance.rtl)&&I(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<Rh.length;s++)this.propagateProperty(e,t,Rh[s],n)}transferContentProps(e,t,i,n){for(let r=0;r<Lh.length;r++)this.propagateProperty(e,t,Lh[r],n);if(this.style["text-overflow"]){let r=t.element.firstElementChild;I(r,"text-overflow","inherit"),I(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!==v.auto&&!J(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!==v.auto&&!J(a)};for(let s=0;s<Oh.length;s++){let o=Oh[s];if(o==="width"||o==="height"){if(o==="width"&&!n()||o==="height"&&!r())continue;I(t,o,"100%");continue}this.propagatePropertyToElement(e,t,o,i)}}finishContainer(e,t,i,n,r,s,o){var a,h,l,u,d,p,f,g,m,w;this.vertical?this.calculatedWidth=t.computedBlockSize+t.snapOffsetX:this.calculatedHeight=t.computedBlockSize+t.snapOffsetY;let b=(this.vertical||!n)&&this.isAutoHeight,x=(!this.vertical||!n)&&this.isAutoWidth,y=null;if(x||b){x&&I(t.element,"width","auto"),b&&I(t.element,"height","auto");let P=n&&bs(n);P&&Us(n),y=s.getElementClientRect(n?n.element:t.element),P&&Ua(n),x&&(this.calculatedWidth=Math.ceil(y.right-y.left-t.paddingLeft-t.borderLeft-t.paddingRight-t.borderRight),this.vertical&&(this.calculatedWidth+=t.snapOffsetX)),b&&(this.calculatedHeight=y.bottom-y.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 P=this.getPropAsNumber(e,"column-rule-width"),S=this.getProp(e,"column-rule-style"),R=this.getProp(e,"column-rule-color");if(P>0&&S&&S!=v.none&&R!=v.transparent){let A=this.getPropAsNumber(e,"column-gap"),U=this.vertical?t.height:t.width,G=parseFloat(this.vertical?(a=n?.element.style.left)!=null?a:"":(h=n?.element.style.top)!=null?h:""),Z=t.getPaddingRect(),fe=n,ue=this.vertical?"border-top":"border-left";for(let C=1;C<r;C++){let _=this.vertical?(U+A)*C/r-A/2+t.paddingTop-P/2:(U+A)*C/r-A/2+t.paddingLeft-P/2,k=this.vertical?Z.y1+_+P/2:Z.x1+_+P/2,O=(d=(u=(l=fe.pageFloatLayoutContext)==null?void 0:l.parent)==null?void 0:u.getBlockEndEdgeOfBlockStartFloats)==null?void 0:d.call(u,k),E=(g=(f=(p=fe.pageFloatLayoutContext)==null?void 0:p.parent)==null?void 0:f.getBlockStartEdgeOfBlockEndFloats)==null?void 0:g.call(f,k),T=isFinite(O)?this.vertical?O-Z.x1:O-Z.y1:NaN,L=isFinite(E)?this.vertical?E-Z.x1:E-Z.y1:NaN,z=parseFloat(this.vertical?(m=n?.element.style.width)!=null?m:"":(w=n?.element.style.height)!=null?w:""),H=z>0?z:this.vertical?n.width:n.height,K=Math.max(G>0?G:0,0),ee=K+H,Q=Math.max(K,isFinite(this.vertical?L:T)?Math.max(0,this.vertical?L:T):0),ge=Math.min(ee,isFinite(this.vertical?T:L)?Math.max(0,this.vertical?T:L):ee),re=Math.max(0,ge-Q),se=t.element.ownerDocument.createElement("div");I(se,"position","absolute"),I(se,this.vertical?"left":"top",`${Q}px`),I(se,this.vertical?"top":"left",`${_}px`),I(se,this.vertical?"height":"width","0px"),I(se,this.vertical?"width":"height",`${re}px`),I(se,ue,`${P}px ${S.toString()}${R?` ${R.toString()}`:""}`),t.element.insertBefore(se,t.element.firstChild)}}}for(let P=0;P<Fh.length;P++)this.propagateProperty(e,t,Fh[P],o);for(let P=0;P<Bh.length;P++)this.propagateDelayedProperty(e,t,Bh[P],i.delayedItems)}applyCascadeAndInit(e,t){let i=this.cascaded,n=this.pageBox.specified;for(let s in n)this instanceof yn&&this.pageBox.pseudoName=="vivliostyle-page-rule-master"&&(s==="writing-mode"||s==="direction")||Bi(s)&&yi(i,s,ke(n,s));if(this.pageBox.pseudoName==ol)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 Ss(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)}},Rh=["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"],Fh=["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"],Lh=["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"],Oh=["width","height","image-resolution","object-fit","object-position"],Bh=["transform","transform-origin"],ol="background-host",Jb=class extends Xs{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)}},al=class extends Xs{constructor(e,t){super(e,t),this.pageMasterInstance=this}boxSpecificEnabled(e){let t=this.pageBox.pageMaster;return t.condition&&(e=At(t.scope,e,t.condition)),e}adjustPageLayout(e,t,i){}},Qb=class extends Xs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}},Pn=class extends Xs{constructor(e,t){super(e,t),this.pageMasterInstance=e.pageMasterInstance}processPartitionList(e,t,i){let n=null;if(t instanceof de&&(n=[t]),t instanceof tt&&(n=t.values),n){let r=this.pageBox.scope;for(let s=0;s<n.length;s++)if(n[s]instanceof de){let o=xo(n[s].name,"enabled"),a=new je(r,o);i&&(a=new mi(r,a)),e=At(r,e,a)}}return e}boxSpecificEnabled(e){let t=this.pageBox.scope,i=this.style,n=cp(t,i.required,t._false)!==t._false;if(n||this.isAutoHeight){let r=Zb(t,i["flow-from"],"body"),s=new Yn(t,"has-content",[r]);e=At(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=At(t,s,e),this.pageMasterInstance.style.enabled=new $(s)}return e}prepareContainer(e,t,i,n,r){var s;this.pageBox.pageMaster instanceof mp||(I(t.element,"overflow","hidden"),t.element.setAttribute("data-vivliostyle-page-partition",(s=this.pageBox.name)!=null?s:"")),super.prepareContainer(e,t,i,n,r)}},ll=class extends In{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 D(t,i?uc:cc)}},dp=class extends ll{constructor(e,t,i,n){super(e,t,i,n)}},ev=class pp extends ll{constructor(t,i,n,r){super(t,i,n,r),n.specified.width=new D(Nl,0),n.specified.height=new D(Nl,0)}startPartitionRule(t,i,n){let r=new Cr(this.scope,t,i,n,this.target),s=new dp(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}startPartitionGroupRule(t,i,n){let r=new lp(this.scope,t,i,n,this.target),s=new pp(this.scope,this.owner,r,this.validatorSet);this.owner.pushHandler(s)}},tv=class extends ll{constructor(e,t,i,n){super(e,t,i,n)}startPartitionRule(e,t,i){let n=new Cr(this.scope,e,t,i,this.target),r=new dp(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}startPartitionGroupRule(e,t,i){let n=new lp(this.scope,e,t,i,this.target),r=new ev(this.scope,this.owner,n,this.validatorSet);this.owner.pushHandler(r)}};function fp(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===v.vertical_lr||n!==v.vertical_rl&&r!==v.rtl?"ltr":"rtl"}var iv={a10:{width:new F(26,"mm"),height:new F(37,"mm")},a9:{width:new F(37,"mm"),height:new F(52,"mm")},a8:{width:new F(52,"mm"),height:new F(74,"mm")},a7:{width:new F(74,"mm"),height:new F(105,"mm")},a6:{width:new F(105,"mm"),height:new F(148,"mm")},a5:{width:new F(148,"mm"),height:new F(210,"mm")},a4:{width:new F(210,"mm"),height:new F(297,"mm")},a3:{width:new F(297,"mm"),height:new F(420,"mm")},a2:{width:new F(420,"mm"),height:new F(594,"mm")},a1:{width:new F(594,"mm"),height:new F(841,"mm")},a0:{width:new F(841,"mm"),height:new F(1189,"mm")},b10:{width:new F(31,"mm"),height:new F(44,"mm")},b9:{width:new F(44,"mm"),height:new F(62,"mm")},b8:{width:new F(62,"mm"),height:new F(88,"mm")},b7:{width:new F(88,"mm"),height:new F(125,"mm")},b6:{width:new F(125,"mm"),height:new F(176,"mm")},b5:{width:new F(176,"mm"),height:new F(250,"mm")},b4:{width:new F(250,"mm"),height:new F(353,"mm")},b3:{width:new F(353,"mm"),height:new F(500,"mm")},b2:{width:new F(500,"mm"),height:new F(707,"mm")},b1:{width:new F(707,"mm"),height:new F(1e3,"mm")},b0:{width:new F(1e3,"mm"),height:new F(1414,"mm")},c10:{width:new F(28,"mm"),height:new F(40,"mm")},c9:{width:new F(40,"mm"),height:new F(57,"mm")},c8:{width:new F(57,"mm"),height:new F(81,"mm")},c7:{width:new F(81,"mm"),height:new F(114,"mm")},c6:{width:new F(114,"mm"),height:new F(162,"mm")},c5:{width:new F(162,"mm"),height:new F(229,"mm")},c4:{width:new F(229,"mm"),height:new F(324,"mm")},c3:{width:new F(324,"mm"),height:new F(458,"mm")},c2:{width:new F(458,"mm"),height:new F(648,"mm")},c1:{width:new F(648,"mm"),height:new F(917,"mm")},c0:{width:new F(917,"mm"),height:new F(1297,"mm")},"jis-b10":{width:new F(32,"mm"),height:new F(45,"mm")},"jis-b9":{width:new F(45,"mm"),height:new F(64,"mm")},"jis-b8":{width:new F(64,"mm"),height:new F(91,"mm")},"jis-b7":{width:new F(91,"mm"),height:new F(128,"mm")},"jis-b6":{width:new F(128,"mm"),height:new F(182,"mm")},"jis-b5":{width:new F(182,"mm"),height:new F(257,"mm")},"jis-b4":{width:new F(257,"mm"),height:new F(364,"mm")},"jis-b3":{width:new F(364,"mm"),height:new F(515,"mm")},"jis-b2":{width:new F(515,"mm"),height:new F(728,"mm")},"jis-b1":{width:new F(728,"mm"),height:new F(1030,"mm")},"jis-b0":{width:new F(1030,"mm"),height:new F(1456,"mm")},letter:{width:new F(8.5,"in"),height:new F(11,"in")},legal:{width:new F(8.5,"in"),height:new F(14,"in")},ledger:{width:new F(11,"in"),height:new F(17,"in")}},nv=new F(.24,"pt"),T0=new F(3,"mm"),rv=new F(10,"mm"),sv=new F(13,"mm");function As(e){let t={width:mr,height:wr,bleed:Ne,bleedOffset:Ne,cropOffset:Ne},i=e.size;if(!(!i||i.value===v.auto)){let l=i.value,u,d;if(l.isSpaceList()?(u=l.values[0],d=l.values[1]):(u=l,d=null),u.isNumeric())t.width=u,t.height=d||u;else{let p=u.name&&iv[u.name.toLowerCase()];p&&(d&&d===v.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&&!J(n.value)?n.value:v.none,o=r&&!J(r.value)?r.value:v.auto;if(o===v.auto){if(s!==v.none){let l=!1;s.isSpaceList()?l=s.values.some(u=>u===v.crop):l=s===v.crop,l&&(t.bleed=new F(6,"pt"))}}else o.isNumeric()&&(t.bleed=o);let a=e["crop-offset"],h=a&&!J(a.value)?a.value:v.auto;return h===v.auto?s!==v.none&&(t.bleedOffset=sv):h.isNumeric()&&(t.cropOffset=h),t}function Mh(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===mr?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===wr?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 gp(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 tr(e,t,i,n){n=n||"polyline";let r=e.createElementNS("http://www.w3.org/2000/svg",n);return r.setAttribute("stroke",i===v.auto?"#010101":i.toString()),r.setAttribute("stroke-width",t),r.setAttribute("fill","none"),r}var wa=(e=>(e.TOP_LEFT="top left",e.TOP_RIGHT="top right",e.BOTTOM_LEFT="bottom left",e.BOTTOM_RIGHT="bottom right",e))(wa||{});function ov(e,t,i,n,r,s,o){let a=r;a<=s+2*_t.mm&&(a=s+r/2);let h=Math.max(r,a),l=s+h+i/2,u=gp(e,l,l),d=[[0,s+r],[r,s+r],[r,s+r-a]],p=d.map(m=>[m[1],m[0]]);(t==="top right"||t==="bottom right")&&(d=d.map(m=>[s+h-m[0],m[1]]),p=p.map(m=>[s+h-m[0],m[1]])),(t==="bottom left"||t==="bottom right")&&(d=d.map(m=>[m[0],s+h-m[1]]),p=p.map(m=>[m[0],s+h-m[1]]));let f=tr(e,i,n);f.setAttribute("points",d.map(m=>m.join(",")).join(" ")),u.appendChild(f);let g=tr(e,i,n);return g.setAttribute("points",p.map(m=>m.join(",")).join(" ")),u.appendChild(g),t.split(" ").forEach(m=>{u.style[m]=`${o}px`}),u}var cr=(e=>(e.TOP="top",e.BOTTOM="bottom",e.LEFT="left",e.RIGHT="right",e))(cr||{});function av(e,t,i,n,r,s){let o=r*2,a,h;t==="top"||t==="bottom"?(a=o,h=r):(a=r,h=o);let l=gp(e,a,h),u=tr(e,i,n);u.setAttribute("points",`0,${h/2} ${a},${h/2}`),l.appendChild(u);let d=tr(e,i,n);d.setAttribute("points",`${a/2},0 ${a/2},${h}`),l.appendChild(d);let p=tr(e,i,n,"circle");p.setAttribute("cx",a/2),p.setAttribute("cy",h/2),p.setAttribute("r",r/4),l.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(cr).forEach(g=>{let m=cr[g];m===t?l.style[m]=`${s}px`:m!==f&&(l.style[m]="0",l.style[`margin-${m}`]="auto")}),l}function lv(e,t,i,n){let r=!1,s=!1,o=e.marks;if(o){let m=o.value;m instanceof te?m.values.forEach(w=>{w===v.crop?r=!0:w===v.cross&&(s=!0)}):m===v.crop?r=!0:m===v.cross&&(s=!0)}let a=t.bleed;if(!r&&!s)return;let h=i.container,l=h.ownerDocument,u=nt(nv,n),d=Math.max(0,t.bleedOffset-nt(rv,n)),p=t.bleedOffset-d,f=e["crop-marks-line-color"],g=f&&!J(f.value)?f.value:v.auto;r&&Object.keys(wa).forEach(m=>{let w=wa[m],b=ov(l,w,u,g,p,a,d);h.appendChild(b)}),s&&Object.keys(cr).forEach(m=>{let w=cr[m],b=av(l,w,u,g,p,d);h.appendChild(b)})}var ya=(()=>{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})(),hl={"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"}},hv=(()=>{let e=hl;return Object.keys(e).sort((t,i)=>e[t].order-e[i].order)})(),ul="vivliostyle-page-rule-master",dr="_marginBoxes",Rs="_footnoteArea",mp=class extends op{constructor(e,t,i){super(e,null,ul,[],t,null,0),c(this,"pageMarginBoxes",{});let n=As(i),r=new uv(this.scope,this,i,n);this.createPageMarginBoxes(i),this.applySpecified(i,n)}createPageMarginBoxes(e){let t=e[dr];t&&hv.forEach(i=>{t[i]&&(this.pageMarginBoxes[i]=new dv(this.scope,this,i,e))})}applySpecified(e,t){this.specified.position=new D(v.relative,0),this.specified.width=new D(t.width,0),this.specified.height=new D(t.height,0);for(let i in e)!ya[i]&&i!=="background-clip"&&(this.specified[i]=e[i])}createInstance(e){return new yn(e,this)}},uv=class extends Cr{constructor(e,t,i,n){super(e,null,null,[],t),this.pageSize=n;let r=new cv(this.scope,this);this.applySpecified(i)}applySpecified(e){this.specified["wrap-flow"]=new D(v.auto,0),this.specified["z-index"]=new D(new Be(0),0),this.specified.position=new D(v.absolute,0),this.specified.overflow=new D(v.visible,0);for(let t in ya)ya.hasOwnProperty(t)&&(this.specified[t]=e[t])}createInstance(e){return new fv(e,this)}},cv=class extends Cr{constructor(e,t){super(e,null,null,[],t),this.specified["flow-from"]=new D(B("body"),0)}createInstance(e){return new wp(e,this)}},dv=class extends Cr{constructor(e,t,i,n){super(e,null,null,[],t),this.marginBoxName=i,this.applySpecified(n)}applySpecified(e){let t=e[dr][this.marginBoxName];for(let i in e){let n=e[i],r=t[i];(Wc[i]||r&&r.value===v.inherit)&&(this.specified[i]=n)}for(let i in t)if(Object.prototype.hasOwnProperty.call(t,i)){let n=t[i];n&&n.value!==Y&&n.value!==v.inherit&&n.value!==v.unset&&n.value!==v.revert&&(this.specified[i]=n)}}createInstance(e){return new yp(e,this)}},yn=class extends al{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=Ne,e["margin-left"]=Ne,e["border-left-width"]=Ne,e["padding-left"]=Ne,e["padding-right"]=Ne,e["border-right-width"]=Ne,e["margin-right"]=Ne,e.right=Ne}initVertical(){let e=this.style;e.top=Ne,e["margin-top"]=Ne,e["border-top-width"]=Ne,e["padding-top"]=Ne,e["padding-bottom"]=Ne,e["border-bottom-width"]=Ne,e["margin-bottom"]=Ne,e.bottom=Ne}setPageAreaDimension(e){this.pageAreaDimension=e;let t=this.style;t.width=new $(e.borderBoxWidth),t.height=new $(e.borderBoxHeight),t["padding-left"]=new $(e.marginLeft),t["padding-right"]=new $(e.marginRight),t["padding-top"]=new $(e.marginTop),t["padding-bottom"]=new $(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",h=this.pageBox.scope,l={},u={},d={};for(let y in e){let P=hl[y];if(P){let S=e[y],R=this.pageMarginBoxInstances[y],A=new as(S,R.style,t,h,r);l[P.positionAlongVariableDimension]=S,u[P.positionAlongVariableDimension]=R,d[P.positionAlongVariableDimension]=A}}let p={start:i.start.evaluate(n),end:i.end.evaluate(n),extent:i.extent.evaluate(n)},f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,m={};Object.keys(l).forEach(y=>{let P=y,S=be(h,u[P].style[t?"max-width":"max-height"],i.extent);if(S){let R=S.evaluate(n);if(f[P]>R){let A=d[P]=new _h(l[P],u[P].style,t,h,r,R);m[P]=A.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),g=!1,[s,o,a].forEach(y=>{var P;f[y]=(P=m[y])!=null?P:f[y]}));let w={};Object.keys(l).forEach(y=>{let P=y,S=be(h,u[P].style[t?"min-width":"min-height"],i.extent);if(S){let R=S.evaluate(n);if(f[P]<R){let A=d[P]=new _h(l[P],u[P].style,t,h,r,R);w[P]=A.getOuterSize(),g=!0}}}),g&&(f=this.getSizesOfMarginBoxesAlongVariableDimension(d,p.extent),[s,o,a].forEach(y=>{f[y]=w[y]||f[y]}));let b=p.start+p.extent,x=p.start+(p.start+p.extent);[s,o,a].forEach(y=>{let P=f[y];if(P!=null){let S=l[y],R=0;switch(y){case s:R=t?S.left:S.top;break;case o:R=(x-P)/2;break;case a:R=b-P;break}t?S.setHorizontalPosition(R,P-S.getInsetLeft()-S.getInsetRight()):S.setVerticalPosition(R,P-S.getInsetTop()-S.getInsetBottom())}})}getSizesOfMarginBoxesAlongVariableDimension(e,t){var i;let n=e.start,r=e.center,s=e.end,o={};if(r){let a=[n,s],h=new pv(a),l=this.distributeAutoMarginBoxSizes(r,h,t);l.xSize!=null&&(o.center=l.xSize);let u=(i=l.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 as&&e.minMaxFitContent&&(n.xSize=e.getOuterSize()),t instanceof as&&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(),h=t.getOuterMinContentSize(),l=a+h;l<i?n.xSize=a+(i-l)*(r-a)/(o-l):l>0&&(n.xSize=i*a/l)}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)}},as=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===v.auto||J(s),this.minMaxFitContent=s instanceof de&&(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=za(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()}},pv=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}},_h=class extends as{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()}},fv=class extends Pn{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),h=be(n,t[o],a),l=be(n,t[`margin-${r}`],a),u=be(n,t[`margin-${s}`],a),d=yt(n,t[`padding-${r}`],a),p=yt(n,t[`padding-${s}`],a),f=Gt(n,t[`border-${r}-width`],t[`border-${r}-style`],a),g=Gt(n,t[`border-${s}-width`],t[`border-${s}-style`],a),m=ie(n,ie(n,f,d),ie(n,g,p)),w,b,x;return h?(this.borderBoxSizing?(b=h,x=ye(n,b,m)):(x=h,b=ie(n,x,m)),w=ye(n,a,b),!l&&!u?(l=Ur(n,w,new Ye(n,.5)),u=l):l?u=ye(n,w,l):l=ye(n,w,u)):(l||(l=n.zero),u||(u=n.zero),w=ie(n,l,u),b=ye(n,a,w),x=ye(n,b,m),h=this.borderBoxSizing?b:x),t[r]=new $(l),t[s]=new $(u),t[`margin-${r}`]=Ne,t[`margin-${s}`]=Ne,t[`border-${r}-width`]=new $(f),t[`border-${s}-width`]=new $(g),t[`padding-${r}`]=new $(d),t[`padding-${s}`]=new $(p),t[o]=new $(h),t[`max-${o}`]=new $(h),{borderBoxExtent:b,contentBoxExtent:x,marginStart:l,marginEnd:u}}prepareContainer(e,t,i,n,r){t.element.setAttribute("data-vivliostyle-page-area-container",!0),super.prepareContainer(e,t,i,n,r)}},wp=class extends Pn{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 $(this.parentInstance.contentBoxWidth),e["margin-left"]=new $(new rn(i,t.left.toExpr(i,null))),e["margin-right"]=new $(new rn(i,t.right.toExpr(i,null))),e["border-left-width"]=t.left,e["border-right-width"]=t.right,e["border-left-style"]=v.solid,e["border-right-style"]=v.solid,e["border-left-color"]=v.transparent,e["border-right-color"]=v.transparent}initVertical(){let e=this.style,t=this.parentInstance.style,i=this.pageBox.scope;e.top=t["padding-top"],e.height=new $(this.parentInstance.contentBoxHeight),e["margin-top"]=new $(new rn(i,t.top.toExpr(i,null))),e["margin-bottom"]=new $(new rn(i,t.bottom.toExpr(i,null))),e["border-top-width"]=t.top,e["border-bottom-width"]=t.bottom,e["border-top-style"]=v.solid,e["border-bottom-style"]=v.solid,e["border-top-color"]=v.transparent,e["border-bottom-color"]=v.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}},yp=class extends Pn{constructor(e,t){super(e,t),c(this,"boxInfo"),c(this,"suppressEmptyBoxGeneration",!0);let i=t.marginBoxName;this.boxInfo=hl[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){I(t,"display","flex"),I(t,"flex-flow",this.vertical?this.rtl?"row-reverse":"row":"column");let i=this.getProp(e,"vertical-align"),n=null;i===B("middle")?n="center":i===B("top")?n="flex-start":i===B("bottom")&&(n="flex-end"),n&&I(t,"justify-content",n);let r=this.getProp(e,"content");if(this.vertical||r instanceof ot||r instanceof $&&r.expr instanceof Ie&&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")),I(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",h=a?t.borderBoxWidth:t.borderBoxHeight,l=be(n,i[o],h),u=a?t.marginLeft:t.marginTop;if(this.boxInfo.positionAlongVariableDimension==="start")i[r]=new $(u);else if(l){let d=yt(n,i[`margin-${r}`],h),p=yt(n,i[`margin-${s}`],h),f=yt(n,i[`padding-${r}`],h),g=yt(n,i[`padding-${s}`],h),m=Gt(n,i[`border-${r}-width`],i[`border-${r}-style`],h),w=Gt(n,i[`border-${s}-width`],i[`border-${s}-style`],h),b=ie(n,l,ie(n,this.borderBoxSizing?n.zero:ie(n,ie(n,f,g),ie(n,m,w)),ie(n,d,p)));switch(this.boxInfo.positionAlongVariableDimension){case"center":i[r]=new $(ie(n,u,Eo(n,ye(n,h,b),new Ye(n,2))));break;case"end":i[r]=new $(ye(n,ie(n,u,h),b));break}}}positionAndSizeAlongFixedDimension(e,t){let i=this.style,n=this.pageBox.scope,r=this.borderBoxSizing,s=e.inside,o=e.outside,a=e.extent,h=t[`margin${o.charAt(0).toUpperCase()}${o.substring(1)}`],l=Ah(n,i[`margin-${s}`],h),u=Ah(n,i[`margin-${o}`],h),d=yt(n,i[`padding-${s}`],h),p=yt(n,i[`padding-${o}`],h),f=Gt(n,i[`border-${s}-width`],i[`border-${s}-style`],h),g=Gt(n,i[`border-${o}-width`],i[`border-${o}-style`],h),m=be(n,i[a],h),w=null;function b(x){if(w)return w;w={extent:m?m.evaluate(x):null,marginInside:l?l.evaluate(x):null,marginOutside:u?u.evaluate(x):null};let y=h.evaluate(x),P=0;return r||[f,d,p,g].forEach(S=>{S&&(P+=S.evaluate(x))}),(w.marginInside===null||w.marginOutside===null)&&P+w.extent+w.marginInside+w.marginOutside>y&&(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=y-P-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=y-P-w.extent-w.marginOutside:typeof w.marginInside=="number"&&w.marginOutside===null?w.marginOutside=y-P-w.extent-w.marginInside:w.marginInside=w.marginOutside=(y-P-w.extent)/2),w}i[a]=new $(new Ie(n,function(){let x=b(this).extent;return x===null?"auto":x},a)),i[`margin-${s}`]=new $(new Ie(n,function(){let x=b(this).marginInside;return x===null?"auto":x},`margin-${s}`)),i[`margin-${o}`]=new $(new Ie(n,function(){let x=b(this).marginOutside;return x===null?"auto":x},`margin-${o}`)),s==="left"?i.left=new $(ie(n,t.marginLeft,t.borderBoxWidth)):s==="top"&&(i.top=new $(ie(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,h=this.pageBox.marginBoxName,l=this.boxInfo;!l.isInLeftColumn&&!l.isInRightColumn?l.isInTopRow?a.top[h]=t:l.isInBottomRow&&(a.bottom[h]=t):!l.isInTopRow&&!l.isInBottomRow&&(l.isInLeftColumn?a.left[h]=t:l.isInRightColumn&&(a.right[h]=t));let u=this.parentInstance.pageAreaDimension,d=this.getProp(e,"width"),p=d instanceof de&&(d.name==="min-content"||d.name==="max-content"||d.name==="fit-content")?d.name:null,f=this.getPropAsNumber(e,"min-width"),g=this.getPropAsNumber(e,"max-width");if(p||f||g){p&&I(t.element,"width",p),f&&I(t.element,"min-width",`${f}px`),g&&I(t.element,"max-width",`${g}px`);let y=this.getProp(e,"margin-left"),P=this.getProp(e,"margin-right");if(l.isInLeftColumn){let S=u.borderBoxWidth.evaluate(e)+u.marginRight.evaluate(e);I(t.element,"right",`${S}px`),(y===v.auto||P!==v.auto)&&I(t.element,"margin-left","auto"),P===v.auto&&I(t.element,"margin-right","auto")}else l.isInRightColumn&&(I(t.element,"right","0"),(P===v.auto||y!==v.auto)&&I(t.element,"margin-right","auto"),y===v.auto&&I(t.element,"margin-left","auto"))}let m=this.getProp(e,"height"),w=m instanceof de&&(m.name==="min-content"||m.name==="max-content"||m.name==="fit-content")?m.name:null,b=this.getPropAsNumber(e,"min-height"),x=this.getPropAsNumber(e,"max-height");if(w||b||x){w&&I(t.element,"height",w),b&&I(t.element,"min-height",`${b}px`),x&&I(t.element,"max-height",`${x}px`);let y=this.getProp(e,"margin-top"),P=this.getProp(e,"margin-bottom");if(l.isInTopRow){let S=u.borderBoxHeight.evaluate(e)+u.marginBottom.evaluate(e);I(t.element,"bottom",`${S}px`),(y===v.auto||P!==v.auto)&&I(t.element,"margin-top","auto"),P===v.auto&&I(t.element,"margin-bottom","auto")}else l.isInBottomRow&&(I(t.element,"bottom","0"),(P===v.auto||y!==v.auto)&&I(t.element,"margin-bottom","auto"),y===v.auto&&I(t.element,"margin-top","auto"))}}},gv=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 je(e,"page-number"),r=new Fa(e,new Cu(e,n,new Ye(e,2)),i?e.one:e.zero);e.defineName("recto-page",new mi(e,r)),e.defineName("verso-page",r),(t.pageProgression||fp(this.docElementStyle))==="ltr"?(e.defineName("left-page",r),e.defineName("right-page",new mi(e,r))):(e.defineName("left-page",new mi(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===ol?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 D?r=`${n.value}`:r=this.makeCascadeValueObjectKey(n),t.push(i+r+(n.priority||""))}return t.sort().join("^")}generatePageRuleMaster(e){let t=new mp(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:ul}),n=i.specified,r=e.size;if(r&&!J(r.value)){let o=As(e),a=r.priority;Dt(n,"width",new D(o.width,a),this.context),Dt(n,"height",new D(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}},mv=class extends Se{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}},wv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"page-number").evaluate(e.context)===1&&this.chained.apply(e)}getPriority(){return 2}},yv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"blank-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 2}},bv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"left-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},vv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"right-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},xv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"recto-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Sv=class extends Se{constructor(e){super(),this.scope=e}apply(e){new je(this.scope,"verso-page").evaluate(e.context)&&this.chained.apply(e)}getPriority(){return 1}},Cv=class extends Hi{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}},kv=class extends Hi{constructor(e,t,i,n){super(t,i),this.scope=e,this.a=t,this.b=i,this.pageType=n}apply(e){let t=e.pageTypePageIndices[this.pageType];if(t){for(let i of t)if(this.matchANPlusB(i)){this.chained.apply(e);return}}}getPriority(){return 3}},Ev=class extends Ya{constructor(e,t){super(e,t,null,null,null)}apply(e){Pv(e.context,e.currentStyle,this.style,this.specificity,e)}};function Pv(e,t,i,n,r){vs(e,t,i,n,null,null,null);let s=i[dr];if(s){let a=ei(t,dr);for(let h in s)if(s.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l),vs(e,l,s[h],n,null,null,null)}}let o=i[Rs];if(o){let a=ei(t,Rs);for(let h in o)if(o.hasOwnProperty(h)){let l=a[h];l||(l={},a[h]=l);let u=o[h];for(let p in u)if(u.hasOwnProperty(p)&&p!=="_pseudos"){let f=u[p];f instanceof D&&Dt(l,p,f)}let d=bt(u,"_pseudos");if(d){let p=ei(l,"_pseudos");for(let f in d)if(d.hasOwnProperty(f)){let g=p[f];g||(g={},p[f]=g);let m=d[f];for(let w in m)if(m.hasOwnProperty(w)){let b=m[w];b instanceof D&&Dt(g,w,b)}}}}}}var Nv=class extends ar{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 mv(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 kv(this.scope,i,n,r)),this.specificity+=65792}else this.currentPseudoPageClassSelectors.push(`:${e}(${i}n${n<0?n:"+"+n})`),this.chain.push(new Cv(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 wv(this.scope)),this.specificity+=256;break;case"blank":this.chain.push(new yv(this.scope)),this.specificity+=256;break;case"left":this.chain.push(new bv(this.scope)),this.specificity+=1;break;case"right":this.chain.push(new vv(this.scope)),this.specificity+=1;break;case"recto":this.chain.push(new xv(this.scope)),this.specificity+=1;break;case"verso":this.chain.push(new Sv(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=ke(this.elementStyle,e),r=this.pageProps;if(e==="bleed"||e==="marks")r[""]||(r[""]={}),Object.keys(r).forEach(s=>{yi(r[s],e,n)});else if(e==="size"){let s=r[""];this.currentPageSelectors.forEach(o=>{let a=new D(n.value,n.priority+o.specificity),h=o.selectors?o.selectors.join(""):"",l=r[h];l?Dt(l,e,a):(l=r[h]={},yi(l,e,a),s&&["bleed","marks"].forEach(u=>{s[u]&&yi(l,u,s[u])}))})}}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.pagetypes,"*",e)}makeApplyRuleAction(e){return new Ev(this.elementStyle,e)}startFootnoteRule(e){let t=ei(this.elementStyle,Rs),i=t.area;if(i||(i={},t.area=i),e){let r=ei(i,"_pseudos"),s=r[e];s||(s={},r[e]=s),i=s}let n=new bp(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}startPageMarginBoxRule(e){let t=ei(this.elementStyle,dr),i=t[e];i||(i={},t[e]=i);let n=new Tv(this.scope,this.owner,this.validatorSet,i);this.owner.pushHandler(n)}},Tv=class extends In{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 D(t,n);yi(this.boxStyle,e,r)}},bp=class extends In{constructor(e,t,i,n){super(e,t,!1),this.validatorSet=i,this.areaStyle=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 D(t,n);yi(this.areaStyle,e,r)}},si=!0;function Iv(e){si=e}var _i=[];function Dh(e,t){return e===t||(e.src||t.src?e.src===t.src:e.textContent===t.textContent)}function vp(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 cl(e,t,i){if(!si||!(i!=null&&i.inHead)&&!(i!=null&&i.atEnd)&&vp(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,h=(s&&!a||r&&e.defer)&&!o,l=!(i!=null&&i.atEnd)&&(i?.forceDefer||h||a);if(xp(t)||(t.onload=null),l)return _i.some(d=>Dh(d,e))||_i.push(e),N(!0);for(let d of t.document.head.getElementsByTagName("script"))d.hasAttribute("data-vivliostyle-scripting")&&Dh(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=h,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(W.debug("script:",r),r){let d=Ut(u);return t.document.head.appendChild(u),vn([d])}else return t.document.head.appendChild(u),N(!0)}function Av(e,t){var i;let n={},r=o=>{var a;let h=(a=o["font-family"])==null?void 0:a.value;if(h)if(h.values)for(let u of h.values)n[u.stringValue()]=!0;else n[h.stringValue()]=!0;let l=o._marginBoxes;if(l)for(let u of Object.values(l))r(u)},s=o=>{if(o instanceof Ya)r(o.style);else if(o instanceof Rn||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 Rv(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=Av(e,i),r.textContent=e.documentElement.textContent,t.document.body.appendChild(r),r}function Fv(e,t,i){if(!si)return N(!1);let n=vp(e);if(n.length===0)return N(!1);let r=n.some(u=>!(u.async||u.defer||u.type==="module")),s=r?Rv(e,t,i):null,o=t.document.fonts,a=t.$,h=!1,l=M("loadScripts");return l.loop(()=>{if(n.length===0)return r?l.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 cl(u,t,{inHead:!0,forceDefer:h}).thenAsync(()=>(!h&&t.$!==a&&(_i.push(u),h=!0),n.length===0&&r&&(W.debug("dispatchEvent: DOMContentLoaded (document)"),t.document.dispatchEvent(new Event("DOMContentLoaded"))),N(!0)))}).then(()=>{s&&s.remove(),l.finish(!0)}),l.result()}function Lv(e){if(!si)return N(!1);let t=M("loadScripts");return t.loop(()=>_i.length===0?N(!1):cl(_i.shift(),e,{atEnd:!0}).thenReturn(_i.length>0)).then(()=>{W.debug("dispatchEvent: DOMContentLoaded (window)"),e.dispatchEvent(new Event("DOMContentLoaded")),W.debug("dispatchEvent: load (window)"),e.dispatchEvent(new Event("load")),t.finish(!0)}),t.result()}function xp(e){return si?_i.length>0||!!e.document.head.querySelector("script[data-vivliostyle-scripting]"):!1}function Fs(e,t){return!!(e&&e.match(new RegExp(`(^|\\s)${t}($|\\s)`)))}function dn(e){if(e.localName!=="aside")return!1;if(Fs(e.getAttribute("role"),"doc-footnote"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return Fs(t,"footnote")}function ir(e){if(e.localName!=="a")return!1;if(Fs(e.getAttribute("role"),"doc-noteref"))return!0;let t=e.getAttributeNS("http://www.idpf.org/2007/ops","type")||e.getAttribute("epub:type");return Fs(t,"noteref")}function Ov(e){let t=e.getElementsByTagName("a");for(let i=0;i<t.length;i++){let n=t.item(i);if(!ir(n)||!(n instanceof HTMLAnchorElement)||!n.hash||n.href!==n.baseURI.replace(/#.*$/,"")+n.hash)continue;let r=n.hash.substring(1),s=e.getElementById(r);s&&dn(s)&&s.setAttribute("data-vivliostyle-footnote-referenced","true")}}kt("PREPROCESS_SINGLE_DOCUMENT",Ov);var Bv=(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)}`),Mv={};function _v(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 ba=class Xn extends Ta{constructor(t,i,n,r,s,o,a,h,l,u,d,p,f,g,m,w=new Map,b={value:!1}){super(),this.flowName=t,this.context=i,this.viewport=n,this.styler=r,this.regionIds=s,this.xmldoc=o,this.docFaces=a,this.footnoteStyle=h,this.stylerProducer=l,this.page=u,this.customRenderer=d,this.fallbackMap=p,this.documentURLTransformer=f,this.pageProps=g,this.cascadedPageStyle=m,this.semanticFootnoteFirstRefOffsets=w,this.semanticFootnoteFirstRefOffsetsInitialized=b,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 Xn(this.flowName,this.context,this.viewport,this.styler,this.regionIds,this.xmldoc,this.docFaces,this.footnoteStyle,this.stylerProducer,this.page,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.pageProps,this.cascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized)}initializeSemanticFootnoteFirstRefOffsets(t){if(this.semanticFootnoteFirstRefOffsetsInitialized.value)return;let i=t.getElementsByTagName("a");for(let n=0;n<i.length;n++){let r=i.item(n);if(!ir(r))continue;let s=r.getAttribute("href")||r.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!s)continue;let o=Ir(s,this.xmldoc.url);o!=="#"&&(this.semanticFootnoteFirstRefOffsets.has(o)||this.semanticFootnoteFirstRefOffsets.set(o,this.xmldoc.getElementOffset(r)))}this.semanticFootnoteFirstRefOffsetsInitialized.value=!0}shouldGenerateSemanticFootnote(t){if(t.localName!=="a"||!ir(t))return!0;let i=t.getAttribute("href")||t.getAttributeNS("http://www.w3.org/1999/xlink","href");if(!i)return!0;let n=Ir(i,this.xmldoc.url);if(n==="#")return!0;this.initializeSemanticFootnoteFirstRefOffsets(t.ownerDocument);let r=this.semanticFootnoteFirstRefOffsets.get(n);return r==null?!0:this.xmldoc.getElementOffset(t)===r}createPseudoelementShadow(t,i,n,r,s,o,a,h){var l;let u=this.getPseudoMap(n,this.regionIds,this.isFootnote,this.nodeContext,o);if(!u)return h;let d=[],p=$n.createElementNS("http://www.pyroxy.com/ns/shadow","root"),f=p;for(let w of Yw){let b;if(w){if(!u[w]||w=="footnote-marker"&&!(i&&this.isFootnote)&&!((l=this.nodeContext)!=null&&l.pluginProps.nestedFootnoteDetached))continue;if(w.match(/^first-/)){let x=r.display;if(!x||x===v.inline)continue;let y=t.firstElementChild;if(y&&Me(y.previousSibling)){let P=s.getStyle(y,!1);if(P){let S=ke(P,"display");if(S!=null&&S.value&&S.value!==v.inline)continue}}}if(w==="before"||w==="after"||w==="footnote-marker"){let x=u[w].content;if(!x||!Rt(x.value))continue}d.push(w),b=$n.createElementNS("http://www.w3.org/1999/xhtml","span"),Xr(b,w)}else b=$n.createElementNS("http://www.pyroxy.com/ns/shadow","content");f.appendChild(b),w.match(/^first-/)&&(f=b)}if(!d.length)return h;let g=new uo(t,n,s,o,this.exprContentListener),m=new $r(t,p,null,a,h,ht.ROOTLESS,g);return h||m}getPseudoMap(t,i,n,r,s){let o=bt(t,"_pseudos");if(!o)return null;let a={};for(let h in o){let l=a[h]={};Jn(l,o[h],s),Jo(l,s,o[h]),gd(o[h],i,n,(u,d)=>{Jn(l,d,s),dd(d,p=>{Jn(l,p,s)})})}return a}createRefShadow(t,i,n,r,s){let o=M("createRefShadow");return this.xmldoc.store.load(t).then(a=>{let h=a;if(h){let l=h.getElement(t);if(l){let u=this.stylerProducer.getStylerForDoc(h);s=new $r(n,l,h,r,s,i,u)}}o.finish(s)}),o.result()}createShadows(t,i,n,r,s,o,a){let h=M("createShadows"),l=null,u=r.template,d;if(u instanceof ot||u===v.footnote)if(u!==v.footnote||this.shouldGenerateSemanticFootnote(t)){let p=u instanceof ot?u.url:Ee("user-agent.xml#footnote",fi);d=this.createRefShadow(p,ht.ROOTLESS,t,a,l)}else d=N(l);else d=N(l);return d.then(p=>{let f=null;if(t.namespaceURI=="http://www.pyroxy.com/ns/shadow"&&t.localName=="include"){let m=t.getAttribute("href"),w=null;m?w=a?a.xmldoc:this.xmldoc:a&&(a.owner.namespaceURI=="http://www.w3.org/1999/xhtml"?m=a.owner.getAttribute("href"):m=a.owner.getAttributeNS("http://www.w3.org/1999/xlink","href"),w=a.parentShadow?a.parentShadow.xmldoc:this.xmldoc),m&&(m=Ir(m,w.url),f=this.createRefShadow(m,ht.ROOTED,t,a,p))}f==null&&(f=N(p));let g=null;f.then(m=>{if(r.display===v.table_cell){let w=Ee("user-agent.xml#table-cell",fi);g=this.createRefShadow(w,ht.ROOTLESS,t,a,m)}else g=N(m);g.then(w=>{w=this.createPseudoelementShadow(t,i,n,r,s,o,a,w),h.finish(w)})})}),h.result()}setViewRoot(t,i){this.viewRoot=t,this.isFootnote=i}computeStyle(t,i,n,r){var s;let o=this.context,a=Qo(n,o,this.regionIds,this.isFootnote,this.nodeContext),h=!((s=this.nodeContext)!=null&&s.parent);h&&(!a["writing-mode"]&&this.styler.rootStyle["writing-mode"]&&(a["writing-mode"]=this.styler.rootStyle["writing-mode"]),!a.direction&&this.styler.rootStyle.direction&&(a.direction=this.styler.rootStyle.direction));let l=t;t=pd(a,o,t);let u=!h&&t!==l;i=fd(a,o,i);let d=(b,x)=>{let y;u&&(t?/^(min-|max-)?(height|inline-size)$/.test(b)&&(y=o.pageAreaHeight):/^(min-|max-)?(width|inline-size)$/.test(b)&&(y=o.pageAreaWidth));let P=x.evaluate(o,b,y,t);return b=="font-family"&&(P=this.docFaces.filterFontFamily(P)),P},p=!!new je(o.style.pageScope,"left-page").evaluate(o);if(md(a,r,t,i,p,d),u){let b=r[t?"height":"width"];(!b||b===v.auto)&&(r[t?"height":"width"]=v.max_content)}if(ys(r.position))return r.position=v.fixed,r.visibility=v.hidden,t;let f=r.position,g=r.float,m=r.display||(this.sourceNode&&this.sourceNode.namespaceURI==="http://www.w3.org/1999/xhtml"?v.inline:void 0),w=Bc(m,f,g,this.sourceNode===this.xmldoc.root);return["display","position","float"].forEach(b=>{w[b]&&(r[b]=w[b])}),t}inheritFromSourceParent(t){var i,n;let r=this.nodeContext.sourceNode,s=[],o=null,a=r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content"),h=this.isFootnote&&(!((i=this.nodeContext)!=null&&i.parent)||a),l=this.nodeContext.shadowContext;if(r instanceof Element&&r.namespaceURI==="http://www.pyroxy.com/ns/shadow"&&r.localName==="include"&&r.classList.contains("-vivliostyle-footnote-content")){let w=l?.owner;if(w instanceof Element&&ir(w)){let b=w.getAttribute("href")||w.getAttributeNS("http://www.w3.org/1999/xlink","href");if(b){let x=Ir(b,this.xmldoc.url),y=this.xmldoc.getElement(x);y&&dn(y)&&((n=y.parentNode)==null?void 0:n.nodeType)===1&&(r=y.parentNode,l=null)}}}let u=-1;for(;r&&r.nodeType==1;){let w=l&&l.root==r,b=!!w&&l.type==ht.ROOTED&&dn(r);if(!w||l.type==ht.ROOTLESS||b){let x=(l?l.styler:this.styler).getStyle(r,!1);s.push(x),o=o||vo(r)}w&&!b?(r=l.owner,l=l.parentShadow):(r=r.parentNode,u++)}let d=new Set;if(s.length>0){let w=s[0],b=Qo(w,this.context,this.regionIds,this.isFootnote,this.nodeContext);for(let x in b){if(!un(x))continue;let y=b[x].evaluate(this.context,x);y&&y!==v.inherit&&y!==v.unset&&y!==v.revert&&y!==Y&&d.add(x)}}let p=u===0,f=this.context.queryUnitSize("em",p),g={"font-size":new D(new F(f,"px"),0)};p&&(g["line-height"]=new D(new vt(this.context.pref.lineHeight),0));let m=new nw(g,this.context);for(let w=s.length-1;w>=0;--w){let b=s[w],x=[];for(let S in b)un(S)&&x.push(S);x.sort(Il);let y,P;for(let S of x){if(w>0&&h&&S.startsWith("--viv-marker-")||w>0&&d.has(S))continue;m.setPropName(S);let R=ke(b,S),A=R;if(R.value===v.initial)delete g[S];else if(!J(R.value)){if(S==="font-size"&&w===s.length-1&&this.context.isRelativeRootFontSize&&this.context.rootFontSize)A=new D(new F(this.context.rootFontSize,"px"),R.priority);else if(S==="line-height"&&w===s.length-1&&this.context.rootLineHeight&&R.value instanceof F&&(R.value.unit==="lh"||R.value.unit==="rlh"))A=new D(new F(this.context.rootLineHeight,"px"),R.priority);else if(w===0&&R.value instanceof F&&R.value.unit==="lh"){let U=this.getLineHeightUnitSize(S,y,P);U!=null&&(A=new D(new F(R.value.num*U,"px"),R.priority))}else jt(S)||(A=R.filterValue(m));S==="font-size"?y=A.value:S==="line-height"&&(P=A.value),g[S]=A}}}for(let w in t)un(w)||(g[w]=t[w]);return{lang:o,elementStyle:g}}resolveURL(t){return t=Ee(t,this.xmldoc.url),this.fallbackMap[t]||t}inheritLangAttribute(){this.nodeContext.lang=vo(this.nodeContext.sourceNode)||this.nodeContext.parent&&this.nodeContext.parent.lang||this.nodeContext.lang}transferPolyfilledInheritedProps(t){let i=Xm().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(J(s))s===v.initial&&(n[r]=void 0);else if(s instanceof Be)n[r]=s.num;else if(s instanceof de)n[r]=s.name;else if(s instanceof F){let o=s;switch(o.unit){case"dpi":case"dpcm":case"dppx":n[r]=o.num*_t[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=Ft("RESOLVE_FORMATTING_CONTEXT");for(let h=0;h<a.length;h++){let l=a[h](t,i,n,r,s,o);if(l){t.formattingContext=l;return}}}createElementView(t,i){var n,r;let s=!0,o=M("createElementView"),a=this.sourceNode,h=this.nodeContext.shadowContext?this.nodeContext.shadowContext.styler:this.styler,l=h.getStyle(a,!1);if(!this.nodeContext.shadowContext){let y=this.xmldoc.getElementOffset(a);$s.registerFragmentIndex(y,this.nodeContext.fragmentIndex,0)}let u={};if(!this.nodeContext.parent){let y=this.inheritFromSourceParent(l);l=y.elementStyle,this.nodeContext.lang=y.lang}let d=l.position,p=l.float,f=l["float-reference"],g=p&&!J(p.value)&&p.value!==v.none&&f&&!J(f.value)?km(f.value.toString()):null,m=!!this.nodeContext.shadowContext&&this.nodeContext.shadowContext.type===ht.ROOTED&&dn(a);if(this.nodeContext.parent&&(ys(d?.value)||g&&wi(g)||m)){let y=this.inheritFromSourceParent(l);l=y.elementStyle,this.nodeContext.lang=y.lang}this.nodeContext.vertical=this.computeStyle(this.nodeContext.vertical,this.nodeContext.direction==="rtl",l,u),g&&wi(g)&&u.display===v.block&&(u.display=v.flow_root),h.processContent(a,u,this.nodeContext),this.transferPolyfilledInheritedProps(u),this.inheritLangAttribute(),u.direction&&(this.nodeContext.direction=u.direction.toString());let w=u["flow-into"];if(w&&w.toString()!=this.flowName)return o.finish(!1),o.result();if(si&&a.localName==="script"&&a.namespaceURI==="http://www.w3.org/1999/xhtml")return cl(a,this.viewport.window).thenFinish(o),o.result();let b=u.display;if(J(b)&&(b===v.initial||b===v.unset?b=v.inline:b===v.inherit?b=((n=this.nodeContext.parent)==null?void 0:n.display)&&B((r=this.nodeContext.parent)==null?void 0:r.display):b=null),b===v.none)return o.finish(!1),o.result();let x=this.nodeContext.parent==null;return this.nodeContext.flexContainer=b===v.flex,this.createShadows(a,x,l,u,h,this.context,this.nodeContext.shadowContext).then(y=>{var P;this.nodeContext.nodeShadow=y;let S=u.position,R=u.float,A=u.clear,U=this.nodeContext.vertical?v.vertical_rl:v.horizontal_tb,G=this.nodeContext.parent?this.nodeContext.parent.vertical?v.vertical_rl:v.horizontal_tb:U,Z=Rm(a),fe=u["column-count"],ue=u["column-width"],C=fe&&fe!==v.auto&&!J(fe)||ue&&ue!==v.auto&&!J(ue);this.nodeContext.establishesBFC=Lm(b,S,R,u.overflow,U,G,C||Z),this.nodeContext.containingBlockForAbsolute=Om(S),this.nodeContext.isInsideBFC()&&R!==v.footnote&&!(g&&wi(g))&&(R=null,A=null);let _=null,k=!1,O=this.isFootnote&&(!((P=this.nodeContext)!=null&&P.parent)||this.nodeContext.pluginProps.nestedFootnoteDetached),E=R instanceof te||R===v.left||R===v.right||R===v.top||R===v.bottom||R===v.inline_start||R===v.inline_end||R===v.block_start||R===v.block_end||R===v.snap_block||R===v.snap_inline||R===v.inside||R===v.outside||R===v.footnote;if(R&&(delete u.float,R===v.footnote))if(_=u["footnote-display"],k=!!u["--viv-marker-content"],O){E=!1;let X=_?.toString();b=k?B("list-item"):X==="inline"?v.inline:v.block,u.display=b}else u.display=v.inline;A&&(A===v.inherit&&this.nodeContext.parent&&this.nodeContext.parent.clearSide&&(A=B(this.nodeContext.parent.clearSide)),(A===v.left||A===v.right||A===v.top||A===v.bottom||A===v.inline_start||A===v.inline_end||A===v.block_start||A===v.block_end||A===v.inside||A===v.outside||A===v.both||A===v.all||A===v.same||A===v.column||A===v.region||A===v.page)&&(delete u.clear,(E||u.display&&u.display!=v.inline)&&(this.nodeContext.clearSide=A.toString())));let T=Hn(b)&&!!(u["ua-list-item-count"]||u["--viv-marker-content"]),L=u["break-inside"];(E||L&&!J(L)&&L!==v.auto)&&this.nodeContext.breakPenalty++,b&&b!==v.inline&&Mt(b)&&this.nodeContext.breakPenalty++,this.nodeContext.inline=!E&&!b||Mt(b)||_c(b),this.nodeContext.display=b?b.toString():"inline",this.nodeContext.floatSide=E?R.toString():null,this.nodeContext.floatReference=g||Te.INLINE;let z=u["float-min-wrap-block"];this.nodeContext.floatMinWrapBlock=z&&!J(z)?z:null;let H=this.isInsideNonRootMultiColumn(),K=u["column-span"];if(this.nodeContext.columnSpan=!H&&K&&!J(K)?K:null,!this.nodeContext.inline){let X=u["break-after"];X&&!J(X)&&!(H&&X===v.column)&&(this.nodeContext.breakAfter=X.toString(),Lo[this.nodeContext.breakAfter]&&(u["break-after"]=v.column));let Et=u["break-before"];Et&&!J(Et)&&!(H&&Et===v.column)&&(this.nodeContext.breakBefore=Et.toString(),Lo[this.nodeContext.breakBefore]&&(this.isAtStartOfPage()?delete u["break-before"]:u["break-before"]=v.column),this.nodeContext.fragmentIndex!==1&&(this.nodeContext.breakBefore=null));let Bt=u.page,xt=Bt&&!J(Bt)&&Bt.toString();!xt&&!this.nodeContext.parent&&(this.nodeContext.shadowContext||b===v.table_header_group||b===v.table_footer_group)&&(xt=this.styler.cascade.currentPageType),!xt||xt.toLowerCase()==="auto"?xt=this.nodeContext.pageType:this.nodeContext.pageType=xt,this.styler.cascade.currentPageType!==xt&&!(!xt&&u.position===v.fixed)&&(this.nodeContext.fragmentIndex===1&&!xn(this.nodeContext.breakBefore)&&(this.nodeContext.breakBefore="page"),xt!==this.styler.cascade.previousPageType&&(this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.styler.cascade.currentPageType=xt)}this.nodeContext.captionSide=u["caption-side"]&&u["caption-side"].toString()||"top";let ee=u["border-collapse"];if(!ee||ee===B("separate")){let X=u["border-spacing"],Et,Bt;X&&(X instanceof te?(Et=X.values[0],Bt=X.values[1]):Et=Bt=X,Et.isNumeric()&&(this.nodeContext.inlineBorderSpacing=nt(Et,this.context)),Bt.isNumeric()&&(this.nodeContext.blockBorderSpacing=nt(Bt,this.context)))}let Q=u["footnote-policy"];this.nodeContext.footnotePolicy=Q&&!J(Q)?Q:null;let ge=u["x-first-pseudo"];if(ge){let X=this.nodeContext.parent?this.nodeContext.parent.firstPseudo:null;this.nodeContext.firstPseudo=new vm(X,ge.num)}this.nodeContext.inline||this.processAfterIfcontinues(a,l,h,this.context);let re=u["white-space"];if(re){let X=Cc(re.toString());X!==null&&(this.nodeContext.whitespace=X)}let se=u["hyphenate-character"];se&&se instanceof j&&(this.nodeContext.hyphenateCharacter=se.str);let _e=u["word-break"],De=u["line-break"],pe=u["overflow-wrap"];(_e===v.break_all||De===v.anywhere||pe===v.break_word||pe===v.anywhere)&&(this.nodeContext.breakWord=!0),this.resolveFormattingContext(this.nodeContext,t,b,S,R,x),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,h));let le=!1,me=null,we=[],oe=a.namespaceURI,q=a.localName,Ze=q;oe=="http://www.w3.org/1999/xhtml"?(q=="html"||q=="body"||q=="script"||q=="link"||q=="meta"?q="div":q=="vide_"?q="video":q=="audi_"?q="audio":q=="object"&&(le=!!this.customRenderer),a.hasAttribute(Qa)&&a.hasAttribute("src")&&u.content instanceof ot&&(q="img")):oe=="http://www.idpf.org/2007/ops"?(q="span",oe="http://www.w3.org/1999/xhtml"):oe=="http://www.pyroxy.com/ns/shadow"?(oe="http://www.w3.org/1999/xhtml",q=this.nodeContext.inline?"span":"div"):le=!!this.customRenderer,T?t?(q="li",u["--viv-marker-content"]&&(u["list-style-type"]=v.none,u["list-style-image"]=v.none)):(b=Mt(b)?v.inline:v.block,u.display=b,q="div"):q=="body"||q=="li"?q="div":q=="q"&&(q="span"),u.behavior&&u.behavior.toString()!="none"&&this.customRenderer&&(le=!0),a.dataset&&a.getAttribute("data-math-typeset")==="true"&&(le=!0);let at;if(le){let X=this.nodeContext.parent?this.nodeContext.parent.viewNode:null;at=this.customRenderer(a,X,u)}else at=N(null);at.then(X=>{var Et,Bt,xt;if(X)le&&(s=X.getAttribute("data-adapt-process-children")=="true");else if(u.display===v.none){o.finish(!1);return}else X=this.createElement(oe,q);if(!x&&C&&u["column-fill"]===v.auto){let Ke=this.nodeContext.vertical?u.width:u.height;(!Ke||Ke===v.auto||J(Ke))&&(X.setAttribute("data-viv-saved-column-fill","auto"),u["column-fill"]=v.balance)}q!=Ze&&(X.setAttribute("data-vivliostyle-original-tag",Ze),(Ze==="html"||Ze==="body")&&(X.role="presentation")),q=="a"&&X.addEventListener("click",this.page.hrefHandler,!1),me&&(this.applyPseudoelementStyle(this.nodeContext,"inner",me),X.appendChild(me)),X.localName=="iframe"&&X.namespaceURI=="http://www.w3.org/1999/xhtml"&&_v(X);let kr=this.nodeContext.inheritedProps["image-resolution"],qs=[],Ys=u.width,Zs=u.height,Lp=a.getAttribute("width"),Op=a.getAttribute("height"),Ks=Ys===v.auto||!Ys&&!Lp,Js=Zs===v.auto||!Zs&&!Op,fl=a.attributes,Bp=fl.length,Er=null,gl=null;b===v.table_cell&&((xt=(Bt=(Et=this.nodeContext.parent)==null?void 0:Et.viewNode)==null?void 0:Bt.lastElementChild)==null?void 0:xt.localName)==="a"&&X.appendChild(this.nodeContext.parent.viewNode.lastElementChild);for(let Ke=0;Ke<Bp;Ke++){let pt=fl[Ke],ft=pt.namespaceURI,he=pt.localName,He=pt.nodeValue;if(ft){if(ft=="http://www.w3.org/2000/xmlns/")continue;ft=="http://www.w3.org/1999/xlink"&&he=="href"&&(He=this.documentURLTransformer.transformURL(this.resolveURL(He),this.xmldoc.url))}else{if(!si&&he.match(/^on/)||he=="style")continue;if((he=="id"||he=="name")&&t){let Je=this.documentURLTransformer.transformFragment(He,this.xmldoc.url);X.setAttribute(he,He),X.setAttribute("data-vivliostyle-id",Je);let Si=X.ownerDocument.createElement("a");Si.setAttribute(he,Je),Si.setAttribute(Cn,"1"),Si.style.position="absolute",X.appendChild(Si),this.page.registerElementWithId(X,Je);continue}if(he=="src"||he=="href"||he=="poster")He=this.resolveURL(He),he==="href"&&(He=this.documentURLTransformer.transformURL(He,this.xmldoc.url));else if(he=="srcset")He=He.split(",").map(Je=>this.resolveURL(Je.trim())).join(",");else if(he==="data"&&le&&q==="object"&&X.hasAttribute("data"))continue;if(he==="poster"&&q==="video"&&oe==="http://www.w3.org/1999/xhtml"&&Ks&&Js){let Je=new Image,Si=Ut(Je,He);we.push(Si),qs.push({image:Je,element:X,fetcher:Si})}}if(oe=="http://www.w3.org/2000/svg"&&/^[A-Z\-]+$/.test(he)&&(he=he.toLowerCase()),this.isSVGUrlAttribute(he)&&(He=Bv(He,this.xmldoc.url,this.documentURLTransformer)),ft){let Je=Mv[ft];Je&&(he=`${Je}:${he}`)}if(he=="src"&&!ft&&(q=="img"||q=="input")&&oe=="http://www.w3.org/1999/xhtml")Er=He;else if(he=="alt"&&!ft&&q=="img"&&oe=="http://www.w3.org/1999/xhtml")gl=He;else if(he=="href"&&q=="image"&&oe=="http://www.w3.org/2000/svg"&&ft=="http://www.w3.org/1999/xlink")this.page.fetchers.push(Ut(X,He));else if(ft)X.setAttributeNS(ft,he,He);else try{X.setAttribute(he,He)}catch(Je){W.warn(Je)}}if(Er){let Ke=q==="input"?new Image:X,pt=Ut(Ke,Er,gl);Ke!==X&&(X.src=Er);let ft=()=>{var he,He;if(u.position===v.fixed)return!0;for(let Je=(he=this.nodeContext.parent)==null?void 0:he.viewNode;Je&&Je!==this.viewRoot;Je=Je.parentElement)if(((He=Je.style)==null?void 0:He.position)==="fixed")return!0;return!1};!Ks&&!Js&&!(()=>{let he=this.nodeContext.vertical?Ys:Zs;return he instanceof F&&he.unit==="%"})()&&!ft()?this.page.fetchers.push(pt):(Ks&&Js&&kr&&kr!==1&&qs.push({image:Ke,element:X,fetcher:pt}),we.push(pt))}delete u.content;let Pr=u["--viv-marker-content"];if(Pr){let Ke=Pr instanceof te?Pr.values:[Pr];for(let pt of Ke)pt instanceof ot&&pt.url&&we.push(Ut(new Image,pt.url))}if(this.preprocessElementStyle(u),this.applyComputedStyles(X,u),this.nodeContext.inline)t||(gt(X,"inline-start"),on(X)&>(X,"clone"));else if(t){if(!zs(u.position)){let Ke=u["margin-break"],pt=this.getBreakTypeAt(this.nodeContext),ft=pt!==null,he=pt==="auto";(Ke===v.discard&&ft||Ke!==v.keep&&he&&!this.nodeContext.floatSide)&&so(X,"block-start")}}else{let Ke=this.nodeContext.vertical?"width":"height";ci(X,Ke)&&I(X,Ke,this.nodeContext.display==="table-row"?"0.01px":""),gt(X,"block-start"),on(X)&>(X,"clone"),so(X,"block-start")}T&&u["ua-list-item-count"]&&X.setAttribute("value",u["ua-list-item-count"].stringValue()),this.viewNode=X,we.length?vn(we).then(()=>{kr>0&&this.modifyElemDimensionWithImageResolution(qs,kr,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&&(Me(r,n.parent.whitespace)||hi(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&&Hs(i))}getBreakTypeAt(t){var i,n,r,s,o;if(this.isInsideTable(t))return null;for(let h=t;h&&!h.after;h=h.parent){if(Ge(h.breakBefore))return h.breakBefore;if(h.fragmentIndex===1&&!h.parent)return h.sourceNode===h.sourceNode.ownerDocument.documentElement?"page":null;if((i=h.parent)!=null&&i.floatSide)return null;let l=(n=h.parent)==null?void 0:n.viewNode;if(l){let u=this.viewport.window.getComputedStyle(l),d=parseFloat(u.paddingBlockStart),p=parseFloat(u.borderBlockStartWidth);if(d||p)return null;let f=l?.firstChild;for(;f&&(Me(f,h.parent.whitespace)||!h.floatSide&&hi(f));)f=f.nextSibling;if(f&&f!==h.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 Ge(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 uo(t,i,n,r,this.exprContentListener);this.nodeContext.afterIfContinues=new Kw(t,o)}}isSVGUrlAttribute(t){return Xn.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,h=o.height/i,l=s.element;if(a>0&&h>0){if(n["box-sizing"]===v.border_box&&(n["border-left-style"]!==v.none&&(a+=nt(n["border-left-width"],this.context)),n["border-right-style"]!==v.none&&(a+=nt(n["border-right-width"],this.context)),n["border-top-style"]!==v.none&&(h+=nt(n["border-top-width"],this.context)),n["border-bottom-style"]!==v.none&&(h+=nt(n["border-bottom-width"],this.context))),i>1){let u=n["max-width"]||v.none,d=n["max-height"]||v.none;if(u===v.none&&d===v.none)I(l,"max-width",`${a}px`);else if(u!==v.none&&d===v.none)I(l,"width",`${a}px`);else if(u===v.none&&d!==v.none)I(l,"height",`${h}px`);else{u.isNumeric(),d.isNumeric();let p=u,f=d;p.unit!=="%"?I(l,"max-width",`${Math.min(a,nt(p,this.context))}px`):f.unit!=="%"?I(l,"max-height",`${Math.min(h,nt(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}else if(i<1){let u=n["min-width"]||Ne,d=n["min-height"]||Ne;u.isNumeric(),u.isNumeric();let p=u,f=d;p.num===0&&f.num===0?I(l,"min-width",`${a}px`):p.num!==0&&f.num===0?I(l,"width",`${a}px`):p.num===0&&f.num!==0?I(l,"height",`${h}px`):p.unit!=="%"?I(l,"min-width",`${Math.max(a,nt(p,this.context))}px`):f.unit!=="%"?I(l,"min-height",`${Math.max(h,nt(f,this.context))}px`):r?I(l,"height",`${h}px`):I(l,"width",`${a}px`)}}}})}preprocessElementStyle(t){Ft("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 zi&&!this.nodeContext.belongsTo(this.nodeContext.formattingContext))return;let o=this.nodeContext.parent,a=o&&o.formattingContext;this.nodeContext.formattingContext=new zi(a,this.nodeContext.sourceNode),this.nodeContext.formattingContext.initializeRepetitiveElements(this.nodeContext.vertical);return}}processRepeatOnBreak(t){let i=t["repeat-on-break"];return i!==v.none&&((i===v.auto||J(i))&&(t.display===v.table_header_group?i=v.header:t.display===v.table_footer_group?i=v.footer:i=v.none),i&&i!==v.none)?i.toString():null}createTextNodeView(){let t=M("createTextNodeView");return this.preprocessTextContent().then(()=>{let i=this.offsetInNode||0,n=Zl(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=M("preprocessTextContent"),r=Ft("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=lm(t,i),n.finish(!0)}),n.result()}createNodeView(t,i){let n=M("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 h=(d,p)=>d?.nodeType===1&&Kt(d)===p,l=this.nodeContext.parent,u=l?h(this.viewNode,"after")&&h(l.viewNode,"first-letter")&&(a=l.viewNode)!=null&&a.hasChildNodes()?l.parent.viewNode:l.viewNode:this.viewRoot;this.nodeContext.pluginProps.nestedFootnoteDetached&&(u=this.viewRoot),u&&(this.nodeContext.inline&&!(this.viewNode.nodeType===3&&Me(this.viewNode))&&!u.hasChildNodes()&&bc(u).includes("block-start")&>(u,"text-start"),u.appendChild(this.viewNode),_m(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.subShadow.root,o=n.subShadow.type,o==ht.ROOTLESS&&(s=s.firstChild)):(s=n.owner.firstChild,o=ht.ROOTLESS);let h=t.sourceNode.nextSibling;if(h?(t.sourceNode=h,t.resetView()):t.shadowSibling?t=t.shadowSibling:s?t=null:(t=t.parent.modify(),t.after=!0),s){let l=new Qi(s,r,i);return l.shadowContext=a,l.shadowType=o,l.shadowSibling=t,this.processShadowContent(l)}return t.boxOffset=i,t}nextPositionInTree(t){let i=t.boxOffset+1;if(t.after){if(!t.parent)return null;if(t.shadowType!=ht.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==ht.ROOTLESS&&(r=r.firstChild),r){let s=new Qi(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 Qi(n,t,i));if(t.sourceNode.nodeType!=1){let r=Zl(t.preprocessedTextContent);i+=r.length-1-t.offsetInNode}return t=t.modify(),t.boxOffset=i,t.after=!0,t}}findImmediateFootnoteCallSibling(t){let i=this.xmldoc.getElementOffset(t.sourceNode),n=t.viewNode;if(!n)return null;let r=n.previousSibling;for(;r;){if(r.nodeType===Node.TEXT_NODE){if(r.textContent.trim().length===0){r=r.previousSibling;continue}return null}if(r.nodeType===Node.ELEMENT_NODE){let s=r;return Kt(s)==="footnote-call"&&s.getAttribute(Xn.FOOTNOTE_CALL_OWNER_ATTR)===i.toString()?s:null}return null}return null}isSemanticFootnoteElement(t){let i=t.sourceNode;return i instanceof Element&&dn(i)}insertFootnoteCall(t){var i,n;let r=M("insertFootnoteCall"),s=$n.createElementNS("http://www.w3.org/1999/xhtml","span");Xr(s,"footnote-call");let o=this.xmldoc.getElementOffset(t.sourceNode);s.setAttribute(Xn.FOOTNOTE_CALL_OWNER_ATTR,o.toString());let a=new Qi(s,t.parent,t.boxOffset);a.inline=!0;let h=new uo(t.sourceNode,this.styler.getStyle(t.sourceNode,!1),this.styler,this.context,this.exprContentListener);return a.shadowContext=new $r(t.sourceNode,s,null,((i=t.parent)==null?void 0:i.shadowContext)||null,null,ht.ROOTLESS,h),a.shadowSibling=t,t.boxOffset++,(n=t.viewNode)!=null&&n.parentNode&&t.viewNode.parentNode.removeChild(t.viewNode),this.setCurrent(a,!0,!1).then(l=>{if(l&&s.hasChildNodes())r.finish(a);else{let u=a.modify();u.after=!0,a.viewNode||(u.inline=!0),r.finish(u)}}),r.result()}nextInTree(t,i){let n=this.nextPositionInTree(t);if(!n||n.after)return N(n);let r=M("nextInTree");return this.setCurrent(n,!0,i).then(s=>{if((!n.viewNode||!s)&&(n=n.modify(),n.after=!0,n.viewNode||(n.inline=!0)),n.floatSide==="footnote"&&!(this.isFootnote&&!n.parent)&&!n.after&&!n.pluginProps.footnoteCallProcessed&&!n.shadowContext&&!this.isSemanticFootnoteElement(n)){let o=this.findImmediateFootnoteCallSibling(n);o!=null&&o.parentNode&&o.parentNode.removeChild(o),this.isFootnote&&n.parent&&(n.pluginProps.nestedFootnoteDetached=1),n.pluginProps.footnoteCallProcessed=1,this.insertFootnoteCall(n).then(a=>{this.dispatchEvent({type:"nextInTree",nodeContext:a}),r.finish(a)});return}this.dispatchEvent({type:"nextInTree",nodeContext:n}),r.finish(n)}),r.result()}addImageFetchers(t){if(t instanceof tt){let i=t.values;for(let n=0;n<i.length;n++)this.addImageFetchers(i[n])}else if(t instanceof ot){let i=t.url;this.page.fetchers.push(Ut(new Image,i))}}applyComputedStyles(t,i){var n,r,s;let o=i["background-image"];o&&this.addImageFetchers(o);let a=i.position===v.relative,h=((n=this.nodeContext)==null?void 0:n.parent)===null&&((r=this.sourceNode)==null?void 0:r.parentElement)===null&&!!((s=this.viewRoot)!=null&&s.parentElement),l=Object.keys(i);l.sort(Il);let u,d;for(let p of l){if(zv[p])continue;let f=i[p];if(!(!f||f===Y&&!jt(p))){if(f=f.visit(new ng(this.xmldoc.url,this.documentURLTransformer)),f instanceof F)if(f.unit==="em"){let g=this.getEmUnitSize(p,u);g!=null&&(f=new F(f.num*g,"px"))}else if(f.unit==="lh"){let g=this.getLineHeightUnitSize(p,u,d);g!=null&&(f=new F(f.num*g,"px"))}else mu(f.unit)&&(f=Ou(f,this.context));if((p==="font-size"||p==="line-height")&&(p==="font-size"?u=f:d=f,this.viewport.layoutUnitAdj&&f instanceof F&&f.unit!=="%"&&f.unit!=="em"&&f.unit!=="lh"&&(f=new Xi(`calc(${f.toString()} - var(--viv-layoutUnitAdj))`))),cm[p]||a&&dm[p]){this.page.delayedItems.push(new Va(t,p,f));continue}h&&this.page.pageAreaElement&&un(p)?(I(this.page.pageAreaElement.parentElement.parentElement,p,f.toString()),p!=="writing-mode"&&p!=="direction"&&I(this.viewport.layoutBox,p,f.toString())):I(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,h,l;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 vt||n instanceof F&&(n.unit==="em"||n.unit==="%"))p=n instanceof F&&n.unit==="%"?n.num/100:n.num;else{if(n instanceof F&&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=(h=(a=this.nodeContext)==null?void 0:a.parent)==null?void 0:h.viewNode;f&&f.nodeType===1;f=f.parentNode){let g=(l=f?.style)==null?void 0:l.lineHeight;if(g){/^[0-9.]+$/.test(g)&&(p=parseFloat(g));break}}if(p!=null){if(i&&!(i instanceof F))return null;let f=u?this.parsePlusLayoutUnitAdj(u.fontSize):this.context.rootFontSize;if(i instanceof F){let g=Xo(i,f,this.context).num;return typeof g!="number"||isNaN(g)?null:p*g}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 F){let h=Xo(i,a,this.context).num;if(typeof h=="number"&&!isNaN(h))return h}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=bt(s,"_pseudos");if(!o||(s=o[i],!s))return;let a={};t.vertical=this.computeStyle(t.vertical,t.direction==="rtl",s,a);let h=a.content;Rt(h)&&(h.visit(new sr(n,this.context,h,this.exprContentListener)),delete a.content),this.applyComputedStyles(n,a)}peelOff(t,i){let n=M("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,h=[];for(;t.firstPseudo===r;)h.push(t),t=t.parent;let l=h.pop(),u=l.shadowSibling;return n.loop(()=>{for(;h.length>0;){l=h.pop(),t=new Qi(l.sourceNode,t,a),h.length==0&&(t.offsetInNode=s,t.after=o),t.shadowType=l.shadowType,t.shadowContext=l.shadowContext,t.nodeShadow=l.nodeShadow,t.shadowSibling=l.shadowSibling?l.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){var r;let s={},o=[],a=this.footnoteStyle;if(this.cascadedPageStyle){let l=bt(this.cascadedPageStyle,Rs);l&&l.area&&(a=l.area)}let h=bt(a,"_pseudos");if(t=this.computeStyle(t,i,a,s),h&&h.before){let l=h.before,u=!!ke(l,"display"),d={},p=this.createElement("http://www.w3.org/1999/xhtml","span");Xr(p,"before"),n.appendChild(p),this.computeStyle(t,i,l,d),u||(d.display=v.block);let f=ke(l,"content");if(f){let m=((r=this.sourceNode)==null?void 0:r.nodeType)===1?this.sourceNode:this.xmldoc.root;d.content=f.filterValue(new Ss(this.styler.cascade,m,this.styler.cascade.counterResolver,"before")).evaluate(this.context,"content")}let g=d.content;if(Rt(g)){g.visit(new sr(p,this.context,g,this.exprContentListener));let m=p.querySelectorAll("img[src]");for(let b=0;b<m.length;b++){let x=m[b],y=x.getAttribute("src");if(!y)continue;let P=Ut(x,y);o.push(P),this.page.fetchers.push(P)}let w=p.getAttribute("src");if(w){let b=p.querySelector("img");b||(b=this.document.createElement("img"),b.setAttribute("src",w),p.appendChild(b));let x=Ut(b,w);o.push(x),this.page.fetchers.push(x)}}delete d.content,this.applyComputedStyles(p,d)}return delete s.content,this.applyComputedStyles(n,s),o.length?vn(o).thenReturn(t):N(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 h=t.sourceNode.nextSibling,l=(n=ke(this.styler.getStyle(h,!1),"display"))==null?void 0:n.value.toString();o=l&&!Mt(l)||h.getAttribute("data-math-typeset")==="true"&&/^\s*(\$\$|\\\[)/.test(h.textContent)}let a=0;for(let h=s;h;h=h.parent){if(((r=h.viewNode)==null?void 0:r.nodeType)!==1)continue;let l=h.viewNode;if(l.style)if(h.inline){if(gt(l,"inline-end"),on(l)){let u=h.vertical?l.offsetWidth:l.offsetHeight;gt(l,"clone"),(h.vertical?l.offsetWidth:l.offsetHeight)>u&&this.fixClonedBoxDecorationOverflow(l)}}else{let u=this.nodeContext.vertical?"width":"height";if(ci(l,u)&&I(l,u,""),gt(l,"block-end"),!a++&&h!==s){let{textAlign:d}=this.viewport.window.getComputedStyle(l);if(d==="justify"&&!o){let p=this.createChildAnonymousBlockIfNeeded(l);p?p!==l?vc(p,["block-start","text-start","block-end","text-end","justify"]):(gt(l,"text-end"),gt(l,"justify")):gt(l,"text-end")}else gt(l,"text-end")}on(l)&>(l,"clone"),so(l,"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:h}=this.viewport.window.getComputedStyle(s);if(s.localName==="ruby"||Oi[s.localName])return!1;if(s.localName==="br")return!0;if((o==="inline"||o==="contents")&&s.hasChildNodes()){let l=s.lastElementChild;if(l&&(!l.nextSibling||l.nextSibling===s.lastChild&&Me(l.nextSibling))){let u=i(l);if(u||u===null)return u}for(let u=l?.previousElementSibling;u;u=u.previousElementSibling){let d=i(u);if(d||d===null)return null}return!1}if(o==="none"||a==="absolute"||a==="fixed"||h&&h!=="none"||s.hasAttribute(Cn)){let l=s.previousElementSibling;return l&&(l.nextSibling===s||l.nextSibling===s.previousSibling&&Me(l.nextSibling))?i(l):!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&&Me(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(xf(s)){let o=i;for(;o&&o.nodeType!==1;)o=o.parentNode;let a=parseFloat(n.getElementComputedStyle(o)["font-size"]);return this.context,qa(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&&Kt(n)===Kt(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!!Kt(t)}};c(ba,"SVG_URL_ATTRIBUTES",["color-profile","clip-path","cursor","filter","marker","marker-start","marker-end","marker-mid","fill","stroke","mask"]),c(ba,"FOOTNOTE_CALL_OWNER_ATTR","data-viv-footnote-call-owner");var Dv=ba,zv={"float-min-wrap-block":!0,"float-reference":!0,"flow-into":!0,"flow-linger":!0,"flow-options":!0,"flow-priority":!0,"footnote-display":!0,"footnote-policy":!0,"margin-break":!0,page:!0},Vv=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}},Ls=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")&&(I(this.root,"--viv-outputPixelRatio",`${i}`),I(this.root,"--viv-devicePixelRatio",`${e.devicePixelRatio}`),this.scaleRatio=i/e.devicePixelRatio),Pa){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&&I(this.root,"--viv-layoutUnitAdj",`${this.layoutUnitAdj}px`);let h=o.nextElementSibling;h||(h=this.document.createElement("div"),h.setAttribute("data-vivliostyle-layout-box","true"),h.role="presentation",this.root.appendChild(h)),this.outerZoomBox=o,this.contentContainer=a,this.layoutBox=h,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 l={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=l.width),(!this.height||!s&&u)&&(this.height=l.height)}resetZoom(){I(this.outerZoomBox,"width",""),I(this.outerZoomBox,"height",""),I(this.contentContainer,"width",""),I(this.contentContainer,"height",""),I(this.contentContainer,"transform","")}zoom(e,t,i){I(this.root,"--viv-outputScale",`${i}`),I(this.outerZoomBox,"width",`${e*i}px`),I(this.outerZoomBox,"height",`${t*i}px`),I(this.contentContainer,"width",`${e}px`),I(this.contentContainer,"height",`${t}px`)}clear(){let e=this.root;for(;e.lastChild;)e.removeChild(e.lastChild)}},Sp=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($t,"0")}doc(){return new kp([this.document])}getElementOffset(e){let t=e.getAttribute($t);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($t,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 h=ni(a.length,l=>{let u=a[l];return this.getElementOffset(u)>e});if(h==0)break;i=a[h-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}},va=(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))(va||{});function _r(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 Uv(e){let t=e.contentType;if(t){let n=Object.keys(va);for(let r=0;r<n.length;r++)if(va[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 Cp(e,t){let i=e.responseXML;if(!i){let r=new DOMParser,s=e.responseText;if(s){let o=Uv(e);if(i=_r(s,o||"application/xml",r),i&&!o){let a=i.documentElement;a.localName.toLowerCase()==="html"&&!a.namespaceURI?i=_r(s,"text/html",r):a.localName.toLowerCase()==="svg"&&i.contentType!=="image/svg+xml"&&(i=_r(s,"image/svg+xml",r))}i||(i=_r(s,"text/html",r))}}let n=i?new Sp(t,e.url,i):null;return N(n)}function Hv(){return new Ma(Cp,"document")}var $v=class xa{constructor(t){this.fn=t}check(t){return this.fn(t)}withAttribute(t,i){return new xa(n=>this.check(n)&&n.nodeType==1&&n.getAttribute(t)==i)}withChild(t,i){return new xa(n=>{if(!this.check(n))return!1;let r=new kp([n]);return r=r.child(t),i&&(r=r.predicate(i)),r.size()>0})}},zh=new $v(e=>!0),kp=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)}},Wv=new yr(()=>{let e=M("uaStylesheetBase"),t=rp(),i=Ee("user-agent-base.css",fi),n=new ar(null,null,null,null,null,t,!0);return n.startStylesheet("UA"),Ow(n.cascade),Da(rc,n,i,null,null).thenFinish(e),e.result()},"uaStylesheetBaseFetcher");function Gv(){return Wv.get()}var jv=class extends jr{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)||W.warn(`E_CSS_COUNTER_STYLE_INVALID: @counter-style ${this.counterStyleName}`)}},Xv=class{constructor(e,t,i,n,r,s,o,a,h,l,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=h,this.pageProps=l,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,g=f.firstFlowChunkOfFlow(d);return p.matchPageSide(f.startSideOfFlow(d))&&f.hasContent(d,p.lookupOffset)&&!!g&&!p.flowChunkIsAfterParentFlowForcedBreak(g)}),this.pageScope.defineName("page-number",new Ie(this.pageScope,function(){let d=this;return d.pageNumberOffset+d.currentLayoutPosition.page},"page-number")),this.pageScope.defineName("blank-page",new Ie(this.pageScope,function(){let d=this.currentLayoutPosition;return d?.isBlankPage},"blank-page"))}sizeViewport(e,t,i,n){if(this.viewportProps.length){let r=new Co(this.rootScope,e,t,i),s=iw(r,this.viewportProps),o=s.width,a=s.height,h=s["text-zoom"],l=1;if(o&&a||h){let u=_t.em;if((h?h.evaluate(r,"text-zoom"):null)===v.scale&&(l=u/i,i=u,e*=l,t*=l),o&&a){let d=nt(o.evaluate(r,"width"),r),p=nt(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}}};function Vh(e){let t=new Map,i=n=>{n.formattingContext&&!t.has(n.formattingContext)&&t.set(n.formattingContext,n.formattingContext.saveState()),n.shadowSibling&&i(n.shadowSibling)};for(let n in e.flowPositions){let r=e.flowPositions[n];for(let s of r.positions){let o=s.chunkPosition.primary;for(let a of o.steps)i(a);if(s.chunkPosition.floats)for(let a of s.chunkPosition.floats)for(let h of a.steps)i(h)}}return t}function Uh(e){for(let[t,i]of e)i!==void 0&&t.restoreState(i)}var dl=class extends Co{constructor(e,t,i,n,r,s,o,a,h,l,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=h,this.documentURLTransformer=l,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,"currentCascadedPageStyle",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),c(this,"semanticFootnoteFirstRefOffsets",new Map),c(this,"semanticFootnoteFirstRefOffsetsInitialized",{value:!1}),c(this,"pageGroupPageCounts",Object.create(null)),c(this,"currentPageGroupDocument",null),this.lang=t.lang||i,this.faces=new jb(this.style.fontDeobfuscator),this.rootPageFloatLayoutContext=new en(null,null,null,null,null,null,null),this.pageProgression=p||null,this.isVersoFirstPage=!!f;for(let g in e.flowProps){let m=e.flowProps[g],w=ke(m,"flow-consume");w&&(w.evaluate(this,"flow-consume")==v.all?this.primaryFlows[g]=!0:delete this.primaryFlows[g])}}init(){let e=M("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 Eh(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=fp(n)),this.matchStartPageSide(this.styler.breakBeforeValues[0])||(this.pageNumberOffset===0?this.isVersoFirstPage=!0:this.blankPageAtStart=!0);let r=this.style.rootBox;this.rootPageBoxInstance=new Jb(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 gv(s,this.style.pageScope,this.rootPageBoxInstance,this,n);let o=[];for(let h of this.style.fontFaces){if(h.condition&&!h.condition.evaluate(this))continue;let l=Gb(h.properties,this),u=new sp(l);o.push(u)}this.fontMapper.findOrLoadFonts(o,this.faces).then(()=>{Fv(this.xmldoc.document,this.viewport.window,this.styler).thenFinish(e)});let a=this.style.pageProps;return a[""]||(a[""]={}),Object.keys(a).forEach(h=>{let l=a[h];this.styler.cascade.applyVarFilter([l],this.styler,null),this.styler.cascade.applyCalcFilter(l,this.styler.context),this.styler.cascade.applyCmykFilter(l);let u=Mh(As(l),this);this.pageSheetSize[h]={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 Co(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 Eh(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 Sm,i.flowPositions[e.flowName]=n);let r=bm(e.element),s=new xi(r),o=new xm(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(h,l){n=!1}invalidPropertyValue(h,l){n=!1}simpleProperty(h,l,u){}}let s=new r,o=vr(this.style.rootScope,new Xt(t,null),"");return o?(this.xmldoc.store.validatorSet.validatePropertyAndHandleShorthand(e,o,!1,s),n):!1}evalSupportsSelector(e){let t=new Ep(null),i=new Xt(e+"{}",t);return new br(Le,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 h=this.xmldoc.getNodeOffset(r,s,o);h<t&&(t=h)}return t}getNodePositionOffset(e){let t=e.steps[0].node,i=e.offsetInNode,n=e.after,r=0;for(;t.ownerDocument!=this.xmldoc.document;)r++,t=e.steps[r].node,n=!1,i=0;return this.xmldoc.getNodeOffset(t,i,n)}getPageStartOffset(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)for(let s=0;s<r.positions.length;s++){let o=r.positions[s].chunkPosition.primary,a=this.getNodePositionOffset(o);a<i&&(i=a)}}return i}getPageStartCounterOffsets(e){let t=this.getPageStartOffset(e);if(!isFinite(t))return{counterOffset:t,changeOffset:t};let i=this.xmldoc.body||this.xmldoc.root,n=i?this.getFirstInFlowElementAtOrAfter(i,t):null,r=i?this.xmldoc.getElementOffset(i):t,s=t<=r,o=n===i&&s?this.getFirstInFlowChildElement(i):n;if(!o)return{counterOffset:t,changeOffset:t};let a=this.xmldoc.getElementOffset(o),h=t;return s&&a!==t&&(h=a),a===t&&(this.isInlineLevelElement(o)?h=Math.max(0,t-1):h=this.getDeepestFirstInFlowChildOffset(o)),{counterOffset:h,changeOffset:a}}getPageStartElement(e,t=this.getPageStartOffset(e)){if(!isFinite(t))return null;let i=this.xmldoc.body||this.xmldoc.root;if(!i)return null;let n=this.getFirstInFlowElementAtOrAfter(i,t),r=this.xmldoc.getElementOffset(i),s=t<=r;return n===i&&s?this.getFirstInFlowChildElement(i):n}isForcedPageBreakValue(e){return Ge(e)&&e!=="column"&&e!=="region"}hasForcedPageBreakBefore(e){let t=ke(e,"break-before");if(!t)return!1;let i=t.evaluate(this,"break-before").toString();return this.isForcedPageBreakValue(i)}getExplicitPageType(e){let t=ke(e,"page");if(!t)return null;let i=t.evaluate(this,"page").toString();return!i||i.toLowerCase()==="auto"?null:i}getPageGroupPageType(e){let t=this.styler.getStyle(e,!1);return t?this.getExplicitPageType(t):null}getPreviousInFlowSibling(e){let t=e.previousElementSibling;for(;t;){if(this.isNormalFlowElement(t))return t;t=t.previousElementSibling}return null}getFirstDocumentFlowElement(){let e=this.xmldoc.body||this.xmldoc.root;if(!e)return null;let t=this.xmldoc.getElementOffset(e),i=this.getFirstInFlowElementAtOrAfter(e,t);return i===e?this.getFirstInFlowChildElement(e):i}resolveFirstPageType(){let e=this.getFirstDocumentFlowElement();return e?this.getPageGroupPageType(e):null}shouldStartPageGroup(e,t,i){let n=this.styler.getStyle(e,!1);if(!n)return!1;if(this.getFirstDocumentFlowElement()===e)return!0;let r=this.xmldoc.getElementOffset(e),s=this.xmldoc.body||this.xmldoc.root,o=this.xmldoc.getElementOffset(s);if(i<=o&&e===s||!this.getPreviousInFlowSibling(e)&&i===r)return!0;if(r!==i)return!1;if(this.hasForcedPageBreakBefore(n))return!0;let a=this.getPreviousInFlowSibling(e);if(!a)return!1;let h=this.styler.getStyle(a,!1);return h?this.getExplicitPageType(h)!==t:!1}updatePageGroupPageIndices(e){let t=this.pageManager.pageCascadeInstance;t.pageTypePageIndices=Object.create(null);let i=e.startSideOfFlow("body"),n=e.flowPositions.body,r=!!(n&&n.positions.length),s=xn(i)&&!this.matchPageSide(i)&&!r,o=!(this.blankPageAtStart&&e.page===1)&&!e.isBlankPage&&!s,a=this.getPageStartOffset(e),h=this.getPageStartElement(e,a);if(!h)return;let l=h.ownerDocument,u=this.currentPageGroupDocument!==l&&o;u&&(this.pageGroupPageCounts=Object.create(null),this.currentPageGroupDocument=l);let d=h;for(;d;){let p=this.getPageGroupPageType(d);if(p){let f=this.pageGroupPageCounts[p]||(this.pageGroupPageCounts[p]=new Map),g=f.get(d)||0;(g>0||o&&(u||this.shouldStartPageGroup(d,p,a)))&&(g+=1,f.set(d,g),(t.pageTypePageIndices[p]||(t.pageTypePageIndices[p]=[])).push(g))}if(d===this.xmldoc.root)break;d=d.parentElement}}getFirstInFlowElementAtOrAfter(e,t){if(this.isNormalFlowElement(e)&&this.xmldoc.getElementOffset(e)>=t)return e;let i=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:n=>{let r=n;return this.isNormalFlowElement(r)?this.xmldoc.getElementOffset(r)<t?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}).firstChild();return i??null}getDeepestFirstInFlowChildOffset(e){let t=e;for(;;){let i=this.getFirstInFlowChildElement(t);if(!i)return this.xmldoc.getElementOffset(t);t=i}}getFirstInFlowChildElement(e){let t=e.firstChild;for(;t;){if(t.nodeType===Node.TEXT_NODE){if(!Me(t))return null;t=t.nextSibling;continue}if(t.nodeType!==Node.ELEMENT_NODE){t=t.nextSibling;continue}let i=t;if(this.isNormalFlowElement(i))return i;t=t.nextSibling}return null}isNormalFlowElement(e){var t,i;let n=this.styler.getStyle(e,!1);if(this.getDisplayValue(e)===v.none)return!1;let r=(t=n?.position)==null?void 0:t.evaluate(this.styler.context,"position"),s=r&&!J(r)?r:v.static;if(ys(s)||zs(s))return!1;let o=(i=n?.float)==null?void 0:i.evaluate(this.styler.context,"float");return(o&&!J(o)?o:v.none)===v.none}isInlineLevelElement(e){return Mt(this.getDisplayValue(e))}getDisplayValue(e){var t;let i=this.styler.getStyle(e,!1),n=(t=i?.display)==null?void 0:t.evaluate(this.styler.context,"display");return n&&!J(n)?n:v.inline}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){W.debug("Location - page",this.currentLayoutPosition.page),W.debug(" current:",e),W.debug(" lookup:",this.lookupOffset);for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n of i.positions)W.debug(" Chunk",`${t}:`,n.flowChunk.startOffset)}}matchPageSide(e){switch(e){case"left":case"right":case"recto":case"verso":return new je(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=Yl(et(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===ul)continue;let o=1;r.pageBox.pseudoName===ol&&!(this.actualPageWidth&&this.actualPageHeight)&&(o=1/0);let a=r.getProp(this,"utilization");a&&a.isNum()&&(o=a.num);let h=this.queryUnitSize("em",!1),l=this.pageWidth()*this.pageHeight(),u=Math.ceil(o*l/(h*h)),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===v._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=ni(r.length,l=>r[l]>n)-1,o=r[s],a=this.layoutPositionAtPageStart.flowPositions[i],h=this.getConsumedOffset(a);return o<h?!1:h<o?!0:!this.matchPageSide(a.startBreakType)}return!1}setFormattingContextToColumn(e,t){let i=this.currentLayoutPosition.flows[t];i.formattingContext||(i.formattingContext=new Wa(null)),e.flowRootFormattingContext=i.formattingContext}beginIsolatedRootPageFloatLayoutContext(){let e=this.rootPageFloatLayoutContext;return this.rootPageFloatLayoutContext=new en(null,null,null,null,null,null,null),e}endIsolatedRootPageFloatLayoutContext(e){this.rootPageFloatLayoutContext=e}hasActiveRootPageFloatLayoutContext(){return this.rootPageFloatLayoutContext.getDeferredPageFloatContinuations().length>0||this.rootPageFloatLayoutContext.getPageFloatContinuationsDeferredToNext().length>0||this.rootPageFloatLayoutContext.getFloatsDeferredToNextInChildContexts().length>0}layoutDeferredPageFloats(e){let t=e.pageFloatLayoutContext,i=t.getDeferredPageFloatContinuations(),n=this.counterStore.currentPageCountersStack.length>0,r=h=>{var l,u;if(!n||h.floatReference!==Te.PAGE)return!1;let d=((u=(l=this.layoutPositionAtPageStart)==null?void 0:l.flowPositions)==null?void 0:u.body)||null,p=d?this.getConsumedOffset(d):Number.NaN,f=isFinite(p)?p:this.getPageStartOffset(this.layoutPositionAtPageStart,!0),g=this.xmldoc.getNodeOffset(h.nodePosition.steps[0].node,0,!1);return g!=null&&isFinite(f)&&g>f},s=M("layoutDeferredPageFloats"),o=!1,a=0;return s.loopWithFrame(h=>{if(a===i.length){h.breakLoop();return}let l=i[a++],u=l.float;if(r(u)){h.breakLoop();return}let d=new Sn().findByFloat(u),p=d.findPageFloatFragment(u,t);if(p&&p.hasFloat(u)){h.continueLoop();return}else if(t.isForbidden(u)||t.hasPrecedingFloatsDeferredToNext(u)){t.deferPageFloat(l),h.breakLoop();return}e.layoutPageFloatInner(l,d,null,p).then(f=>{if(!f){h.breakLoop();return}let g=t.parent.isInvalidated();if(g){h.breakLoop();return}else t.isInvalidated()&&!g&&(o=!0,t.validate());h.continueLoop()})}).then(()=>{o&&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 xi(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=M("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 h=0;for(;s.includes(h);)h++;let l=i.positions[h];if(l.flowChunk.startOffset>this.lookupOffset||this.flowChunkIsAfterParentFlowForcedBreak(l.flowChunk))break;for(let p=h+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(l.flowChunk)&&(l=f,h=p)}let u=l.flowChunk,d=!0;if(e.layout(l.chunkPosition,o,i.breakAfter).then(p=>{if(e.pageFloatLayoutContext.isInvalidated()){a.breakLoop();return}if(o=!1,l.flowChunk.repeated&&(p===null||u.exclusive)&&r.push(h),u.exclusive){s.push(h),a.breakLoop();return}else{let f=!!p||!!e.pageBreakType,g=this.getLastAfterPositionIfDeferredFloatsExists(e,p);if(e.pageBreakType&&g?(l.chunkPosition=g,i.breakAfter=e.pageBreakType,e.pageBreakType=null):(s.push(h),(p||g)&&(l.chunkPosition=p||g,r.push(h)),i.startBreakType=Yl(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((h,l)=>r.includes(l)||!s.includes(l)),i.breakAfter==="column"&&(i.breakAfter=null),e.saveDistanceToBlockEndFloats();let a=e.pageFloatLayoutContext.getMaxReachedAfterEdge();e.updateMaxReachedAfterEdge(a)}n.finish(!0)})}),n.result()}createLayoutConstraint(e){let t=this.currentLayoutPosition.page-1,i=this.counterStore.createLayoutConstraint(t);return new iy([i].concat(e.getLayoutConstraints()))}createAndLayoutColumn(e,t,i,n,r,s,o,a,h,l,u,d,p,f){let g=e.vertical?e.isAutoWidth&&e.isRightDependentOnAutoWidth:e.isAutoHeight&&e.isTopDependentOnAutoHeight,m=r.element,w=new en(a,Te.COLUMN,null,o,null,null,null),b=this.currentLayoutPosition.clone(),x=M("createAndLayoutColumn"),y;return x.loopWithFrame(P=>{let S=this.createLayoutConstraint(w);if(h>1){let R=this.viewport.document.createElement("div");if(I(R,"position","absolute"),m.appendChild(R),y=new ks(R,p,this.clientLayout,S,w),y.isNonFirstColumn=s>0,y.forceNonfitting=f,y.vertical=r.vertical,y.rtl=r.rtl,y.snapHeight=r.snapHeight,y.snapWidth=r.snapWidth,r.vertical){let A=(r.rtl?h-s-1:s)*(u+l)+r.paddingTop,U=parseFloat(m.style.width);y.setHorizontalPosition(r.paddingLeft+U-r.width,r.width),y.setVerticalPosition(A,u)}else{let A=(r.rtl?h-s-1:s)*(u+l)+r.paddingLeft;y.setVerticalPosition(r.paddingTop,r.height),y.setHorizontalPosition(A,u)}y.originX=t,y.originY=i}else y=new ks(m,p,this.clientLayout,S,w),y.isNonFirstColumn=!1,y.copyFrom(r);y.exclusions=g?[]:n.concat(),y.innerShape=d,w.setContainer(y),(y.vertical?y.height:y.width)>=0?this.layoutColumn(y,o).then(()=>{w.isInvalidated()||w.finish(),y.pageFloatLayoutContext.isInvalidated()&&!a.isInvalidated()?(y.pageFloatLayoutContext.validate(),this.currentLayoutPosition=b.clone(),y.element!==m&&m.removeChild(y.element),P.continueLoop()):P.breakLoop()}):(w.finish(),P.breakLoop())}).then(()=>{x.finish(y)}),x.result()}setPagePageFloatLayoutContextContainer(e,t,i){(t instanceof wp||t instanceof al&&!(t instanceof yn))&&e.setContainer(i)}getRegionPageFloatLayoutContext(e,t,i,n){t instanceof Pn;let r=t.getProp(this,"writing-mode")||null,s=t.getProp(this,"direction")||null;return new en(e,Te.REGION,i,n,null,r,s)}layoutFlowColumnsWithBalancing(e,t,i,n,r,s,o,a,h){let l=this.currentLayoutPosition.clone(),u=this.getRegionPageFloatLayoutContext(s,t,o,a),d=!0,p=()=>(this.currentLayoutPosition=l.clone(),this.layoutFlowColumns(e,t,i,n,r,s,u,o,a,h,d).thenAsync(f=>N(f?{columns:f,position:this.currentLayoutPosition}:null)));return p().thenAsync(f=>{if(!f)return N(null);if(h<=1)return N(f.columns);let g=t.getProp(this,"column-fill")||v.balance,m=this.currentLayoutPosition.flowPositions[a],w=Wy(h,g,p,u,o,f.columns,m);return w?(d=!1,s.lock(),u.lock(),w.balanceColumns(f).thenAsync(b=>(s.unlock(),s.validate(),u.unlock(),this.currentLayoutPosition=b.position,N(b.columns)))):N(f.columns)})}layoutFlowColumns(e,t,i,n,r,s,o,a,h,l,u){let d=M("layoutFlowColumns"),p=this.currentLayoutPosition.clone(),f=Vh(this.currentLayoutPosition),g=t.getPropAsNumber(this,"column-gap"),m=l>1?t.getPropAsNumber(this,"column-width"):a.vertical?a.height:a.width,w=t.getActiveRegions(this),b=t.getProp(this,"shape-inside"),x=qu(b,0,0,a.width,a.height,this),y=new Dv(h,this,this.viewport,this.styler,w,this.xmldoc,this.faces,this.style.footnoteProps,this,e,this.customRenderer,this.fallbackMap,this.documentURLTransformer,this.style.pageProps,this.currentCascadedPageStyle,this.semanticFootnoteFirstRefOffsets,this.semanticFootnoteFirstRefOffsetsInitialized),P=0,S=null,R=[];return d.loopWithFrame(A=>{this.createAndLayoutColumn(t,i,n,r,a,P++,h,o,l,g,m,x,y,u).then(U=>{if(s.isInvalidated()){R=null,A.breakLoop();return}if((U.pageBreakType&&U.pageBreakType!=="column"||P===l)&&!o.isInvalidated()&&o.finish(),o.isInvalidated()){P=0,this.currentLayoutPosition=p.clone(),Uh(f),o.validate(),o.isLocked()?(R=null,A.breakLoop()):A.continueLoop();return}S=U,R[P-1]=S,S.pageBreakType&&S.pageBreakType!="column"&&(P=l,S.pageBreakType!="region"&&(this.pageBreaks[h]=!0)),P<l?A.continueLoop():A.breakLoop()})}).then(()=>{d.finish(R)}),d.result()}layoutContainer(e,t,i,n,r,s,o){t.reset();let a=t.getProp(this,"enabled");if(a&&a!==v._true)return N(!0);let h=M("layoutContainer"),l=t.getProp(this,"wrap-flow")===v.auto,u=t.getProp(this,"flow-from"),d=this.viewport.document.createElement("div");d.role=t instanceof yp?"complementary":"presentation";let p=t.getProp(this,"position");I(d,"position",p?p.name:"absolute");let f=t instanceof yn;t instanceof Pn?i.appendChild(d):i.insertBefore(d,i.firstChild);let g=new Rc(d);g.vertical=t.vertical,g.rtl=t.rtl,g.borderBoxSizing=t.borderBoxSizing,g.exclusions=s,t.prepareContainer(this,g,e,this.faces,this.clientLayout),t instanceof yn&&(g.width<=0||g.height<=0)&&W.warn("Negative or zero page area size"),g.originX=n,g.originY=r,n+=g.left+g.marginLeft+g.borderLeft,r+=g.top+g.marginTop+g.borderTop,this.setPagePageFloatLayoutContextContainer(o,t,g);let m,w=!1;if(!u||!u.isIdent()){let b=[],x=t.getProp(this,"content");if(x instanceof $&&x.expr instanceof Ie&&x.expr.str.startsWith("running-element-"))x.visit(new sr(d,this,x,this.counterStore.getExprContentListener()));else if(Rt(x)){let y="span";x instanceof ot&&(y="img");let P=this.viewport.document.createElement(y);x.visit(new sr(P,this,x,this.counterStore.getExprContentListener())),d.appendChild(P),y=="img"&&t.transferSingleUriContentProps(this,P,this.faces),t.transferContentProps(this,g,e,this.faces);let S=P.querySelectorAll("img[src]");for(let A=0;A<S.length;A++){let U=S[A],G=U.getAttribute("src");if(!G)continue;let Z=Ut(U,G);b.push(Z),e.fetchers.push(Z)}let R=P.getAttribute("src");if(R){let A=P.querySelector("img");A||(A=P);let U=Ut(A,R);b.push(U),e.fetchers.push(U)}y=="span"&&qw(P,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,g,e,null,1,this.clientLayout,this.faces),m=b.length?vn(b).thenReturn(!0):N(!0)}else if(this.pageBreaks[u.toString()])o.isInvalidated()||t.finishContainer(this,g,e,null,1,this.clientLayout,this.faces),m=N(!0);else{let b=M("layoutContainer.inner"),x=u.toString(),y=t.getPropAsNumber(this,"column-count");this.layoutFlowColumnsWithBalancing(e,t,n,r,s,o,g,x,y).then(P=>{if(!o.isInvalidated()){let S=P[0];S.element===d&&(g=S),g.computedBlockSize=Math.max.apply(null,P.map(A=>A.computedBlockSize)),t.finishContainer(this,g,e,S,y,this.clientLayout,this.faces);let R=this.currentLayoutPosition.flowPositions[x];R&&R.breakAfter==="region"&&(R.breakAfter=null)}b.finish(!0)}),m=b.result()}return m.then(()=>{if(o.isInvalidated()){h.finish(!0);return}if(!t.isAutoHeight||Math.floor(g.computedBlockSize)>0){if(!w&&!l){let x=t.getProp(this,"shape-outside"),y=g.getOuterShape(x,this);s.push(y)}}else if(t.children.length==0){i.removeChild(d),h.finish(!0);return}let b=f?0:t.children.length-1;h.loop(()=>{for(;b>=0&&b<t.children.length;){let x=t.children[f?b++:b--],y=this.layoutContainer(e,x,d,n,r,s,o);if(y.isPending())return y.thenAsync(()=>N(!o.isInvalidated()));if(o.isInvalidated())break}return N(!1)}).then(()=>{h.finish(!0)})}),h.result()}processLinger(){let e=this.currentLayoutPosition.page;for(let t in this.currentLayoutPosition.flowPositions){let i=this.currentLayoutPosition.flowPositions[t];for(let n=i.positions.length-1;n>=0;n--){let 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,n,r,s;let o=e.container===e.bleedBox;this.pageBreaks={},t?(this.currentLayoutPosition=t.clone(),this.styler.replayFlowElementsFromOffset(t.highestSeenOffset)):(this.currentLayoutPosition=new Cm,this.styler.replayFlowElementsFromOffset(-1)),this.lang&&e.bleedBox.setAttribute("lang",this.lang),t=this.currentLayoutPosition;let a=1e4;if(t.page>a)throw new Error(`Too many pages generated (over ${a} pages)`);let h=t.startSideOfFlow("body");t.isBlankPage=xn(h)&&this.matchPageSide(h),e.isBlankPage=t.isBlankPage,t.page++,e.pageType==null&&(e.pageType=(n=(i=e.isBlankPage?this.styler.cascade.previousPageType:this.styler.cascade.currentPageType)!=null?i:t.page===1?this.resolveFirstPageType():null)!=null?n:"",this.styler.cascade.previousPageType=this.styler.cascade.currentPageType),this.updatePageGroupPageIndices(t),this.clearScope(this.style.pageScope),this.layoutPositionAtPageStart=t.clone();let l=Vh(t),u=o?{}:this.pageManager.getCascadedPageStyle(e.pageType);if(this.currentCascadedPageStyle=u,this.styler.cascade.applyVarFilter([u],this.styler,null),this.styler.cascade.applyCalcFilter(u,this.styler.context),this.styler.cascade.applyCmykFilter(u),!o){let b=new je(this.style.pageScope,"left-page");e.side=b.evaluate(this)?"left":"right",e.container.setAttribute("data-vivliostyle-page-side",e.side)}let d=this.selectPageMaster(u);if(!d)return N(null);let p=0;if(!o){e.setAutoPageWidth(d.pageBox.specified.width.value===mr),e.setAutoPageHeight(d.pageBox.specified.height.value===wr);let{counterOffset:b,changeOffset:x}=this.getPageStartCounterOffsets(this.layoutPositionAtPageStart);isFinite(b)||(b=this.lookupOffset,x=this.lookupOffset),isFinite(b)&&this.styler.styleUntil(b,0);let y=this.styler.getCounterSnapshotAtOffset(b),P=x===b?y:this.styler.getCounterSnapshotAtOffset(x);y||(y=this.styler.getLastCounterSnapshot()),P||(P=y),this.counterStore.setCurrentPageDocCounters((r=y?.counters)!=null?r:null,(s=P?.changes)!=null?s:null,P?.changeTypes),this.counterStore.setCurrentPage(e),this.counterStore.updatePageCounters(u,this);let S=Mh(As(u),this);this.setPageSizeAndBleed(S,e),lv(u,S,e,this),p=S.bleedOffset+S.bleed}let f=!o&&d.getProp(this,"writing-mode")||v.horizontal_tb;this.pageVertical=f!=v.horizontal_tb;let g=d.getProp(this,"direction")||v.ltr,m=new en(this.rootPageFloatLayoutContext,Te.PAGE,null,null,null,f,g),w=M("layoutNextPage");return w.loopWithFrame(b=>{this.layoutContainer(e,d,e.bleedBox,p,p,[],m).then(()=>{if(m.isInvalidated()||m.finish(),m.isInvalidated()){for(this.currentLayoutPosition=this.layoutPositionAtPageStart.clone(),Uh(l),m.validate();e.bleedBox.lastChild;)e.bleedBox.removeChild(e.bleedBox.lastChild);b.continueLoop()}else b.breakLoop()})}).then(()=>{d.adjustPageLayout(this,e,this.clientLayout),o||(this.processLinger(),t=this.currentLayoutPosition,Object.keys(t.flowPositions).forEach(x=>{let y=t.flowPositions[x],P=y.breakAfter;P&&(P==="page"||!this.matchPageSide(P))&&(y.breakAfter=null)})),this.currentLayoutPosition=this.layoutPositionAtPageStart=null,t.highestSeenOffset=this.styler.getReachedOffset();let b=this.style.store.getTriggersForDoc(this.xmldoc);e.finish(b,this.clientLayout),this.noMorePrimaryFlows(t)&&(t=null),w.finish(t)}),w.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`}},qv=class Ca extends ar{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 op(this.masterHandler.pageScope,t,i,n,this.masterHandler.rootBox,this.condition,this.owner.getBaseSpecificity());this.masterHandler.pushHandler(new tv(r.scope,this.masterHandler,r,this.validatorSet))}startWhenRule(t){let i=t.expr;this.condition!=null&&(i=At(this.scope,this.condition,i)),this.masterHandler.pushHandler(new Ca(this.masterHandler,i,this,this.regionId))}startDefineRule(){this.masterHandler.pushHandler(new Vw(this.scope,this.owner))}startFontFaceRule(){let t={};this.masterHandler.fontFaces.push({properties:t,condition:this.condition}),this.masterHandler.pushHandler(new jr(this.scope,this.owner,null,t,this.masterHandler.validatorSet,"font-face"))}startCounterStyleRule(t){this.masterHandler.pushHandler(new jv(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 jr(this.scope,this.owner,null,i,this.masterHandler.validatorSet))}startViewportRule(){let t={};this.masterHandler.viewportProps.push(t),this.masterHandler.pushHandler(new jr(this.scope,this.owner,this.condition,t,this.masterHandler.validatorSet))}startFootnoteRule(t){let i=this.masterHandler.footnoteProps;if(t){let n=ei(i,"_pseudos");i=n[t],i||(i={},n[t]=i)}this.masterHandler.pushHandler(new bp(this.scope,this.owner,this.masterHandler.validatorSet,i))}startRegionRule(){this.insideRegion=!0,this.startSelectorRule()}startPageRule(){let t=new Nv(this.masterHandler.pageScope,this.masterHandler,this,this.validatorSet,this.masterHandler.pageProps);this.masterHandler.pushHandler(t),t.startPageRule()}startRuleBody(){if(ar.prototype.startRuleBody.call(this),this.insideRegion){this.insideRegion=!1;let t=`R${this.masterHandler.regionCount++}`;this.special("region-id",B(t)),this.endRule();let i=new Ca(this.masterHandler,this.condition,this,t);this.masterHandler.pushHandler(i),i.startRuleBody()}}},Ep=class extends jg{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 Eb),c(this,"footnoteProps",{}),c(this,"flowProps",{}),c(this,"viewportProps",[]),c(this,"pageProps",{}),this.rootScope=new So(null),this.pageScope=new So(this.rootScope),this.rootBox=new Yb(this.rootScope),this.cascadeParserHandler=new qv(this,null,null,null),this.slave=this.cascadeParserHandler}};function Yv(e,t){return t.parseOPSResource(e)}var Zv=class extends Ma{constructor(e){super(Yv,"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=M("OPSDocStore.init");return this.validatorSet=rp(),Gv().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=Ee(pn(t),Di)),this.styleSheets.push({url:t,text:e.text,flavor:"Author",classes:null,media:null})}addUserStyleSheet(e){let t=e.url;t&&(t=Ee(pn(t),Di)),this.styleSheets.push({url:t,text:e.text,flavor:"User",classes:null,media:null})}parseOPSResource(e){let t=M("OPSDocStore.load"),i=e.url,n=i.endsWith("?viv-toc-box");return Cp(e,this).then(r=>{var s;if(!r){t.finish(null);return}if(this.triggerSingleDocumentPreprocessing){let p=Ft("PREPROCESS_SINGLE_DOCUMENT");for(let f=0;f<p.length;f++)try{p[f](r.document)}catch(g){W.warn("Error during single document preprocessing:",g)}}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],g=f.getAttributeNS("http://www.w3.org/2001/xml-events","observer"),m=f.getAttributeNS("http://www.w3.org/2001/xml-events","event"),w=f.getAttribute("action"),b=f.getAttribute("ref");g&&m&&w&&b&&o.push({observer:g,event:m,action:w,ref:b})}this.triggersByDocURL[i]=o;let h=[];if(h.push({url:Ee("user-agent-page.css",fi),text:nc,flavor:"UA",classes:null,media:null}),h.push({url:Ee("user-agent-counter-styles.css",fi),text:ac,flavor:"UA",classes:null,media:null}),n)h.push({url:Ee("user-agent-toc.css",fi),text:sc,flavor:"UA",classes:null,media:null});else{let p=r.document.querySelectorAll("style, link, meta");for(let f of p){let g=f.namespaceURI,m=f.localName;if(g=="http://www.w3.org/1999/xhtml")if(m=="style"){let w=f.getAttribute("class"),b=f.getAttribute("media"),x=f.getAttribute("title");h.push({url:i,text:f.textContent,flavor:"Author",classes:x?w:null,media:b})}else if(m=="link"){let w=f.getAttribute("href"),b=(s=f.getAttribute("rel"))==null?void 0:s.split(/\s+/),x=f.getAttribute("class"),y=f.getAttribute("media");if(w&&b!=null&&b.includes("stylesheet")&&(!b.includes("alternate")||x)){let P=Ee(w,i),S=f.getAttribute("title");h.push({url:P,text:null,classes:S?x:null,media:y,flavor:"Author"})}}else m=="meta"&&f.getAttribute("name")=="viewport"&&h.push({url:i,text:this.processViewportMeta(f),flavor:"Author",classes:null,media:null})}for(let f=0;f<this.styleSheets.length;f++)h.push(this.styleSheets[f])}let l="";for(let p=0;p<h.length;p++)l+=h[p].url,l+="^",h[p].text&&(l+=h[p].text),l+="^";let u=this.styleByKey[l];if(u){this.styleByDocURL[i]=u,t.finish(r);return}let d=this.styleFetcherByKey[l];d||(d=new yr(()=>{let p=M("fetchStylesheet"),f=0,g=new Ep(this.validatorSet);return p.loop(()=>{if(f<h.length){let m=h[f++];return g.startStylesheet(m.flavor),m.text!==null?Da(m.text,g,m.url,m.classes,m.media).thenReturn(!0):pc(m.url,g,m.classes,m.media)}return N(!1)}).then(()=>{let m=g.cascadeParserHandler.finish();u=new Xv(this,g.rootScope,g.pageScope,m,g.rootBox,g.fontFaces,g.footnoteProps,g.flowProps,g.viewportProps,g.pageProps,g.counterStyles),this.styleByKey[l]=u,delete this.styleFetcherByKey[l],p.finish(u)}),p.result()},`FetchStylesheet ${i}`),this.styleFetcherByKey[l]=d,d.start()),d.get().then(p=>{this.styleByDocURL[i]=p,t.finish(r)})}),t.result()}processViewportMeta(e){return""}},nr="\u25B8",Hh="\u25BE",Kv="\u25B9";function pl(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 Jv(e){let t=pl(e),i=[];for(let n of t)for(let r of n.querySelectorAll("li a[href]"))i.push(r);return i}var Qv=class{constructor(e,t,i,n,r,s,o,a,h,l,u){this.store=e,this.url=t,this.lang=i,this.clientLayout=n,this.fontMapper=r,this.rendererFactory=o,this.fallbackMap=a,this.documentURLTransformer=h,this.counterStore=l,this.cmykStore=u,c(this,"pref"),c(this,"page",null),c(this,"instance",null),this.pref=du(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;ci(n,"height","auto")!="auto"&&(I(n,"height","auto"),this.setAutoHeight(n,t)),ci(n,"position","static")=="absolute"&&(I(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=v.inherit,r["text-decoration"]=v.none;break;case"toc-node":r.display=v.block,r.margin=Ne,r.padding=Ne,r["padding-inline-start"]=new F(1.25,"em");break;case"toc-node-first-child":r.display=v.inline_block,r.margin=new F(.2,"em"),r["vertical-align"]=v.top,r.color=v.inherit,r["text-decoration"]=v.none;break;case"toc-container":r.padding=Ne;break}if(!s||s.toString()!="toc-node"&&s.toString()!="toc-container")return t(i,n,r);let o=i.firstChild;o&&o.nodeType!==1&&Me(o)&&i.replaceChild(i.ownerDocument.createComment(o.textContent),o);let a=n.getAttribute("data-adapt-class");if(a=="toc-node"){let l=n.firstChild;l.textContent!=nr&&(l.textContent=nr,I(l,"cursor","pointer"),l.addEventListener("click",e0,!1),l.setAttribute("role","button"),l.setAttribute("aria-expanded","false"),n.setAttribute("aria-expanded","false"),n.style.height!=="0px"&&(l.tabIndex=0))}let h=n.ownerDocument.createElement("div");if(h.setAttribute("data-adapt-process-children","true"),s.toString()=="toc-node"){let l=n.ownerDocument.createElement("div");if(l.textContent=Kv,I(l,"margin","0.2em 0 0 -1em"),I(l,"margin-inline-start","-1em"),I(l,"margin-inline-end","0"),I(l,"display","inline-block"),I(l,"width","1em"),I(l,"text-align","center"),I(l,"vertical-align","top"),I(l,"cursor","default"),I(l,"font-family","Menlo,sans-serif"),h.appendChild(l),I(h,"overflow","hidden"),h.setAttribute("data-adapt-class","toc-node"),h.setAttribute("role","treeitem"),a=="toc-node"||a=="toc-container"){I(h,"height","0px");let u=i.firstElementChild;u&&u.localName==="a"&&(u.tabIndex=-1)}else n.setAttribute("role","tree")}else a=="toc-node"&&(h.setAttribute("data-adapt-class","toc-container"),h.setAttribute("role","group"),h.setAttribute("aria-hidden","true"));return N(h)}}showTOC(e,t,i,n,r){if(this.page)return N(this.page);let s=M("showTOC"),o=new Sc(e,e);this.page=o;let a=Wt(this.url)+"?viv-toc-box";return this.store.load(a).then(h=>{for(let f of pl(h.document))f.setAttribute("data-vivliostyle-role","doc-toc");let l=this.store.getStyleForDoc(h),u=l.sizeViewport(i,1e5,r);t=new Ls(t.window,u.fontSize,0,e,u.width,u.height);let d=this.makeCustomRenderer(h),p=new dl(l,h,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]"),h=e(a);return{id:s,title:o,children:h}}let i=this.page.container.querySelector("[role=tree]");return e(i)}};function e0(e){let t=e.target,i=t.textContent==nr;t.textContent=i?Hh:nr;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==Hh){a.textContent=nr,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()}function Dr(e){let t={};return Object.keys(e).forEach(i=>{t[i]=Array.from(e[i])}),t}function t0(e){let t=Object.create(null);return Object.keys(e).forEach(i=>{t[i]=new Map(e[i])}),t}var $h=class extends Zv{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=Hv(),this.jsonStore=Hg()}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)}loadWebPubManifest(e,t){this.loadAsJSON(e,!0).then(i=>{if(!i){this.reportLoadError(e),t.finish(null);return}let n=new ls(this,e);n.initWithWebPubManifest(i,void 0,e).then(()=>{t.finish(n)})})}loadPubDoc(e){let t=M("loadPubDoc");if(/\.opf(?:[#?]|$)/i.test(e)){let[,i,n]=e.match(/^((?:.*\/)?)([^/]*)$/);this.loadOPF(i,n).thenFinish(t)}else/\.json(?:ld)?(?:[#?]|$)/i.test(e)?this.loadWebPubManifest(e,t):/\.(x?html?|xht)(?:[#?]|$)/i.test(e)?this.loadWebPub(e).then(i=>{if(i){t.finish(i);return}this.reportLoadError(e),t.finish(null)}):Ds(e,null,"HEAD").then(i=>{if(i.status>=400)this.loadEPUBDoc(e).then(n=>{if(n){t.finish(n);return}W.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"){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"?this.loadWebPubManifest(e,t):this.loadWebPub(e).then(n=>{if(n){t.finish(n);return}this.loadEPUBDoc(e).then(r=>{if(r){t.finish(r);return}this.reportLoadError(e),t.finish(null)})})});return t.result()}loadEPUBDoc(e){let t=M("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=M("loadOPF");return this.loadAsPlainXML(i,!0,`Failed to fetch EPUB OPF ${i}`).then(s=>{s?(n=new ls(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=M("loadWebPub");return this.load(e).then(i=>{if(!i)this.reportLoadError(e),t.finish(null);else if(i.document.querySelector("a[href='META-INF/'],a[href$='/META-INF/']"))t.finish(null);else{let n=i.document,r=new ls(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=Na(n.getElementById(o.substr(1)).textContent);r.initWithWebPubManifest(a,n).then(()=>{t.finish(r)})}else{let a=Ee(s.getAttribute("href"),e);this.loadAsJSON(a,!0,`Failed to fetch Publication Manifest ${a}`).then(h=>{r.initWithWebPubManifest(h,n,a).then(()=>{t.finish(r)})})}}else r.initWithWebPubManifest({},n).then(()=>{r.toc&&r.toc.src===i.url&&pl(n).length===0&&(r.toc=null),t.finish(r)})}}),t.result()}addDocument(e,t){let i=M("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(Di)||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:")?W.error(`Failed to load ${e}. Invalid data.`):e.startsWith("http:")&&Di.startsWith("https:")?W.error(`Failed to load ${e}. Mixed Content ("http:" content on "https:" context) is not allowed.`):i()?W.error(`Failed to load ${e}. This may be caused by the server not allowing cross-origin resource sharing (CORS).`):W.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=M("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""}},Wh=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=lf}initWithElement(e,t){this.id=e.getAttribute("id"),this.src=Ee(e.getAttribute("href"),t),this.mediaType=e.getAttribute("media-type");let i=e.getAttribute("properties");i&&(this.itemProperties=gf(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 i0(e){return e.id}function n0(e){return t=>{let i=M("deobfuscator");return r0("SHA-1",e).then(n=>{let r=t.slice(0,1040),s=t.slice(1040,t.size);zg(r).then(o=>{let a=new DataView(o);for(let h=0;h<a.byteLength;h++){let l=a.getUint8(h);l^=n[h%20],a.setUint8(h,l)}i.finish(lc([a,s]))})}),i.result()}}function r0(e,t){let i=M("makeDigest"),n=i.suspend();return window.crypto.subtle.digest(e,new TextEncoder().encode(t)).then(r=>{n.schedule(new Uint8Array(r))}),i.result()}var pi={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"},qn="http://idpf.org/epub/vocab/package/meta/#",Ve={language:`${pi.dcterms}language`,title:`${pi.dcterms}title`,creator:`${pi.dcterms}creator`,layout:`${pi.rendition}layout`,titleType:`${qn}title-type`,displaySeq:`${qn}display-seq`,alternateScript:`${qn}alternate-script`,role:`${qn}role`};function s0(e,t){let i={};return(n,r)=>{var s,o,a,h,l,u;let d,p,f=n.r||i,g=r.r||i;if(e==Ve.title&&(d=((s=f[Ve.titleType])==null?void 0:s[0].v)=="main",p=((o=g[Ve.titleType])==null?void 0:o[0].v)=="main",d!=p))return d?-1:1;let m=parseInt((a=f[Ve.displaySeq])==null?void 0:a[0].v,10);isNaN(m)&&(m=Number.MAX_VALUE);let w=parseInt((h=g[Ve.displaySeq])==null?void 0:h[0].v,10);return isNaN(w)&&(w=Number.MAX_VALUE),m!=w?m-w:e!=Ve.language&&t&&(d=((l=f[Ve.language]||f[Ve.alternateScript])==null?void 0:l[0].v)==t,p=((u=g[Ve.language]||g[Ve.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=pi;else{i={};for(let p in pi)i[p]=pi[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]]:qn;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:pi.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=eo(s,d=>d.refines),a=d=>mf(d,(p,f)=>p.map(g=>{let m={v:g.value,o:g.order};g.scheme&&(m.s=g.scheme);let w=o[`#${g.id}`]||[];if(w.length||g.lang||g.role){g.lang&&w.push({name:Ve.language,value:g.lang,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null}),g.role&&w.push({name:Ve.role,value:g.role,lang:null,id:null,refines:g.id,scheme:null,order:g.order,role:null});let b=eo(w,x=>x.name);m.r=a(b)}return m})),h=a(eo(s,d=>d.refines?null:d.name)),l=null;h[Ve.language]&&(l=h[Ve.language][0].v);let u=d=>{for(let p in d){let f=d[p];f.sort(s0(p,l));for(let g=0;g<f.length;g++){let m=f[g].r;m&&u(m)}}};return u(h),h}function a0(){let e=window.MathJax;return e?e.Hub:null}var Gh={"application/xhtml+xml":!0,"image/jpeg":!0,"image/png":!0,"image/svg+xml":!0,"image/gif":!0,"audio/mp3":!0},bo="viv-id-",ls=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 bo+hu(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(h=>h.src===o))return`#${this.transformFragment(a,o)}`}return n}restoreURL(n){n.charAt(0)==="#"&&(n=n.substring(1)),n.indexOf(bo)===0&&(n=n.substring(bo.length));let r=ff(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=Ee("",this.pubURL);return e===t||e+"/"===t?"":(t.charAt(t.length-1)!="/"&&(t+="/"),e.substr(0,t.length)==t?decodeURIComponent(e.substr(t.length)):null)}else return e}initWithXMLDoc(e,t){this.opfXML=e,this.encXML=t;let i=e.doc().child("package"),n=i.attribute("unique-identifier")[0];if(n){let h=e.getElement(`${e.url}#${n}`);h&&(this.uid=h.textContent.replace(/[ \n\r\t]/g,""))}let r={};this.items=i.child("manifest").child("item").asArray().map(h=>{let l=new Wh,u=h;l.initWithElement(u,e.url);let d=u.getAttribute("fallback");return d&&!Gh[l.mediaType]&&(r[l.src]=d),!this.toc&&l.itemProperties.nav&&(this.toc=l),!this.cover&&l.itemProperties["cover-image"]&&(this.cover=l),l}),this.itemMap=Cl(this.items,i0),this.itemMapByPath=Cl(this.items,h=>this.getPathFromURL(h.src));for(let h in r){let l=h;for(;;){let u=this.itemMap[r[l]];if(!u)break;if(Gh[u.mediaType]){this.fallbackMap[h]=u.src;break}l=u.src}}this.spine=i.child("spine").child("itemref").asArray().map((h,l)=>{let u=h,d=u.getAttribute("idref"),p=this.itemMap[d];return p&&(p.itemRefElement=u,p.spineIndex=l),p});let s=i.child("spine").attribute("page-progression-direction")[0];s&&(this.pageProgression=tu(s));let o=t?t.doc().child("encryption").child("EncryptedData").predicate(zh.withChild("EncryptionMethod",zh.withAttribute("Algorithm","http://www.idpf.org/2008/embedding"))).child("CipherData").child("CipherReference").attribute("URI"):[],a=i.child("bindings").child("mediaType").asArray();for(let h=0;h<a.length;h++){let l=a[h].getAttribute("handler"),u=a[h].getAttribute("media-type");u&&l&&this.itemMap[l]&&(this.bindings[u]=this.itemMap[l].src)}if(this.metadata=o0(i.child("metadata"),i.attribute("prefix")[0]),this.metadata[Ve.language]&&(this.lang=this.metadata[Ve.language][0].v),this.metadata[Ve.layout]&&(this.prePaginated=this.metadata[Ve.layout][0].v==="pre-paginated"),o.length>0&&this.uid){let h=n0(this.uid);for(let l=0;l<o.length;l++)this.store.deobfuscators[this.pubURL+o[l]]=h}return this.prePaginated&&this.assignAutoPages(),N(!0)}assignAutoPages(){let e=0;for(let t of this.spine){let i=this.prePaginated?1:Math.ceil(t.compressedSize/1024);t.epage=e,t.epageCount=i,e+=i}this.epageCount=e,this.epageCountCallback&&this.epageCountCallback(this.epageCount)}setEPageCountMode(e){this.epageIsRenderedPage=e||this.prePaginated}countEPages(e){if(this.epageCountCallback=e,this.epageIsRenderedPage)return this.prePaginated&&this.epageCount==0&&this.assignAutoPages(),N(!0);let t=0,i=0,n=M("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,h=o.lang||this.lang;h&&h.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 Sp(null,"",new DOMParser().parseFromString("<spine></spine>","text/xml"));return e.forEach(n=>{let r=new Wh;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[Ve.title]=(Array.isArray(a)?a:[a]).map(m=>{var w;return{v:(w=m.value)!=null?w:m}}));let h=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(m=>m.content);h&&h.length!==0&&(this.metadata[Ve.creator]=(Array.isArray(h)?h:[h]).map(m=>{var w;return{v:(w=m.name)!=null?w:m}}));let l=e.inLanguage||((o=e.metadata)==null?void 0:o.language)||t?.documentElement.lang||t?.documentElement.getAttribute("xml:lang");l&&(this.metadata[Ve.language]=(Array.isArray(l)?l:[l]).map(m=>({v:m})));let u=this.getPathFromURL(this.pubURL);if(!e.readingOrder&&t&&u!==null){e.readingOrder=[encodeURI(u)];for(let m of Jv(t)){let w=m.getAttribute("href");if(/^(https?:)?\/\//.test(w)||/\.(jpe?g|png|gif|pdf|svg|mml)([#?]|$)/.test(w))continue;let b=Wt(Ee(w,this.pubURL)),x=this.getPathFromURL(b),y=x!==null?encodeURI(x):b;e.readingOrder.indexOf(y)==-1&&e.readingOrder.push(y)}}let d=[],p=0,f=-1;[e.readingOrder,e.resources].forEach(m=>{m instanceof Array&&m.forEach(w=>{let b=m===e.readingOrder,x=typeof w=="string"?w:w.url||w.href,y=typeof w=="string"?"":w.encodingFormat||w.href&&w.type||"";if(b||y==="text/html"||y==="application/xhtml+xml"||!y&&w.rel!=="stylesheet"&&/(^|\/)([^/]+\.(x?html|htm|xht)|[^/.]*)([#?]|$)/.test(x)){let P=i?i.replace(/\/[^/]+$/,"/"):this.pubURL,S={url:Ee(pn(x),P),index:p++,startPage:null,skipPagesBefore:null};w.rel==="contents"&&f===-1&&(f=S.index),d.push(S)}})});let g=M("initWithWebPubManifest");return this.initWithChapters(d).then(()=>{var m,w;f!==-1&&(this.toc=this.items[f]),this.toc||(this.toc=i?(m=this.items)==null?void 0:m[0]:this.itemMapByPath[u]);let b=(w=e.readingOrder)==null?void 0:w.length;b&&b<this.items.length&&this.items.splice(b),g.finish(!0)}),g.result()}getCFI(e,t){let i=this.spine[e],n=M("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),h=t-a,l=new Ml;l.prependPathFromNode(s,h,!1,null),i.itemRefElement&&l.prependPathFromNode(i.itemRefElement,0,!1,null),o=l.toString()}n.finish(o)}),n.result()}resolveFragment(e){return bn("resolveFragment",t=>{if(!e){t.finish(null);return}let i=new Ml;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)=>{W.warn(i,"Cannot resolve fragment:",e),t.finish(null)})}resolveEPage(e){return bn("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=ni(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)=>{W.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=M("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()}},zr=(e,t)=>({page:e,position:{spineIndex:e.spineIndex,pageIndex:t,offsetInItem:e.offset}}),l0=class{constructor(e,t,i,n,r,s){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"),c(this,"paginationProgress",{totalOffsetsBySpine:[],renderedOffsetsBySpine:[],lastReportedPages:0,lastReportedFraction:0}),this.pref=du(n),this.clientLayout=new Vv(t),this.counterStore=new lg(e.documentURLTransformer),this.cmykStore=new Vu,s!=null&&s.length&&this.cmykStore.registerCmykReserveMap(s)}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=M("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)}getRenderedPageCount(){let e=0;for(let t of this.spineItems)t&&(e+=t.pages.length);return e}markSpineItemCompleteIfReady(e){e.complete=e.layoutPositions.length===e.pages.length,e.complete&&e.instance.viewport.layoutBox.removeAttribute("style")}getTotalOffsetForViewItem(e){let t=e.item.spineIndex,i=this.paginationProgress.totalOffsetsBySpine[t];return i==null&&(i=e.xmldoc.getTotalOffset(),this.paginationProgress.totalOffsetsBySpine[t]=i),i}getTotalOffsetAll(){let e=0;for(let t of this.spineItems)t&&(e+=this.getTotalOffsetForViewItem(t));return e}getRenderedOffsetAll(){var e;let t=0,i=this.paginationProgress.totalOffsetsBySpine,n=this.paginationProgress.renderedOffsetsBySpine;for(let r=0;r<i.length;r++){let s=i[r];if(!s)continue;let o=(e=n[r])!=null?e:0;t+=Math.min(s,o)}return t}reportPaginationProgress(e,t){let i=Ft("PAGINATION_PROGRESS");if(!i.length)return;let n=e.item.spineIndex,r=this.getTotalOffsetForViewItem(e),s=r;t&&(s=e.instance.getPosition(t,!0)),s<0&&(s=0),s>r&&(s=r);let o=this.paginationProgress.renderedOffsetsBySpine[n];o!=null&&s<o&&(s=o),this.paginationProgress.renderedOffsetsBySpine[n]=s;let a=this.getRenderedPageCount(),h=this.getTotalOffsetAll(),l=this.getRenderedOffsetAll(),u=h>0?l/h:0;u<this.paginationProgress.lastReportedFraction?u=this.paginationProgress.lastReportedFraction:this.paginationProgress.lastReportedFraction=u,a>this.paginationProgress.lastReportedPages&&(this.paginationProgress.lastReportedPages=a);let d={fraction:u,pages:this.paginationProgress.lastReportedPages};for(let p of i)try{p(d)}catch(f){W.warn(f)}}isInCounterResolveScope(){return this.counterStore.currentPageCountersStack.length>0}hasNonEmptyPageType(e){return!!(e!=null&&e.pageType)&&e.pageType!==""}hasPageTypeBoundaryBetween(e,t){return e?.pageType!=null&&t?.pageType!=null&&e.pageType!==t.pageType}resolvePageTypeForRenderSlot(e,t,i,n,r,s,o){let a=!1;if(n){let h=this.hasPageTypeBoundaryBetween(r,n),l=s?.pageType===n.pageType,u=n.offset!==t.offset,d=o&&!u&&i>0&&h&&l;if(a=n.pageType!=null&&(d||i===0||n.pageType===r?.pageType),t.pageType=a?n.pageType:null,!o&&!a){let p=i>1&&h&&l?r.pageType:null;e.instance.styler.cascade.currentPageType=p,e.instance.pageManager.pageCascadeInstance.currentPageType=p}}!o&&this.hasNonEmptyPageType(r)&&this.hasNonEmptyPageType(s)&&r.pageType!==s.pageType&&(!n||n.pageType==null)&&(t.pageType=r.pageType)}evaluateNextPageRelayout(e,t,i,n,r){if(!e||t&&!i)return{needsRelayout:!1,shouldCascade:!1};let s=!!t&&(e.pageType===t.pageType||!t.pageType);return t&&n&&(!r||s)&&(t.pageType==null||e.pageType==null||e.pageType!==t.pageType)&&(t.pageType=null),{needsRelayout:!0,shouldCascade:!!t||!r}}preparePageCountersForRender(e,t){let i=e.pages[t],n=e.pageCounterStarts[t];i&&n&&(this.counterStore.currentPageCounters=Dr(n));let r=Dr(this.counterStore.currentPageCounters);return(!n||!i)&&(e.pageCounterStarts[t]=r),i}maybeRelayoutFollowingPage(e,t,i,n){if(!t)return N(!0);let r=e.layoutPositions[t.page];e.layoutPositions[t.page]=t;let s=e.pages[t.page],o=!!i&&n.offset!==i.offset,a=!r||!t.isSamePosition(r)||t.highestSeenOffset!==r.highestSeenOffset||o,h=this.isInCounterResolveScope(),l=this.evaluateNextPageRelayout(i,s,a,o,h);return l.needsRelayout?(e.complete=!1,l.shouldCascade?this.renderSinglePage(e,t):N(!0)):N(!0)}resolveUnresolvedReferencesForPage(e,t,i,n){let r=M("resolveUnresolvedReferencesForPage"),s=this.isInCounterResolveScope()?[]:this.counterStore.getUnresolvedRefsToPage(t),o=0,a=t;return r.loopWithFrame(h=>{if(o++,o>s.length){h.breakLoop();return}let l=s[o-1];if(l.refs=l.refs.filter(u=>!u.isResolved()),l.refs.length===0){h.continueLoop();return}this.getPageViewItem(l.spineIndex).then(u=>{if(!u){h.continueLoop();return}let d=u.instance.styler.cascade,p=u.instance.pageManager.pageCascadeInstance,f={currentPageType:d.currentPageType,previousPageType:d.previousPageType},g={currentPageType:p.currentPageType,previousPageType:p.previousPageType},m=t0(u.instance.pageGroupPageCounts),w=u.instance.currentPageGroupDocument,b=u.instance.scopes;u.instance.scopes={};let x=l.pageIndex<u.pages.length-1,y=!!u.pages[l.pageIndex]&&x,P=y?u.instance.beginIsolatedRootPageFloatLayoutContext():null;this.counterStore.pushPageCounters(l.pageCounters),this.counterStore.pushReferencesToSolve(l.refs);let S=u.layoutPositions[l.pageIndex];this.renderSinglePage(u,S).then(R=>{y&&u.instance.endIsolatedRootPageFloatLayoutContext(P);let A=d.currentPageType;d.currentPageType=f.currentPageType,d.previousPageType=f.previousPageType,p.currentPageType=g.currentPageType,p.previousPageType=g.previousPageType,u.instance.pageGroupPageCounts=m,u.instance.currentPageGroupDocument=w,u.instance.scopes=b;let U=Dr(this.counterStore.currentPageCounters);this.counterStore.popPageCounters(),this.counterStore.popReferencesToSolve(),R.pageAndPosition.position.spineIndex===a.spineIndex&&R.pageAndPosition.position.pageIndex===i&&(a=R.pageAndPosition.page),a.pageType&&a.pageType!==f.currentPageType&&A!==R.pageAndPosition.page.pageType&&(d.currentPageType=a.pageType);let G=u!==e,Z=u.pages.length,fe=u.layoutPositions[Z],ue=u.instance.hasActiveRootPageFloatLayoutContext();if(fe&&!ue){let C=G?Dr(this.counterStore.currentPageCounters):null;G&&(this.counterStore.currentPageCounters=U);let _=Z;this.renderSinglePage(u,fe).then(()=>{G&&this.markSpineItemCompleteIfReady(u);let k=u.pages.length-_;if(G&&k>0){this.counterStore.adjustPageCountersOfLaterSpines(u.item.spineIndex,k),this.counterStore.updateTargetCounterNodesInPages(u.pages);let O=u.item.spineIndex;for(let E=O+1;E<this.spineItems.length;E++){let T=this.spineItems[E];if(T){T.item.epage+=k;for(let L of T.pageCounterStarts)L!=null&&L.page&&(L.page=L.page.map(z=>z+k));this.counterStore.updatePageCounterNodesInPages(T.pages,T.pageCounterStarts)}}if(C){let E=C.page;E&&(C.page=E.map(T=>T+k))}}C&&(this.counterStore.currentPageCounters=C),h.continueLoop()});return}G&&this.markSpineItemCompleteIfReady(u),h.continueLoop()})})}).then(()=>{a.container.parentElement||(a=e.pages[i]),a.isLastPage=!n&&e.item.spineIndex===this.opf.spine.length-1,a.isLastPage&&(this.viewport,this.counterStore.finishLastPage(this.viewport)),a.container.setAttribute("data-vivliostyle-page-index",i),a.container.setAttribute("data-vivliostyle-spine-index",a.spineIndex),r.finish(a)}),r.result()}renderSinglePage(e,t){let i=M("renderSinglePage"),n=t?Math.max(t.page,0):0,r=this.isInCounterResolveScope(),s=this.preparePageCountersForRender(e,n),o=n>0?e.pages[n-1]:null,a=e.pages[n+1],h=this.makePage(e,t);return this.resolvePageTypeForRenderSlot(e,h,n,s,o,a,r),e.instance.layoutNextPage(h,t).then(l=>{t=l;let u=t?t.page-1:e.layoutPositions.length-1;this.finishPageContainer(e,h,u),this.counterStore.finishPage(h.spineIndex,u),this.reportPaginationProgress(e,t),this.maybeRelayoutFollowingPage(e,t,s,h).thenAsync(()=>this.resolveUnresolvedReferencesForPage(e,h,u,t)).then(d=>{i.finish({pageAndPosition:zr(d,u),nextLayoutPosition:t})})}),i.result()}normalizeSeekPosition(e,t){let i=e.pageIndex,n=-1;if(i<0){n=e.offsetInItem;let r=ni(t.layoutPositions.length,s=>t.instance.getPosition(t.layoutPositions[s],!0)>n);r===t.layoutPositions.length?t.complete?i=t.pages.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=M("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.pages.length-1,r=n.pages[s],o.breakLoop()):t?this.renderPage(a).then(h=>{h&&(r=h.page,s=h.position.pageIndex),o.breakLoop()}):s<n.layoutPositions.length&&!n.pages[s]?this.renderPage(a).then(h=>{h&&(r=h.page,s=h.position.pageIndex),o.breakLoop()}):i.sleep(100).then(()=>{o.continueLoop()})}).then(()=>{i.finish(zr(r,s))})})}),i.result()}renderPage(e){let t=M("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(zr(o,r));return}t.loopWithFrame(a=>{if(r<i.layoutPositions.length){a.breakLoop();return}if(i.complete){r=i.pages.length-1,a.breakLoop();return}let h=i.layoutPositions[i.layoutPositions.length-1];this.renderSinglePage(i,h).then(l=>{let u=l.pageAndPosition.page;if(h=l.nextLayoutPosition,h){if(s>=0&&i.instance.getPosition(h)>s){o=u,r=i.layoutPositions.length-2,a.breakLoop();return}a.continueLoop()}else o=u,r=l.pageAndPosition.position.pageIndex,this.markSpineItemCompleteIfReady(i),a.breakLoop()})}).then(()=>{o=o||i.pages[r];let a=i.layoutPositions[r];if(o){t.finish(zr(o,r));return}this.renderSinglePage(i,a).then(h=>{h.nextLayoutPosition||this.markSpineItemCompleteIfReady(i),t.finish(h.pageAndPosition)})})}),t.result()}renderAllPages(){let e=M("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=M("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 h={spineIndex:s,pageIndex:s===n?r:Number.POSITIVE_INFINITY,offsetInItem:s===n?e.offsetInItem:-1};this.renderPage(h).then(l=>{o=l,++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=M("nextPage");return this.getPageViewItem(i).then(s=>{if(!s){r.finish(null);return}if(s.complete&&n==s.pages.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],h=s.pages[s.pages.length-1];a&&h&&a.side==h.side&&(o.pages.forEach(l=>{l.container&&l.container.remove()}),this.spineItems[i]=null,this.spineItemLoadingContinuations[i]=null)}else n++;this.findPage({spineIndex:i,pageIndex:n,offsetInItem:-1},t).thenFinish(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=M("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),h=o&&o.page;h&&h.side===a.side&&(h=null),r?n.finish({left:a,right:h}):n.finish({left:h,right:a})}),n.result()}nextSpread(e,t){let i=this.getPage(e);if(!i)return N(null);let n=this.isRectoPage(i,e),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=M("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=M("navigateToCFI");return this.opf.resolveFragment(e).then(r=>{r?this.findPage(r,i).thenFinish(n):n.finish(null)}),n.result()}resolveSemanticFootnoteNavigationOffset(e,t){if(!dn(t))return null;let i=t.getAttribute("id");if(!i)return null;let n=Ee(`#${i}`,e.xmldoc.url),r=e.xmldoc.document.getElementsByTagName("a");for(let s=0;s<r.length;s++){let o=r.item(s);if(!ir(o))continue;let a=o.getAttribute("href")||o.getAttributeNS("http://www.w3.org/1999/xlink","href");if(a&&Ee(a,e.xmldoc.url)===n)return e.xmldoc.getElementOffset(o)}return null}navigateTo(e,t,i){W.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=M("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),h=a&&this.resolveSemanticFootnoteNavigationOffset(o,a),l=h??(a?o.xmldoc.getElementOffset(a):0);this.findPage({spineIndex:r.spineIndex,pageIndex:-1,offsetInItem:l},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",rr||(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 Sc(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=pu(this.viewport.width,this.viewport.height,i.width,i.height),a=vr(null,new Xt(o,null),"");s.delayedItems.push(new Va(n,"transform",a))}return s}makeObjectView(e,t,i,n){let r=t.getAttribute("data"),s=null;if(r){r=Ee(r,e.url);let o=t.getAttribute("media-type");if(!o){let a=this.opf.getPathFromURL(r);if(a){let h=this.opf.itemMapByPath[a];h&&(o=h.mediaType)}}if(o){let a=this.opf.bindings[o];if(a){s=this.viewport.document.createElement("iframe"),s.style.border="none";let h=xl(r),l=xl(o),u=new ii;u.append(a),u.append("?src="),u.append(h),u.append("&type="),u.append(l);for(let f=t.firstChild;f;f=f.nextSibling)if(f.nodeType==1){let g=f;if(g.localName=="param"&&g.namespaceURI=="http://www.w3.org/1999/xhtml"){let m=g.getAttribute("name"),w=g.getAttribute("value");m&&w&&(u.append("&"),u.append(encodeURIComponent(m)),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=a0();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 h=r.queue;h.Push(["Typeset",r,o]);let l=M("makeMathJaxView"),u=l.suspend();return h.Push(()=>{u.schedule(o)}),l.result()}return N(null)}resolveURLsInMathML(e,t){if(e!=null){if(e.nodeType===1&&e.tagName==="mglyph"){let i=Array.from(e.attributes);for(let n of i){if(n.name!=="src")continue;let r=Ee(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=M("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 h=r.itemRefElement.getAttribute("properties");h&&o.root.setAttribute("data-vivliostyle-epub-spine-properties",h),r.title=o.document.title;let l=s.getStyleForDoc(o),u=this.makeCustomRenderer(o),d=this.viewport,p=l.sizeViewport(d.width,d.height,d.fontSize,this.pref);(p.width!=d.width||p.height!=d.height||p.fontSize!=d.fontSize)&&(d=new Ls(d.window,p.fontSize,d.pixelRatio,d.root,p.width,p.height));let f=(a=this.spineItems[0])==null?void 0:a.instance.isVersoFirstPage,g=this.spineItems[e-1],m,w;if(r.startPage!==null)m=r.startPage-1,w=m;else{if(e>0&&(!g||!g.complete))m=r.epage||e,!this.opf.prePaginated&&m%2==(f?1:0)&&m++,w=m;else{m=g?g.instance.pageNumberOffset+g.pages.length:0;let y=g&&g.pageCounterStarts[g.pages.length-1],P=y&&y.page;if(P&&P.length)w=P[P.length-1]+1;else{let S=this.counterStore.currentPageCounters.page;w=!S||!S.length?m:S[S.length-1]}}r.skipPagesBefore!==null&&(m+=r.skipPagesBefore,w+=r.skipPagesBefore)}this.counterStore.forceSetPageCounter(w);let b=new dl(l,o,this.opf.lang,d,this.clientLayout,this.fontMapper,u,this.opf.fallbackMap,m,this.opf.documentURLTransformer,this.counterStore,this.cmykStore,this.opf.pageProgression,f);b.pref=this.pref;let x=this.opf.metadata&&this.opf.metadata[Ve.title];b.pubTitle=x&&x[0]&&x[0].v||"",b.docTitle=r.title||"",b.init().then(()=>{!this.opf.pageProgression&&b.pageProgression&&(this.opf.pageProgression=b.pageProgression),t={item:r,xmldoc:o,instance:b,layoutPositions:[null],pages:[],complete:!1,pageCounterStarts:[]},this.spineItems[e]=t,i.finish(t),n.forEach(y=>{y.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=M("showTOC");this.tocView||(this.tocView=new Qv(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),rr||(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(h=>{a.style.visibility="visible",a.setAttribute("aria-hidden","false"),n.finish(h)}),n.result()}hideTOC(){this.tocVisible=!1,this.tocView&&this.tocView.hideTOC()}isTOCVisible(){return this.tocVisible&&!!this.tocView&&this.tocView.isTOCVisible()}},jh="data-vivliostyle-viewer-status",h0="data-vivliostyle-spread-view",Pp=(e=>(e.SINGLE_PAGE="singlePage",e.SPREAD="spread",e.AUTO_SPREAD="autoSpread",e))(Pp||{}),u0=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"),c(this,"cmykReserveMap"),c(this,"cmykReserveMapUrl");let r=t.ownerDocument,s=(o,a)=>{let h=r.getElementById(o);return h||(h=r.createElement("style"),h.id=o,a&&(h.textContent=a),r.head.appendChild(h)),h};s("vivliostyle-viewport-screen-css",Qu),s("vivliostyle-viewport-css",ec),s("vivliostyle-polyfill-css",oc),t.setAttribute("data-vivliostyle-viewer-viewport",!0),rr&&t.setAttribute("data-vivliostyle-debug",!0),t.setAttribute(jh,"loading"),this.fontMapper=new Xb(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=cu(),this.pageSizes=[],this.pixelRatioLimit=Pa==="chromium"&&"currentCSSZoom"in Element.prototype?16:0,this.pixelRatio=Math.min(8,this.pixelRatioLimit)}addLogListeners(){let e=ru;W.addListener(e.DEBUG,t=>{this.callback({t:"debug",content:t})}),W.addListener(e.INFO,t=>{this.callback({t:"info",content:t})}),W.addListener(e.WARN,t=>{this.callback({t:"warn",content:t})}),W.addListener(e.ERROR,t=>{this.callback({t:"error",content:t})})}callback(e){e.i=this.instanceId,this.callbackFn(e)}setReadyState(e){if(this.readyState!==e){this.readyState=e,this.viewportElement.setAttribute(jh,e);let t=this.getCurrentPageProgression();t&&this.viewportElement.setAttribute("data-vivliostyle-page-progression",t),this.callback({t:"readystatechange"})}}loadPublication(e){wt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.fragment,n=e.authorStyleSheet,r=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let s=M("loadPublication");return this.configure(e).then(()=>{let o=new $h;o.init(n,r).then(()=>{let a=Ee(pn(t),this.window.location.href);this.packageURL=[a],o.loadPubDoc(a).then(h=>{h?(this.opf=h,this.loadCmykReserveMap(o).then(()=>{this.render(i).then(()=>{s.finish(!0)})})):s.finish(!1)})})}),s.result()}loadXML(e){wt.registerStartTiming("beforeRender"),this.setReadyState("loading");let t=e.url,i=e.document,n=e.fragment,r=e.authorStyleSheet,s=e.userStyleSheet;this.cmykReserveMapUrl=e.cmykReserveMapUrl,this.viewport=null;let o=M("loadXML");return this.configure(e).then(()=>{let a=new $h;a.init(r,s).then(()=>{let h=t.map((l,u)=>({url:Ee(pn(l.url),this.window.location.href),index:u,startPage:l.startPage,skipPagesBefore:l.skipPagesBefore}));this.packageURL=h.map(l=>l.url),this.opf=new ls(a,""),this.opf.initWithChapters(h,i).then(()=>{this.loadCmykReserveMap(a).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(()=>(wt.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=_t[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"&&(yl(e.userAgentRootURL.replace(/resources\/?$/,"")),bl(e.userAgentRootURL)),typeof e.rootURL=="string"&&(yl(e.rootURL),bl(`${Di}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!==si&&(Iv(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){Ft("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=>{I(e.container,"display","none")}),this.currentPage=null,this.currentSpread=null}showSinglePage(e){e.addEventListener("hyperlink",this.hyperlinkListener,!1),e.addEventListener("replaced",this.pageReplacedListener,!1),I(e.container,"visibility","visible"),I(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=M("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?vn(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 Ls(this.window,this.fontSize,this.pixelRatio,e,t.width,t.height)}else return new Ls(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(h0,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(g){let m=g*.75;return Math.ceil(m)};var s=o;let a=Math.max(...this.pageSizes.map(g=>g.width)),h=Math.max(...this.pageSizes.map(g=>g.height)),l=o(a),u=o(h),d=l*((this.pixelRatio||1)-1)+2,p=u*((this.pixelRatio||1)-1)+2,f=`@page {size: ${l}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)}loadCmykReserveMap(e){if(!this.cmykReserveMapUrl)return this.cmykReserveMap=void 0,N(!0);let t=Ee(pn(this.cmykReserveMapUrl),Di),i=M("loadCmykReserveMap");return e.loadAsJSON(t).then(n=>{_f(n)?this.cmykReserveMap=n:(W.warn("Invalid cmykReserveMap data, ignoring"),this.cmykReserveMap=void 0),i.finish(!0)}),i.result()}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 l0(this.opf,this.viewport,this.fontMapper,this.pref,this.setPageSize.bind(this),this.cmykReserveMap),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 Xh),this.renderTask=null}resize(){if(this.needResize=!1,this.needRefresh=!1,this.sizeIsGood())return N(!0);this.setReadyState("loading"),this.cancelRenderingTask();let e=Ro().getScheduler().run(()=>bn("resize",t=>{if(!this.opf){t.finish(!1);return}this.renderTask=e,wt.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.isLastPageForNotification(this.currentPage),metadata:this.opf.metadata,docTitle:this.opf.spine[this.pagePosition.spineIndex].title};(this.currentPage.isFirstPage||this.pagePosition.pageIndex==0&&this.opf.spine[this.pagePosition.spineIndex].epage)&&(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),wt.registerEndTiming("render (resize)"),si&&xp(this.window)?Lv(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 Xh)wt.registerEndTiming("render (resize)"),W.debug(i.message);else throw i}));return N(!0)}sendLocationNotification(e,t){let i=M("sendLocationNotification"),n={t:"nav",first:e.isFirstPage,last:this.isLastPageForNotification(e),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()}isLastPageForNotification(e){if(!this.opfView||!this.pagePosition)return e.isLastPage;let t=this.opfView.spineItems[this.pagePosition.spineIndex];if(!t||!t.complete)return!1;let i=t.item.spineIndex===this.opf.spine.length-1,n=this.pagePosition.pageIndex===t.pages.length-1;return i&&n}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=M("moveTo");return i.call(this.opfView).then(r=>{let s;if(r){this.pagePosition=r.position;let o=M("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=M("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 bn("runCommand",i=>{let n=this.actions[t];n?n.call(this,e).then(()=>{this.callback({t:"done",a:t}),i.finish(!0)}):(W.error("No such action:",t),i.finish(!0))},(i,n)=>{W.error(n,"Error during action:",t),i.finish(!0)})}initEmbed(e){let t=qh(e),i=null,n=this;Lg(()=>{let r=M("commandLoop"),s=Ro().getScheduler();return n.hyperlinkListener=o=>{let a=o,h=a.href.charAt(0)==="#"||n.packageURL.some(l=>a.href.substr(0,l.length)==l);if(h){o.preventDefault();let l={t:"hyperlink",href:a.href,internal:h};s.run(()=>(n.callback(l),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=M("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=qh(r),n.kick(),!0),this.window.adapt_command=n.sendCommand}},Np=(e=>(e.FIT_INSIDE_VIEWPORT="fit inside viewport",e))(Np||{}),Xh=class Tp extends Error{constructor(){super(),c(this,"name","RenderingCanceledError"),c(this,"message","Page rendering has been canceled"),c(this,"stack"),Object.setPrototypeOf(this,Tp.prototype),this.stack=new Error().stack}};function qh(e){return typeof e=="string"?Na(e):e}var Yh=Ea;function c0(){return{autoResize:!0,fontSize:16,pageBorderWidth:1,renderAllPages:!0,pageViewMode:"autoSpread",zoom:1,fitToScreen:!1,defaultPaperSize:void 0,allowScripts:!0,pixelRatio:8}}function Zh(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 Ip=class{constructor(e,t){this.settings=e,c(this,"initialized",!1),c(this,"adaptViewer_"),c(this,"options"),c(this,"eventTarget"),c(this,"readyState"),eu(e.debug),this.adaptViewer_=new u0(e.window||window,e.viewportElement,"main",this.dispatcher.bind(this)),this.options=c0(),t&&this.setOptions(t),this.eventTarget=new Ta,Object.defineProperty(this,"readyState",{get(){return this.adaptViewer_.readyState}})}setOptions(e){let t=Object.assign({a:"configure"},Zh(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(l){if(l)return l.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 h=Object.assign({a:e?"loadXML":"loadPublication",userAgentRootURL:this.settings.userAgentRootURL,url:d0(e)||t,document:r.documentObject,fragment:r.fragment,authorStyleSheet:o,userStyleSheet:a,cmykReserveMapUrl:r.cmykReserveMapUrl},Zh(this.options));this.initialized?this.adaptViewer_.sendCommand(h):(this.initialized=!0,this.adaptViewer_.initEmbed(h))}getCurrentPageProgression(){return this.adaptViewer_.getCurrentPageProgression()}resolveNavigation(e){switch(e){case"left":return this.getCurrentPageProgression()===Yh.LTR?"previous":"next";case"right":return this.getCurrentPageProgression()===Yh.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 d0(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 Ap=(e=>(e.PREVIOUS="previous",e.NEXT="next",e.LEFT="left",e.RIGHT="right",e.FIRST="first",e.LAST="last",e.EPAGE="epage",e))(Ap||{}),p0=Np,f0=Pp;wt.forceRegisterEndTiming("load_vivliostyle");var g0=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
1853
|
<!DOCTYPE html>
|
|
1800
1854
|
<html data-vivliostyle-paginated="true">
|
|
1801
1855
|
<head>
|
|
@@ -1823,6 +1877,6 @@ span[data-viv-leader] {
|
|
|
1823
1877
|
<body onload='parent.printInstance.runInIframe(window)'>
|
|
1824
1878
|
<div id="vivliostyle-viewer-viewport"></div>
|
|
1825
1879
|
</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 m0(e,t){new g0(e,t).init()}});var w0
|
|
1880
|
+
</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 Ip({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(`
|
|
1881
|
+
`);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 m0(e,t){new g0(e,t).init()}});var w0=$p(Fp());var export_printHTML=w0.printHTML;export{export_printHTML as printHTML};
|
|
1828
1882
|
//# sourceMappingURL=index.es6.js.map
|