@vivliostyle/print 2.30.6 → 2.30.7
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 +1 -1
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.es6.js +1 -1
- package/dist/index.es6.js.map +2 -2
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -1475,7 +1475,7 @@ span[data-viv-leader] {
|
|
|
1475
1475
|
text-orientation: mixed;
|
|
1476
1476
|
white-space: pre;
|
|
1477
1477
|
}
|
|
1478
|
-
`;function ss(e,t,i,n,s){let r=F("ajax"),o=new XMLHttpRequest,a=r.suspend(o),h={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};o.open(i||"GET",e,!0),t&&(o.responseType=t),o.onreadystatechange=()=>{if(o.readyState===4){if(h.status=o.status,h.url=o.responseURL,h.statusText=o.statusText||o.status==404&&"Not Found"||"",h.status==200||h.status==0)if((!t||t==="document")&&o.responseXML&&o.responseXML.documentElement.localName!="parsererror")h.responseXML=o.responseXML,h.contentType=o.responseXML.contentType;else if((!t||t==="document")&&o.response instanceof Document)h.responseXML=o.response,h.contentType=o.response.contentType;else{let l=o.response;(!t||t==="text")&&typeof l=="string"?h.responseText=l:l?typeof l=="string"?h.responseBlob=Gl([l]):h.responseBlob=l:D.warn("Unexpected empty success response for",e);let c=o.getResponseHeader("Content-Type");c&&(h.contentType=c.replace(/(.*);.*$/,"$1"))}a.schedule(h)}};try{n?(o.setRequestHeader("Content-Type",s||"text/plain; charset=UTF-8"),o.send(n)):(/^file:|^https?:\/\/[^/]+\.githubusercontent\.com|\.(xhtml|xht|opf)$/i.test(e)?/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?o.overrideMimeType("text/html; charset=Shift_JIS"):/\.(html|htm)$/i.test(e)?o.overrideMimeType("text/html; charset=UTF-8"):/\.(xhtml|xht|xml|opf)$/i.test(e)?o.overrideMimeType("application/xml; charset=UTF-8"):/\.(txt|css)$/i.test(e)?o.overrideMimeType("text/plain; charset=UTF-8"):o.overrideMimeType("text/html; charset=UTF-8"):/^data:,(<|%3c)/i.test(e)?o.overrideMimeType("text/html; charset=UTF-8"):/^data:,/i.test(e)&&o.overrideMimeType("text/plain; charset=UTF-8"),o.send(null))}catch(l){D.warn(l,`Error fetching ${e}`),a.schedule(h)}return r.result()}function Gl(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function tp(e){let t=F("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function ip(e){return URL.createObjectURL(e)}var _r=class{constructor(e,t){this.parser=e,this.type=t,u(this,"resources",{}),u(this,"fetchers",{})}load(e,t,i){e=Ct(e);let n=this.resources[e];return typeof n<"u"?k(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=F("fetch"),s=e.endsWith("?viv-toc-box");s&&(e=e.replace("?viv-toc-box",""));let r=Ee("user-agent.xml",Kt),o=!s&&e===r;return o&&(e=`data:application/xml,${encodeURIComponent(Dl)}`),ss(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(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Ct(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new fn(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Ct(e)]}delete(e){delete this.resources[Ct(e)]}};function np(e,t){let i=e.responseText;return k(i?Pr(i):null)}function sp(){return new _r(np,"text")}function si(e,t,i){let n=new fn(()=>{let s=F("loadElement"),r=s.suspend(e),o=!1,a=h=>{o||(o=!0,r.schedule(h?h.type:"timeout"))};return e.addEventListener("load",a,!1),e.addEventListener("error",a,!1),e.addEventListener("abort",a,!1),e.namespaceURI=="http://www.w3.org/2000/svg"?(t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),setTimeout(a,300)):e.localName==="script"?setTimeout(a,3e3):t&&(e.src=t,i&&(e.alt=i)),s.result()},`loadElement ${t||e.localName}`);return n.start(),n}var Ho=0,rp=16777216,Wl=33554432,jl=50331648,Xl=67108864,op=83886080,ap=100663296,Mr=class{constructor(e){this.scope=e,u(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(){}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){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return Ho;case"User":return ap;default:return op}}getBaseSpecificity(){switch(this.flavor){case"UA":return Ho;case"User":return rp;default:return Wl}}},lp=class extends Mr{constructor(){super(null),u(this,"stack",[]),u(this,"tokenizer",null),u(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;D.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()}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){this.slave.startFuncWithSelector(e)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},$o=class extends Mr{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,u(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 $o{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new $o(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}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){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())}},Ce=[],Vn=[],pe=[],Se=[],ot=[],Qe=[],xe=[],Le=[],ue=[],Me=[],je=[],_e=[],ve=[],ri=55,oi=56,Cn=57;Ce[1]=28,Ce[36]=29,Ce[7]=29,Ce[9]=29,Ce[14]=29,Ce[18]=29,Ce[50]=29,Ce[20]=30,Ce[13]=27,Ce[0]=200,Vn[1]=46,Vn[0]=200,Qe[1]=2,Qe[36]=4,Qe[7]=6,Qe[9]=8,Qe[14]=10,Qe[18]=14,Qe[50]=42,pe[37]=11,pe[23]=12,pe[35]=56,pe[1]=1,pe[36]=3,pe[7]=5,pe[9]=7,pe[14]=9,pe[12]=13,pe[18]=55,pe[50]=58,pe[16]=41,Se[37]=11,Se[23]=12,Se[35]=56,Se[1]=1,Se[36]=3,Se[7]=5,Se[9]=7,Se[14]=9,Se[18]=55,ot[1]=2,ot[36]=4,ot[7]=6,ot[9]=8,ot[18]=14,ot[50]=42,ot[14]=10,ot[12]=13,xe[1]=15,xe[7]=16,xe[4]=17,xe[5]=18,xe[3]=19,xe[2]=20,xe[8]=21,xe[27]=57,xe[16]=22,xe[19]=23,xe[6]=24,xe[11]=25,xe[17]=26,xe[13]=48,xe[31]=47,xe[23]=54,xe[0]=44,Le[1]=31,Le[4]=32,Le[5]=32,Le[3]=33,Le[2]=34,Le[10]=40,Le[6]=38,Le[31]=36,Le[24]=36,Le[32]=35,ue[1]=45,ue[16]=37,ue[37]=37,ue[38]=37,ue[47]=37,ue[48]=37,ue[39]=37,ue[49]=37,ue[41]=37,ue[26]=37,ue[25]=37,ue[23]=37,ue[24]=37,ue[19]=37,ue[21]=37,ue[36]=37,ue[18]=37,ue[22]=37,ue[11]=39,ue[12]=43,ue[17]=49,Me[0]=200,Me[12]=50,Me[13]=51,Me[14]=50,Me[15]=51,Me[10]=50,Me[11]=51,Me[17]=53,je[0]=200,je[12]=50,je[13]=52,je[14]=50,je[15]=51,je[10]=50,je[11]=51,je[17]=53,_e[0]=200,_e[12]=50,_e[13]=51,_e[14]=50,_e[15]=51,_e[10]=50,_e[11]=51,ve[11]=0,ve[16]=0,ve[22]=1,ve[18]=1,ve[26]=2,ve[25]=2,ve[38]=3,ve[37]=3,ve[48]=3,ve[47]=3,ve[39]=3,ve[49]=3,ve[41]=3,ve[23]=4,ve[24]=4,ve[36]=5,ve[19]=5,ve[21]=5,ve[0]=6,ve[ri]=2,ve[oi]=2;var mn=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,u(this,"valStack",[]),u(this,"namespacePrefixToURI",{}),u(this,"defaultNamespaceURI",null),u(this,"propName",null),u(this,"propImportant",!1),u(this,"exprContext"),u(this,"result",null),u(this,"importReady",!1),u(this,"importURL",null),u(this,"importCondition",null),u(this,"errorBrackets",[]),u(this,"ruleStack",[]),u(this,"regionRule",!1),u(this,"pageRule",!1),u(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(G)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,s=0,r;do if(r=i[--n],e===")"&&r instanceof Ai){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 ke(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=je);let h=new ki(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,h),h.name==="var"){let l=h.values[0]instanceof ft&&h.values[0].name;(!Nt(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=je)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=je,null;if(o>1)return new qe(this.extractVals(",",n+1));let a=i[0];return a instanceof $e?a:a?new Ai(a.toString()):G}exprError(e,t){this.actions=this.propName?je:Me,D.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 h=a.shift(),l=a.shift(),c=new jc(n.getScope(),h,l);a.unshift(c)}return i.push(new V(a[0])),!0}else if(o=="("){let h=i.pop(),l=i.pop();s=new $i(n.getScope(),_s(l,h),a),e=0;continue}}if(o==10){s.isMediaName()&&(s=new Ro(n.getScope(),s,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)s=new Ot(n.getScope(),s);else if(o==-24)s=new cl(n.getScope(),s);else if(o==-Cn)s=new Gc(n.getScope(),s);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(ve[e]>ve[o]){i.push(o);break}switch(r=i.pop(),o){case 26:s=new Rr(n.getScope(),r,s);break;case ri:s=new Wc(n.getScope(),r,s);break;case oi:s=new Xc(n.getScope(),r,s);break;case 25:s=new Ar(n.getScope(),r,s);break;case 38:s=new qc(n.getScope(),r,s);break;case 37:s=new Kc(n.getScope(),r,s);break;case 48:s=new Yc(n.getScope(),r,s);break;case 47:s=new Ds(n.getScope(),r,s);break;case 39:case 49:s=new Lr(n.getScope(),r,s);break;case 41:s=new Zc(n.getScope(),r,s);break;case 23:s=new dl(n.getScope(),r,s);break;case 24:s=new pl(n.getScope(),r,s);break;case 36:s=new Fr(n.getScope(),r,s);break;case 19:s=new fl(n.getScope(),r,s);break;case 21:s=new gl(n.getScope(),r,s);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),s=new ed(n.getScope(),i.pop(),r,s);break;case 10:if(r.isMediaName())s=new Ro(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 c=i.nthToken(1),p=i.nthToken(2);if(c.type===1&&p.type===18)i.consume(),i.consume(),s=c.text,n=p.position+1;else{if(c.type===10||c.type===6||c.type===1&&c.text.toLowerCase()==="not"&&(p.type===10||p.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 h=o.position,l=t&&s==="selector"&&a>0?"":i.input.substring(n,h).trim();return new td(this.handler.getScope(),s,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 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=lt(i,t,new Ot(i,new ze(i,"pref-horizontal")));break;case"horizontal":t=lt(i,t,new ze(i,"pref-horizontal"));break;case"day":t=lt(i,t,new Ot(i,new ze(i,"pref-night-mode")));break;case"night":t=lt(i,t,new ze(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new V(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":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,h=this.valStack,l,c,p,d,f,g,m,y=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),s&&y===null&&(y=l.position-1,a.input[y]==="("&&y++),this.actions===xe&&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 Ai(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=je):(this.actions=Qe,o.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=xe,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=je,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=xe,h.splice(0,h.length);continue;case 29:this.actions=Qe,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(),p=this.namespacePrefixToURI[l.text],p!=null)switch(l=a.token(),l.type){case 1:o.tagSelector(p,l.text),s?this.actions=Se:this.actions=pe,a.consume();break;case 36:o.tagSelector(p,null),s?this.actions=Se:this.actions=pe,a.consume();break;default:this.actions=Me,o.error("E_CSS_NAMESPACE",l)}else this.actions=Me,o.error("E_CSS_UNDECLARED_PREFIX",l);else o.tagSelector(this.defaultNamespaceURI,l.text),s?this.actions=Se:this.actions=pe,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),s?this.actions=Se:this.actions=pe,a.consume();break;case 36:o.tagSelector(null,null),s?this.actions=Se:this.actions=pe,a.consume();break;default:this.actions=Me,o.error("E_CSS_NAMESPACE",l)}else o.tagSelector(this.defaultNamespaceURI,null),s?this.actions=Se:this.actions=pe,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),s?this.actions=Se:this.actions=pe,a.consume();continue;case 7:l.precededBySpace&&o.descendantSelector();case 8:o.classSelector(l.text),s?this.actions=Se:this.actions=pe,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(),s?this.actions=Se:this.actions=pe;continue;case 6:switch(d=l.text,a.consume(),d){case"is":case"not":case"where":case"has":this.actions=Qe,o.startFuncWithSelector(d),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,d==="has")?this.actions=pe:this.actions=_e;continue;case"lang":case"href-epub-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),d==="href-epub-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)break;break e;default:m=this.readPseudoParams()}if(l=a.token(),l.type==11){o.pseudoclassSelector(d,m),a.consume(),s?this.actions=Se:this.actions=pe;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Me;continue;case 58:l.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:o.pseudoelementSelector(l.text,null),s?this.actions=Se:this.actions=pe,a.consume();continue;case 6:if(d=l.text,a.consume(),d=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){o.pseudoelementSelector(d,m),s?this.actions=Se:this.actions=pe,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Me;continue;case 9:l.precededBySpace&&o.descendantSelector();case 10:if(a.consume(),l=a.token(),l.type==1)d=l.text,a.consume();else if(l.type==36)d=null,a.consume();else if(l.type==34)d="";else{this.actions=_e,o.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(p=d&&this.namespacePrefixToURI[d],p===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}d=l.text,a.consume(),l=a.token()}else p="";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(p,d,0,null),s?this.actions=Se:this.actions=pe,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(p,d,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}s?this.actions=Se:this.actions=pe,a.consume();continue;case 11:o.childSelector(),this.actions=ot,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=ot,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=ot,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=Ce,a.consume();continue;case 41:o.nextSelector(),this.actions=Qe,a.consume();continue;case 15:h.push(B(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new El(l.text)),a.consume();continue;case 17:h.push(new ei(l.num)),a.consume();continue;case 18:h.push(new Jt(l.num)),a.consume();continue;case 19:h.push(new T(l.num,l.text)),a.consume();continue;case 20:h.push(new Ae(l.text)),a.consume();continue;case 21:h.push(new ct(Ee(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new kl(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(es),a.consume();continue;case 24:d=l.text.toLowerCase(),d=="-epubx-expr"||d=="env"?(this.actions=Le,this.exprContext=0,h.push("{")):(h.push(d),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(),c=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(c.type==17||c.type==0||c.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(c=a.nthToken(1),c.type){case 4:case 3:case 5:if(!c.precededBySpace){a.consume();continue}}h.push(new Ai("+")),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?Vn:Ce;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(c=a.nthToken(1),c.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,c.text,"("),a.consume()):(h.push(new ze(o.getScope(),_s(l.text,c.text))),this.actions=ue),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new Io(o.getScope(),!0,c.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=c),h.push(new Io(o.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==ri&&h[h.length-1]!==oi&&(c.type===10||c.type===6)){h.push(-Cn),a.consume();continue}else h.push(new ze(o.getScope(),l.text));this.actions=ue}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=ue;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new Fe(o.getScope(),l.num)),a.consume(),this.actions=ue;continue;case 33:d=l.text,d=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?d="vh":d="vw"),h.push(new Zt(o.getScope(),l.num,d)),a.consume(),this.actions=ue;continue;case 34:h.push(new Fe(o.getScope(),l.text)),a.consume(),this.actions=ue;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new yl(o.getScope(),l.num)),a.consume(),this.actions=ue);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Le,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==oi&&h[h.length-2]!==-Cn?(this.actions=Le,this.exprStackReduce(ri,l),h.push(ri),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==ri&&h[h.length-2]!==-Cn?(this.actions=Le,this.exprStackReduce(oi,l),h.push(oi),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=xe),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=Ce)),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=Ce,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=Ce,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let b=this.readSupportsTest(l);if(b){h.push(b),this.actions=ue;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=Ce,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(d=l.text.toLowerCase(),d){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=Le,h.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Me;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(d=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[d]=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=Me;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){d=l.text.toLowerCase(),d!="utf-8"&&d!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${d}`,l),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",l),this.actions=Me;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(),d){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(d),o.startRuleBody();continue}break;case"-adapt-footnote-area":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){d=l.text,a.consume(),a.consume(),o.startFootnoteRule(d),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=Qe;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=ot;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(),l=a.token(),l.type==12){a.consume(),o.startPageMarginBoxRule(d),this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Le,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Le,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Le,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(d),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,w=null,S=[];for(l.type==1&&(b=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(w=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;)S.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),d){case"-epubx-page-master":o.startPageMasterRule(b,w,S);break;case"-epubx-partition":o.startPartitionRule(b,w,S);break;case"-epubx-partition-group":o.startPartitionGroupRule(b,w,S);break}this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${d}`,l),this.actions=_e;continue;default:o.error(`E_CSS_AT_UNKNOWN ${d}`,l),this.actions=Me;continue}o.error(`E_CSS_AT_SYNTAX ${d}`,l),this.actions=Me;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ce;continue}case 51:if(s&&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=Ce),a.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Ce),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(s){switch(l.type){case 16:case 11:if(this.actions===Qe)o.error("E_CSS_SYNTAX",l);else{let b=a.input.substring(y,l.position);o.pushSelectorText(b),y=l.position+1}if(l.type===16){o.nextSelector(),this.actions=Qe,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(r){this.actions=pe;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!==Me&&this.actions!==_e&&this.actions!==je){if(l.type==54)o.error("E_CSS_SYNTAX",l);else if(this.actions===xe){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Ai(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Le&&h.length>0){o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ce,a.consume();continue}else{if(l.type===17&&this.actions==Le)return this.actions=Ce,a.consume(),!1;o.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=je:this.actions=_e;continue}a.consume();continue}}return!1}},ql=class extends Mr{constructor(e){super(null),this.scope=e}error(e,t){D.warn(e,t.toString())}getScope(){return this.scope}};function hp(e,t,i,n,s){let r=F("parseStylesheet"),o=new mn(Ce,e,t,i),a=null;return s&&(a=cp(new gt(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 l=Ee(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let c=F("parseStylesheet.import");return Yl(l,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,c.finish(!0)}),c.result()}let h=r.timeSlice();if(h.isPending)return h}return k(!1)}).then(()=>{a&&t.endRule(),r.finish(!0)}),r.result()}function zr(e,t,i,n,s){return vi("parseStylesheetFromText",r=>{let o=new gt(e,t);hp(o,t,i,n,s).thenFinish(r)},(r,o)=>{D.warn(o,`Failed to parse stylesheet text: ${e}`),r.finish(!1)})}function Yl(e,t,i,n){return vi("parseStylesheetFromURL",s=>{ss(e).then(r=>{r.responseText?zr(r.responseText,t,e,i,n).then(o=>{o||D.warn(`Failed to parse stylesheet from ${e}`),s.finish(!0)}):s.finish(!0)})},(s,r)=>{D.warn(r,"Exception while fetching and parsing:",e),s.finish(!0)})}function Ti(e,t,i){let n=new mn(xe,t,new ql(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function up(e,t,i){new mn(Vn,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function cp(e,t,i){let n=new mn(Le,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var dp={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function pp(e){return!!dp[e]}function fp(e,t,i){let n=t.evaluate(e);switch(typeof n){case"number":return pp(i)?n==Math.round(n)?new Jt(n):new ei(n):new T(n,"px");case"string":return n?Ti(t.scope,new gt(n,null),""):G;case"boolean":return n?v._true:v._false;case"undefined":return G}throw new Error("E_UNEXPECTED")}function Kl(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 h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function Zl(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 Jl={"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"}]}},gp=Kl(Jl,!0);function Ql(e,t,i){return Zl(e,t,i||null,gp)}var mp=Kl(Jl,!1);function eh(e,t,i){return Zl(e,t,i||null,mp)}var wp={"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 bp(e,t){let i=wp[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 Dr(e,t,i){let n={display:t.style.display,position:t.style.position,width:t.style.width,maxWidth:t.style.maxWidth,minWidth:t.style.minWidth,height:t.style.height,maxHeight:t.style.maxHeight,minHeight:t.style.minHeight},s=t.ownerDocument,r=t.parentNode,o=s.createElement("div");N(o,"position",n.position),r.insertBefore(o,t),o.appendChild(t),N(t,"width","auto"),N(t,"max-width","none"),N(t,"min-width","0"),N(t,"height","auto"),N(t,"max-height","none"),N(t,"min-height","0");function a(R){return e.getElementComputedStyle(t).getPropertyValue(R)}let h=Ka("writing-mode"),l=(h?a(h[0]):null)||a("writing-mode"),c=l==="vertical-rl"||l==="tb-rl"||l==="vertical-lr"||l==="tb-lr",p=c?"height":"width",d=c?"width":"height";function f(){return N(t,"display","block"),N(t,"position","static"),a(p)}function g(){N(t,"display","inline-block"),N(o,p,"99999999px");let R=a(p);return N(o,p,""),R}function m(){N(t,"display","inline-block"),N(o,p,"0");let R=a(p);return N(o,p,""),R}function y(){let R=f(),L=m(),_=parseFloat(R);if(_<=parseFloat(L))return L;{let U=g();return _<=parseFloat(U)?R:U}}function b(){return a(d)}function w(){throw new Error("Getting fill-available block size is not implemented")}let S={};return i.forEach(R=>{var L;let _;switch(R){case"fill-available inline size":_=f();break;case"max-content inline size":_=g();break;case"min-content inline size":_=m();break;case"fit-content inline size":_=y();break;case"fill-available block size":_=w();break;case"max-content block size":case"min-content block size":case"fit-content block size":_=b();break;case"fill-available width":_=c?w():f();break;case"fill-available height":_=c?f():w();break;case"max-content width":_=c?b():g();break;case"max-content height":_=c?g():b();break;case"min-content width":_=c?b():m();break;case"min-content height":_=c?m():b();break;case"fit-content width":_=c?b():y();break;case"fit-content height":_=c?y():b();break}_==="0px"&&t.childNodes.length===1&&((L=t.firstElementChild)==null?void 0:L.localName)==="img"&&!t.firstElementChild.complete&&(_="1px"),S[R]=parseFloat(_),N(t,"position",n.position),N(t,"display",n.display)}),N(t,"width",n.width),N(t,"max-width",n.maxWidth),N(t,"min-width",n.minWidth),N(t,"height",n.height),N(t,"max-height",n.maxHeight),N(t,"min-height",n.minHeight),r.insertBefore(t,o),r.removeChild(o),S}function _i(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 th(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function ih(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function it(e,t){let i=th(e);i.includes(t)||(i.push(t),ih(e,i))}function yp(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function vp(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Ps(e,t){let i=yp(e);i.includes(t)||(i.push(t),vp(e,i))}function xp(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 Xs={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ke(e){return!!Xs[e]}var Sp={left:!0,right:!0,recto:!0,verso:!0};function tn(e){return!!Sp[e]}var Cp={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Un(e){return!!Cp[e]}function Xe(e,t){if(e)if(t){if(tn(t))return t;if(tn(e))return e;{let i=Ke(e),n=Ke(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:Un(t)?t:Un(e)?e:t}}else return e;else return t}function Go(e){return Ke(e)?e:"auto"}ht("SIMPLE_PROPERTY",xp);var Wi=bc(vc());function Ep(e,t){return(0,Wi.default)(e,t,0)}function Wo(e){return e.reduce((t,i)=>i[0]===Wi.default.DELETE?t:t+i[1],"")}function kp(e,t){return nh(e,t,1)}function Np(e,t){return nh(e,t,-1)}function nh(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 Wi.default.INSERT:n++;break;case Wi.default.DELETE:n--,s++;break;case Wi.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var qs;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(qs||(qs={}));var fi;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(fi||(fi={}));var Hn;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Hn||(Hn={}));var Xt;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||_t.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||_t.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(Xt||(Xt={}));var _t;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(_t||(_t={}));var Pt;(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={}))})(Pt||(Pt={}));var Pp={transform:!0,"transform-origin":!0},Tp={top:!0,bottom:!0,left:!0,right:!0},Vr=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},Ip={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 Rp(e,t){let i=Ip[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Ys=class Mi extends Tr{constructor(t,i){super(),this.container=t,this.bleedBox=i,u(this,"pageAreaElement",null),u(this,"delayedItems",[]),u(this,"hrefHandler"),u(this,"elementsById",{}),u(this,"dimensions",{width:0,height:0}),u(this,"isFirstPage",!1),u(this,"isLastPage",!1),u(this,"isBlankPage",!1),u(this,"isAutoPageWidth",!0),u(this,"isAutoPageHeight",!0),u(this,"spineIndex",0),u(this,"position",null),u(this,"offset",-1),u(this,"side",null),u(this,"fetchers",[]),u(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),u(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(Mi.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Mi.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Mi.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Mi.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||N(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],h=this.elementsById[o.observer];if(a&&h){let l=Rp(a,o.action);if(l)for(let c=0;c<h.length;c++)h[c].addEventListener(o.event,l,!1)}}}};u(Ys,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),u(Ys,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var sh=Ys,xi="data-adapt-spec",Ze=Pt.Whitespace;function rh(e){switch(e){case"normal":case"nowrap":return Ze.IGNORE;case"pre-line":return Ze.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return Ze.PRESERVE;default:return null}}function Ue(e,t){if(!e)return!0;if(e.nodeType==1)return!1;let i=e.textContent;switch(t){case Ze.PRESERVE:return i.length==0;case Ze.NEWLINE:return!!i.match(/^[ \t]*$/);case Ze.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var Ap=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,u(this,"forcedBreakOffsets",[]),u(this,"formattingContext",null)}},Lp=class{constructor(e,t,i,n,s,r,o,a,h){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=h,u(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function Fp(e,t){return e.top-t.top}function Op(e,t){return t.right-e.right}function oh(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===Pt.ShadowType.ROOTLESS&&t.shadowType===Pt.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Zs(e.shadowContext,t.shadowContext)&&Zs(e.nodeShadow,t.nodeShadow)&&oh(e.shadowSibling,t.shadowSibling)}function Mt(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(!oh(e.steps[i],t.steps[i]))return!1;return!0}function Bp(e){return{steps:[{node:e,shadowType:rt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function $n(e,t){return{steps:[{node:e.sourceNode,shadowType:rt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function Gn(e,t){let i=new zi(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?Gn(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var rt=Pt.ShadowType,Ks=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,u(this,"subShadow",null),s&&(s.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&Zs(this.parentShadow,e.parentShadow):!1}};function Zs(e,t){return e===t||!!e&&!!t&&e.equals(t)}var _p=class{constructor(e,t){this.outer=e,this.count=t}},zi=class ah{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,u(this,"offsetInNode",0),u(this,"after",!1),u(this,"shadowType"),u(this,"shadowContext"),u(this,"nodeShadow",null),u(this,"shadowSibling",null),u(this,"shared",!1),u(this,"inline",!0),u(this,"overflow",!1),u(this,"breakPenalty"),u(this,"display",null),u(this,"floatReference"),u(this,"floatSide",null),u(this,"clearSide",null),u(this,"floatMinWrapBlock",null),u(this,"columnSpan",null),u(this,"verticalAlign","baseline"),u(this,"captionSide","top"),u(this,"inlineBorderSpacing",0),u(this,"blockBorderSpacing",0),u(this,"flexContainer",!1),u(this,"whitespace"),u(this,"hyphenateCharacter"),u(this,"breakWord"),u(this,"establishesBFC",!1),u(this,"containingBlockForAbsolute",!1),u(this,"breakBefore",null),u(this,"breakAfter",null),u(this,"viewNode",null),u(this,"clearSpacer",null),u(this,"inheritedProps"),u(this,"vertical"),u(this,"direction"),u(this,"firstPseudo"),u(this,"lang",null),u(this,"preprocessedTextContent",null),u(this,"formattingContext"),u(this,"repeatOnBreak",null),u(this,"pluginProps",{}),u(this,"fragmentIndex",1),u(this,"afterIfContinues",null),u(this,"footnotePolicy",null),u(this,"pageType"),this.shadowType=rt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=fi.FloatReference.INLINE,this.whitespace=i?i.whitespace:Ze.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=fi.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:Ze.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 ah(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(){return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:this.fragmentIndex}}toNodePosition(){var t,i,n;let s=this,r=[];s.shadowType===Pt.ShadowType.ROOTLESS&&(s.floatReference!==fi.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?Np(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}},zt=class lh{constructor(t){this.primary=t,u(this,"floats",null)}clone(){let t=new lh(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(!Mt(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(!Mt(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},Mp=class hh{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new hh(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},zp=class uh{constructor(){u(this,"positions",[]),u(this,"startBreakType",null),u(this,"breakAfter",null)}clone(){let t=new uh,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}},Dp=class ch{constructor(){u(this,"page",0),u(this,"flows",{}),u(this,"flowPositions",{}),u(this,"isBlankPage",!1),u(this,"highestSeenOffset",0),u(this,"highestSeenNode"),u(this,"lookupPositionOffset")}clone(){let t=new ch;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&&tn(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},dh=class{constructor(e){this.element=e,u(this,"left",0),u(this,"top",0),u(this,"marginLeft",0),u(this,"marginRight",0),u(this,"marginTop",0),u(this,"marginBottom",0),u(this,"borderLeft",0),u(this,"borderRight",0),u(this,"borderTop",0),u(this,"borderBottom",0),u(this,"paddingLeft",0),u(this,"paddingRight",0),u(this,"paddingTop",0),u(this,"paddingBottom",0),u(this,"width",0),u(this,"height",0),u(this,"originX",0),u(this,"originY",0),u(this,"exclusions",null),u(this,"innerShape",null),u(this,"computedBlockSize",0),u(this,"snapWidth",0),u(this,"snapHeight",0),u(this,"snapOffsetX",0),u(this,"snapOffsetY",0),u(this,"vertical",!1),u(this,"rtl",!1)}getInsetTop(){return this.marginTop+this.borderTop+this.paddingTop}getInsetBottom(){return this.marginBottom+this.borderBottom+this.paddingBottom}getInsetLeft(){return this.marginLeft+this.borderLeft+this.paddingLeft}getInsetRight(){return this.marginRight+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}setVerticalPosition(e,t){this.top=e,this.height=t,N(this.element,"top",`${e}px`),N(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,N(this.element,"left",`${e}px`),N(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+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.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.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):Br(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 nt(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 nt(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return Al(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 nt(e,t,e+i,t+n)}},Wn=class extends It{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.url)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=Ti(t.scope,new gt(i,null),"").stringValue()),this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof De&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Dt(e){return e!=null&&e!==G&&e!==v.normal&&e!==v.none&&!J(e)}var Re=fi.FloatReference;function Vp(e){switch(e){case"inline":return Re.INLINE;case"column":return Re.COLUMN;case"region":return Re.REGION;case"page":return Re.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function gi(e){switch(e){case Re.INLINE:return!1;case Re.COLUMN:case Re.REGION:case Re.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function Up(e,t,i){let n=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=eh(e,n,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let s=Ql(e,n,i),r=bp(s,n);r==="line-left"?e="left":r==="line-right"&&(e="right")}return e!=="left"&&e!=="right"&&(D.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var ph=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,u(this,"order",null),u(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}},Hp=class{constructor(){u(this,"floats",[]),u(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>Mt(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=>Mt(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}},fh=class{constructor(e,t,i,n,s){this.floatReference=e,this.floatSide=t,this.continuations=i,this.area=n,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}},jo=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&Mt(this.nodePosition,e.nodePosition):!1}},Di=class{constructor(e,t,i,n,s,r,o){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=s,u(this,"children",[]),u(this,"writingMode"),u(this,"direction"),u(this,"invalidated",!1),u(this,"floatStore"),u(this,"forbiddenFloats",[]),u(this,"floatFragments",[]),u(this,"stashedFloatFragments",[]),u(this,"floatAnchors",{}),u(this,"floatsDeferredToNext",[]),u(this,"floatsDeferredFromPrevious"),u(this,"layoutConstraints",[]),u(this,"locked",!1),e&&e.children.push(this),this.writingMode=r||e&&e.writingMode||v.horizontal_tb,this.direction=o||e&&e.direction||v.ltr,this.floatStore=e?e.floatStore:new Hp;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&&Mt(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 Si().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===Re.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();return eh(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Ql(e,t,i)}removeEndFloatFragments(e){let t=this.toLogical(e);if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogical(n.floatSide)===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogical(e.floatSide);if(i==="block-end"||i==="snap-block"||i==="inline-end"){let n=0;for(;n<this.floatFragments.length;){let s=this.floatFragments[n],r=this.toLogical(s.floatSide);(r===i||i==="snap-block"&&r==="block-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){this.container;let s=this.toLogical(e),r=this.toPhysical(e),o=this.getLimitValueInner(s,t,i,n);if(this.parent&&this.parent.container){let a=this.parent.getLimitValue(r,t,i,n);switch(r){case"top":return Math.max(o,a);case"left":return Math.max(o,a);case"bottom":return Math.min(o,a);case"right":return Math.min(o,a);default:}}return o}getLimitValueInner(e,t,i,n){this.container;let s=this.getLimitValuesInner(t,i,n);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){this.container;let n=this.container.originX,s=this.container.originY,r=this.container.getPaddingRect(),o={top:r.y1-s,left:r.x1-n,bottom:r.y2-s,right:r.x2-n,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};function a(l,c,p){return l.unit==="%"?p*l.num/100:e.convertLengthToPx(l,c,t)}let h=this.floatFragments;return h.length>0&&(o=h.reduce((l,c)=>{if(i&&!i(c,this))return l;let p=this.toLogical(c.floatSide),d=c.area,f=c.continuations[0].float.floatMinWrapBlock,g=l.top,m=l.left,y=l.bottom,b=l.right,w=l.floatMinWrapBlockStart,S=l.floatMinWrapBlockEnd;switch(p){case"inline-start":d.vertical?g=Math.max(g,d.top+d.height):m=Math.max(m,d.left+d.width);break;case"block-start":d.vertical?(f&&d.left<b&&(w=a(f,d.rootViewNodes[0],r.x2-r.x1)),b=Math.min(b,d.left)):(f&&d.top+d.height>g&&(w=a(f,d.rootViewNodes[0],r.y2-r.y1)),g=Math.max(g,d.top+d.height));break;case"inline-end":d.vertical?y=Math.min(y,d.top):b=Math.min(b,d.left);break;case"block-end":d.vertical?(f&&d.left+d.width>m&&(S=a(f,d.rootViewNodes[0],r.x2-r.x1)),m=Math.max(m,d.left+d.width)):(f&&d.top<y&&(S=a(f,d.rootViewNodes[0],r.y2-r.y1)),y=Math.min(y,d.top));break;default:throw new Error(`Unknown logical float side: ${p}`)}return{top:g,left:m,bottom:y,right:b,floatMinWrapBlockStart:w,floatMinWrapBlockEnd:S}},o)),o.left+=n,o.right+=n,o.top+=s,o.bottom+=s,o}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.toLogical(i);if(a==="snap-block"){if(!o["block-start"]&&!o["block-end"])return null}else if(!o[a])return null;e.clientLayout;let h=this.getLimitValue("block-start",e.layoutContext,e.clientLayout),l=this.getLimitValue("block-end",e.layoutContext,e.clientLayout),c=this.getLimitValue("inline-start",e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-end",e.layoutContext,e.clientLayout),d=e.vertical?e.originX:e.originY,f=e.vertical?e.originY:e.originX;h=e.vertical?Math.min(h,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+d):Math.max(h,e.top+d),l=e.vertical?Math.max(l,e.left+d):Math.min(l,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+d);function g(S,R){let L=S(e.bands,R);return L?(e.vertical&&(L=Tl(L)),h=e.vertical?Math.min(h,L.x2):Math.max(h,L.y1),l=e.vertical?Math.max(l,L.x1):Math.min(l,L.y2),!0):r}let m,y,b,w;if(s){let S=e.vertical?Dn(new nt(l,c,h,p)):new nt(c,h,p,l);if((a==="block-start"||a==="snap-block"||a==="inline-start")&&!g(cd,S)||(a==="block-end"||a==="snap-block"||a==="inline-end")&&!g(dd,S)||(b=(l-h)*e.getBoxDir(),m=b-e.getInsetBefore()-e.getInsetAfter(),w=(p-c)*e.getInlineDir(),y=w-e.getInsetStart()-e.getInsetEnd(),!r&&(m<=0||y<=0)))return null}else{m=e.computedBlockSize,b=m+e.getInsetBefore()+e.getInsetAfter();let S=(l-h)*e.getBoxDir();if(a==="snap-block"){if(n===null)a="block-start";else{let L=this.container.getPaddingRect(),_=this.container.getBoxDir()*(n-(this.container.vertical?L.x2:L.y1)),U=this.container.getBoxDir()*((this.container.vertical?L.x1:L.y2)-n-b);_<=U?a="block-start":a="block-end"}if(!o[a])if(o["block-end"])a="block-end";else return null}if(!r&&S<b)return null;a==="inline-start"||a==="inline-end"?y=Dr(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?y=e.getContentInlineSize():y=e.vertical?e.height:e.width,w=y+e.getInsetStart()+e.getInsetEnd();let R=(p-c)*e.getInlineDir();if(!r&&R<w)return null}switch(h-=d,l-=d,c-=f,p-=f,a){case"inline-start":case"block-start":case"snap-block":e.setInlinePosition(c,y),e.setBlockPosition(h,m);break;case"inline-end":case"block-end":e.setInlinePosition(p-w*e.getInlineDir(),y),e.setBlockPosition(l-b*e.getBoxDir(),m);break;default:throw new Error(`unknown float direction: ${i}`)}return a}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 l=>h.isAnchorAlreadyAppeared(l.float.getId())}function n(h,l){return h.continuations.some(i(l))}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}t.clientLayout;let a=this.getLimitValue("block-start",t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",t.layoutContext,t.clientLayout,n)*t.getBoxDir()<r*t.getBoxDir()?r:a}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.toLogical(t),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 h(p){return d=>d.floatSide===p&&d.getOrder()<a}function l(p,d){return p.children.some(f=>f.floatFragments.some(h(d))||l(f,d))}function c(p,d){let f=p.parent;return!!f&&(f.floatFragments.some(h(d))||c(f,d))}return o.forEach(p=>{switch(p){case"block-start":case"inline-start":n[p]=!l(this,p);break;case"block-end":case"inline-end":n[p]=!c(this,p);break;default:throw new Error(`Unexpected side: ${p}`)}}),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}},Li=[],Si=class{static register(e){Li.push(e)}findByNodeContext(e){for(let t=Li.length-1;t>=0;t--){let i=Li[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=Li.length-1;t>=0;t--){let i=Li[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},$p=class{appliesToNodeContext(e){return gi(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 ph(r,n,s,e.clearSide,t.flowName,e.floatMinWrapBlock);return t.addPageFloat(a),k(a)})}createPageFloatFragment(e,t,i,n){let s=e[0].float;return new fh(s.floatReference,t,e,i,n)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){}forbid(e,t){}};Si.register(new $p);var Gp=fh,Js=class gh extends ph{constructor(t,i,n,s,r){super(t,i,"block-end",null,n,r),this.footnotePolicy=s}isAllowedToPrecede(t){return!(t instanceof gh)}},Xo=class extends Gp{constructor(e,t,i,n){super(e,"block-end",t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof Js?!0:this.getOrder()<e.getOrder()}},Wp=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!Mt(t,this.footnote.nodePosition)}},jp=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof Js}createPageFloat(e,t,i){let n=Re.REGION,s=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Re.PAGE).hasSameContainerAs(s)&&(n=Re.PAGE);let r=e.toNodePosition();t.flowName;let o=new Js(r,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);return t.addPageFloat(o),k(o)}createPageFloatFragment(e,t,i,n){let s=e[0].float;return new Xo(s.floatReference,e,i,n)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof Xo);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 v.line:{let n=new Wp(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Si.register(new jp);var Xp="data-vivliostyle-flow-root";function qp(e){return e.getAttribute(Xp)==="true"}function qo(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 B(i)}function Ur(e){return e===v.absolute||e===v.fixed}function Yo(e){return e instanceof ki&&e.name==="running"}function mh(e,t,i,n){return e===v.none||(Ur(t)?(i=v.none,e=qo(e)):(i&&i!==v.none&&!J(i)||n)&&(e=qo(e))),{display:e,position:t,float:i}}function wh(e,t,i,n){return mh(e,t,i,n).display===v.block}function jt(e){switch(e.toString()){case"inline":case"inline-block":case"inline-list-item":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return!1}}function bh(e){switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function Yp(e,t,i,n,s,r,o){return s=s||r||v.horizontal_tb,!!o||!!i&&i!==v.none&&!J(i)||Ur(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)||!!r&&s!==r}function Kp(e){return e===v.relative||e===v.absolute||e===v.fixed}function ai(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(o&&jt(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,h=r.nextSibling;a.removeChild(r),a.insertBefore(r,h)}let o=t.getElementClientRect(r);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(),h=s.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(s,i),a.setEnd(s,i+1);let l=t.getRangeClientRects(a);return l=l.filter(c=>c.right>c.left&&c.bottom>c.top),l.length?(n?o=Math.min.apply(null,l.map(c=>c.left)):o=Math.max.apply(null,l.map(c=>c.bottom)),o):NaN}}function Qs(e,t,i){let n=t.clientLayout.getElementClientRect(e),s=t.getComputedMargin(e);return i?n.width+s.left+s.right:n.height+s.top+s.bottom}function hi(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function yh(e,t){if(e)for(let i=e.lastChild,n=i;i!==t;i=n)n=i.previousSibling,!(i.nodeType===1&&i.hasAttribute("data-vivliostyle-float-box"))&&e.removeChild(i)}function Hr(e){return!!e.getAttribute(xi)}function vh(e){var t;if(e?.nodeType!==1)return!1;let i=e;if(Hr(i))return!0;let n=(t=i.style)==null?void 0:t.position;return n==="absolute"||n==="fixed"}function ui(e){let t=e?.viewNode;return t?.nodeType===1&&Hr(t)}function Zp(e){return e!=="inline"&&(jt(e)||bh(e))}function Ko(e){for(let t=e.parent;t;t=t.parent)if(t.display!=="inline"&&jt(t.display))return t;return null}var $r=class{calculateOffset(e){return mi(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function mi(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var rs=class extends $r{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,u(this,"overflowIfRepetitiveElementsDropped"),u(this,"isEdgeUpdated",!1),u(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(Un(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=ai(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 h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===s&&!r)&&(o+=e.parseComputedLength(l.paddingBlockEnd)),h===s&&!r&&(o+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),r?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===s)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===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(!Xt.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Fi=class{find(e){let t=pt("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()}`)}},ci=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 rs(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===Pt.ShadowType.ROOTLESS&&ui(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;yh(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),k(!0)}},Gr=class{constructor(e){this.parent=e,u(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},Wr=new ci,Jp=qs.isInstanceOfBlockFormattingContext;ht("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&&wh(i,n,s,r)?new Gr(o?o.formattingContext:null):null});ht("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Gr?Wr:null);var jr=class{constructor(){u(this,"initialBreakPositions",null),u(this,"initialStateOfFormattingContext",null),u(this,"initialPosition"),u(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=F("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)}},Qp=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){}},er=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=F("LayoutIterator");return n.loopWithFrame(s=>{let r;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Ue(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:k(!0)).thenAsync(()=>i.break?k(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()}},ji=class extends Qp{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&&Ke(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=Xe(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:k(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),k(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:k(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=Xe(e.breakAtTheEdge,e.nodeContext.breakAfter)),k(!0)))}},tr=[];function ef(){tr=[]}function xh(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var tf=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},nf=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Sh=class An{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let s=An.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){An.fragmentIndices={}}matches(){let t=An.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&xh(t.fragmentIndex,this.a,this.b)}};u(Sh,"fragmentIndices",{});var os=Sh,En=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new os(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new nf(e)}static buildAnyMatcher(e){return new tf(e)}},Ch={"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-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-size-adjust":!0,"text-spacing-trim":!0,"text-stroke-color":!0,"text-stroke-width":!0,"text-transform":!0,"text-underline-position":!0,visibility:!0,"white-space":!0,widows:!0,"word-break":!0,"word-spacing":!0,"writing-mode":!0},sf=["image-resolution","orphans","widows"];function rf(){return pt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(sf))}var of={"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},ir=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],af=["max-%","min-%","%"],lf=(()=>{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<ir.length;i++)for(let n=0;n<e.length;n++){let s=ir[i].replace("%",e[n]);t[s]=!0}return t})();function as(e,t){let i={};for(let n of ir)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 af)for(let s in t){let r=n.replace("%",s),o=n.replace("%",t[s]);i[r]=o,i[o]=r}return i}var Eh=as({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),kh=as({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),hf=as({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),uf=as({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),K=class nr{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 nr(i,this.priority)}increaseSpecificity(t){return t==0?this:new nr(this.value,this.priority+t)}evaluate(t,i,n,s){return i&&Nt(i)?this.value:Xn(t,this.value,i,n,s)}isEnabled(t){return!0}},sr=class rr extends K{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new K(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new rr(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new rr(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){D.warn(i)}return!1}};function or(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Tt(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 Nh={"region-id":!0,"fragment-selector-id":!0};function cf(e){return!!Nh[e]}function ar(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function wi(e){return e.charAt(0)!=="_"&&!Nh[e]}function Xi(e){return!!Ch[e]||Nt(e)}function Ve(e,t){return e[t]}function qt(e,t,i){i?e[t]=i:delete e[t]}function dt(e,t){return e[t]}function ls(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Ph=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Th(e,t){return e[t]}function Ih(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function jn(e,t,i,n,s,r,o){var a,h;if([{id:s,styleKey:"_pseudos"},{id:r,styleKey:"_regions"}].forEach(l=>{if(l.id){let c=ls(t,l.styleKey);t=c[l.id],t||(t={},c[l.id]=t)}}),o){let l=Ph(t);t={},l.push({styles:t,matcher:o})}for(let l in i)if(!ar(l))if(cf(l)){let c=Th(i,l),p=Ih(t,l);Array.prototype.push.apply(p,c)}else{let c=Ve(i,l);if(!c.isEnabled(e))continue;let p=c.increaseSpecificity(n);Tt(t,l,p,e);let d=(h=(a=e.style)==null?void 0:a.validatorSet.shorthands[l])==null?void 0:h.propList;if(d)for(let f of d){let g=new K(G,p.priority);Tt(t,f,g,e)}}}function df(e,t){let i={};for(let n=0;n<t.length;n++)jn(e,i,t[n],0,null,null,null);return i}function Rh(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 pf=class extends Ei{constructor(e,t){super(),this.props=e,this.context=t,u(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=Ve(this.props,"font-size");if(!e.value.isNumeric())return me.em;let t=e.value;if(!Uc(t.unit))throw new Error("Unexpected state");return t.num*me[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?Ah(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="ex"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Xr(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Xn(this.context,e,this.propName).visit(this):e}};function Xr(e,t,i){let n=e.unit,s=e.num;if(n==="em"||n==="ex"){let r=me[n]/me.em;return new T(s*r*t,"px")}else return n==="rem"?new T(s*i.fontSize(),"px"):n==="rlh"?new T(s*i.rootLineHeight,"px"):e}function Ah(e,t,i){e=Xr(e,t,i);let n=e.unit,s=e.num;return n==="px"?e:n==="%"?new T(s/100*t,"px"):new T(s*i.queryUnitSize(n,!1),"px")}var Ii=class{apply(e){}mergeWith(e){return new ff([this,e])}clone(){return this}},kn=class extends Ii{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},ff=class Lh extends Ii{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 Lh([].concat(this.list))}},qr=class extends Ii{constructor(e,t,i,n,s){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=s}apply(e){jn(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},fe=class extends Ii{constructor(){super(),u(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},gf=class extends fe{constructor(e){super(),this.className=e}apply(e){e.currentClassNames.includes(this.className)&&this.chained.apply(e)}getPriority(){return 10}makePrimary(e){return this.chained&&e.insertInTable(e.classes,this.className,this.chained),!0}},mf=class extends fe{constructor(e){super(),this.id=e}apply(e){(e.currentId==this.id||e.currentXmlId==this.id)&&this.chained.apply(e)}getPriority(){return 11}makePrimary(e){return this.chained&&e.insertInTable(e.ids,this.id,this.chained),!0}},Zo=class extends fe{constructor(e){super(),this.localName=e}apply(e){e.currentLocalName==this.localName&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){return this.chained&&e.insertInTable(e.tags,this.localName,this.chained),!0}},wf=class extends fe{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}},bf=class extends fe{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+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)}}}},yf=class extends fe{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function hs(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 Jo=class extends fe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){hs(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},vf=class extends fe{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){hs(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}},xf=class extends fe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){hs(e.currentElement,this.ns,this.name,(t,i,n)=>!!of[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Oi=class extends fe{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){hs(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)}},Sf=class extends fe{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Qo=class extends fe{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},Cf=class extends fe{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},wn=class extends fe{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return xh(e,this.a,this.b)}},Ef=class extends wn{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},lr=class extends wn{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}},hr=class extends wn{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}},ur=class extends wn{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}},kf=class extends fe{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}},Nf=class extends fe{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},Pf=class extends fe{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},Tf=class extends fe{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},Ge=class extends fe{constructor(e){super(),this.condition=e}apply(e){if(e.conditions[this.condition])try{e.dependentConditions.push(this.condition),this.chained.apply(e)}finally{e.dependentConditions.pop()}}getPriority(){return 5}},If=class Fh extends Ii{constructor(){super(),u(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new Fh;return t.applied=this.applied,t}},Yr=class extends fe{constructor(e){super(),u(this,"checkAppliedAction"),u(this,"firstActions",[]),this.checkAppliedAction=new If;for(let t of e)this.firstActions.push(Rh(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 fe?e.getPriority():0))}positive(){return!0}relational(){return!1}},Rf=class extends Yr{positive(){return!1}},Af=class extends Yr{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}},us=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)}},Lf=class Oh extends us{constructor(t,i,n){super(t,i,n)}fresh(t){return new Oh(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}},Ff=class Bh extends us{constructor(t,i,n){super(t,i,n)}fresh(t){return new Bh(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)}},Of=class _h extends us{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new _h(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)}},Bf=class Mh extends us{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new Mh(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}},_f=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}},Mf=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}},zf=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}},Df=class extends Ei{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new ct(e):new ct("about:invalid");case"string":default:return e?new Ae(e):new Ae("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof ke){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 qi(e){if(Dt(e)){if(e instanceof Ae)return e.stringValue();if(e instanceof ke)return e.values.map(t=>qi(t)).join("")}return""}var cr=class extends Ei{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 Ae("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new Ae("")}return e}format(e,t){let i=!1,n=!1,s;(s=t.match(/^upper-(.*)/))!=null?(i=!0,t=s[1]):(s=t.match(/^lower-(.*)/))!=null&&(n=!0,t=s[1]);let r="";return ea[t]?r=Uf(ea[t],e):ta[t]?r=$f(ta[t],e):ia[t]!=null?r=ia[t]:t=="decimal-leading-zero"?(r=`${e}`,r.length==1&&(r=`0${r}`)):t=="cjk-ideographic"||t=="trad-chinese-informal"?r=Wf(e,Gf):r=`${e}`,i?r.toUpperCase():n?r.toLowerCase():r}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 Ae(this.format(s,i))}else{let s=new V(this.counterResolver.getPageCounterVal(t,r=>this.format(r||0,i)));return new ke([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 kt;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 V(this.counterResolver.getPageCountersVal(t,a=>{let h=[];if(a.length)for(let c=0;c<a.length;c++)h.push(this.format(a[c],n));let l=r.toString();return l.length&&h.push(l),h.length?h.join(i):this.format(0,n)}));return new ke([o])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof ct?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e.length>2?e[2].stringValue():"decimal",r=new V(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,s)));return new ke([r])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof ct?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 V(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,r));return h.length?h.join(s):this.format(0,r)}));return new ke([o])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new V(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 V(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,s,r,o;let a=e.length>0?e[0].stringValue():"text",h="";switch(a){case"text":h=this.element.textContent;break;case"before":case"after":{let l=dt(this.cascade.currentStyle,"_pseudos"),c=(i=(t=l?.[a])==null?void 0:t.content)==null?void 0:i.value;h=qi(c)}break;case"first-letter":{let l=dt(this.cascade.currentStyle,"_pseudos"),c=(qi((s=(n=l?.before)==null?void 0:n.content)==null?void 0:s.value)||this.element.textContent||qi((o=(r=l?.after)==null?void 0:r.content)==null?void 0:o.value)).match(Fs);h=c?c[0]:""}break}return new Ae(h)}visitFuncLeader(e){let t="";if(e[0]instanceof ft)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof Ae&&(t=e[0].stringValue());return t.length==0?new Ae(""):new V(new De(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"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}},Vf=(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(ce){if(S==="rtl"){let de="\u200F";g.textContent=(ce.startsWith(de)?"":de)+ce+(ce.endsWith(de)?"":de)}else g.textContent=ce},c=function(){let ce=i.clientLayout.getElementClientRect(m);return L.left>ce.left||L.right<ce.right||L.top>ce.top||L.bottom<ce.bottom},p=function(){let ce,de;if(l(b),c())ce=1,de=b.length/y.length;else{ce=b.length/y.length,de=ce;for(let x=0;x<16;x++){let P=b;for(let C=0;C<1<<x;C++)P+=y;if(l(P),c()){de+=1<<x;break}}}for(let x=0;x<16;x++){let P="",C=Math.floor((ce+de)/2);for(let E=0;E<C;E++)P+=y;if(l(P),c())de=C;else{if(ce==C)return;ce=C}}l(y)},d=function(ce){let de=0,x=m.parentElement;for(;x&&x!==f.viewNode;)de+=i.getComputedInsets(x)[ce],x=x.parentElement;return de};var s=l,r=c,o=p,a=d;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,m=g.parentElement,y=g.getAttribute("data-viv-leader-value"),b=g.textContent||y,{writingMode:w,direction:S,marginInlineEnd:R}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(y),m.style.display="inline-block",m.style.textIndent="0";let L=i.clientLayout.getElementClientRect(f.viewNode),_=i.clientLayout.getElementClientRect(m),U=i.parseComputedLength(R);w==="vertical-rl"||w==="vertical-lr"?(S==="rtl"?L.top+=U:L.bottom-=U,L.left=_.left,L.right=_.right,L.top=Math.min(_.top,L.top),L.bottom=Math.max(_.bottom,L.bottom)):(S==="rtl"?L.left+=U:L.right-=U,L.top=_.top,L.bottom=_.bottom,L.left=Math.min(_.left,L.left),L.right=Math.max(_.right,L.right)),p();let W=i.clientLayout.getElementClientRect(m);S=="rtl"?m.style.float="left":m.style.float="right";let we=i.clientLayout.getElementClientRect(m),He=0;S=="rtl"?w=="vertical-rl"||w=="vertical-lr"?He=W.top-we.top-d("top"):He=W.left-we.left-d("left"):w=="vertical-rl"||w=="vertical-lr"?He=we.bottom-W.bottom-d("bottom"):He=we.right-W.right-d("right"),He=Math.max(0,He-.1),m.style.float="",g.style.marginInlineStart=`${He}px`}};ht("POST_LAYOUT_BLOCK",Vf);var ea={roman:[4999,1e3,"M",900,"CM",500,"D",400,"CD",100,"C",90,"XC",50,"L",40,"XL",10,"X",9,"IX",5,"V",4,"IV",1,"I"],armenian:[9999,9e3,"\u0584",8e3,"\u0583",7e3,"\u0582",6e3,"\u0581",5e3,"\u0580",4e3,"\u057F",3e3,"\u057E",2e3,"\u057D",1e3,"\u057C",900,"\u057B",800,"\u057A",700,"\u0579",600,"\u0578",500,"\u0577",400,"\u0576",300,"\u0575",200,"\u0574",100,"\u0573",90,"\u0572",80,"\u0571",70,"\u0570",60,"\u056F",50,"\u056E",40,"\u056D",30,"\u056C",20,"\u056B",10,"\u056A",9,"\u0569",8,"\u0568",7,"\u0567",6,"\u0566",5,"\u0565",4,"\u0564",3,"\u0563",2,"\u0562",1,"\u0561"],georgian:[19999,1e4,"\u10F5",9e3,"\u10F0",8e3,"\u10EF",7e3,"\u10F4",6e3,"\u10EE",5e3,"\u10ED",4e3,"\u10EC",3e3,"\u10EB",2e3,"\u10EA",1e3,"\u10E9",900,"\u10E8",800,"\u10E7",700,"\u10E6",600,"\u10E5",500,"\u10E4",400,"\u10F3",300,"\u10E2",200,"\u10E1",100,"\u10E0",90,"\u10DF",80,"\u10DE",70,"\u10DD",60,"\u10F2",50,"\u10DC",40,"\u10DB",30,"\u10DA",20,"\u10D9",10,"\u10D8",9,"\u10D7",8,"\u10F1",7,"\u10D6",6,"\u10D5",5,"\u10D4",4,"\u10D3",3,"\u10D2",2,"\u10D1",1,"\u10D0"],hebrew:[999,400,"\u05EA",300,"\u05E9",200,"\u05E8",100,"\u05E7",90,"\u05E6",80,"\u05E4",70,"\u05E2",60,"\u05E1",50,"\u05E0",40,"\u05DE",30,"\u05DC",20,"\u05DB",19,"\u05D9\u05D8",18,"\u05D9\u05D7",17,"\u05D9\u05D6",16,"\u05D8\u05D6",15,"\u05D8\u05D5",10,"\u05D9",9,"\u05D8",8,"\u05D7",7,"\u05D6",6,"\u05D5",5,"\u05D4",4,"\u05D3",3,"\u05D2",2,"\u05D1",1,"\u05D0"]},ta={latin:"a-z",alpha:"a-z",greek:"\u03B1-\u03C1\u03C3-\u03C9",russian:"\u0430-\u0438\u043A-\u0449\u044D-\u044F"},ia={square:"\u25A0",disc:"\u2022",circle:"\u25E6",none:""};function Uf(e,t){let i=e[0];if(t>i||t<=0||t!=Math.round(t))return"";let n="";for(let s=1;s<e.length;s+=2){let r=e[s],o=Math.floor(t/r);if(o>20)return"";for(t-=o*r;o>0;)n+=e[s+1],o--}return n}function Hf(e){let t=[],i=0;for(;i<e.length;)if(e.substr(i+1,1)=="-"){let n=e.charCodeAt(i),s=e.charCodeAt(i+2);i+=3;for(let r=n;r<=s;r++)t.push(String.fromCharCode(r))}else t.push(e.substr(i++,1));return t}function $f(e,t){if(t<=0||t!=Math.round(t))return"";let i=Hf(e),n="";do{t--;let s=t%i.length;n=i[s]+n,t=(t-s)/i.length}while(t>0);return n}var Gf={formal:!1,digits:"\u96F6\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D",markers:"\u5341\u767E\u5343",negative:"\u8CA0"};function Wf(e,t){if(e>9999||e<-9999)return`${e}`;if(e==0)return t.digits.charAt(0);let i=new kt;if(e<0&&(i.append(t.negative),e=-e),e<10)i.append(t.digits.charAt(e));else if(!t.formal&&e<=19)i.append(t.markers.charAt(0)),e!=0&&i.append(t.digits.charAt(e-10));else{let n=Math.floor(e/1e3);n&&(i.append(t.digits.charAt(n)),i.append(t.markers.charAt(2)));let s=Math.floor(e/100)%10;s&&(i.append(t.digits.charAt(s)),i.append(t.markers.charAt(1)));let r=Math.floor(e/10)%10;r&&(i.append(t.digits.charAt(r)),i.append(t.markers.charAt(0)));let o=e%10;o&&i.append(t.digits.charAt(o))}return i.toString()}var Kr=1/1048576;function ii(e,t){for(let i in e)t[i]=e[i].clone()}var jf=class zh{constructor(){u(this,"nsCount",0),u(this,"nsPrefix",{}),u(this,"tags",{}),u(this,"nstags",{}),u(this,"epubtypes",{}),u(this,"classes",{}),u(this,"ids",{}),u(this,"pagetypes",{}),u(this,"order",0)}clone(){let t=new zh;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return ii(this.tags,t.tags),ii(this.nstags,t.nstags),ii(this.epubtypes,t.epubtypes),ii(this.classes,t.classes),ii(this.ids,t.ids),ii(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){return new Xf(this,t,i,n,s)}nextOrder(){return this.order+=Kr}},Xf=class{constructor(e,t,i,n,s){this.context=t,this.counterListener=i,this.counterResolver=n,u(this,"code"),u(this,"stack",[[],[]]),u(this,"conditions",{}),u(this,"currentElement",null),u(this,"currentElementOffset",null),u(this,"currentStyle",null),u(this,"currentClassNames",null),u(this,"currentLocalName",""),u(this,"currentNamespace",""),u(this,"currentId",""),u(this,"currentXmlId",""),u(this,"currentNSTag",""),u(this,"currentEpubTypes",null),u(this,"currentPageType",null),u(this,"previousPageType",null),u(this,"firstPageType",null),u(this,"isFirst",!0),u(this,"isRoot",!0),u(this,"counters",{}),u(this,"counterScoping",[{}]),u(this,"quotes"),u(this,"quoteDepth",0),u(this,"lang",""),u(this,"siblingOrderStack",[0]),u(this,"currentSiblingOrder",0),u(this,"siblingTypeCountsStack",[{}]),u(this,"currentSiblingTypeCounts"),u(this,"currentFollowingSiblingOrder",null),u(this,"followingSiblingOrderStack"),u(this,"followingSiblingTypeCountsStack",[{}]),u(this,"currentFollowingSiblingTypeCounts"),u(this,"viewConditions",{}),u(this,"dependentConditions",[]),u(this,"elementStack"),this.code=e,this.quotes=[new Ae("\u201C"),new Ae("\u201D"),new Ae("\u2018"),new Ae("\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=En.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]:En.buildAnyMatcher([].concat(s)):null}).filter(n=>n);return i.length<=0?t:t===null?i.length===1?i[0]:En.buildAllMatcher(i):En.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=Ts,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 h=v.inline,l=e.display;if(l&&(h=l.evaluate(this.context)),h===v.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 c=v.inline,p=e.float;p&&(c=p.evaluate(this.context));let d=null,f=null,g=null,m=e["counter-reset"];if(m){let w=m.evaluate(this.context);w&&(d=Gi(w,!0))}let y=e["counter-set"];if(y){let w=y.evaluate(this.context);w&&(g=Gi(w,!1))}let b=e["counter-increment"];if(b){let w=b.evaluate(this.context);w&&(f=Gi(w,!1))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(d||(d={}),d["list-item"]=((i=(t=this.currentElement)==null?void 0:t.start)!=null?i:1)-1),h===v.list_item&&(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:"")&&(g||(g={}),g["list-item"]=this.currentElement.value)),((o=this.currentElement)==null?void 0:o.parentNode.nodeType)===Node.DOCUMENT_NODE&&(d||(d={}),d.footnote===void 0&&(d.footnote=0)),c===v.footnote&&(f||(f={}),f.footnote===void 0)){let w=(a=this.currentStyle["counter-increment"])==null?void 0:a.value;(!w||!(w===v.footnote||w instanceof ke&&w.values.includes(v.footnote)))&&(f.footnote=1)}if(d)for(let w in d)this.defineCounter(w,d[w]);if(f)for(let w in f){this.counters[w]||this.defineCounter(w,0);let S=this.counters[w];S[S.length-1]+=f[w]}if(g)for(let w in g)if(!this.counters[w])this.defineCounter(w,g[w]);else{let S=this.counters[w];S[S.length-1]=g[w]}if(h===v.list_item){let w=this.counters["list-item"],S=w[w.length-1];e["ua-list-item-count"]=new K(new ei(S),0)}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 cr(this,this.currentElement,this.counterResolver));let i=t.value instanceof qe?t.value.values:[t.value];for(let n of i)if(n instanceof ke){let s=n.values[0].stringValue(),r=n.values.slice(1).map(o=>qi(o)).join("");this.counterResolver.setNamedString(s,r,this.currentElementOffset)}delete e["string-set"]}setRunningElement(e){let t=e.position;if(t?.value instanceof ki&&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 cr(this,t,this.counterResolver))),this.popCounters()}pushElement(e,t,i,n){var s,r;this.currentPageType=null,this.currentElement=t,this.currentElementOffset=n,this.currentStyle=i,this.currentNamespace=t.namespaceURI,this.currentLocalName=t.localName;let o=this.code.nsPrefix[this.currentNamespace];o?this.currentNSTag=o+this.currentLocalName:this.currentNSTag="",this.currentId=t.getAttribute("id"),this.currentXmlId=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let a=t.getAttribute("class");a?this.currentClassNames=a.split(/\s+/):this.currentClassNames=Ts;let h=t.getAttributeNS("http://www.idpf.org/2007/ops","type");h?this.currentEpubTypes=h.split(/\s+/):this.currentEpubTypes=Ts;let l=Os(t);l&&(this.stack[this.stack.length-1].push(new Mf(this.lang)),this.lang=l.toLowerCase());let c=this.isRoot,p=this.siblingOrderStack;this.currentSiblingOrder=++p[p.length-1],p.push(0);let d=this.siblingTypeCountsStack,f=this.currentSiblingTypeCounts=d[d.length-1],g=f[this.currentNamespace];g||(g=f[this.currentNamespace]={}),g[this.currentLocalName]=(g[this.currentLocalName]||0)+1,d.push({});let m=this.followingSiblingOrderStack;m[m.length-1]!==null?this.currentFollowingSiblingOrder=--m[m.length-1]:this.currentFollowingSiblingOrder=null,m.push(null);let y=this.followingSiblingTypeCountsStack,b=this.currentFollowingSiblingTypeCounts=y[y.length-1];b&&b[this.currentNamespace]&&b[this.currentNamespace][this.currentLocalName]--,y.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],e,t),this.applyCalcFilter(this.currentStyle,this.context),this.applyAttrFilter(t);let w=i.quotes,S=null;if(w){let _=w.evaluate(this.context);_&&(S=new zf(this.quotes),_===v.none?this.quotes=[new Ae(""),new Ae("")]:_===v.auto||_===v.initial?this.quotes=[new Ae("\u201C"),new Ae("\u201D"),new Ae("\u2018"),new Ae("\u2019")]:_ instanceof ke&&(this.quotes=_.values))}this.pushCounters(this.currentStyle);let R=this.currentId||this.currentXmlId||t.getAttribute("name")||"";if(c||R){let _={};Object.keys(this.counters).forEach(U=>{_[U]=Array.from(this.counters[U])}),this.counterListener.countersOfId(R,_)}let L=dt(this.currentStyle,"_pseudos");if(L){let _=!0;for(let U of qf){U||(_=!1);let W=L[U];W&&((U==="before"||U==="after")&&!Dt((s=W.content)==null?void 0:s.value)||(U==="footnote-call"||U==="footnote-marker")&&((r=Ve(this.currentStyle,"float"))==null?void 0:r.value)!==v.footnote?delete L[U]:_?this.processPseudoelementProps(W,t):this.stack[this.stack.length-2].push(new _f(W,t)))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),S&&this.stack[this.stack.length-2].push(S)}applyAttrFilterInner(e,t){for(let i in t)wi(i)&&!Nt(i)&&(t[i]=t[i].filterValue(e))}applyAttrFilter(e){let t=new Df(e),i=this.currentStyle,n=dt(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 ng(e,t,i),h=32,l={};for(let c in o)if(ar(c)){let p=dt(o,c);for(let d in p)this.applyVarFilter([p[d],...e],t,i)}else if(wi(c)){let p=Ve(o,c),d=p.value;for(let f=0;;f++){if(f>=h){d=G;break}let g=d.visit(a);if(a.error){d=G,a.error=!1;break}if(g===d)break;d=g}if(d!==p.value){let f=t.validatorSet,g=(n=f?.shorthands[c])==null?void 0:n.clone();if(g)if(J(d)){for(let m of g.propList){let y=new K(d,p.priority),b=Ve(o,m);qt(l,m,or(this.context,b,y))}delete o[c]}else{let m=Ti(t.scope,new gt(d.toString(),null),"");if(m&&(m.visit(g),!g.error)){for(let y of g.propList){let b=new K((r=(s=g.values[y])!=null?s:f.defaultValues[y])!=null?r:v.initial,p.priority),w=Ve(o,y);qt(l,y,or(this.context,w,b))}delete o[c]}}else o[c]=new K(d,p.priority)}if(l[c]){let f=Ve(o,c);f&&f.value!==G&&Tt(l,c,f,this.context)}}for(let c in l)o[c]=l[c]}applyCalcFilter(e,t){let i=new jh(t);for(let n in e)if(ar(n)){let s=dt(e,n);for(let r in s)this.applyCalcFilter(s[r],t)}else if(wi(n)&&!Nt(n)){let s=Ve(e,n),r=s.value.visit(i);r!==s.value&&(e[n]=new K(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()}},Ts=[],qf=["before","transclusion-before","footnote-call","footnote-marker","inner","first-letter","first-line","","transclusion-after","after"],dr=null;function Yf(e){dr=e}var nn=class extends gn{constructor(e,t,i,n,s,r,o){super(e,t,o),this.condition=i,this.regionId=s,this.validatorSet=r,u(this,"chain",null),u(this,"specificity",0),u(this,"elementStyle",null),u(this,"conditionCount",0),u(this,"pseudoelement",null),u(this,"footnoteContent",!1),u(this,"cascade"),u(this,"state"),u(this,"viewConditionId",null),u(this,"insideSelectorRule"),u(this,"invalid",!1),this.cascade=n?n.cascade:dr?dr.clone():new jf,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Rh(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 wf(e,t.toLowerCase())):t?this.chain.push(new Zo(t.toLowerCase())):this.chain.push(new yf(e)))}invalidSelector(e){D.warn(e),this.chain.push(new Ge("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof sn;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 gf(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new Nf);break;case"disabled":this.chain.push(new Pf);break;case"checked":this.chain.push(new Tf);break;case"root":case"scope":this.chain.push(new Cf);break;case"link":this.chain.push(new Zo("a")),this.chain.push(new Jo("","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)${Rt(i)}($|\\s)`),s=t[1];this.chain.push(new bf(n,s))}else this.chain.push(new Ge(""));break;case"-adapt-footnote-content":case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ge(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new Sf(new RegExp(`^${Rt(i.toLowerCase())}($|-)`)))}else this.chain.push(new Ge(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=Kf[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new Ge(""));break}case"first-child":this.chain.push(new Qo);break;case"last-child":this.chain.push(new hr(0,1));break;case"first-of-type":this.chain.push(new lr(0,1));break;case"last-of-type":this.chain.push(new ur(0,1));break;case"only-child":this.chain.push(new Qo),this.chain.push(new hr(0,1));break;case"only-of-type":this.chain.push(new lr(0,1)),this.chain.push(new ur(0,1));break;case"empty":this.chain.push(new kf);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"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 Ge(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new Ge(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new mf(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let s;switch(i){case 0:s=new Jo(e,t);break;case 39:s=new vf(e,t,n);break;case 45:!n||n.match(/\s/)?s=new Ge(""):s=new Oi(e,t,new RegExp(`(^|\\s)${Rt(n)}($|\\s)`));break;case 44:s=new Oi(e,t,new RegExp(`^${Rt(n)}($|-)`));break;case 43:n?s=new Oi(e,t,new RegExp(`^${Rt(n)}`)):s=new Ge("");break;case 42:n?s=new Oi(e,t,new RegExp(`${Rt(n)}$`)):s=new Ge("");break;case 46:n?s=new Oi(e,t,new RegExp(Rt(n))):s=new Ge("");break;case 50:if(n=="supported")s=new xf(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${Nn++}`;this.processChain(new kn(new Lf(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}childSelector(){let e=`c${Nn++}`;this.processChain(new kn(new Ff(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${Nn++}`;this.processChain(new kn(new Of(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${Nn++}`;this.processChain(new kn(new Bf(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,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 qr(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new sr(t,0,this.condition):i=new K(t,0),Ih(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 ke([v.exclusive,v._static]),i),this.simpleProperty("flow-into",t,i),t=v.block),pt("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 sr(t,n,this.condition):new K(t,n);Tt(this.elementStyle,e,s)}finish(){return this.cascade}startFuncWithSelector(e){let t;switch(e){case"is":t=new sn(this);break;case"not":t=new Zf(this);break;case"where":t=new Jf(this);break;case"has":t=new Qf(this);break}t&&(t.startSelectorRule(),this.owner.pushHandler(t))}},Kf={"nth-child":Ef,"nth-of-type":lr,"nth-last-child":hr,"nth-last-of-type":ur},Nn=0,sn=class Dh extends nn{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,u(this,"parentChain"),u(this,"chains",[]),u(this,"maxSpecificity",0),u(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 Af(this.selectorTexts):this.positive()?new Yr(this.chains):new Rf(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Ge("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(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 Dh;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}},Zf=class extends sn{positive(){return!1}forgiving(){return!1}},Jf=class extends sn{increasingSpecificity(){return!1}},Qf=class extends sn{relational(){return!0}},eg=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 Zt(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,s))}}},Pn=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,u(this,"order"),this.order=0}property(e,t,i){i?D.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){D.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){D.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=Kr;let s=this.condition?new sr(t,n,this.condition):new K(t,n);Tt(this.elementStyle,e,s)}},tg=class extends ql{constructor(e,t){super(e),this.validatorSet=t,u(this,"elementStyle",{}),u(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){D.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){D.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Xl:jl;n+=this.order,this.order+=Kr;let s=new K(t,n);Tt(this.elementStyle,e,s)}};function Vh(e,t){let i=Ph(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function pr(e,t,i){Vh(i,n=>{Yi(e,n,t)})}function ig(e,t,i,n){let s=new tg(e,t),r=new gt(n,s);try{up(r,s,i)}catch(o){D.warn(o,"Style attribute parse error:")}return s.elementStyle}function Uh(e,t,i){let n=e["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==v.inherit&&s!==v.revert&&s!==v.unset)return s===v.vertical_rl}return i}function Hh(e,t,i){let n=e.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==v.inherit&&s!==v.revert&&s!==v.unset)return s===v.rtl}return i}function $h(e,t,i,n,s){let r={};for(let o in e)wi(o)&&(r[o]=Ve(e,o));return pr(r,t,e),Gh(e,i,n,(o,a)=>{Yi(r,a,t),pr(r,t,a)}),r}function Gh(e,t,i,n){let s=dt(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 Yi(e,t,i){for(let n in t)if(wi(n)){let s=Ve(t,n),r=e[n];e[n]=or(i,r,s)}}var Wh=(e,t,i,n,s)=>{let r=i?n?hf:Eh:n?uf:kh;for(let o in e)if(e.hasOwnProperty(o)){let a=e[o];if(!a)continue;let h=r[o],l;if(h){let c=e[h];if(c&&c.priority>a.priority)continue;l=lf[h]?h:o}else l=o;t[l]=s(o,a)}},ng=class extends Ei{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 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=(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 ft&&e.values[0].name;return!t||!Nt(t)?(this.error=!0,G):this.getVarValue(t)||(e.values.length<2?(this.error=!0,G):e.values.length===2?e.values[1]:new qe(e.values.slice(1)))}},jh=class extends Ei{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=Ti(this.context.rootScope,new gt(i,null),"");if(n instanceof V)try{let s=n.expr.evaluate(this.context);typeof s=="number"&&(t=new T(s,"px"))}catch(s){D.warn(s)}return t}visitNumeric(e){return this.resolveViewportUnit&&(ol(e.unit)||$c(e.unit))?new T(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new T(e.num*this.percentRef/100,"px"):e}};function Xn(e,t,i,n,s){try{if(t instanceof V)return t.expr instanceof De&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:fp(e,t.expr,i);if(t instanceof T||t instanceof ki||t instanceof ke||t instanceof qe)return t.visit(new jh(e,!0,n,s))}catch(r){return D.warn(r),G}return t}var na={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function sa(e){let t=e instanceof $e?e:typeof e=="string"?B(e):v.none;if(t===v.none)return na;let i=t instanceof ke?t.values:[t],n=Object.create(na);for(let s of i)if(s instanceof ft)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 ra(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var sg={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},oa={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},aa={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function la(e){let t=e instanceof $e?e:typeof e=="string"?B(e):v.normal;if(t===v.normal)return oa;if(t===v.auto)return aa;let i=t instanceof ke?t.values:[t],n=Object.create(oa);for(let s of i)if(s instanceof ft)switch(s.name){case"trim-both":case"trim-auto":return aa;case"space-all":return sg;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 Is={ideographAlpha:!1,ideographNumeric:!1},rg={ideographAlpha:!0,ideographNumeric:!0};function ha(e){let t=e instanceof $e?e:typeof e=="string"?B(e):v.normal;if(t===v.normal||t===v.auto)return rg;if(t===v.none)return Is;let i=t instanceof ke?t.values:[t],n=Object.create(Is);for(let s of i)if(s instanceof ft)switch(s.name){case"no-autospace":return Is;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function ua(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function ca(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 og=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=ca(s);let o=ha(t),a=la(i),h=sa(n);if(ra(h)&&ua(o,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(r?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let c=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),p=null,d=null;for(let f=c.nextNode();f;f=d){d=c.nextNode();let g=!p,m=!p||/\n$/.test(p.textContent),y=!d||/^\n/.test(d.textContent),b=!d;this.processTextSpacing(f,g||m,g,m,y,b,p,d,o,a,h,s,r),p=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,s,r,o,a,h;let l=!e||e.fragmentIndex===1&&d(),c=l||f();function p(b){var w;if(b?.nodeType!==1)return!1;let S=b;if(S.hasAttribute(xi))return!0;let{position:R,float:L}=(w=S.style)!=null?w:{};return R==="absolute"||R==="fixed"||L&&L!=="none"}function d(){let b=t[0];for(let w=b;;w=w.parent)if(!w||!w.inline){if(w?.fragmentIndex!==1)return!1;break}if(!b.inline)return!0;for(let w=b.viewNode.previousSibling;w;w=w.previousSibling)if(!Ue(w,b.whitespace)&&!p(w))return!1;return!0}function f(){var b,w;let S=t[0],R;for(;S&&S.inline&&(R=(b=S.viewNode)==null?void 0:b.previousSibling,!(R&&(R.nodeType===3&&/^[ \t\r\n\f]*$/.test(R.textContent)&&S.whitespace!==Ze.PRESERVE&&(R=R.previousSibling),R)));)S=S.parent;for(;R;){if(R.nodeType===1){if(R.localName==="br")return!0;let L=(w=R.style)==null?void 0:w.display;if(L&&L!=="inline")return!/^(inline|ruby)\b/.test(L)}else if(R.nodeType===3){if(S.whitespace===Ze.PRESERVE){if(/\n$/.test(R.textContent))return!0}else if(S.whitespace===Ze.NEWLINE&&/\n[ \t\r\n\f]*$/.test(R.textContent))return!0}R=R.lastChild}return!1}let g=-1;for(let b=0;b<t.length;b++){let w=t[b];if(!w.after&&w.inline&&!w.display&&w.parent&&w.viewNode.parentNode&&w.viewNode.nodeType===Node.TEXT_NODE&&!Ue(w.viewNode,w.whitespace)){let S=function(E){var A,I,O;if(((A=E.viewNode)==null?void 0:A.nodeType)===1)return E.viewNode.localName==="br";if(((I=E.viewNode)==null?void 0:I.nodeType)===3){if(E.whitespace===Ze.PRESERVE){if(/\n$/.test(E.viewNode.textContent))return!0}else if(E.whitespace===Ze.NEWLINE&&/\n[ \t\r\n\f]*$/.test(E.viewNode.textContent))return!0;if(((O=E.viewNode.previousElementSibling)==null?void 0:O.localName)==="br")return Ue(E.viewNode,E.whitespace)}return!1},R=function(E){var A,I,O;if(((A=E.viewNode)==null?void 0:A.nodeType)===1)return E.viewNode.localName==="br";if(((I=E.viewNode)==null?void 0:I.nodeType)===3){if(E.whitespace===Ze.PRESERVE){if(/^\n/.test(E.viewNode.textContent))return!0}else if(E.whitespace===Ze.NEWLINE&&/^[ \t\r\n\f]*\n/.test(E.viewNode.textContent))return!0;if(((O=E.viewNode.nextElementSibling)==null?void 0:O.localName)==="br")return Ue(E.viewNode,E.whitespace)}return!1};var m=S,y=R;let L=ca((r=(n=(i=w.lang)!=null?i:w.parent.lang)!=null?n:e?.lang)!=null?r:(s=e?.parent)==null?void 0:s.lang),_=ha(w.inheritedProps["text-autospace"]),U=la(w.inheritedProps["text-spacing-trim"]),W=sa(w.inheritedProps["hanging-punctuation"]);if(ra(W)&&ua(_,U)||/\b(flex|grid)\b/.test(w.parent.display))continue;g<0&&(g=b);let we=null,He=null,ce=b===g,de=b===g&&l,x=b===g&&c,P=!1,C=!1;for(let E=b-1;E>=0;E--){let A=t[E];if(S(A)){x=!0;break}if(!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){we=A.viewNode;break}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((o=A.viewNode)==null?void 0:o.nodeType)===1&&(A.viewNode.localName==="br"||Wt[A.viewNode.localName]))break;E===0&&(ce=!0,l&&(de=!0,x=!0))}for(let E=b+1;E<t.length;E++){let A=t[E];if(R(A)){P=!0;break}if(A.viewNode!==w.viewNode&&!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){He=A.viewNode;break}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((a=A.viewNode)==null?void 0:a.nodeType)===1&&(A.viewNode.localName==="br"||Wt[A.viewNode.localName])){E===t.length-1&&p(A.viewNode)&&(C=!0);break}if(E===t.length-1){P=!0,C=!0;for(let I=A.viewNode.nextSibling;I;I=I.nextSibling)if(!p(I)){C=!1;break}}}if(((h=w.parent)==null?void 0:h.display)==="inline-block"){if(!de){let E=w.parent.viewNode.firstChild;for(;Ue(E,w.whitespace);)E=E.nextSibling;w.viewNode===E&&(de=!0)}if(!C){let E=w.parent.viewNode.lastChild;for(;Ue(E,w.whitespace);)E=E.previousSibling;w.viewNode===E&&(C=!0)}}this.processTextSpacing(w.viewNode,ce,de,x,P,C,we,He,_,U,W,L,w.vertical)}}}processTextSpacing(e,t,i,n,s,r,o,a,h,l,c,p,d){let f=e.textContent,g=e.ownerDocument,m,y,b;function w(){if(t)return!0;if(!o)return!1;m||(m=g.createRange(),m.selectNode(e));let P=m.getClientRects()[0];y||(y=g.createRange(),y.selectNode(o));let C=y.getClientRects(),E=C[C.length-1];return!P||!E?!1:d?P.top<E.top+E.height-P.width||P.left+P.width<E.left+P.width/10||P.left>E.left+E.width-P.width/10:P.left<E.left+E.width-P.height||P.top>E.top+E.height-P.height/10||P.top+P.height<E.top+P.height/10}function S(){if(!a)return!1;m||(m=g.createRange(),m.selectNode(e));let P=m.getClientRects()[0];b||(b=g.createRange(),b.selectNode(a));let C=b.getClientRects()[0];return!P||!C?!1:d?P.top+P.height>C.top+P.width||P.left>C.left+C.width-P.width/10||P.left+P.width<C.left+P.width/10:P.left+P.width>C.left+P.height||P.top+P.height<C.top+P.height/10||P.top>C.top+C.height-P.height/10}let R=!1,L=!1,_=!1,U=!1,W;if(i&&c.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(W="viv-ts-open",R=!0,L=!0):r&&c.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(W="viv-ts-close",R=!0,_=!0):(c.forceEnd||c.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(W="viv-ts-close",R=!0,U=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(W="viv-ts-open",R=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||p==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||p!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(W="viv-ts-close",R=!0),R){let P=function(O){let z=parseFloat(g.defaultView.getComputedStyle(O).fontSize)*.7;return(d?O.offsetHeight:O.offsetWidth)>z},C=function(){return d?E.offsetLeft:E.offsetTop};var we=P,He=C;if(e.parentElement.localName==="viv-ts-inner")return;let E=g.createElement(W),A=g.createElement("viv-ts-inner");E.appendChild(A),e.parentNode.insertBefore(E,e),A.appendChild(e);let I=P(A);if(I||L||_||U){if(W==="viv-ts-open"){if(L)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)&&w())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"&&P(o.parentElement)))E.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&w()){let O=C();E.className="viv-ts-auto",O===C()&&!w()&&(E.className="viv-ts-trim")}}else if(W==="viv-ts-close"){if(_)E.className=I?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(r||s){let O=C();U?(E.className=I?c.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",c.allowEnd&&O===C()&&(l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-hang-end",O===C()&&(E.className="")):E.className="viv-ts-space")):l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-ts-auto",O===C()&&(E.className="")):E.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))I&&l.trimAdjacent&&(E.className="viv-ts-trim");else if(U){let O=S(),z=O&&c.allowEnd;z||(E.className=I?"viv-hang-end":"viv-hang-end viv-hang-hw"),I?z&&l.trimEnd?E.className="viv-ts-auto":!z&&!S()?E.className="":!O&&c.allowEnd&&(l.trimEnd?(E.className="viv-ts-auto",S()||(E.className="viv-hang-end")):(E.className="viv-ts-space",S()||(l.allowEnd?(E.className="viv-ts-auto",S()||(E.className="viv-hang-end")):E.className="viv-hang-end"))):!O&&!S()&&(E.className="")}else if(l.trimEnd||l.allowEnd)if(S())l.allowEnd?E.className="viv-ts-space":E.className="viv-ts-auto";else{let O=C();E.className="viv-ts-auto",O===C()&&(E.className="")}}}}let ce=!1;function de(P){var C;let E=(C=P?.ownerDocument.defaultView)==null?void 0:C.getComputedStyle(P);return!!E&&(E.textOrientation==="upright"||E.textCombineUpright==="all"||E["-webkit-text-combine"]==="horizontal")}function x(P,C){if(P.nodeType===1){let I=g.defaultView.getComputedStyle(P);if(parseFloat(I.marginInlineEnd)||parseFloat(I.borderInlineEndWidth)||parseFloat(I.paddingInlineEnd))return!0}let E=P.parentElement;if(E&&!E.contains(C))return x(E,C);if(C.nodeType===1){let I=g.defaultView.getComputedStyle(C);if(parseFloat(I.marginInlineStart)||parseFloat(I.borderInlineStartWidth)||parseFloat(I.paddingInlineStart))return!0}let A=C.parentElement;return A&&!A.contains(P)?x(P,A):!1}(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))&&!(d&&de(o.parentElement))&&!x(o,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),ce=!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))&&!(d&&de(a.parentElement))&&!x(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),ce=!0))}registerHooks(){ht("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),ht("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),ht("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},Zr=new og;Zr.registerHooks();function ag(e){Zr.preprocessForTextSpacing(e)}function lg(e,t,i,n,s,r){Zr.processGeneratedContent(e,t,i,n,s,r)}var Ln=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),hg=["footnote-marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],Jr="data-adapt-pseudo";function di(e){return e.getAttribute(Jr)||""}function fr(e,t){e.setAttribute(Jr,t)}var da=class{constructor(e,t,i,n,s){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=s,u(this,"contentProcessed",{})}getStyle(e,t){let i=di(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=dt(this.style,"_pseudos")[i]||{};if(i.match(/^first-/)&&!n["x-first-pseudo"]){let s=1,r;i=="first-letter"?s=0:(r=i.match(/^first-([0-9]+)-lines$/))!=null&&(s=r[1]-0),n["x-first-pseudo"]=new K(new Jt(s),0)}return n}processContent(e,t,i){let n=di(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let s=t.content;s&&Dt(s)&&(s.visit(new Wn(e,this.context,s,this.exprContentListener)),ag(e))}}},Xw=Hn.isInstanceOfAfterIfContinuesLayoutConstraint,ug=os.registerFragmentIndex,qw=os.clearFragmentIndices,cg=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new Qr(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 N(r,"display","block"),k(r)})}createNodePositionForPseudoElement(){let e=Ln.createElementNS("http://www.w3.org/1999/xhtml","div");fr(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 zt(i)}createShadowContext(e){return new Ks(this.sourceNode,e,null,null,null,Pt.ShadowType.ROOTED,this.styler)}},dg=class Xh{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,u(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),k(!0))):k(!0)}getRepetitiveElements(){return new pg(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Xh?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},pg=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 qh(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return k(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let s=gg(e,t,n);return t.fragmentLayoutConstraints.push(new dg(e,i,s)),k(e)})}function Yh(e,t){return e.thenAsync(i=>qh(i,t))}function fg(e,t){let i=F("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let s=qh(n,t);return n=n.parent,s.thenReturn(!0)}else return k(!1)}).then(()=>{i.finish(!0)}),i.result()}function gg(e,t,i){let n=e.viewNode;n.appendChild(i);let s=Qs(i,t,e.vertical);return n.removeChild(i),s}var mg=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},Rs=class extends $r{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,u(this,"alreadyEvaluated",!1),u(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]}},qn=class extends dh{constructor(e,t,i,n,s){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=s,u(this,"last"),u(this,"viewDocument"),u(this,"flowRootFormattingContext",null),u(this,"isFloat",!1),u(this,"isFootnote",!1),u(this,"startEdge",0),u(this,"endEdge",0),u(this,"beforeEdge",0),u(this,"afterEdge",0),u(this,"footnoteEdge",0),u(this,"box",null),u(this,"chunkPositions",null),u(this,"bands",null),u(this,"overflown",!1),u(this,"breakPositions",null),u(this,"pageBreakType",null),u(this,"forceNonfitting",!0),u(this,"leftFloatEdge",0),u(this,"rightFloatEdge",0),u(this,"bottommostFloatTop",0),u(this,"stopAtOverflow",!0),u(this,"lastAfterPosition",null),u(this,"fragmentLayoutConstraints",[]),u(this,"pseudoParent",null),u(this,"nodeContextOverflowingDueToRepetitiveElements",null),u(this,"blockDistanceToBlockEndFloats",NaN),u(this,"breakAtTheEdgeBeforeFloat",null),this.last=e.lastChild,this.viewDocument=e.ownerDocument,s.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}isOverflown(e){return this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let t=F("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,s=null;return t.loop(()=>{for(;n>=0;){let r=s,o=i[n];if(s=Gn(o,r),n===i.length-1&&!s.formattingContext&&(s.formattingContext=this.flowRootFormattingContext),n==0&&(s.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),s.after=e.after,s.preprocessedTextContent=e.preprocessedTextContent,s.after))break;let a=this.layoutContext.setCurrent(s,n==0&&s.offsetInNode==0);if(n--,a.isPending())return a}return k(!1)}).then(()=>{t.finish(s)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?kp(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 s=e.viewNode.textContent,r=s.match(Fs),o=r?r[0].length:0;if(!r&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&s===e.sourceNode.textContent){let a=s+e.sourceNode.nextSibling.textContent,h=a.match(Fs);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 k(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=F("buildViewToNextBlockEdge");return n.loopWithFrame(s=>{e.viewNode&&!ui(e)&&t.push(e.copy()),this.maybePeelOff(e,0).then(r=>{let o=r;o!==e&&(e=o,ui(e)||t.push(e.copy())),this.nextInTree(e).then(a=>{if(e=a,!e){s.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(gi(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(h=>{if(e=h,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){s.breakLoop();return}s.continueLoop()}):e.inline?s.continueLoop():s.breakLoop()})})}).then(()=>{n.finish(e)}),n.result()}nextInTree(e,t){let i=this.layoutContext.nextInTree(e,t);return Yh(i,this)}buildDeepElementView(e){if(!e.viewNode)return k(e);let t=[],i=e.sourceNode,n=F("buildDeepElementView");return n.loopWithFrame(s=>{e.viewNode&&e.inline&&!ui(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(r=>{let o=r;if(o!==e){let a=o;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=o,s.breakLoop();return}ui(o)||t.push(o.copy())}this.nextInTree(o).then(a=>{e=a,!e||e.sourceNode==i?s.breakLoop():this.layoutConstraint.allowLayout(e)?s.continueLoop():(e=e.modify(),e.overflow=!0,this.stopAtOverflow?s.breakLoop():s.continueLoop())})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let s=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),N(s,"height",`${i}px`),N(s,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),N(s,"width",`${i}px`),N(s,"height",`${n}px`)),N(s,"float",t),N(s,"clear",t),this.element.insertBefore(s,e),s}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(),s=null;for(let r of t){let o=r.y2-r.y1;r.left=this.createFloat(e,"left",r.x1-i,o),r.right=this.createFloat(e,"right",n-r.x2,o),r.x1<n&&r.x2>i?s=r:s||N(r.right,"float","none")}if(s){let r=t[t.length-1],o=this.vertical?-this.getLeftEdge():this.getBottomEdge();s!==r&&r.y2>=o&&(this.footnoteEdge=this.vertical?-s.y2:s.y2)}}calculateEdge(e,t,i,n){let s;if(e&&hi(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(s=ai(e,this.clientLayout,0,this.vertical),!isNaN(s)))return s;e=t[i];let r=n-e.boxOffset;for(;;){if(s=ai(e,this.clientLayout,r,this.vertical),!isNaN(s))return s;if(r>0){r--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(r=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 xs(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 xs(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 xs(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=F("layoutFloat"),i=e.viewNode,n=Up(e.floatSide,e.vertical,e.direction);return i.setAttribute("data-vivliostyle-float-box","true"),N(i,"float","none"),N(i,"display","inline-block"),N(i,"vertical-align","top"),this.buildDeepElementView(e).then(s=>{let r=this.clientLayout.getElementClientRect(i),o=this.getComputedMargin(i),a=new nt(r.left-o.left,r.top-o.top,r.right+o.right,r.bottom+o.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,c=e.parent;for(;c&&c.inline;)c=c.parent;if(c){let S=c.viewNode.ownerDocument.createElement("div");S.style.left="0px",S.style.top="0px",this.vertical?(S.style.bottom="0px",S.style.width="1px"):(S.style.right="0px",S.style.height="1px"),c.viewNode.appendChild(S);let R=this.clientLayout.getElementClientRect(S);h=Math.max(this.rtl?this.getEndEdge(R):this.getStartEdge(R),h),l=Math.min(this.rtl?this.getStartEdge(R):this.getEndEdge(R),l),c.viewNode.removeChild(S);let L=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+L):h=Math.min(h,l-L),e.firstPseudo||c.viewNode.appendChild(e.viewNode)}let p=new nt(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),d=a;this.vertical&&(d=Dn(a));let f=this.getBoxDir();if(d.y1<this.bottommostFloatTop*f){let S=d.y2-d.y1;d.y1=this.bottommostFloatTop*f,d.y2=d.y1+S}pd(p,this.bands,d,n),this.vertical&&(a=Tl(d));let g=this.getComputedInsets(i);N(i,"width",`${a.x2-a.x1-g.left-g.right}px`),N(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),N(i,"position","absolute"),e.display,N(i,"display",e.display);let m,y=null;if(c&&(c.containingBlockForAbsolute?y=c:y=c.getContainingBlockForAbsolute()),y){let S=y.viewNode.ownerDocument.createElement("div");S.style.position="absolute",y.vertical?S.style.right="0":S.style.left="0",S.style.top="0",y.viewNode.appendChild(S),m=this.clientLayout.getElementClientRect(S),y.viewNode.removeChild(S)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(y?y.vertical:this.vertical)?N(i,"right",`${m.right-a.x2}px`):N(i,"left",`${a.x1-m.left}px`),N(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,w=this.vertical?a.x2:a.y1;!this.isOverflown(b)||this.breakPositions.length==0?(this.killFloats(),p=new nt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(p=Dn(p)),fd(p,this.bands,d,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=b:this.rightFloatEdge=b,this.bottommostFloatTop=w,this.updateMaxReachedAfterEdge(b),t.finish(s)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,s,r){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();e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),s.adjustPageFloatArea(e,a,this),e.init();let c=!!o.setFloatAreaDimensions(e,t,i,n,!0,!o.hasFloatFragments(),r);return c?(e.killFloats(),e.init()):a.element.parentNode.removeChild(h),c}createPageFloatArea(e,t,i,n,s){let r=this.element.ownerDocument.createElement("div");N(r,"position","absolute");let o=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new Di(null,Re.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null),h=o.getContainer(),l=new yg(t,r,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,s)?l:null}layoutSinglePageFloatFragment(e,t,i,n,s,r,o){let a=this.pageFloatLayoutContext;e=(o?o.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),c=this.createPageFloatArea(h,t,r,s,l),p={floatArea:c,pageFloatFragment:null,newPosition:null};if(!c)return k(p);let d=F("layoutSinglePageFloatFragment"),f=!1,g=0;return d.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let y=e[g],b=new zt(y.nodePosition);c.layout(b,!0).then(w=>{p.newPosition=w,!w||n?(g++,m.continueLoop()):(f=!0,m.breakLoop())})}).then(()=>{if(!f){let m=a.setFloatAreaDimensions(c,h.floatReference,t,r,!1,n,l);if(!m)f=!0;else{let y=s.createPageFloatFragment(e,m,c,!!p.newPosition);a.addPageFloatFragment(y,!0),p.pageFloatFragment=y}}d.finish(p)}),d.result()}layoutPageFloatInner(e,t,i,n){let s=this.pageFloatLayoutContext,r=e.float;s.stashEndFloatFragments(r);function o(h,l){l?s.removePageFloatFragment(l,!0):h&&h.element.parentNode.removeChild(h.element),s.restoreStashedFragments(r.floatReference),s.deferPageFloat(e)}let a=F("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],r.floatSide,r.clearSide,!s.hasFloatFragments(),t,i,n).then(h=>{let l=h.floatArea,c=h.pageFloatFragment,p=h.newPosition;c?this.layoutStashedPageFloats(r.floatReference,[n]).then(d=>{if(d){if(s.addPageFloatFragment(c),s.discardStashedFragments(r.floatReference),p){let f=new jo(r,p.primary);s.deferPageFloat(f)}a.finish(!0)}else o(l,c),a.finish(!1)}):(o(l,c),a.finish(!1))}),a.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),s=[],r=[],o=!1,a=F("layoutStashedPageFloats"),h=0;return a.loopWithFrame(l=>{if(h>=n.length){l.breakLoop();return}let c=n[h];if(t.includes(c)){h++,l.continueLoop();return}let p=new Si().findByFloat(c.continuations[0].float);this.layoutSinglePageFloatFragment(c.continuations,c.floatSide,null,!1,p,null).then(d=>{let f=d.floatArea;f&&s.push(f);let g=d.pageFloatFragment;g?(r.push(g),h++,l.continueLoop()):(o=!0,l.breakLoop())})}).then(()=>{o?(r.forEach(l=>{i.removePageFloatFragment(l,!0)}),s.forEach(l=>{let c=l.element;c&&c.parentNode&&c.parentNode.removeChild(c)})):n.forEach(l=>{let c=l.area.element;c&&c.parentNode&&c.parentNode.removeChild(c)}),a.finish(!o)}),a.result()}setFloatAnchorViewNode(e){let t=e.viewNode.parentNode,i=t.ownerDocument.createElement("span");i.setAttribute(xi,"1"),e.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(e,"footnote-call",i),t.appendChild(i),t.removeChild(e.viewNode);let n=e.modify();return n.after=!0,n.viewNode=i,n}resolveFloatReferenceFromColumnSpan(e,t,i){let n=F("resolveFloatReferenceFromColumnSpan"),s=this.pageFloatLayoutContext,r=s.getPageFloatLayoutContext(Re.REGION);return s.getContainer().width<r.getContainer().width&&e===Re.COLUMN?t===v.auto?this.buildDeepElementView(i.copy()).then(o=>{let a=o.viewNode,h=Dr(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(Re.REGION):n.finish(e)}):t===v.all?n.finish(Re.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Si().findByNodeContext(e),n,s=t.findPageFloatByNodePosition(e.toNodePosition());return s?n=k(s):n=i.createPageFloat(e,t,this),n.thenAsync(r=>{let o=$n(e,0),a=this.setFloatAnchorViewNode(e),h=i.findPageFloatFragment(r,t),l=new jo(r,o);if(h&&h.hasFloat(r))return t.registerPageFloatAnchor(r,a.viewNode),k(a);if(t.isForbidden(r)||t.hasPrecedingFloatsDeferredToNext(r))return t.deferPageFloat(l),t.registerPageFloatAnchor(r,a.viewNode),k(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return k(null);{let c=ai(a,this.clientLayout,0,this.vertical);return this.isOverflown(c)?k(a):this.layoutPageFloatInner(l,i,c,h).thenAsync(p=>p?k(null):(t.registerPageFloatAnchor(r,a.viewNode),k(a)))}})}processLineStyling(e,t,i){let n=F("processLineStyling"),s=i.concat([]);i.splice(0,i.length);let r=0,o=e.firstPseudo;return o.count==0&&(o=o.outer),n.loopWithFrame(a=>{if(!o){a.breakLoop();return}let h=this.findLinePositions(s),l=o.count-r;if(h.length<=l){a.breakLoop();return}let c=this.findAcceptableBreakInside(s,h[l-1],!0);if(c==null){a.breakLoop();return}this.finishBreak(c,!1,!1).then(()=>{r+=l,this.layoutContext.peelOff(c,0).then(p=>{e=p,o=e.firstPseudo,s=[],this.buildViewToNextBlockEdge(e,s).then(d=>{t=d,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,s),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&Wt[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let s=e[n];if(!s.after||!s.viewNode||s.viewNode.nodeType!=1)break;let r=this.getComputedMargin(s.viewNode),o=this.vertical?-r.left:r.bottom;o>0?t=Math.max(t,o):i=Math.min(i,o)}return t+i}layoutBreakableBlock(e){let t=F("layoutBreakableBlock"),i=[];return this.buildViewToNextBlockEdge(e,i).then(n=>{let s=i.length-1;if(s<0){t.finish(n);return}this.postLayoutBlock(n,i);let r=this.calculateEdge(n,i,s,i[s].boxOffset),o=!1;if(!n||!hi(n.viewNode)){let h=mi(n,this.collectElementsOffset());o=this.isOverflown(r+(this.vertical?-1:1)*h.minimum),this.isOverflown(r+(this.vertical?-1:1)*h.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(r+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(r);let a;e.firstPseudo?a=this.processLineStyling(e,n,i):a=k(n),a.then(h=>{i.length>0&&(this.saveBoxBreakPosition(i),o&&!this.isLoneImage(i)&&h&&(h=h.modify(),h.overflow=!0)),t.finish(h)})}),t.result()}postLayoutBlock(e,t){pt("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,s=0,r=t[0].boxOffset,o=s,a=t.length-1,h=t[a].boxOffset,l;for(;r<h;){l=r+Math.ceil((h-r)/2),o=s;let c=a;for(;o<c;){let d=o+Math.ceil((c-o)/2);t[d].boxOffset>l?c=d-1:o=d}let p=this.calculateEdge(null,t,o,l);if(this.vertical?p<=n:p>=n){for(h=l-1;t[o].boxOffset==l;)o--;a=o}else i&&this.updateMaxReachedAfterEdge(p),r=l,s=o}return{nodeContext:t[o],index:r,checkPointIndex:o}}findAcceptableBreakInside(e,t,i){var n,s;let r=this.findEndOfLine(t,e,!0),o=r.nodeContext,a=o.viewNode;if(a.nodeType!=1&&((n=a.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let h=a;o=this.resolveTextNodeBreaker(o).breakTextNode(h,o,r.index,e,r.checkPointIndex,i)}else{let h=Ko(o);if(h){if(((s=this.breakPositions)==null?void 0:s[0])instanceof Rs&&h!=null&&h.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;o=h}}return this.clearOverflownViewNodes(o,!1),o}resolveTextNodeBreaker(e){return pt("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Yn.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),s=!1,r=e,o=null,a=!1,h=!0;for(;h;){let l=!0;do{let c=null;r==t&&(t.nodeType===1?h=!(!t.firstChild||s):h=!1);let p=r.nodeType===1?r:null;p?s?s=!1:Hr(p)?l=!a:!p.firstChild||Wt[p.localName]||/^r(uby|[bt]c?)$/.test(p.localName)||Zp(this.clientLayout.getElementComputedStyle(p).display)?(l=!a,l?(p.localName==="ruby"&&r.firstChild&&(r=r.firstChild),n.setStartBefore(r),a=!0,o=r):p.localName!=="ruby"&&(o=r),r.contains(t)&&(h=!1)):c=r.firstChild:(a||(r.parentNode==null?h=!1:(n.setStartBefore(r),a=!0)),o=r),c||(c=r.nextSibling,c||(s=!0,c=r.parentNode)),r=c}while(l&&h);if(a){n.setEndAfter(o);let c=this.clientLayout.getRangeClientRects(n);for(let p=0;p<c.length;p++)i.push(c[p]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?Op:Fp);let n=0,s=0,r=0,o=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],c=1;if(o>0){let p=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?c=h*(this.getAfterEdge(l)-n)/p:h*this.getAfterEdge(l)>h*s?c=h*(s-this.getBeforeEdge(l))/p:c=1}if(o==0||c>=.6||c>=.2&&this.getStartEdge(l)>=r-1){r=this.getEndEdge(l),this.vertical?(n=o==0?l.right:Math.max(n,l.right),s=o==0?l.left:Math.min(s,l.left)):(n=o==0?l.top:Math.min(n,l.top),s=o==0?l.bottom:Math.max(s,l.bottom)),o++,a++;continue}}if(o>0&&(t.push(s),o=0),a>=i.length)break}return t.sort(Qa),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&_i(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=mi(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 s=e.checkPoints,r=s[0];for(;r.parent&&r.inline;)r=r.parent;let o,a;t?(o=1,a=1):(o=Math.max((r.inheritedProps.widows||2)-0,1),a=Math.max((r.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(r),l=this.findLinePositions(s),c=this.footnoteEdge-h,p=this.getBoxDir(),d=this.getOffsetByRepetitiveElements(e);c-=p*d;let f=this.findFirstOverflowingEdgeAndCheckPoint(s);isNaN(f.edge)&&(f.edge=p*(1/0));let g=Bt(l.length,w=>{let S=l[w];return this.vertical?S<c||S<=f.edge:S>c||S>=f.edge}),m=g<=0;m&&(g=Bt(l.length,w=>this.vertical?l[w]<c:l[w]>c));let y=s[s.length-1].viewNode;if(y?.parentElement.localName==="viv-ts-inner"&&(y=y.parentElement.parentElement),(g===l.length&&y.nextSibling||g>=l.length-1&&y.parentElement.querySelector(".MJXc-display"))&&(o=0),g=Math.min(l.length-o,g),g<a)return null;c=l[g-1];let b;if(m?b=f.checkPoint:b=this.findAcceptableBreakInside(e.checkPoints,c,t),b){let w=this.getAfterEdgeOfBlockContainer(b);!isNaN(w)&&w<c&&(c=w),this.computedBlockSize=p*(c-this.beforeEdge)+d}return b}getAfterEdgeOfBlockContainer(e){let t=e;do t=t.parent;while(t&&t.inline);return t?(t=t.copy().modify(),t.after=!0,ai(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 Fi().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=Wr.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 s=this.breakPositions.length-1;s>=0&&!t;--s){e=this.breakPositions[s],t=e.findAcceptableBreak(this,i);let r=e.getMinBreakPenalty();r>i&&(n=Math.min(n,r))}}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 k(e);let s=F("doFinishBreak"),r=!1;if(!e){if(this.forceNonfitting)return D.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(o=>{o?(o=o.modify(),o.overflow=!1,this.finishBreak(o,r,!0).then(()=>{s.finish(o)})):s.finish(o)}),s.result();e=i,r=!0,this.computedBlockSize=n}return this.finishBreak(e,r,!0).then(()=>{s.finish(e)}),s.result()}isBreakable(e){if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}zeroIndent(e){let t=e.toString();return t==""||t=="auto"||!!t.match(/^0+(.0*)?[^0-9]/)}checkOverflowAndSaveEdge(e,t){if(!e||hi(e.viewNode))return!1;let i=ai(e,this.clientLayout,0,this.vertical),n=mi(e,this.collectElementsOffset()),s=this.isOverflown(i+(this.vertical?-1:1)*n.minimum);if(this.isOverflown(i+(this.vertical?-1:1)*n.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let r=i+this.getTrailingMarginEdgeAdjustment(t),o=this.footnoteEdge-this.getBoxDir()*n.current;i=this.vertical?Math.min(i,Math.max(r,o)):Math.max(i,Math.min(r,o))}return this.updateMaxReachedAfterEdge(i),s}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||hi(e.viewNode))return!1;let s=this.checkOverflowAndSaveEdge(e,t);return(i||!s)&&this.saveEdgeBreakPosition(e,n,s),s}applyClearance(e){if(!e.viewNode.parentNode)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=this.clientLayout.getElementClientRect(i),s=this.getBeforeEdge(n),r=this.getBoxDir(),o=e.clearSide,a=-this.getBoxDir()*(1/0);switch(o==="all"&&(a=this.pageFloatLayoutContext.getPageFloatClearEdge(o,this)),o){case"left":a=r*Math.max(a*r,this.leftFloatEdge*r);break;case"right":a=r*Math.max(a*r,this.rightFloatEdge*r);break;default:a=r*Math.max(a*r,Math.max(this.rightFloatEdge*r,this.leftFloatEdge*r))}if(s*r>=a*r)return e.viewNode.parentNode.removeChild(i),!1;{let h=Math.max(1,(a-s)*r);this.vertical?i.style.width=`${h}px`:i.style.height=`${h}px`,n=this.clientLayout.getElementClientRect(i);let l=this.getAfterEdge(n);if(!e.floatSide)if(this.vertical){let c=l+t.right-a;c>0==t.right>=0&&(c+=t.right),i.style.marginLeft=`${c}px`}else{let c=a-(l+t.top);c>0==t.top>=0&&(c+=t.top),i.style.marginBottom=`${c}px`}return e.clearSpacer=i,!0}}isBFC(e){return!!(Jp(e)||Xt.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}skipEdges(e,t,i){var n;let s=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(s&&!this.isBFC(s))return k(e);let r=F("skipEdges"),o=!i&&t&&e&&e.after,a=i,h=null,l=[],c=[],p=!1;function d(){return!!i||!t&&Ke(a)&&!f()}function f(){var m;if(!h||e.floatSide)return!1;for(let y=h;y!=null&&y.parent;y=y.parent){let b=y.after?y.viewNode:(m=y.viewNode)==null?void 0:m.previousSibling;for(;b&&(Ue(b,y.parent.whitespace)||vh(b));)b=b.previousSibling;if(b)return!1}return!0}let g=()=>{e=l[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=a};return r.loopWithFrame(m=>{for(var y;e;){e.formattingContext;let b=new Fi().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ue(e.viewNode,e.whitespace))break;if(!e.after){d()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)?(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0):(e=e.modify(),e.breakBefore=a),m.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=Un(a)?a:null),b&&b.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),a,!1),!e.inline&&!e.repeatOnBreak&&(h?Ko(h):this.breakPositions[this.breakPositions.length-1]instanceof Rs)&&this.saveEdgeBreakPosition(e.copy(),a,!1),!this.isBFC(e.formattingContext)||Xt.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Ue(e.sourceNode.firstChild,e.whitespace)){l.push(e.copy()),a=Xe(a,e.breakBefore),d()?g():(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0),m.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let S=e.viewNode.style;if(e.after){e.floatSide&&(a=a??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let R=e.sourceNode;if(R.localName==="svg"||R.localName==="math"||R.getAttribute("data-math-typeset")==="true"){p=!1,h=e.copy(),c.push(h),a=Xe(null,e.breakAfter),this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,a);break}if(e.inline||b&&b.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(d()){g(),m.breakLoop();return}l=[],t=!1,o=!1,a=null}p=!1,h=e.copy(),c.push(h),a=Xe(a,e.breakAfter),S&&!(this.zeroIndent(S.paddingBottom)&&this.zeroIndent(S.borderBottomWidth))&&(c=[h])}else{if(l.push(e.copy()),a=Xe(a,e.breakBefore),(e.pageType!=((y=e.parent)==null?void 0:y.pageType)||!Ke(a))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,a),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){m.breakLoop();return}let R=e.viewNode.localName;if(Wt[R]){d()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)&&(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0),m.breakLoop();return}S&&!(this.zeroIndent(S.paddingTop)&&this.zeroIndent(S.borderTopWidth))&&(o=!1,c=[]),p=!0}}while(!1);let w=this.nextInTree(e,o);if(w.isPending()){w.then(S=>{e=S,m.continueLoop()});return}else e=w.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(h,c,!this.stopAtOverflow,a)?h&&this.stopAtOverflow&&(e=h.modify(),e.overflow=!0):Ke(a)&&(this.pageBreakType=a),m.breakLoop()}).then(()=>{h&&(this.lastAfterPosition=h.toNodePosition()),r.finish(e)}),r.result()}skipTailEdges(e){let t=e.copy(),i=F("skipEdges"),n=null,s=!1;return i.loopWithFrame(r=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ue(e.viewNode,e.whitespace))break;if(!e.after){Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=Xe(n,e.breakBefore),Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(s){if(Ke(n)){this.pageBreakType=n,r.breakLoop();return}n=null}s=!1,n=Xe(n,e.breakAfter)}else{n=Xe(n,e.breakBefore);let h=e.viewNode.localName;if(Wt[h]){Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}if(a&&!(this.zeroIndent(a.paddingTop)&&this.zeroIndent(a.borderTopWidth))){r.breakLoop();return}}s=!0}while(!1);let o=this.layoutContext.nextInTree(e);if(o.isPending()){o.then(a=>{e=a,r.continueLoop()});return}else e=o.get()}t=null,r.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){return gi(e.floatReference)||e.floatSide==="footnote"?this.layoutPageFloat(e):this.layoutFloat(e)}layoutNext(e,t,i){let n=F("layoutNext");return this.skipEdges(e,t,i||null).then(s=>{if(e=s,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let r=e.formattingContext;new Fi().find(r).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 Fi().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 nt(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=ud(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],N(this.element,"width",`${this.width}px`),N(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),s=new Fi().find(e.formattingContext),r=this.calculateClonedPaddingBorder(n),o=s.createEdgeBreakPosition(n,t,i,this.computedBlockSize+r);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 Rs(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 k(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?k(null):k(e);let n=F("layout");return this.openAllViews(e.primary).then(s=>{let r=null;if(s.viewNode)r=s.copy();else{let a=h=>{h.nodeContext.viewNode&&(r=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let o=new wg(t,i);o.layout(s,this).then(a=>{this.doFinishBreak(a,o.context.overflownNodeContext,r,o.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=k(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let c=new zt(h.toNodePosition());n.finish(c)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=F("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((s,r)=>s.getPriorityOfFinishBreak()-r.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):k(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=F("doLayout"),s=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(r=>{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())r.breakLoop();else if(this.pageBreakType)r.breakLoop();else if(e&&this.stopByOverflow(e)){s=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),r.breakLoop()}else o?o=!1:r.continueLoop()}),o){o=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),r.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:s})}),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=F("redoLayout"),n=0,s=null,r=!0;return i.loopWithFrame(o=>{if(n<e.length){let a=e[n++];this.layout(a,r).then(h=>{r=!1,h?(s=h,o.breakLoop()):o.continueLoop()});return}o.breakLoop()}).then(()=>{i.finish(s)}),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(Xt.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(Hn.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}_t.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},Qr=class{constructor(e,t,i){u(this,"startNodeContexts",[]),u(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 qn.prototype.openAllViews.call(this,r).thenAsync(o=>(s.startNodeContexts.push(o.copy()),k(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 rs(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 Mt(e.toNodePosition(),this.column.lastAfterPosition)}getColumnElement(){return this.column.element}getColumn(){return this.column}},Yn=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+pa(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&&vo(s)&&vo(r)?pa(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};u(Yn,"instance");Yn.instance=new Yn;function pa(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var wg=class extends jr{constructor(e,t){super(),this.leadingEdge=e,u(this,"breakAfter"),u(this,"initialPageBreakType",null),u(this,"initialComputedBlockSize",0),u(this,"initialOverflown",!1),u(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new bg(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||ef()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&yh(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}},bg=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=F("DefaultLayoutMode.doLayout");return fg(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}},yg=class extends qn{constructor(e,t,i,n,s,r,o){super(t,i,n,s,r),this.floatSide=e,this.parentContainer=o,u(this,"rootViewNodes",[]),u(this,"floatMargins",[]),u(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),k(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 h=li(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),c=o*l/100;N(e,a,`${c}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=>{li(e,r)==="auto"&&N(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=li(t,"height");n!==""&&n!=="auto"&&N(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=li(t,"width");n!==""&&n!=="auto"&&N(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=this.clientLayout.getElementClientRect(e),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}},Qt=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,u(this,"formattingContextType","RepetitiveElementsOwner"),u(this,"isRoot",!1),u(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||tr.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new vg(e,this.rootSourceNode),tr.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},vg=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,u(this,"headerSourceNode",null),u(this,"footerSourceNode",null),u(this,"headerViewNode",null),u(this,"footerViewNode",null),u(this,"headerNodePosition",null),u(this,"footerNodePosition",null),u(this,"headerHeight",0),u(this,"footerHeight",0),u(this,"isSkipHeader",!1),u(this,"isSkipFooter",!1),u(this,"enableSkippingFooter",!0),u(this,"enableSkippingHeader",!0),u(this,"doneInitialLayout",!1),u(this,"firstContentSourceNode",null),u(this,"lastContentSourceNode",null),u(this,"affectedNodeCache",[]),u(this,"afterLastContentNodeCache",[]),u(this,"allowInsert",!1),u(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=$n(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=$n(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=Qs(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Qs(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?k(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?k(!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 Qr(n,o,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new zt(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,r.removeChild(o),this.moveChildren(o,r,i),a.getColumn().pageBreakType=h,k(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(xi,"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)||(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}},Kh=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}},Zh=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},xg=class extends Kh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},Sg=class extends Zh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new eo(e)),this.processor.doLayout(e,t)}},eo=class Jh{constructor(t){u(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),u(this,"nodeContext");let i=St(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||hi(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=St(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return k(!0);let r=this.nodeContext;return Pg(n,r,i).thenAsync(()=>Tg(n,r,i).thenAsync(()=>(s.prepareLayoutFragment(),k(!0))))}getRepetitiveElements(){return St(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof Jh?St(this.nodeContext.formattingContext)===St(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},Cg=class extends jr{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 xg(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new Sg(this.formattingContext,this.processor))}},Eg=class extends ji{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),k(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),k(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return ji.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"?k(!0):ji.prototype.afterNonInlineElementNode.call(this,e)}},kg=class extends ci{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=St(e.formattingContext);return n.getRootViewNode(e)?(i&&Qh(e.parent,t),e.belongsTo(n)?ci.prototype.layout.call(this,e,t,i):new Cg(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=Ig(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=St(e.formattingContext),n=F("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=St(e.formattingContext),n=new Eg(i,t);return new er(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=St(e.formattingContext),n=F("doLayout"),s=t.layoutContext.nextInTree(e,!1);return Yh(s,t).then(r=>{let o=r;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 ci.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){ci.prototype.clearOverflownViewNodes(e,t,i,n)}};function Ng(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof Qt&&!i.belongsTo(n)&&t(n,i)}}function Qh(e,t){e&&Ng(e.after?e.parent:e,(i,n)=>{_t.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new eo(n))})}function Pg(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 k(!0)}function Tg(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 k(!0)}function Ig(e){let t=e.formattingContext;return!t||!(t instanceof Qt)?null:t}function St(e){return e instanceof Qt,e}var Rg=new kg;ht("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Qt&&!_t.isInstanceOfTableFormattingContext(e)?Rg:null);var eu=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,u(this,"cells",[])}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},Ag=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,u(this,"viewElement"),u(this,"colSpan"),u(this,"rowSpan"),u(this,"height",0),u(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}},Lg=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Fg=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,u(this,"pseudoColumn"),u(this,"empty",!1),this.pseudoColumn=new Qr(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&N(e,"vertical-align","top"),i&&i!=="normal"&&N(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return N(e,"vertical-align",t),i&&i!=="normal"&&N(e,"align-content",i),n}},Og=class{constructor(e,t){this.viewNode=e,this.side=t}},Bg=class extends rs{constructor(e,t,i,n){super(e,t,i,n),u(this,"formattingContext"),u(this,"acceptableCellBreakPositions",null),u(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();return this.getAcceptableCellBreakPositions().forEach(t=>{e+=t.breakPosition.getMinBreakPenalty()}),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)}},_g=class extends $r{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,u(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(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,h=r.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(r=>r.nodeContext&&r.nodeContext.overflow),s?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext,t=e.getRowByIndex(this.rowIndex),i=0;return e.isFreelyFragmentableRow(t)||(i+=10),this.getAcceptableCellBreakPositions().forEach(n=>{i+=n.breakPosition.getMinBreakPenalty()}),i}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)}},bi=class extends Qt{constructor(e,t){super(e,t),this.tableSourceNode=t,u(this,"formattingContextType","Table"),u(this,"vertical",!1),u(this,"columnCount",-1),u(this,"tableWidth",0),u(this,"captions",[]),u(this,"colGroups",null),u(this,"colWidths",null),u(this,"inlineBorderSpacing",0),u(this,"rows",[]),u(this,"slots",[]),u(this,"cellFragments",[]),u(this,"lastRowViewNode",null),u(this,"cellBreakPositions",[]),u(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 eu(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 Lg(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]}isFreelyFragmentableRow(e){return e.getMinimumHeight()>this.tableWidth/2}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=e.getElementClientRect(i.viewElement);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 Mg(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(Xt.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}_t.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},Mg=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=mi(e,n);i=Math.max(i,t(s))}),i}};function at(e){return e instanceof bi,e}function zg(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Dg(e){return e==="table"||e==="inline-table"}function fa(e){return zg(e)||Dg(e)}function tu(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 bi)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof bi){o=a.formattingContext===t;break}}return o||s==="table-row"&&!fa(r)||s==="table-cell"&&r!=="table-row"&&!fa(r)||n.formattingContext instanceof bi&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,k(!0))):null}var Vg=class extends ji{constructor(e,t){super(),this.formattingContext=e,this.column=t,u(this,"rowIndex",-1),u(this,"columnIndex",0),u(this,"inRow",!1),u(this,"checkPoints",[]),u(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=tu(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 Og(n.viewNode,n.captionSide);t.captions.push(o);break}case"table-header-group":return r.isHeaderRegistered()||(this.inHeaderOrFooter=!0,r.setHeaderNodeContext(n)),k(!0);case"table-footer-group":return r.isFooterRegistered()||(this.inHeaderOrFooter=!0,r.setFooterNodeContext(n)),k(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,n.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new eu(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,k(!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 Ag(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&&!ui(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},iu=class nu extends ji{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,u(this,"inRow",!1),u(this,"currentRowIndex",-1),u(this,"currentColumnIndex",0),u(this,"originalStopAtOverflow"),u(this,"inHeader"),u(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,h=i.verticalAlign;o>1&&(N(a,"box-sizing","border-box"),N(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let l=a.ownerDocument.createElement("div");a.appendChild(l);let c=new Fg(this.column,l,i);return this.formattingContext.addCellFragment(s,r,c),n.primary.steps.length===1&&n.primary.after&&(c.empty=!0),c.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(p=>p+1,0);if(s===0)return k(!0);let r=this.column.layoutContext,o=t.nodeContext;o.viewNode.parentNode.removeChild(o.viewNode);let a=F("layoutRowSpanningCellsFromPreviousFragment"),h=k(!0),l=0,c=[];return n.forEach(p=>{h=h.thenAsync(()=>{let d=Gn(p[0].cellNodePosition.steps[1],o.parent);return r.setCurrent(d,!1).thenAsync(()=>{let f=k(!0),g=0;function m(y){for(;g<y;){if(!c.includes(g)){let b=d.viewNode.ownerDocument.createElement("td");N(b,"padding","0"),d.viewNode.appendChild(b)}g++}}return p.forEach(y=>{f=f.thenAsync(()=>{let b=y.cell;m(b.anchorSlot.columnIndex);let w=y.cellNodePosition,S=Gn(w.steps[0],d);return S.offsetInNode=w.offsetInNode,S.after=w.after,S.fragmentIndex=w.steps[0].fragmentIndex+1,r.setCurrent(S,!1).thenAsync(()=>{let R=y.breakChunkPosition;for(let L=0;L<b.colSpan;L++)c.push(g+L);return g+=b.colSpan,this.layoutCell(b,S,R).thenAsync(()=>(S.viewNode.rowSpan=b.rowIndex+b.rowSpan-this.currentRowIndex+s-l,k(!0)))})})}),f.thenAsync(()=>(m(i.getColumnCount()),l++,k(!0)))})})}),h.then(()=>{r.setCurrent(o,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return k(!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),k(!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);ug(s,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return k(!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,k(!0);let s=i.copy().modify();s.after=!0,t.nodeContext=s;let r=F("startTableCell"),o;if(this.hasBrokenCellAtSlot(n.anchorSlot.columnIndex)){let a=this.formattingContext.cellBreakPositions.shift();i.fragmentIndex=a.cellNodePosition.steps[0].fragmentIndex+1,o=k(a.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(a=>{a.viewNode&&i.viewNode.removeChild(a.viewNode);let h=$n(a,0);return k(new zt(h))});return o.then(a=>{this.layoutCell(n,i,a).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,r.finish(!0)})}),r.result()}startNonInlineBox(t){let i=tu(t,at(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,k(!0)):r==="table-footer-group"&&s&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,k(!0)):r==="table-row"?this.startTableRow(t):r==="table-cell"?this.startTableCell(t):k(!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 _g(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(s)}return k(!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)):N(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)):N(i.viewNode,"display","table-row-group")),s&&nu.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 k(!0)}};u(iu,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Ug=iu,rn=[];function Hg(e){let t=rn.findIndex(n=>n.root===e),i=rn[t];return i?i.tableLayoutOption:null}function $g(e){let t=rn.findIndex(i=>i.root===e);t>=0&&rn.splice(t,1)}var su=class{layoutEntireTable(e,t){let i=at(e.formattingContext),n=new Vg(i,t);return new er(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let s=e.ownerDocument,r=s.createElement("tr"),o=[];for(let h=0;h<t;h++){let l=s.createElement("td");r.appendChild(l),o.push(l)}e.parentNode.insertBefore(r,e.nextSibling);let a=o.map(h=>{let l=n.getElementClientRect(h),c=i?l.height:l.width;return Math.ceil(c)});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),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,o,t),l.forEach((c,p)=>{N(c,n?"height":"width",`${a[p]}px`)}),h.forEach(c=>{r.appendChild(c.cloneNode(!0))}),e.colGroups=r}doInitialLayout(e,t){let i=at(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Hg(e.sourceNode);$g(e.sourceNode);let s=F("TableLayoutProcessor.doInitialLayout"),r=e.copy();return this.layoutEntireTable(e,t).then(o=>{let a=o.viewNode,h=t.clientLayout.getElementClientRect(a),l=t.vertical?h.left:h.bottom;if(l+=(t.vertical?-1:1)*mi(e,t.collectElementsOffset()).current,!t.isOverflown(l)&&(!n||!n.calculateBreakPositionsInside)){t.breakPositions.push(new Xg(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)}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=at(e.formattingContext),n=i.getRootViewNode(e),s=n.firstChild;this.addCaptions(i,n,s),this.addColGroups(i,n,s);let r=new Ug(i,t),o=new er(r,t.layoutContext),a=F("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=at(e.formattingContext);return n.getRootViewNode(e)?(i&&Qh(e.parent,t),new Wg(n,this).layout(e,t)):t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new Bg(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}finishBreak(e,t,i,n){let s=at(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=F("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===o.length){l.breakLoop();return}let c=o[h++],p=s.getCellFragmentOfCell(c),d=p.findAcceptableBreakPosition().nodeContext,f=p.cellNodeContext,g=f.toNodePosition(),m=new zt(d.toNodePosition());s.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:c});let y=f.viewNode;p.column.layoutContext.processFragmentedBlockEdge(p.cellNodeContext),r<c.rowIndex+c.rowSpan-1&&(y.rowSpan=r-c.rowIndex+1),p.empty?l.continueLoop():p.pseudoColumn.finishBreak(d,!1,!0).then(()=>{Gg(p,s,d),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),s.finishFragment(),a.finish(!0)}),a.result()}}return s.finishFragment(),Wr.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){ci.prototype.clearOverflownViewNodes(e,t,i,n)}};function Gg(e,t,i){let n=t.getRepetitiveElements();if(!n)return;let s=t.vertical,r=e.column,o=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=r.clientLayout.getElementClientRect(a),l=r.getComputedPaddingBorder(a);if(s){let c=h.right-r.footnoteEdge-n.calculateOffset(i)-l.right;N(o,"max-width",`${c}px`)}else{let c=r.footnoteEdge-n.calculateOffset(i)-h.top-l.top;N(o,"max-height",`${c}px`)}N(o,"overflow","hidden")}var Wg=class extends jr{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new jg(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new Yg(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()}},jg=class extends Kh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},Xg=class extends rs{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 qg(this.position.sourceNode))}},qg=class ru{constructor(t){this.tableRootNode=t,u(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,s){i.sourceNode,rn.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return k(!0)}equalsTo(t){return t instanceof ru&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Yg=class extends Zh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new Kg(e);t.fragmentLayoutConstraints.some(s=>n.equalsTo(s))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},Kg=class ou extends eo{constructor(t){super(t),u(this,"flagmentLayoutConstraintType","TableRow"),u(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||n.pseudoParent||hi(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=at(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=at(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 su().removeColGroups(r,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,s)}finishBreak(t,i){let n=at(this.nodeContext.formattingContext),s=F("finishBreak"),r=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.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 k(!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=at(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof ou?at(this.nodeContext.formattingContext)===at(t.nodeContext.formattingContext):!1}},Zg=new su;function Jg(e,t,i,n,s,r){if(!t)return null;if(i===v.table){let o=e.parent;return new bi(o?o.formattingContext:null,e.sourceNode)}return null}function Qg(e){return e instanceof bi?Zg:null}ht("RESOLVE_FORMATTING_CONTEXT",Jg);ht("RESOLVE_LAYOUT_PROCESSOR",Qg);function ga(e){return e.reduce((t,i)=>t+i,0)/e.length}function em(e){let t=ga(e);return ga(e.map(i=>{let n=i-t;return n*n}))}var tm=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function on(e){return e.vertical?e.width:e.height}function an(e,t){e.vertical?e.width=t:e.height=t}var au=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,u(this,"originalContainerBlockSize"),this.originalContainerBlockSize=on(e)}balanceColumns(e){let t=F("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 tm(e,t)}preBalance(e){}postBalance(){an(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)}},gr=1;function lu(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+gr}function hu(e,t){let i=e[e.length-1].layoutResult.columns,n=Math.max.apply(null,i.map(s=>isNaN(s.blockDistanceToBlockEndFloats)?s.computedBlockSize:s.computedBlockSize-s.blockDistanceToBlockEndFloats+gr))-gr;n<on(t)?an(t,n):an(t,on(t)-1)}var im=class extends au{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,u(this,"originalPosition",null),u(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);an(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 ma(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return lu(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!ma(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):on(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)hu(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,on(this.layoutContainer)+this.originalContainerBlockSize*.1);an(this.layoutContainer,t)}}};function ma(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize;return e.slice(0,e.length-1).every(i=>t>i.computedBlockSize)}var nm=class extends au{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 em(t)}hasNextCandidate(e){return lu(e)}updateCondition(e){hu(e,this.layoutContainer)}};function sm(e,t,i,n,s,r,o){if(t===v.auto)return null;{let a=o.positions.length===0,h=r[r.length-1],l=!!(h&&h.pageBreakType);return a||l?new im(i,n,s,e):t===v.balance_all?new nm(i,n,s):(v.balance,null)}}var As=class{constructor(e,t,i){u(this,"endStuckFixed"),u(this,"endFixed"),u(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},rm=class{constructor(){u(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 As(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 As(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new As(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=Bt(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=Bt(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}},om=class mr{constructor(t,i,n,s,r,o,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=s,this.flowChunk=r,this.atBlockStart=o,this.atFlowStart=a,this.isParentBoxDisplayed=h,u(this,"flowName"),u(this,"isBlockValue",null),u(this,"hasBoxValue",null),u(this,"styleValues",{}),u(this,"beforeBox",null),u(this,"afterBox",null),u(this,"breakBefore",null),this.flowName=r.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let c=new mr(t,l.before,n,!1,r,this.isBlock(),a,!0),p=c.styleValue("content");Dt(p)&&(this.beforeBox=c,this.breakBefore=c.breakBefore)}}this.breakBefore=Xe(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ke(this.breakBefore)&&(r.breakBefore=Xe(r.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let r=new mr(this.context,s.after,t,!1,this.flowChunk,i,n,!0),o=r.styleValue("content");Dt(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",v.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=wh(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==v.none),this.hasBoxValue}getBreakValue(t){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(i=n.toString())}return i}},am=class{constructor(e){this.context=e,u(this,"stack",[]),u(this,"atBlockStart",!0),u(this,"atFlowStart",!0),u(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 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(),h=new om(this.context,e,t,i,r,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=rh(i);n&&!Ue(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=Xe(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!")}},wa=class{constructor(e,t,i,n,s,r,o,a){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=s,this.validatorSet=r,this.counterListener=o,u(this,"root"),u(this,"cascadeHolder"),u(this,"last"),u(this,"rootStyle",{}),u(this,"styleMap",{}),u(this,"flows",{}),u(this,"flowChunks",[]),u(this,"flowListener",null),u(this,"flowToReach",null),u(this,"idToReach",null),u(this,"cascade"),u(this,"offsetMap"),u(this,"primary",!0),u(this,"primaryStack",[]),u(this,"rootBackgroundAssigned",!1),u(this,"rootLayoutAssigned",!1),u(this,"lastOffset"),u(this,"breakBeforeValues",{}),u(this,"boxStack"),u(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,o,a,e.lang),this.offsetMap=new rm;let h=e.getElementOffset(this.root);this.lastOffset=h,this.boxStack=new am(n),this.offsetMap.addStuckRange(h);let l=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,l,h),this.postprocessTopStyle(l,!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}`]=l,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 K(s,Wl))}}}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)Xi(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&&!J(n)||s&&!J(s))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<ba.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,ba[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],s=!0;if(n&&!J(n.value)){let a=n.evaluate(this.context);if(a instanceof T){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"ex":h*=this.context.initialFontSize*me.ex/me.em;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*me.lh/me.em;break;default:{let l=me[a.unit];l&&(h*=l),s=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=s}}let r=(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 ei)this.context.rootLineHeight=a.num*r;else if(a instanceof T){let h=a.num;switch(a.unit){case"em":case"rem":h*=r;break;case"ex":h*=r*me.ex/me.em;break;case"%":h*=r/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*me.lh/me.em;break;default:{let l=me[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*me.lh/me.em}}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 ig(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=Ve(r,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,r,this.root,i);this.boxStack.empty()&&this.boxStack.push(r,i,!0,h)}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),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,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,h=!1,l=t["flow-options"];if(l){let m=md(l.evaluate(this.context,"flow-options"));o=!!m.exclusive,a=!!m.static,h=!!m.last}let c=t["flow-linger"];c&&(r=Do(c.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let p=t["flow-priority"];p&&(s=Do(p.evaluate(this.context,"flow-priority"),0));let d=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[e]=new Ap(e,m)}let g=new Lp(e,i,n,s,r,o,a,h,d);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(Ke(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]=Xe(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 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=Xe(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 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,c=a["flow-into"];if(c){let d=c.evaluate(s,"flow-into").toString(),f=this.encounteredFlowElement(d,a,o,this.lastOffset);this.primary=!!this.primaryFlows[d],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=Xe(l.flowChunk.breakBefore,l.breakBefore));let p=this.boxStack.nearestBlockStartOffset(l);if(p===0){let d=a.page,f=d&&!J(d.value)&&d.value.toString();f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,p,l.flowName),l.beforeBox){let d=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(d,l.beforeBox.atBlockStart?p: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&&p===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){}},ba=["column-count","column-width","column-fill"],pi=class{constructor(e){this.validator=e,u(this,"success",null),u(this,"failure",null),u(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)}},$t=class{constructor(e,t){this.where=e,this.success=t,u(this,"what",-1)}},Bi=class uu{constructor(){u(this,"nodes",[]),u(this,"connections",[]),u(this,"match",[]),u(this,"nomatch",[]),u(this,"error",[]),u(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 uu;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],s=new pi(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 $t(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 pi(ya);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 $t(s,!0),a=new $t(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 pi(ya);i.markAsStartAlternate(t),this.nodes.push(i);let n=new $t(0,!0),s=new $t(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 pi(t));let n=new $t(i,!0),s=new $t(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 Pe}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]}},lm=1,cu=2,du=4,Gt=8,Fn=16,wr=32,On=64,pu=128,Vi=256,Ui=512,br=1024,fu=2048,gu=4096,mu=8192,wu=class extends It{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Pe=class bu extends wu{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&lm?t:null}visitSlash(t){return this.allowed&fu?t:null}visitStr(t){return this.allowed&cu?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&du||this.allowed&On&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&Ui)?t.unit=="%"&&this.allowed&br?t:null:t.num<0&&!(this.allowed&Vi)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&Ui?t:null:t.num<=0&&!(this.allowed&Vi)?null:this.allowed&Fn?t:null}visitInt(t){return t.num==0?this.allowed&Ui?t:null:t.num<=0&&!(this.allowed&Vi)?null:this.allowed&(wr|Fn)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&On&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&pu?t:null}visitURange(t){return this.allowed&gu?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){return this.allowed&On&&CSS.supports("color",t.toString())||this.allowed&mu&&CSS.supports("background-image",t.toString())||t.name==="calc"&&this.allowed&(Gt|Fn|wr|Vi|Ui|br)?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 bu(this.allowed|t.allowed,i,n)}},ne={},ya=new Pe(0,ne,ne),to=class extends wu{constructor(e){super(),u(this,"successTerminal"),u(this,"failureTerminal"),u(this,"first"),this.successTerminal=new pi(null),this.failureTerminal=new pi(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 h=e[r],l=h;if(s.isSpecial()){let c=!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":c=a[s.getAlternate()]==null,s=c?s.success:s.failure}else{if(r==0&&!t&&s.validator instanceof Ki&&this instanceof Ki){if(l=new ke(e).visit(s.validator),l){r=e.length,s=s.success;continue}}else if(r==0&&!t&&s.validator instanceof io&&this instanceof Ki){if(l=new qe(e).visit(s.validator),l){r=e.length,s=s.success;continue}}else l=h.visit(s.validator);if(!l){s=s.failure;continue}if(l!==h&&e===n){n=[];for(let c=0;c<r;c++)n[c]=e[c]}e!==n&&(n[r-i]=l),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}},Ki=class extends to{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ke(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof io){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new qe(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},io=class extends to{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 qe(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}},hm=class extends to{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 ki(e.name,t):null}},yu=class{tryParse(e,t,i){return t}success(e,t){}},vu=class extends yu{constructor(e,t){super(),this.name=t,u(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 ke(n):n[0];return this.success(r,i),t+s}return t}success(e,t){t.values[this.name]=e}},um=class extends vu{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}},cm=class extends yu{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==es){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}},no=class extends It{constructor(){super(...arguments),u(this,"syntax",null),u(this,"propList",null),u(this,"error",!1),u(this,"values",{}),u(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new vu(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: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)}},Ri=class extends no{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}},xu=class extends no{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 um(this.validatorSet,this.propList)}},dm=class extends no{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===es){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}},pm=class extends Ri{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:v.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 qe?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 qe(t[i]);return null}},fm=class extends Ri{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]===es){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 ke(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 qe(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}},gm=class extends Ri{validateList(e){if(e.length===1&&e[0]instanceof ft)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)}},mm=["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","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"],wm=class extends Ri{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)mm.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},va={SIMPLE:Ri,INSETS:xu,INSETS_SLASH:dm,COMMA:pm,FONT:fm,TEXT_SPACING:gm,ALL:wm},bm=class{constructor(){u(this,"validators",{}),u(this,"prefixes",{}),u(this,"defaultValues",{}),u(this,"namedValidators",{}),u(this,"systemFonts",{}),u(this,"shorthands",{}),u(this,"layoutProps",{}),u(this,"backgroundProps",{})}addReplacement(e,t){let i;if(t.type==3)i=new T(t.num,t.text);else if(t.type==7)i=new El(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 s in n)n[s]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Bi;if(e=="||"){for(let s=0;s<t.length;s++){let r=new Bi;r.startClause(s),r.addGroup(t[s],1),r.endClause(s),i.addGroup(r,s==0?1:4)}let n=new Bi;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 Bi;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 Bi;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new io(t);break;case"SPACE":i=new Ki(t);break;default:i=new hm(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Pe(On,ne,ne)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Pe(mu,ne,ne)),this.namedValidators.POS_INT=this.primitive(new Pe(wr,ne,ne)),this.namedValidators.POS_NUM=this.primitive(new Pe(Fn,ne,ne)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Pe(Gt,ne,{"%":G})),this.namedValidators.NEGATIVE=this.primitive(new Pe(Vi,ne,ne)),this.namedValidators.ZERO=this.primitive(new Pe(Ui,ne,ne)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Pe(br,ne,ne)),this.namedValidators.POS_LENGTH=this.primitive(new Pe(Gt,ne,{em:G,ex:G,ch:G,rem:G,lh:G,rlh:G,vw:G,vh:G,vi:G,vb:G,vmin:G,vmax:G,pvw:G,pvh:G,pvi:G,pvb:G,pvmin:G,pvmax:G,cm:G,mm:G,in:G,px:G,pt:G,pc:G,q:G})),this.namedValidators.POS_ANGLE=this.primitive(new Pe(Gt,ne,{deg:G,grad:G,rad:G,turn:G})),this.namedValidators.POS_TIME=this.primitive(new Pe(Gt,ne,{s:G,ms:G})),this.namedValidators.FREQUENCY=this.primitive(new Pe(Gt,ne,{Hz:G,kHz:G})),this.namedValidators.RESOLUTION=this.primitive(new Pe(Gt,ne,{dpi:G,dpcm:G,dppx:G})),this.namedValidators.URI=this.primitive(new Pe(pu,ne,ne)),this.namedValidators.URANGE=this.primitive(new Pe(gu,ne,ne)),this.namedValidators.IDENT=this.primitive(new Pe(du,ne,ne)),this.namedValidators.STRING=this.primitive(new Pe(cu,ne,ne)),this.namedValidators.SLASH=this.primitive(new Pe(fu,ne,ne));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 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)},h=c=>{if(o)throw new Error(`'${c}': unexpected`);if(s&&s!=c)throw new Error(`mixed operators: '${c}' and '${s}'`);s=c,o=!0},l=null;for(;!l;){e.consume();let c=e.token();switch(c.type){case 1:if(o||h(" "),this.isBuiltIn(c.text)){let p=this.namedValidators[c.text];if(!p)throw new Error(`'${c.text}' unexpected`);i.push(p.clone())}else{let p={};p[c.text.toLowerCase()]=B(c.text),i.push(this.primitive(new Pe(0,p,ne)))}o=!1;break;case 5:{let p={};p[`${c.num}`]=new Jt(c.num),i.push(this.primitive(new Pe(0,p,ne))),o=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:o||h(" "),n.push({vals:i,op:s,b:"["}),s="",i=[],o=!0;break;case 6:o||h(" "),n.push({vals:i,op:s,b:"(",fn:c.text}),s="",i=[],o=!0;break;case 15:{r=a();let p=n.pop();if(p.b!="[")throw new Error("']' unexpected");i=p.vals,i.push(r),s=p.op,o=!1;break}case 11:{r=a();let p=n.pop();if(p.b!="(")throw new Error("')' unexpected");i=p.vals,i.push(this.newFunc(p.fn,r)),s=p.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(),c=e.token(),c.type!=5)throw new Error("<int> expected");let p=c.num,d=p;if(e.consume(),c=e.token(),c.type==16){if(e.consume(),c=e.token(),c.type!=5)throw new Error("<int> expected");d=c.num,e.consume(),c=e.token()}if(c.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),p,d));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 Ki(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 ei(n.num));break;case 5:i.push(new Jt(n.num));break;case 3:i.push(new T(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new ke(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&va[i.text]?(n=new va[i.text],e.consume()):n=new Ri,n.setOwner(this);let s=!1,r=[],o=!1,a=[],h=[];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("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof xu){let l=this.shorthands[i.text];r.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(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 l=new cm(r,o),c=a.pop();r=c.syntax,o=c.slash,r.push(l);break}case 17:s=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(r,h),this.shorthands[t]=n}}parse(e){let t=new gt(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:v.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){if(Nt(e)||n.ruleType==="font-face"||vm(t)){n.simpleProperty(e,t,i);return}let s="",r=e;e=e.toLowerCase();let o=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);o&&(s=o[1],e=o[2]);let a=this.prefixes[e];if(!a||!a[s]){CSS.supports(e,t.toString())?n.simpleProperty(r,t,i):n.unknownProperty(r,t);return}let h=this.validators[e];if(h){let l=J(t)||t.isExpr()?t:t.visit(h);l?n.simpleProperty(e,l,i):!s&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(r,t)}else{let l=this.shorthands[e].clone();J(t)?l.propagateDefaultingValue(t,i,n):(t.visit(l),l.finish(i,n)||n.invalidPropertyValue(r,t))}}};function Su(){let e=new bm;return e.initBuiltInValidators(),e.parse(zl),e}var ym=class extends It{constructor(){super(...arguments),u(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function vm(e){let t=new ym;return e.visit(t),t.varFound}var ln={"font-style":v.auto,"font-stretch":v.auto,"font-weight":v.auto,"unicode-range":sd},Yw=`OTTO${new Date().valueOf()}`;function xm(e){let t=new kt;for(let i in ln)t.append(" "),t.append(e[i].toString());return t.toString()}function Sm(e){for(let t in ln)e[t]||(e[t]=ln[t])}function Cm(e,t){let i={};for(let n in e)i[n]=Ve(e,n).evaluate(t,n);return Sm(i),i}var Cu=class{constructor(e){this.properties=e,u(this,"fontTraitKey"),u(this,"src"),u(this,"blobURLs",[]),u(this,"blobs",[]),u(this,"family"),this.fontTraitKey=xm(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 kt;i.append(`@font-face {
|
|
1478
|
+
`;function ss(e,t,i,n,s){let r=F("ajax"),o=new XMLHttpRequest,a=r.suspend(o),h={status:0,statusText:"",url:e,contentType:null,responseText:null,responseXML:null,responseBlob:null};o.open(i||"GET",e,!0),t&&(o.responseType=t),o.onreadystatechange=()=>{if(o.readyState===4){if(h.status=o.status,h.url=o.responseURL,h.statusText=o.statusText||o.status==404&&"Not Found"||"",h.status==200||h.status==0)if((!t||t==="document")&&o.responseXML&&o.responseXML.documentElement.localName!="parsererror")h.responseXML=o.responseXML,h.contentType=o.responseXML.contentType;else if((!t||t==="document")&&o.response instanceof Document)h.responseXML=o.response,h.contentType=o.response.contentType;else{let l=o.response;(!t||t==="text")&&typeof l=="string"?h.responseText=l:l?typeof l=="string"?h.responseBlob=Gl([l]):h.responseBlob=l:D.warn("Unexpected empty success response for",e);let c=o.getResponseHeader("Content-Type");c&&(h.contentType=c.replace(/(.*);.*$/,"$1"))}a.schedule(h)}};try{n?(o.setRequestHeader("Content-Type",s||"text/plain; charset=UTF-8"),o.send(n)):(/^file:|^https?:\/\/[^/]+\.githubusercontent\.com|\.(xhtml|xht|opf)$/i.test(e)?/\/aozorabunko\/[^/]+\/cards\/[^/]+\/files\/[^/.]+\.html$/.test(e)?o.overrideMimeType("text/html; charset=Shift_JIS"):/\.(html|htm)$/i.test(e)?o.overrideMimeType("text/html; charset=UTF-8"):/\.(xhtml|xht|xml|opf)$/i.test(e)?o.overrideMimeType("application/xml; charset=UTF-8"):/\.(txt|css)$/i.test(e)?o.overrideMimeType("text/plain; charset=UTF-8"):o.overrideMimeType("text/html; charset=UTF-8"):/^data:,(<|%3c)/i.test(e)?o.overrideMimeType("text/html; charset=UTF-8"):/^data:,/i.test(e)&&o.overrideMimeType("text/plain; charset=UTF-8"),o.send(null))}catch(l){D.warn(l,`Error fetching ${e}`),a.schedule(h)}return r.result()}function Gl(e,t){let i=t||"application/octet-stream";return new Blob(e,{type:i})}function tp(e){let t=F("readBlob"),i=new FileReader,n=t.suspend(i);return i.addEventListener("load",()=>{n.schedule(i.result)},!1),i.readAsArrayBuffer(e),t.result()}function ip(e){return URL.createObjectURL(e)}var _r=class{constructor(e,t){this.parser=e,this.type=t,u(this,"resources",{}),u(this,"fetchers",{})}load(e,t,i){e=Ct(e);let n=this.resources[e];return typeof n<"u"?k(n):this.fetch(e,t,i).get()}fetchInner(e,t,i){let n=F("fetch"),s=e.endsWith("?viv-toc-box");s&&(e=e.replace("?viv-toc-box",""));let r=Ee("user-agent.xml",Kt),o=!s&&e===r;return o&&(e=`data:application/xml,${encodeURIComponent(Dl)}`),ss(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(h=>{delete this.fetchers[e],this.resources[e]=h,n.finish(h)})}),n.result()}fetch(e,t,i){if(e=Ct(e),this.resources[e])return null;let n=this.fetchers[e];return n||(n=new fn(()=>this.fetchInner(e,t,i),`Fetch ${e}`),this.fetchers[e]=n,n.start()),n}get(e){return this.resources[Ct(e)]}delete(e){delete this.resources[Ct(e)]}};function np(e,t){let i=e.responseText;return k(i?Pr(i):null)}function sp(){return new _r(np,"text")}function si(e,t,i){let n=new fn(()=>{let s=F("loadElement"),r=s.suspend(e),o=!1,a=h=>{o||(o=!0,r.schedule(h?h.type:"timeout"))};return e.addEventListener("load",a,!1),e.addEventListener("error",a,!1),e.addEventListener("abort",a,!1),e.namespaceURI=="http://www.w3.org/2000/svg"?(t&&e.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",t),setTimeout(a,300)):e.localName==="script"?setTimeout(a,3e3):t&&(e.src=t,i&&(e.alt=i)),s.result()},`loadElement ${t||e.localName}`);return n.start(),n}var Ho=0,rp=16777216,Wl=33554432,jl=50331648,Xl=67108864,op=83886080,ap=100663296,Mr=class{constructor(e){this.scope=e,u(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(){}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){}endFuncWithSelector(){}pushSelectorText(e){}getImportantSpecificity(){switch(this.flavor){case"UA":return Ho;case"User":return ap;default:return op}}getBaseSpecificity(){switch(this.flavor){case"UA":return Ho;case"User":return rp;default:return Wl}}},lp=class extends Mr{constructor(){super(null),u(this,"stack",[]),u(this,"tokenizer",null),u(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;D.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()}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){this.slave.startFuncWithSelector(e)}endFuncWithSelector(){this.slave.endFuncWithSelector()}pushSelectorText(e){this.slave.pushSelectorText(e)}},$o=class extends Mr{constructor(e,t,i){super(e),this.owner=t,this.topLevel=i,u(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 $o{constructor(e,t,i){super(e,t,i)}report(e){this.error(e,this.getCurrentToken())}reportAndSkip(e){this.report(e),this.owner.pushHandler(new $o(this.scope,this.owner,!1))}startSelectorRule(){this.reportAndSkip("E_CSS_UNEXPECTED_SELECTOR")}startFontFaceRule(){this.reportAndSkip("E_CSS_UNEXPECTED_FONT_FACE")}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){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())}},Ce=[],Vn=[],pe=[],Se=[],ot=[],Qe=[],xe=[],Le=[],ue=[],Me=[],je=[],_e=[],ve=[],ri=55,oi=56,Cn=57;Ce[1]=28,Ce[36]=29,Ce[7]=29,Ce[9]=29,Ce[14]=29,Ce[18]=29,Ce[50]=29,Ce[20]=30,Ce[13]=27,Ce[0]=200,Vn[1]=46,Vn[0]=200,Qe[1]=2,Qe[36]=4,Qe[7]=6,Qe[9]=8,Qe[14]=10,Qe[18]=14,Qe[50]=42,pe[37]=11,pe[23]=12,pe[35]=56,pe[1]=1,pe[36]=3,pe[7]=5,pe[9]=7,pe[14]=9,pe[12]=13,pe[18]=55,pe[50]=58,pe[16]=41,Se[37]=11,Se[23]=12,Se[35]=56,Se[1]=1,Se[36]=3,Se[7]=5,Se[9]=7,Se[14]=9,Se[18]=55,ot[1]=2,ot[36]=4,ot[7]=6,ot[9]=8,ot[18]=14,ot[50]=42,ot[14]=10,ot[12]=13,xe[1]=15,xe[7]=16,xe[4]=17,xe[5]=18,xe[3]=19,xe[2]=20,xe[8]=21,xe[27]=57,xe[16]=22,xe[19]=23,xe[6]=24,xe[11]=25,xe[17]=26,xe[13]=48,xe[31]=47,xe[23]=54,xe[0]=44,Le[1]=31,Le[4]=32,Le[5]=32,Le[3]=33,Le[2]=34,Le[10]=40,Le[6]=38,Le[31]=36,Le[24]=36,Le[32]=35,ue[1]=45,ue[16]=37,ue[37]=37,ue[38]=37,ue[47]=37,ue[48]=37,ue[39]=37,ue[49]=37,ue[41]=37,ue[26]=37,ue[25]=37,ue[23]=37,ue[24]=37,ue[19]=37,ue[21]=37,ue[36]=37,ue[18]=37,ue[22]=37,ue[11]=39,ue[12]=43,ue[17]=49,Me[0]=200,Me[12]=50,Me[13]=51,Me[14]=50,Me[15]=51,Me[10]=50,Me[11]=51,Me[17]=53,je[0]=200,je[12]=50,je[13]=52,je[14]=50,je[15]=51,je[10]=50,je[11]=51,je[17]=53,_e[0]=200,_e[12]=50,_e[13]=51,_e[14]=50,_e[15]=51,_e[10]=50,_e[11]=51,ve[11]=0,ve[16]=0,ve[22]=1,ve[18]=1,ve[26]=2,ve[25]=2,ve[38]=3,ve[37]=3,ve[48]=3,ve[47]=3,ve[39]=3,ve[49]=3,ve[41]=3,ve[23]=4,ve[24]=4,ve[36]=5,ve[19]=5,ve[21]=5,ve[0]=6,ve[ri]=2,ve[oi]=2;var mn=class{constructor(e,t,i,n){this.actions=e,this.tokenizer=t,this.handler=i,this.baseURL=n,u(this,"valStack",[]),u(this,"namespacePrefixToURI",{}),u(this,"defaultNamespaceURI",null),u(this,"propName",null),u(this,"propImportant",!1),u(this,"exprContext"),u(this,"result",null),u(this,"importReady",!1),u(this,"importURL",null),u(this,"importCondition",null),u(this,"errorBrackets",[]),u(this,"ruleStack",[]),u(this,"regionRule",!1),u(this,"pageRule",!1),u(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(G)}return i}valStackReduce(e,t){let i=this.valStack,n=i.length,s=0,r;do if(r=i[--n],e===")"&&r instanceof Ai){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 ke(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=je);let h=new ki(i[n-1],this.extractVals(",",n+1));if(i.splice(n-1,o+2,h),h.name==="var"){let l=h.values[0]instanceof ft&&h.values[0].name;(!Nt(l)||l===this.propName)&&(this.handler.error(`E_CSS_INVALID_VAR ${h.toString()}`,t),this.actions=je)}return h}if(e!=";"||n>=0)return this.handler.error("E_CSS_UNEXPECTED_VAL_END",t),this.actions=je,null;if(o>1)return new qe(this.extractVals(",",n+1));let a=i[0];return a instanceof $e?a:a?new Ai(a.toString()):G}exprError(e,t){this.actions=this.propName?je:Me,D.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 h=a.shift(),l=a.shift(),c=new jc(n.getScope(),h,l);a.unshift(c)}return i.push(new V(a[0])),!0}else if(o=="("){let h=i.pop(),l=i.pop();s=new $i(n.getScope(),_s(l,h),a),e=0;continue}}if(o==10){s.isMediaName()&&(s=new Ro(n.getScope(),s,null)),e=0;continue}}else if(typeof o=="string"){i.push(o);break}if(o<0)if(o==-31)s=new Ot(n.getScope(),s);else if(o==-24)s=new cl(n.getScope(),s);else if(o==-Cn)s=new Gc(n.getScope(),s);else return this.exprError("F_UNEXPECTED_STATE",t),!1;else{if(ve[e]>ve[o]){i.push(o);break}switch(r=i.pop(),o){case 26:s=new Rr(n.getScope(),r,s);break;case ri:s=new Wc(n.getScope(),r,s);break;case oi:s=new Xc(n.getScope(),r,s);break;case 25:s=new Ar(n.getScope(),r,s);break;case 38:s=new qc(n.getScope(),r,s);break;case 37:s=new Kc(n.getScope(),r,s);break;case 48:s=new Yc(n.getScope(),r,s);break;case 47:s=new Ds(n.getScope(),r,s);break;case 39:case 49:s=new Lr(n.getScope(),r,s);break;case 41:s=new Zc(n.getScope(),r,s);break;case 23:s=new dl(n.getScope(),r,s);break;case 24:s=new pl(n.getScope(),r,s);break;case 36:s=new Fr(n.getScope(),r,s);break;case 19:s=new fl(n.getScope(),r,s);break;case 21:s=new gl(n.getScope(),r,s);break;case 18:if(i.length>1)switch(i[i.length-1]){case 22:i.pop(),s=new ed(n.getScope(),i.pop(),r,s);break;case 10:if(r.isMediaName())s=new Ro(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 c=i.nthToken(1),p=i.nthToken(2);if(c.type===1&&p.type===18)i.consume(),i.consume(),s=c.text,n=p.position+1;else{if(c.type===10||c.type===6||c.type===1&&c.text.toLowerCase()==="not"&&(p.type===10||p.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 h=o.position,l=t&&s==="selector"&&a>0?"":i.input.substring(n,h).trim();return new td(this.handler.getScope(),s,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 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=lt(i,t,new Ot(i,new ze(i,"pref-horizontal")));break;case"horizontal":t=lt(i,t,new ze(i,"pref-horizontal"));break;case"day":t=lt(i,t,new Ot(i,new ze(i,"pref-night-mode")));break;case"night":t=lt(i,t,new ze(i,"pref-night-mode"));break;default:t=i._false}}return t===i._true?null:new V(t)}isInsidePropertyOnlyRule(){switch(this.ruleStack[this.ruleStack.length-1]){case"[selector]":case"font-face":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,h=this.valStack,l,c,p,d,f,g,m,y=null;for(i&&(this.inStyleDeclaration=!0),n&&(this.exprContext=2,this.valStack.push("{"));e>0;--e){if(l=a.token(),s&&y===null&&(y=l.position-1,a.input[y]==="("&&y++),this.actions===xe&&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 Ai(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=je):(this.actions=Qe,o.startSelectorRule());continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=xe,h.splice(0,h.length);continue;case 46:if(a.nthToken(1).type!=18){this.actions=je,o.error("E_CSS_COLON_EXPECTED",a.nthToken(1));continue}this.propName=l.text,this.propImportant=!1,a.consume(),a.consume(),this.actions=xe,h.splice(0,h.length);continue;case 29:this.actions=Qe,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(),p=this.namespacePrefixToURI[l.text],p!=null)switch(l=a.token(),l.type){case 1:o.tagSelector(p,l.text),s?this.actions=Se:this.actions=pe,a.consume();break;case 36:o.tagSelector(p,null),s?this.actions=Se:this.actions=pe,a.consume();break;default:this.actions=Me,o.error("E_CSS_NAMESPACE",l)}else this.actions=Me,o.error("E_CSS_UNDECLARED_PREFIX",l);else o.tagSelector(this.defaultNamespaceURI,l.text),s?this.actions=Se:this.actions=pe,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),s?this.actions=Se:this.actions=pe,a.consume();break;case 36:o.tagSelector(null,null),s?this.actions=Se:this.actions=pe,a.consume();break;default:this.actions=Me,o.error("E_CSS_NAMESPACE",l)}else o.tagSelector(this.defaultNamespaceURI,null),s?this.actions=Se:this.actions=pe,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),s?this.actions=Se:this.actions=pe,a.consume();continue;case 7:l.precededBySpace&&o.descendantSelector();case 8:o.classSelector(l.text),s?this.actions=Se:this.actions=pe,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(),s?this.actions=Se:this.actions=pe;continue;case 6:switch(d=l.text,a.consume(),d){case"is":case"not":case"where":case"has":this.actions=Qe,o.startFuncWithSelector(d),this.runParser(Number.POSITIVE_INFINITY,!1,!1,!1,!0,d==="has")?this.actions=pe:this.actions=_e;continue;case"lang":case"href-epub-type":if(l=a.token(),l.type===1){m=[l.text],a.consume(),d==="href-epub-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)break;break e;default:m=this.readPseudoParams()}if(l=a.token(),l.type==11){o.pseudoclassSelector(d,m),a.consume(),s?this.actions=Se:this.actions=pe;continue}break}o.error("E_CSS_PSEUDOCLASS_SYNTAX",l),this.actions=Me;continue;case 58:l.precededBySpace&&o.descendantSelector();case 42:switch(a.consume(),l=a.token(),l.type){case 1:o.pseudoelementSelector(l.text,null),s?this.actions=Se:this.actions=pe,a.consume();continue;case 6:if(d=l.text,a.consume(),d=="nth-fragment"){if(m=this.readNthPseudoParams(),m===null)break}else m=this.readPseudoParams();if(l=a.token(),l.type==11){o.pseudoelementSelector(d,m),s?this.actions=Se:this.actions=pe,a.consume();continue}break}o.error("E_CSS_PSEUDOELEM_SYNTAX",l),this.actions=Me;continue;case 9:l.precededBySpace&&o.descendantSelector();case 10:if(a.consume(),l=a.token(),l.type==1)d=l.text,a.consume();else if(l.type==36)d=null,a.consume();else if(l.type==34)d="";else{this.actions=_e,o.error("E_CSS_ATTR",l),a.consume();continue}if(l=a.token(),l.type==34){if(p=d&&this.namespacePrefixToURI[d],p===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}d=l.text,a.consume(),l=a.token()}else p="";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(p,d,0,null),s?this.actions=Se:this.actions=pe,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(p,d,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}s?this.actions=Se:this.actions=pe,a.consume();continue;case 11:o.childSelector(),this.actions=ot,a.consume();continue;case 12:o.adjacentSiblingSelector(),this.actions=ot,a.consume();continue;case 56:o.followingSiblingSelector(),this.actions=ot,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=Ce,a.consume();continue;case 41:o.nextSelector(),this.actions=Qe,a.consume();continue;case 15:h.push(B(l.text)),a.consume();continue;case 16:f=parseInt(l.text,16),h.push(new El(l.text)),a.consume();continue;case 17:h.push(new ei(l.num)),a.consume();continue;case 18:h.push(new Jt(l.num)),a.consume();continue;case 19:h.push(new T(l.num,l.text)),a.consume();continue;case 20:h.push(new Ae(l.text)),a.consume();continue;case 21:h.push(new ct(Ee(l.text,this.baseURL))),a.consume();continue;case 57:h.push(new kl(l.text)),a.consume();continue;case 22:this.valStackReduce(",",l),h.push(","),a.consume();continue;case 23:h.push(es),a.consume();continue;case 24:d=l.text.toLowerCase(),d=="-epubx-expr"||d=="env"?(this.actions=Le,this.exprContext=0,h.push("{")):(h.push(d),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(),c=a.nthToken(1),l.type==1&&l.text.toLowerCase()=="important"&&(c.type==17||c.type==0||c.type==13)){a.consume(),this.propImportant=!0;continue}this.exprError("E_CSS_SYNTAX",l);continue;case 54:switch(c=a.nthToken(1),c.type){case 4:case 3:case 5:if(!c.precededBySpace){a.consume();continue}}h.push(new Ai("+")),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?Vn:Ce;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(c=a.nthToken(1),c.type==9)a.nthToken(2).type==10&&!a.nthToken(2).precededBySpace?(h.push(l.text,c.text,"("),a.consume()):(h.push(new ze(o.getScope(),_s(l.text,c.text))),this.actions=ue),a.consume();else{if(this.exprContext==2||this.exprContext==3)l.text.toLowerCase()=="not"?(a.consume(),h.push(new Io(o.getScope(),!0,c.text))):(l.text.toLowerCase()=="only"&&(a.consume(),l=c),h.push(new Io(o.getScope(),!1,l.text)));else if(this.exprContext===4&&l.text.toLowerCase()==="not"&&h[h.length-1]!==ri&&h[h.length-1]!==oi&&(c.type===10||c.type===6)){h.push(-Cn),a.consume();continue}else h.push(new ze(o.getScope(),l.text));this.actions=ue}a.consume();continue;case 38:if(this.exprContext===4){h.push(this.readSupportsTest(l)),this.actions=ue;continue}h.push(null,l.text,"("),a.consume();continue;case 32:h.push(new Fe(o.getScope(),l.num)),a.consume(),this.actions=ue;continue;case 33:d=l.text,d=="%"&&(this.propName&&this.propName.match(/height|^(top|bottom)$/)?d="vh":d="vw"),h.push(new Zt(o.getScope(),l.num,d)),a.consume(),this.actions=ue;continue;case 34:h.push(new Fe(o.getScope(),l.text)),a.consume(),this.actions=ue;continue;case 35:a.consume(),l=a.token(),l.type!=5||l.precededBySpace?this.exprError("E_CSS_SYNTAX",l):(h.push(new yl(o.getScope(),l.num)),a.consume(),this.actions=ue);continue;case 36:h.push(-l.type),a.consume();continue;case 37:this.actions=Le,this.exprStackReduce(l.type,l),h.push(l.type),a.consume();continue;case 45:l.text.toLowerCase()==="and"&&h[h.length-2]!==oi&&h[h.length-2]!==-Cn?(this.actions=Le,this.exprStackReduce(ri,l),h.push(ri),a.consume()):l.text.toLowerCase()==="or"&&h[h.length-2]!==ri&&h[h.length-2]!==-Cn?(this.actions=Le,this.exprStackReduce(oi,l),h.push(oi),a.consume()):this.exprError("E_CSS_SYNTAX",l);continue;case 39:this.exprStackReduce(l.type,l)&&(this.actions=xe),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=Ce)),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=Ce,a.consume(),!1):(this.importCondition=h.pop(),this.importReady=!0,this.actions=Ce,a.consume(),!1);a.consume();continue;case 40:if(this.exprContext===4){let b=this.readSupportsTest(l);if(b){h.push(b),this.actions=ue;continue}}h.push(l.type),a.consume();continue;case 27:if(this.actions=Ce,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(d=l.text.toLowerCase(),d){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=Le,h.push("{");continue}o.error("E_CSS_IMPORT_SYNTAX",l),this.actions=Me;continue;case"namespace":switch(a.consume(),l=a.token(),l.type){case 1:if(d=l.text,a.consume(),l=a.token(),(l.type==2||l.type==8)&&a.nthToken(1).type==17){this.namespacePrefixToURI[d]=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=Me;continue;case"charset":if(a.consume(),l=a.token(),l.type==2&&a.nthToken(1).type==17){d=l.text.toLowerCase(),d!="utf-8"&&d!="utf-16"&&o.error(`E_CSS_UNEXPECTED_CHARSET ${d}`,l),a.consume(),a.consume();continue}o.error("E_CSS_CHARSET_SYNTAX",l),this.actions=Me;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(),d){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(d),o.startRuleBody();continue}break;case"-adapt-footnote-area":switch(a.consume(),l=a.token(),l.type){case 12:a.consume(),o.startFootnoteRule(null),this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue;case 50:if(a.consume(),l=a.token(),l.type==1&&a.nthToken(1).type==12){d=l.text,a.consume(),a.consume(),o.startFootnoteRule(d),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=Qe;continue;case"page":a.consume(),o.startPageRule(),this.pageRule=!0,this.actions=ot;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(),l=a.token(),l.type==12){a.consume(),o.startPageMarginBoxRule(d),this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break;case"-epubx-when":a.consume(),this.propName=null,this.exprContext=1,this.actions=Le,h.push("{");continue;case"media":a.consume(),this.propName=null,this.exprContext=2,this.actions=Le,h.push("{");continue;case"supports":a.consume(),this.propName=null,this.exprContext=4,this.actions=Le,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(d),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,w=null,S=[];for(l.type==1&&(b=l.text,a.consume(),l=a.token()),l.type==18&&a.nthToken(1).type==1&&(w=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;)S.push(a.nthToken(1).text),a.consume(),a.consume(),a.consume(),l=a.token();if(l.type==12){switch(a.consume(),d){case"-epubx-page-master":o.startPageMasterRule(b,w,S);break;case"-epubx-partition":o.startPartitionRule(b,w,S);break;case"-epubx-partition-group":o.startPartitionGroupRule(b,w,S);break}this.ruleStack.push(d),o.startRuleBody(),this.inStyleDeclaration=!0;continue}break}case"":o.error(`E_CSS_UNEXPECTED_AT${d}`,l),this.actions=_e;continue;default:o.error(`E_CSS_AT_UNKNOWN ${d}`,l),this.actions=Me;continue}o.error(`E_CSS_AT_SYNTAX ${d}`,l),this.actions=Me;continue;case 50:this.errorBrackets.push(l.type+1),a.consume();continue;case 52:if(this.errorBrackets.length==0){this.actions=Ce;continue}case 51:if(s&&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=Ce),a.consume();continue;case 53:this.errorBrackets.length==0&&(this.actions=Ce),a.consume();continue;case 200:return!0;default:if(n)return this.exprStackReduce(11,l)?(this.result=h.pop(),!0):!1;if(s){switch(l.type){case 16:case 11:if(this.actions===Qe)o.error("E_CSS_SYNTAX",l);else{let b=a.input.substring(y,l.position);o.pushSelectorText(b),y=l.position+1}if(l.type===16){o.nextSelector(),this.actions=Qe,a.consume();continue}else return o.endFuncWithSelector(),a.consume(),!0;case 37:case 23:case 35:if(r){this.actions=pe;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!==Me&&this.actions!==_e&&this.actions!==je){if(l.type==54)o.error("E_CSS_SYNTAX",l);else if(this.actions===xe){switch(l.type){case 10:case 12:case 14:this.errorBrackets.push(l.type+1);break}h.push(new Ai(l.toString())),a.consume();continue}else if(l.type===12&&this.actions==Le&&h.length>0){o.startMediaRule(h.pop()),this.ruleStack.push("media"),o.startRuleBody(),this.actions=Ce,a.consume();continue}else{if(l.type===17&&this.actions==Le)return this.actions=Ce,a.consume(),!1;o.error("E_CSS_SYNTAX",l)}this.isInsidePropertyOnlyRule()?this.actions=je:this.actions=_e;continue}a.consume();continue}}return!1}},ql=class extends Mr{constructor(e){super(null),this.scope=e}error(e,t){D.warn(e,t.toString())}getScope(){return this.scope}};function hp(e,t,i,n,s){let r=F("parseStylesheet"),o=new mn(Ce,e,t,i),a=null;return s&&(a=cp(new gt(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 l=Ee(o.importURL,i);o.importCondition&&(t.startMediaRule(o.importCondition),t.startRuleBody());let c=F("parseStylesheet.import");return Yl(l,t,null,null).then(()=>{o.importCondition&&t.endRule(),o.importReady=!1,o.importURL=null,o.importCondition=null,c.finish(!0)}),c.result()}let h=r.timeSlice();if(h.isPending)return h}return k(!1)}).then(()=>{a&&t.endRule(),r.finish(!0)}),r.result()}function zr(e,t,i,n,s){return vi("parseStylesheetFromText",r=>{let o=new gt(e,t);hp(o,t,i,n,s).thenFinish(r)},(r,o)=>{D.warn(o,`Failed to parse stylesheet text: ${e}`),r.finish(!1)})}function Yl(e,t,i,n){return vi("parseStylesheetFromURL",s=>{ss(e).then(r=>{r.responseText?zr(r.responseText,t,e,i,n).then(o=>{o||D.warn(`Failed to parse stylesheet from ${e}`),s.finish(!0)}):s.finish(!0)})},(s,r)=>{D.warn(r,"Exception while fetching and parsing:",e),s.finish(!0)})}function Ti(e,t,i){let n=new mn(xe,t,new ql(e),i);return n.runParser(Number.POSITIVE_INFINITY,!0,!1,!1,!1),n.result}function up(e,t,i){new mn(Vn,e,t,i).runParser(Number.POSITIVE_INFINITY,!1,!0,!1,!1)}function cp(e,t,i){let n=new mn(Le,e,t,i);return n.runParser(Number.POSITIVE_INFINITY,!1,!1,!0,!1),n.result}var dp={"z-index":!0,"column-count":!0,"flow-linger":!0,opacity:!0,page:!0,"flow-priority":!0,utilization:!0};function pp(e){return!!dp[e]}function fp(e,t,i){let n=t.evaluate(e);switch(typeof n){case"number":return pp(i)?n==Math.round(n)?new Jt(n):new ei(n):new T(n,"px");case"string":return n?Ti(t.scope,new gt(n,null),""):G;case"boolean":return n?v._true:v._false;case"undefined":return G}throw new Error("E_UNEXPECTED")}function Kl(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 h=t?a.logical:a.physical,l=t?a.physical:a.logical;return{regexp:new RegExp(`(-?)${h}(-?)`),to:`$1${l}$2`}})})}),i}function Zl(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 Jl={"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"}]}},gp=Kl(Jl,!0);function Ql(e,t,i){return Zl(e,t,i||null,gp)}var mp=Kl(Jl,!1);function eh(e,t,i){return Zl(e,t,i||null,mp)}var wp={"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 bp(e,t){let i=wp[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 Dr(e,t,i){let n={display:t.style.display,position:t.style.position,width:t.style.width,maxWidth:t.style.maxWidth,minWidth:t.style.minWidth,height:t.style.height,maxHeight:t.style.maxHeight,minHeight:t.style.minHeight},s=t.ownerDocument,r=t.parentNode,o=s.createElement("div");N(o,"position",n.position),r.insertBefore(o,t),o.appendChild(t),N(t,"width","auto"),N(t,"max-width","none"),N(t,"min-width","0"),N(t,"height","auto"),N(t,"max-height","none"),N(t,"min-height","0");function a(R){return e.getElementComputedStyle(t).getPropertyValue(R)}let h=Ka("writing-mode"),l=(h?a(h[0]):null)||a("writing-mode"),c=l==="vertical-rl"||l==="tb-rl"||l==="vertical-lr"||l==="tb-lr",p=c?"height":"width",d=c?"width":"height";function f(){return N(t,"display","block"),N(t,"position","static"),a(p)}function g(){N(t,"display","inline-block"),N(o,p,"99999999px");let R=a(p);return N(o,p,""),R}function m(){N(t,"display","inline-block"),N(o,p,"0");let R=a(p);return N(o,p,""),R}function y(){let R=f(),L=m(),_=parseFloat(R);if(_<=parseFloat(L))return L;{let U=g();return _<=parseFloat(U)?R:U}}function b(){return a(d)}function w(){throw new Error("Getting fill-available block size is not implemented")}let S={};return i.forEach(R=>{var L;let _;switch(R){case"fill-available inline size":_=f();break;case"max-content inline size":_=g();break;case"min-content inline size":_=m();break;case"fit-content inline size":_=y();break;case"fill-available block size":_=w();break;case"max-content block size":case"min-content block size":case"fit-content block size":_=b();break;case"fill-available width":_=c?w():f();break;case"fill-available height":_=c?f():w();break;case"max-content width":_=c?b():g();break;case"max-content height":_=c?g():b();break;case"min-content width":_=c?b():m();break;case"min-content height":_=c?m():b();break;case"fit-content width":_=c?b():y();break;case"fit-content height":_=c?y():b();break}_==="0px"&&t.childNodes.length===1&&((L=t.firstElementChild)==null?void 0:L.localName)==="img"&&!t.firstElementChild.complete&&(_="1px"),S[R]=parseFloat(_),N(t,"position",n.position),N(t,"display",n.display)}),N(t,"width",n.width),N(t,"max-width",n.maxWidth),N(t,"min-width",n.minWidth),N(t,"height",n.height),N(t,"max-height",n.maxHeight),N(t,"min-height",n.minHeight),r.insertBefore(t,o),r.removeChild(o),S}function _i(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 th(e){let t=e.getAttribute("data-viv-box-break");return t?t.split(" "):[]}function ih(e,t){e.setAttribute("data-viv-box-break",t.join(" "))}function it(e,t){let i=th(e);i.includes(t)||(i.push(t),ih(e,i))}function yp(e){let t=e.getAttribute("data-viv-margin-discard");return t?t.split(" "):[]}function vp(e,t){e.setAttribute("data-viv-margin-discard",t.join(" "))}function Ps(e,t){let i=yp(e);i.includes(t)||(i.push(t),vp(e,i))}function xp(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 Xs={page:!0,left:!0,right:!0,recto:!0,verso:!0,column:!0,region:!0};function Ke(e){return!!Xs[e]}var Sp={left:!0,right:!0,recto:!0,verso:!0};function tn(e){return!!Sp[e]}var Cp={avoid:!0,"avoid-page":!0,"avoid-column":!0,"avoid-region":!0};function Un(e){return!!Cp[e]}function Xe(e,t){if(e)if(t){if(tn(t))return t;if(tn(e))return e;{let i=Ke(e),n=Ke(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:Un(t)?t:Un(e)?e:t}}else return e;else return t}function Go(e){return Ke(e)?e:"auto"}ht("SIMPLE_PROPERTY",xp);var Wi=bc(vc());function Ep(e,t){return(0,Wi.default)(e,t,0)}function Wo(e){return e.reduce((t,i)=>i[0]===Wi.default.DELETE?t:t+i[1],"")}function kp(e,t){return nh(e,t,1)}function Np(e,t){return nh(e,t,-1)}function nh(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 Wi.default.INSERT:n++;break;case Wi.default.DELETE:n--,s++;break;case Wi.default.EQUAL:s++;break}if(s>t)return!0}return!1}),Math.max(Math.min(t,s-1)+n,0)}var qs;(e=>{function t(i){return i&&i.formattingContextType==="Block"}e.isInstanceOfBlockFormattingContext=t})(qs||(qs={}));var fi;(e=>{let t;(i=>(i.INLINE="inline",i.COLUMN="column",i.REGION="region",i.PAGE="page"))(t=e.FloatReference||(e.FloatReference={}))})(fi||(fi={}));var Hn;(e=>{function t(i){return i&&i.flagmentLayoutConstraintType=="AfterIfContinue"}e.isInstanceOfAfterIfContinuesLayoutConstraint=t})(Hn||(Hn={}));var Xt;(e=>{function t(n){return n?n.formattingContextType==="RepetitiveElementsOwner"||_t.isInstanceOfTableFormattingContext(n):!1}e.isInstanceOfRepetitiveElementsOwnerFormattingContext=t;function i(n){return n?n.flagmentLayoutConstraintType==="RepetitiveElementsOwner"||_t.isInstanceOfTableRowLayoutConstraint(n):!1}e.isInstanceOfRepetitiveElementsOwnerLayoutConstraint=i})(Xt||(Xt={}));var _t;(e=>{function t(n){return n&&n.formattingContextType==="Table"}e.isInstanceOfTableFormattingContext=t;function i(n){return n&&n.flagmentLayoutConstraintType==="TableRow"}e.isInstanceOfTableRowLayoutConstraint=i})(_t||(_t={}));var Pt;(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={}))})(Pt||(Pt={}));var Pp={transform:!0,"transform-origin":!0},Tp={top:!0,bottom:!0,left:!0,right:!0},Vr=class{constructor(e,t,i){this.target=e,this.name=t,this.value=i}},Ip={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 Rp(e,t){let i=Ip[t];return i?()=>{for(let n=0;n<e.length;n++)try{i(e[n])}catch{}}:null}var Ys=class Mi extends Tr{constructor(t,i){super(),this.container=t,this.bleedBox=i,u(this,"pageAreaElement",null),u(this,"delayedItems",[]),u(this,"hrefHandler"),u(this,"elementsById",{}),u(this,"dimensions",{width:0,height:0}),u(this,"isFirstPage",!1),u(this,"isLastPage",!1),u(this,"isBlankPage",!1),u(this,"isAutoPageWidth",!0),u(this,"isAutoPageHeight",!0),u(this,"spineIndex",0),u(this,"position",null),u(this,"offset",-1),u(this,"side",null),u(this,"fetchers",[]),u(this,"marginBoxes",{top:{},bottom:{},left:{},right:{}}),u(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(Mi.AUTO_PAGE_WIDTH_ATTRIBUTE,"true"):this.container.removeAttribute(Mi.AUTO_PAGE_WIDTH_ATTRIBUTE)}setAutoPageHeight(t){this.isAutoPageHeight=t,t?this.container.setAttribute(Mi.AUTO_PAGE_HEIGHT_ATTRIBUTE,"true"):this.container.removeAttribute(Mi.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||N(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],h=this.elementsById[o.observer];if(a&&h){let l=Rp(a,o.action);if(l)for(let c=0;c<h.length;c++)h[c].addEventListener(o.event,l,!1)}}}};u(Ys,"AUTO_PAGE_WIDTH_ATTRIBUTE","data-vivliostyle-auto-page-width"),u(Ys,"AUTO_PAGE_HEIGHT_ATTRIBUTE","data-vivliostyle-auto-page-height");var sh=Ys,xi="data-adapt-spec",Ze=Pt.Whitespace;function rh(e){switch(e){case"normal":case"nowrap":return Ze.IGNORE;case"pre-line":return Ze.NEWLINE;case"pre":case"pre-wrap":case"break-spaces":return Ze.PRESERVE;default:return null}}function Ue(e,t){if(!e)return!0;if(e.nodeType==1)return!1;let i=e.textContent;switch(t){case Ze.PRESERVE:return i.length==0;case Ze.NEWLINE:return!!i.match(/^[ \t]*$/);case Ze.IGNORE:default:return!!i.match(/^[ \t\r\n\f]*$/)}}var Ap=class{constructor(e,t){this.flowName=e,this.parentFlowName=t,u(this,"forcedBreakOffsets",[]),u(this,"formattingContext",null)}},Lp=class{constructor(e,t,i,n,s,r,o,a,h){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=h,u(this,"startPage",-1)}isBetter(e){return this.exclusive?!e.exclusive||this.priority>e.priority?!0:this.last:!1}};function Fp(e,t){return e.top-t.top}function Op(e,t){return t.right-e.right}function oh(e,t){var i,n;return e===t?!0:!e||!t?!1:(e.node===t.node||!!e.shadowContext&&!!t.shadowContext&&e.shadowType===Pt.ShadowType.ROOTLESS&&t.shadowType===Pt.ShadowType.ROOTLESS&&((i=e.node)==null?void 0:i.outerHTML)===((n=t.node)==null?void 0:n.outerHTML))&&e.shadowType===t.shadowType&&Zs(e.shadowContext,t.shadowContext)&&Zs(e.nodeShadow,t.nodeShadow)&&oh(e.shadowSibling,t.shadowSibling)}function Mt(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(!oh(e.steps[i],t.steps[i]))return!1;return!0}function Bp(e){return{steps:[{node:e,shadowType:rt.NONE,shadowContext:null,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:0}],offsetInNode:0,after:!1,preprocessedTextContent:null}}function $n(e,t){return{steps:[{node:e.sourceNode,shadowType:rt.NONE,shadowContext:e.shadowContext,nodeShadow:null,shadowSibling:null,formattingContext:null,fragmentIndex:t??e.fragmentIndex}],offsetInNode:0,after:!1,preprocessedTextContent:e.preprocessedTextContent}}function Gn(e,t){let i=new zi(e.node,t,0);return i.shadowType=e.shadowType,i.shadowContext=e.shadowContext,i.nodeShadow=e.nodeShadow,i.shadowSibling=e.shadowSibling?Gn(e.shadowSibling,t.copy()):null,i.formattingContext=e.formattingContext,i.fragmentIndex=e.fragmentIndex+1,i}var rt=Pt.ShadowType,Ks=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,u(this,"subShadow",null),s&&(s.subShadow=this)}equals(e){return e?this.owner===e.owner&&this.xmldoc===e.xmldoc&&this.type===e.type&&Zs(this.parentShadow,e.parentShadow):!1}};function Zs(e,t){return e===t||!!e&&!!t&&e.equals(t)}var _p=class{constructor(e,t){this.outer=e,this.count=t}},zi=class ah{constructor(t,i,n){this.sourceNode=t,this.parent=i,this.boxOffset=n,u(this,"offsetInNode",0),u(this,"after",!1),u(this,"shadowType"),u(this,"shadowContext"),u(this,"nodeShadow",null),u(this,"shadowSibling",null),u(this,"shared",!1),u(this,"inline",!0),u(this,"overflow",!1),u(this,"breakPenalty"),u(this,"display",null),u(this,"floatReference"),u(this,"floatSide",null),u(this,"clearSide",null),u(this,"floatMinWrapBlock",null),u(this,"columnSpan",null),u(this,"verticalAlign","baseline"),u(this,"captionSide","top"),u(this,"inlineBorderSpacing",0),u(this,"blockBorderSpacing",0),u(this,"flexContainer",!1),u(this,"whitespace"),u(this,"hyphenateCharacter"),u(this,"breakWord"),u(this,"establishesBFC",!1),u(this,"containingBlockForAbsolute",!1),u(this,"breakBefore",null),u(this,"breakAfter",null),u(this,"viewNode",null),u(this,"clearSpacer",null),u(this,"inheritedProps"),u(this,"vertical"),u(this,"direction"),u(this,"firstPseudo"),u(this,"lang",null),u(this,"preprocessedTextContent",null),u(this,"formattingContext"),u(this,"repeatOnBreak",null),u(this,"pluginProps",{}),u(this,"fragmentIndex",1),u(this,"afterIfContinues",null),u(this,"footnotePolicy",null),u(this,"pageType"),this.shadowType=rt.NONE,this.shadowContext=i?i.shadowContext:null,this.breakPenalty=i?i.breakPenalty:0,this.floatReference=fi.FloatReference.INLINE,this.whitespace=i?i.whitespace:Ze.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=fi.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:Ze.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 ah(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(){return{node:this.sourceNode,shadowType:this.shadowType,shadowContext:this.shadowContext,nodeShadow:this.nodeShadow,shadowSibling:this.shadowSibling?this.shadowSibling.toNodePositionStep():null,formattingContext:this.formattingContext,fragmentIndex:this.fragmentIndex}}toNodePosition(){var t,i,n;let s=this,r=[];s.shadowType===Pt.ShadowType.ROOTLESS&&(s.floatReference!==fi.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?Np(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}},zt=class lh{constructor(t){this.primary=t,u(this,"floats",null)}clone(){let t=new lh(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(!Mt(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(!Mt(this.floats[i],t.floats[i]))return!1}else if(t.floats)return!1;return!0}},Mp=class hh{constructor(t,i){this.chunkPosition=t,this.flowChunk=i}clone(){return new hh(this.chunkPosition.clone(),this.flowChunk)}isSamePosition(t){return!!t&&(this===t||this.chunkPosition.isSamePosition(t.chunkPosition))}},zp=class uh{constructor(){u(this,"positions",[]),u(this,"startBreakType",null),u(this,"breakAfter",null)}clone(){let t=new uh,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}},Dp=class ch{constructor(){u(this,"page",0),u(this,"flows",{}),u(this,"flowPositions",{}),u(this,"isBlankPage",!1),u(this,"highestSeenOffset",0),u(this,"highestSeenNode"),u(this,"lookupPositionOffset")}clone(){let t=new ch;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&&tn(n)?n:"any"}firstFlowChunkOfFlow(t){let i=this.flowPositions[t];if(!i)return null;let n=i.positions[0];return n?n.flowChunk:null}},dh=class{constructor(e){this.element=e,u(this,"left",0),u(this,"top",0),u(this,"marginLeft",0),u(this,"marginRight",0),u(this,"marginTop",0),u(this,"marginBottom",0),u(this,"borderLeft",0),u(this,"borderRight",0),u(this,"borderTop",0),u(this,"borderBottom",0),u(this,"paddingLeft",0),u(this,"paddingRight",0),u(this,"paddingTop",0),u(this,"paddingBottom",0),u(this,"width",0),u(this,"height",0),u(this,"originX",0),u(this,"originY",0),u(this,"exclusions",null),u(this,"innerShape",null),u(this,"computedBlockSize",0),u(this,"snapWidth",0),u(this,"snapHeight",0),u(this,"snapOffsetX",0),u(this,"snapOffsetY",0),u(this,"vertical",!1),u(this,"rtl",!1)}getInsetTop(){return this.marginTop+this.borderTop+this.paddingTop}getInsetBottom(){return this.marginBottom+this.borderBottom+this.paddingBottom}getInsetLeft(){return this.marginLeft+this.borderLeft+this.paddingLeft}getInsetRight(){return this.marginRight+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}setVerticalPosition(e,t){this.top=e,this.height=t,N(this.element,"top",`${e}px`),N(this.element,"height",`${t}px`)}setHorizontalPosition(e,t){this.left=e,this.width=t,N(this.element,"left",`${e}px`),N(this.element,"width",`${t}px`)}setBlockPosition(e,t){if(this.vertical){let i=t+this.marginLeft+this.marginRight+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.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.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):Br(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 nt(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 nt(e,t,e+i,t+n)}getOuterShape(e,t){let i=this.getOuterRect();return Al(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 nt(e,t,e+i,t+n)}},Wn=class extends It{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.url)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=Ti(t.scope,new gt(i,null),"").stringValue()),this.elem.ownerDocument;let n=this.exprContentListener(t,i,this.elem.ownerDocument);!n&&i&&t instanceof De&&t.str.startsWith("running-element-")&&(i=""),this.visitStrInner(i,n)}return null}};function Dt(e){return e!=null&&e!==G&&e!==v.normal&&e!==v.none&&!J(e)}var Re=fi.FloatReference;function Vp(e){switch(e){case"inline":return Re.INLINE;case"column":return Re.COLUMN;case"region":return Re.REGION;case"page":return Re.PAGE;default:throw new Error(`Unknown float-reference: ${e}`)}}function gi(e){switch(e){case Re.INLINE:return!1;case Re.COLUMN:case Re.REGION:case Re.PAGE:return!0;default:throw new Error(`Unknown float-reference: ${e}`)}}function Up(e,t,i){let n=t?"vertical-rl":"horizontal-tb";if((e==="top"||e==="bottom")&&(e=eh(e,n,i)),e==="block-start"&&(e="inline-start"),e==="block-end"&&(e="inline-end"),e==="inline-start"||e==="inline-end"){let s=Ql(e,n,i),r=bp(s,n);r==="line-left"?e="left":r==="line-right"&&(e="right")}return e!=="left"&&e!=="right"&&(D.warn(`Invalid float value: ${e}. Fallback to left.`),e="left"),e}var ph=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,u(this,"order",null),u(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}},Hp=class{constructor(){u(this,"floats",[]),u(this,"nextPageFloatIndex",0)}nextOrder(){return this.nextPageFloatIndex++}createPageFloatId(e){return`pf${e}`}addPageFloat(e){if(this.floats.findIndex(t=>Mt(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=>Mt(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}},fh=class{constructor(e,t,i,n,s){this.floatReference=e,this.floatSide=t,this.continuations=i,this.area=n,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}},jo=class{constructor(e,t){this.float=e,this.nodePosition=t}equals(e){return e?this===e?!0:this.float===e.float&&Mt(this.nodePosition,e.nodePosition):!1}},Di=class{constructor(e,t,i,n,s,r,o){this.parent=e,this.floatReference=t,this.container=i,this.flowName=n,this.generatingNodePosition=s,u(this,"children",[]),u(this,"writingMode"),u(this,"direction"),u(this,"invalidated",!1),u(this,"floatStore"),u(this,"forbiddenFloats",[]),u(this,"floatFragments",[]),u(this,"stashedFloatFragments",[]),u(this,"floatAnchors",{}),u(this,"floatsDeferredToNext",[]),u(this,"floatsDeferredFromPrevious"),u(this,"layoutConstraints",[]),u(this,"locked",!1),e&&e.children.push(this),this.writingMode=r||e&&e.writingMode||v.horizontal_tb,this.direction=o||e&&e.direction||v.ltr,this.floatStore=e?e.floatStore:new Hp;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&&Mt(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 Si().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===Re.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();return eh(e,t,i)}toPhysical(e){let t=this.writingMode.toString(),i=this.direction.toString();return Ql(e,t,i)}removeEndFloatFragments(e){let t=this.toLogical(e);if(t==="block-end"||t==="inline-end"){let i=0;for(;i<this.floatFragments.length;){let n=this.floatFragments[i];this.toLogical(n.floatSide)===t?this.removePageFloatFragment(n):i++}}}stashEndFloatFragments(e){let t=e.floatReference;if(t!==this.floatReference){this.getParent(t).stashEndFloatFragments(e);return}let i=this.toLogical(e.floatSide);if(i==="block-end"||i==="snap-block"||i==="inline-end"){let n=0;for(;n<this.floatFragments.length;){let s=this.floatFragments[n],r=this.toLogical(s.floatSide);(r===i||i==="snap-block"&&r==="block-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){this.container;let s=this.toLogical(e),r=this.toPhysical(e),o=this.getLimitValueInner(s,t,i,n);if(this.parent&&this.parent.container){let a=this.parent.getLimitValue(r,t,i,n);switch(r){case"top":return Math.max(o,a);case"left":return Math.max(o,a);case"bottom":return Math.min(o,a);case"right":return Math.min(o,a);default:}}return o}getLimitValueInner(e,t,i,n){this.container;let s=this.getLimitValuesInner(t,i,n);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){this.container;let n=this.container.originX,s=this.container.originY,r=this.container.getPaddingRect(),o={top:r.y1-s,left:r.x1-n,bottom:r.y2-s,right:r.x2-n,floatMinWrapBlockStart:0,floatMinWrapBlockEnd:0};function a(l,c,p){return l.unit==="%"?p*l.num/100:e.convertLengthToPx(l,c,t)}let h=this.floatFragments;return h.length>0&&(o=h.reduce((l,c)=>{if(i&&!i(c,this))return l;let p=this.toLogical(c.floatSide),d=c.area,f=c.continuations[0].float.floatMinWrapBlock,g=l.top,m=l.left,y=l.bottom,b=l.right,w=l.floatMinWrapBlockStart,S=l.floatMinWrapBlockEnd;switch(p){case"inline-start":d.vertical?g=Math.max(g,d.top+d.height):m=Math.max(m,d.left+d.width);break;case"block-start":d.vertical?(f&&d.left<b&&(w=a(f,d.rootViewNodes[0],r.x2-r.x1)),b=Math.min(b,d.left)):(f&&d.top+d.height>g&&(w=a(f,d.rootViewNodes[0],r.y2-r.y1)),g=Math.max(g,d.top+d.height));break;case"inline-end":d.vertical?y=Math.min(y,d.top):b=Math.min(b,d.left);break;case"block-end":d.vertical?(f&&d.left+d.width>m&&(S=a(f,d.rootViewNodes[0],r.x2-r.x1)),m=Math.max(m,d.left+d.width)):(f&&d.top<y&&(S=a(f,d.rootViewNodes[0],r.y2-r.y1)),y=Math.min(y,d.top));break;default:throw new Error(`Unknown logical float side: ${p}`)}return{top:g,left:m,bottom:y,right:b,floatMinWrapBlockStart:w,floatMinWrapBlockEnd:S}},o)),o.left+=n,o.right+=n,o.top+=s,o.bottom+=s,o}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.toLogical(i);if(a==="snap-block"){if(!o["block-start"]&&!o["block-end"])return null}else if(!o[a])return null;e.clientLayout;let h=this.getLimitValue("block-start",e.layoutContext,e.clientLayout),l=this.getLimitValue("block-end",e.layoutContext,e.clientLayout),c=this.getLimitValue("inline-start",e.layoutContext,e.clientLayout),p=this.getLimitValue("inline-end",e.layoutContext,e.clientLayout),d=e.vertical?e.originX:e.originY,f=e.vertical?e.originY:e.originX;h=e.vertical?Math.min(h,e.left+e.getInsetLeft()+e.width+e.getInsetRight()+d):Math.max(h,e.top+d),l=e.vertical?Math.max(l,e.left+d):Math.min(l,e.top+e.getInsetTop()+e.height+e.getInsetBottom()+d);function g(S,R){let L=S(e.bands,R);return L?(e.vertical&&(L=Tl(L)),h=e.vertical?Math.min(h,L.x2):Math.max(h,L.y1),l=e.vertical?Math.max(l,L.x1):Math.min(l,L.y2),!0):r}let m,y,b,w;if(s){let S=e.vertical?Dn(new nt(l,c,h,p)):new nt(c,h,p,l);if((a==="block-start"||a==="snap-block"||a==="inline-start")&&!g(cd,S)||(a==="block-end"||a==="snap-block"||a==="inline-end")&&!g(dd,S)||(b=(l-h)*e.getBoxDir(),m=b-e.getInsetBefore()-e.getInsetAfter(),w=(p-c)*e.getInlineDir(),y=w-e.getInsetStart()-e.getInsetEnd(),!r&&(m<=0||y<=0)))return null}else{m=e.computedBlockSize,b=m+e.getInsetBefore()+e.getInsetAfter();let S=(l-h)*e.getBoxDir();if(a==="snap-block"){if(n===null)a="block-start";else{let L=this.container.getPaddingRect(),_=this.container.getBoxDir()*(n-(this.container.vertical?L.x2:L.y1)),U=this.container.getBoxDir()*((this.container.vertical?L.x1:L.y2)-n-b);_<=U?a="block-start":a="block-end"}if(!o[a])if(o["block-end"])a="block-end";else return null}if(!r&&S<b)return null;a==="inline-start"||a==="inline-end"?y=Dr(e.clientLayout,e.element,["fit-content inline size"])["fit-content inline size"]:e.adjustContentRelativeSize?y=e.getContentInlineSize():y=e.vertical?e.height:e.width,w=y+e.getInsetStart()+e.getInsetEnd();let R=(p-c)*e.getInlineDir();if(!r&&R<w)return null}switch(h-=d,l-=d,c-=f,p-=f,a){case"inline-start":case"block-start":case"snap-block":e.setInlinePosition(c,y),e.setBlockPosition(h,m);break;case"inline-end":case"block-end":e.setInlinePosition(p-w*e.getInlineDir(),y),e.setBlockPosition(l-b*e.getBoxDir(),m);break;default:throw new Error(`unknown float direction: ${i}`)}return a}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 l=>h.isAnchorAlreadyAppeared(l.float.getId())}function n(h,l){return h.continuations.some(i(l))}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}t.clientLayout;let a=this.getLimitValue("block-start",t.layoutContext,t.clientLayout,n);return this.getLimitValue("block-end",t.layoutContext,t.clientLayout,n)*t.getBoxDir()<r*t.getBoxDir()?r:a}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.toLogical(t),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 h(p){return d=>d.floatSide===p&&d.getOrder()<a}function l(p,d){return p.children.some(f=>f.floatFragments.some(h(d))||l(f,d))}function c(p,d){let f=p.parent;return!!f&&(f.floatFragments.some(h(d))||c(f,d))}return o.forEach(p=>{switch(p){case"block-start":case"inline-start":n[p]=!l(this,p);break;case"block-end":case"inline-end":n[p]=!c(this,p);break;default:throw new Error(`Unexpected side: ${p}`)}}),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}},Li=[],Si=class{static register(e){Li.push(e)}findByNodeContext(e){for(let t=Li.length-1;t>=0;t--){let i=Li[t];if(i.appliesToNodeContext(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}findByFloat(e){for(let t=Li.length-1;t>=0;t--){let i=Li[t];if(i.appliesToFloat(e))return i}throw new Error(`No PageFloatLayoutStrategy found for ${e}`)}},$p=class{appliesToNodeContext(e){return gi(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 ph(r,n,s,e.clearSide,t.flowName,e.floatMinWrapBlock);return t.addPageFloat(a),k(a)})}createPageFloatFragment(e,t,i,n){let s=e[0].float;return new fh(s.floatReference,t,e,i,n)}findPageFloatFragment(e,t){return t.findPageFloatFragment(e)}adjustPageFloatArea(e,t,i){}forbid(e,t){}};Si.register(new $p);var Gp=fh,Js=class gh extends ph{constructor(t,i,n,s,r){super(t,i,"block-end",null,n,r),this.footnotePolicy=s}isAllowedToPrecede(t){return!(t instanceof gh)}},Xo=class extends Gp{constructor(e,t,i,n){super(e,"block-end",t,i,n)}getOrder(){return 1/0}shouldBeStashedBefore(e){return e instanceof Js?!0:this.getOrder()<e.getOrder()}},Wp=class{constructor(e){this.footnote=e}allowLayout(e){let t=e.toNodePosition();return!Mt(t,this.footnote.nodePosition)}},jp=class{appliesToNodeContext(e){return e.floatSide==="footnote"}appliesToFloat(e){return e instanceof Js}createPageFloat(e,t,i){let n=Re.REGION,s=t.getPageFloatLayoutContext(n);t.getPageFloatLayoutContext(Re.PAGE).hasSameContainerAs(s)&&(n=Re.PAGE);let r=e.toNodePosition();t.flowName;let o=new Js(r,n,t.flowName,e.footnotePolicy,e.floatMinWrapBlock);return t.addPageFloat(o),k(o)}createPageFloatFragment(e,t,i,n){let s=e[0].float;return new Xo(s.floatReference,e,i,n)}findPageFloatFragment(e,t){let i=t.getPageFloatLayoutContext(e.floatReference).floatFragments.filter(n=>n instanceof Xo);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 v.line:{let n=new Wp(i);t.addLayoutConstraint(n,i.floatReference);break}}}};Si.register(new jp);var Xp="data-vivliostyle-flow-root";function qp(e){return e.getAttribute(Xp)==="true"}function qo(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 B(i)}function Ur(e){return e===v.absolute||e===v.fixed}function Yo(e){return e instanceof ki&&e.name==="running"}function mh(e,t,i,n){return e===v.none||(Ur(t)?(i=v.none,e=qo(e)):(i&&i!==v.none&&!J(i)||n)&&(e=qo(e))),{display:e,position:t,float:i}}function wh(e,t,i,n){return mh(e,t,i,n).display===v.block}function jt(e){switch(e.toString()){case"inline":case"inline-block":case"inline-list-item":case"inline-flex":case"inline-grid":case"ruby":case"inline-table":return!0;default:return!1}}function bh(e){switch(e.toString()){case"ruby-base":case"ruby-text":case"ruby-base-container":case"ruby-text-container":return!0;default:return!1}}function Yp(e,t,i,n,s,r,o){return s=s||r||v.horizontal_tb,!!o||!!i&&i!==v.none&&!J(i)||Ur(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)||!!r&&s!==r}function Kp(e){return e===v.relative||e===v.absolute||e===v.fixed}function ai(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(o&&jt(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,h=r.nextSibling;a.removeChild(r),a.insertBefore(r,h)}let o=t.getElementClientRect(r);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(),h=s.textContent.length;if(!h)return NaN;e.after&&(i+=h),i>=h&&(i=h-1),a.setStart(s,i),a.setEnd(s,i+1);let l=t.getRangeClientRects(a);return l=l.filter(c=>c.right>c.left&&c.bottom>c.top),l.length?(n?o=Math.min.apply(null,l.map(c=>c.left)):o=Math.max.apply(null,l.map(c=>c.bottom)),o):NaN}}function Qs(e,t,i){let n=t.clientLayout.getElementClientRect(e),s=t.getComputedMargin(e);return i?n.width+s.left+s.right:n.height+s.top+s.bottom}function hi(e){for(;e;){if(e.parentNode===e.ownerDocument)return!1;e=e.parentNode}return!0}function yh(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)}function Hr(e){return!!e.getAttribute(xi)}function vh(e){var t;if(e?.nodeType!==1)return!1;let i=e;if(Hr(i))return!0;let n=(t=i.style)==null?void 0:t.position;return n==="absolute"||n==="fixed"}function ui(e){let t=e?.viewNode;return t?.nodeType===1&&Hr(t)}function Zp(e){return e!=="inline"&&(jt(e)||bh(e))}function Ko(e){for(let t=e.parent;t;t=t.parent)if(t.display!=="inline"&&jt(t.display))return t;return null}var $r=class{calculateOffset(e){return mi(this.getNodeContext(),e.collectElementsOffset())}breakPositionChosen(e){}getNodeContext(){return null}};function mi(e,t){return{current:t.reduce((i,n)=>i+n.calculateOffset(e),0),minimum:t.reduce((i,n)=>i+n.calculateMinimumOffset(e),0)}}var rs=class extends $r{constructor(e,t,i,n){super(),this.position=e,this.breakOnEdge=t,this.overflows=i,this.computedBlockSize=n,u(this,"overflowIfRepetitiveElementsDropped"),u(this,"isEdgeUpdated",!1),u(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(Un(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=ai(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 h=n;h;h=h.parentElement){let l=e.clientLayout.getElementComputedStyle(h);if((h===n||h===s&&!r)&&(o+=e.parseComputedLength(l.paddingBlockEnd)),h===s&&!r&&(o+=e.parseComputedLength(l.borderSpacing.replace(/^\S+ (\S+)$/,"$1"))),r?a=Math.max(a,e.parseComputedLength(l.borderBlockEndWidth)):(h===n||h===s)&&(a+=e.parseComputedLength(l.borderBlockEndWidth)),h===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(!Xt.isInstanceOfRepetitiveElementsOwnerFormattingContext(t))return!1;let i=t.getRepetitiveElements();return i?i.isFirstContentNode(e):!1}},Fi=class{find(e){let t=pt("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()}`)}},ci=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 rs(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===Pt.ShadowType.ROOTLESS&&ui(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;yh(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),k(!0)}},Gr=class{constructor(e){this.parent=e,u(this,"formattingContextType","Block")}getName(){return"Block formatting context (BlockFormattingContext)"}isFirstTime(e,t){return t}getParent(){return this.parent}saveState(){}restoreState(e){}},Wr=new ci,Jp=qs.isInstanceOfBlockFormattingContext;ht("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&&wh(i,n,s,r)?new Gr(o?o.formattingContext:null):null});ht("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Gr?Wr:null);var jr=class{constructor(){u(this,"initialBreakPositions",null),u(this,"initialStateOfFormattingContext",null),u(this,"initialPosition"),u(this,"initialFragmentLayoutConstraints")}layout(e,t){return this.prepareLayout(e,t),this.tryLayout(e,t)}tryLayout(e,t){let i=F("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)}},Qp=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){}},er=class{constructor(e,t){this.strategy=e,this.layoutContext=t}iterate(e){let t=this.strategy,i=t.initialState(e),n=F("LayoutIterator");return n.loopWithFrame(s=>{let r;for(;i.nodeContext;){i.nodeContext.viewNode?i.nodeContext.viewNode.nodeType!==1?Ue(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:k(!0)).thenAsync(()=>i.break?k(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()}},ji=class extends Qp{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&&Ke(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=Xe(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:k(!0),i=i.thenAsync(()=>(e.break||(e.leadingEdgeContexts=[],e.leadingEdge=!1,e.atUnforcedBreak=!1,e.breakAtTheEdge=null),k(!0)))):(t=this.endNonInlineBox(e),i=t&&t.isPending()?t:k(!0)),i.thenAsync(()=>(e.break||(e.onStartEdges=!1,e.lastAfterNodeContext=e.nodeContext.copy(),e.breakAtTheEdge=Xe(e.breakAtTheEdge,e.nodeContext.breakAfter)),k(!0)))}},tr=[];function ef(){tr=[]}function xh(e,t,i){return e-=i,t===0?e===0:e%t===0&&e/t>=0}var tf=class{constructor(e){this.matchers=e}matches(){return this.matchers.some(e=>e.matches())}},nf=class{constructor(e){this.matchers=e}matches(){return this.matchers.every(e=>e.matches())}},Sh=class An{constructor(t,i,n){this.elementOffset=t,this.a=i,this.b=n}static registerFragmentIndex(t,i,n){let s=An.fragmentIndices;(!s[t]||s[t].priority<=n)&&(s[t]={fragmentIndex:i,priority:n})}static clearFragmentIndices(){An.fragmentIndices={}}matches(){let t=An.fragmentIndices[this.elementOffset];return t!=null&&t.fragmentIndex!=null&&xh(t.fragmentIndex,this.a,this.b)}};u(Sh,"fragmentIndices",{});var os=Sh,En=class{static buildViewConditionMatcher(e,t){let i=t.split("_");return i[0]=="NFS"?new os(e,parseInt(i[1],10),parseInt(i[2],10)):(`${t}`,null)}static buildAllMatcher(e){return new nf(e)}static buildAnyMatcher(e){return new tf(e)}},Ch={"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-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-size-adjust":!0,"text-spacing-trim":!0,"text-stroke-color":!0,"text-stroke-width":!0,"text-transform":!0,"text-underline-position":!0,visibility:!0,"white-space":!0,widows:!0,"word-break":!0,"word-spacing":!0,"writing-mode":!0},sf=["image-resolution","orphans","widows"];function rf(){return pt("POLYFILLED_INHERITED_PROPS").reduce((e,t)=>e.concat(t()),[].concat(sf))}var of={"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},ir=["margin-%","padding-%","border-%-width","border-%-style","border-%-color","%"],af=["max-%","min-%","%"],lf=(()=>{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<ir.length;i++)for(let n=0;n<e.length;n++){let s=ir[i].replace("%",e[n]);t[s]=!0}return t})();function as(e,t){let i={};for(let n of ir)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 af)for(let s in t){let r=n.replace("%",s),o=n.replace("%",t[s]);i[r]=o,i[o]=r}return i}var Eh=as({"block-start":"right","block-end":"left","inline-start":"top","inline-end":"bottom"},{"block-size":"width","inline-size":"height"}),kh=as({"block-start":"top","block-end":"bottom","inline-start":"left","inline-end":"right"},{"block-size":"height","inline-size":"width"}),hf=as({"block-start":"right","block-end":"left","inline-start":"bottom","inline-end":"top"},{"block-size":"width","inline-size":"height"}),uf=as({"block-start":"top","block-end":"bottom","inline-start":"right","inline-end":"left"},{"block-size":"height","inline-size":"width"}),K=class nr{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 nr(i,this.priority)}increaseSpecificity(t){return t==0?this:new nr(this.value,this.priority+t)}evaluate(t,i,n,s){return i&&Nt(i)?this.value:Xn(t,this.value,i,n,s)}isEnabled(t){return!0}},sr=class rr extends K{constructor(t,i,n){super(t,i),this.condition=n}getBaseValue(){return new K(this.value,this.priority)}filterValue(t){let i=this.value.visit(t);return i===this.value?this:new rr(i,this.priority,this.condition)}increaseSpecificity(t){return t==0?this:new rr(this.value,this.priority+t,this.condition)}isEnabled(t){try{return!!this.condition.evaluate(t)}catch(i){D.warn(i)}return!1}};function or(e,t,i){return(!t||i.priority>=t.priority)&&i.isEnabled(e)?i.getBaseValue():t}function Tt(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 Nh={"region-id":!0,"fragment-selector-id":!0};function cf(e){return!!Nh[e]}function ar(e){return e.charAt(0)==="_"&&e!=="_viewConditionalStyles"}function wi(e){return e.charAt(0)!=="_"&&!Nh[e]}function Xi(e){return!!Ch[e]||Nt(e)}function Ve(e,t){return e[t]}function qt(e,t,i){i?e[t]=i:delete e[t]}function dt(e,t){return e[t]}function ls(e,t){let i=e[t];return i||(i={},e[t]=i),i}var Ph=e=>{let t=e._viewConditionalStyles;return t||(t=[],e._viewConditionalStyles=t),t};function Th(e,t){return e[t]}function Ih(e,t){let i=e[t];return i||(i=[],e[t]=i),i}function jn(e,t,i,n,s,r,o){var a,h;if([{id:s,styleKey:"_pseudos"},{id:r,styleKey:"_regions"}].forEach(l=>{if(l.id){let c=ls(t,l.styleKey);t=c[l.id],t||(t={},c[l.id]=t)}}),o){let l=Ph(t);t={},l.push({styles:t,matcher:o})}for(let l in i)if(!ar(l))if(cf(l)){let c=Th(i,l),p=Ih(t,l);Array.prototype.push.apply(p,c)}else{let c=Ve(i,l);if(!c.isEnabled(e))continue;let p=c.increaseSpecificity(n);Tt(t,l,p,e);let d=(h=(a=e.style)==null?void 0:a.validatorSet.shorthands[l])==null?void 0:h.propList;if(d)for(let f of d){let g=new K(G,p.priority);Tt(t,f,g,e)}}}function df(e,t){let i={};for(let n=0;n<t.length;n++)jn(e,i,t[n],0,null,null,null);return i}function Rh(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 pf=class extends Ei{constructor(e,t){super(),this.props=e,this.context=t,u(this,"propName","")}setPropName(e){this.propName=e}getFontSize(){let e=Ve(this.props,"font-size");if(!e.value.isNumeric())return me.em;let t=e.value;if(!Uc(t.unit))throw new Error("Unexpected state");return t.num*me[t.unit]}visitNumeric(e){return this.context,this.propName==="font-size"?Ah(e,this.getFontSize(),this.context):e.unit==="em"||e.unit==="ex"||e.unit==="rem"||e.unit==="lh"||e.unit==="rlh"?Xr(e,this.getFontSize(),this.context):e}visitExpr(e){return this.propName=="font-size"?Xn(this.context,e,this.propName).visit(this):e}};function Xr(e,t,i){let n=e.unit,s=e.num;if(n==="em"||n==="ex"){let r=me[n]/me.em;return new T(s*r*t,"px")}else return n==="rem"?new T(s*i.fontSize(),"px"):n==="rlh"?new T(s*i.rootLineHeight,"px"):e}function Ah(e,t,i){e=Xr(e,t,i);let n=e.unit,s=e.num;return n==="px"?e:n==="%"?new T(s/100*t,"px"):new T(s*i.queryUnitSize(n,!1),"px")}var Ii=class{apply(e){}mergeWith(e){return new ff([this,e])}clone(){return this}},kn=class extends Ii{constructor(e){super(),this.conditionItem=e}apply(e){e.pushConditionItem(this.conditionItem.fresh(e))}},ff=class Lh extends Ii{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 Lh([].concat(this.list))}},qr=class extends Ii{constructor(e,t,i,n,s){super(),this.style=e,this.specificity=t,this.pseudoelement=i,this.regionId=n,this.viewConditionId=s}apply(e){jn(e.context,e.currentStyle,this.style,this.specificity,this.pseudoelement,this.regionId,e.buildViewConditionMatcher(this.viewConditionId))}},fe=class extends Ii{constructor(){super(),u(this,"chained",null)}apply(e){this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},gf=class extends fe{constructor(e){super(),this.className=e}apply(e){e.currentClassNames.includes(this.className)&&this.chained.apply(e)}getPriority(){return 10}makePrimary(e){return this.chained&&e.insertInTable(e.classes,this.className,this.chained),!0}},mf=class extends fe{constructor(e){super(),this.id=e}apply(e){(e.currentId==this.id||e.currentXmlId==this.id)&&this.chained.apply(e)}getPriority(){return 11}makePrimary(e){return this.chained&&e.insertInTable(e.ids,this.id,this.chained),!0}},Zo=class extends fe{constructor(e){super(),this.localName=e}apply(e){e.currentLocalName==this.localName&&this.chained.apply(e)}getPriority(){return 8}makePrimary(e){return this.chained&&e.insertInTable(e.tags,this.localName,this.chained),!0}},wf=class extends fe{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}},bf=class extends fe{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+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)}}}},yf=class extends fe{constructor(e){super(),this.ns=e}apply(e){e.currentNamespace==this.ns&&this.chained.apply(e)}};function hs(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 Jo=class extends fe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){hs(e.currentElement,this.ns,this.name,(t,i,n)=>t.hasAttributeNS(i,n))&&this.chained.apply(e)}},vf=class extends fe{constructor(e,t,i){super(),this.ns=e,this.name=t,this.value=i}apply(e){hs(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}},xf=class extends fe{constructor(e,t){super(),this.ns=e,this.name=t}apply(e){hs(e.currentElement,this.ns,this.name,(t,i,n)=>!!of[t.getAttributeNS(i,n)])&&this.chained.apply(e)}getPriority(){return 0}makePrimary(e){return!1}},Oi=class extends fe{constructor(e,t,i){super(),this.ns=e,this.name=t,this.regexp=i}apply(e){hs(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)}},Sf=class extends fe{constructor(e){super(),this.langRegExp=e}apply(e){e.lang.match(this.langRegExp)&&this.chained.apply(e)}},Qo=class extends fe{constructor(){super()}apply(e){e.isFirst&&this.chained.apply(e)}getPriority(){return 6}},Cf=class extends fe{constructor(){super()}apply(e){e.isRoot&&this.chained.apply(e)}getPriority(){return 12}},wn=class extends fe{constructor(e,t){super(),this.a=e,this.b=t}matchANPlusB(e){return xh(e,this.a,this.b)}},Ef=class extends wn{constructor(e,t){super(e,t)}apply(e){this.matchANPlusB(e.currentSiblingOrder)&&this.chained.apply(e)}getPriority(){return 5}},lr=class extends wn{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}},hr=class extends wn{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}},ur=class extends wn{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}},kf=class extends fe{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}},Nf=class extends fe{constructor(){super()}apply(e){e.currentElement.disabled===!1&&this.chained.apply(e)}getPriority(){return 5}},Pf=class extends fe{constructor(){super()}apply(e){e.currentElement.disabled===!0&&this.chained.apply(e)}getPriority(){return 5}},Tf=class extends fe{constructor(){super()}apply(e){let t=e.currentElement;(t.selected===!0||t.checked===!0)&&this.chained.apply(e)}getPriority(){return 5}},Ge=class extends fe{constructor(e){super(),this.condition=e}apply(e){if(e.conditions[this.condition])try{e.dependentConditions.push(this.condition),this.chained.apply(e)}finally{e.dependentConditions.pop()}}getPriority(){return 5}},If=class Fh extends Ii{constructor(){super(),u(this,"applied",!1)}apply(t){this.applied=!0}clone(){let t=new Fh;return t.applied=this.applied,t}},Yr=class extends fe{constructor(e){super(),u(this,"checkAppliedAction"),u(this,"firstActions",[]),this.checkAppliedAction=new If;for(let t of e)this.firstActions.push(Rh(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 fe?e.getPriority():0))}positive(){return!0}relational(){return!1}},Rf=class extends Yr{positive(){return!1}},Af=class extends Yr{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}},us=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)}},Lf=class Oh extends us{constructor(t,i,n){super(t,i,n)}fresh(t){return new Oh(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}},Ff=class Bh extends us{constructor(t,i,n){super(t,i,n)}fresh(t){return new Bh(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)}},Of=class _h extends us{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new _h(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)}},Bf=class Mh extends us{constructor(t,i,n){super(t,i,n),u(this,"fired",!1)}fresh(t){return new Mh(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}},_f=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}},Mf=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}},zf=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}},Df=class extends Ei{constructor(e){super(),this.element=e}createValueFromString(e,t){switch(t){case"url":return e?new ct(e):new ct("about:invalid");case"string":default:return e?new Ae(e):new Ae("")}}visitFunc(e){if(e.name!=="attr")return super.visitFunc(e);let t="string",i=null,n=null;if(e.values[0]instanceof ke){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 qi(e){if(Dt(e)){if(e instanceof Ae)return e.stringValue();if(e instanceof ke)return e.values.map(t=>qi(t)).join("")}return""}var cr=class extends Ei{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 Ae("");case"no-close-quote":return t.quoteDepth>0&&t.quoteDepth--,new Ae("")}return e}format(e,t){let i=!1,n=!1,s;(s=t.match(/^upper-(.*)/))!=null?(i=!0,t=s[1]):(s=t.match(/^lower-(.*)/))!=null&&(n=!0,t=s[1]);let r="";return ea[t]?r=Uf(ea[t],e):ta[t]?r=$f(ta[t],e):ia[t]!=null?r=ia[t]:t=="decimal-leading-zero"?(r=`${e}`,r.length==1&&(r=`0${r}`)):t=="cjk-ideographic"||t=="trad-chinese-informal"?r=Wf(e,Gf):r=`${e}`,i?r.toUpperCase():n?r.toLowerCase():r}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 Ae(this.format(s,i))}else{let s=new V(this.counterResolver.getPageCounterVal(t,r=>this.format(r||0,i)));return new ke([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 kt;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 V(this.counterResolver.getPageCountersVal(t,a=>{let h=[];if(a.length)for(let c=0;c<a.length;c++)h.push(this.format(a[c],n));let l=r.toString();return l.length&&h.push(l),h.length?h.join(i):this.format(0,n)}));return new ke([o])}visitFuncTargetCounter(e){let t=e[0],i;t instanceof ct?i=t.url:i=t.stringValue();let n=e[1].toString(),s=e.length>2?e[2].stringValue():"decimal",r=new V(this.counterResolver.getTargetCounterVal(i,n,o=>this.format(o||0,s)));return new ke([r])}visitFuncTargetCounters(e){let t=e[0],i;t instanceof ct?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 V(this.counterResolver.getTargetCountersVal(i,n,a=>{let h=a.map(l=>this.format(l,r));return h.length?h.join(s):this.format(0,r)}));return new ke([o])}visitFuncString(e){let t=e.length>0?e[0].stringValue():"",i=e.length>1?e[1].stringValue():"first";return new V(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 V(this.counterResolver.getRunningElementVal(t,i))}visitFuncContent(e){var t,i,n,s,r,o;let a=e.length>0?e[0].stringValue():"text",h="";switch(a){case"text":h=this.element.textContent;break;case"before":case"after":{let l=dt(this.cascade.currentStyle,"_pseudos"),c=(i=(t=l?.[a])==null?void 0:t.content)==null?void 0:i.value;h=qi(c)}break;case"first-letter":{let l=dt(this.cascade.currentStyle,"_pseudos"),c=(qi((s=(n=l?.before)==null?void 0:n.content)==null?void 0:s.value)||this.element.textContent||qi((o=(r=l?.after)==null?void 0:r.content)==null?void 0:o.value)).match(Fs);h=c?c[0]:""}break}return new Ae(h)}visitFuncLeader(e){let t="";if(e[0]instanceof ft)switch(e[0].stringValue()){case"dotted":t=".";break;case"solid":t="_";break;case"space":t=" ";break}else e[0]instanceof Ae&&(t=e[0].stringValue());return t.length==0?new Ae(""):new V(new De(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"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}},Vf=(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(ce){if(S==="rtl"){let de="\u200F";g.textContent=(ce.startsWith(de)?"":de)+ce+(ce.endsWith(de)?"":de)}else g.textContent=ce},c=function(){let ce=i.clientLayout.getElementClientRect(m);return L.left>ce.left||L.right<ce.right||L.top>ce.top||L.bottom<ce.bottom},p=function(){let ce,de;if(l(b),c())ce=1,de=b.length/y.length;else{ce=b.length/y.length,de=ce;for(let x=0;x<16;x++){let P=b;for(let C=0;C<1<<x;C++)P+=y;if(l(P),c()){de+=1<<x;break}}}for(let x=0;x<16;x++){let P="",C=Math.floor((ce+de)/2);for(let E=0;E<C;E++)P+=y;if(l(P),c())de=C;else{if(ce==C)return;ce=C}}l(y)},d=function(ce){let de=0,x=m.parentElement;for(;x&&x!==f.viewNode;)de+=i.getComputedInsets(x)[ce],x=x.parentElement;return de};var s=l,r=c,o=p,a=d;let f=h.parent;for(;f&&f.inline;)f=f.parent;let g=h.viewNode,m=g.parentElement,y=g.getAttribute("data-viv-leader-value"),b=g.textContent||y,{writingMode:w,direction:S,marginInlineEnd:R}=i.clientLayout.getElementComputedStyle(m);g.style.marginInlineStart="1px",l(y),m.style.display="inline-block",m.style.textIndent="0";let L=i.clientLayout.getElementClientRect(f.viewNode),_=i.clientLayout.getElementClientRect(m),U=i.parseComputedLength(R);w==="vertical-rl"||w==="vertical-lr"?(S==="rtl"?L.top+=U:L.bottom-=U,L.left=_.left,L.right=_.right,L.top=Math.min(_.top,L.top),L.bottom=Math.max(_.bottom,L.bottom)):(S==="rtl"?L.left+=U:L.right-=U,L.top=_.top,L.bottom=_.bottom,L.left=Math.min(_.left,L.left),L.right=Math.max(_.right,L.right)),p();let W=i.clientLayout.getElementClientRect(m);S=="rtl"?m.style.float="left":m.style.float="right";let we=i.clientLayout.getElementClientRect(m),He=0;S=="rtl"?w=="vertical-rl"||w=="vertical-lr"?He=W.top-we.top-d("top"):He=W.left-we.left-d("left"):w=="vertical-rl"||w=="vertical-lr"?He=we.bottom-W.bottom-d("bottom"):He=we.right-W.right-d("right"),He=Math.max(0,He-.1),m.style.float="",g.style.marginInlineStart=`${He}px`}};ht("POST_LAYOUT_BLOCK",Vf);var ea={roman:[4999,1e3,"M",900,"CM",500,"D",400,"CD",100,"C",90,"XC",50,"L",40,"XL",10,"X",9,"IX",5,"V",4,"IV",1,"I"],armenian:[9999,9e3,"\u0584",8e3,"\u0583",7e3,"\u0582",6e3,"\u0581",5e3,"\u0580",4e3,"\u057F",3e3,"\u057E",2e3,"\u057D",1e3,"\u057C",900,"\u057B",800,"\u057A",700,"\u0579",600,"\u0578",500,"\u0577",400,"\u0576",300,"\u0575",200,"\u0574",100,"\u0573",90,"\u0572",80,"\u0571",70,"\u0570",60,"\u056F",50,"\u056E",40,"\u056D",30,"\u056C",20,"\u056B",10,"\u056A",9,"\u0569",8,"\u0568",7,"\u0567",6,"\u0566",5,"\u0565",4,"\u0564",3,"\u0563",2,"\u0562",1,"\u0561"],georgian:[19999,1e4,"\u10F5",9e3,"\u10F0",8e3,"\u10EF",7e3,"\u10F4",6e3,"\u10EE",5e3,"\u10ED",4e3,"\u10EC",3e3,"\u10EB",2e3,"\u10EA",1e3,"\u10E9",900,"\u10E8",800,"\u10E7",700,"\u10E6",600,"\u10E5",500,"\u10E4",400,"\u10F3",300,"\u10E2",200,"\u10E1",100,"\u10E0",90,"\u10DF",80,"\u10DE",70,"\u10DD",60,"\u10F2",50,"\u10DC",40,"\u10DB",30,"\u10DA",20,"\u10D9",10,"\u10D8",9,"\u10D7",8,"\u10F1",7,"\u10D6",6,"\u10D5",5,"\u10D4",4,"\u10D3",3,"\u10D2",2,"\u10D1",1,"\u10D0"],hebrew:[999,400,"\u05EA",300,"\u05E9",200,"\u05E8",100,"\u05E7",90,"\u05E6",80,"\u05E4",70,"\u05E2",60,"\u05E1",50,"\u05E0",40,"\u05DE",30,"\u05DC",20,"\u05DB",19,"\u05D9\u05D8",18,"\u05D9\u05D7",17,"\u05D9\u05D6",16,"\u05D8\u05D6",15,"\u05D8\u05D5",10,"\u05D9",9,"\u05D8",8,"\u05D7",7,"\u05D6",6,"\u05D5",5,"\u05D4",4,"\u05D3",3,"\u05D2",2,"\u05D1",1,"\u05D0"]},ta={latin:"a-z",alpha:"a-z",greek:"\u03B1-\u03C1\u03C3-\u03C9",russian:"\u0430-\u0438\u043A-\u0449\u044D-\u044F"},ia={square:"\u25A0",disc:"\u2022",circle:"\u25E6",none:""};function Uf(e,t){let i=e[0];if(t>i||t<=0||t!=Math.round(t))return"";let n="";for(let s=1;s<e.length;s+=2){let r=e[s],o=Math.floor(t/r);if(o>20)return"";for(t-=o*r;o>0;)n+=e[s+1],o--}return n}function Hf(e){let t=[],i=0;for(;i<e.length;)if(e.substr(i+1,1)=="-"){let n=e.charCodeAt(i),s=e.charCodeAt(i+2);i+=3;for(let r=n;r<=s;r++)t.push(String.fromCharCode(r))}else t.push(e.substr(i++,1));return t}function $f(e,t){if(t<=0||t!=Math.round(t))return"";let i=Hf(e),n="";do{t--;let s=t%i.length;n=i[s]+n,t=(t-s)/i.length}while(t>0);return n}var Gf={formal:!1,digits:"\u96F6\u4E00\u4E8C\u4E09\u56DB\u4E94\u516D\u4E03\u516B\u4E5D",markers:"\u5341\u767E\u5343",negative:"\u8CA0"};function Wf(e,t){if(e>9999||e<-9999)return`${e}`;if(e==0)return t.digits.charAt(0);let i=new kt;if(e<0&&(i.append(t.negative),e=-e),e<10)i.append(t.digits.charAt(e));else if(!t.formal&&e<=19)i.append(t.markers.charAt(0)),e!=0&&i.append(t.digits.charAt(e-10));else{let n=Math.floor(e/1e3);n&&(i.append(t.digits.charAt(n)),i.append(t.markers.charAt(2)));let s=Math.floor(e/100)%10;s&&(i.append(t.digits.charAt(s)),i.append(t.markers.charAt(1)));let r=Math.floor(e/10)%10;r&&(i.append(t.digits.charAt(r)),i.append(t.markers.charAt(0)));let o=e%10;o&&i.append(t.digits.charAt(o))}return i.toString()}var Kr=1/1048576;function ii(e,t){for(let i in e)t[i]=e[i].clone()}var jf=class zh{constructor(){u(this,"nsCount",0),u(this,"nsPrefix",{}),u(this,"tags",{}),u(this,"nstags",{}),u(this,"epubtypes",{}),u(this,"classes",{}),u(this,"ids",{}),u(this,"pagetypes",{}),u(this,"order",0)}clone(){let t=new zh;t.nsCount=this.nsCount;for(let i in this.nsPrefix)t.nsPrefix[i]=this.nsPrefix[i];return ii(this.tags,t.tags),ii(this.nstags,t.nstags),ii(this.epubtypes,t.epubtypes),ii(this.classes,t.classes),ii(this.ids,t.ids),ii(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){return new Xf(this,t,i,n,s)}nextOrder(){return this.order+=Kr}},Xf=class{constructor(e,t,i,n,s){this.context=t,this.counterListener=i,this.counterResolver=n,u(this,"code"),u(this,"stack",[[],[]]),u(this,"conditions",{}),u(this,"currentElement",null),u(this,"currentElementOffset",null),u(this,"currentStyle",null),u(this,"currentClassNames",null),u(this,"currentLocalName",""),u(this,"currentNamespace",""),u(this,"currentId",""),u(this,"currentXmlId",""),u(this,"currentNSTag",""),u(this,"currentEpubTypes",null),u(this,"currentPageType",null),u(this,"previousPageType",null),u(this,"firstPageType",null),u(this,"isFirst",!0),u(this,"isRoot",!0),u(this,"counters",{}),u(this,"counterScoping",[{}]),u(this,"quotes"),u(this,"quoteDepth",0),u(this,"lang",""),u(this,"siblingOrderStack",[0]),u(this,"currentSiblingOrder",0),u(this,"siblingTypeCountsStack",[{}]),u(this,"currentSiblingTypeCounts"),u(this,"currentFollowingSiblingOrder",null),u(this,"followingSiblingOrderStack"),u(this,"followingSiblingTypeCountsStack",[{}]),u(this,"currentFollowingSiblingTypeCounts"),u(this,"viewConditions",{}),u(this,"dependentConditions",[]),u(this,"elementStack"),this.code=e,this.quotes=[new Ae("\u201C"),new Ae("\u201D"),new Ae("\u2018"),new Ae("\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=En.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]:En.buildAnyMatcher([].concat(s)):null}).filter(n=>n);return i.length<=0?t:t===null?i.length===1?i[0]:En.buildAllMatcher(i):En.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=Ts,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 h=v.inline,l=e.display;if(l&&(h=l.evaluate(this.context)),h===v.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 c=v.inline,p=e.float;p&&(c=p.evaluate(this.context));let d=null,f=null,g=null,m=e["counter-reset"];if(m){let w=m.evaluate(this.context);w&&(d=Gi(w,!0))}let y=e["counter-set"];if(y){let w=y.evaluate(this.context);w&&(g=Gi(w,!1))}let b=e["counter-increment"];if(b){let w=b.evaluate(this.context);w&&(f=Gi(w,!1))}if((this.currentLocalName=="ol"||this.currentLocalName=="ul")&&this.currentNamespace=="http://www.w3.org/1999/xhtml"&&(d||(d={}),d["list-item"]=((i=(t=this.currentElement)==null?void 0:t.start)!=null?i:1)-1),h===v.list_item&&(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:"")&&(g||(g={}),g["list-item"]=this.currentElement.value)),((o=this.currentElement)==null?void 0:o.parentNode.nodeType)===Node.DOCUMENT_NODE&&(d||(d={}),d.footnote===void 0&&(d.footnote=0)),c===v.footnote&&(f||(f={}),f.footnote===void 0)){let w=(a=this.currentStyle["counter-increment"])==null?void 0:a.value;(!w||!(w===v.footnote||w instanceof ke&&w.values.includes(v.footnote)))&&(f.footnote=1)}if(d)for(let w in d)this.defineCounter(w,d[w]);if(f)for(let w in f){this.counters[w]||this.defineCounter(w,0);let S=this.counters[w];S[S.length-1]+=f[w]}if(g)for(let w in g)if(!this.counters[w])this.defineCounter(w,g[w]);else{let S=this.counters[w];S[S.length-1]=g[w]}if(h===v.list_item){let w=this.counters["list-item"],S=w[w.length-1];e["ua-list-item-count"]=new K(new ei(S),0)}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 cr(this,this.currentElement,this.counterResolver));let i=t.value instanceof qe?t.value.values:[t.value];for(let n of i)if(n instanceof ke){let s=n.values[0].stringValue(),r=n.values.slice(1).map(o=>qi(o)).join("");this.counterResolver.setNamedString(s,r,this.currentElementOffset)}delete e["string-set"]}setRunningElement(e){let t=e.position;if(t?.value instanceof ki&&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 cr(this,t,this.counterResolver))),this.popCounters()}pushElement(e,t,i,n){var s,r;this.currentPageType=null,this.currentElement=t,this.currentElementOffset=n,this.currentStyle=i,this.currentNamespace=t.namespaceURI,this.currentLocalName=t.localName;let o=this.code.nsPrefix[this.currentNamespace];o?this.currentNSTag=o+this.currentLocalName:this.currentNSTag="",this.currentId=t.getAttribute("id"),this.currentXmlId=t.getAttributeNS("http://www.w3.org/XML/1998/namespace","id");let a=t.getAttribute("class");a?this.currentClassNames=a.split(/\s+/):this.currentClassNames=Ts;let h=t.getAttributeNS("http://www.idpf.org/2007/ops","type");h?this.currentEpubTypes=h.split(/\s+/):this.currentEpubTypes=Ts;let l=Os(t);l&&(this.stack[this.stack.length-1].push(new Mf(this.lang)),this.lang=l.toLowerCase());let c=this.isRoot,p=this.siblingOrderStack;this.currentSiblingOrder=++p[p.length-1],p.push(0);let d=this.siblingTypeCountsStack,f=this.currentSiblingTypeCounts=d[d.length-1],g=f[this.currentNamespace];g||(g=f[this.currentNamespace]={}),g[this.currentLocalName]=(g[this.currentLocalName]||0)+1,d.push({});let m=this.followingSiblingOrderStack;m[m.length-1]!==null?this.currentFollowingSiblingOrder=--m[m.length-1]:this.currentFollowingSiblingOrder=null,m.push(null);let y=this.followingSiblingTypeCountsStack,b=this.currentFollowingSiblingTypeCounts=y[y.length-1];b&&b[this.currentNamespace]&&b[this.currentNamespace][this.currentLocalName]--,y.push({}),this.applyActions(),this.applyVarFilter([this.currentStyle],e,t),this.applyCalcFilter(this.currentStyle,this.context),this.applyAttrFilter(t);let w=i.quotes,S=null;if(w){let _=w.evaluate(this.context);_&&(S=new zf(this.quotes),_===v.none?this.quotes=[new Ae(""),new Ae("")]:_===v.auto||_===v.initial?this.quotes=[new Ae("\u201C"),new Ae("\u201D"),new Ae("\u2018"),new Ae("\u2019")]:_ instanceof ke&&(this.quotes=_.values))}this.pushCounters(this.currentStyle);let R=this.currentId||this.currentXmlId||t.getAttribute("name")||"";if(c||R){let _={};Object.keys(this.counters).forEach(U=>{_[U]=Array.from(this.counters[U])}),this.counterListener.countersOfId(R,_)}let L=dt(this.currentStyle,"_pseudos");if(L){let _=!0;for(let U of qf){U||(_=!1);let W=L[U];W&&((U==="before"||U==="after")&&!Dt((s=W.content)==null?void 0:s.value)||(U==="footnote-call"||U==="footnote-marker")&&((r=Ve(this.currentStyle,"float"))==null?void 0:r.value)!==v.footnote?delete L[U]:_?this.processPseudoelementProps(W,t):this.stack[this.stack.length-2].push(new _f(W,t)))}}this.setNamedStrings(this.currentStyle),this.setRunningElement(this.currentStyle),S&&this.stack[this.stack.length-2].push(S)}applyAttrFilterInner(e,t){for(let i in t)wi(i)&&!Nt(i)&&(t[i]=t[i].filterValue(e))}applyAttrFilter(e){let t=new Df(e),i=this.currentStyle,n=dt(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 ng(e,t,i),h=32,l={};for(let c in o)if(ar(c)){let p=dt(o,c);for(let d in p)this.applyVarFilter([p[d],...e],t,i)}else if(wi(c)){let p=Ve(o,c),d=p.value;for(let f=0;;f++){if(f>=h){d=G;break}let g=d.visit(a);if(a.error){d=G,a.error=!1;break}if(g===d)break;d=g}if(d!==p.value){let f=t.validatorSet,g=(n=f?.shorthands[c])==null?void 0:n.clone();if(g)if(J(d)){for(let m of g.propList){let y=new K(d,p.priority),b=Ve(o,m);qt(l,m,or(this.context,b,y))}delete o[c]}else{let m=Ti(t.scope,new gt(d.toString(),null),"");if(m&&(m.visit(g),!g.error)){for(let y of g.propList){let b=new K((r=(s=g.values[y])!=null?s:f.defaultValues[y])!=null?r:v.initial,p.priority),w=Ve(o,y);qt(l,y,or(this.context,w,b))}delete o[c]}}else o[c]=new K(d,p.priority)}if(l[c]){let f=Ve(o,c);f&&f.value!==G&&Tt(l,c,f,this.context)}}for(let c in l)o[c]=l[c]}applyCalcFilter(e,t){let i=new jh(t);for(let n in e)if(ar(n)){let s=dt(e,n);for(let r in s)this.applyCalcFilter(s[r],t)}else if(wi(n)&&!Nt(n)){let s=Ve(e,n),r=s.value.visit(i);r!==s.value&&(e[n]=new K(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()}},Ts=[],qf=["before","transclusion-before","footnote-call","footnote-marker","inner","first-letter","first-line","","transclusion-after","after"],dr=null;function Yf(e){dr=e}var nn=class extends gn{constructor(e,t,i,n,s,r,o){super(e,t,o),this.condition=i,this.regionId=s,this.validatorSet=r,u(this,"chain",null),u(this,"specificity",0),u(this,"elementStyle",null),u(this,"conditionCount",0),u(this,"pseudoelement",null),u(this,"footnoteContent",!1),u(this,"cascade"),u(this,"state"),u(this,"viewConditionId",null),u(this,"insideSelectorRule"),u(this,"invalid",!1),this.cascade=n?n.cascade:dr?dr.clone():new jf,this.state=0}insertNonPrimary(e){this.cascade.insertInTable(this.cascade.tags,"*",e)}processChain(e){let t=Rh(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 wf(e,t.toLowerCase())):t?this.chain.push(new Zo(t.toLowerCase())):this.chain.push(new yf(e)))}invalidSelector(e){D.warn(e),this.chain.push(new Ge("")),this.setInvalid()}setInvalid(){this.invalid=!0;for(let e=this;e instanceof sn;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 gf(e))}pseudoclassSelector(e,t){if(this.pseudoelement){this.invalidSelector(`::${this.pseudoelement} followed by :${e}`);return}switch(e.toLowerCase()){case"enabled":this.chain.push(new Nf);break;case"disabled":this.chain.push(new Pf);break;case"checked":this.chain.push(new Tf);break;case"root":case"scope":this.chain.push(new Cf);break;case"link":this.chain.push(new Zo("a")),this.chain.push(new Jo("","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)${Rt(i)}($|\\s)`),s=t[1];this.chain.push(new bf(n,s))}else this.chain.push(new Ge(""));break;case"-adapt-footnote-content":case"footnote-content":this.footnoteContent=!0;break;case"visited":case"active":case"hover":case"focus":this.chain.push(new Ge(""));break;case"lang":if(t&&t.length==1&&typeof t[0]=="string"){let i=t[0];this.chain.push(new Sf(new RegExp(`^${Rt(i.toLowerCase())}($|-)`)))}else this.chain.push(new Ge(""));break;case"nth-child":case"nth-last-child":case"nth-of-type":case"nth-last-of-type":{let i=Kf[e.toLowerCase()];t&&t.length==2?this.chain.push(new i(t[0],t[1])):this.chain.push(new Ge(""));break}case"first-child":this.chain.push(new Qo);break;case"last-child":this.chain.push(new hr(0,1));break;case"first-of-type":this.chain.push(new lr(0,1));break;case"last-of-type":this.chain.push(new ur(0,1));break;case"only-child":this.chain.push(new Qo),this.chain.push(new hr(0,1));break;case"only-of-type":this.chain.push(new lr(0,1)),this.chain.push(new ur(0,1));break;case"empty":this.chain.push(new kf);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"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 Ge(""));break;case"nth-fragment":t&&t.length==2?this.viewConditionId=`NFS_${t[0]}_${t[1]}`:this.chain.push(new Ge(""));break;default:this.invalidSelector(`Unknown pseudo-element ::${e}`);return}this.specificity+=1}idSelector(e){this.specificity+=65536,this.chain.push(new mf(e))}attributeSelector(e,t,i,n){this.specificity+=256,t=t.toLowerCase(),n=n||"";let s;switch(i){case 0:s=new Jo(e,t);break;case 39:s=new vf(e,t,n);break;case 45:!n||n.match(/\s/)?s=new Ge(""):s=new Oi(e,t,new RegExp(`(^|\\s)${Rt(n)}($|\\s)`));break;case 44:s=new Oi(e,t,new RegExp(`^${Rt(n)}($|-)`));break;case 43:n?s=new Oi(e,t,new RegExp(`^${Rt(n)}`)):s=new Ge("");break;case 42:n?s=new Oi(e,t,new RegExp(`${Rt(n)}$`)):s=new Ge("");break;case 46:n?s=new Oi(e,t,new RegExp(Rt(n))):s=new Ge("");break;case 50:if(n=="supported")s=new xf(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${Nn++}`;this.processChain(new kn(new Lf(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}childSelector(){let e=`c${Nn++}`;this.processChain(new kn(new Ff(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}adjacentSiblingSelector(){let e=`a${Nn++}`;this.processChain(new kn(new Of(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}followingSiblingSelector(){let e=`f${Nn++}`;this.processChain(new kn(new Bf(e,this.viewConditionId,null))),this.chain=[new Ge(e)],this.viewConditionId=null}nextSelector(){this.finishChain(),this.pseudoelement=null,this.footnoteContent=!1,this.specificity=0,this.chain=[]}startSelectorRule(){this.isInsideSelectorRule("E_CSS_UNEXPECTED_SELECTOR")||(this.state=1,this.elementStyle={},this.pseudoelement=null,this.specificity=0,this.footnoteContent=!1,this.chain=[],this.invalid=!1)}error(e,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 qr(this.elementStyle,e,this.pseudoelement,t,this.viewConditionId)}special(e,t){let i;this.condition?i=new sr(t,0,this.condition):i=new K(t,0),Ih(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 ke([v.exclusive,v._static]),i),this.simpleProperty("flow-into",t,i),t=v.block),pt("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 sr(t,n,this.condition):new K(t,n);Tt(this.elementStyle,e,s)}finish(){return this.cascade}startFuncWithSelector(e){let t;switch(e){case"is":t=new sn(this);break;case"not":t=new Zf(this);break;case"where":t=new Jf(this);break;case"has":t=new Qf(this);break}t&&(t.startSelectorRule(),this.owner.pushHandler(t))}},Kf={"nth-child":Ef,"nth-of-type":lr,"nth-last-child":hr,"nth-last-of-type":ur},Nn=0,sn=class Dh extends nn{constructor(t){super(t.scope,t.owner,t.condition,t,t.regionId,t.validatorSet,!1),this.parent=t,u(this,"parentChain"),u(this,"chains",[]),u(this,"maxSpecificity",0),u(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 Af(this.selectorTexts):this.positive()?new Yr(this.chains):new Rf(this.chains)),this.increasingSpecificity()&&(this.parent.specificity+=this.maxSpecificity)):this.parentChain.push(new Ge("")),this.owner.popHandler()}startRuleBody(){this.reportAndSkip("E_CSS_UNEXPECTED_RULE_BODY")}error(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 Dh;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}},Zf=class extends sn{positive(){return!1}forgiving(){return!1}},Jf=class extends sn{increasingSpecificity(){return!1}},Qf=class extends sn{relational(){return!0}},eg=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 Zt(this.scope,100,n);this.scope.defineName(e,t.toExpr(this.scope,s))}}},Pn=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,u(this,"order"),this.order=0}property(e,t,i){i?D.warn("E_IMPORTANT_NOT_ALLOWED"):this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){D.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){D.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?this.getImportantSpecificity():this.getBaseSpecificity();n+=this.order,this.order+=Kr;let s=this.condition?new sr(t,n,this.condition):new K(t,n);Tt(this.elementStyle,e,s)}},tg=class extends ql{constructor(e,t){super(e),this.validatorSet=t,u(this,"elementStyle",{}),u(this,"order",0)}property(e,t,i){this.validatorSet.validatePropertyAndHandleShorthand(e,t,i,this)}invalidPropertyValue(e,t){D.warn("E_INVALID_PROPERTY_VALUE",`${e}:`,t.toString())}unknownProperty(e,t){D.warn("E_INVALID_PROPERTY",`${e}:`,t.toString())}simpleProperty(e,t,i){let n=i?Xl:jl;n+=this.order,this.order+=Kr;let s=new K(t,n);Tt(this.elementStyle,e,s)}};function Vh(e,t){let i=Ph(e);i&&i.forEach(n=>{n.matcher.matches()&&t(n.styles)})}function pr(e,t,i){Vh(i,n=>{Yi(e,n,t)})}function ig(e,t,i,n){let s=new tg(e,t),r=new gt(n,s);try{up(r,s,i)}catch(o){D.warn(o,"Style attribute parse error:")}return s.elementStyle}function Uh(e,t,i){let n=e["writing-mode"];if(n){let s=n.evaluate(t,"writing-mode");if(s&&s!==v.inherit&&s!==v.revert&&s!==v.unset)return s===v.vertical_rl}return i}function Hh(e,t,i){let n=e.direction;if(n){let s=n.evaluate(t,"direction");if(s&&s!==v.inherit&&s!==v.revert&&s!==v.unset)return s===v.rtl}return i}function $h(e,t,i,n,s){let r={};for(let o in e)wi(o)&&(r[o]=Ve(e,o));return pr(r,t,e),Gh(e,i,n,(o,a)=>{Yi(r,a,t),pr(r,t,a)}),r}function Gh(e,t,i,n){let s=dt(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 Yi(e,t,i){for(let n in t)if(wi(n)){let s=Ve(t,n),r=e[n];e[n]=or(i,r,s)}}var Wh=(e,t,i,n,s)=>{let r=i?n?hf:Eh:n?uf:kh;for(let o in e)if(e.hasOwnProperty(o)){let a=e[o];if(!a)continue;let h=r[o],l;if(h){let c=e[h];if(c&&c.priority>a.priority)continue;l=lf[h]?h:o}else l=o;t[l]=s(o,a)}},ng=class extends Ei{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 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=(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 ft&&e.values[0].name;return!t||!Nt(t)?(this.error=!0,G):this.getVarValue(t)||(e.values.length<2?(this.error=!0,G):e.values.length===2?e.values[1]:new qe(e.values.slice(1)))}},jh=class extends Ei{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=Ti(this.context.rootScope,new gt(i,null),"");if(n instanceof V)try{let s=n.expr.evaluate(this.context);typeof s=="number"&&(t=new T(s,"px"))}catch(s){D.warn(s)}return t}visitNumeric(e){return this.resolveViewportUnit&&(ol(e.unit)||$c(e.unit))?new T(e.num*this.context.queryUnitSize(e.unit,!1,this.vertical),"px"):typeof this.percentRef=="number"&&e.unit==="%"?new T(e.num*this.percentRef/100,"px"):e}};function Xn(e,t,i,n,s){try{if(t instanceof V)return t.expr instanceof De&&(t.expr.str.startsWith("named-string-")||t.expr.str.startsWith("running-element-"))?t:fp(e,t.expr,i);if(t instanceof T||t instanceof ki||t instanceof ke||t instanceof qe)return t.visit(new jh(e,!0,n,s))}catch(r){return D.warn(r),G}return t}var na={first:!1,forceEnd:!1,allowEnd:!1,last:!1};function sa(e){let t=e instanceof $e?e:typeof e=="string"?B(e):v.none;if(t===v.none)return na;let i=t instanceof ke?t.values:[t],n=Object.create(na);for(let s of i)if(s instanceof ft)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 ra(e){return!e.first&&!e.last&&!e.forceEnd&&!e.allowEnd}var sg={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!1,trimAdjacent:!1},oa={trimStart:!1,spaceFirst:!1,trimEnd:!1,allowEnd:!0,trimAdjacent:!0},aa={trimStart:!0,spaceFirst:!1,trimEnd:!0,allowEnd:!1,trimAdjacent:!0};function la(e){let t=e instanceof $e?e:typeof e=="string"?B(e):v.normal;if(t===v.normal)return oa;if(t===v.auto)return aa;let i=t instanceof ke?t.values:[t],n=Object.create(oa);for(let s of i)if(s instanceof ft)switch(s.name){case"trim-both":case"trim-auto":return aa;case"space-all":return sg;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 Is={ideographAlpha:!1,ideographNumeric:!1},rg={ideographAlpha:!0,ideographNumeric:!0};function ha(e){let t=e instanceof $e?e:typeof e=="string"?B(e):v.normal;if(t===v.normal||t===v.auto)return rg;if(t===v.none)return Is;let i=t instanceof ke?t.values:[t],n=Object.create(Is);for(let s of i)if(s instanceof ft)switch(s.name){case"no-autospace":return Is;case"ideograph-alpha":n.ideographAlpha=!0;break;case"ideograph-numeric":n.ideographNumeric=!0;break}return n}function ua(e,t){return!e.ideographAlpha&&!e.ideographNumeric&&!t.trimStart&&!t.spaceFirst&&!t.trimEnd&&!t.allowEnd&&!t.trimAdjacent}function ca(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 og=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=ca(s);let o=ha(t),a=la(i),h=sa(n);if(ra(h)&&ua(o,a))return;this.preprocessForTextSpacing(e);let l=e.style.whiteSpace;(r?e.offsetHeight:e.offsetWidth)===0&&(e.style.whiteSpace="pre");let c=e.ownerDocument.createNodeIterator(e,NodeFilter.SHOW_TEXT),p=null,d=null;for(let f=c.nextNode();f;f=d){d=c.nextNode();let g=!p,m=!p||/\n$/.test(p.textContent),y=!d||/^\n/.test(d.textContent),b=!d;this.processTextSpacing(f,g||m,g,m,y,b,p,d,o,a,h,s,r),p=f}e.style.whiteSpace=l}postLayoutBlock(e,t){var i,n,s,r,o,a,h;let l=!e||e.fragmentIndex===1&&d(),c=l||f();function p(b){var w;if(b?.nodeType!==1)return!1;let S=b;if(S.hasAttribute(xi))return!0;let{position:R,float:L}=(w=S.style)!=null?w:{};return R==="absolute"||R==="fixed"||L&&L!=="none"}function d(){let b=t[0];for(let w=b;;w=w.parent)if(!w||!w.inline){if(w?.fragmentIndex!==1)return!1;break}if(!b.inline)return!0;for(let w=b.viewNode.previousSibling;w;w=w.previousSibling)if(!Ue(w,b.whitespace)&&!p(w))return!1;return!0}function f(){var b,w;let S=t[0],R;for(;S&&S.inline&&(R=(b=S.viewNode)==null?void 0:b.previousSibling,!(R&&(R.nodeType===3&&/^[ \t\r\n\f]*$/.test(R.textContent)&&S.whitespace!==Ze.PRESERVE&&(R=R.previousSibling),R)));)S=S.parent;for(;R;){if(R.nodeType===1){if(R.localName==="br")return!0;let L=(w=R.style)==null?void 0:w.display;if(L&&L!=="inline")return!/^(inline|ruby)\b/.test(L)}else if(R.nodeType===3){if(S.whitespace===Ze.PRESERVE){if(/\n$/.test(R.textContent))return!0}else if(S.whitespace===Ze.NEWLINE&&/\n[ \t\r\n\f]*$/.test(R.textContent))return!0}R=R.lastChild}return!1}let g=-1;for(let b=0;b<t.length;b++){let w=t[b];if(!w.after&&w.inline&&!w.display&&w.parent&&w.viewNode.parentNode&&w.viewNode.nodeType===Node.TEXT_NODE&&!Ue(w.viewNode,w.whitespace)){let S=function(E){var A,I,O;if(((A=E.viewNode)==null?void 0:A.nodeType)===1)return E.viewNode.localName==="br";if(((I=E.viewNode)==null?void 0:I.nodeType)===3){if(E.whitespace===Ze.PRESERVE){if(/\n$/.test(E.viewNode.textContent))return!0}else if(E.whitespace===Ze.NEWLINE&&/\n[ \t\r\n\f]*$/.test(E.viewNode.textContent))return!0;if(((O=E.viewNode.previousElementSibling)==null?void 0:O.localName)==="br")return Ue(E.viewNode,E.whitespace)}return!1},R=function(E){var A,I,O;if(((A=E.viewNode)==null?void 0:A.nodeType)===1)return E.viewNode.localName==="br";if(((I=E.viewNode)==null?void 0:I.nodeType)===3){if(E.whitespace===Ze.PRESERVE){if(/^\n/.test(E.viewNode.textContent))return!0}else if(E.whitespace===Ze.NEWLINE&&/^[ \t\r\n\f]*\n/.test(E.viewNode.textContent))return!0;if(((O=E.viewNode.nextElementSibling)==null?void 0:O.localName)==="br")return Ue(E.viewNode,E.whitespace)}return!1};var m=S,y=R;let L=ca((r=(n=(i=w.lang)!=null?i:w.parent.lang)!=null?n:e?.lang)!=null?r:(s=e?.parent)==null?void 0:s.lang),_=ha(w.inheritedProps["text-autospace"]),U=la(w.inheritedProps["text-spacing-trim"]),W=sa(w.inheritedProps["hanging-punctuation"]);if(ra(W)&&ua(_,U)||/\b(flex|grid)\b/.test(w.parent.display))continue;g<0&&(g=b);let we=null,He=null,ce=b===g,de=b===g&&l,x=b===g&&c,P=!1,C=!1;for(let E=b-1;E>=0;E--){let A=t[E];if(S(A)){x=!0;break}if(!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){we=A.viewNode;break}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((o=A.viewNode)==null?void 0:o.nodeType)===1&&(A.viewNode.localName==="br"||Wt[A.viewNode.localName]))break;E===0&&(ce=!0,l&&(de=!0,x=!0))}for(let E=b+1;E<t.length;E++){let A=t[E];if(R(A)){P=!0;break}if(A.viewNode!==w.viewNode&&!A.display&&A.viewNode.nodeType===Node.TEXT_NODE&&A.viewNode.textContent.length>0){He=A.viewNode;break}if(A.display&&!/^(inline|ruby)\b/.test(A.display)||((a=A.viewNode)==null?void 0:a.nodeType)===1&&(A.viewNode.localName==="br"||Wt[A.viewNode.localName])){E===t.length-1&&p(A.viewNode)&&(C=!0);break}if(E===t.length-1){P=!0,C=!0;for(let I=A.viewNode.nextSibling;I;I=I.nextSibling)if(!p(I)){C=!1;break}}}if(((h=w.parent)==null?void 0:h.display)==="inline-block"){if(!de){let E=w.parent.viewNode.firstChild;for(;Ue(E,w.whitespace);)E=E.nextSibling;w.viewNode===E&&(de=!0)}if(!C){let E=w.parent.viewNode.lastChild;for(;Ue(E,w.whitespace);)E=E.previousSibling;w.viewNode===E&&(C=!0)}}this.processTextSpacing(w.viewNode,ce,de,x,P,C,we,He,_,U,W,L,w.vertical)}}}processTextSpacing(e,t,i,n,s,r,o,a,h,l,c,p,d){let f=e.textContent,g=e.ownerDocument,m,y,b;function w(){if(t)return!0;if(!o)return!1;m||(m=g.createRange(),m.selectNode(e));let P=m.getClientRects()[0];y||(y=g.createRange(),y.selectNode(o));let C=y.getClientRects(),E=C[C.length-1];return!P||!E?!1:d?P.top<E.top+E.height-P.width||P.left+P.width<E.left+P.width/10||P.left>E.left+E.width-P.width/10:P.left<E.left+E.width-P.height||P.top>E.top+E.height-P.height/10||P.top+P.height<E.top+P.height/10}function S(){if(!a)return!1;m||(m=g.createRange(),m.selectNode(e));let P=m.getClientRects()[0];b||(b=g.createRange(),b.selectNode(a));let C=b.getClientRects()[0];return!P||!C?!1:d?P.top+P.height>C.top+P.width||P.left>C.left+C.width-P.width/10||P.left+P.width<C.left+P.width/10:P.left+P.width>C.left+P.height||P.top+P.height<C.top+P.height/10||P.top>C.top+C.height-P.height/10}let R=!1,L=!1,_=!1,U=!1,W;if(i&&c.first&&/^[\p{Ps}\p{Pf}\p{Pi}'"\u3000]\p{M}*$/u.test(f)?(W="viv-ts-open",R=!0,L=!0):r&&c.last&&/^[\p{Pe}\p{Pf}\p{Pi}'"]\p{M}*$/u.test(f)?(W="viv-ts-close",R=!0,_=!0):(c.forceEnd||c.allowEnd)&&/^[、。,.、。]\p{M}*$/u.test(f)?(W="viv-ts-close",R=!0,U=!0):(l.trimStart||l.spaceFirst||l.trimAdjacent)&&/^[‘“〝([{⦅〈〈《「『【〔〖〘〚]\p{M}*$/u.test(f)?(W="viv-ts-open",R=!0):(l.trimEnd||l.allowEnd||l.trimAdjacent)&&(/^[’”〞〟)]}⦆〉〉》」』】〕〗〙〛]\p{M}*$/u.test(f)||p==="zh-hans"&&/^[:;]\p{M}*$/u.test(f)||p!=="zh-hant"&&/^[、。,.]\p{M}*$/u.test(f))&&(W="viv-ts-close",R=!0),R){let P=function(O){let z=parseFloat(g.defaultView.getComputedStyle(O).fontSize)*.7;return(d?O.offsetHeight:O.offsetWidth)>z},C=function(){return d?E.offsetLeft:E.offsetTop};var we=P,He=C;if(e.parentElement.localName==="viv-ts-inner")return;let E=g.createElement(W),A=g.createElement("viv-ts-inner");E.appendChild(A),e.parentNode.insertBefore(E,e),A.appendChild(e);let I=P(A);if(I||L||_||U){if(W==="viv-ts-open"){if(L)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)&&w())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"&&P(o.parentElement)))E.className="viv-ts-trim";else if((l.trimStart||l.spaceFirst)&&w()){let O=C();E.className="viv-ts-auto",O===C()&&!w()&&(E.className="viv-ts-trim")}}else if(W==="viv-ts-close"){if(_)E.className=I?"viv-hang-last":"viv-hang-last viv-hang-hw";else if(r||s){let O=C();U?(E.className=I?c.allowEnd&&l.allowEnd?"viv-ts-auto":"viv-hang-end":"viv-hang-end viv-hang-hw",c.allowEnd&&O===C()&&(l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-hang-end",O===C()&&(E.className="")):E.className="viv-ts-space")):l.trimEnd?E.className="viv-ts-trim":l.allowEnd?(E.className="viv-ts-auto",O===C()&&(E.className="")):E.className="viv-ts-space"}else if(a&&/^[\p{Pe}\p{Pf}\u00B7\u2027\u30FB\u3000:;、。,.]/u.test(a.textContent))I&&l.trimAdjacent&&(E.className="viv-ts-trim");else if(U){let O=S(),z=O&&c.allowEnd;z||(E.className=I?"viv-hang-end":"viv-hang-end viv-hang-hw"),I?z&&l.trimEnd?E.className="viv-ts-auto":!z&&!S()?E.className="":!O&&c.allowEnd&&(l.trimEnd?(E.className="viv-ts-auto",S()||(E.className="viv-hang-end")):(E.className="viv-ts-space",S()||(l.allowEnd?(E.className="viv-ts-auto",S()||(E.className="viv-hang-end")):E.className="viv-hang-end"))):!O&&!S()&&(E.className="")}else if(l.trimEnd||l.allowEnd)if(S())l.allowEnd?E.className="viv-ts-space":E.className="viv-ts-auto";else{let O=C();E.className="viv-ts-auto",O===C()&&(E.className="")}}}}let ce=!1;function de(P){var C;let E=(C=P?.ownerDocument.defaultView)==null?void 0:C.getComputedStyle(P);return!!E&&(E.textOrientation==="upright"||E.textCombineUpright==="all"||E["-webkit-text-combine"]==="horizontal")}function x(P,C){if(P.nodeType===1){let I=g.defaultView.getComputedStyle(P);if(parseFloat(I.marginInlineEnd)||parseFloat(I.borderInlineEndWidth)||parseFloat(I.paddingInlineEnd))return!0}let E=P.parentElement;if(E&&!E.contains(C))return x(E,C);if(C.nodeType===1){let I=g.defaultView.getComputedStyle(C);if(parseFloat(I.marginInlineStart)||parseFloat(I.borderInlineStartWidth)||parseFloat(I.paddingInlineStart))return!0}let A=C.parentElement;return A&&!A.contains(P)?x(P,A):!1}(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))&&!(d&&de(o.parentElement))&&!x(o,e)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e),ce=!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))&&!(d&&de(a.parentElement))&&!x(e,a)&&(e.parentNode.insertBefore(g.createElement("viv-ts-thin-sp"),e.nextSibling),ce=!0))}registerHooks(){ht("POLYFILLED_INHERITED_PROPS",this.getPolyfilledInheritedProps.bind(this)),ht("PREPROCESS_SINGLE_DOCUMENT",this.preprocessSingleDocument.bind(this)),ht("POST_LAYOUT_BLOCK",this.postLayoutBlock.bind(this),!0)}},Zr=new og;Zr.registerHooks();function ag(e){Zr.preprocessForTextSpacing(e)}function lg(e,t,i,n,s,r){Zr.processGeneratedContent(e,t,i,n,s,r)}var Ln=new DOMParser().parseFromString('<root xmlns="http://www.pyroxy.com/ns/shadow"/>',"text/xml"),hg=["footnote-marker","first-5-lines","first-4-lines","first-3-lines","first-2-lines","first-line","first-letter","before","","after"],Jr="data-adapt-pseudo";function di(e){return e.getAttribute(Jr)||""}function fr(e,t){e.setAttribute(Jr,t)}var da=class{constructor(e,t,i,n,s){this.element=e,this.style=t,this.styler=i,this.context=n,this.exprContentListener=s,u(this,"contentProcessed",{})}getStyle(e,t){let i=di(e);this.styler&&i&&i.match(/after$/)&&(this.style=this.styler.getStyle(this.element,!0),this.styler=null);let n=dt(this.style,"_pseudos")[i]||{};if(i.match(/^first-/)&&!n["x-first-pseudo"]){let s=1,r;i=="first-letter"?s=0:(r=i.match(/^first-([0-9]+)-lines$/))!=null&&(s=r[1]-0),n["x-first-pseudo"]=new K(new Jt(s),0)}return n}processContent(e,t,i){let n=di(e);if(!this.contentProcessed[n]){this.contentProcessed[n]=!0;let s=t.content;s&&Dt(s)&&(s.visit(new Wn(e,this.context,s,this.exprContentListener)),ag(e))}}},Xw=Hn.isInstanceOfAfterIfContinuesLayoutConstraint,ug=os.registerFragmentIndex,qw=os.clearFragmentIndices,cg=class{constructor(e,t){this.sourceNode=e,this.styler=t}createElement(e,t){let i=t.viewNode.ownerDocument.createElement("div"),n=new Qr(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 N(r,"display","block"),k(r)})}createNodePositionForPseudoElement(){let e=Ln.createElementNS("http://www.w3.org/1999/xhtml","div");fr(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 zt(i)}createShadowContext(e){return new Ks(this.sourceNode,e,null,null,null,Pt.ShadowType.ROOTED,this.styler)}},dg=class Xh{constructor(t,i,n){this.nodeContext=t,this.afterIfContinues=i,this.pseudoElementHeight=n,u(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),k(!0))):k(!0)}getRepetitiveElements(){return new pg(this.nodeContext,this.pseudoElementHeight)}equalsTo(t){return t instanceof Xh?this.afterIfContinues==t.afterIfContinues:!1}getPriorityOfFinishBreak(){return 9}},pg=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 qh(e,t){if(!e||!e.afterIfContinues||e.after||t.isFloatNodeContext(e))return k(e);let i=e.afterIfContinues;return i.createElement(t,e).thenAsync(n=>{let s=gg(e,t,n);return t.fragmentLayoutConstraints.push(new dg(e,i,s)),k(e)})}function Yh(e,t){return e.thenAsync(i=>qh(i,t))}function fg(e,t){let i=F("processAfterIfContinuesOfAncestors"),n=e;return i.loop(()=>{if(n!==null){let s=qh(n,t);return n=n.parent,s.thenReturn(!0)}else return k(!1)}).then(()=>{i.finish(!0)}),i.result()}function gg(e,t,i){let n=e.viewNode;n.appendChild(i);let s=Qs(i,t,e.vertical);return n.removeChild(i),s}var mg=class{constructor(e){this.constraints=e}allowLayout(e){return this.constraints.every(t=>t.allowLayout(e))}},Rs=class extends $r{constructor(e,t){super(),this.checkPoints=e,this.penalty=t,u(this,"alreadyEvaluated",!1),u(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]}},qn=class extends dh{constructor(e,t,i,n,s){super(e),this.layoutContext=t,this.clientLayout=i,this.layoutConstraint=n,this.pageFloatLayoutContext=s,u(this,"last"),u(this,"viewDocument"),u(this,"flowRootFormattingContext",null),u(this,"isFloat",!1),u(this,"isFootnote",!1),u(this,"startEdge",0),u(this,"endEdge",0),u(this,"beforeEdge",0),u(this,"afterEdge",0),u(this,"footnoteEdge",0),u(this,"box",null),u(this,"chunkPositions",null),u(this,"bands",null),u(this,"overflown",!1),u(this,"breakPositions",null),u(this,"pageBreakType",null),u(this,"forceNonfitting",!0),u(this,"leftFloatEdge",0),u(this,"rightFloatEdge",0),u(this,"bottommostFloatTop",0),u(this,"stopAtOverflow",!0),u(this,"lastAfterPosition",null),u(this,"fragmentLayoutConstraints",[]),u(this,"pseudoParent",null),u(this,"nodeContextOverflowingDueToRepetitiveElements",null),u(this,"blockDistanceToBlockEndFloats",NaN),u(this,"breakAtTheEdgeBeforeFloat",null),this.last=e.lastChild,this.viewDocument=e.ownerDocument,s.setContainer(this)}getTopEdge(){return this.vertical?this.rtl?this.endEdge:this.startEdge:this.beforeEdge}getBottomEdge(){return this.vertical?this.rtl?this.startEdge:this.endEdge:this.afterEdge}getLeftEdge(){return this.vertical?this.afterEdge:this.rtl?this.endEdge:this.startEdge}getRightEdge(){return this.vertical?this.beforeEdge:this.rtl?this.startEdge:this.endEdge}isFloatNodeContext(e){return!!e.floatSide&&(!this.isFloat||!!e.parent)}stopByOverflow(e){return this.stopAtOverflow&&!!e&&e.overflow}isOverflown(e){return this.vertical?e<this.footnoteEdge:e>this.footnoteEdge}getExclusions(){let e=this.pageFloatLayoutContext.getFloatFragmentExclusions();return this.exclusions.concat(e)}openAllViews(e){let t=F("openAllViews"),i=e.steps;this.layoutContext.setViewRoot(this.element,this.isFootnote);let n=i.length-1,s=null;return t.loop(()=>{for(;n>=0;){let r=s,o=i[n];if(s=Gn(o,r),n===i.length-1&&!s.formattingContext&&(s.formattingContext=this.flowRootFormattingContext),n==0&&(s.offsetInNode=this.calculateOffsetInNodeForNodeContext(e),s.after=e.after,s.preprocessedTextContent=e.preprocessedTextContent,s.after))break;let a=this.layoutContext.setCurrent(s,n==0&&s.offsetInNode==0);if(n--,a.isPending())return a}return k(!1)}).then(()=>{t.finish(s)}),t.result()}calculateOffsetInNodeForNodeContext(e){return e.preprocessedTextContent?kp(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 s=e.viewNode.textContent,r=s.match(Fs),o=r?r[0].length:0;if(!r&&((i=e.sourceNode)==null?void 0:i.nodeType)===3&&((n=e.sourceNode.nextSibling)==null?void 0:n.nodeType)===3&&s===e.sourceNode.textContent){let a=s+e.sourceNode.nextSibling.textContent,h=a.match(Fs);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 k(e)}buildViewToNextBlockEdge(e,t){let i=!1,n=F("buildViewToNextBlockEdge");return n.loopWithFrame(s=>{var r;e.viewNode&&!ui(e)&&((r=e.viewNode.parentElement)==null?void 0:r.namespaceURI)==="http://www.w3.org/1999/xhtml"&&t.push(e.copy()),this.maybePeelOff(e,0).then(o=>{let a=o;a!==e&&(e=a,ui(e)||t.push(e.copy())),this.nextInTree(e).then(h=>{if(e=h,!e){s.breakLoop();return}(i||!this.layoutConstraint.allowLayout(e))&&(i=!0,e=e.modify(),e.overflow=!0),this.isFloatNodeContext(e)&&(gi(e.floatReference)||e.floatSide==="footnote")?this.layoutFloatOrFootnote(e).then(l=>{if(e=l,this.pageFloatLayoutContext.isInvalidated()&&(e=null),!e){s.breakLoop();return}s.continueLoop()}):e.inline?s.continueLoop():s.breakLoop()})})}).then(()=>{n.finish(e)}),n.result()}nextInTree(e,t){let i=this.layoutContext.nextInTree(e,t);return Yh(i,this)}buildDeepElementView(e){if(!e.viewNode)return k(e);let t=[],i=e.sourceNode,n=F("buildDeepElementView");return n.loopWithFrame(s=>{e.viewNode&&e.inline&&!ui(e)?t.push(e.copy()):(t.length>0&&this.postLayoutBlock(e,t),t=[]),this.maybePeelOff(e,0).then(r=>{let o=r;if(o!==e){let a=o;for(;a&&a.sourceNode!=i;)a=a.parent;if(a==null){e=o,s.breakLoop();return}ui(o)||t.push(o.copy())}this.nextInTree(o).then(a=>{e=a,!e||e.sourceNode==i?s.breakLoop():this.layoutConstraint.allowLayout(e)?s.continueLoop():(e=e.modify(),e.overflow=!0,this.stopAtOverflow?s.breakLoop():s.continueLoop())})})}).then(()=>{t.length>0&&this.postLayoutBlock(e,t),n.finish(e)}),n.result()}createFloat(e,t,i,n){let s=this.viewDocument.createElement("div");return this.vertical?(n>=this.height&&(n-=.1),n<1&&(n=0),N(s,"height",`${i}px`),N(s,"width",`${n}px`)):(i>=this.width&&(i-=.1),i<1&&(i=0),N(s,"width",`${i}px`),N(s,"height",`${n}px`)),N(s,"float",t),N(s,"clear",t),this.element.insertBefore(s,e),s}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(),s=null;for(let r of t){let o=r.y2-r.y1;r.left=this.createFloat(e,"left",r.x1-i,o),r.right=this.createFloat(e,"right",n-r.x2,o),r.x1<n&&r.x2>i?s=r:s||N(r.right,"float","none")}if(s){let r=t[t.length-1],o=this.vertical?-this.getLeftEdge():this.getBottomEdge();s!==r&&r.y2>=o&&(this.footnoteEdge=this.vertical?-s.y2:s.y2)}}calculateEdge(e,t,i,n){let s;if(e&&hi(e.viewNode))return NaN;if(e&&e.after&&!e.inline&&(s=ai(e,this.clientLayout,0,this.vertical),!isNaN(s)))return s;e=t[i];let r=n-e.boxOffset;for(;;){if(s=ai(e,this.clientLayout,r,this.vertical),!isNaN(s))return s;if(r>0){r--;continue}if(i--,i<0)return this.beforeEdge;e=t[i],e.viewNode.nodeType!=1&&(r=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 xs(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 xs(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 xs(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=F("layoutFloat"),i=e.viewNode,n=Up(e.floatSide,e.vertical,e.direction);return N(i,"float","none"),N(i,"display","inline-block"),N(i,"vertical-align","top"),this.buildDeepElementView(e).then(s=>{let r=this.clientLayout.getElementClientRect(i),o=this.getComputedMargin(i),a=new nt(r.left-o.left,r.top-o.top,r.right+o.right,r.bottom+o.bottom),h=this.rtl?this.endEdge:this.startEdge,l=this.rtl?this.startEdge:this.endEdge,c=e.parent;for(;c&&c.inline;)c=c.parent;if(c){let S=c.viewNode.ownerDocument.createElement("div");S.style.left="0px",S.style.top="0px",this.vertical?(S.style.bottom="0px",S.style.width="1px"):(S.style.right="0px",S.style.height="1px"),c.viewNode.appendChild(S);let R=this.clientLayout.getElementClientRect(S);h=Math.max(this.rtl?this.getEndEdge(R):this.getStartEdge(R),h),l=Math.min(this.rtl?this.getStartEdge(R):this.getEndEdge(R),l),c.viewNode.removeChild(S);let L=this.vertical?a.y2-a.y1:a.x2-a.x1;n=="left"?l=Math.max(l,h+L):h=Math.min(h,l-L),c!==e.parent&&!e.firstPseudo&&(c.viewNode.appendChild(i),i.setAttribute("data-vivliostyle-float-box-moved","true"))}let p=new nt(h,this.getBoxDir()*this.beforeEdge,l,this.getBoxDir()*this.afterEdge),d=a;this.vertical&&(d=Dn(a));let f=this.getBoxDir();if(d.y1<this.bottommostFloatTop*f){let S=d.y2-d.y1;d.y1=this.bottommostFloatTop*f,d.y2=d.y1+S}pd(p,this.bands,d,n),this.vertical&&(a=Tl(d));let g=this.getComputedInsets(i);N(i,"width",`${a.x2-a.x1-g.left-g.right}px`),N(i,"height",`${a.y2-a.y1-g.top-g.bottom}px`),N(i,"position","absolute"),e.display,N(i,"display",e.display);let m,y=null;if(c&&(c.containingBlockForAbsolute?y=c:y=c.getContainingBlockForAbsolute()),y){let S=y.viewNode.ownerDocument.createElement("div");S.style.position="absolute",y.vertical?S.style.right="0":S.style.left="0",S.style.top="0",y.viewNode.appendChild(S),m=this.clientLayout.getElementClientRect(S),y.viewNode.removeChild(S)}else m={left:this.getLeftEdge()-this.paddingLeft,right:this.getRightEdge()+this.paddingRight,top:this.getTopEdge()-this.paddingTop};(y?y.vertical:this.vertical)?N(i,"right",`${m.right-a.x2}px`):N(i,"left",`${a.x1-m.left}px`),N(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,w=this.vertical?a.x2:a.y1;!this.isOverflown(b)||this.breakPositions.length==0?(this.killFloats(),p=new nt(this.getLeftEdge(),this.getTopEdge(),this.getRightEdge(),this.getBottomEdge()),this.vertical&&(p=Dn(p)),fd(p,this.bands,d,null,n),this.createFloats(),n=="left"?this.leftFloatEdge=b:this.rightFloatEdge=b,this.bottommostFloatTop=w,this.updateMaxReachedAfterEdge(b),t.finish(s)):(e=e.modify(),e.overflow=!0,t.finish(e))}),t.result()}setupFloatArea(e,t,i,n,s,r){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();e.setHorizontalPosition(l.x1-a.originX,l.x2-l.x1),e.setVerticalPosition(l.y1-a.originY,l.y2-l.y1),s.adjustPageFloatArea(e,a,this),e.init();let c=!!o.setFloatAreaDimensions(e,t,i,n,!0,!o.hasFloatFragments(),r);return c?(e.killFloats(),e.init()):a.element.parentNode.removeChild(h),c}createPageFloatArea(e,t,i,n,s){let r=this.element.ownerDocument.createElement("div");N(r,"position","absolute");let o=this.pageFloatLayoutContext.getPageFloatLayoutContext(e.floatReference),a=new Di(null,Re.COLUMN,null,this.pageFloatLayoutContext.flowName,e.nodePosition,null,null),h=o.getContainer(),l=new yg(t,r,this.layoutContext.clone(),this.clientLayout,this.layoutConstraint,a,h);return a.setContainer(l),this.setupFloatArea(l,e.floatReference,t,i,n,s)?l:null}layoutSinglePageFloatFragment(e,t,i,n,s,r,o){let a=this.pageFloatLayoutContext;e=(o?o.continuations:[]).concat(e);let h=e[0].float,l=a.getPageFloatPlacementCondition(h,t,i),c=this.createPageFloatArea(h,t,r,s,l),p={floatArea:c,pageFloatFragment:null,newPosition:null};if(!c)return k(p);let d=F("layoutSinglePageFloatFragment"),f=!1,g=0;return d.loopWithFrame(m=>{if(g>=e.length){m.breakLoop();return}let y=e[g],b=new zt(y.nodePosition);c.layout(b,!0).then(w=>{p.newPosition=w,!w||n?(g++,m.continueLoop()):(f=!0,m.breakLoop())})}).then(()=>{if(!f){let m=a.setFloatAreaDimensions(c,h.floatReference,t,r,!1,n,l);if(!m)f=!0;else{let y=s.createPageFloatFragment(e,m,c,!!p.newPosition);a.addPageFloatFragment(y,!0),p.pageFloatFragment=y}}d.finish(p)}),d.result()}layoutPageFloatInner(e,t,i,n){let s=this.pageFloatLayoutContext,r=e.float;s.stashEndFloatFragments(r);function o(h,l){l?s.removePageFloatFragment(l,!0):h&&h.element.parentNode.removeChild(h.element),s.restoreStashedFragments(r.floatReference),s.deferPageFloat(e)}let a=F("layoutPageFloatInner");return this.layoutSinglePageFloatFragment([e],r.floatSide,r.clearSide,!s.hasFloatFragments(),t,i,n).then(h=>{let l=h.floatArea,c=h.pageFloatFragment,p=h.newPosition;c?this.layoutStashedPageFloats(r.floatReference,[n]).then(d=>{if(d){if(s.addPageFloatFragment(c),s.discardStashedFragments(r.floatReference),p){let f=new jo(r,p.primary);s.deferPageFloat(f)}a.finish(!0)}else o(l,c),a.finish(!1)}):(o(l,c),a.finish(!1))}),a.result()}layoutStashedPageFloats(e,t){let i=this.pageFloatLayoutContext,n=i.getStashedFloatFragments(e),s=[],r=[],o=!1,a=F("layoutStashedPageFloats"),h=0;return a.loopWithFrame(l=>{if(h>=n.length){l.breakLoop();return}let c=n[h];if(t.includes(c)){h++,l.continueLoop();return}let p=new Si().findByFloat(c.continuations[0].float);this.layoutSinglePageFloatFragment(c.continuations,c.floatSide,null,!1,p,null).then(d=>{let f=d.floatArea;f&&s.push(f);let g=d.pageFloatFragment;g?(r.push(g),h++,l.continueLoop()):(o=!0,l.breakLoop())})}).then(()=>{o?(r.forEach(l=>{i.removePageFloatFragment(l,!0)}),s.forEach(l=>{let c=l.element;c&&c.parentNode&&c.parentNode.removeChild(c)})):n.forEach(l=>{let c=l.area.element;c&&c.parentNode&&c.parentNode.removeChild(c)}),a.finish(!o)}),a.result()}setFloatAnchorViewNode(e){let t=e.viewNode.parentNode,i=t.ownerDocument.createElement("span");i.setAttribute(xi,"1"),e.floatSide==="footnote"&&this.layoutContext.applyPseudoelementStyle(e,"footnote-call",i),t.appendChild(i),t.removeChild(e.viewNode);let n=e.modify();return n.after=!0,n.viewNode=i,n}resolveFloatReferenceFromColumnSpan(e,t,i){let n=F("resolveFloatReferenceFromColumnSpan"),s=this.pageFloatLayoutContext,r=s.getPageFloatLayoutContext(Re.REGION);return s.getContainer().width<r.getContainer().width&&e===Re.COLUMN?t===v.auto?this.buildDeepElementView(i.copy()).then(o=>{let a=o.viewNode,h=Dr(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(Re.REGION):n.finish(e)}):t===v.all?n.finish(Re.REGION):n.finish(e):n.finish(e),n.result()}layoutPageFloat(e){let t=this.pageFloatLayoutContext,i=new Si().findByNodeContext(e),n,s=t.findPageFloatByNodePosition(e.toNodePosition());return s?n=k(s):n=i.createPageFloat(e,t,this),n.thenAsync(r=>{let o=$n(e,0),a=this.setFloatAnchorViewNode(e),h=i.findPageFloatFragment(r,t),l=new jo(r,o);if(h&&h.hasFloat(r))return t.registerPageFloatAnchor(r,a.viewNode),k(a);if(t.isForbidden(r)||t.hasPrecedingFloatsDeferredToNext(r))return t.deferPageFloat(l),t.registerPageFloatAnchor(r,a.viewNode),k(a);if(this.nodeContextOverflowingDueToRepetitiveElements)return k(null);{let c=ai(a,this.clientLayout,0,this.vertical);return this.isOverflown(c)?k(a):this.layoutPageFloatInner(l,i,c,h).thenAsync(p=>p?k(null):(t.registerPageFloatAnchor(r,a.viewNode),k(a)))}})}processLineStyling(e,t,i){let n=F("processLineStyling"),s=i.concat([]);i.splice(0,i.length);let r=0,o=e.firstPseudo;return o.count==0&&(o=o.outer),n.loopWithFrame(a=>{if(!o){a.breakLoop();return}let h=this.findLinePositions(s),l=o.count-r;if(h.length<=l){a.breakLoop();return}let c=this.findAcceptableBreakInside(s,h[l-1],!0);if(c==null){a.breakLoop();return}this.finishBreak(c,!1,!1).then(()=>{r+=l,this.layoutContext.peelOff(c,0).then(p=>{e=p,o=e.firstPseudo,s=[],this.buildViewToNextBlockEdge(e,s).then(d=>{t=d,a.continueLoop()})})})}).then(()=>{Array.prototype.push.apply(i,s),n.finish(t)}),n.result()}isLoneImage(e){return e.length!=2&&this.breakPositions.length>0?!1:e[0].sourceNode==e[1].sourceNode&&Wt[e[0].sourceNode.localName]}getTrailingMarginEdgeAdjustment(e){let t=0,i=0;for(let n=e.length-1;n>=0;n--){let s=e[n];if(!s.after||!s.viewNode||s.viewNode.nodeType!=1)break;let r=this.getComputedMargin(s.viewNode),o=this.vertical?-r.left:r.bottom;o>0?t=Math.max(t,o):i=Math.min(i,o)}return t+i}layoutBreakableBlock(e){let t=F("layoutBreakableBlock"),i=[];return this.buildViewToNextBlockEdge(e,i).then(n=>{let s=i.length-1;if(s<0){t.finish(n);return}this.postLayoutBlock(n,i);let r=this.calculateEdge(n,i,s,i[s].boxOffset),o=!1;if(!n||!hi(n.viewNode)){let h=mi(n,this.collectElementsOffset());o=this.isOverflown(r+(this.vertical?-1:1)*h.minimum),this.isOverflown(r+(this.vertical?-1:1)*h.current)&&!this.nodeContextOverflowingDueToRepetitiveElements&&(this.nodeContextOverflowingDueToRepetitiveElements=n)}n==null&&(r+=this.getTrailingMarginEdgeAdjustment(i)),this.updateMaxReachedAfterEdge(r);let a;e.firstPseudo?a=this.processLineStyling(e,n,i):a=k(n),a.then(h=>{i.length>0&&(this.saveBoxBreakPosition(i),o&&!this.isLoneImage(i)&&h&&(h=h.modify(),h.overflow=!0)),t.finish(h)})}),t.result()}postLayoutBlock(e,t){pt("POST_LAYOUT_BLOCK").forEach(i=>{i(e,t,this)})}findEndOfLine(e,t,i){let n=this.vertical?e-1:e+1,s=0,r=t[0].boxOffset,o=s,a=t.length-1,h=t[a].boxOffset,l;for(;r<h;){l=r+Math.ceil((h-r)/2),o=s;let c=a;for(;o<c;){let d=o+Math.ceil((c-o)/2);t[d].boxOffset>l?c=d-1:o=d}let p=this.calculateEdge(null,t,o,l);if(this.vertical?p<=n:p>=n){for(h=l-1;t[o].boxOffset==l;)o--;a=o}else i&&this.updateMaxReachedAfterEdge(p),r=l,s=o}return{nodeContext:t[o],index:r,checkPointIndex:o}}findAcceptableBreakInside(e,t,i){var n,s;let r=this.findEndOfLine(t,e,!0),o=r.nodeContext;if(r.checkPointIndex===0&&r.index===o.boxOffset)return null;let a=o.viewNode;if(a.nodeType!=1&&((n=a.parentElement)==null?void 0:n.localName)!=="viv-ts-inner"){let h=a;o=this.resolveTextNodeBreaker(o).breakTextNode(h,o,r.index,e,r.checkPointIndex,i)}else{let h=Ko(o);if(h){if(((s=this.breakPositions)==null?void 0:s[0])instanceof Rs&&h!=null&&h.viewNode.contains(this.breakPositions[0].checkPoints[0].viewNode))return null;o=h}}return this.clearOverflownViewNodes(o,!1),o}resolveTextNodeBreaker(e){return pt("RESOLVE_TEXT_NODE_BREAKER").reduce((t,i)=>i(e)||t,Yn.instance)}getRangeBoxes(e,t){let i=[],n=e.ownerDocument.createRange(),s=!1,r=e,o=null,a=!1,h=!0;for(;h;){let l=!0;do{let c=null;r==t&&(t.nodeType===1?h=!(!t.firstChild||s):h=!1);let p=r.nodeType===1?r:null;p?s?s=!1:Hr(p)?l=!a:!p.firstChild||Wt[p.localName]||/^r(uby|[bt]c?)$/.test(p.localName)||Zp(this.clientLayout.getElementComputedStyle(p).display)?(l=!a,l?(p.localName==="ruby"&&r.firstChild&&(r=r.firstChild),n.setStartBefore(r),a=!0,o=r):p.localName!=="ruby"&&(o=r),r.contains(t)&&(h=!1)):c=r.firstChild:(a||(r.parentNode==null?h=!1:(n.setStartBefore(r),a=!0)),o=r),c||(c=r.nextSibling,c||(s=!0,c=r.parentNode)),r=c}while(l&&h);if(a){n.setEndAfter(o);let c=this.clientLayout.getRangeClientRects(n);for(let p=0;p<c.length;p++)i.push(c[p]);a=!1}}return i}findLinePositions(e){let t=[],i=this.getRangeBoxes(e[0].viewNode,e[e.length-1].viewNode);i.sort(this.vertical?Op:Fp);let n=0,s=0,r=0,o=0,a=0,h=this.getBoxDir();for(;;){if(a<i.length){let l=i[a],c=1;if(o>0){let p=Math.max(this.getBoxSize(l),1);h*this.getBeforeEdge(l)<h*n?c=h*(this.getAfterEdge(l)-n)/p:h*this.getAfterEdge(l)>h*s?c=h*(s-this.getBeforeEdge(l))/p:c=1}if(o==0||c>=.6||c>=.2&&this.getStartEdge(l)>=r-1){r=this.getEndEdge(l),this.vertical?(n=o==0?l.right:Math.max(n,l.right),s=o==0?l.left:Math.min(s,l.left)):(n=o==0?l.top:Math.min(n,l.top),s=o==0?l.bottom:Math.max(s,l.bottom)),o++,a++;continue}}if(o>0&&(t.push(s),o=0),a>=i.length)break}return t.sort(Qa),this.vertical&&t.reverse(),t}calculateClonedPaddingBorder(e){let t=0;for(let i=e;i;i=i.parent)if(!i.inline&&_i(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=mi(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 s=e.checkPoints,r=s[0];for(;r.parent&&r.inline;)r=r.parent;let o,a;t?(o=1,a=1):(o=Math.max((r.inheritedProps.widows||2)-0,1),a=Math.max((r.inheritedProps.orphans||2)-0,1));let h=this.calculateClonedPaddingBorder(r),l=this.findLinePositions(s),c=this.footnoteEdge-h,p=this.getBoxDir(),d=this.getOffsetByRepetitiveElements(e);c-=p*d;let f=this.findFirstOverflowingEdgeAndCheckPoint(s);isNaN(f.edge)&&(f.edge=p*(1/0));let g=Bt(l.length,w=>{let S=l[w];return this.vertical?S<c||S<=f.edge:S>c||S>=f.edge}),m=g<=0;m&&(g=Bt(l.length,w=>this.vertical?l[w]<c:l[w]>c));let y=s[s.length-1].viewNode;if(y?.parentElement.localName==="viv-ts-inner"&&(y=y.parentElement.parentElement),(g===l.length&&y.nextSibling||g>=l.length-1&&y.parentElement.querySelector(".MJXc-display"))&&(o=0),g=Math.min(l.length-o,g),g<a)return null;c=l[g-1];let b;if(m?b=f.checkPoint:b=this.findAcceptableBreakInside(e.checkPoints,c,t),b){let w=this.getAfterEdgeOfBlockContainer(b);!isNaN(w)&&w<c&&(c=w),this.computedBlockSize=p*(c-this.beforeEdge)+d}return b}getAfterEdgeOfBlockContainer(e){let t=e;do t=t.parent;while(t&&t.inline);return t?(t=t.copy().modify(),t.after=!0,ai(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 Fi().find(e.formattingContext).finishBreak(this,e,t,i);return n||(n=Wr.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 s=this.breakPositions.length-1;s>=0&&!t;--s){e=this.breakPositions[s],t=e.findAcceptableBreak(this,i);let r=e.getMinBreakPenalty();r>i&&(n=Math.min(n,r))}}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 k(e);let s=F("doFinishBreak"),r=!1;if(!e){if(this.forceNonfitting)return D.warn("Could not find any page breaks?!!"),this.skipTailEdges(t).then(o=>{o?(o=o.modify(),o.overflow=!1,this.finishBreak(o,r,!0).then(()=>{s.finish(o)})):s.finish(o)}),s.result();e=i,r=!0,this.computedBlockSize=n}return this.finishBreak(e,r,!0).then(()=>{s.finish(e)}),s.result()}isBreakable(e){if(e.after)return!0;switch(e.sourceNode.namespaceURI){case"http://www.w3.org/2000/svg":return!1}return!e.flexContainer}zeroIndent(e){let t=e.toString();return t==""||t=="auto"||!!t.match(/^0+(.0*)?[^0-9]/)}checkOverflowAndSaveEdge(e,t){if(!e||hi(e.viewNode))return!1;let i=ai(e,this.clientLayout,0,this.vertical),n=mi(e,this.collectElementsOffset()),s=this.isOverflown(i+(this.vertical?-1:1)*n.minimum);if(this.isOverflown(i+(this.vertical?-1:1)*n.current)&&!this.nodeContextOverflowingDueToRepetitiveElements)this.nodeContextOverflowingDueToRepetitiveElements=e;else if(t){let r=i+this.getTrailingMarginEdgeAdjustment(t),o=this.footnoteEdge-this.getBoxDir()*n.current;i=this.vertical?Math.min(i,Math.max(r,o)):Math.max(i,Math.min(r,o))}return this.updateMaxReachedAfterEdge(i),s}checkOverflowAndSaveEdgeAndBreakPosition(e,t,i,n){if(!e||hi(e.viewNode))return!1;let s=this.checkOverflowAndSaveEdge(e,t);return(i||!s)&&this.saveEdgeBreakPosition(e,n,s),s}applyClearance(e){if(!e.viewNode.parentNode)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=this.clientLayout.getElementClientRect(i),s=this.getBeforeEdge(n),r=this.getBoxDir(),o=e.clearSide,a=-this.getBoxDir()*(1/0);switch(o==="all"&&(a=this.pageFloatLayoutContext.getPageFloatClearEdge(o,this)),o){case"left":a=r*Math.max(a*r,this.leftFloatEdge*r);break;case"right":a=r*Math.max(a*r,this.rightFloatEdge*r);break;default:a=r*Math.max(a*r,Math.max(this.rightFloatEdge*r,this.leftFloatEdge*r))}if(s*r>=a*r)return e.viewNode.parentNode.removeChild(i),!1;{let h=Math.max(1,(a-s)*r);this.vertical?i.style.width=`${h}px`:i.style.height=`${h}px`,n=this.clientLayout.getElementClientRect(i);let l=this.getAfterEdge(n);if(!e.floatSide)if(this.vertical){let c=l+t.right-a;c>0==t.right>=0&&(c+=t.right),i.style.marginLeft=`${c}px`}else{let c=a-(l+t.top);c>0==t.top>=0&&(c+=t.top),i.style.marginBottom=`${c}px`}return e.clearSpacer=i,!0}}isBFC(e){return!!(Jp(e)||Xt.isInstanceOfRepetitiveElementsOwnerFormattingContext(e))}skipEdges(e,t,i){var n;let s=e.after?(n=e.parent)==null?void 0:n.formattingContext:e.formattingContext;if(s&&!this.isBFC(s))return k(e);let r=F("skipEdges"),o=!i&&t&&e&&e.after,a=i,h=null,l=[],c=[],p=!1;function d(){return!!i||!t&&Ke(a)&&!f()}function f(){var m;if(!h||e.floatSide)return!1;for(let y=h;y!=null&&y.parent;y=y.parent){let b=y.after?y.viewNode:(m=y.viewNode)==null?void 0:m.previousSibling;for(;b&&(Ue(b,y.parent.whitespace)||vh(b));)b=b.previousSibling;if(b)return!1}return!0}let g=()=>{e=l[0]||e,e.viewNode.parentNode.removeChild(e.viewNode),this.pageBreakType=a};return r.loopWithFrame(m=>{for(var y;e;){e.formattingContext;let b=new Fi().find(e.formattingContext);do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ue(e.viewNode,e.whitespace))break;if(!e.after){d()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)?(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0):(e=e.modify(),e.breakBefore=a),m.breakLoop();return}}if(!e.after){if(e.floatSide&&(this.breakAtTheEdgeBeforeFloat=Un(a)?a:null),b&&b.startNonInlineElementNode(e))break;if(e.clearSide&&this.applyClearance(e)&&t&&this.breakPositions.length===0&&this.saveEdgeBreakPosition(e.copy(),a,!1),!e.inline&&!e.repeatOnBreak&&(h?Ko(h):this.breakPositions[this.breakPositions.length-1]instanceof Rs)&&this.saveEdgeBreakPosition(e.copy(),a,!1),!this.isBFC(e.formattingContext)||Xt.isInstanceOfRepetitiveElementsOwnerFormattingContext(e.formattingContext)||this.isFloatNodeContext(e)||e.flexContainer||!e.nodeShadow&&!e.sourceNode.firstElementChild&&Ue(e.sourceNode.firstChild,e.whitespace)){l.push(e.copy()),a=Xe(a,e.breakBefore),d()?g():(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)||!this.layoutConstraint.allowLayout(e))&&(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0),m.breakLoop();return}}if(e.viewNode.nodeType!=1)break;let S=e.viewNode.style;if(e.after){e.floatSide&&(a=a??this.breakAtTheEdgeBeforeFloat,this.breakAtTheEdgeBeforeFloat=null);let R=e.sourceNode;if(R.localName==="svg"||R.localName==="math"||R.getAttribute("data-math-typeset")==="true"){p=!1,h=e.copy(),c.push(h),a=Xe(null,e.breakAfter),this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,a);break}if(e.inline||b&&b.afterNonInlineElementNode(e,this.stopAtOverflow))break;if(p){if(d()){g(),m.breakLoop();return}l=[],t=!1,o=!1,a=null}p=!1,h=e.copy(),c.push(h),a=Xe(a,e.breakAfter),S&&!(this.zeroIndent(S.paddingBottom)&&this.zeroIndent(S.borderBottomWidth))&&(c=[h])}else{if(l.push(e.copy()),a=Xe(a,e.breakBefore),(e.pageType!=((y=e.parent)==null?void 0:y.pageType)||!Ke(a))&&!this.layoutConstraint.allowLayout(e)&&(this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!this.stopAtOverflow,a),e=e.modify(),e.overflow=!0,this.stopAtOverflow)){m.breakLoop();return}let R=e.viewNode.localName;if(Wt[R]){d()?g():this.checkOverflowAndSaveEdgeAndBreakPosition(h,null,!0,a)&&(e=(this.stopAtOverflow&&h||e).modify(),e.overflow=!0),m.breakLoop();return}S&&!(this.zeroIndent(S.paddingTop)&&this.zeroIndent(S.borderTopWidth))&&(o=!1,c=[]),p=!0}}while(!1);let w=this.nextInTree(e,o);if(w.isPending()){w.then(S=>{e=S,m.continueLoop()});return}else e=w.get()}this.checkOverflowAndSaveEdgeAndBreakPosition(h,c,!this.stopAtOverflow,a)?h&&this.stopAtOverflow&&(e=h.modify(),e.overflow=!0):Ke(a)&&(this.pageBreakType=a),m.breakLoop()}).then(()=>{h&&(this.lastAfterPosition=h.toNodePosition()),r.finish(e)}),r.result()}skipTailEdges(e){let t=e.copy(),i=F("skipEdges"),n=null,s=!1;return i.loopWithFrame(r=>{for(;e;){do{if(!e.viewNode)break;if(e.inline&&e.viewNode.nodeType!=1){if(Ue(e.viewNode,e.whitespace))break;if(!e.after){Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}}if(!e.after&&(this.isFloatNodeContext(e)||e.flexContainer)){n=Xe(n,e.breakBefore),Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}if(e.viewNode.nodeType!=1)break;let a=e.viewNode.style;if(e.after){if(s){if(Ke(n)){this.pageBreakType=n,r.breakLoop();return}n=null}s=!1,n=Xe(n,e.breakAfter)}else{n=Xe(n,e.breakBefore);let h=e.viewNode.localName;if(Wt[h]){Ke(n)&&(this.pageBreakType=n),r.breakLoop();return}if(a&&!(this.zeroIndent(a.paddingTop)&&this.zeroIndent(a.borderTopWidth))){r.breakLoop();return}}s=!0}while(!1);let o=this.layoutContext.nextInTree(e);if(o.isPending()){o.then(a=>{e=a,r.continueLoop()});return}else e=o.get()}t=null,r.breakLoop()}).then(()=>{i.finish(t)}),i.result()}layoutFloatOrFootnote(e){return gi(e.floatReference)||e.floatSide==="footnote"?this.layoutPageFloat(e):this.layoutFloat(e)}layoutNext(e,t,i){let n=F("layoutNext");return this.skipEdges(e,t,i||null).then(s=>{if(e=s,!e||this.pageBreakType||this.stopByOverflow(e))n.finish(e);else{let r=e.formattingContext;new Fi().find(r).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 Fi().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 nt(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=ud(this.box,[this.getInnerShape()],this.getExclusions(),8,this.snapHeight,this.vertical),this.createFloats()}init(){this.chunkPositions=[],N(this.element,"width",`${this.width}px`),N(this.element,"height",`${this.height}px`),this.initGeom(),this.computedBlockSize=0,this.overflown=!1,this.pageBreakType=null,this.lastAfterPosition=null}saveEdgeBreakPosition(e,t,i){e.formattingContext;let n=e.copy(),s=new Fi().find(e.formattingContext),r=this.calculateClonedPaddingBorder(n),o=s.createEdgeBreakPosition(n,t,i,this.computedBlockSize+r);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 Rs(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 k(e);if(this.isFullWithPageFloats())return e.primary.after&&e.primary.steps.length===1?k(null):k(e);let n=F("layout");return this.openAllViews(e.primary).then(s=>{let r=null;if(s.viewNode)r=s.copy();else{let a=h=>{h.nodeContext.viewNode&&(r=h.nodeContext,this.layoutContext.removeEventListener("nextInTree",a))};this.layoutContext.addEventListener("nextInTree",a)}let o=new wg(t,i);o.layout(s,this).then(a=>{this.doFinishBreak(a,o.context.overflownNodeContext,r,o.initialComputedBlockSize).then(h=>{let l=null;this.pseudoParent?l=k(null):l=this.doFinishBreakOfFragmentLayoutConstraints(h),l.then(()=>{if(this.pageFloatLayoutContext.isInvalidated()){n.finish(null);return}if(!h)n.finish(null);else{this.overflown=!0;let c=new zt(h.toNodePosition());n.finish(c)}})})})}),n.result()}isFullWithPageFloats(){return this.pageFloatLayoutContext.isColumnFullWithPageFloats(this)}getMaxBlockSizeOfPageFloats(){return this.pageFloatLayoutContext.getMaxBlockSizeOfPageFloats()}doFinishBreakOfFragmentLayoutConstraints(e){let t=F("doFinishBreakOfFragmentLayoutConstraints"),i=[].concat(this.fragmentLayoutConstraints);i.sort((s,r)=>s.getPriorityOfFinishBreak()-r.getPriorityOfFinishBreak());let n=0;return t.loop(()=>n<i.length?i[n++].finishBreak(e,this).thenReturn(!0):k(!1)).then(()=>{t.finish(!0)}),t.result()}doLayout(e,t,i){let n=F("doLayout"),s=null;return this.breakPositions=[],this.nodeContextOverflowingDueToRepetitiveElements=null,n.loopWithFrame(r=>{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())r.breakLoop();else if(this.pageBreakType)r.breakLoop();else if(e&&this.stopByOverflow(e)){s=e;let h=this.findAcceptableBreakPosition();e=h.nodeContext,h.breakPosition&&h.breakPosition.breakPositionChosen(this),r.breakLoop()}else o?o=!1:r.continueLoop()}),o){o=!1;return}}this.computedBlockSize+=this.getOffsetByRepetitiveElements(),r.breakLoop()}).then(()=>{n.finish({nodeContext:e,overflownNodeContext:s})}),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=F("redoLayout"),n=0,s=null,r=!0;return i.loopWithFrame(o=>{if(n<e.length){let a=e[n++];this.layout(a,r).then(h=>{r=!1,h?(s=h,o.breakLoop()):o.continueLoop()});return}o.breakLoop()}).then(()=>{i.finish(s)}),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(Xt.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}if(Hn.isInstanceOfAfterIfContinuesLayoutConstraint(i)){let n=i.getRepetitiveElements();e.push(n)}_t.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(this).forEach(n=>{e.push(n)})});return e}},Qr=class{constructor(e,t,i){u(this,"startNodeContexts",[]),u(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 qn.prototype.openAllViews.call(this,r).thenAsync(o=>(s.startNodeContexts.push(o.copy()),k(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 rs(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 Mt(e.toNodePosition(),this.column.lastAfterPosition)}getColumnElement(){return this.column.element}getColumn(){return this.column}},Yn=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+pa(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&&vo(s)&&vo(r)?pa(n):""),i}updateNodeContext(e,t,i){return e=e.modify(),e.offsetInNode+=t,e.breakBefore=null,e}};u(Yn,"instance");Yn.instance=new Yn;function pa(e){return e.hyphenateCharacter||e.parent&&e.parent.hyphenateCharacter||"-"}var wg=class extends jr{constructor(e,t){super(),this.leadingEdge=e,u(this,"breakAfter"),u(this,"initialPageBreakType",null),u(this,"initialComputedBlockSize",0),u(this,"initialOverflown",!1),u(this,"context",{overflownNodeContext:null}),this.breakAfter=t||null}resolveLayoutMode(e){return new bg(this.leadingEdge,this.breakAfter,this.context)}prepareLayout(e,t){t.fragmentLayoutConstraints=[],t.pseudoParent||ef()}clearNodes(e){super.clearNodes(e);let t=e;for(;t;){let i=t.viewNode;i&&yh(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}},bg=class{constructor(e,t,i){this.leadingEdge=e,this.breakAfter=t,this.context=i}doLayout(e,t){let i=F("DefaultLayoutMode.doLayout");return fg(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}},yg=class extends qn{constructor(e,t,i,n,s,r,o){super(t,i,n,s,r),this.floatSide=e,this.parentContainer=o,u(this,"rootViewNodes",[]),u(this,"floatMargins",[]),u(this,"adjustContentRelativeSize",!0)}openAllViews(e){return super.openAllViews(e).thenAsync(t=>(t&&this.fixFloatSizeAndPosition(t),k(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 h=li(e,a);if(h&&h.charAt(h.length-1)==="%"){let l=parseFloat(h),c=o*l/100;N(e,a,`${c}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=>{li(e,r)==="auto"&&N(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=li(t,"height");n!==""&&n!=="auto"&&N(t,"margin-top","auto")}}else if(i==="block-end"||i==="bottom"){let n=li(t,"width");n!==""&&n!=="auto"&&N(t,"margin-left","auto")}}}getContentInlineSize(){return Math.max.apply(null,this.rootViewNodes.map((e,t)=>{let i=this.clientLayout.getElementClientRect(e),n=this.floatMargins[t];return this.vertical?n.top+i.height+n.bottom:n.left+i.width+n.right}))}},Qt=class{constructor(e,t){this.parent=e,this.rootSourceNode=t,u(this,"formattingContextType","RepetitiveElementsOwner"),u(this,"isRoot",!1),u(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||tr.some(t=>t.root===this.rootSourceNode?(this.repetitiveElements=t.elements,!0):!1)||(this.repetitiveElements=new vg(e,this.rootSourceNode),tr.push({root:this.rootSourceNode,elements:this.repetitiveElements}))}saveState(){}restoreState(e){}},vg=class{constructor(e,t){this.vertical=e,this.ownerSourceNode=t,u(this,"headerSourceNode",null),u(this,"footerSourceNode",null),u(this,"headerViewNode",null),u(this,"footerViewNode",null),u(this,"headerNodePosition",null),u(this,"footerNodePosition",null),u(this,"headerHeight",0),u(this,"footerHeight",0),u(this,"isSkipHeader",!1),u(this,"isSkipFooter",!1),u(this,"enableSkippingFooter",!0),u(this,"enableSkippingHeader",!0),u(this,"doneInitialLayout",!1),u(this,"firstContentSourceNode",null),u(this,"lastContentSourceNode",null),u(this,"affectedNodeCache",[]),u(this,"afterLastContentNodeCache",[]),u(this,"allowInsert",!1),u(this,"allowInsertRepeatitiveElements")}setHeaderNodeContext(e){this.headerNodePosition||(this.headerNodePosition=$n(e,0),this.headerSourceNode=e.sourceNode,this.headerViewNode=e.viewNode)}setFooterNodeContext(e){this.footerNodePosition||(this.footerNodePosition=$n(e,0),this.footerSourceNode=e.sourceNode,this.footerViewNode=e.viewNode)}updateHeight(e){this.headerViewNode&&(this.headerHeight=Qs(this.headerViewNode,e,this.vertical),this.headerViewNode=null),this.footerViewNode&&(this.footerHeight=Qs(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?k(!0):this.appendElementToFragment(this.headerNodePosition,e,t,i)}appendFooterToFragment(e,t,i){return!this.footerNodePosition||this.isSkipFooter?k(!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 Qr(n,o,t),h=a.getColumn().pageBreakType;return a.getColumn().pageBreakType=null,this.allowInsertRepeatitiveElements=!0,a.layout(new zt(e),!0).thenAsync(()=>(this.allowInsertRepeatitiveElements=!1,r.removeChild(o),this.moveChildren(o,r,i),a.getColumn().pageBreakType=h,k(!0)))}moveChildren(e,t,i){if(t)for(;e.firstChild;){let n=e.firstChild;e.removeChild(n),n.setAttribute(xi,"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)||(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}},Kh=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}},Zh=class{constructor(e){this.formattingContext=e}accept(e,t){return!0}postLayout(e,t,i,n){return n}},xg=class extends Kh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}accept(e,t){return!1}},Sg=class extends Zh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return!e.belongsTo(this.formattingContext)&&!e.after&&t.fragmentLayoutConstraints.unshift(new eo(e)),this.processor.doLayout(e,t)}},eo=class Jh{constructor(t){u(this,"flagmentLayoutConstraintType","RepetitiveElementsOwner"),u(this,"nodeContext");let i=St(t.formattingContext);this.nodeContext=i.getRootNodeContext(t)}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||hi(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=St(this.nodeContext.formattingContext),s=this.getRepetitiveElements();if(!s)return k(!0);let r=this.nodeContext;return Pg(n,r,i).thenAsync(()=>Tg(n,r,i).thenAsync(()=>(s.prepareLayoutFragment(),k(!0))))}getRepetitiveElements(){return St(this.nodeContext.formattingContext).getRepetitiveElements()}equalsTo(t){return t instanceof Jh?St(this.nodeContext.formattingContext)===St(t.nodeContext.formattingContext):!1}getPriorityOfFinishBreak(){return 10}},Cg=class extends jr{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 xg(this.formattingContext,this.processor):(!e.belongsTo(this.formattingContext)&&!e.after&&t&&t.preventSkippingHeader(),new Sg(this.formattingContext,this.processor))}},Eg=class extends ji{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),k(!0);break;case"footer":if(n.isFooterRegistered())i.repeatOnBreak="none";else return n.setFooterNodeContext(i),k(!0);break}n.firstContentSourceNode||(n.firstContentSourceNode=i.sourceNode)}return ji.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"?k(!0):ji.prototype.afterNonInlineElementNode.call(this,e)}},kg=class extends ci{layout(e,t,i){if(t.isFloatNodeContext(e))return t.layoutFloatOrFootnote(e);let n=St(e.formattingContext);return n.getRootViewNode(e)?(i&&Qh(e.parent,t),e.belongsTo(n)?ci.prototype.layout.call(this,e,t,i):new Cg(n,this).layout(e,t)):t.buildDeepElementView(e)}startNonInlineElementNode(e){let t=Ig(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=St(e.formattingContext),n=F("BlockLayoutProcessor.doInitialLayout");return this.layoutEntireBlock(e,t).thenFinish(n),n.result()}layoutEntireBlock(e,t){let i=St(e.formattingContext),n=new Eg(i,t);return new er(n,t.layoutContext).iterate(e)}doLayout(e,t){let i=St(e.formattingContext),n=F("doLayout"),s=t.layoutContext.nextInTree(e,!1);return Yh(s,t).then(r=>{let o=r;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 ci.prototype.finishBreak.call(this,e,t,i,n)}clearOverflownViewNodes(e,t,i,n){ci.prototype.clearOverflownViewNodes(e,t,i,n)}};function Ng(e,t){for(let i=e;i;i=i.parent){let n=i.formattingContext;n&&n instanceof Qt&&!i.belongsTo(n)&&t(n,i)}}function Qh(e,t){e&&Ng(e.after?e.parent:e,(i,n)=>{_t.isInstanceOfTableFormattingContext(i)||t.fragmentLayoutConstraints.push(new eo(n))})}function Pg(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 k(!0)}function Tg(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 k(!0)}function Ig(e){let t=e.formattingContext;return!t||!(t instanceof Qt)?null:t}function St(e){return e instanceof Qt,e}var Rg=new kg;ht("RESOLVE_LAYOUT_PROCESSOR",e=>e instanceof Qt&&!_t.isInstanceOfTableFormattingContext(e)?Rg:null);var eu=class{constructor(e,t){this.rowIndex=e,this.sourceNode=t,u(this,"cells",[])}addCell(e){this.cells.push(e)}getMinimumHeight(){return Math.min.apply(null,this.cells.map(e=>e.height))}},Ag=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,u(this,"viewElement"),u(this,"colSpan"),u(this,"rowSpan"),u(this,"height",0),u(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}},Lg=class{constructor(e,t,i){this.rowIndex=e,this.columnIndex=t,this.cell=i}},Fg=class{constructor(e,t,i){this.column=e,this.cellNodeContext=i,u(this,"pseudoColumn"),u(this,"empty",!1),this.pseudoColumn=new Qr(e,t,i)}findAcceptableBreakPosition(){let e=this.cellNodeContext.viewNode,{verticalAlign:t,alignContent:i}=e.style;t!=="top"&&t!=="baseline"&&N(e,"vertical-align","top"),i&&i!=="normal"&&N(e,"align-content","normal");let n=this.pseudoColumn.findAcceptableBreakPosition(!0);return N(e,"vertical-align",t),i&&i!=="normal"&&N(e,"align-content",i),n}},Og=class{constructor(e,t){this.viewNode=e,this.side=t}},Bg=class extends rs{constructor(e,t,i,n){super(e,t,i,n),u(this,"formattingContext"),u(this,"acceptableCellBreakPositions",null),u(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();return this.getAcceptableCellBreakPositions().forEach(t=>{e+=t.breakPosition.getMinBreakPenalty()}),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)}},_g=class extends $r{constructor(e,t,i){super(),this.rowIndex=e,this.beforeNodeContext=t,this.formattingContext=i,u(this,"acceptableCellBreakPositions",null)}findAcceptableBreak(e,t){if(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,h=r.nodeContext;return!a.isStartNodeContext(h)&&!a.isLastAfterNodeContext(h)});return this.beforeNodeContext.overflow=n.some(r=>r.nodeContext&&r.nodeContext.overflow),s?this.beforeNodeContext:null}getMinBreakPenalty(){let e=this.formattingContext,t=e.getRowByIndex(this.rowIndex),i=0;return e.isFreelyFragmentableRow(t)||(i+=10),this.getAcceptableCellBreakPositions().forEach(n=>{i+=n.breakPosition.getMinBreakPenalty()}),i}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)}},bi=class extends Qt{constructor(e,t){super(e,t),this.tableSourceNode=t,u(this,"formattingContextType","Table"),u(this,"vertical",!1),u(this,"columnCount",-1),u(this,"tableWidth",0),u(this,"captions",[]),u(this,"colGroups",null),u(this,"colWidths",null),u(this,"inlineBorderSpacing",0),u(this,"rows",[]),u(this,"slots",[]),u(this,"cellFragments",[]),u(this,"lastRowViewNode",null),u(this,"cellBreakPositions",[]),u(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 eu(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 Lg(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]}isFreelyFragmentableRow(e){return e.getMinimumHeight()>this.tableWidth/2}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=e.getElementClientRect(i.viewElement);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 Mg(e.map(t=>t.elements))]}collectElementsOffsetFromColumn(e,t){e.fragmentLayoutConstraints.forEach(i=>{if(Xt.isInstanceOfRepetitiveElementsOwnerLayoutConstraint(i)){let n=i.getRepetitiveElements();t.push(n)}_t.isInstanceOfTableRowLayoutConstraint(i)&&i.getElementsOffsetsForTableCell(null).forEach(n=>{t.push(n)})})}saveState(){return[].concat(this.cellBreakPositions)}restoreState(e){this.cellBreakPositions=e}},Mg=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=mi(e,n);i=Math.max(i,t(s))}),i}};function at(e){return e instanceof bi,e}function zg(e){return e==="table-row-group"||e==="table-header-group"||e==="table-footer-group"}function Dg(e){return e==="table"||e==="inline-table"}function fa(e){return zg(e)||Dg(e)}function tu(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 bi)){for(let a=n.parent;a;a=a.parent)if(a.formattingContext instanceof bi){o=a.formattingContext===t;break}}return o||s==="table-row"&&!fa(r)||s==="table-cell"&&r!=="table-row"&&!fa(r)||n.formattingContext instanceof bi&&n.formattingContext!==t?i.buildDeepElementView(n).thenAsync(a=>(e.nodeContext=a,k(!0))):null}var Vg=class extends ji{constructor(e,t){super(),this.formattingContext=e,this.column=t,u(this,"rowIndex",-1),u(this,"columnIndex",0),u(this,"inRow",!1),u(this,"checkPoints",[]),u(this,"inHeaderOrFooter",!1)}startNonInlineElementNode(e){let t=this.formattingContext,i=tu(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 Og(n.viewNode,n.captionSide);t.captions.push(o);break}case"table-header-group":return r.isHeaderRegistered()||(this.inHeaderOrFooter=!0,r.setHeaderNodeContext(n)),k(!0);case"table-footer-group":return r.isFooterRegistered()||(this.inHeaderOrFooter=!0,r.setFooterNodeContext(n)),k(!0);case"table-row":this.inHeaderOrFooter||(this.inRow=!0,this.rowIndex++,n.sourceNode,this.columnIndex=0,t.addRow(this.rowIndex,new eu(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,k(!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 Ag(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&&!ui(t)&&this.checkPoints.push(t.clone())}postLayoutBlockContents(e){this.checkPoints.length>0&&this.column.postLayoutBlock(e.nodeContext,this.checkPoints),this.checkPoints=[]}},iu=class nu extends ji{constructor(t,i){super(!0),this.formattingContext=t,this.column=i,u(this,"inRow",!1),u(this,"currentRowIndex",-1),u(this,"currentColumnIndex",0),u(this,"originalStopAtOverflow"),u(this,"inHeader"),u(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,h=i.verticalAlign;o>1&&(N(a,"box-sizing","border-box"),N(a,this.formattingContext.vertical?"height":"width",`${this.getColSpanningCellWidth(t)}px`));let l=a.ownerDocument.createElement("div");a.appendChild(l);let c=new Fg(this.column,l,i);return this.formattingContext.addCellFragment(s,r,c),n.primary.steps.length===1&&n.primary.after&&(c.empty=!0),c.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(p=>p+1,0);if(s===0)return k(!0);let r=this.column.layoutContext,o=t.nodeContext;o.viewNode.parentNode.removeChild(o.viewNode);let a=F("layoutRowSpanningCellsFromPreviousFragment"),h=k(!0),l=0,c=[];return n.forEach(p=>{h=h.thenAsync(()=>{let d=Gn(p[0].cellNodePosition.steps[1],o.parent);return r.setCurrent(d,!1).thenAsync(()=>{let f=k(!0),g=0;function m(y){for(;g<y;){if(!c.includes(g)){let b=d.viewNode.ownerDocument.createElement("td");N(b,"padding","0"),d.viewNode.appendChild(b)}g++}}return p.forEach(y=>{f=f.thenAsync(()=>{let b=y.cell;m(b.anchorSlot.columnIndex);let w=y.cellNodePosition,S=Gn(w.steps[0],d);return S.offsetInNode=w.offsetInNode,S.after=w.after,S.fragmentIndex=w.steps[0].fragmentIndex+1,r.setCurrent(S,!1).thenAsync(()=>{let R=y.breakChunkPosition;for(let L=0;L<b.colSpan;L++)c.push(g+L);return g+=b.colSpan,this.layoutCell(b,S,R).thenAsync(()=>(S.viewNode.rowSpan=b.rowIndex+b.rowSpan-this.currentRowIndex+s-l,k(!0)))})})}),f.thenAsync(()=>(m(i.getColumnCount()),l++,k(!0)))})})}),h.then(()=>{r.setCurrent(o,!0,t.atUnforcedBreak).then(()=>{a.finish(!0)})}),a.result()}startTableRow(t){if(this.inHeader||this.inFooter)return k(!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),k(!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);ug(s,n.fragmentIndex+1,1)}})}startTableCell(t){if(this.inHeader||this.inFooter)return k(!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,k(!0);let s=i.copy().modify();s.after=!0,t.nodeContext=s;let r=F("startTableCell"),o;if(this.hasBrokenCellAtSlot(n.anchorSlot.columnIndex)){let a=this.formattingContext.cellBreakPositions.shift();i.fragmentIndex=a.cellNodePosition.steps[0].fragmentIndex+1,o=k(a.breakChunkPosition)}else o=this.column.nextInTree(i,t.atUnforcedBreak).thenAsync(a=>{a.viewNode&&i.viewNode.removeChild(a.viewNode);let h=$n(a,0);return k(new zt(h))});return o.then(a=>{this.layoutCell(n,i,a).then(()=>{this.afterNonInlineElementNode(t),this.currentColumnIndex++,r.finish(!0)})}),r.result()}startNonInlineBox(t){let i=tu(t,at(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,k(!0)):r==="table-footer-group"&&s&&s.isFooterSourceNode(n.sourceNode)?(this.inFooter=!0,k(!0)):r==="table-row"?this.startTableRow(t):r==="table-cell"?this.startTableCell(t):k(!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 _g(this.currentRowIndex,n,this.formattingContext);this.column.breakPositions.push(s)}return k(!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)):N(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)):N(i.viewNode,"display","table-row-group")),s&&nu.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 k(!0)}};u(iu,"ignoreList",{"table-caption":!0,"table-column-group":!0,"table-column":!0});var Ug=iu,rn=[];function Hg(e){let t=rn.findIndex(n=>n.root===e),i=rn[t];return i?i.tableLayoutOption:null}function $g(e){let t=rn.findIndex(i=>i.root===e);t>=0&&rn.splice(t,1)}var su=class{layoutEntireTable(e,t){let i=at(e.formattingContext),n=new Vg(i,t);return new er(n,t.layoutContext).iterate(e)}getColumnWidths(e,t,i,n){let s=e.ownerDocument,r=s.createElement("tr"),o=[];for(let h=0;h<t;h++){let l=s.createElement("td");r.appendChild(l),o.push(l)}e.parentNode.insertBefore(r,e.nextSibling);let a=o.map(h=>{let l=n.getElementClientRect(h),c=i?l.height:l.width;return Math.ceil(c)});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),h=this.getColGroupElements(t),l=this.normalizeAndGetColElements(h);this.addMissingColElements(l,h,o,t),l.forEach((c,p)=>{N(c,n?"height":"width",`${a[p]}px`)}),h.forEach(c=>{r.appendChild(c.cloneNode(!0))}),e.colGroups=r}doInitialLayout(e,t){let i=at(e.formattingContext);i.vertical=e.vertical,i.initializeRepetitiveElements(e.vertical),e.sourceNode;let n=Hg(e.sourceNode);$g(e.sourceNode);let s=F("TableLayoutProcessor.doInitialLayout"),r=e.copy();return this.layoutEntireTable(e,t).then(o=>{let a=o.viewNode,h=t.clientLayout.getElementClientRect(a),l=t.vertical?h.left:h.bottom;if(l+=(t.vertical?-1:1)*mi(e,t.collectElementsOffset()).current,!t.isOverflown(l)&&(!n||!n.calculateBreakPositionsInside)){t.breakPositions.push(new Xg(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)}removeColGroups(e,t){if(e.colGroups&&t){let i=this.getColGroupElements(t);i&&i.forEach(n=>{t.removeChild(n)})}}doLayout(e,t){let i=at(e.formattingContext),n=i.getRootViewNode(e),s=n.firstChild;this.addCaptions(i,n,s),this.addColGroups(i,n,s);let r=new Ug(i,t),o=new er(r,t.layoutContext),a=F("TableFormattingContext.doLayout");return o.iterate(e).thenFinish(a),a.result()}layout(e,t,i){let n=at(e.formattingContext);return n.getRootViewNode(e)?(i&&Qh(e.parent,t),new Wg(n,this).layout(e,t)):t.buildDeepElementView(e)}createEdgeBreakPosition(e,t,i,n){return new Bg(e,t,i,n)}startNonInlineElementNode(e){return!1}afterNonInlineElementNode(e,t){return!1}finishBreak(e,t,i,n){let s=at(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=F("TableLayoutProcessor.finishBreak"),h=0;return a.loopWithFrame(l=>{if(h===o.length){l.breakLoop();return}let c=o[h++],p=s.getCellFragmentOfCell(c),d=p.findAcceptableBreakPosition().nodeContext,f=p.cellNodeContext,g=f.toNodePosition(),m=new zt(d.toNodePosition());s.cellBreakPositions.push({cellNodePosition:g,breakChunkPosition:m,cell:c});let y=f.viewNode;p.column.layoutContext.processFragmentedBlockEdge(p.cellNodeContext),r<c.rowIndex+c.rowSpan-1&&(y.rowSpan=r-c.rowIndex+1),p.empty?l.continueLoop():p.pseudoColumn.finishBreak(d,!1,!0).then(()=>{Gg(p,s,d),l.continueLoop()})}).then(()=>{e.clearOverflownViewNodes(t,!1),e.layoutContext.processFragmentedBlockEdge(t),s.finishFragment(),a.finish(!0)}),a.result()}}return s.finishFragment(),Wr.finishBreak(e,t,i,n)}clearOverflownViewNodes(e,t,i,n){ci.prototype.clearOverflownViewNodes(e,t,i,n)}};function Gg(e,t,i){let n=t.getRepetitiveElements();if(!n)return;let s=t.vertical,r=e.column,o=e.pseudoColumn.getColumnElement(),a=e.cellNodeContext.viewNode,h=r.clientLayout.getElementClientRect(a),l=r.getComputedPaddingBorder(a);if(s){let c=h.right-r.footnoteEdge-n.calculateOffset(i)-l.right;N(o,"max-width",`${c}px`)}else{let c=r.footnoteEdge-n.calculateOffset(i)-h.top-l.top;N(o,"max-height",`${c}px`)}N(o,"overflow","hidden")}var Wg=class extends jr{constructor(e,t){super(),this.tableFormattingContext=e,this.processor=t}resolveLayoutMode(e){let t=this.tableFormattingContext.getRepetitiveElements();return!t||!t.doneInitialLayout?new jg(this.tableFormattingContext,this.processor):(e.sourceNode===this.tableFormattingContext.tableSourceNode&&!e.after&&t&&t.preventSkippingHeader(),new Yg(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()}},jg=class extends Kh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){return this.processor.doInitialLayout(e,t)}},Xg=class extends rs{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 qg(this.position.sourceNode))}},qg=class ru{constructor(t){this.tableRootNode=t,u(this,"flagmentLayoutConstraintType","EntireTable")}allowLayout(t,i,n){return t.overflow,!1}nextCandidate(t){return!0}postLayout(t,i,n,s){i.sourceNode,rn.push({root:i.sourceNode,tableLayoutOption:{calculateBreakPositionsInside:!0}})}finishBreak(t,i){return k(!0)}equalsTo(t){return t instanceof ru&&t.tableRootNode===this.tableRootNode}getPriorityOfFinishBreak(){return 0}},Yg=class extends Zh{constructor(e,t){super(e),this.processor=t}doLayout(e,t){let i=this.formattingContext.getRepetitiveElements();if(i&&!i.isAfterLastContent(e)){let n=new Kg(e);t.fragmentLayoutConstraints.some(s=>n.equalsTo(s))||t.fragmentLayoutConstraints.unshift(n)}return this.processor.doLayout(e,t)}},Kg=class ou extends eo{constructor(t){super(t),u(this,"flagmentLayoutConstraintType","TableRow"),u(this,"cellFragmentLayoutConstraints",[])}allowLayout(t,i,n){let s=this.getRepetitiveElements();return!s||n.pseudoParent||hi(this.nodeContext.viewNode)||!s.isEnableToUpdateState()?!0:!(i&&!t||t&&t.overflow)}nextCandidate(t){let i=at(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=at(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 su().removeColGroups(r,o),this.removeDummyRowNodes(n)}super.postLayout(t,i,n,s)}finishBreak(t,i){let n=at(this.nodeContext.formattingContext),s=F("finishBreak"),r=this.cellFragmentLayoutConstraints.reduce((a,h)=>a.concat(h.constraints.map(l=>({constraint:l,breakPosition:h.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 k(!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=at(this.nodeContext.formattingContext),n=i.findCellFromColumn(t);return n?i.collectElementsOffsetOfUpperCells(n):i.collectElementsOffsetOfHighestColumn()}equalsTo(t){return t instanceof ou?at(this.nodeContext.formattingContext)===at(t.nodeContext.formattingContext):!1}},Zg=new su;function Jg(e,t,i,n,s,r){if(!t)return null;if(i===v.table){let o=e.parent;return new bi(o?o.formattingContext:null,e.sourceNode)}return null}function Qg(e){return e instanceof bi?Zg:null}ht("RESOLVE_FORMATTING_CONTEXT",Jg);ht("RESOLVE_LAYOUT_PROCESSOR",Qg);function ga(e){return e.reduce((t,i)=>t+i,0)/e.length}function em(e){let t=ga(e);return ga(e.map(i=>{let n=i-t;return n*n}))}var tm=class{constructor(e,t){this.layoutResult=e,this.penalty=t}};function on(e){return e.vertical?e.width:e.height}function an(e,t){e.vertical?e.width=t:e.height=t}var au=class{constructor(e,t,i){this.layoutContainer=e,this.columnGenerator=t,this.regionPageFloatLayoutContext=i,u(this,"originalContainerBlockSize"),this.originalContainerBlockSize=on(e)}balanceColumns(e){let t=F("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 tm(e,t)}preBalance(e){}postBalance(){an(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)}},gr=1;function lu(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+gr}function hu(e,t){let i=e[e.length-1].layoutResult.columns,n=Math.max.apply(null,i.map(s=>isNaN(s.blockDistanceToBlockEndFloats)?s.computedBlockSize:s.computedBlockSize-s.blockDistanceToBlockEndFloats+gr))-gr;n<on(t)?an(t,n):an(t,on(t)-1)}var im=class extends au{constructor(e,t,i,n){super(i,e,t),this.columnCount=n,u(this,"originalPosition",null),u(this,"foundUpperBound",!1)}preBalance(e){let t=e.columns.reduce((i,n)=>i+n.computedBlockSize,0);an(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 ma(t)?1/0:Math.max.apply(null,t.map(i=>i.computedBlockSize))}hasNextCandidate(e){if(e.length===1)return!0;if(this.foundUpperBound)return lu(e);{let t=e[e.length-1];return this.checkPosition(t.layoutResult.position)&&!ma(t.layoutResult.columns)?(this.foundUpperBound=!0,!0):on(this.layoutContainer)<this.originalContainerBlockSize}}updateCondition(e){if(this.foundUpperBound)hu(e,this.layoutContainer);else{let t=Math.min(this.originalContainerBlockSize,on(this.layoutContainer)+this.originalContainerBlockSize*.1);an(this.layoutContainer,t)}}};function ma(e){if(e.length<=1)return!1;let t=e[e.length-1].computedBlockSize;return e.slice(0,e.length-1).every(i=>t>i.computedBlockSize)}var nm=class extends au{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 em(t)}hasNextCandidate(e){return lu(e)}updateCondition(e){hu(e,this.layoutContainer)}};function sm(e,t,i,n,s,r,o){if(t===v.auto)return null;{let a=o.positions.length===0,h=r[r.length-1],l=!!(h&&h.pageBreakType);return a||l?new im(i,n,s,e):t===v.balance_all?new nm(i,n,s):(v.balance,null)}}var As=class{constructor(e,t,i){u(this,"endStuckFixed"),u(this,"endFixed"),u(this,"endSlipped"),this.endStuckFixed=e,this.endFixed=t,this.endSlipped=i}},rm=class{constructor(){u(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 As(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 As(e,e,i))}}addSlippedRange(e){this.map.length==0?this.map.push(new As(e,0,0)):this.map[this.map.length-1].endFixed=e}slippedByFixed(e){let t=Bt(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=Bt(this.map.length,n=>e<=this.map[n].endSlipped),i=this.map[t];return i.endStuckFixed-(i.endSlipped-e)}},om=class mr{constructor(t,i,n,s,r,o,a,h){if(this.context=t,this.style=i,this.offset=n,this.isRoot=s,this.flowChunk=r,this.atBlockStart=o,this.atFlowStart=a,this.isParentBoxDisplayed=h,u(this,"flowName"),u(this,"isBlockValue",null),u(this,"hasBoxValue",null),u(this,"styleValues",{}),u(this,"beforeBox",null),u(this,"afterBox",null),u(this,"breakBefore",null),this.flowName=r.flowName,this.hasBox()){let l=i._pseudos;if(l&&l.before){let c=new mr(t,l.before,n,!1,r,this.isBlock(),a,!0),p=c.styleValue("content");Dt(p)&&(this.beforeBox=c,this.breakBefore=c.breakBefore)}}this.breakBefore=Xe(this.getBreakValue("before"),this.breakBefore),this.atFlowStart&&Ke(this.breakBefore)&&(r.breakBefore=Xe(r.breakBefore,this.breakBefore))}buildAfterPseudoElementBox(t,i,n){if(this.hasBox()){let s=this.style._pseudos;if(s&&s.after){let r=new mr(this.context,s.after,t,!1,this.flowChunk,i,n,!0),o=r.styleValue("content");Dt(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",v.inline)}isBlock(){if(this.isBlockValue===null){let t=this.displayValue(),i=this.styleValue("position"),n=this.styleValue("float");this.isBlockValue=wh(t,i,n,this.isRoot)}return this.isBlockValue}hasBox(){return this.hasBoxValue===null&&(this.hasBoxValue=this.isParentBoxDisplayed&&this.displayValue()!==v.none),this.hasBoxValue}getBreakValue(t){let i=null;if(this.isBlock()){let n=this.styleValue(`break-${t}`);n&&(i=n.toString())}return i}},am=class{constructor(e){this.context=e,u(this,"stack",[]),u(this,"atBlockStart",!0),u(this,"atFlowStart",!0),u(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 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(),h=new om(this.context,e,t,i,r,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=rh(i);n&&!Ue(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=Xe(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!")}},wa=class{constructor(e,t,i,n,s,r,o,a){this.xmldoc=e,this.scope=i,this.context=n,this.primaryFlows=s,this.validatorSet=r,this.counterListener=o,u(this,"root"),u(this,"cascadeHolder"),u(this,"last"),u(this,"rootStyle",{}),u(this,"styleMap",{}),u(this,"flows",{}),u(this,"flowChunks",[]),u(this,"flowListener",null),u(this,"flowToReach",null),u(this,"idToReach",null),u(this,"cascade"),u(this,"offsetMap"),u(this,"primary",!0),u(this,"primaryStack",[]),u(this,"rootBackgroundAssigned",!1),u(this,"rootLayoutAssigned",!1),u(this,"lastOffset"),u(this,"breakBeforeValues",{}),u(this,"boxStack"),u(this,"bodyReached",!0),this.root=e.root,this.cascadeHolder=t,this.last=this.root,this.cascade=t.createInstance(n,o,a,e.lang),this.offsetMap=new rm;let h=e.getElementOffset(this.root);this.lastOffset=h,this.boxStack=new am(n),this.offsetMap.addStuckRange(h);let l=this.getAttrStyle(this.root);switch(this.cascade.pushElement(this,this.root,l,h),this.postprocessTopStyle(l,!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}`]=l,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 K(s,Wl))}}}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)Xi(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&&!J(n)||s&&!J(s))&&(this.transferPropsToRoot(e,this.validatorSet.backgroundProps),this.rootBackgroundAssigned=!0)}if(!this.rootLayoutAssigned){for(let n=0;n<ba.length;n++)if(this.hasProp(e,this.validatorSet.layoutProps,ba[n])){this.transferPropsToRoot(e,this.validatorSet.layoutProps),this.rootLayoutAssigned=!0;break}}if(!t){let n=e["font-size"],s=!0;if(n&&!J(n.value)){let a=n.evaluate(this.context);if(a instanceof T){let h=a.num;switch(a.unit){case"em":case"rem":h*=this.context.initialFontSize;break;case"ex":h*=this.context.initialFontSize*me.ex/me.em;break;case"%":h*=this.context.initialFontSize/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*me.lh/me.em;break;default:{let l=me[a.unit];l&&(h*=l),s=!1}}this.context.rootFontSize=h,this.context.isRelativeRootFontSize=s}}let r=(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 ei)this.context.rootLineHeight=a.num*r;else if(a instanceof T){let h=a.num;switch(a.unit){case"em":case"rem":h*=r;break;case"ex":h*=r*me.ex/me.em;break;case"%":h*=r/100;break;case"lh":case"rlh":h*=this.context.initialFontSize*me.lh/me.em;break;default:{let l=me[a.unit];l&&(h*=l)}}this.context.rootLineHeight=h}}else this.context.rootLineHeight=this.context.fontSize()*me.lh/me.em}}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 ig(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=Ve(r,"flow-into"),a=o?o.evaluate(t,"flow-into").toString():"body",h=this.encounteredFlowElement(a,r,this.root,i);this.boxStack.empty()&&this.boxStack.push(r,i,!0,h)}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),h=a["flow-into"];if(h){let l=h.evaluate(t,"flow-into").toString();this.encounteredFlowElement(l,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,h=!1,l=t["flow-options"];if(l){let m=md(l.evaluate(this.context,"flow-options"));o=!!m.exclusive,a=!!m.static,h=!!m.last}let c=t["flow-linger"];c&&(r=Do(c.evaluate(this.context,"flow-linger"),Number.POSITIVE_INFINITY));let p=t["flow-priority"];p&&(s=Do(p.evaluate(this.context,"flow-priority"),0));let d=this.breakBeforeValues[n]||null,f=this.flows[e];if(!f){let m=this.boxStack.lastFlowName();f=this.flows[e]=new Ap(e,m)}let g=new Lp(e,i,n,s,r,o,a,h,d);return this.flowChunks.push(g),this.flowToReach==e&&(this.flowToReach=null),this.flowListener&&this.flowListener.encounteredFlowChunk(g,f),g}registerForcedBreakOffset(e,t,i){if(Ke(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]=Xe(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 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=Xe(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 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,c=a["flow-into"];if(c){let d=c.evaluate(s,"flow-into").toString(),f=this.encounteredFlowElement(d,a,o,this.lastOffset);this.primary=!!this.primaryFlows[d],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=Xe(l.flowChunk.breakBefore,l.breakBefore));let p=this.boxStack.nearestBlockStartOffset(l);if(p===0){let d=a.page,f=d&&!J(d.value)&&d.value.toString();f&&f.toLowerCase()!=="auto"&&(this.cascade.firstPageType=f)}if(this.registerForcedBreakOffset(l.breakBefore,p,l.flowName),l.beforeBox){let d=l.beforeBox.getBreakValue("after");this.registerForcedBreakOffset(d,l.beforeBox.atBlockStart?p: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&&p===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){}},ba=["column-count","column-width","column-fill"],pi=class{constructor(e){this.validator=e,u(this,"success",null),u(this,"failure",null),u(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)}},$t=class{constructor(e,t){this.where=e,this.success=t,u(this,"what",-1)}},Bi=class uu{constructor(){u(this,"nodes",[]),u(this,"connections",[]),u(this,"match",[]),u(this,"nomatch",[]),u(this,"error",[]),u(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 uu;for(let i=0;i<this.nodes.length;i++){let n=this.nodes[i],s=new pi(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 $t(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 pi(ya);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 $t(s,!0),a=new $t(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 pi(ya);i.markAsStartAlternate(t),this.nodes.push(i);let n=new $t(0,!0),s=new $t(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 pi(t));let n=new $t(i,!0),s=new $t(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 Pe}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]}},lm=1,cu=2,du=4,Gt=8,Fn=16,wr=32,On=64,pu=128,Vi=256,Ui=512,br=1024,fu=2048,gu=4096,mu=8192,wu=class extends It{constructor(){super()}validateForShorthand(e,t){let i=e[t].visit(this);return i?[i]:null}},Pe=class bu extends wu{constructor(t,i,n){super(),this.allowed=t,this.idents=i,this.units=n}visitEmpty(t){return this.allowed&lm?t:null}visitSlash(t){return this.allowed&fu?t:null}visitStr(t){return this.allowed&cu?t:null}visitIdent(t){return this.idents[t.name.toLowerCase()]||(this.allowed&du||this.allowed&On&&CSS.supports("color",t.name)?t:null)}visitNumeric(t){return t.num==0&&!(this.allowed&Ui)?t.unit=="%"&&this.allowed&br?t:null:t.num<0&&!(this.allowed&Vi)?null:this.units[t.unit]?t:null}visitNum(t){return t.num==0?this.allowed&Ui?t:null:t.num<=0&&!(this.allowed&Vi)?null:this.allowed&Fn?t:null}visitInt(t){return t.num==0?this.allowed&Ui?t:null:t.num<=0&&!(this.allowed&Vi)?null:this.allowed&(wr|Fn)?t:this.idents[`${t.num}`]||null}visitHexColor(t){return this.allowed&On&&/^([0-9A-F]{3,4}|([0-9A-F]{2}){3,4})$/i.test(t.hex)?t:null}visitURL(t){return this.allowed&pu?t:null}visitURange(t){return this.allowed&gu?t:null}visitSpaceList(t){return null}visitCommaList(t){return null}visitFunc(t){return this.allowed&On&&CSS.supports("color",t.toString())||this.allowed&mu&&CSS.supports("background-image",t.toString())||t.name==="calc"&&this.allowed&(Gt|Fn|wr|Vi|Ui|br)?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 bu(this.allowed|t.allowed,i,n)}},ne={},ya=new Pe(0,ne,ne),to=class extends wu{constructor(e){super(),u(this,"successTerminal"),u(this,"failureTerminal"),u(this,"first"),this.successTerminal=new pi(null),this.failureTerminal=new pi(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 h=e[r],l=h;if(s.isSpecial()){let c=!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":c=a[s.getAlternate()]==null,s=c?s.success:s.failure}else{if(r==0&&!t&&s.validator instanceof Ki&&this instanceof Ki){if(l=new ke(e).visit(s.validator),l){r=e.length,s=s.success;continue}}else if(r==0&&!t&&s.validator instanceof io&&this instanceof Ki){if(l=new qe(e).visit(s.validator),l){r=e.length,s=s.success;continue}}else l=h.visit(s.validator);if(!l){s=s.failure;continue}if(l!==h&&e===n){n=[];for(let c=0;c<r;c++)n[c]=e[c]}e!==n&&(n[r-i]=l),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}},Ki=class extends to{constructor(e){super(e)}visitSpaceList(e){let t=this.validateList(e.values,!1,0);return t===e.values?e:t?new ke(t):null}visitCommaList(e){let t=this.first,i=!1;for(;t;){if(t.validator instanceof io){i=!0;break}t=t.failure}if(i){let n=this.validateList(e.values,!1,0);return n===e.values?e:n?new qe(n):null}return null}validateForShorthand(e,t){return this.validateList(e,!0,t)}},io=class extends to{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 qe(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}},hm=class extends to{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 ki(e.name,t):null}},yu=class{tryParse(e,t,i){return t}success(e,t){}},vu=class extends yu{constructor(e,t){super(),this.name=t,u(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 ke(n):n[0];return this.success(r,i),t+s}return t}success(e,t){t.values[this.name]=e}},um=class extends vu{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}},cm=class extends yu{constructor(e,t){super(),this.nodes=e,this.slash=t}tryParse(e,t,i){let n=t;if(this.slash)if(e[t]==es){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}},no=class extends It{constructor(){super(...arguments),u(this,"syntax",null),u(this,"propList",null),u(this,"error",!1),u(this,"values",{}),u(this,"validatorSet",null)}setOwner(e){this.validatorSet=e}syntaxNodeForProperty(e){return new vu(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: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)}},Ri=class extends no{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}},xu=class extends no{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 um(this.validatorSet,this.propList)}},dm=class extends no{constructor(){super()}validateList(e){let t=e.length;for(let i=0;i<e.length;i++)if(e[i]===es){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}},pm=class extends Ri{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:v.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 qe?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 qe(t[i]);return null}},fm=class extends Ri{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]===es){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 ke(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 qe(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}},gm=class extends Ri{validateList(e){if(e.length===1&&e[0]instanceof ft)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)}},mm=["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","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"],wm=class extends Ri{constructor(){super()}init(e,t){super.init(e,t);for(let i in this.validatorSet.validators)mm.includes(i)||this.propList.push(i)}validateList(e){return this.error=!0,0}},va={SIMPLE:Ri,INSETS:xu,INSETS_SLASH:dm,COMMA:pm,FONT:fm,TEXT_SPACING:gm,ALL:wm},bm=class{constructor(){u(this,"validators",{}),u(this,"prefixes",{}),u(this,"defaultValues",{}),u(this,"namedValidators",{}),u(this,"systemFonts",{}),u(this,"shorthands",{}),u(this,"layoutProps",{}),u(this,"backgroundProps",{})}addReplacement(e,t){let i;if(t.type==3)i=new T(t.num,t.text);else if(t.type==7)i=new El(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 s in n)n[s]=i;return e}throw new Error("unexpected replacement")}newGroup(e,t){let i=new Bi;if(e=="||"){for(let s=0;s<t.length;s++){let r=new Bi;r.startClause(s),r.addGroup(t[s],1),r.endClause(s),i.addGroup(r,s==0?1:4)}let n=new Bi;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 Bi;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 Bi;return t.addPrimitive(e),t}newFunc(e,t){let i;switch(e){case"COMMA":i=new io(t);break;case"SPACE":i=new Ki(t);break;default:i=new hm(e.toLowerCase(),t);break}return this.primitive(i)}initBuiltInValidators(){this.namedValidators.COLOR=this.primitive(new Pe(On,ne,ne)),this.namedValidators.IMAGE_FUNCTION=this.primitive(new Pe(mu,ne,ne)),this.namedValidators.POS_INT=this.primitive(new Pe(wr,ne,ne)),this.namedValidators.POS_NUM=this.primitive(new Pe(Fn,ne,ne)),this.namedValidators.POS_PERCENTAGE=this.primitive(new Pe(Gt,ne,{"%":G})),this.namedValidators.NEGATIVE=this.primitive(new Pe(Vi,ne,ne)),this.namedValidators.ZERO=this.primitive(new Pe(Ui,ne,ne)),this.namedValidators.ZERO_PERCENTAGE=this.primitive(new Pe(br,ne,ne)),this.namedValidators.POS_LENGTH=this.primitive(new Pe(Gt,ne,{em:G,ex:G,ch:G,rem:G,lh:G,rlh:G,vw:G,vh:G,vi:G,vb:G,vmin:G,vmax:G,pvw:G,pvh:G,pvi:G,pvb:G,pvmin:G,pvmax:G,cm:G,mm:G,in:G,px:G,pt:G,pc:G,q:G})),this.namedValidators.POS_ANGLE=this.primitive(new Pe(Gt,ne,{deg:G,grad:G,rad:G,turn:G})),this.namedValidators.POS_TIME=this.primitive(new Pe(Gt,ne,{s:G,ms:G})),this.namedValidators.FREQUENCY=this.primitive(new Pe(Gt,ne,{Hz:G,kHz:G})),this.namedValidators.RESOLUTION=this.primitive(new Pe(Gt,ne,{dpi:G,dpcm:G,dppx:G})),this.namedValidators.URI=this.primitive(new Pe(pu,ne,ne)),this.namedValidators.URANGE=this.primitive(new Pe(gu,ne,ne)),this.namedValidators.IDENT=this.primitive(new Pe(du,ne,ne)),this.namedValidators.STRING=this.primitive(new Pe(cu,ne,ne)),this.namedValidators.SLASH=this.primitive(new Pe(fu,ne,ne));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 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)},h=c=>{if(o)throw new Error(`'${c}': unexpected`);if(s&&s!=c)throw new Error(`mixed operators: '${c}' and '${s}'`);s=c,o=!0},l=null;for(;!l;){e.consume();let c=e.token();switch(c.type){case 1:if(o||h(" "),this.isBuiltIn(c.text)){let p=this.namedValidators[c.text];if(!p)throw new Error(`'${c.text}' unexpected`);i.push(p.clone())}else{let p={};p[c.text.toLowerCase()]=B(c.text),i.push(this.primitive(new Pe(0,p,ne)))}o=!1;break;case 5:{let p={};p[`${c.num}`]=new Jt(c.num),i.push(this.primitive(new Pe(0,p,ne))),o=!1;break}case 34:h("|");break;case 25:h("||");break;case 14:o||h(" "),n.push({vals:i,op:s,b:"["}),s="",i=[],o=!0;break;case 6:o||h(" "),n.push({vals:i,op:s,b:"(",fn:c.text}),s="",i=[],o=!0;break;case 15:{r=a();let p=n.pop();if(p.b!="[")throw new Error("']' unexpected");i=p.vals,i.push(r),s=p.op,o=!1;break}case 11:{r=a();let p=n.pop();if(p.b!="(")throw new Error("')' unexpected");i=p.vals,i.push(this.newFunc(p.fn,r)),s=p.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(),c=e.token(),c.type!=5)throw new Error("<int> expected");let p=c.num,d=p;if(e.consume(),c=e.token(),c.type==16){if(e.consume(),c=e.token(),c.type!=5)throw new Error("<int> expected");d=c.num,e.consume(),c=e.token()}if(c.type!=13)throw new Error("'}' expected");i.push(this.addCounts(i.pop(),p,d));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 Ki(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 ei(n.num));break;case 5:i.push(new Jt(n.num));break;case 3:i.push(new T(n.num,n.text));break;default:throw new Error("unexpected token")}}this.defaultValues[t]=i.length>1?new ke(i):i[0]}}parseShorthands(e){for(;;){let t=this.readNameAndPrefixes(e,3);if(!t)return;let i=e.nthToken(1),n;i.type==1&&va[i.text]?(n=new va[i.text],e.consume()):n=new Ri,n.setOwner(this);let s=!1,r=[],o=!1,a=[],h=[];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("_")||h.push(i.text);else if(this.shorthands[i.text]instanceof xu){let l=this.shorthands[i.text];r.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(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 l=new cm(r,o),c=a.pop();r=c.syntax,o=c.slash,r.push(l);break}case 17:s=!0,e.consume();break;default:throw new Error("unexpected token")}n.init(r,h),this.shorthands[t]=n}}parse(e){let t=new gt(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:v.initial}return i}validatePropertyAndHandleShorthand(e,t,i,n){if(Nt(e)||n.ruleType==="font-face"||vm(t)){n.simpleProperty(e,t,i);return}let s="",r=e;e=e.toLowerCase();let o=e.match(/^-([a-z]+)-([-a-z0-9]+)$/);o&&(s=o[1],e=o[2]);let a=this.prefixes[e];if(!a||!a[s]){CSS.supports(e,t.toString())?n.simpleProperty(r,t,i):n.unknownProperty(r,t);return}let h=this.validators[e];if(h){let l=J(t)||t.isExpr()?t:t.visit(h);l?n.simpleProperty(e,l,i):!s&&CSS.supports(e,t.toString())?n.simpleProperty(e,t,i):n.invalidPropertyValue(r,t)}else{let l=this.shorthands[e].clone();J(t)?l.propagateDefaultingValue(t,i,n):(t.visit(l),l.finish(i,n)||n.invalidPropertyValue(r,t))}}};function Su(){let e=new bm;return e.initBuiltInValidators(),e.parse(zl),e}var ym=class extends It{constructor(){super(...arguments),u(this,"varFound",!1)}visitFunc(e){return e.name==="var"?this.varFound=!0:this.varFound||this.visitValues(e.values),null}};function vm(e){let t=new ym;return e.visit(t),t.varFound}var ln={"font-style":v.auto,"font-stretch":v.auto,"font-weight":v.auto,"unicode-range":sd},Yw=`OTTO${new Date().valueOf()}`;function xm(e){let t=new kt;for(let i in ln)t.append(" "),t.append(e[i].toString());return t.toString()}function Sm(e){for(let t in ln)e[t]||(e[t]=ln[t])}function Cm(e,t){let i={};for(let n in e)i[n]=Ve(e,n).evaluate(t,n);return Sm(i),i}var Cu=class{constructor(e){this.properties=e,u(this,"fontTraitKey"),u(this,"src"),u(this,"blobURLs",[]),u(this,"blobs",[]),u(this,"family"),this.fontTraitKey=xm(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 kt;i.append(`@font-face {
|
|
1479
1479
|
font-family: `),i.append(this.family),i.append(`;
|
|
1480
1480
|
`);for(let n in ln)i.append(n),i.append(": "),this.properties[n].appendTo(i,!0),i.append(`;
|
|
1481
1481
|
`);if(t){i.append('src: url("');let n=ip(t);i.append(n),this.blobURLs.push(n),this.blobs.push(t),i.append('")')}else i.append("src: "),i.append(e);return i.append(`;
|