@vivliostyle/core
Version:
Vivliostyle Core library for HTML+CSS typesetting with EPUB/Web publications support
1 lines • 581 kB
JavaScript
var t,e,n,i=(t=require("fast-diff"))&&"object"==typeof t&&"default"in t?t.default:t;function r(t){exports.isDebug=t}function o(t){switch(t){case"ltr":return exports.PageProgression.LTR;case"rtl":return exports.PageProgression.RTL;default:throw new Error("unknown PageProgression: "+t)}}exports.isDebug=!1,function(t){t.LTR="ltr",t.RTL="rtl"}(exports.PageProgression||(exports.PageProgression={})),(e=exports.PageSide||(exports.PageSide={})).LEFT="left",e.RIGHT="right",(n=exports.ReadyState||(exports.ReadyState={})).LOADING="loading",n.INTERACTIVE="interactive",n.COMPLETE="complete";var a,s={PageProgression:exports.PageProgression,PageSide:exports.PageSide,ReadyState:exports.ReadyState};function l(t){var e=Array.from(t),n=null;return e[0]instanceof Error&&(n=e.shift()),{error:n,messages:e}}function u(t){var e=t.error,n=e&&(e.frameTrace||e.stack),i=[].concat(t.messages);return e&&(i.length>0&&(i=i.concat(["\n"])),i=i.concat([e.toString()]),n&&(i=i.concat(["\n"]).concat(n))),i}!function(t){t[t.DEBUG=1]="DEBUG",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.ERROR=4]="ERROR"}(a||(a={}));var h,c=new(function(){function t(t){this.opt_console=t,this.listeners={}}var e=t.prototype;return e.consoleDebug=function(t){var e,n,i;this.opt_console?this.opt_console.debug?(e=this.opt_console).debug.apply(e,t):(n=this.opt_console).log.apply(n,t):(i=console).debug.apply(i,t)},e.consoleInfo=function(t){var e,n,i;this.opt_console?this.opt_console.info?(e=this.opt_console).info.apply(e,t):(n=this.opt_console).log.apply(n,t):(i=console).info.apply(i,t)},e.consoleWarn=function(t){var e,n,i;this.opt_console?this.opt_console.warn?(e=this.opt_console).warn.apply(e,t):(n=this.opt_console).log.apply(n,t):(i=console).warn.apply(i,t)},e.consoleError=function(t){var e,n,i;this.opt_console?this.opt_console.error?(e=this.opt_console).error.apply(e,t):(n=this.opt_console).log.apply(n,t):(i=console).error.apply(i,t)},e.triggerListeners=function(t,e){var n=this.listeners[t];n&&n.forEach(function(t){t(e)})},e.addListener=function(t,e){var n=this.listeners[t];n||(n=this.listeners[t]=[]),n.push(e)},e.debug=function(){var t=l(arguments);this.consoleDebug(u(t)),this.triggerListeners(a.DEBUG,t)},e.info=function(){var t=l(arguments);this.consoleInfo(u(t)),this.triggerListeners(a.INFO,t)},e.warn=function(){var t=l(arguments);this.consoleWarn(u(t)),this.triggerListeners(a.WARN,t)},e.error=function(){var t=l(arguments);this.consoleError(u(t)),this.triggerListeners(a.ERROR,t)},t}());(h=exports.HOOKS||(exports.HOOKS={})).SIMPLE_PROPERTY="SIMPLE_PROPERTY",h.PREPROCESS_SINGLE_DOCUMENT="PREPROCESS_SINGLE_DOCUMENT",h.PREPROCESS_TEXT_CONTENT="PREPROCESS_TEXT_CONTENT",h.PREPROCESS_ELEMENT_STYLE="PREPROCESS_ELEMENT_STYLE",h.POLYFILLED_INHERITED_PROPS="POLYFILLED_INHERITED_PROPS",h.CONFIGURATION="CONFIGURATION",h.RESOLVE_TEXT_NODE_BREAKER="RESOLVE_TEXT_NODE_BREAKER",h.RESOLVE_FORMATTING_CONTEXT="RESOLVE_FORMATTING_CONTEXT",h.RESOLVE_LAYOUT_PROCESSOR="RESOLVE_LAYOUT_PROCESSOR",h.POST_LAYOUT_BLOCK="POST_LAYOUT_BLOCK";var f={};function d(t,e){if(exports.HOOKS[t]){var n=f[t];n||(n=f[t]=[]),n.push(e)}else c.warn(new Error("Skipping unknown plugin hook '"+t+"'."))}function p(t,e){if(exports.HOOKS[t]){var n=f[t];if(n){var i=n.indexOf(e);i>=0&&n.splice(i,1)}}else c.warn(new Error("Ignoring unknown plugin hook '"+t+"'."))}function g(t){return f[t]||[]}var m={registerHook:d,removeHook:p},v=function(){function t(t){this.performanceInstance=t,this.timestamps={},this.registerTiming=E,this.registerStartTiming=this.registerStartTiming=E,this.registerEndTiming=this.registerEndTiming=E}var e=t.prototype;return e.forceRegisterStartTiming=function(t,e){y.call(this,t,"start",e)},e.forceRegisterEndTiming=function(t,e){y.call(this,t,"end",e)},e.printTimings=function(){var t=this.timestamps,e="";Object.keys(t).forEach(function(n){for(var i=t[n],r=i.length,o=0;o<r;o++){var a=i[o];e+=n,r>1&&(e+="("+o+")"),e+=" => start: "+a.start+", end: "+a.end+", duration: "+(a.end-a.start)+"\n"}}),c.info(e)},e.disable=function(){this.registerTiming=E,this.registerStartTiming=this.registerStartTiming=E,this.registerEndTiming=this.registerEndTiming=E},e.enable=function(){this.registerTiming=y,this.registerStartTiming=this.registerStartTiming=w,this.registerEndTiming=this.registerEndTiming=N},e.isEnabled=function(){return this.registerStartTiming===w},t}();function E(){}function y(t,e,n){n||(n=this.performanceInstance.now());var i,r=this.timestamps[t];r||(r=this.timestamps[t]=[]);for(var o=r.length-1;o>=0&&(!(i=r[o])||i[e]);o--)i=null;i||r.push(i={}),i[e]=n}function w(t,e){this.registerTiming(t,"start",e)}function N(t,e){this.registerTiming(t,"end",e)}var b={now:Date.now},S=new v(window&&window.performance||b);S.forceRegisterStartTiming("load_vivliostyle");var C={profiler:{registerStartTiming:S.registerStartTiming,registerEndTiming:S.registerEndTiming,printTimings:S.printTimings,disable:S.disable,enable:S.enable}};function T(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function x(t,e,n){return e&&T(t.prototype,e),n&&T(t,n),t}function I(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function P(t){return(P=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function R(t,e){return(R=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function A(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(t){return!1}}function L(t,e,n){return(L=A()?Reflect.construct:function(t,e,n){var i=[null];i.push.apply(i,e);var r=new(Function.bind.apply(t,i));return n&&R(r,n.prototype),r}).apply(null,arguments)}function O(t){var e="function"==typeof Map?new Map:void 0;return(O=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return L(t,arguments,P(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),R(n,t)})(t)}function k(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function F(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function D(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return F(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?F(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0;return function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}var _={};function B(t){return JSON.parse(t)}function M(t){var e=t.match(/^([^#]*)/);return e?e[1]:t}var U=window.location.href;function V(t){U=t}var H,z=window.location.href;function G(t){z=t}function W(t,e){if(/^data:/i.test(e))return t||e;if(!e||t.match(/^\w{2,}:/))return t.toLowerCase().match("^javascript:")?"#":(t.match(/^\w{2,}:\/\/[^\/]+$/)&&(t+="/"),t);var n;if(e.match(/^\w{2,}:\/\/[^\/]+$/)&&(e+="/"),t.match(/^\/\//))return(n=e.match(/^(\w{2,}:)\/\//))?n[1]+t:t;if(t.match(/^\//))return(n=e.match(/^(\w{2,}:\/\/[^\/]+)\//))?n[1]+t:t;if(t.match(/^\.(\/|$)/)&&(t=t.substr(2)),e=function(t){var e=t.match(/^([^#?]*)/);return e?e[1]:t}(e),t.match(/^#/))return e+t;var i=e.lastIndexOf("/");if(i<0)return t;if(i<e.length-1&&e.lastIndexOf(".")<i){if(""==t)return e;i=(e+="/").length-1}var r=e.substr(0,i+1)+t,o="";for((n=r.match(/^([^?#]*)([?#].*)$/))&&(r=n[1],o=n[2]);!((i=r.indexOf("/../"))<=0);){var a=r.lastIndexOf("/",i-1);if(a<=0)break;r=r.substr(0,a)+r.substr(i+3)}return r.replace(/\/(\.\/)+/g,"/")+o}function X(t){var e;return(e=/^(https?:)\/\/github\.com\/([^/]+\/[^/]+)\/(blob\/|tree\/|raw\/)?(.*)$/.exec(t))?t=e[1]+"//raw.githubusercontent.com/"+e[2]+"/"+(e[3]?"":"master/")+e[4]:(e=/^(https?:)\/\/www\.aozora\.gr\.jp\/(cards\/[^/]+\/files\/[^/.]+\.html)$/.exec(t))?t=e[1]+"//raw.githubusercontent.com/aozorabunko/aozorabunko/master/"+e[2]:(e=/^(https?:)\/\/gist\.github\.com\/([^/]+\/\w+)(\/|$)(raw(\/|$))?(.*)$/.exec(t))?t=e[1]+"//gist.githubusercontent.com/"+e[2]+"/raw/"+e[6]:(e=/^(https?:)\/\/(?:[^/.]+\.)?jsbin\.com\/(?!(?:blog|help)\b)(\w+)((\/\d+)?).*$/.exec(t))&&(t=e[1]+"//output.jsbin.com/"+e[2]+e[3]+"/"),t}function j(t){return null==t?t:t.toString()}!function(t){t.FB2="http://www.gribuser.ru/xml/fictionbook/2.0",t.epub="http://www.idpf.org/2007/ops",t.EV="http://www.w3.org/2001/xml-events",t.MATHML="http://www.w3.org/1998/Math/MathML",t.XML="http://www.w3.org/XML/1998/namespace",t.XHTML="http://www.w3.org/1999/xhtml",t.XLINK="http://www.w3.org/1999/xlink",t.SHADOW="http://www.pyroxy.com/ns/shadow",t.SVG="http://www.w3.org/2000/svg",t.DC="http://purl.org/dc/elements/1.1/",t.NCX="http://www.daisy.org/z3986/2005/ncx/",t.SSE="http://example.com/sse"}(H||(H={}));var Y=function(){function t(){this.queue=[null]}var e=t.prototype;return e.length=function(){return this.queue.length-1},e.add=function(t){for(var e=this.queue.length;e>1;){var n=Math.floor(e/2),i=this.queue[n];if(i.compare(t)>0)return void(this.queue[e]=t);this.queue[e]=i,e=n}this.queue[1]=t},e.peek=function(){return this.queue[1]},e.remove=function(){var t=this.queue[1],e=this.queue.pop(),n=this.queue.length;if(n>1){for(var i=1;;){var r=2*i;if(r>=n)break;if(this.queue[r].compare(e)>0)r+1<n&&this.queue[r+1].compare(this.queue[r])>0&&r++;else{if(!(r+1<n&&this.queue[r+1].compare(e)>0))break;r++}this.queue[i]=this.queue[r],i=r}this.queue[i]=e}return t},t}(),K=["","-webkit-","-moz-","-ms-","-o-","-epub-"],q={};function Q(t,e){if("writing-mode"===e){var n=document.createElement("span");return"-ms-"===t?(n.style.setProperty(t+e,"tb-rl"),"tb-rl"===n.style["writing-mode"]):(n.style.setProperty(t+e,"vertical-rl"),"vertical-rl"===n.style[t+e])}return"string"==typeof document.documentElement.style[function(t,e){return t&&(e="-"+e,"moz"===(t=t.replace(/-/g,""))&&(t="Moz")),t+e.replace(/-[a-z]/g,function(t){return t.substr(1).toUpperCase()})}(t,e)]}function Z(t){var e=q[t];if(e||null===e)return e;switch(t){case"text-combine-upright":if(Q("-webkit-","text-combine")&&!Q("","text-combine-upright"))return q[t]=["-webkit-text-combine"],["-webkit-text-combine"];break;case"writing-mode":if(Q("-ms-","writing-mode"))return q[t]=["-ms-writing-mode"],["-ms-writing-mode"];break;case"filter":if(Q("-webkit-","filter"))return q[t]=["-webkit-filter"],["-webkit-filter"];break;case"clip-path":if(Q("-webkit-","clip-path"))return q[t]=["-webkit-clip-path","clip-path"];break;case"margin-inline-start":if(Q("-webkit-","margin-start"))return q[t]=["-webkit-margin-start"],["-webkit-margin-start"];break;case"margin-inline-end":if(Q("-webkit-","margin-end"))return q[t]=["-webkit-margin-end"],["-webkit-margin-end"];break;case"padding-inline-start":if(Q("-webkit-","padding-start"))return q[t]=["-webkit-padding-start"],["-webkit-padding-start"];break;case"padding-inline-end":if(Q("-webkit-","padding-end"))return q[t]=["-webkit-padding-end"],["-webkit-padding-end"]}for(var n,i=D(K);!(n=i()).done;){var r=n.value;if(Q(r,t))return q[t]=[e=r+t],[e]}return c.warn("Property not supported by the browser: ",t),q[t]=null,null}function $(t,e,n){try{var i=Z(e);if(!i)return;i.forEach(function(e){if("-ms-writing-mode"===e)switch(n){case"horizontal-tb":n="lr-tb";break;case"vertical-rl":n="tb-rl";break;case"vertical-lr":n="tb-lr"}else if("-webkit-text-combine"===e)switch(n){case"all":n="horizontal"}t&&t.style&&t.style.setProperty(e,n)})}catch(t){c.warn(t)}}function J(t,e,n){try{var i=q[e];return t.style.getPropertyValue(i?i[0]:e)}catch(t){}return n||""}function tt(t){var e=t.getAttributeNS(H.XML,"lang");return e||t.namespaceURI!=H.XHTML||(e=t.getAttribute("lang")),e}var et=function(){function t(){this.list=[]}var e=t.prototype;return e.append=function(t){return this.list.push(t),this},e.clear=function(){this.list=[]},e.toString=function(){var t=this.list.join("");return this.list=[t],t},t}();function nt(t){return"\\"+t.charCodeAt(0).toString(16)+" "}function it(t){return t.replace(/[^-_a-zA-Z0-9\u0080-\uFFFF]/g,nt)}function rt(t){return t.replace(/[\u0000-\u001F"\\]/g,nt)}function ot(t){return t.replace(/[\s+&?=#\u007F-\uFFFF]+/g,encodeURIComponent)}function at(t){return!!t.match(/^[a-zA-Z\u009E\u009F\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u037B-\u037D\u0386\u0388-\u0482\u048A-\u0527]$/)}function st(t,e){return t.replace(/[^-a-zA-Z0-9_]/g,function(t){return function(t,e){return(e="string"==typeof e?e:"\\u")+(65536|t.charCodeAt(0)).toString(16).substr(1)}(t,e)})}function lt(t){return st(t)}function ut(t,e){for(var n=0,i=t;;){if(0==n||e(n-1),i==t||e(i),n==i)return n;var r=n+i>>1;e(r)?i=r:n=r+1}}function ht(t,e){return t-e}function ct(t,e){for(var n,i={},r=D(t);!(n=r()).done;){var o=n.value,a=e(o);a&&!i[a]&&(i[a]=o)}return i}function ft(t,e){for(var n,i={},r=D(t);!(n=r()).done;){var o=n.value,a=e(o);a&&(i[a]?i[a].push(o):i[a]=[o])}return i}var dt=function(){function t(){this.listeners={}}var e=t.prototype;return e.dispatchEvent=function(t){var e=this.listeners[t.type];if(e){t.target=this,t.currentTarget=this;for(var n=0;n<e.length;n++)e[n](t)}},e.addEventListener=function(t,e,n){if(!n){var i=this.listeners[t];i?i.push(e):this.listeners[t]=[e]}},e.removeEventListener=function(t,e,n){if(!n){var i=this.listeners[t];if(i){var r=i.indexOf(e);r>=0&&i.splice(r,1)}}},t}(),pt=null,gt=null,mt=null,vt=null;function Et(t){if(1==t.nodeType){var e=t.getAttribute("id");if(e&&e.match(/^[-a-zA-Z_0-9.\u007F-\uFFFF]+$/))return e}return null}function yt(t){return"^"+t}function wt(t){return t.replace(/[\[\]\(\),=;^]/g,yt)}function Nt(t){return t.substr(1)}function bt(t){return t?t.replace(/\^[\[\]\(\),=;^]/g,Nt):t}function St(t){var e=[];do{var n=t.match(/^(\^,|[^,])*/),i=bt(n[0]);if(!(t=t.substr(n[0].length+1))&&!e.length)return i;e.push(i)}while(t);return e}function Ct(t){for(var e={};t;){var n=t.match(/^;([^;=]+)=(([^;]|\^;)*)/);if(!n)return e;e[n[1]]=St(n[2]),t=t.substr(n[0].length)}return e}var Tt=function(){function t(){}var e=t.prototype;return e.appendTo=function(t){t.append("!")},e.applyTo=function(t){return!1},t}(),xt=function(){function t(t,e,n){this.index=t,this.id=e,this.sideBias=n}var e=t.prototype;return e.appendTo=function(t){t.append("/"),t.append(this.index.toString()),(this.id||this.sideBias)&&(t.append("["),this.id&&t.append(this.id),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))},e.applyTo=function(t){if(1!=t.node.nodeType)throw new Error("E_CFI_NOT_ELEMENT");var e,n=t.node,i=n.children,r=i.length,o=Math.floor(this.index/2)-1;if(o<0||0==r)t.node=(e=n.firstChild)||n;else{if(e=i[Math.min(o,r-1)],1&this.index){var a=e.nextSibling;a&&1!=a.nodeType?e=a:t.after=!0}t.node=e}if(this.id&&(t.after||this.id!=Et(t.node)))throw new Error("E_CFI_ID_MISMATCH");return t.sideBias=this.sideBias,!0},t}(),It=function(){function t(t,e,n,i){this.offset=t,this.textBefore=e,this.textAfter=n,this.sideBias=i}var e=t.prototype;return e.applyTo=function(t){if(this.offset>0&&!t.after){for(var e=this.offset,n=t.node;;){var i=n.nodeType;if(1==i)break;var r=n.nextSibling;if(3<=i&&i<=5){var o=n.textContent.length;if(e<=o)break;if(!r){e=o;break}e-=o}if(!r){e=0;break}n=r}t.node=n,t.offset=e}return t.sideBias=this.sideBias,!0},e.appendTo=function(t){t.append(":"),t.append(this.offset.toString()),(this.textBefore||this.textAfter||this.sideBias)&&(t.append("["),(this.textBefore||this.textAfter)&&(this.textBefore&&t.append(wt(this.textBefore)),t.append(","),this.textAfter&&t.append(wt(this.textAfter))),this.sideBias&&(t.append(";s="),t.append(this.sideBias)),t.append("]"))},t}(),Pt=function(){function t(){this.steps=null}var e=t.prototype;return e.fromString=function(t){var e=t.match(/^#?epubcfi\((.*)\)$/);if(!e)throw new Error("E_CFI_NOT_CFI");for(var n=e[1],i=0,r=[];;){var o=void 0;switch(n.charAt(i)){case"/":if(i++,!(e=n.substr(i).match(/^(0|[1-9][0-9]*)(\[([-a-zA-Z_0-9.\u007F-\uFFFF]+)(;([^\]]|\^\])*)?\])?/)))throw new Error("E_CFI_NUMBER_EXPECTED");i+=e[0].length;var a=parseInt(e[1],10),s=e[3];o=Ct(e[4]),r.push(new xt(a,s,j(o.s)));break;case":":if(i++,!(e=n.substr(i).match(/^(0|[1-9][0-9]*)(\[((([^\];,]|\^[\];,])*)(,(([^\];,]|\^[\];,])*))?)(;([^]]|\^\])*)?\])?/)))throw new Error("E_CFI_NUMBER_EXPECTED");i+=e[0].length;var l=parseInt(e[1],10),u=e[4];u&&(u=bt(u));var h=e[7];h&&(h=bt(h)),o=Ct(e[10]),r.push(new It(l,u,h,j(o.s)));break;case"!":i++,r.push(new Tt);break;case"~":case"@":case"":return void(this.steps=r);default:throw new Error("E_CFI_PARSE_ERROR")}}},e.navigate=function(e){for(var n={node:e.documentElement,offset:0,after:!1,sideBias:null,ref:null},i=0;i<this.steps.length;i++)if(!this.steps[i].applyTo(n)){n.ref=new t,n.ref.steps=this.steps.slice(i+1);break}return n},e.trim=function(t,e){return t.replace(/\s+/g," ").match(e?/^[ -\uD7FF\uE000-\uFFFF]{0,8}/:/[ -\uD7FF\uE000-\uFFFF]{0,8}$/)[0].replace(/^\s/,"").replace(/\s$/,"")},e.prependPathFromNode=function(t,e,n,i){for(var r=[],o=t.parentNode,a="",s="";t;){switch(t.nodeType){case 3:case 4:case 5:var l=t.textContent,u=l.length;n?(e+=u,a||(a=l)):(e>u&&(e=u),n=!0,a=l.substr(0,e),s=l.substr(e)),t=t.previousSibling;continue;case 8:t=t.previousSibling;continue}break}for((e>0||a||s)&&(a=this.trim(a,!1),s=this.trim(s,!0),r.push(new It(e,a,s,i)),i=null);o&&o&&9!=o.nodeType;){for(var h=n?null:Et(t),c=n?1:0;t;)1==t.nodeType&&(c+=2),t=t.previousSibling;r.push(new xt(c,h,i)),i=null,t=o,o=o.parentNode,n=!1}r.reverse(),this.steps?(r.push(new Tt),this.steps=r.concat(this.steps)):this.steps=r},e.toString=function(){if(!this.steps)return"";var t=new et;t.append("epubcfi(");for(var e=0;e<this.steps.length;e++)this.steps[e].appendTo(t);return t.append(")"),t.toString()},t}();function Rt(t){return{fontFamily:t.fontFamily,lineHeight:t.lineHeight,margin:t.margin,hyphenate:t.hyphenate,columnWidth:t.columnWidth,horizontal:t.horizontal,nightMode:t.nightMode,spreadView:t.spreadView,pageBorder:t.pageBorder,enabledMediaTypes:Object.assign({},t.enabledMediaTypes),defaultPaperSize:t.defaultPaperSize?Object.assign({},t.defaultPaperSize):void 0}}var At={fontFamily:"serif",lineHeight:1.25,margin:8,hyphenate:!1,columnWidth:25,horizontal:!1,nightMode:!1,spreadView:!1,pageBorder:1,enabledMediaTypes:{vivliostyle:!0,print:!0},defaultPaperSize:void 0},Lt={};function Ot(t,e,n,i){var r=Math.min((t-0)/n,(e-0)/i);return"matrix("+r+",0,0,"+r+",0,0)"}function kt(t){return'"'+rt(""+t)+'"'}function Ft(t){return it(""+t)}function Dt(t,e){return t?it(t)+"."+it(e):it(e)}var _t=0,Bt=function(){function t(t,e){if(this.parent=t,this.resolver=e,this.children=[],this.values={},this.funcs={},this.builtIns={},this.scopeKey="S"+_t++,this.zero=new Ee(this,0),this.one=new Ee(this,1),this._true=new Ee(this,!0),this._false=new Ee(this,!1),t&&t.children.push(this),!t){var n=this.builtIns;n.floor=Math.floor,n.ceil=Math.ceil,n.round=Math.round,n.sqrt=Math.sqrt,n.min=Math.min,n.max=Math.max,n.letterbox=Ot,n["css-string"]=kt,n["css-name"]=Ft,n.typeof=function(t){return typeof t},this.defineBuiltInName("page-width",function(){return this.pageWidth()}),this.defineBuiltInName("page-height",function(){return this.pageHeight()}),this.defineBuiltInName("pref-font-family",function(){return this.pref.fontFamily}),this.defineBuiltInName("pref-night-mode",function(){return this.pref.nightMode}),this.defineBuiltInName("pref-hyphenate",function(){return this.pref.hyphenate}),this.defineBuiltInName("pref-margin",function(){return this.pref.margin}),this.defineBuiltInName("pref-line-height",function(){return this.pref.lineHeight}),this.defineBuiltInName("pref-column-width",function(){return this.pref.columnWidth*this.fontSize}),this.defineBuiltInName("pref-horizontal",function(){return this.pref.horizontal}),this.defineBuiltInName("pref-spread-view",function(){return this.pref.spreadView}),this.defineBuiltInName("pub-title",function(){return kt(this.pubTitle?this.pubTitle:"")}),this.defineBuiltInName("doc-title",function(){return kt(this.docTitle?this.docTitle:"")})}}var e=t.prototype;return e.defineBuiltInName=function(t,e){this.values[t]=new ge(this,e,t)},e.defineName=function(t,e){this.values[t]=e},e.defineFunc=function(t,e){this.funcs[t]=e},e.defineBuiltIn=function(t,e){this.builtIns[t]=e},t}();function Mt(t){switch(t.toLowerCase()){case"vw":case"vh":case"vi":case"vb":case"vmin":case"vmax":case"pvw":case"pvh":case"pvi":case"pvb":case"pvmin":case"pvmax":return!0;default:return!1}}var Ut={px:1,in:96,pt:4/3,pc:16,cm:96/2.54,mm:96/25.4,q:96/2.54/40,em:16,rem:16,ex:8,dppx:1,dpi:1/96,dpcm:2.54/96};function Vt(t){switch(t){case"q":case"rem":return!0;default:return!1}}var Ht=function(){function t(t,e,n,i){this.rootScope=t,this.viewportWidth=e,this.viewportHeight=n,this.actualPageWidth=null,this.actualPageHeight=null,this.rootFontSize=null,this.scopes={},this.pageAreaWidth=null,this.pageAreaHeight=null,this.pageVertical=null,this.pubTitle=null,this.docTitle=null,this.pageWidth=function(){return this.actualPageWidth?this.actualPageWidth:this.pref.spreadView?Math.floor(e/2)-this.pref.pageBorder:e},this.pageHeight=function(){return this.actualPageHeight?this.actualPageHeight:n},this.initialFontSize=i,this.fontSize=function(){return this.rootFontSize?this.rootFontSize:i},this.pref=At}var e=t.prototype;return e.getScopeContext=function(t){var e=this.scopes[t.scopeKey];return e||(this.scopes[t.scopeKey]=e={}),e},e.clearScope=function(t){this.scopes[t.scopeKey]={};for(var e=0;e<t.children.length;e++)this.clearScope(t.children[e])},e.queryUnitSize=function(t,e){if(Mt(t)){var n=this.pageWidth()/100,i=this.pageHeight()/100,r=null!=this.pageAreaWidth?this.pageAreaWidth/100:n,o=null!=this.pageAreaHeight?this.pageAreaHeight/100:i;switch(t){case"vw":return r;case"vh":return o;case"vi":return this.pageVertical?o:r;case"vb":return this.pageVertical?r:o;case"vmin":return r<o?r:o;case"vmax":return r>o?r:o;case"pvw":return n;case"pvh":return i;case"pvi":return this.pageVertical?i:n;case"pvb":return this.pageVertical?n:i;case"pvmin":return n<i?n:i;case"pvmax":return n>i?n:i}}return"em"==t||"rem"==t?e?this.initialFontSize:this.fontSize():"ex"==t?Ut.ex*(e?this.initialFontSize:this.fontSize())/Ut.em:Ut[t]},e.evalName=function(t,e){do{var n=t.values[e];if(n)return n;if(t.resolver&&(n=t.resolver.call(this,e,!1)))return n;t=t.parent}while(t);throw new Error("Name '"+e+"' is undefined")},e.evalCall=function(t,e,n,i){do{var r=t.funcs[e];if(r)return r;if(t.resolver&&(r=t.resolver.call(this,e,!0)))return r;var o=t.builtIns[e];if(o){if(i)return t.zero;for(var a=Array(n.length),s=0;s<n.length;s++)a[s]=n[s].evaluate(this);return new Ee(t,o.apply(this,a))}t=t.parent}while(t);throw new Error("Function '"+e+"' is undefined")},e.evalMediaName=function(t,e){var n="all"===t||!!this.pref.enabledMediaTypes[t];return e?!n:n},e.evalMediaTest=function(t,e){var n="",i=t.match(/^(min|max)-(.*)$/);i&&(n=i[1],t=i[2]);var r=null,o=null;switch(t){case"width":case"height":case"device-width":case"device-height":case"color":e&&(r=e.evaluate(this))}switch(t){case"width":o=this.pageWidth();break;case"height":o=this.pageHeight();break;case"device-width":o=window.screen.availWidth;break;case"device-height":o=window.screen.availHeight;break;case"color":o=window.screen.pixelDepth}if(null!=o&&null!=r)switch(n){case"min":return o>=r;case"max":return o<=r;default:return o==r}else if(null!=o&&null==e)return 0!==o;return!1},e.queryVal=function(t,e){var n=this.scopes[t.scopeKey];return n?n[e]:void 0},e.storeVal=function(t,e,n){this.getScopeContext(t)[e]=n},t}(),zt=function(){function t(t){this.scope=t,this.scope=t,this.key="_"+_t++}var e=t.prototype;return e.toString=function(){var t=new et;return this.appendTo(t,0),t.toString()},e.appendTo=function(t,e){throw new Error("F_ABSTRACT")},e.evaluateCore=function(t){throw new Error("F_ABSTRACT")},e.expand=function(t,e){return this},e.dependCore=function(t,e,n){return t===this},e.dependOuter=function(t,e,n){var i=n[this.key];if(null!=i)return i!==Lt&&i;n[this.key]=Lt;var r=this.dependCore(t,e,n);return n[this.key]=r,r},e.depend=function(t,e){return this.dependOuter(t,e,{})},e.evaluate=function(t){var e=t.queryVal(this.scope,this.key);return void 0!==e||(e=this.evaluateCore(t),t.storeVal(this.scope,this.key,e)),e},e.isMediaName=function(){return!1},t}(),Gt=function(t){function e(e,n){var i;return(i=t.call(this,e)||this).val=n,i}I(e,t);var n=e.prototype;return n.getOp=function(){throw new Error("F_ABSTRACT")},n.evalPrefix=function(t){throw new Error("F_ABSTRACT")},n.evaluateCore=function(t){var e=this.val.evaluate(t);return this.evalPrefix(e)},n.dependCore=function(t,e,n){return t===this||this.val.dependOuter(t,e,n)},n.appendTo=function(t,e){10<e&&t.append("("),t.append(this.getOp()),this.val.appendTo(t,10),10<e&&t.append(")")},n.expand=function(t,e){var n=this.val.expand(t,e);return n===this.val?this:new this.constructor(this.scope,n)},e}(zt),Wt=function(t){function e(e,n,i){var r;return(r=t.call(this,e)||this).lhs=n,r.rhs=i,r}I(e,t);var n=e.prototype;return n.getPriority=function(){throw new Error("F_ABSTRACT")},n.getOp=function(){throw new Error("F_ABSTRACT")},n.evalInfix=function(t,e){throw new Error("F_ABSTRACT")},n.evaluateCore=function(t){var e=this.lhs.evaluate(t),n=this.rhs.evaluate(t);return this.evalInfix(e,n)},n.dependCore=function(t,e,n){return t===this||this.lhs.dependOuter(t,e,n)||this.rhs.dependOuter(t,e,n)},n.appendTo=function(t,e){var n=this.getPriority();n<=e&&t.append("("),this.lhs.appendTo(t,n),t.append(this.getOp()),this.rhs.appendTo(t,n),n<=e&&t.append(")")},n.expand=function(t,e){var n=this.lhs.expand(t,e),i=this.rhs.expand(t,e);return n===this.lhs&&i===this.rhs?this:new this.constructor(this.scope,n,i)},e}(zt),Xt=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}return I(e,t),e.prototype.getPriority=function(){return 1},e}(Wt),jt=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}return I(e,t),e.prototype.getPriority=function(){return 2},e}(Wt),Yt=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}return I(e,t),e.prototype.getPriority=function(){return 3},e}(Wt),Kt=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}return I(e,t),e.prototype.getPriority=function(){return 4},e}(Wt),qt=function(t){function e(e,n){return t.call(this,e,n)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"!"},n.evalPrefix=function(t){return!t},e}(Gt),Qt=function(t){function e(e,n){return t.call(this,e,n)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"-"},n.evalPrefix=function(t){return-t},e}(Gt),Zt=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"&&"},n.evaluateCore=function(t){return this.lhs.evaluate(t)&&this.rhs.evaluate(t)},e}(Xt),$t=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}return I(e,t),e.prototype.getOp=function(){return" and "},e}(Zt),Jt=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"||"},n.evaluateCore=function(t){return this.lhs.evaluate(t)||this.rhs.evaluate(t)},e}(Xt),te=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}return I(e,t),e.prototype.getOp=function(){return", "},e}(Jt),ee=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"<"},n.evalInfix=function(t,e){return t<e},e}(jt),ne=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"<="},n.evalInfix=function(t,e){return t<=e},e}(jt),ie=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return">"},n.evalInfix=function(t,e){return t>e},e}(jt),re=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return">="},n.evalInfix=function(t,e){return t>=e},e}(jt),oe=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"=="},n.evalInfix=function(t,e){return t==e},e}(jt),ae=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"!="},n.evalInfix=function(t,e){return t!=e},e}(jt),se=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"+"},n.evalInfix=function(t,e){return t+e},e}(Yt),le=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return" - "},n.evalInfix=function(t,e){return t-e},e}(Yt),ue=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"*"},n.evalInfix=function(t,e){return t*e},e}(Kt),he=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"/"},n.evalInfix=function(t,e){return t/e},e}(Kt),ce=function(t){function e(e,n,i){return t.call(this,e,n,i)||this}I(e,t);var n=e.prototype;return n.getOp=function(){return"%"},n.evalInfix=function(t,e){return t%e},e}(Kt),fe=function(t){function e(e,n,i){var r;return(r=t.call(this,e)||this).num=n,r.unit=i.toLowerCase(),r}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){t.append(this.num.toString()),t.append(it(this.unit))},n.evaluateCore=function(t){return this.num*t.queryUnitSize(this.unit,!1)},e}(zt),de=function(t){function e(e,n){var i;return(i=t.call(this,e)||this).qualifiedName=n,i}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){t.append(this.qualifiedName)},n.evaluateCore=function(t){return t.evalName(this.scope,this.qualifiedName).evaluate(t)},n.dependCore=function(t,e,n){return t===this||e.evalName(this.scope,this.qualifiedName).dependOuter(t,e,n)},e}(zt),pe=function(t){function e(e,n,i){var r;return(r=t.call(this,e)||this).not=n,r.name=i,r}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){this.not&&t.append("not "),t.append(it(this.name))},n.evaluateCore=function(t){return t.evalMediaName(this.name,this.not)},n.dependCore=function(t,e,n){return t===this||this.value.dependOuter(t,e,n)},n.isMediaName=function(){return!0},e}(zt),ge=function(t){function e(e,n,i){var r;return(r=t.call(this,e)||this).fn=n,r.str=i,r}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){t.append(this.str)},n.evaluateCore=function(t){return this.fn.call(t)},e}(zt),me=function(t){function e(e,n,i){var r;return(r=t.call(this,e)||this).qualifiedName=n,r.params=i,r}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){t.append(this.qualifiedName),function(t,e){t.append("(");for(var n=0;n<e.length;n++)n&&t.append(","),e[n].appendTo(t,0);t.append(")")}(t,this.params)},n.evaluateCore=function(t){return t.evalCall(this.scope,this.qualifiedName,this.params,!1).expand(t,this.params).evaluate(t)},n.dependCore=function(t,e,n){if(t===this)return!0;for(var i=0;i<this.params.length;i++)if(this.params[i].dependOuter(t,e,n))return!0;return e.evalCall(this.scope,this.qualifiedName,this.params,!0).dependOuter(t,e,n)},n.expand=function(t,n){var i=function(t,e,n){for(var i=e,r=0;r<e.length;r++){var o=e[r].expand(t,n);if(e!==i)i[r]=o;else if(o!==e[r]){i=Array(e.length);for(var a=0;a<r;a++)i[a]=e[a];i[r]=o}}return i}(t,this.params,n);return i===this.params?this:new e(this.scope,this.qualifiedName,i)},e}(zt),ve=function(t){function e(e,n,i,r){var o;return(o=t.call(this,e)||this).cond=n,o.ifTrue=i,o.ifFalse=r,o}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){e>0&&t.append("("),this.cond.appendTo(t,0),t.append("?"),this.ifTrue.appendTo(t,0),t.append(":"),this.ifFalse.appendTo(t,0),e>0&&t.append(")")},n.evaluateCore=function(t){return this.cond.evaluate(t)?this.ifTrue.evaluate(t):this.ifFalse.evaluate(t)},n.dependCore=function(t,e,n){return t===this||this.cond.dependOuter(t,e,n)||this.ifTrue.dependOuter(t,e,n)||this.ifFalse.dependOuter(t,e,n)},n.expand=function(t,n){var i=this.cond.expand(t,n),r=this.ifTrue.expand(t,n),o=this.ifFalse.expand(t,n);return i===this.cond&&r===this.ifTrue&&o===this.ifFalse?this:new e(this.scope,i,r,o)},e}(zt),Ee=function(t){function e(e,n){var i;return(i=t.call(this,e)||this).val=n,i}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){switch(typeof this.val){case"number":case"boolean":t.append(this.val.toString());break;case"string":t.append('"'),t.append(rt(this.val)),t.append('"');break;default:throw new Error("F_UNEXPECTED_STATE")}},n.evaluateCore=function(t){return this.val},e}(zt),ye=function(t){function e(e,n,i){var r;return(r=t.call(this,e)||this).name=n,r.value=i,r}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){t.append("("),t.append(rt(this.name.name)),t.append(":"),this.value.appendTo(t,0),t.append(")")},n.evaluateCore=function(t){return t.evalMediaTest(this.name.name,this.value)},n.dependCore=function(t,e,n){return t===this||this.value.dependOuter(t,e,n)},n.expand=function(t,n){var i=this.value.expand(t,n);return i===this.value?this:new e(this.scope,this.name,i)},e}(zt),we=function(t){function e(e,n){var i;return(i=t.call(this,e)||this).index=n,i}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){t.append("$"),t.append(this.index.toString())},n.expand=function(t,e){var n=e[this.index];if(!n)throw new Error("Parameter missing: "+this.index);return n},e}(zt);function Ne(t,e,n){return e===t._false||e===t.zero||n==t._false||n==t.zero?t._false:e===t._true||e===t.one?n:n===t._true||n===t.one?e:new Zt(t,e,n)}function be(t,e,n){return e===t.zero?n:n===t.zero?e:new se(t,e,n)}function Se(t,e,n){return e===t.zero?new Qt(t,n):n===t.zero?e:new le(t,e,n)}function Ce(t,e,n){return e===t.zero||n===t.zero?t.zero:e===t.one?n:n===t.one?e:new ue(t,e,n)}function Te(t,e,n){return e===t.zero?t.zero:n===t.one?e:new he(t,e,n)}var xe=function(){function t(){}var e=t.prototype;return e.visitValues=function(t){for(var e=0;e<t.length;e++)t[e].visit(this)},e.visitEmpty=function(t){throw new Error("E_CSS_EMPTY_NOT_ALLOWED")},e.visitSlash=function(t){throw new Error("E_CSS_SLASH_NOT_ALLOWED")},e.visitStr=function(t){throw new Error("E_CSS_STR_NOT_ALLOWED")},e.visitIdent=function(t){throw new Error("E_CSS_IDENT_NOT_ALLOWED")},e.visitNumeric=function(t){throw new Error("E_CSS_NUMERIC_NOT_ALLOWED")},e.visitNum=function(t){throw new Error("E_CSS_NUM_NOT_ALLOWED")},e.visitInt=function(t){return this.visitNum(t)},e.visitColor=function(t){throw new Error("E_CSS_COLOR_NOT_ALLOWED")},e.visitURL=function(t){throw new Error("E_CSS_URL_NOT_ALLOWED")},e.visitSpaceList=function(t){throw new Error("E_CSS_LIST_NOT_ALLOWED")},e.visitCommaList=function(t){throw new Error("E_CSS_COMMA_NOT_ALLOWED")},e.visitFunc=function(t){throw new Error("E_CSS_FUNC_NOT_ALLOWED")},e.visitExpr=function(t){throw new Error("E_CSS_EXPR_NOT_ALLOWED")},t}(),Ie=function(t){function e(){return t.call(this)||this}I(e,t);var n=e.prototype;return n.visitValues=function(t){for(var e=null,n=0;n<t.length;n++){var i=t[n],r=i.visit(this);if(e)e[n]=r;else if(i!==r){e=new Array(t.length);for(var o=0;o<n;o++)e[o]=t[o];e[n]=r}}return e||t},n.visitStr=function(t){return t},n.visitIdent=function(t){return t},n.visitSlash=function(t){return t},n.visitNumeric=function(t){return t},n.visitNum=function(t){return t},n.visitInt=function(t){return t},n.visitColor=function(t){return t},n.visitURL=function(t){return t},n.visitSpaceList=function(t){var e=this.visitValues(t.values);return e===t.values?t:new He(e)},n.visitCommaList=function(t){var e=this.visitValues(t.values);return e===t.values?t:new ze(e)},n.visitFunc=function(t){var e=this.visitValues(t.values);return e===t.values?t:new Ge(t.name,e)},n.visitExpr=function(t){return t},e}(xe),Pe=function(){function t(){}var e=t.prototype;return e.toString=function(){var t=new et;return this.appendTo(t,!0),t.toString()},e.stringValue=function(){var t=new et;return this.appendTo(t,!1),t.toString()},e.toExpr=function(t,e){throw new Error("F_ABSTRACT")},e.appendTo=function(t,e){t.append("[error]")},e.isExpr=function(){return!1},e.isNumeric=function(){return!1},e.isNum=function(){return!1},e.isIdent=function(){return!1},e.isSpaceList=function(){return!1},e.visit=function(t){throw new Error("F_ABSTRACT")},t}(),Re=function(t){function e(){return t.call(this)||this}I(e,t);var n=e.prototype;return n.toExpr=function(t,e){return new Ee(t,"")},n.appendTo=function(t,e){},n.visit=function(t){return t.visitEmpty(this)},x(e,null,[{key:"instance",get:function(){return this.empty||(this.empty=new e),this.empty}}]),e}(Pe).instance,Ae=function(t){function e(){return t.call(this)||this}I(e,t);var n=e.prototype;return n.toExpr=function(t,e){return new Ee(t,"/")},n.appendTo=function(t,e){t.append("/")},n.visit=function(t){return t.visitSlash(this)},x(e,null,[{key:"instance",get:function(){return this.slash||(this.slash=new e),this.slash}}]),e}(Pe).instance,Le=function(t){function e(e){var n;return(n=t.call(this)||this).str=e,n}I(e,t);var n=e.prototype;return n.toExpr=function(t,e){return new Ee(t,this.str)},n.appendTo=function(t,e){e?(t.append('"'),t.append(rt(this.str)),t.append('"')):t.append(this.str)},n.visit=function(t){return t.visitStr(this)},e}(Pe),Oe={},ke=function(t){function e(e){var n;if((n=t.call(this)||this).name=e,Oe[e])throw new Error("E_INVALID_CALL");return Oe[e]=k(n),n}I(e,t);var n=e.prototype;return n.toExpr=function(t,e){return new Ee(t,this.name)},n.appendTo=function(t,e){t.append(e?it(this.name):this.name)},n.visit=function(t){return t.visitIdent(this)},n.isIdent=function(){return!0},e}(Pe);function Fe(t){var e=Oe[t];return e||(e=new ke(t)),e}var De=function(t){function e(e,n){var i;return(i=t.call(this)||this).num=e,i.unit=n.toLowerCase(),i}I(e,t);var n=e.prototype;return n.toExpr=function(t,e){return 0==this.num?t.zero:e&&"%"==this.unit?100==this.num?e:new ue(t,e,new Ee(t,this.num/100)):new fe(t,this.num,this.unit)},n.appendTo=function(t,e){t.append(this.num.toString()),t.append(this.unit)},n.visit=function(t){return t.visitNumeric(this)},n.isNumeric=function(){return!0},e}(Pe),_e=function(t){function e(e){var n;return(n=t.call(this)||this).num=e,n}I(e,t);var n=e.prototype;return n.toExpr=function(t,e){return 0==this.num?t.zero:1==this.num?t.one:new Ee(t,this.num)},n.appendTo=function(t,e){t.append(this.num.toString())},n.visit=function(t){return t.visitNum(this)},n.isNum=function(){return!0},e}(Pe),Be=function(t){function e(e){return t.call(this,e)||this}return I(e,t),e.prototype.visit=function(t){return t.visitInt(this)},e}(_e),Me=function(t){function e(e){var n;return(n=t.call(this)||this).rgb=e,n}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){t.append("#");var n=this.rgb.toString(16);t.append("000000".substr(n.length)),t.append(n)},n.visit=function(t){return t.visitColor(this)},e}(Pe),Ue=function(t){function e(e){var n;return(n=t.call(this)||this).url=e,n}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){t.append('url("'),t.append(rt(this.url)),t.append('")')},n.visit=function(t){return t.visitURL(this)},e}(Pe);function Ve(t,e,n,i){var r=e.length;e[0].appendTo(t,i);for(var o=1;o<r;o++)t.append(n),e[o].appendTo(t,i)}var He=function(t){function e(e){var n;return(n=t.call(this)||this).values=e,n}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){Ve(t,this.values," ",e)},n.visit=function(t){return t.visitSpaceList(this)},n.isSpaceList=function(){return!0},e}(Pe),ze=function(t){function e(e){var n;return(n=t.call(this)||this).values=e,n}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){Ve(t,this.values,",",e)},n.visit=function(t){return t.visitCommaList(this)},e}(Pe),Ge=function(t){function e(e,n){var i;return(i=t.call(this)||this).name=e,i.values=n,i}I(e,t);var n=e.prototype;return n.appendTo=function(t,e){t.append(it(this.name)),t.append("("),Ve(t,this.values,",",e),t.append(")")},n.visit=function(t){return t.visitFunc(this)},e}(Pe),We=function(t){function e(e){var n;return(n=t.call(this)||this).expr=e,n}I(e,t);var n=e.prototype;return n.toExpr=function(){return this.expr},n.appendTo=function(t,e){t.append("-epubx-expr("),this.expr.appendTo(t,0),t.append(")")},n.visit=function(t){return t.visitExpr(this)},n.isExpr=function(){return!0},e}(Pe);function Xe(t,e){if(t){if(t.isNumeric()){var n=t;return e.queryUnitSize(n.unit,!1)*n.num}if(t.isNum())return t.num}return 0}function je(t,e){return new De(Xe(t,e),"px")}var Ye={absolute:Fe("absolute"),all:Fe("all"),always:Fe("always"),auto:Fe("auto"),avoid:Fe("avoid"),balance:Fe("balance"),balance_all:Fe("balance-all"),block:Fe("block"),block_end:Fe("block-end"),block_start:Fe("block-start"),both:Fe("both"),bottom:Fe("bottom"),border_box:Fe("border-box"),break_all:Fe("break-all"),break_word:Fe("break-word"),crop:Fe("crop"),cross:Fe("cross"),column:Fe("column"),exclusive:Fe("exclusive"),_false:Fe("false"),fixed:Fe("fixed"),flex:Fe("flex"),footnote:Fe("footnote"),footer:Fe("footer"),header:Fe("header"),hidden:Fe("hidden"),horizontal_tb:Fe("horizontal-tb"),inherit:Fe("inherit"),inline:Fe("inline"),inline_block:Fe("inline-block"),inline_end:Fe("inline-end"),inline_start:Fe("inline-start"),landscape:Fe("landscape"),left:Fe("left"),line:Fe("line"),list_item:Fe("list-item"),ltr:Fe("ltr"),manual:Fe("manual"),none:Fe("none"),normal:Fe("normal"),oeb_page_foot:Fe("oeb-page-foot"),oeb_page_head:Fe("oeb-page-head"),page:Fe("page"),relative:Fe("relative"),right:Fe("right"),same:Fe("same"),scale:Fe("scale"),snap_block:Fe("snap-block"),spread:Fe("spread"),_static:Fe("static"),rtl:Fe("rtl"),table:Fe("table"),table_caption:Fe("table-caption"),table_cell:Fe("table-cell"),table_footer_group:Fe("table-footer-group"),table_header_group:Fe("table-header-group"),table_row:Fe("table-row"),top:Fe("top"),transparent:Fe("transparent"),vertical_lr:Fe("vertical-lr"),vertical_rl:Fe("vertical-rl"),visible:Fe("visible"),_true:Fe("true")},Ke=new De(100,"%"),qe=new De(100,"pvw"),Qe=new De(100,"pvh"),Ze=new De(0,"px"),$e={"font-size":1,color:2};function Je(t,e){return($e[t]||Number.MAX_VALUE)-($e[e]||Number.MAX_VALUE)}var tn=function(t,e,n,i){this.x1=t,this.y1=e,this.x2=n,this.y2=i},en=function(t,e){this.x=t,this.y=e},nn=function(t,e,n,i){this.left=t,this.top=e,this.right=n,this.bottom=i},rn=function(t,e,n,i){this.low=t,this.high=e,this.winding=n,this.shapeId=i},on=function(t,e,n,i){this.y1=t,this.y2=e,this.x1=n,this.x2=i,this.left=null,this.right=null};function an(t,e){return t.low.y-e.low.y||t.low.x-e.low.x}var sn=function(){function t(t){this.points=t}var e=t.prototype;return e.addSegments=function(t,e){for(var n=this.points,i=n.length,r=n[i-1],o=0;o<i;o++){var a,s=n[o];a=r.y<s.y?new rn(r,s,1,e):new rn(s,r,-1,e),t.push(a),r=s}},e.withOffset=function(e,n){for(var i,r=[],o=D(this.points);!(i=o()).done;){var a=i.value;r.push(new en(a.x+e,a.y+n))}return new t(r)},t}();function ln(t,e,n,i){for(var r=[],o=0;o<20;o++){var a=2*o*Math.PI/20;r.push(new en(t+n*Math.sin(a),e+i*Math.cos(a)))}return new sn(r)}function un(t,e,n,i){return new sn([new en(t,e),new en(n,e),new en(n,i),new en(t,i)])}var hn=function(t,e,n,i){this.x=t,this.winding=e,this.shapeId=n,this.lowOrHigh=i};function cn(t,e){var n=t.low.x+(t.high.x-t.low.x)*(e-t.low.y)/(t.high.y-t.low.y);if(isNaN(n))throw new Error("Bad intersection");return n}function fn(t,e,n,i){var r,o,a,s;e.high.y<n&&c.warn("Error: inconsistent segment (1)"),e.low.y<=n?(r=cn(e,n),o=e.winding):(r=e.low.x,o=0),e.high.y>=i?(a=cn(e,i),s=e.winding):(a=e.high.x,s=0),r<a?(t.push(new hn(r,o,e.shapeId,-1)),t.push(new hn(a,s,e.shapeId,1))):(t.push(new hn(a,s,e.shapeId,-1)),t.push(new hn(r,o,e.shapeId,1)))}function dn(t,e,n){var i,r=e+n,o=Array(r),a=Array(r);for(i=0;i<=r;i++)o[i]=0,a[i]=0;for(var s=[],l=!1,u=t.length,h=0;h<u;h++){var c=t[h];o[c.shapeId]+=c.winding,a[c.shapeId]+=c.lowOrHigh;var f=!1;for(i=0;i<e;i++)if(o[i]&&!a[i]){f=!0;break}if(f)for(i=e;i<=r;i++)if(o[i]||a[i]){f=!1;break}l!=f&&(s.push(c.x),l=f)}return s}function pn(t,e){return e?Math.floor(t/e)*e:t}function gn(t){return new tn(t.y1,-t.x2,t.y2,-t.x1)}function mn(t){return new tn(-t.y2,t.x1,-t.y1,t.x2)}function vn(t){return new sn(t.points.map(function(t){return function(t){return new en(t.y,-t.x)}(t)}))}function En(t,e){for(var n=e.length-1,i=new on(t.y2,t.y2,t.x1,t.x2);n>=0;){var r=i;((i=e[n]).y2-i.y1<1||i.x1==r.x1&&i.x2==r.x2)&&(r.y1=i.y1,e.splice(n,1),i=r),n--}}function yn(t,e){for(var n=0,i=t.length;n<i;){var r=Math.floor((n+i)/2);e>=t[r].y2?n=r+1:i=r}return n}function wn(t,e){if(!t.length)return e;var n,i,r=e.y1;for(i=0;i<t.length&&!((n=t[i]).y2>e.y1&&n.x1-.1<=e.x1&&n.x2+.1>=e.x2);i++)r=Math.max(r,n.y2);for(var o=r;i<t.length&&!((n=t[i]).y1>=e.y2||n.x1-.1>e.x1||n.x2+.1<e.x2);i++)o=n.y2;return(o=i===t.length?e.y2:Math.min(o,e.y2))<=r?null:new tn(e.x1,r,e.x2,o)}function Nn(t,e){if(!t.length)return e;var n,i,r=e.y2;for(i=t.length-1;i>=0&&(n=t[i],!(i===t.length-1&&n.y2<e.y2))&&!(n.y1<e.y2&&n.x1-.1<=e.x1&&n.x2+.1>=e.x2);i--)r=Math.min(r,n.y1);for(var o=Math.min(r,n.y2);i>=0&&!((n=t[i]).y2<=e.y1||n.x1-.1>e.x1||n.x2+.1<e.x2);i--)o=n.y1;return r<=(o=Math.max(o,e.y1))?null:new tn(e.x1,o,e.x2,r)}var bn=function(t){function e(){var e;return(e=t.call(this)||this).propSet={},e}I(e,t);var n=e.prototype;return n.visitIdent=function(t){return this.propSet[t.name]=!0,t},n.visitSpaceList=function(t){return this.visitValues(t.values),t},e}(xe),Sn=function(t){function e(e){var n;return(n=t.call(this)||this).value=e,n}return I(e,t),e.prototype.visitInt=function(t){return this.value=t.num,t},e}(xe);function Cn(t,e){if(t){var n=new Sn(e);try{return t.visit(n),n.value}catch(t){c.warn(t,"toInt: ")}}return e}var Tn=function(t){function e(){var e;return(e=t.call(this)||this).collect=!1,e.coords=[],e.name=null,e}I(e,t);var n=e.prototype;return n.visitNumeric=function(t){return this.collect&&this.coords.push(t),null},n.visitNum=function(t){return this.collect&&0==t.num&&this.coords.push(new De(0,"px")),null},n.visitSpaceList=function(t){return this.visitValues(t.values),null},n.visitFunc=function(t){return this.collect||(this.collect=!0,this.visitValues(t.values),this.collect=!1,this.name=t.name.toLowerCase()),null},n.getShape=function(t,e,n,i,r){var o=this;if(this.coords.length>0){var a=[];switch(this.coords.forEach(function(t,e){if("%"==t.unit){var s=e%2==0?n:i;3==e&&"circle"==o.name&&(s=Math.sqrt((n*n+i*i)/2)),a.push(t.num*s/100)}else a.push(t.num*r.queryUnitSize(t.unit,!1))}),this.name){case"polygon":if(a.length%2==0){for(var s=[],l=0;l<a.length;l+=2)s.push(new en(t+a[l],e+a[l+1]));return new sn(s)}break;case"rectangle":if(4==a.length)return un(t+a[0],e+a[1],t+a[0]+a[2],e+a[1]+a[3]);break;case"ellipse":if(4==a.length)return ln(t+a[0],e+a[1],a[2],a[3]);break;case"circle":if(3==a.length)return ln(t+a[0],e+a[1],a[2],a[2])}}return null},e}(xe);function xn(t,e,n,i,r,o){if(t){var a=new Tn;try{return t.visit(a),a.getShape(e,n,i,r,o)}catch(t){c.warn(t,"toShape:")}}return un(e,n,e+i,n+r)}var In=function(t){function e(e){var n;return(n=t.call(this)||this).reset=e,n.counters={},n.name=null,n}I(e,t);var n=e.prototype;return n.visitIdent=function(t){return this.name=t.toString(),this.counters[this.name]=this.reset?0:(this.counters[this.name]||0)+1,t},n.visitInt=function(t){return this.name&&(this.counters[this.name]+=t.num-(this.reset?0:1)),t},n.visitSpaceList=function(t){return this.visitValues(t.values),t},e}(xe);function Pn(t,e){var n=new In(e);try{t.visit(n)}catch(t){c.warn(t,"toCounters:")}return n.counters}var Rn=function(t){function e(e,n){var i;return(i=t.call(this)||this).baseUrl=e,i.transformer=n,i}return I(e,t),e.prototype.visitURL=function(t){return new Ue(this.transformer.transformURL(t.url,this.baseUrl))},e}(Ie);function An(t){var e={};return Object.keys(t).forEach(function(n){e[n]=Array.from(t[n])}),e}var Ln,On=function(){function t(t,e){this.targetId=t,this.resolved=e,this.pageCounters=null,this.spineIndex=-1,this.pageIndex=-1}var e=t.prototype;return e.equals=function(t){return this===t||!!t&&this.targetId===t.targetId&&this.resolved===t.resolved&&this.spineIndex===t.spineIndex&&this.pageIndex===t.pageIndex},e.isResolved=function(){return this.resolved},e.resolve=function(){this.resolved=!0},e.unresolve=function(){this.resolved=!1},t}(),kn=function(){function t(t,e){this.counterStore=t,this.baseURL=e}var e=t.prototype;return e.countersOfId=function(t,e){t=this.counterStore.documentURLTransformer.transformFragment(t,this.baseURL),this.counterStore.countersById[t]=e},e.getExprContentListener=function(){return this.counterStore.getExprContentListener()},t}(),Fn=function(){function t(t,e,n,i){this.counterStore=t,this.baseURL=e,this.rootScope=n,this.pageScope=i,this.styler=null}var e=t.prototype;return e.setStyler=function(t){this.styler=t},e.getFragment=function(t){var e=t.match(/^[^#]*#(.*)$/);return e?e[1]:null},e.getTransformedId=function(t){var e=this.counterStore.documentURLTransformer.transformURL(W(t,this.baseURL),this.baseURL);return"#"===e.charAt(0)&&(e=e.substring(1)),e},e.getPageCounterVal=function(t,e){var n=this,i=new ge(this.pageScope,function(){return e(function(){var e=n.counterStore.currentPageCounters[t];return e&&e.length?e[e.length-1]:null}())},"page-counter-"+t);return this.counterStore.registerPageCounterExpr(t,function(t){return e(t[0])},i),i},e.getPageCountersVal=function(t,e){var n=this,i=new ge(this.pageScope,function(){return e(n.counterStore.currentPageCounters[t]||[])},"page-counters-"+t);return this.counterStore.registerPageCounterExpr(t,e,i),i},e.getTargetCounters=function(t,e,n){var i=this.counterStore.countersById[e];return!i&&n&&t&&(this.styler.styleUntilIdIsReached(t),i=this.counterStore.countersByI