/*! nehan.js Copyright (C) 2010 - 2018 Watanabe Masaki repository: https://github.com/tategakibunko/nehan.js url: http://tb.antiscroll.com/ licensed under MIT license. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ var Nehan=Nehan||{};Nehan.version="5.5.10",Nehan.Config={defaultLang:"",defaultRoot:"document",kerning:!0,maxRollbackCount:5,maxYieldCount:2e4,maxPageCount:5e3,useVerticalGlyphIfEnable:!0,enableAutoCloseTag:!0,allowedInlineStyleProps:[],disabledMarkups:["script","noscript","style","iframe","form","input","select","button","textarea","canvas"],preloadMarkups:["img","math"],managedCssProps:["border-color","border-radius","border-style","border-width","box-sizing","break-after","break-before","clear","color","display","extent","embeddable","float","flow","font-family","font-size","font-style","font-weight","height","interactive","letter-spacing","line-height","list-style-type","list-style-position","list-style-image","margin","measure","meta","padding","position","section","section-root","text-align","text-emphasis-style","text-emphasis-position","text-emphasis-color","text-orientation","text-combine-upright","width","word-break","white-space"],callbackCssProps:["onload","oncreate","onblock","online","ontext"],tabCount:4,minTableCellSize:48,defaultRtRate:.5,defaultEmphaTextRate:.5,defaultListSpacingRate:.3,boxFlowSet:{vert:"tb-rl",hori:"lr-tb"},defaultBoxFlow:"lr-tb",defaultLineHeight:2,maxFontSize:90,defaultFontSize:16,defaultFontColor:"000000",defaultFontSize:16,defaultFontFamily:"'ヒラギノ明朝 Pro W3','Hiragino Mincho Pro','HiraMinProN-W3','Meiryo','メイリオ','IPA明朝','IPA Mincho','MS 明朝','MS Mincho', monospace",headerFontSizes:{h1:"2rem",h2:"1.714rem",h3:"1.28rem",h4:"1.071rem",h5:"1rem",h6:"1rem"},headerLineHeight:1.4,defaultSingleTagNames:["area","base","br","embed","col","hr","img","input","keygen","link","meta","param","source","wbr","?xml","!doctype","end-page","page-break"],fontImgRoot:"https://raw.githubusercontent.com/tategakibunko/nehan.js/master/char-img",absFontSizes:{"xx-large":"33px","x-large":"24px",large:"18px",medium:"16px",small:"13px","x-small":"10px","xx-small":"8px",larger:"1.2em",smaller:"0.8em"},spacingSizeRate:{space:.25,thinsp:.2,nbsp:.38,ensp:.5,emsp:1},mathjax:{maxRetryCount:3,retryWait:300},rexWord:/^[\u0021-\u0025\u0027-\u003A\u003C-\u007E\u00C0-\u02A8\u2000-\u206F\uFB00-\uFB06]+/,formatTagContent:function(t,e){return t.isTextVertical()?e.replace(/\u2019/g,"'").replace(/\uFF62/g,"「").replace(/\uFF63/g,"」").replace(/\uFF0C/g,"、").replace(/\uFF64/g,"、").replace(/\uFF61/g,"。"):e}},Nehan.Display={getVertBlockDir:function(){return Nehan.Config.boxFlowSet.vert.split("-")[1]},getStdFont:function(){return new Nehan.Font({size:Nehan.Config.defaultFontSize,family:Nehan.Config.defaultFontFamily,lineHeight:Nehan.Config.defaultLineHeight,weight:"normal",style:"normal"})},getStdBoxFlow:function(){return Nehan.BoxFlows.getByName(Nehan.Config.defaultBoxFlow)},getStdVertFlow:function(){return Nehan.BoxFlows.getByName(Nehan.Config.boxFlowSet.vert)},getStdHoriFlow:function(){return Nehan.BoxFlows.getByName(Nehan.Config.boxFlowSet.hori)},getRtFontSize:function(t){return Math.round(Nehan.Config.defaultRtRate*t)}},Nehan.Client=function(){function t(){this.platform=navigator.platform.toLowerCase(),this.userAgent=navigator.userAgent.toLowerCase(),this.appName=navigator.appName.toLowerCase(),this.appVersion=parseInt(navigator.appVersion,10),this.name=this._parseBrowserName(this.userAgent,this.appName),this.version=this._parseBrowserVersion(this.userAgent,this.appVersion)}return t.prototype.isWindows=function(){return this.userAgent.indexOf("windows")>=0},t.prototype.isMacintosh=function(){return this.userAgent.indexOf("macintosh")>=0},t.prototype.isChromeOS=function(){return this.userAgent.indexOf("cros")>=0},t.prototype.isIphone=function(){return this.userAgent.indexOf("iphone")>=0&&this.platform.indexOf("nintendo")<0},t.prototype.isIpod=function(){return this.userAgent.indexOf("ipod")>=0},t.prototype.isIpad=function(){return this.userAgent.indexOf("ipad")>=0},t.prototype.isNintendoBrowser=function(){return this.platform.indexOf("nintendo")>=0},t.prototype.isAppleMobileFamily=function(){return this.isIphone()||this.isIpod()||this.isIpad()},t.prototype.isAndroid=function(){return this.userAgent.indexOf("android")>=0},t.prototype.isSmartPhone=function(){return this.isAppleMobileFamily()||this.isAndroid()},t.prototype.isWebkit=function(){return this.userAgent.indexOf("webkit")>=0},t.prototype.isIE=function(){return"msie"===this.name},t.prototype.isTrident=function(){return this.isIE()&&this.version>=11},t.prototype.isChrome=function(){return"chrome"===this.name},t.prototype.isSafari=function(){return"safari"===this.name},t.prototype.isFirefox=function(){return"firefox"===this.name},t.prototype.isTrident=function(){return this.userAgent.indexOf("trident")>=0&&this.userAgent.indexOf("msie")<0},t.prototype.isEdge=function(){return this.userAgent.indexOf("edge")>=0},t.prototype._parseBrowserName=function(t,e){return this.isTrident()||this.isEdge()?"msie":t.indexOf("crios")>=0?"chrome":this.isAppleMobileFamily()&&t.indexOf("safari")>=0?"safari":t.match(/(opera|chrome|safari|firefox|msie)/)?RegExp.$1.toLowerCase():e},t.prototype._parseBrowserVersion=function(t,e){return this.isTrident()?this._parseVersionTrident(t):this.isAppleMobileFamily()&&"chrome"!==this.name?this._parseVersionAppleMobileFamily(t):t.match(/(opera|chrome|safari|firefox|msie|crios)\/?\s*(\.?\d+(?:\.\d+)*)/)?this._parseVersionNormalClient(t,parseInt(RegExp.$2,10)):e},t.prototype._parseVersionTrident=function(t){return t.match(/rv:([\.\d]+)/)?parseInt(RegExp.$1,10):this.version},t.prototype._parseVersionNormalClient=function(t,e){return this.isAndroid()?e:t.match(/version\/([\.\d]+)/)?parseInt(RegExp.$1,10):e},t.prototype._parseVersionAppleMobileFamily=function(t){return t.match(/os ([\d_]+) like/)?parseInt(RegExp.$1,10):this.version},t}(),Nehan.Env=function(){var t=new Nehan.Client,e=t.version,n=!(t.isIE()&&e<=8),r=t.isIE()&&e>=10,i=t.isChrome()&&e>=24&&!t.isNintendoBrowser(),o=t.isSafari()&&e>=5||t.isAppleMobileFamily(),s=t.isFirefox()&&e>=41;return{client:t,isTransformEnable:n,isVerticalGlyphEnable:i||o||r||s,isTextCombineEnable:t.isChrome()&&e>=47||t.isFirefox()&&e>=48||t.isIE()&&e>=11||t.isSafari()&&e>=9}}(),Nehan.Class={},Nehan.Class.extend=function(t,e){function n(){}n.prototype=e.prototype,t.superClass_=e.prototype,t.prototype=new n,t.prototype.constructor=t},Nehan.List={iter:function(t,e){for(var n=0,r=t.length;n=0&&!1!==e(t[n],n);n--);},forall:function(t,e){for(var n=0,r=t.length;n=0;n--){var r=t[n];if(e(r,n))return r}return null},indexOf:function(t,e){for(var n=0,r=t.length;nr)&&(n=t,r=o)}),n},last:function(t){var e=t.length;return 0===e?null:t[e-1]},create:function(t,e){for(var n=[],r=0;r0;)n.unshift(r%e),r=Math.floor(r/e);return n},trimHeadCRLF:function(t){return t.replace(/^[\r|\n]+/,"")},trimTailCRLF:function(t){return t.replace(/[\r|\n]+$/,"")},trimCRLF:function(t){return this.trimTailCRLF(this.trimHeadCRLF(t))},trim:function(t){return t.replace(/^\s+/,"").replace(/\s+$/,"")},cutQuote:function(t){return t.replace(/['\"]/g,"")},capitalize:function(t){return""===t?"":t.charAt(0).toUpperCase()+t.slice(1)},filenameConcat:function(t,e){return t=""===t?"":"/"===t.slice(-1)?t:t+"/",e=""===e?"":"/"===e[0]?e.substring(1,e.length):e,t+e},camelToChain:function(t){return t.replace(/([A-Z])/g,function(t,e){return"-"+e.toLowerCase()})},camelize:function(t){return t.indexOf("-")<0?t:t.split("-").map(function(t,e){return 0===e?t:this.capitalize(t)}.bind(this)).join("")},splitBy:function(t,e){return t.indexOf(e)<0?[t]:t.split(e)},splitBySpace:function(t){return t.indexOf(" ")<0?[t]:t.split(/\s+/)},isNumber:function(t){return t===1/0||("number"==typeof t||"string"==typeof t)&&(t==parseFloat(t)&&isFinite(t))},getEmSize:function(t,e){return Math.round(e*t)},getPxFromPt:function(t){return Math.round(4*t/3)},getPercentValue:function(t,e){return Math.round(e*t/100)},replaceFirstLetter:function(t,e){return t.replace(/(^(<[^>]+>|[\s\n])*)(\S)/im,function(t,n,r,i){return n+e(i)})},charCodeOfCharRef:function(t){return 0===t.indexOf("&#x")?parseInt(t.replace("&#x","").replace(";",""),16):parseInt(t.replace("&#","").replace(";",""),10)},isNumCharRef:function(t){return/&#x?[0-9a-f]{4,};/i.test(t)},debugDomSize:function(t,e){console.log("%s offset:(%dx%d), client:(%dx%d), scroll:(%dx%d)",e||"",t.offsetWidth,t.offsetHeight,t.clientWidth,t.clientHeight,t.scrollWidth,t.scrollHeight)},charRefToUni:function(t){return this.isNumCharRef(t)?String.fromCharCode(this.charCodeOfCharRef(t)):t}},Nehan.Const={cssVenderPrefixes:["-moz","-webkit","-o","-ms"],cssPhysicalBoxDirs:["top","right","bottom","left"],cssLogicalBoxDirs:["before","end","after","start"],cssPhysicalBoxCorders:["top-left","top-right","bottom-left","bottom-right"],cssLogicalBoxCorners:["before-start","before-end","after-end","after-start"],css2dIndex:{1:[0,0],2:[0,1]},css4dIndex:{1:[0,0,0,0],2:[0,1,0,1],3:[0,1,2,1],4:[0,1,2,3]},space:" ",clearFix:"
"},Nehan.Css={normalizeKey:function(t){return Nehan.Utils.trim(t).toLowerCase().replace(/\s+/g," ").replace(/\s+,/g,",").replace(/,\s+/g,",").replace(/\s+\(/g,"(").replace(/\(\s+/g,"(")},normalizeValue:function(t){return t.replace(/;/g,"").replace(/^\s+/,"").replace(/\s+$/,"").replace(/\s+/g," ").replace(/\s+,/g,",").replace(/,\s+/g,",").replace(/\s+\//g,"/").replace(/\/\s+/g,"/").replace(/\s+\(/g,"(").replace(/\(\s+/g,"(").replace(/\s+\)/g,")").replace(/\)\s+/g,")")},getImageURL:function(t){return t.replace(/url/gi,"").replace(/'/g,"").replace(/"/g,"").replace(/\(/g,"").replace(/\)/g,"").replace(/\s/g,"")},addNehanPrefix:function(t){return 0===t.indexOf("nehan-")?t:"nehan-"+t},addNehanHeaderPrefix:function(t){return"nehan-header-"+t},addNehanTocLinkPrefix:function(t){return"nehan-toc-link-"+t}},Nehan.Html={escape:function(t){return t.replace(/&/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""")},unescape:function(t){var e=document.createElement("div");return e.innerHTML=t.replace(//g,">").replace(/ /g," ").replace(/\r/g," ").replace(/\n/g," "),e.textContent||e.innerText},attr:function(t){var e=[];for(var n in t)void 0!==t[n]&&""!==t[n]&&e.push(n+"='"+this.escape(t[n]+"")+"'");return e==[]?"":e.join(" ")},tagWrap:function(t,e,n){return[this.tagStart(t,n||{}),e,this.tagEnd(t)].join("")},tagSingle:function(t,e){return"<"+t+" "+this.attr(e)+"/>"},tagStart:function(t,e){return"<"+t+" "+this.attr(e)+">"},tagEnd:function(t){return""},normalize:function(t){return t.replace(/\u0008/g,"").replace(/\u000B/g,"").replace(/\u000C/g,"").replace(/\u200B/g,"").replace(/\u2028/g,"").replace(/\u2029/g,"").replace(/\r/g,"").replace(//g,"").replace(/[^<]*<\/rp>/gi,"").replace(//gi,"").replace(/<\/rb>/gi,"").replace(/<\/rt>/gi,"")}},Nehan.Uri=function(){function t(t){this.address=this._normalize(t||"")}return t.prototype._normalize=function(t){return t.replace(/\s/g,"")},t.prototype.getAddress=function(){return this.address},t.prototype.getAnchorName=function(){var t=this.address.indexOf("#");if(t<0)return"";var e=this.address.substring(t+1);return e.length>0?e:""},t}(),Nehan.TagAttrLexer=function(){function t(t){this.buff=t,this._error=!1}var e=/[^=\s]+/;return t.prototype.isEnd=function(){return this._error||""===this.buff},t.prototype.get=function(){var t=this._peek();if(null===t)return null;switch(t){case"=":return this._step(1),t;case"'":case'"':return this._getLiteral(t);case" ":return this._step(1),this.get();default:return this._getSymbol()}},t.prototype._peek=function(){return this.buff?this.buff.charAt(0):null},t.prototype._step=function(t){this.buff=this.buff.substring(t)},t.prototype._getSymbol=function(){var t=this.buff.match(e),n=t?t[0]:null;return n&&this._step(n.length),n},t.prototype._getLiteral=function(t){var e=this.buff.indexOf(t,1);if(e<0)return console.error("TagAttrLexer::syntax error:literal not closed(%s)",this.buff),this._error=!0,null;var n=this.buff.substring(1,e);return this._step(e+1),n},t}(),Nehan.TagAttrParser={parse:function(t){for(var e=new Nehan.TagAttrLexer(t),n=null,r=null,i={},o=function(t,e){i[t]=String(e)};null!==r||!e.isEnd();)n=e.get(),null===n?r&&(o(r,!0),r=null):"="===n&&r?(o(r,e.get()||!0),r=null):r?(o(r,!0),r=n):n&&"="!==n&&(r=n);return i}},Nehan.TagAttrs=function(){function t(t){var e=t?Nehan.TagAttrParser.parse(t):{};this.classes=this._parseClasses(e),this.attrs=this._parseAttrs(e),this.dataset=this._parseDataset(e)}return t.prototype.hasAttr=function(t){return"class"===t?this.classes.length>0:void 0!==this.attrs[t]},t.prototype.hasClass=function(t){return Nehan.List.exists(this.classes,Nehan.Closure.eq(t))},t.prototype.addClass=function(t){return this.hasClass(t)||(this.classes.push(t),this.setAttr("class",[this.getAttr("class"),t].join(" "))),this.classes},t.prototype.removeClass=function(t){return this.classes=this.classes.filter(function(e){return e!=t}),this.setAttr("class",this.classes.join(" ")),this.classes},t.prototype.getAttr=function(t,e){return"class"===t?this.classes:(e=void 0===e?null:e,void 0===this.attrs[t]?e:this.attrs[t])},t.prototype.getData=function(t,e){return e=void 0===e?null:e,void 0===this.dataset[t]?e:this.dataset[t]},t.prototype.getKey=function(){return Object.keys(this.attrs).sort().map(function(t){return t+"="+this.attrs[t]}.bind(this)).join("&")},t.prototype.setAttr=function(t,e){e="string"==typeof e?e:String(e),0===t.indexOf("data-")?this.dataset[this._parseDatasetName(t)]=e:this.attrs[t]=e},t.prototype.toString=function(){return[this.toAttrString(),this.toDatasetString()].join(" ")},t.prototype.toAttrString=function(){var t=[];for(var e in this.attrs)t.push(e+"='"+this.attrs[e]+"'");return t.join(" ")},t.prototype.toDatasetString=function(){var t=[];for(var e in this.dataset)t.push("data-"+Nehan.Utils.camelToChain(e)+"='"+this.getData(e)+"'");return t.join(" ")},t.prototype._parseClasses=function(t){var e=t.class||"";return e=Nehan.Utils.trim(e.replace(/\s+/g," ")),(""===e?[]:e.split(/\s+/)).map(function(t){return 0===t.indexOf("nehan-")?t.replace("nehan-",""):t})},t.prototype._parseAttrs=function(t){var e={};return Nehan.Obj.iter(t,function(t,n){t.indexOf("data-")<0&&(e[t]=n)}),e},t.prototype._parseDataset=function(t){var e={};for(var n in t)0===n.indexOf("data-")&&(e[this._parseDatasetName(n)]=t[n]);return e},t.prototype._parseDatasetName=function(t){return Nehan.Utils.camelize(t.slice(5))},t}(),Nehan.Tag=function(){function t(t,e,n){this.src=t,this.content=e||"",this.name=this._parseName(this.src),this.attrs=this._parseTagAttrs(this.name,this.src),this._key=this._createKey(),Nehan.Obj.merge(this,{firstChild:!1,firstOfType:!1,lastChild:!1,lastOfType:!1,onlyChild:!1,onlyOfType:!1},n||{})}return t.prototype.clone=function(){return new t(this.src,this.content)},t.prototype.setContent=function(t){return this._fixed?this:(this.content=t,this)},t.prototype.setContentImmutable=function(t){return this._fixed=t,this},t.prototype.setAlias=function(t){return this.alias=t,this},t.prototype.setAttr=function(t,e){return this.attrs.setAttr(t,e),this},t.prototype.setAttrs=function(t){for(var e in t)this.setAttr(e,t[e]);return this},t.prototype.setFirstChild=function(t){return this.firstChild=t,this},t.prototype.setOnlyChild=function(t){return this.onlyChild=t,this},t.prototype.setOnlyOfType=function(t){return this.onlyOfType=t,this},t.prototype.setFirstOfType=function(t){return this.firstOfType=t,this},t.prototype.setLastChild=function(t){return this.lastChild=t,this},t.prototype.setLastOfType=function(t){return this.lastOfType=t,this},t.prototype.addClass=function(t){return this.attrs.addClass(t),this},t.prototype.removeClass=function(t){return this.attrs.removeClass(t),this},t.prototype.getId=function(){return this.attrs.getAttr("id")},t.prototype.getClasses=function(){return this.attrs.classes},t.prototype.getName=function(){return this.alias||this.name},t.prototype.getPseudoElementName=function(){var t=this.getName();return t.indexOf("::")<0?"":t.replace("::","")},t.prototype.getPath=function(){var t=this.getName(),e=this.getId();e&&(t+="#"+e);var n=this.getClasses();return n.length>0&&(t+="."+n.join(".")),t},t.prototype.getAttr=function(t,e){return this.attrs.getAttr(t,e)},t.prototype.getData=function(t,e){return this.attrs.getData(t,e)},t.prototype.getContent=function(){return this.content},t.prototype.getSrc=function(){return this.src},t.prototype.getWrapSrc=function(){return""===this.content?this.src:this.src+this.content+""},t.prototype.getKey=function(){return this._key},t.prototype.hasClass=function(t){return this.attrs.hasClass(t)},t.prototype.hasAttr=function(t){return this.attrs.hasAttr(t)},t.prototype.isHeaderTag=function(){return Nehan.List.exists(["h1","h2","h3","h4","h5","h6"],Nehan.Closure.eq(this.name))},t.prototype.isAnchorTag=function(){return"a"===this.name&&null!==this.getAttr("name")},t.prototype.isAnchorLinkTag=function(){var t=this.getAttr("href");return"a"===this.name&&t&&t.indexOf("#")>=0},t.prototype.isPageBreakTag=function(){return"page-break"===this.name},t.prototype.isCloseTag=function(){return"/"===this.name.charAt(0)},t.prototype.isSingleTag=function(){return this._single||!1},t.prototype.isEmpty=function(){return""===this.content},t.prototype.isFirstChild=function(){return this.firstChild},t.prototype.isOnlyChild=function(){return this.onlyChild},t.prototype.isOnlyOfType=function(){return this.onlyOfType},t.prototype.isFirstOfType=function(){return this.firstOfType},t.prototype.isLastChild=function(){return this.lastChild},t.prototype.isLastOfType=function(){return this.lastOfType},t.prototype.toString=function(){return("<"+this.getName()+" "+this.attrs.toString()+">").replace(/\s+/g," ").replace(/\s>$/,">").replace(/\s\/>$/,"/>")},t.prototype._getTagAttrSrc=function(t){return t.replace(/<[\S]+/,"").replace(/^\s+/,"").replace("/>","").replace(">","").replace(/\s+$/,"").replace(/\n/g," ").replace(/[ |\s]+/g," ").replace(/\s+=/g,"=").replace(/=\s+/g,"=")},t.prototype._createKey=function(){return this.getName()+"["+this.attrs.getKey()+"]"},t.prototype._parseName=function(t){return t.replace(//g,"").split(/\s/)[0].toLowerCase()},t.prototype._parseTagAttrs=function(t,e){var n=this._getTagAttrSrc(e);return t.length===n.length?new Nehan.TagAttrs(""):new Nehan.TagAttrs(n)},t}(),Nehan.Closure={id:function(t){return t},eq:function(t){return function(e){return t===e}},neq:function(t){return function(e){return t!==e}},isTagName:function(t){return function(e){if(e instanceof Nehan.Tag==!1)return!1;var n=e.getName();return Nehan.List.exists(t,function(t){return t===n})}},animationFrame:function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(t,e){var n=void 0===e?1e3/60:e;window.setTimeout(t,n)}}},Nehan.Set=function(){function t(){this.values=[]}return t.prototype.iter=function(t){this.values.forEach(t)},t.prototype.length=function(){return this.values.length},t.prototype.isEmpty=function(t){return 0===this.length()},t.prototype.exists=function(t){return Nehan.List.exists(this.values,Nehan.Closure.eq(t))},t.prototype.remove=function(t){var e=Nehan.List.indexOf(this.values,Nehan.Closure.eq(t));return e>=0&&this.values.splice(e,1),this},t.prototype.add=function(t){return this.exists(t)||this.values.push(t),this},t.prototype.addValues=function(t){return t.forEach(function(t){this.add(t)}.bind(this)),this},t.prototype.union=function(e){var n=this.values.concat();e.iter(function(t){this.exists(t)||n.push(t)}.bind(this));var r=new t;return r.values=n,r},t.prototype.getValues=function(){return this.values},t}(),Nehan.LowerNameSet=function(){function t(){Nehan.Set.call(this)}return Nehan.Class.extend(t,Nehan.Set),t.prototype.add=function(t){return Nehan.Set.prototype.add.call(this,t.toLowerCase())},t}(),Nehan.HashSet=function(){function t(t){this._values=Nehan.Obj.clone(t||{})}return t.prototype.iter=function(t){Nehan.Obj.iter(this._values,t)},t.prototype.merge=function(t,e){return e},t.prototype.union=function(t){return t.iter(function(t,e){this.add(t,e)}.bind(this)),this},t.prototype.get=function(t){return this._values[t]||null},t.prototype.getValues=function(){return this._values},t.prototype.add=function(t,e){var n=this._values[t]||null,r=n?this.merge(n,e):e;return this._values[t]=r,this},t.prototype.addValues=function(t){for(var e in t)this.add(e,t[e]);return this},t.prototype.remove=function(t){return this._values[t]=null,delete this._values[t],this},t}(),Nehan.CssHashSet=function(){function t(t){Nehan.HashSet.call(this,t)}return Nehan.Class.extend(t,Nehan.HashSet),t.prototype.add=function(t,e){Nehan.HashSet.prototype.add.call(this,t,e)},t.prototype.merge=function(t,e){return"object"==typeof t&&"object"==typeof e?Nehan.Obj.copy(t,e):e},t}(),Nehan.CssEdgeParser=function(){var t=function(t){switch(t.length){case 0:return{};case 1:return{before:t[0],end:t[0],after:t[0],start:t[0]};case 2:return{before:t[0],end:t[1],after:t[0],start:t[1]};case 3:return{before:t[0],end:t[1],after:t[2],start:t[1]};default:return{before:t[0],end:t[1],after:t[2],start:t[3]}}},e=function(t){if("number"==typeof t)return String(t);if("string"==typeof t)return t;if("function"==typeof t)return t;throw console.error("invalid edge value unit:%o",t),"invalid edge format"},n=function(e){if(e instanceof Array)return t(e);if("object"==typeof e)return e;if("function"==typeof e)return e;if("number"==typeof e)return n(e.toString());if("string"==typeof e)return""===e||" "===e?{}:t(Nehan.Utils.splitBySpace(e));throw console.error("invalid edge value shorthand:%o",e),"invalid edge format"};return{formatValue:function(t,r){return t.hasAttr()?Nehan.Obj.createOne(t.getAttr(),e(r)):n(r)}}}(),Nehan.CssBorderRadiusParser=function(){var t=function(t,e){return e.map(function(e){return t[e]})},e=function(e){var n=Nehan.Const.css2dIndex[Math.min(e.length,2)]||[];return t(e,n)},n=function(e){var n=Nehan.Const.css4dIndex[Math.min(e.length,4)]||[];return t(e,n)},r=function(t){return Nehan.List.zipObject(Nehan.Const.cssLogicalBoxCorners,t)},i=function(t){if(""===t)return{};var i=Nehan.Utils.splitBy(t,"/"),o=e(i),s=o.map(function(t){var e=Nehan.Utils.splitBySpace(t);return n(e)}),a=Nehan.List.zipArray(s[0],s[1]);return r(a)},o=function(t){if(0===t.length)return{};if(t[0]instanceof Array){var i=e(t.map(n));return r(Nehan.List.zipArray(i[0],i[1]))}return r(n(t.map(e)))},s=function(t){return e(Nehan.Utils.splitBy(t,"/"))},a=function(t){return t instanceof Array?o(t):"object"==typeof t?t:"string"==typeof t?i(t):(console.error("invalid border-radius:%o",t),{})};return{formatValue:function(t,e){return t.hasAttr()?Nehan.Obj.createOne(t.getAttr(),s(e)):a(e)}}}(),Nehan.CssFontParser=function(){var t=function(t){var e={},n=Nehan.Utils.splitBy(t,"/");switch(n.length){case 1:e.size=n[0];break;case 2:e.size=n[0],e["line-height"]=n[1]}return e},e=function(e){var n={};return Nehan.Utils.splitBySpace(e).forEach(function(e,r){if(e.indexOf("/")>=0)return void Nehan.Obj.copy(n,t(e));switch(e){case"normal":case"inherit":case"initial":break;case"italic":case"oblique":n.style=e;break;case"small-caps":n.variant=e;break;case"bold":case"bolder":case"lighter":n.weight=e;break;case"caption":case"icon":case"menu":case"message-box":case"small-caption":case"status-bar":break;default:!n.size&&(e.indexOf("px")>=0||e.indexOf("pt")>=0||e.indexOf("em")>=0||e.indexOf("%")>=0)?n.size=e:Nehan.Utils.isNumber(e)?n.weight=e:n.family=e}}),n},n=function(t){return t},r=function(t){if("object"==typeof t||"function"==typeof t)return t;if("string"==typeof t)return e(t);throw console.error("invalid font value:%o",t),"invalid font value"};return{formatValue:function(t,e){return t.hasAttr()?Nehan.Obj.createOne(t.getAttr(),n(e)):r(e)}}}(),Nehan.CssTextEmphaParser=function(){var t=function(t){if("none"===t)return{};var e={},n=[];return Nehan.Utils.splitBySpace(t).forEach(function(t){switch(t){case"filled":case"open":n.unshift(t);break;case"dot":case"circle":case"double-circle":case"triangle":case"sesame":n.push(t);break;default:/'.*'/.test(t)?n=[t]:e.color=t}}),e.style=n.join(" "),e},e=function(t){var e=Nehan.Utils.splitBySpace(t);switch(e.length){case 0:return{hori:"over",vert:"right"};case 1:return{hori:e[0],vert:"right"};default:return{hori:e[0],vert:e[1]}}},n=function(t,n){switch(t.getAttr()){case"position":return e(n);default:return n}},r=function(e){if("object"==typeof e)return e;if("string"==typeof e)return t(e);throw console.error("invalid format(text-emphasis):",e),"invalid format(text-emphasis)"};return{formatValue:function(t,e){return t.hasAttr()?Nehan.Obj.createOne(t.getAttr(),n(t,e)):r(e)}}}(),Nehan.CssListStyleParser=function(){var t=function(t){t=Nehan.Utils.trim(t).replace(/\s+/g," ").replace(/;/g,"");var e={},n=Nehan.Utils.splitBySpace(t),r=n.length;return r>=1&&(e.type=n[0]),r>=2&&(e.image=n[1]),r>=3&&(e.position=n[2]),e},e=function(t){return t},n=function(e){if("object"==typeof e||"function"==typeof e)return e;if("string"==typeof e)return t(e);throw console.error("invalid list-style value:%o",e),"invalid list-style value"};return{formatValue:function(t,r){return t.hasAttr()?Nehan.Obj.createOne(t.getAttr(),e(r)):n(r)}}}(),Nehan.CssProp=function(){function t(t){var n=Nehan.Utils.camelToChain(t),r=e[n];this.name=r?r.name:n,this.attr=r?r.attr:null}var e={"margin-before":{name:"margin",attr:"before"},"margin-end":{name:"margin",attr:"end"},"margin-after":{name:"margin",attr:"after"},"margin-start":{name:"margin",attr:"start"},"padding-before":{name:"padding",attr:"before"},"padding-end":{name:"padding",attr:"end"},"padding-after":{name:"padding",attr:"after"},"padding-start":{name:"padding",attr:"start"},"border-width-before":{name:"border-width",attr:"before"},"border-width-end":{name:"border-width",attr:"end"},"border-width-after":{name:"border-width",attr:"after"},"border-width-start":{name:"border-width",attr:"start"},"border-style-before":{name:"border-style",attr:"before"},"border-style-end":{name:"border-style",attr:"end"},"border-style-after":{name:"border-style",attr:"after"},"border-style-start":{name:"border-style",attr:"start"},"border-color-before":{name:"border-color",attr:"before"},"border-color-end":{name:"border-color",attr:"end"},"border-color-after":{name:"border-color",attr:"after"},"border-color-start":{name:"border-color",attr:"start"},"border-before-start-radius":{name:"border-radius",attr:"before-start"},"border-before-end-radius":{name:"border-radius",attr:"before-end"},"border-after-end-radius":{name:"border-radius",attr:"after-end"},"border-after-start-radius":{name:"border-radius",attr:"after-start"},"list-style-position":{name:"list-style",attr:"position"},"list-style-type":{name:"list-style",attr:"type"},"list-style-image":{name:"list-style",attr:"image"},"text-emphasis-position":{name:"text-emphasis",attr:"position"},"text-emphasis-style":{name:"text-emphasis",attr:"style"},"text-emphasis-color":{name:"text-emphasis",attr:"color"},"font-size":{name:"font",attr:"size"},"font-family":{name:"font",attr:"family"},"font-style":{name:"font",attr:"style"},"font-weight":{name:"font",attr:"weight"},"font-variant":{name:"font",attr:"variant"}};return t.prototype.getName=function(){return this.name},t.prototype.getAttr=function(){return this.attr},t.prototype.hasAttr=function(){return null!==this.attr},t}(),Nehan.CssEntry=function(){function t(t,e){this.prop=t,this.value=e}return t.prototype.getPropName=function(){return this.prop.getName()},t.prototype.getPropAttr=function(){return this.prop.getAttr()},t.prototype.getValue=function(){return this.value},t}(),Nehan.CssParser=function(){var t=function(e){return e instanceof Array?e.map(t):"function"==typeof e||"object"==typeof e?e:"number"==typeof e?e.toString():Nehan.Css.normalizeValue(e)},e=function(e,n){var r=t(n);switch(e.getName()){case"margin":case"padding":case"border-width":case"border-style":case"border-color":return Nehan.CssEdgeParser.formatValue(e,r);case"border-radius":return Nehan.CssBorderRadiusParser.formatValue(e,r);case"list-style":return Nehan.CssListStyleParser.formatValue(e,r);case"font":return Nehan.CssFontParser.formatValue(e,r);case"text-emphasis":return Nehan.CssTextEmphaParser.formatValue(e,r);default:return r}};return{formatEntry:function(t,n){var r=new Nehan.CssProp(t),i=e(r,n);return new Nehan.CssEntry(r,i)}}}(),Nehan.AttrSelector=function(){function t(t){this.expr=this._normalize(t),this.left=this.op=this.right=null,this._parseExpr(this.expr)}var e=/[^=^~|$*\s]+/,n=["|=","~=","^=","$=","*=","="];return t.prototype.test=function(t){return this.op&&this.left&&this.right?this._testOp(t):!!this.left&&this._testHasAttr(t)},t.prototype._normalize=function(t){return t.replace(/\[/g,"").replace(/\]/g,"")},t.prototype._parseSymbol=function(t){var n=t.match(e);return n?n[0]:""},t.prototype._parseOp=function(t){return Nehan.List.find(n,function(e){return t.indexOf(e)>=0})},t.prototype._parseExpr=function(t){this.left=this._parseSymbol(t),this.left&&(t=Nehan.Utils.trim(t.slice(this.left.length))),this.op=this._parseOp(t),this.op&&(t=Nehan.Utils.trim(t.slice(this.op.length)),this.right=Nehan.Utils.cutQuote(Nehan.Utils.trim(t)))},t.prototype._testHasAttr=function(t){return null!==t.getMarkupAttr(this.left)},t.prototype._testEqual=function(t){return t.getMarkupAttr(this.left)===this.right},t.prototype._testCaretEqual=function(t){var e=t.getMarkupAttr(this.left);return new RegExp("^"+this.right).test(e)},t.prototype._testDollarEqual=function(t){var e=t.getMarkupAttr(this.left);return new RegExp(this.right+"$").test(e)},t.prototype._testTildeEqual=function(t){var e=t.getMarkupAttr(this.left),n=e?e.split(/\s+/):[] ;return Nehan.List.exists(n,Nehan.Closure.eq(this.right))},t.prototype._testPipeEqual=function(t){var e=t.getMarkupAttr(this.left);return!!e&&(e==this.right||e.indexOf(this.right+"-")>=0)},t.prototype._testStarEqual=function(t){return t.getMarkupAttr(this.left).indexOf(this.right)>=0},t.prototype._testOp=function(t){switch(this.op){case"=":return this._testEqual(t);case"^=":return this._testCaretEqual(t);case"$=":return this._testDollarEqual(t);case"|=":return this._testPipeEqual(t);case"~=":return this._testTildeEqual(t);case"*=":return this._testStarEqual(t)}throw"undefined operation:"+this.op},t}(),Nehan.PseudoClassSelector=function(){function t(t,e){this.name=t,this.args=e||[]}return t.prototype.test=function(t){switch(this.name){case":nth-child":if(0===this.args.length)return!1;var e=parseInt(this.args[0].name,10);return t.isNthChild(e);case":first-child":return t.isFirstChild();case":last-child":return t.isLastChild();case":first-of-type":return t.isFirstOfType();case":last-of-type":return t.isLastOfType();case":only-child":return t.isOnlyChild();case":only-of-type":return t.isOnlyOfType();case":empty":return t.isMarkupEmpty();case":root":return t.isRoot();case":not":return t.not(this.args);case":matches":return t.matches(this.args);case":lang":return t.lang(this.args.map(function(t){return t.name}))}return!1},t}(),Nehan.PseudoElementSelector=function(){function t(t){this.name=t}return t.prototype.test=function(t){switch(this.name){case"::before":case"::after":return!0;case"::first-letter":case"::first-line":case"::marker":return!t.isMarkupEmpty()}return!1},t}(),Nehan.CompoundSelector=function(){function t(t){this.name=t.name||null,this.nameRex=t.nameRex||null,this.id=t.id||null,this.classes=t.classes||[],this.attrs=t.attrs||[],this.pseudoClass=t.pseudoClass||null,this.pseudoElement=t.pseudoElement||null,this.classes.sort()}return t.prototype.test=function(t){return null!==t&&(!(this.name&&!this.testName(t.getMarkupName()))&&(!(this.nameRex&&!this.testNameRex(t.getMarkupName()))&&(!(this.classes.length>0&&!this.testClassNames(t.getMarkupClasses()))&&((!this.id||t.getMarkupId()==this.id)&&(!(this.attrs.length>0&&!this._testAttrs(t))&&!(this.pseudoClass&&!this.pseudoClass.test(t)))))))},t.prototype.testName=function(t){return null!==this.name&&("*"===this.name||t===this.name)},t.prototype.testNameRex=function(t){return null!==this.nameRex&&this.nameRex.test(t)},t.prototype.testClassNames=function(t){return this.classes.every(function(e){return Nehan.List.exists(t,Nehan.Closure.eq(e))})},t.prototype.getNameSpec=function(){return this.nameRex?1:null===this.name||"*"===this.name?0:1},t.prototype.getIdSpec=function(){return this.id?1:0},t.prototype.getClassSpec=function(){return this.classes.length},t.prototype.getAttrSpec=function(){return this.attrs.length},t.prototype.getPseudoClassSpec=function(){return this.pseudoClass&&!this.pseudoElement?1:0},t.prototype._testAttrs=function(t){return this.attrs.every(function(e){return e.test(t)})},t}(),Nehan.SelectorLexer=function(){function t(t){this.buff=this._normalize(t)}var e=/^[\w-_\*!\?]+/,n=/^\/[^\/]+\//,r=/^#[\w-_]+/,i=/^\.[\w-_]+/,o=/^\[[^\]]+\]/,s=/^:[\w-_]+/,a=/^::[\w-_]+/,h=/\(.*?\)/;return t.prototype.getTokens=function(){for(var t=[];""!==this.buff;){var e=this._getNextToken();if(null===e)break;t.push(e)}return t},t.prototype._getNextToken=function(){if(this.buff=Nehan.Utils.trim(this.buff),""===this.buff)return null;var t=this.buff.charAt(0);switch(t){case"+":case"~":case">":return this._stepBuff(1),t;default:return this._getCompoundSelector()}throw"invalid selector:["+this.buff+"]"},t.prototype._normalize=function(t){return Nehan.Utils.trim(t).replace(/\s+/g," ")},t.prototype._stepBuff=function(t){this.buff=Nehan.Utils.trim(this.buff.slice(t))},t.prototype._getByRex=function(t){var e=null,n=this.buff.match(t);return n&&(e=n[0],this._stepBuff(e.length)),e},t.prototype._getCompoundSelector=function(){var t=this.buff.length,e=this._getName(),n=null===e?this._getNameRex():null,r=this._getId(),i=this._getClasses(),o=this._getAttrs(),s=this._getPseudoClass(),a=this._getPseudoElement();if(this.buff.length===t)throw"invalid selector:["+this.buff+"]";return new Nehan.CompoundSelector({name:e,nameRex:n,id:r,classes:i,attrs:o,pseudoClass:s,pseudoElement:a})},t.prototype._getName=function(){return this._getByRex(e)},t.prototype._getNameRex=function(){var t=this._getByRex(n);return null===t?null:new RegExp(t.replace(/[\/]/g,""))},t.prototype._getId=function(){var t=this._getByRex(r);return t?t.substring(1):null},t.prototype._getClasses=function(){for(var t=[];;){var e=this._getClass();if(null===e)break;t.push(e)}return t},t.prototype._getClass=function(){var t=this._getByRex(i);return t?t.substring(1):null},t.prototype._getAttrs=function(){for(var t=[];;){var e=this._getByRex(o);if(null===e)break;t.push(new Nehan.AttrSelector(e))}return t},t.prototype._getPseudoClass=function(){var t=this._getByRex(s);if(!t)return null;var e=this._getByRex(h);if(!e)return new Nehan.PseudoClassSelector(t);var n=this._getPseudoArgs(e);return new Nehan.PseudoClassSelector(t,n)},t.prototype._getPseudoElement=function(){var t=this._getByRex(a);return t?new Nehan.PseudoElementSelector(t):null},t.prototype._getPseudoArgs=function(e){return e=e.replace(/\s/g,"").replace("(","").replace(")",""),Nehan.Utils.splitBy(e,",").map(function(e){return new t(e).getTokens()[0]})},t}(),Nehan.SelectorStateMachine=function(){var t=function(t,e){for(var n=t.parent;null!==n;){if(e.test(n))return n;n=n.parent}return null},e=function(t,e){var n=t.parent;return null===n?null:e.test(n)?n:null},n=function(t,e){var n=t.getChildIndex(),r=t.getParentNthChild(n-1)||null;return r&&e.test(r)?r:null},r=function(t,e){for(var n=t.getChildIndex(),r=0;r=0;){if((s=c())instanceof Nehan.CompoundSelector==!1)throw console.error("syntax error:%o",o),"selector syntax error";if(!s.test(i))return!1;if(null===(a=c()))return!0;if(a instanceof Nehan.CompoundSelector)h=a,l=" ";else if("string"==typeof a&&(l=a,null===(h=c())||h instanceof Nehan.CompoundSelector==!1))throw console.error("syntax error:%o",o),"selector syntax error";switch(l){case" ":i=t(i,h);break;case">":i=e(i,h);break;case"+":i=n(i,h);break;case"~":i=r(i,h);break;default:throw"selector syntax error:invalid combinator("+l+")"}if(null===i)return!1;!function(){u++}()}return!0}}}(),Nehan.SelectorValue=function(){function t(t){this.entries=this._initialize(t)}return t.prototype._initialize=function(t){var e={};for(var n in t){var r=Nehan.CssParser.formatEntry(n,t[n]),i=r.getPropName(),o=r.getValue(),s=e[i];s&&"object"==typeof s&&"object"==typeof o?Nehan.Obj.copy(s,o):e[i]=o}return e},t.prototype.merge=function(t){var e=t.getEntries();for(var n in e){var r=e[n],i=this.entries[n]||null;i&&"object"==typeof i&&"object"==typeof r?Nehan.Obj.copy(i,r):this.entries[n]=r}return this},t.prototype.getEntries=function(){return this.entries},t}(),Nehan.ComplexSelector=function(){function t(t){this.key=this._normalizeKey(t),this.elements=this._getSelectorElements(this.key),this.spec=this._countSpec(this.elements)}return t.prototype.test=function(t){return Nehan.SelectorStateMachine.accept(t,this.elements)},t.prototype.testPseudoElement=function(t,e){var n=this.hasPseudoElementName(e),r=this.test(t);return n&&r},t.prototype.getKey=function(){return this.key},t.prototype.getSpec=function(){return this.spec},t.prototype.hasPseudoElement=function(){return this.key.indexOf("::")>=0},t.prototype.hasPseudoElementName=function(t){return this.key.indexOf("::"+t)>=0},t.prototype._countSpec=function(t){var e=0,n=0,r=0;return Nehan.List.iter(t,function(t){t instanceof Nehan.CompoundSelector&&(e+=t.getIdSpec(),n+=t.getClassSpec()+t.getPseudoClassSpec()+t.getAttrSpec(),r+=t.getNameSpec())}),parseInt([e,n,r].join(""),10)},t.prototype._getSelectorElements=function(t){return new Nehan.SelectorLexer(t).getTokens()},t.prototype._normalizeKey=function(t){return t=t instanceof RegExp?"/"+t.source+"/":t,Nehan.Utils.trim(t).replace(/\s+/g," ")},t}(),Nehan.SelectorEntry=function(){function t(t,e){this.complexSelector=new Nehan.ComplexSelector(t),this.value=new Nehan.SelectorValue(e)}return t.prototype.getKey=function(){return this.complexSelector.getKey()},t.prototype.getSpec=function(){return this.complexSelector.getSpec()},t.prototype.getEntries=function(){return this.value.getEntries()},t.prototype.test=function(t){return this.complexSelector.test(t)},t.prototype.testPseudoElement=function(t,e){return this.complexSelector.testPseudoElement(t,e)},t.prototype.hasPseudoElement=function(){return this.complexSelector.hasPseudoElement()},t.prototype.hasPseudoElementName=function(t){return this.complexSelector.hasPseudoElementName(t)},t.prototype.updateValue=function(t){var e=new Nehan.SelectorValue(t);return this.value.merge(e),this},t}(),Nehan.Selectors=function(){function t(t){this.stylesheet=t||{},this.selectors=[],this.selectorsPe=[],this.selectorsPc=[],this.selectorsCache={},this._initialize(this.stylesheet)}return t.prototype._initialize=function(t){Nehan.Obj.iter(t,function(t,e){this._insertValue(t,e)}.bind(this))},t.prototype._sortSelectors=function(t){return t.sort(function(t,e){return t.getSpec()-e.getSpec()}),t},t.prototype._isPcKey=function(t){return t.indexOf("::")<0&&t.indexOf(":")>=0},t.prototype._isPeKey=function(t){return t.indexOf("::")>=0},t.prototype._findSelector=function(t){var e=this._getTargetSelectors(t);return Nehan.List.find(e,function(e){return e.getKey()===t})},t.prototype._getTargetSelectors=function(t){return this._isPeKey(t)?this.selectorsPe:this._isPcKey(t)?this.selectorsPc:this.selectors},t.prototype._updateValue=function(t,e){this._findSelector(t).updateValue(e)},t.prototype._insertValue=function(t,e){var n=new Nehan.SelectorEntry(t,e);return this._getTargetSelectors(t).push(n),n},t.prototype.get=function(t){return this._findSelector(t)},t.prototype.setValue=function(t,e){this.stylesheet[t]?this._updateValue(t,e):this._insertValue(t,e)},t.prototype.setValues=function(t){for(var e in t)this.setValue(e,t[e])},t.prototype.create=function(t,e){return new Nehan.SelectorEntry(t,e)},t.prototype.getValue=function(t){var e=t.getSelectorCacheKey(),n=this.selectorsCache[e]||null,r=n||this.selectors.filter(function(e){return e.test(t)});null===n&&(this.selectorsCache[e]=r);var i=this.selectorsPc.filter(function(e){return e.test(t)}),o=r.concat(i);return 0===o.length?{}:this._sortSelectors(o).reduce(function(t,e){return t.union(new Nehan.CssHashSet(e.getEntries()))},new Nehan.CssHashSet).getValues()},t.prototype.getValuePe=function(t,e){var n=t.getSelectorCacheKeyPe(e),r=this.selectorsCache[n]||null,i=r||this.selectorsPe.filter(function(n){return n.testPseudoElement(t,e)});return null===r&&(this.selectorsCache[n]=i),0===i.length?{}:this._sortSelectors(i).reduce(function(t,e){return t.union(new Nehan.CssHashSet(e.getEntries()))},new Nehan.CssHashSet).getValues()},t}(),Nehan.Color=function(){function t(t){this.setValue(t)}return t.prototype.setValue=function(t){this.value=t},t.prototype.getValue=function(){return this.value},t.prototype.getCssValue=function(){return this.value},t.prototype.getCss=function(){var t={};return t.color=this.getCssValue(),t},t}(),Nehan.Cardinal=function(){var t={"lower-alpha":["a","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],"upper-alpha":["A","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],"lower-roman":["i","i","ii","iii","iv","v","vi","vii","viii","ix","x","xi","xii","xiii","xiv","xv","xvi","xvii","xviii","xix","xx"],"upper-roman":["I","I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX"],"lower-greek":["α","α","β","γ","δ","ε","ζ","η","θ","ι","κ","λ","μ","ν","ξ","ο","π","ρ","σ","τ","υ","φ","χ","ψ","ω"],"upper-greek":["Α","Α","Β","Γ","Δ","Ε","Ζ","Η","Θ","Ι","Κ","Λ","Μ","Ν","Ξ","Ο","Π","Ρ","Σ","Τ","Υ","Φ","Χ","Ψ","Ω"],"cjk-ideographic":["〇","一","二","三","四","五","六","七","八","九","十"],hiragana:["あ","あ","い","う","え","お","か","き","く","け","こ","さ","し","す","せ","そ","た","ち","つ","て","と","な","に","ぬ","ね","の","は","ひ","ふ","へ","ほ","ま","み","む","め","も","や","ゆ","よ","ら","り","る","れ","ろ","わ","ゐ","ゑ","を","ん"],"hiragana-iroha":["い","い","ろ","は","に","ほ","へ","と","ち","り","ぬ","る","を","わ","か","よ","た","れ","そ","つ","ね","な","ら","む","う","ゐ","の","お","く","や","ま","け","ふ","こ","え","て","あ","さ","き","ゆ","め","み","し","ゑ","ひ","も","せ","す"],katakana:["ア","ア","イ","ウ","エ","オ","カ","キ","ク","ケ","コ","サ","シ","ス","セ","ソ","タ","チ","ツ","テ","ト","ナ","ニ","ヌ","ネ","ノ","ハ","ヒ","フ","ヘ","ホ","マ","ミ","ム","メ","モ","ヤ","ユ","ヨ","ラ","リ","ル","レ","ロ","ワ","ヰ","ヱ","ヲ","ン"],"katakana-iroha":["イ","イ","ロ","ハ","ニ","ホ","ヘ","ト","チ","リ","ヌ","ル","ヲ","ワ","カ","ヨ","タ","レ","ソ","ツ","ネ","ナ","ラ","ム","ウ","ヰ","ノ","オ","ク","ヤ","マ","ケ","フ","コ","エ","テ","ア","サ","キ","ユ","メ","ミ","シ","ヱ","ヒ","モ","セ","ス"]},e={"upper-latin":"upper-alpha","lower-latin":"lower-alpha"};return{getTableByName:function(n){return t[e[n]||n]},getBaseByName:function(t){return this.getTableByName(t).length},getStringByName:function(t,e){for(var n=this.getTableByName(t),r=n.length,i=Nehan.Utils.convBase(e,r),o="",s=0;s=e?e:n;return this.subtractAfter(t,r),r},t.prototype.copyTo=function(t){return Nehan.List.iter(Nehan.Const.cssPhysicalBoxDirs,function(e){t[e]=this[e]}.bind(this)),t},t.prototype.getDirProp=function(t){return[this.getType(),t].join("-")},t.prototype.getCss=function(){return Nehan.Const.cssPhysicalBoxDirs.reduce(function(t,e){var n=this[e];return n>0&&(t[this.getDirProp(e)]=n+"px"),t}.bind(this),{})},t.prototype.getWidth=function(){return this.left+this.right},t.prototype.getHeight=function(){return this.top+this.bottom},t.prototype.getMeasure=function(t){return t.isTextVertical()?this.getHeight():this.getWidth()},t.prototype.getExtent=function(t){return t.isBlockflowVertical()?this.getHeight():this.getWidth()},t.prototype.setSize=function(t,e){return Nehan.BoxRect.setLogicalValues(this,t,e),this},t.prototype.setStart=function(t,e){this[t.getPropStart()]=e},t.prototype.setEnd=function(t,e){this[t.getPropEnd()]=e},t.prototype.setBefore=function(t,e){this[t.getPropBefore()]=e},t.prototype.setAfter=function(t,e){this[t.getPropAfter()]=e},t.prototype.getStart=function(t){return this[t.getPropStart()]},t.prototype.getEnd=function(t){return this[t.getPropEnd()]},t.prototype.getBefore=function(t){return this[t.getPropBefore()]},t.prototype.getAfter=function(t){return this[t.getPropAfter()]},t.prototype.setByName=function(t,e,n){this[t.getProp(e)]=n},t.prototype.getByName=function(t,e){return this[t.getProp(e)]||0},t}(),Nehan.Radius2d=function(){function t(t){t=t||{},this.hori=void 0!==t.hori?t.hori:0,this.vert=void 0!==t.vert?t.vert:0}return t.prototype.clone=function(){var t=new Nehan.Radius2d;return t.hori=this.hori,t.vert=this.vert,t},t.prototype.setSize=function(t){return this.hori=t[0],this.vert=t[1],this},t.prototype.getCssValueHori=function(){return this.hori+"px"},t.prototype.getCssValueVert=function(){return this.vert+"px"},t}(),Nehan.BorderRadius=function(){function t(){this.topLeft=new Nehan.Radius2d,this.topRight=new Nehan.Radius2d,this.bottomRight=new Nehan.Radius2d,this.bottomLeft=new Nehan.Radius2d}return t.prototype.clone=function(){var e=new t;return e.topLeft=this.topLeft.clone(),e.topRight=this.topRight.clone(),e.bottomRight=this.bottomRight.clone(),e.bottomLeft=this.bottomLeft.clone(),e},t.prototype.getArray=function(){return[this.topLeft,this.topRight,this.bottomRight,this.bottomLeft]},t.prototype.getCssValueHori=function(){return this.getArray().map(function(t){return t.getCssValueHori()}).join(" ")},t.prototype.getCssValueVert=function(){return this.getArray().map(function(t){return t.getCssValueVert()}).join(" ")},t.prototype.getCssValue=function(){return[this.getCssValueHori(),this.getCssValueVert()].join("/")},t.prototype.getCss=function(){var t={},e=this.getCssValue();return t["border-radius"]=e,Nehan.List.iter(Nehan.Const.cssVenderPrefixes,function(n){var r=[n,"border-radius"].join("-");t[r]=e}),t},t.prototype.getCorner=function(t,e){var n=Nehan.BoxCorner.getPhysicalCornerName(t,e);return this[Nehan.Utils.camelize(n)]},t.prototype.setSize=function(t,e){Nehan.Const.cssLogicalBoxCorners.forEach(function(n){void 0!==e[n]&&this.getCorner(t,n).setSize(e[n])}.bind(this))},t.prototype.setBeforeStart=function(t,e){this.getCorner(t,"before-start").setSize(e)},t.prototype.setAfterStart=function(t,e){this.getCorner(t,"after-start").setSize(e)},t.prototype.setBeforeEnd=function(t,e){this.getCorner(t,"before-end").setSize(e)},t.prototype.setAfterEnd=function(t,e){this.getCorner(t,"after-end").setSize(e)},t.prototype.clearBefore=function(t){this.setBeforeStart(t,[0,0]),this.setBeforeEnd(t,[0,0])},t.prototype.clearAfter=function(t){this.setAfterStart(t,[0,0]),this.setAfterEnd(t,[0,0])},t}(),Nehan.BorderColor=function(){function t(){}return t.prototype.clone=function(){var e=new t;return Nehan.List.iter(Nehan.Const.cssPhysicalBoxDirs,function(t){this[t]&&(e[t]=this[t])}.bind(this)),e},t.prototype.setColor=function(t,e){Nehan.BoxRect.setLogicalValues(this,t,Nehan.Obj.map(e,function(t,e){return new Nehan.Color(e)}))},t.prototype.getCss=function(){var t={};return Nehan.List.iter(Nehan.Const.cssPhysicalBoxDirs,function(e){if(this[e]){var n=["border",e,"color"].join("-"),r=this[e];t[n]=r.getCssValue()}}.bind(this)),t},t}(),Nehan.BorderStyle=function(){function t(){}return t.prototype.clone=function(){var e=new t;return Nehan.List.iter(Nehan.Const.cssPhysicalBoxDirs,function(t){this[t]&&(e[t]=this[t])}.bind(this)),e},t.prototype.setStyle=function(t,e){Nehan.BoxRect.setLogicalValues(this,t,e)},t.prototype.getCss=function(){var t={};return Nehan.List.iter(Nehan.Const.cssPhysicalBoxDirs,function(e){if(this[e]){var n=["border",e,"style"].join("-"),r=this[e];t[n]=r}}.bind(this)),t},t}(),Nehan.Padding=function(){function t(){Nehan.Edge.call(this)}return Nehan.Class.extend(t,Nehan.Edge),t.prototype.getType=function(){return"padding"},t.prototype.clone=function(){return this.copyTo(new t)},t}(),Nehan.Margin=function(){function t(){Nehan.Edge.call(this)}return Nehan.Class.extend(t,Nehan.Edge),t.prototype.getType=function(){return"margin"},t.prototype.clone=function(){return this.copyTo(new t)},t}(),Nehan.Border=function(){function t(){Nehan.Edge.call(this)}return Nehan.Class.extend(t,Nehan.Edge),t.prototype.getType=function(){return"border"},t.prototype.clone=function(){var e=this.copyTo(new t);return this.radius&&(e.radius=this.radius.clone()),this.style&&(e.style=this.style.clone()),this.color&&(e.color=this.color.clone()),e},t.prototype.clearBefore=function(t){this.setBefore(t,0),this.radius&&this.radius.clearBefore(t)},t.prototype.clearAfter=function(t){this.setAfter(t,0),this.radius&&this.radius.clearAfter(t)},t.prototype.getDirProp=function(t){return["border",t,"width"].join("-")},t.prototype.setRadius=function(t,e){this.radius=new Nehan.BorderRadius,this.radius.setSize(t,e)},t.prototype.setColor=function(t,e){this.color=new Nehan.BorderColor,this.color.setColor(t,e)},t.prototype.setStyle=function(t,e){this.style=new Nehan.BorderStyle,this.style.setStyle(t,e)},t.prototype.getCss=function(){var t=Nehan.Edge.prototype.getCss.call(this);return this.radius&&Nehan.Obj.copy(t,this.radius.getCss()),this.color&&Nehan.Obj.copy(t,this.color.getCss()),this.style&&Nehan.Obj.copy(t,this.style.getCss()),t},t}(),Nehan.MarginCancel=function(){var t=function(t){t.parent&&t.parent.edge&&t.parent.edge.margin&&e(t),t.prev&&t.prev.isBlock()&&t.prev.edge&&t.prev.edge.margin&&t.edge.margin&&i(t)},e=function(t){t.isFirstChild()&&n(t),t.isLastChild()&&r(t)},n=function(t){t.flow===t.parent.flow&&o(t,{edge:t.parent.edge,target:"before"},{edge:t.edge,target:"before"})},r=function(t){t.flow===t.parent.flow&&o(t,{edge:t.parent.edge,target:"after"},{edge:t.edge,target:"after"})},i=function(t){t.flow===t.prev.flow?t.isFloated()&&t.prev.isFloated()?t.isFloatStart()&&t.prev.isFloatStart()?o(t,{edge:t.prev.edge,target:"end"},{edge:t.edge,target:"start"}):t.isFloatEnd()&&t.prev.isFloatEnd()&&o(t,{edge:t.prev.edge,target:"start"},{edge:t.edge,target:"end"}):t.isFloated()||t.prev.isFloated()||o(t,{edge:t.prev.edge,target:"after"},{edge:t.edge,target:"before"}):t.prev.isTextHorizontal()&&t.isTextVertical()?o(t,{edge:t.prev.edge,target:"after"},{edge:t.edge,target:"before"}):t.prev.isTextVertical()&&t.isTextHorizontal()&&(t.prev.flow.isBlockRightToLeft()?o(t,{edge:t.prev.edge,target:"after"},{edge:t.edge,target:"end"}):o(t,{edge:t.prev.edge,target:"after"},{edge:t.edge,target:"start"}))},o=function(t,e,n){if(!(e.edge.border&&e.edge.border.getByName(t.flow,e.target)||n.edge.border&&n.edge.border.getByName(t.flow,n.target))){var r=e.edge.margin.getByName(t.flow,e.target),i=n.edge.margin.getByName(t.flow,n.target),o=r>i?0:i-r;n.edge.margin.setByName(t.flow,n.target,o);var s=i-o;t.contentExtent+=s}};return{cancel:function(e){t(e)}}}(),Nehan.BorderCollapse=function(){var t=function(e,n){var r=e.parent;return r.edge&&r.edge.border&&r.edge.border.getByName(e.flow,n)>0?r.edge.border:r.parent?t(r,n):null},e=function(t,e){switch(t.display){case"table-header-group":case"table-row-group":case"table-footer-group":case"table-row":n(t,e);break;case"table-cell":r(t,e)}},n=function(e,n){var r=t(e,"start");r&&i(e,{border:r,target:"start"},{border:n,target:"start"});var o=t(e,"end");if(o&&i(e,{border:o,target:"end"},{border:n,target:"end"}),e.prev&&e.prev.edge&&e.prev.edge.border&&i(e,{border:e.prev.edge.border,target:"after"},{border:n,target:"before"}),e.isFirstChild()){var s=t(e,"before");s&&i(e,{border:s,target:"before"},{border:n,target:"before"})}if(e.isLastChild()){var a=t(e,"after");a&&i(e,{border:a,target:"after"},{border:n,target:"after"})}},r=function(e,n){e.prev&&e.prev.edge&&e.prev.edge.border&&i(e,{border:e.prev.edge.border,target:"end"},{border:n,target:"start"});var r=t(e,"before");r&&i(e,{border:r,target:"before"},{border:n,target:"before"});var o=t(e,"after");if(o&&i(e,{border:o,target:"after"},{border:n,target:"after"}),e.isFirstChild()){var s=t(e,"start");s&&i(e,{border:s,target:"start"},{border:n,target:"start"})}if(e.isLastChild()){var a=t(e,"end");a&&i(e,{border:a,target:"end"},{border:n,target:"end"})}},i=function(t,e,n){var r=e.border.getByName(t.flow,e.target),i=n.border.getByName(t.flow,n.target),o=Math.max(0,i-r),s=i-o;switch(n.target){case"before":case"after":t.contentExtent+=s;break;case"start":case"end":t.contentMeasure+=s}n.border.setByName(t.flow,n.target,o)};return{collapse:function(t){e(t,t.edge.border)}}}(),Nehan.BoxEdge=function(){function t(t){t=t||{},this.padding=t.padding||new Nehan.Padding,this.border=t.border||new Nehan.Border,this.margin=t.margin||new Nehan.Margin}return t.prototype.clone=function(){var e=new t;return e.padding=this.padding.clone(),e.border=this.border.clone(),e.margin=this.margin.clone(),e},t.prototype.clear=function(){this.padding.clear(),this.border.clear(),this.margin.clear()},t.prototype.getCss=function(){var t={};return Nehan.Obj.copy(t,this.padding.getCss()),Nehan.Obj.copy(t,this.border.getCss()),Nehan.Obj.copy(t,this.margin.getCss()),t},t.prototype.getWidth=function(){var t=0;return t+=this.padding.getWidth(),t+=this.border.getWidth(),t+=this.margin.getWidth()},t.prototype.getHeight=function(){var t=0;return t+=this.padding.getHeight(),t+=this.border.getHeight(),t+=this.margin.getHeight()},t.prototype.getMeasure=function(t){var e=0;return e+=this.padding.getMeasure(t),e+=this.border.getMeasure(t),e+=this.margin.getMeasure(t)},t.prototype.getExtent=function(t){var e=0;return e+=this.padding.getExtent(t),e+=this.margin.getExtent(t),e+=this.border.getExtent(t)},t.prototype.getInnerMeasureSize=function(t){var e=0;return e+=this.padding.getMeasure(t),e+=this.border.getMeasure(t)},t.prototype.getInnerExtentSize=function(t){var e=0;return e+=this.padding.getExtent(t),e+=this.border.getExtent(t)},t.prototype.getStart=function(t){var e=0;return e+=this.padding.getStart(t),e+=this.border.getStart(t),e+=this.margin.getStart(t)},t.prototype.getEnd=function(t){var e=0;return e+=this.padding.getEnd(t),e+=this.border.getEnd(t),e+=this.margin.getEnd(t)},t.prototype.getBefore=function(t){var e=0;return e+=this.padding.getBefore(t),e+=this.border.getBefore(t),e+=this.margin.getBefore(t)},t.prototype.getAfter=function(t){var e=0;return e+=this.padding.getAfter(t),e+=this.border.getAfter(t),e+=this.margin.getAfter(t)},t.prototype.getInnerBefore=function(t){var e=0;return e+=this.padding.getBefore(t),e+=this.border.getBefore(t)},t.prototype.setBorderRadius=function(t,e){this.border.setRadius(t,e)},t.prototype.setBorderColor=function(t,e){this.border.setColor(t,e)},t.prototype.setBorderStyle=function(t,e){this.border.setStyle(t,e)},t.prototype.cancelAfter=function(t,e){var n=e;return 0===(n-=this.margin.cancelAfter(t,n))?e:0===(n-=this.padding.cancelAfter(t,n))?e:(n-=this.border.cancelAfter(t,n),0===n?e:e-n)},t.prototype.clearBefore=function(t){this.padding.clearBefore(t),this.border.clearBefore(t),this.margin.clearBefore(t)},t.prototype.clearAfter=function(t){this.padding.clearAfter(t),this.border.clearAfter(t),this.margin.clearAfter(t)},t.prototype.clearEnd=function(t){this.padding.clearEnd(t),this.border.clearEnd(t),this.margin.clearEnd(t)},t.prototype.clearBorderStart=function(t){this.border.clearStart(t)},t.prototype.clearBorderBefore=function(t){this.border.clearBefore(t)},t.prototype.clearBorderAfter=function(t){this.border.clearAfter(t)},t}(),Nehan.BoxSize=function(){function t(t,e){this.width=t,this.height=e}return t.prototype.clone=function(){return new t(this.width,this.height)},t.prototype.setExtent=function(t,e){this[t.getPropExtent()]=e},t.prototype.setMeasure=function(t,e){this[t.getPropMeasure()]=e},t.prototype.getCss=function(){var t={};return t.width=this.width+"px",t.height=this.height+"px",t},t.prototype.getMeasure=function(t){return this[t.getPropMeasure()]},t.prototype.getExtent=function(t){return this[t.getPropExtent()]},t.prototype.isEqualTo=function(t){return this.width===t.width&&this.height===t.height},t}(),Nehan.BoxPosition=function(){function t(t){this.position=t,this.before=null,this.end=null,this.after=null,this.start=null}return t.prototype.isAbsolute=function(){return"absolute"===this.position},t.prototype.getCss=function(t){var e={};return e.position=this.position,this.start&&(e[t.getPropStart()]=this.start+"px"),this.end&&(e[t.getPropEnd()]=this.end+"px"),this.before&&(e[t.getPropBefore()]=this.before+"px"),this.after&&(e[t.getPropAfter()]=this.after+"px"),e},t}(),Nehan.SectionHeader=function(){function t(t){this.id=void 0===t.id?-1:t.id,this.rank=t.rank||0,this.title=t.title||""}return t.prototype.getId=function(){return this.id},t.prototype.getTitle=function(){return this.title},t.prototype.getRank=function(){return this.rank},t}(),Nehan.Section=function(){function t(t){this._parent=t.parent||null,this._pageNo=t.pageNo||0,this._header=null,this._next=null,this._child=null}return t.prototype.isRoot=function(){return null===this._parent},t.prototype.hasHeader=function(){return null!==this._header},t.prototype.hasHeaderId=function(){return this.getHeaderId()>0},t.prototype.hasChild=function(){return null!==this._child},t.prototype.hasNext=function(){return null!==this._next},t.prototype.getNext=function(){return this._next},t.prototype.getChild=function(){return this._child},t.prototype.getParent=function(){return this._parent},t.prototype.getHeader=function(){return this._header},t.prototype.getHeaderId=function(){return this._header?this._header.getId():null},t.prototype.setHeader=function(t){this._header=t},t.prototype.getRank=function(){return this._header?this._header.rank:0},t.prototype.getTitle=function(){return this._header?this._header.title:"no title"},t.prototype.getPageNo=function(){return this._pageNo},t.prototype.updatePageNo=function(t){this._pageNo=t},t.prototype.addChild=function(t){null===this._child?this._child=t:this._child.addNext(t)},t.prototype.addNext=function(t){null===this._next?this._next=t:this._next.addNext(t)},t}(),Nehan.TocContext=function(){function t(){this.stack=[1]}return t.prototype.toString=function(){return this.stack.join(".")},t.prototype.stepNext=function(){return this.stack.length>0&&this.stack[this.stack.length-1]++,this},t.prototype.startRoot=function(){return this.stack.push(1),this},t.prototype.endRoot=function(){return this.stack.pop(),this},t}(),Nehan.OutlineContext=function(){function t(t){this.logs=[],this.markupName=t||"body"}return t.prototype.isEmpty=function(){return 0===this.logs.length},t.prototype.get=function(t){return this.logs[t]||null},t.prototype.getMarkupName=function(){return this.markupName},t.prototype.add=function(t){return this.logs.push(t),this},t}(),Nehan.OutlineContextParser=function(){var t=function(e,n,r){var i=e.get(r++);if(null===i)return null;switch(i.name){case"start-section":var o=new Nehan.Section({parent:n,pageNo:i.pageNo}) ;n&&n.addChild(o),t(e,o,r);break;case"end-section":t(e,n.getParent(),r);break;case"set-header":var s=new Nehan.SectionHeader({id:i.headerId,rank:i.rank,title:i.title});if(null===n){var a=new Nehan.Section({parent:null,pageNo:i.pageNo});a.setHeader(s),t(e,a,r)}else if(n.hasHeader()){var h=i.rank,l=n.getRank();if(h]+>/gi,"").replace(/<\/a>/gi,"");return e.href="#"+t.pageNo,e.innerHTML=n,e.className="nehan-toc-link",e.id=Nehan.Css.addNehanTocLinkPrefix(t.headerId),e},createPageNoItem:function(t){return null}},e=function(t,n,r,i){if(null===r)return n;var o=i.createToc(t,r),s=i.createChild(o),a=i.createLink(o);a&&(a.onclick=function(t){return i.onClickLink(o,t)},s.appendChild(a));var h=i.createPageNoItem(o);h&&s.appendChild(h),n.appendChild(s);var l=r.getChild();if(l){t=t.startRoot();var u=i.createToc(t,l),c=i.createRoot(u);e(t,c,l,i),s.appendChild(c),t=t.endRoot()}var p=r.getNext();return p&&e(t.stepNext(),n,p,i),n};return{convert:function(n,r){r=Nehan.Obj.merge({},t,r||{});var i=new Nehan.TocContext,o=r.createRoot();return e(i,o,n,r)}}}(),Nehan.DocumentHeader=function(){function t(){this.title="",this.metas=[],this.links=[],this.scripts=[],this.styles=[]}return t.prototype.setTitle=function(t){this.title=t},t.prototype.getTitle=function(){return this.title},t.prototype.addLink=function(t){this.links.push(t)},t.prototype.getLinks=function(){return this.links},t.prototype.addMeta=function(t){this.metas.push(t)},t.prototype.getMetas=function(){return this.metas},t.prototype.getMetaByName=function(t){return Nehan.List.find(this.metas,function(e){return e.getTagAttr("name")===t})},t.prototype.getMetaContentByName=function(t){var e=this.getMetaByName(t);return e?e.getTagAttr("content"):null},t.prototype.addScript=function(t){this.scripts.push(t)},t.prototype.getScripts=function(){return this.scripts},t.prototype.addStyle=function(t){this.styles.push(t)},t.prototype.getStyles=function(){return this.styles},t}(),Nehan.Clear=function(){function t(t){this.value=t,this.status=this._createStatus(t||"both")}return t.prototype.hasDirection=function(t){return"both"===this.value||this.value===t},t.prototype.setDone=function(t){this.status[t]=!0},t.prototype.isDoneAll=function(){return Nehan.Obj.forall(this.status,function(t,e){return!0===e})},t.prototype._createStatus=function(t){var e={};switch(t){case"start":case"end":e[t]=!1;break;case"both":e.start=e.end=!1}return e},t}(),Nehan.FloatDirection=function(){function t(t){this.value=t||"none"}return t.prototype.getCss=function(t){var e={};return t||(this.isStart()?e["css-float"]="left":this.isEnd()&&(e["css-float"]="right")),e},t.prototype.getName=function(){return this.value},t.prototype.isStart=function(){return"start"===this.value},t.prototype.isEnd=function(){return"end"===this.value},t.prototype.isNone=function(){return"none"===this.value},t}(),Nehan.FloatDirections={start:new Nehan.FloatDirection("start"),end:new Nehan.FloatDirection("end"),none:new Nehan.FloatDirection("none"),get:function(t){return this[t]||null}},Nehan.FloatGroup=function(){function t(t,e){this.elements=t||[],this.floatDirection=e||Nehan.FloatDirections.get("start"),this._last=!1}return t.prototype.isLast=function(){return this._last},t.prototype.setLast=function(t){this._last=t},t.prototype.add=function(t){this.elements.unshift(t)},t.prototype.isFloatStart=function(){return this.floatDirection.isStart()},t.prototype.isFloatEnd=function(){return this.floatDirection.isEnd()},t.prototype.getElements=function(){return this.isFloatStart()?this.elements:Nehan.List.reverse(this.elements)},t.prototype.getMeasure=function(t){return this.elements.reduce(function(e,n){return e+n.getLayoutMeasure(t)},0)},t.prototype.getExtent=function(t){return this.elements.reduce(function(e,n){return Math.max(e,n.getLayoutExtent(t))},0)},t.prototype.getFloatDirection=function(){return this.floatDirection},t.prototype.getLength=function(){return this.elements.length},t}(),Nehan.FloatGroupStack=function(){function t(t,e,r){var i=n(t,Nehan.FloatDirections.start,e),o=n(t,Nehan.FloatDirections.end,r);this.stack=i.concat(o).sort(function(e,n){return e.getExtent(t)-n.getExtent(t)});var s=Nehan.List.maxobj(this.stack,function(e){return e.getExtent(t)});this.flow=t,this.lastGroup=null,this.extent=s?s.getExtent(t):0}var e=function(t,e,n){var r=n.pop()||null;if(null===r)return null;for(var i=r.getLayoutExtent(t),o=new Nehan.FloatGroup([r],e);;){var s=n.pop();if(!(s&&s.getLayoutExtent(t)<=i)){n.push(s);break}o.add(s)}return o},n=function(t,n,r){var i,o=[];do{(i=e(t,n,r))&&o.push(i)}while(null!==i);return o.length>0&&o[0].setLast(!0),o};return t.prototype.isEmpty=function(){return 0===this.stack.length},t.prototype.getExtent=function(){return this.extent},t.prototype.getLastGroup=function(){return this.lastGroup},t.prototype.pop=function(){return this.lastGroup=this.stack.pop()||null,this.lastGroup},t}(),Nehan.LineHeight=function(){return{set:function(t,e,n){if(0!==e.elements.length){var r=e.getFontSize(),i=Math.floor(e.maxFontSize*n),o=i-e.maxExtent;if(0!==o){var s=Math.floor(e.maxFontSize*(n-1)),a=Math.round(s/2);if(e.edge=new Nehan.BoxEdge,o<0){if(e.elements.length<=1)return;if(Math.abs(o)>=r)return void e.edge.padding.setAfter(t,a)}if(e.isDecorated)return void e.edge.padding.setAfter(t,Math.abs(o));a>0&&(e.edge.padding.setBefore(t,a),e.edge.padding.setAfter(t,a))}}}}}(),Nehan.VerticalAlign=function(){var t=function(t,e){Nehan.List.iter(e.elements,function(n){var r=n.maxFontSize,i=Math.floor((e.maxFontSize-r)/2);if(i>0){var o=n.edge?n.edge.clone():new Nehan.BoxEdge;o.padding.setAfter(t,i),n.size.width=e.maxExtent-i,Nehan.Obj.copy(n.css,o.getCss(t))}})},e=function(t,e){Nehan.List.iter(e.elements,function(n){var r=(n.maxFontSize,e.maxExtent-n.maxExtent);if(r>0){var i=n.edge?n.edge.clone():new Nehan.BoxEdge;i.padding.setBefore(t,r),Nehan.Obj.copy(n.css,i.getCss(t))}})};return{setMiddle:function(t,e){},setBefore:function(t,e){},setTextBefore:function(t,e){},setAfter:function(t,e){},setTextAfter:function(t,e){},setSub:function(t,e){},setSuper:function(t,e){},setPercent:function(t,e,n){},setLength:function(t,e,n){},setBaseline:function(n,r){n.isTextVertical()?t(n,r):e(n,r)}}}(),Nehan.TextAlign=function(){function t(t){this.value=t||"start"}return t.prototype.isStart=function(){return"start"===this.value},t.prototype.isEnd=function(){return"end"===this.value},t.prototype.isCenter=function(){return"center"===this.value},t.prototype.isJustify=function(){return"justify"===this.value},t.prototype.setAlign=function(t){var e=t.context.style,n=e.flow,r=t.getContentMeasure(n),i=r-t.inlineMeasure;if(!(i<=0)){var o=new Nehan.Padding;if(this.isCenter()){var s=Math.floor(i/2);t.size.setMeasure(n,r-s),o.setStart(n,s),Nehan.Obj.copy(t.css,o.getCss())}else this.isEnd()&&(t.size.setMeasure(n,t.inlineMeasure),o.setStart(n,i),Nehan.Obj.copy(t.css,o.getCss()))}},t.prototype.setJustify=function(t){var e=t.context.style,n=e.flow,r=e.getFontSize(),i=Math.floor(r/2),o=Math.floor(i/2),s=t.getContentMeasure(n),a=t.inlineMeasure,h=s-a,l=2*e.getFontSize(),u=function(t,e){if(t){var r=t.size.getMeasure(n),i=r+e;t.size.setMeasure(n,i)}};if(!(t.hasLineBreak||h>=l||0===h)){var c=function(t){return t.reduce(function(t,e){return e instanceof Nehan.Box?e.isTextBlock()?t.concat(c(e.elements||[])):t:e?t.concat(e):t},[])},p=c(t.elements);if(0!==p.length){var f=p.filter(function(t){return t instanceof Nehan.Word||t instanceof Nehan.Char&&!t.isKerningChar()});if(0!==f.length){if(h<0)return void Nehan.List.iter(f,function(t){if(t instanceof Nehan.Word){var e;if((e=t.paddingEnd||0)>0&&(h+=e,u(t.parent,-1*e),t.paddingEnd=0,h>=0))return!1;if((e=t.paddingStart||0)>0&&(h+=e,u(t.parent,-1*e),t.paddingStart=0,h>=0))return!1}return!0});var g=Math.max(1,Math.min(o,Math.floor(h/f.length/2)));Nehan.List.iter(f,function(t){return t.paddingEnd=(t.paddingEnd||0)+g,h-=g,u(t.parent,g),!(h<=0)&&!(t instanceof Nehan.Word&&(t.paddingStart=(t.paddingStart||0)+g,h-=g,u(t.parent,g),h<=0))})}}}},t}(),Nehan.TextAligns={start:new Nehan.TextAlign("start"),end:new Nehan.TextAlign("end"),center:new Nehan.TextAlign("center"),justify:new Nehan.TextAlign("justify"),get:function(t){return this[t]||null}},Nehan.Break=function(){function t(t){this.value=t}return t.prototype.isAlways=function(){return"always"===this.value},t.prototype.isAvoid=function(){return"avoid"===this.value},t.prototype.isFirst=function(t){return t.isTextVertical()?t.isBlockLeftToRight()?"left"===this.value:"right"===this.value:t.isTextLeftToRight()?"left"===this.value:"right"===this.value},t.prototype.isSecond=function(t){return!1===this.isFirst(t)},t.prototype.isNth=function(t){},t}(),Nehan.Breaks={before:{always:new Nehan.Break("always"),avoid:new Nehan.Break("avoid"),left:new Nehan.Break("left"),right:new Nehan.Break("right"),first:new Nehan.Break("first"),second:new Nehan.Break("second")},after:{always:new Nehan.Break("always"),avoid:new Nehan.Break("avoid"),left:new Nehan.Break("left"),right:new Nehan.Break("right"),first:new Nehan.Break("first"),second:new Nehan.Break("second")},getBefore:function(t){return this.before[t]||null},getAfter:function(t){return this.after[t]||null}},Nehan.Page=function(){function t(t){Nehan.Obj.merge(this,{tree:null,element:null,text:"",seekPos:0,pageNo:0,charPos:0,charCount:0,percent:0},t)}return t}(),Nehan.Flow=function(){function t(t){this.dir=t}return t.prototype.init=function(t){this.dir=t},t.prototype.isHorizontal=function(){return"lr"===this.dir||"rl"===this.dir},t.prototype.isVertical=function(){return"tb"===this.dir},t.prototype.isLeftToRight=function(){return"lr"===this.dir},t.prototype.isRightToLeft=function(){return"rl"===this.dir},t}(),Nehan.BlockFlow=function(){function t(t){Nehan.Flow.call(this,t)}return Nehan.Class.extend(t,Nehan.Flow),t.prototype.getPropBefore=function(){switch(this.dir){case"lr":return"left";case"rl":return"right";case"tb":return"top";default:return""}},t.prototype.getPropAfter=function(){switch(this.dir){case"lr":return"right";case"rl":return"left";case"tb":return"bottom";default:return""}},t}(),Nehan.InlineFlow=function(){function t(t){Nehan.Flow.call(this,t)}return Nehan.Class.extend(t,Nehan.Flow),t.prototype.getPropStart=function(){switch(this.dir){case"lr":return"left";case"rl":return"right";case"tb":return"top";default:return""}},t.prototype.getPropEnd=function(){switch(this.dir){case"lr":return"right";case"rl":return"left";case"tb":return"bottom";default:return""}},t}(),Nehan.BoxFlow=function(){function t(t,e){this.inflow=new Nehan.InlineFlow(t),this.blockflow=new Nehan.BlockFlow(e)}return t.prototype.isTextLineFirst=function(){return!(!this.isTextVertical()||!this.blockflow.isLeftToRight())},t.prototype.isBlockflowVertical=function(){return this.blockflow.isVertical()},t.prototype.isTextVertical=function(){return this.inflow.isVertical()},t.prototype.isTextHorizontal=function(){return this.inflow.isHorizontal()},t.prototype.isTextLeftToRight=function(){return this.inflow.isLeftToRight()},t.prototype.isTextRightToLeft=function(){return this.inflow.isRightToLeft()},t.prototype.isBlockLeftToRight=function(){return this.blockflow.isLeftToRight()},t.prototype.isBlockRightToLeft=function(){return this.blockflow.isRightToLeft()},t.prototype.getCss=function(){var t={};return this.isTextVertical()?t["css-float"]=this.isBlockLeftToRight()?"left":"right":t["css-float"]=this.isTextLeftToRight()?"left":"right",t},t.prototype.getName=function(){return[this.inflow.dir,this.blockflow.dir].join("-")},t.prototype.getProp=function(t){switch(t){case"start":return this.getPropStart();case"end":return this.getPropEnd();case"before":return this.getPropBefore();case"after":return this.getPropAfter()}throw console.error("BoxFlow::getProp, undefined property(%o)",t),"BoxFlow::getProp, undefined property"},t.prototype.getPropStart=function(){return this.inflow.getPropStart()},t.prototype.getPropEnd=function(){return this.inflow.getPropEnd()},t.prototype.getPropBefore=function(){return this.blockflow.getPropBefore()},t.prototype.getPropAfter=function(){return this.blockflow.getPropAfter()},t.prototype.getPropExtent=function(){return this.isTextVertical()?"width":"height"},t.prototype.getPropMeasure=function(){return this.isTextVertical()?"height":"width"},t.prototype.getPropWidth=function(){return this.isTextVertical()?"extent":"measure"},t.prototype.getPropHeight=function(){return this.isTextVertical()?"measure":"extent"},t.prototype.getFlipFlow=function(){return this.isTextVertical()?Nehan.Display.getStdHoriFlow():Nehan.Display.getStdVertFlow()},t.prototype.getBoxSize=function(t,e){var n=new Nehan.BoxSize(0,0);return n[this.getPropMeasure()]=t,n[this.getPropExtent()]=e,n},t.prototype.toString=function(){return this.getName()},t}(),Nehan.BoxFlows={"tb-rl":new Nehan.BoxFlow("tb","rl"),"tb-lr":new Nehan.BoxFlow("tb","lr"),"lr-tb":new Nehan.BoxFlow("lr","tb"),"rl-tb":new Nehan.BoxFlow("rl","tb"),get:function(t,e){return this.getByName([t,e].join("-"))},getByName:function(t){return this[t]||null}},Nehan.WordBreak=function(){function t(t){this.value=t}return t.prototype.isWordBreakAll=function(){return"break-all"===this.value},t.prototype.isHyphenationEnable=function(){return"normal"===this.value},t}(),Nehan.WordBreaks={"keep-all":new Nehan.WordBreak("keep-all"),normal:new Nehan.WordBreak("normal"),"break-all":new Nehan.WordBreak("break-all"),loose:new Nehan.WordBreak("loose"),"break-strict":new Nehan.WordBreak("break-strict"),getInitialValue:function(){return this.normal},getByName:function(t){return this[t]||null}},Nehan.TextMetrics=function(){var t=function(){var t=document.createElement("span");return Nehan.Obj.copy(t.style,{margin:0,padding:0,border:0,lineHeight:1,height:"auto",visibility:"hidden"}),t}();return{getMetrics:function(e,n){var r=document.body,i=t.style;r.style.display="block",i.font=e.getCssShorthand(),t.innerHTML=n,r.appendChild(t);var o=t.getBoundingClientRect(),s={width:Math.round(o.right-o.left),height:Math.round(o.bottom-o.top)};return r.removeChild(t),s},getMeasure:function(t,e){return this.getMetrics(t,e).width}}}(),Nehan.Text=function(){function t(t){this.content=this._normalize(t)}return t.prototype._normalize=function(t){return t.replace(/^\n+/,"")},t.prototype.isWhiteSpaceOnly=function(){return!(this.content.indexOf(" ")>=0)&&!this.content.match(/[\S]/)},t.prototype.getContent=function(){return this.content},t.prototype.getHeadChar=function(){return new Nehan.Char({data:this.content.substring(0,1)})},t.prototype.cutHeadChar=function(){return this.content=this.content.substring(1),this},t.prototype.toString=function(t){return this.getContent()},t}(),Nehan.Char=function(){function t(t){this._initialize(t||{})}var e=[".","。"],n=[",","、"],r=["(","[","{","≪","❲","〈","《","「","『","【","〔","〖","(","<","[","{","「"],i=[")","]","}","≫","❳","〉","》","」","』","】","〕","〗",")",">","]","}","」"],o=["ぁ","ぃ","ぅ","ぇ","ぉ","っ","ゃ","ゅ","ょ","ゎ","ァ","ィ","ゥ","ェ","ォ","ヵ","ヶ","ッ","ャ","ュ","ョ","ヮ"],s=["\\","]","”",")",",",".","\\","、","。","〉","》","」","』","】","〕","〟",")",",",".",">","]","」"],a=["(","[","\\","“","〈","《","「","『","【","〔","〝","(","<","[","「"],h=["゙","゚","゛","゜","゙","゚"],l=[" "," ","\ufeff"],u=/[\w!\.\?\/:#;"',]/,c=/[\uFF65-\uFF9f]/,p=/[\uFF67-\uFF6f]/,f=Nehan.Env.client.isIE();return t.prototype._initialize=function(t){this.data=t.data||"",this.ref=t.ref||"",this._setup()},t.prototype.getData=function(t){return t.isTextVertical()?this._getDataVert():this._getDataHori()},t.prototype.toString=function(t){return this.getData(t)},t.prototype._getDataVert=function(){return(this.vertCnv||this.data||this.ref)+(this.ligature||"")},t.prototype._getDataHori=function(){return(this.horiCnv||this.data||this.ref)+(this.ligature||"")},t.prototype.getCssPadding=function(t){var e=new Nehan.Padding;return this.paddingStart&&e.setStart(t.context.style.flow,this.paddingStart),this.paddingEnd&&e.setEnd(t.context.style.flow,this.paddingEnd),e.getCss()},t.prototype.getCssVertGlyph=function(t){var e={},n=this.isZenkaku(),r=this.isKakkoStart(),i=this.isKakkoEnd(),o=this.isTenten(),s=this.isPaddingEnable();return f&&(e.height="1em"),n&&r&&!s?(e.height="1em",e["margin-top"]="-0.5em"):n&&i&&!s?(e.height="1em",e["margin-bottom"]="-0.5em"):!r&&!i&&!o&&this.vscale<1&&(e.height="0.5em",Nehan.Obj.copy(e,this.getCssPadding(t))),e},t.prototype.getCssVertImgChar=function(t){var e={},n=t.context.style.getFontSize();return e.display="block",e.width=n+"px",e.height=this.getVertHeight(n)+"px",this.isPaddingEnable()&&Nehan.Obj.copy(e,this.getCssPadding(t)),e},t.prototype.getCssVertSingleHalfChar=function(t){var e={};return t.edge?e["padding-left"]="0.25em":e["text-align"]="center",e},t.prototype.getCssVertHalfKana=function(t){var e={};return e["text-align"]="center",this.hasLigature()?e["padding-left"]="0.25em":this.isHalfKanaSmall()&&(e["padding-left"]="0.25em",e["margin-top"]="-0.25em"),e},t.prototype.getCssVertRotateCharIE=function(t){var e={},n=t.context.style.getFontSize();return e["css-float"]="left",e["writing-mode"]="tb-rl",e["padding-left"]=Math.round(n/2)+"px",e["line-height"]=n+"px",e},t.prototype.getCssVertDashIE=function(t){var e={};return e.height="0.84em",e},t.prototype.getCssVertEmphaText=function(t){var e={},n=t.context.style.getFontSize();return e["font-size"]="0.5em",e.display="inline-block",e.width=n+"px",e.height=n+"px",e.position="absolute",e},t.prototype.getCssHoriEmphaSrc=function(t){var e={};return e.display="block",e.float="left",e["line-height"]="1em",e.height="1em",e},t.prototype.getCssHoriEmphaText=function(t){var e={},n=t.getFontSize(),r=Math.floor(t.getFontSize()/2);return e.display="block",e.width=n+"px",e.height=r+"px",e["padding-left"]="0.25em",e["line-height"]=r+"px",e["font-size"]=r+"px",e.float="left",e},t.prototype.getCssVertLetterSpacing=function(t){var e={};return e["margin-bottom"]=t.letterSpacing+"px",e},t.prototype.getCssHoriSpaceChar=function(t){var e={};return e.display="inline-block",e.width=this.bodySize+"px",e},t.prototype.getCssHoriTabChar=function(t){var e={};return e.display="inline-block",e.width=this.bodySize+"px",e},t.prototype.getCssVertSpaceChar=function(t){var e={};return e.height=this.bodySize+"px",e["line-height"]=this.bodySize+"px",e},t.prototype.getCssVertTabChar=function(t){var e={};return e.height=this.bodySize+"px",e["line-height"]=this.bodySize+"px",e},t.prototype.getCssVertSmallKana=function(){var t={};return t.position="relative",t.top="-0.1em",t.right="-0.12em",t.height=this.bodySize+"px",t["line-height"]=this.bodySize+"px",t.clear="both",t},t.prototype.getAdvanceScale=function(t){return t.isTextVertical()?this.getVertScale():this.getHoriScale()},t.prototype.getHoriScale=function(){return this.hscale||1},t.prototype.getVertScale=function(){return this.vscale||1},t.prototype.getVertHeight=function(t){var e=this.getVertScale();return 1===e?t:Math.round(t*e)},t.prototype.hasMetrics=function(){return void 0!==this.bodySize},t.prototype.getAdvance=function(t,e){return this.bodySize+this.getPaddingSize()+(e||0)},t.prototype.getPaddingSize=function(){return(this.paddingStart||0)+(this.paddingEnd||0)},t.prototype.getCharCount=function(){return this.isSpaceGroup()||this.isIdeographicSpace()?0:1},t.prototype.setMetrics=function(t,e){t.isTextVertical()?this._setMetricsVert(t,e):this._setMetricsHori(t,e)},t.prototype._setMetricsVert=function(t,e){var n=this.getAdvanceScale(t);this.bodySize=1!=n?Math.round(e.size*n):e.size,this.spaceRateStart&&(this.paddingStart=Math.round(this.spaceRateStart*e.size)),this.spaceRateEnd&&(this.paddingEnd=Math.round(this.spaceRateEnd*e.size)),this.isSmallKana()&&(this.bodySize-=Math.floor(.1*e.size))},t.prototype._setMetricsHori=function(t,e){var n=this.getAdvanceScale(t);return this.spaceRateStart&&(this.paddingStart=Math.round(this.spaceRateStart*e.size)),this.spaceRateEnd&&(this.paddingEnd=Math.round(this.spaceRateEnd*e.size)),!this.isHankaku()&&!this.isSmallKana()||this.isCharRef()||this.isWhiteSpace()?this.isHalfKana()?void(this.bodySize=Math.round(e.size/2)):void(this.bodySize=1!=n?Math.round(e.size*n):e.size):void(this.bodySize=Nehan.TextMetrics.getMeasure(e,this.getData(t)))},t.prototype._setVertImg=function(t,e,n){this.vertImg=t,this.vscale=e,this.hscale=n},t.prototype._setVertCnv=function(t,e,n){this.vertCnv=t,this.vscale=e,this.hscale=n},t.prototype._setHoriCnv=function(t){this.horiCnv=t},t.prototype._setRotate=function(t){this.rotate=t},t.prototype._setRotateOrVertImg=function(t,e,n,r){if(Nehan.Env.isTransformEnable)return this._setRotate(t),this.vscale=n,void(this.hscale=r);this._setVertImg(e,n,r)},t.prototype._setup=function(){this.isHankaku()&&(this.hscale=.5,this._setRotate(90)),this.data&&this._setupByCharCode(this.data.charCodeAt(0)),this.isSpace()?this.vscale=this.hscale=Nehan.Config.spacingSizeRate.space:this.isNbsp()?this.vscale=this.hscale=Nehan.Config.spacingSizeRate.nbsp:this.isEnsp()?this.vscale=this.hscale=Nehan.Config.spacingSizeRate.ensp:this.isEmsp()?this.vscale=this.hscale=Nehan.Config.spacingSizeRate.emsp:this.isThinsp()?this.vscale=this.hscale=Nehan.Config.spacingSizeRate.thinsp:this.isTabSpace()?this.vscale=this.hscale=Math.floor(Nehan.Config.tabCount/2):this.isLessThanSign()?this._setRotateOrVertImg(90,"kakko7",.5,.5):this.isGreaterThanSign()&&this._setRotateOrVertImg(90,"kakko8",.5,.5)},t.prototype._setupByCharCode=function(t){switch(t){case 12300:case 65378:this._setVertImg("kakko1",.5,.5);break;case 12301:case 65379:this._setVertImg("kakko2",.5,.5);break;case 12302:this._setVertImg("kakko3",.5,.5);break;case 12303:this._setVertImg("kakko4",.5,.5);break;case 65288:case 40:case 65371:case 123:this._setVertImg("kakko5",.5,.5);break;case 65289:case 41:case 65373:case 125:this._setVertImg("kakko6",.5,.5);break;case 65308:case 12296:this._setVertImg("kakko7",.5,.5);break;case 65310:case 12297:this._setVertImg("kakko8",.5,.5);break;case 12298:case 8810:this._setVertImg("kakko9",.5,.5);break;case 12299:case 8811:this._setVertImg("kakko10",.5,.5);break;case 65339:case 12308:case 91:this._setVertImg("kakko11",.5,.5);break;case 65341:case 12309:case 93:this._setVertImg("kakko12",.5,.5);break;case 12304:case 12310:this._setVertImg("kakko17",.5,.5);break;case 12305:case 12311:this._setVertImg("kakko18",.5,.5);break;case 65306:this._setVertImg("tenten",1,1);break;case 58:this._setVertImg("tenten",.5,.5);break;case 12290:case 65377:this._setVertImg("kuten",.5,.5);break;case 65294:case 46:this._setVertImg("period",1,1);break;case 12289:case 65380:case 44:this._setVertImg("touten",.5,.5);break;case 65292:this._setVertImg("touten",.5,1);break;case 65374:case 12316:this._setVertImg("kara",1,1);break;case 8230:this._setVertImg("mmm",1,1);break;case 8229:this._setVertImg("mm",1,1);break;case 12317:this._setVertImg("dmn1",1,1);break;case 12318:this._setRotate(90);break;case 12319:this._setVertImg("dmn2",1,1);break;case 61:case 8786:case 8800:case 65309:this._setVertImg("equal",1,1);break;case 8212:f?this._setVertCnv("|",1,1):this._setRotate(90);break;case 8213:this._setRotate(90),f||this._setVertCnv("—",1,1),this._setHoriCnv("—");break;case 8220:case 8221:this._setRotate(90),this.hscale=this.vscale=.5;break;case 65392:case 12540:this._setVertImg("onbiki",1,1);break;case 65293:case 9472:this._setVertCnv("—",1,1),this._setRotate(90);break;case 65343:this._setRotate(90);break;case 8593:this._setVertCnv("→",1,1);break;case 8594:this._setVertCnv("↓",1,1);break;case 8658:this._setVertCnv("⇓",1,1);break;case 8595:this._setVertCnv("←",1,1);break;case 8592:this._setVertCnv("↑",1,1);break;case 45:this._setRotate(90),this.hscale=.4,this.vscale=.5;break;case 8722:this._setRotate(90)}},t.prototype.setLigature=function(t){this.ligature=t},t.prototype.isNewLine=function(){return"\n"===this.data},t.prototype.isLessThanSign=function(){return"<"==this.ref||"<"===this.data},t.prototype.isGreaterThanSign=function(){return">"==this.ref||">"===this.data},t.prototype.isNbsp=function(){return" "===this.ref||" "===this.data},t.prototype.isThinsp=function(){return" "===this.ref||" "===this.data},t.prototype.isEnsp=function(){return" "===this.ref||" "===this.data},t.prototype.isEmsp=function(){return" "===this.ref||" "===this.data},t.prototype.isTabSpace=function(){return"\t"===this.data||" "===this.ref},t.prototype.isSpace=function(){return" "===this.data},t.prototype.isNoBreakSpace=function(){return this.isNbsp()||Nehan.List.exists(l,Nehan.Closure.eq(this.data))},t.prototype.isSpaceGroup=function(){return this.isSpace()||this.isNbsp()||this.isTabSpace()||this.isThinsp()||this.isEnsp()||this.isEmsp()},t.prototype.isIdeographicSpace=function(){return" "===this.data},t.prototype.isWhiteSpace=function(){return this.isNewLine()||this.isSpaceGroup()},t.prototype.isVertChar=function(){return void 0!==this.vertImg},t.prototype.isRotateChar=function(){return void 0!==this.rotate},t.prototype.isCharRef=function(){return""!==this.ref},t.prototype.isKerningChar=function(){return this.isZenkaku()&&(this.isKutenTouten()||this.isKakko())},t.prototype.isDash=function(){var t=this.data.charCodeAt(0);return 8212===t||8213===t},t.prototype.getImgSrc=function(t){return[Nehan.Config.fontImgRoot,this.vertImg,t+".png"].join("/")},t.prototype.isPaddingEnable=function(){return void 0!==this.paddingStart||void 0!==this.paddingEnd},t.prototype.isTenten=function(){return this.vertImg&&"tenten"===this.vertImg},t.prototype.isHeadNg=function(){return Nehan.List.mem(s,this.data)},t.prototype.isTailNg=function(){return Nehan.List.mem(a,this.data)},t.prototype.isSmallKana=function(){return Nehan.List.mem(o,this.data)},t.prototype.isSingleHalfChar=function(){return 1===this.data.length&&u.test(this.data)},t.prototype.isKakkoStart=function(){return Nehan.List.mem(r,this.data)},t.prototype.isKakkoEnd=function(){return Nehan.List.mem(i,this.data)},t.prototype.isKakko=function(){return this.isKakkoStart()||this.isKakkoEnd()},t.prototype.isKuten=function(){return Nehan.List.mem(e,this.data)},t.prototype.isTouten=function(){return Nehan.List.mem(n,this.data)},t.prototype.isKutenTouten=function(){return this.isKuten()||this.isTouten()},t.prototype.isZenkaku=function(){return"u"===escape(this.data).charAt(1)},t.prototype.isHankaku=function(){return!this.isZenkaku(this.data)},t.prototype.isHalfKana=function(){return c.test(this.data)},t.prototype.isHalfKanaSmall=function(){return p.test(this.data)},t.prototype.isLigature=function(){return Nehan.List.mem(h,this.data)},t.prototype.hasLigature=function(){return void 0!==this.ligature},t}(),Nehan.Word=function(){function t(t,e){this.data=t,this._divided=e||!1}var e=function(t,e,n){for(var r=t.data.length-1;r>=1;r--){var i=t.data.substring(0,r);if(Math.ceil(Nehan.TextMetrics.getMeasure(e,i))<=n){var o=new Nehan.Word(i,!0);return o.bodySize=n,o}}return t},n=function(t,e,n){var r=t.data.split("­")[0]+"­";if(Math.ceil(Nehan.TextMetrics.getMeasure(e,r+"-"))>n)return t;var i=new Nehan.Word(r,!0);return i.bodySize=n,i};return t.prototype.isHeadNg=function(){return!1},t.prototype.isTailNg=function(){return!1},t.prototype.getData=function(t){return t.isTextVertical()?this._getDataVert():this._getDataHori()},t.prototype._getDataVert=function(){var t=this.data;return t=t.replace(/[\u002D\u2010\u2012\u2013]/g,"‑"),t=Nehan.Env.client.isIE()?t.replace(/\u2014/g,"|"):t.replace(/\u2015/g,"—")},t.prototype._getDataHori=function(){var t=this.data;t=t.replace(/\u2015/g,"—");var e=t.indexOf("­");return e>=0&&e===t.length-5&&(t=t.replace(/­/g,"-")),t},t.prototype.getCssHori=function(t){var e={};return e["padding-left"]=this.paddingStart+"px",e["padding-right"]=this.paddingEnd+"px",e},t.prototype.getCssVertTrans=function(t){var e={},n=t.context.style.getFontSize();return t.context.style.letterSpacing&&(e["letter-spacing"]=t.context.style.letterSpacing+"px"),e.width=n+"px",e.height=this.bodySize+"px",e["padding-top"]=this.paddingStart+"px",e["padding-bottom"]=this.paddingEnd+"px",e},t.prototype.getCssVertTransBody=function(t){return{}},t.prototype.getCssVertTransBodyTrident=function(t){var e={};e.width=t.context.style.getFontSize()+"px",e.height=this.bodySize+"px",e["transform-origin"]="50% 50%",e["line-height"]=this.bodySize+"px";var n=Math.floor((this.bodySize-t.context.style.getFontSize())/2);return n>0&&(e.transform="rotate(90deg) translate(-"+n+"px, 0)"),e},t.prototype.getCssVertTransIE=function(t){var e={},n=t.context.style.getFontSize();return e["css-float"]="left",e["writing-mode"]="tb-rl",e["letter-spacing"]=(t.context.style.letterSpacing||0)+"px",e["padding-left"]=Math.round(n/2)+"px",e["line-height"]=n+"px",e},t.prototype.getCharCount=function(){return 1},t.prototype.getAdvance=function(t,e){var n=(e||0)*this.getLetterCount(),r=(this.paddingStart||0)+(this.paddingEnd||0);return this.bodySize+n+r},t.prototype.hasMetrics=function(){return void 0!==this.bodySize},t.prototype.countUpper=function(){for(var t=0,e=0;e=0&&(o=n(this,r,i)),o===this&&(o=e(this,r,i));var s=this.data.slice(o.data.replace(/-$/,"").length);return""===s?this:(this.data=s,this.setDivided(!0),this.setMetrics(t,r),o)},t.prototype.toString=function(t){return this.getData(t)},t}(),Nehan.Tcy=function(){function t(t){this.data=t}return t.prototype.isHeadNg=function(){return!1},t.prototype.isTailNg=function(){return!1},t.prototype.getData=function(){return this.data},t.prototype.getCharCount=function(){return 1},t.prototype.getAdvance=function(t,e){return this.bodySize+e},t.prototype.getCssVert=function(t){var e={};return e["text-align"]="center",Nehan.Env.isTextCombineEnable||(e["font-weight"]="normal"),e["word-break"]="normal",e.height="1em",e},t.prototype.getCssHori=function(t){var e={};return 1===this.data.length&&(e.display="inline-block",e.width=this.bodySize+"px",e["text-align"]="center"),e},t.prototype.hasMetrics=function(){return void 0!==this.bodySize},t.prototype.setMetrics=function(t,e){t.isTextVertical()?this.bodySize=e.size:this.bodySize=Nehan.TextMetrics.getMeasure(e,this.data)},t.prototype.toString=function(t){return this.getData()},t}(),Nehan.Ruby=function(){function t(t,e){this.rbs=t,this.rt=e}return t.prototype.hasMetrics=function(){return void 0!==this.advanceSize},t.prototype.getCharCount=function(){return this.rbs?this.rbs.length:0},t.prototype.getAdvance=function(t){return this.advanceSize},t.prototype.getRbs=function(){return this.rbs},t.prototype.getRbString=function(){return this.rbs.reduce(function(t,e){return t+(e.data||"")},"")},t.prototype.getRtString=function(){return this.rt?this.rt.getContent():""},t.prototype.getRtFontSize=function(){return this.rtFontSize},t.prototype.getCssVertRt=function(t){var e={};return e["css-float"]="left",e}, t.prototype.getCssHoriRt=function(t){var e={},n=this.getRtFontSize();Math.floor((t.context.style.getFontSize()-this.getRtFontSize())/3);return e["font-size"]=n+"px",e["line-height"]=n+"px",e},t.prototype.getCssVertRb=function(t){var e={};return e["css-float"]="left",e.width="1em",this.padding&&Nehan.Obj.copy(e,this.padding.getCss()),e},t.prototype.getCssHoriRb=function(t){var e={};return this.padding&&Nehan.Obj.copy(e,this.padding.getCss()),e["text-align"]="center",e["line-height"]="1em",e},t.prototype.getRtAdvance=function(t,e,n){var r=this.getRtString();return r&&" "!==r?this.rtFontSize*r.length:0},t.prototype.setMetrics=function(t,e,n){this.rtFontSize=Nehan.Display.getRtFontSize(e.size);var r=this.rbs.reduce(function(r,i){return i.setMetrics(t,e),r+i.getAdvance(t,n)},0),i=this.getRtAdvance();if(this.advanceSize=r,i>r){var o=Math.ceil((i-r)/2);this.rbs.length>0&&(this.padding=new Nehan.Padding,this.padding.setStart(t,o),this.padding.setEnd(t,o)),this.advanceSize+=o+o}},t.prototype.toString=function(t){return this.getRbString()},t}(),Nehan.Token={isText:function(t){return t instanceof Nehan.Text||t instanceof Nehan.Char||t instanceof Nehan.Word||t instanceof Nehan.Tcy||t instanceof Nehan.Ruby},isEmphaTargetable:function(t){return t instanceof Nehan.Char||t instanceof Nehan.Tcy},isNewLine:function(t){return t instanceof Nehan.Char&&t.isNewLine()},isWhiteSpace:function(t){return t instanceof Nehan.Char&&t.isWhiteSpace()}},Nehan.ListStyleType=function(){function t(t){this.type=t||"none"}var e={disc:"•",circle:"◦",square:"▪"};return t.prototype.isDecimal=function(){return"decimal"===this.type||"decimal-leading-zero"===this.type},t.prototype.isNone=function(){return"none"===this.type},t.prototype.isMark=function(){return"disc"===this.type||"circle"===this.type||"square"===this.type},t.prototype.isIncremental=function(){return!!this.isDecimal()||!!Nehan.Cardinal.getTableByName(this.type)},t.prototype.isHankaku=function(){return"lower-alpha"===this.type||"upper-alpha"===this.type||"lower-roman"===this.type||"upper-roman"===this.type||this.isMark()||this.isDecimal()},t.prototype.isZenkaku=function(){return!this.isHankaku()},t.prototype.getMarkerHtml=function(t,e,n){var r=this.getMarkerText(e);if(this.isIncremental()){if(this.isZenkaku())return Nehan.Html.tagWrap("::marker",Nehan.Html.tagWrap("span",r,{class:"tcy"}));if(t.isTextVertical())return Nehan.Html.tagWrap("::marker",Nehan.Html.tagWrap("word",r))}return Nehan.Html.tagWrap("::marker",r)},t.prototype.getMarkerText=function(t){if(this.isNone())return Nehan.Const.space;if(this.isMark())return e[this.type]||"";if(this.isIncremental()){t=Math.max(1,t);return this._getMarkerCounterString(t)+"."}return this.type},t.prototype._getMarkerCounterString=function(t){return"decimal"===this.type?t.toString(10):"decimal-leading-zero"===this.type?t<10?"0"+t.toString(10):t.toString(10):Nehan.Cardinal.getStringByName(this.type,t)},t}(),Nehan.ListStylePos=function(){function t(t){this.pos=t}return t.prototype.isOutside=function(){return"outside"===this.pos},t.prototype.isInside=function(){return"inside"===this.pos},t}(),Nehan.ListStyleImage=function(){function t(t){this.image=t}return t.prototype.getMarkerHtml=function(t,e,n){n=n||{};var r=Nehan.Css.getImageURL(this.image),i=n.width||Nehan.Config.defaultFontSize,o=n.height||Nehan.Config.defaultFontSize,s=["nehan-list-image"].concat(n.classes||[]);return Nehan.Html.tagSingle("img",{src:r,class:s.join(" "),width:i,height:o})},t}(),Nehan.ListStyle=function(){function t(t){t=t||{},this.type=new Nehan.ListStyleType(t.type||"none"),this.position=new Nehan.ListStylePos(t.position||"outside"),this.image=t.image&&"none"!==t.image?new Nehan.ListStyleImage(t.image):null}return t.prototype.isOutside=function(){return this.position.isOutside()},t.prototype.isInside=function(){return this.position.isInside()},t.prototype.isImageList=function(){return null!==this.image},t.prototype.getMarkerHtml=function(t,e,n){if(n=n||{},null!==this.image)return this.image.getMarkerHtml(t,e,n);var r=this.type.getMarkerHtml(t,e,n);return""===r&&this.isOutside()?" ":r},t}(),Nehan.TextEmphaStyle=function(){function t(t){this.value=t||"none"}var e={"filled dot":"•","open dot":"◦","filled circle":"●","open circle":"○","filled double-circle":"◉","open double-circle":"◎","filled triangle":"▲","open triangle":"△","filled sesame":"﹅","open sesame":"﹆"};return t.prototype.isEnable=function(){return"none"!=this.value},t.prototype.setValue=function(t){this.value=t},t.prototype.getText=function(){return this.isEnable()?e[this.value]||this.value||e["filled dot"]:""},t.prototype.getCss=function(){return{}},t}(),Nehan.TextEmphaPos=function(){function t(t){Nehan.Obj.merge(this,{hori:"over",vert:"right"},t||{})}return t.prototype.getCss=function(t){return{}},t}(),Nehan.TextEmpha=function(){function t(t){t=t||{},this.style=t.style||new Nehan.TextEmphaStyle,this.position=t.position||new Nehan.TextEmphaPos,this.color=t.color||new Nehan.Color(Nehan.Config.defaultFontColor)}return t.prototype.isEnable=function(){return this.style&&this.style.isEnable()},t.prototype.getText=function(){return this.style?this.style.getText():""},t.prototype.getExtent=function(t){if(!this.isEnable())return t;var e=Math.floor(t*(1+Nehan.Config.defaultEmphaTextRate));return t%2==0?e:e+1},t.prototype.getCssVertEmphaWrap=function(t,e){var n={},r=t.context.style.getFontSize();return n["text-align"]="left",n.width=this.getExtent(r)+"px",n.height=e.getAdvance(t.context.style.flow,t.context.style.letterSpacing||0)+"px",n.position="relative",n},t.prototype.getCssHoriEmphaWrap=function(t,e){var n={},r=t.getFontSize();return n.display="inline-block",n.width=e.getAdvance(t.context.style.flow,t.context.style.letterSpacing)+"px",n.height=this.getExtent(r)+"px",n},t}(),Nehan.Spacing={add:function(t,e,n){t instanceof Nehan.Char?this._addCharSpacing(t,e,n):t instanceof Nehan.Word&&this._addWordSpacing(t,e,n)},_addCharSpacing:function(t,e,n){t.isKakkoStart()?this._setSpacingStart(t,e):(t.isKakkoEnd()||t.isKutenTouten())&&this._setSpacingEnd(t,n)},_addWordSpacing:function(t,e,n){e&&e instanceof Nehan.Char&&!e.isSpaceGroup()&&void 0===e.spaceRateEnd&&(t.spaceRateStart=.25),!(n&&n instanceof Nehan.Char)||n.isSpaceGroup()||n.isKakkoStart()||n.isKutenTouten()&&n.isZenkaku()||(t.spaceRateEnd=.25)},_setSpacingStart:function(t,e){var n=this._getTextSpaceStart(t,e);n>0&&(t.spaceRateStart=n)},_setSpacingEnd:function(t,e){if(!(e instanceof Nehan.Char&&e.isTenten())){var n=this._getTextSpaceEnd(t,e);n>0&&(t.spaceRateEnd=n)}},_getTextSpaceStart:function(t,e){return null===e?.5:e instanceof Nehan.Char&&e.isKakkoStart()?0:.5},_getTextSpaceEnd:function(t,e){return null===e?.5:e instanceof Nehan.Char&&t.isKutenTouten()&&e.isKakkoStart()?0:e instanceof Nehan.Char&&(e.isKakkoEnd()||e.isKutenTouten())?0:.5}},Nehan.PartitionUnit=function(){function t(t){this.weight=t.weight||0,this.isStatic=t.isStatic||!1}return t.prototype.getSize=function(t,e){return Math.floor(t*this.weight/e)},t.prototype.mergeTo=function(t){return this.isStatic&&!t.isStatic?this:!this.isStatic&&t.isStatic?t:this.weight>t.weight?this:t},t}(),Nehan.Partition=function(){function t(t){this._punits=t||[]}var e=function(t,e){var n=t.filter(function(t){return t=e});if(0===i.length)return t;var o=Math.floor(r/i.length);return t.map(function(t){return t=e?t-o:t})};return t.prototype.get=function(t){return this._punits[t]||null},t.prototype.getLength=function(){return this._punits.length},t.prototype.getTotalWeight=function(){return this._punits.reduce(function(t,e){return t+e.weight},0)},t.prototype.mergeTo=function(t){if(this.getLength()!==t.getLength())throw"Partition::mergeTo, invalid merge target(length not same)";var e=this._punits.map(function(e,n){return e.mergeTo(t.get(n))});return new Nehan.Partition(e)},t.prototype.mapMeasure=function(t){var n=this.getTotalWeight(),r=this._punits.map(function(e){return e.getSize(t,n)});return e(r,Nehan.Config.minTableCellSize)},t}(),Nehan.PartitionHashSet=function(){function t(){Nehan.HashSet.call(this)}return Nehan.Class.extend(t,Nehan.HashSet),t.prototype.merge=function(t,e){return t.mergeTo(e)},t.prototype.getSizes=function(t){return this.get(t.partitionCount).mapMeasure(t.measure)},t}(),Nehan.LayoutContext=function(){function t(t,e){this.block=t,this.inline=e}return t.prototype.addBlockElement=function(t,e){this.block.addElement(t,e)},t.prototype.getBlockElements=function(){return this.block.getElements()},t.prototype.getBlockCount=function(){return this.getBlockElements().length},t.prototype.getBlockCurExtent=function(){return this.block.getCurExtent()},t.prototype.getBlockMaxExtent=function(){return this.block.getMaxExtent()},t.prototype.getBlockRestExtent=function(){return this.block.getRestExtent()},t.prototype.getBlockLineNo=function(){return this.block.getLineNo()},t.prototype.incBlockLineNo=function(){return this.block.incLineNo()},t.prototype.isInlineEmpty=function(){return this.inline.isEmpty()},t.prototype.isHyphenated=function(){return this.inline.isHyphenated()},t.prototype.isLineOver=function(){return this.inline.isLineOver()},t.prototype.hasLineBreak=function(){return this.inline.hasLineBreak()},t.prototype.resumeLine=function(t){this.inline.resumeLine(t)},t.prototype.setLineBreak=function(t){this.inline.setLineBreak(t)},t.prototype.setLineOver=function(t){this.inline.setLineOver(t)},t.prototype.setBreakAfter=function(t){this.block.setBreakAfter(t)},t.prototype.setHyphenated=function(t){this.inline.setHyphenated(t)},t.prototype.setHangingPunctuation=function(t){this.hangingPunctuation=t},t.prototype.getHangingPunctuation=function(){return this.hangingPunctuation||null},t.prototype.addInlineMeasure=function(t){this.inline.addMeasure(t)},t.prototype.addInlineBoxElement=function(t,e){this.inline.addBoxElement(t,e)},t.prototype.addInlineTextElement=function(t,e){this.inline.addTextElement(t,e)},t.prototype.getInlineLastElement=function(){return this.inline.getLastElement()},t.prototype.getInlineElements=function(){return this.inline.getElements()},t.prototype.getInlineCurMeasure=function(){return this.inline.getCurMeasure()},t.prototype.getInlineRestMeasure=function(){return this.inline.getRestMeasure()},t.prototype.getInlineMaxMeasure=function(){return this.inline.getMaxMeasure()},t.prototype.getInlineMaxExtent=function(){return this.inline.getMaxExtent()},t.prototype.getInlineMaxFontSize=function(){return this.inline.getMaxFontSize()},t.prototype.getInlineCharCount=function(){return this.inline.getCharCount()},t.prototype.hyphenateSweep=function(t){return this.inline.hyphenateSweep(t)},t.prototype.popInlineElement=function(){return this.inline.popElement()},t.prototype.isBreakAfter=function(){return this.block.isBreakAfter()},t}(),Nehan.BlockContext=function(){function t(t,e){e=e||{},this.curExtent=0,this.maxExtent=t,this.pushedElements=[],this.elements=[],this.pulledElements=[],this.lineNo=e.lineNo||0,this.breakAfter=!1}return t.prototype.addElement=function(t,e){this.curExtent+=e,t.pushed?this.pushedElements.push(t):t.pulled?this.pulledElements.unshift(t):this.elements.push(t)},t.prototype.getCurExtent=function(){return this.curExtent},t.prototype.getRestExtent=function(){return this.maxExtent-this.curExtent},t.prototype.getMaxExtent=function(){return this.maxExtent},t.prototype.getLineNo=function(){return this.lineNo},t.prototype.incLineNo=function(){return this.lineNo++},t.prototype.getElements=function(){return this.pulledElements.concat(this.elements).concat(this.pushedElements)},t.prototype.setBreakAfter=function(t){this.breakAfter=t},t.prototype.isBreakAfter=function(){return this.breakAfter},t}(),Nehan.InlineContext=function(){function t(t){this.charCount=0,this.curMeasure=0,this.maxMeasure=t,this.maxExtent=0,this.maxFontSize=0,this.elements=[],this.lineBreak=!1,this.lineOver=!1,this.hyphenated=!1}return t.prototype.isEmpty=function(){return!this.lineBreak&&0===this.elements.length},t.prototype.isHyphenated=function(){return this.hyphenated},t.prototype.isLineOver=function(){return this.lineOver},t.prototype.hasLineBreak=function(){return this.lineBreak},t.prototype.setLineBreak=function(t){this.lineBreak=t},t.prototype.setLineOver=function(t){this.lineOver=t},t.prototype.setHyphenated=function(t){this.hyphenated=t},t.prototype.addMeasure=function(t){this.curMeasure+=t},t.prototype.addTextElement=function(t,e){this.elements.push(t),this.curMeasure+=e,t.getCharCount&&(this.charCount+=t.getCharCount())},t.prototype.addBoxElement=function(t,e){this.elements.push(t),this.curMeasure+=e,this.charCount+=t.charCount||0,t.maxExtent?this.maxExtent=Math.max(this.maxExtent,t.maxExtent):this.maxExtent=Math.max(this.maxExtent,t.getLayoutExtent()),t.maxFontSize&&(this.maxFontSize=Math.max(this.maxFontSize,t.maxFontSize)),t.hyphenated&&(this.hyphenated=!0)},t.prototype.getLastElement=function(){return Nehan.List.last(this.elements)},t.prototype.getElements=function(){return this.elements},t.prototype.getCurMeasure=function(){return this.curMeasure},t.prototype.getRestMeasure=function(){return this.maxMeasure-this.curMeasure},t.prototype.getMaxMeasure=function(){return this.maxMeasure},t.prototype.getMaxExtent=function(){return this.isEmpty()?0:this.maxExtent},t.prototype.getMaxFontSize=function(){return this.maxFontSize},t.prototype.getCharCount=function(){return this.charCount},t.prototype.popElement=function(){return this.elements.pop()},t.prototype.resumeLine=function(t){this.elements=t.elements,this.curMeasure=t.inlineMeasure,this.maxFontSize=t.maxFontSize||this.maxFontSize,this.maxExtent=t.maxExtent||this.maxExtent,this.charCount=t.charCount||this.charCount},t.prototype.hyphenateSweep=function(t){var e=this.elements.length-1,n=e,r=this.elements[n]||null,i=function(t){return!!(t&&t.isTailNg&&t.isTailNg())},o=function(t){return!!(t&&t.isHeadNg&&t.isHeadNg())};if(!i(r)&&!o(t))return null;if(r&&r instanceof Nehan.Word&&r.isDivided())return null;for(;n>=0&&(r=this.elements[n],o(t)||i(r));)t=r,n--;return n<0?r:0<=n&&n]*>/,n=function(t,e,r,i){var o=t.indexOf(i);if(o<0)return-1;var s=t.match(r),a=s?s.index:-1;if(a<0||o","g"),"")},t)};return t.prototype._normalize=function(t){return t=t.replace(/(<\/[^>]+>)/gm,function(t,e){return e.toLowerCase()}),this.singleTagNames&&(t=r(t,this.singleTagNames)),t},t.prototype.isEmpty=function(){return""===this.src},t.prototype.get=function(){var t=this._getToken();return t&&(t.spos=this.pos),t},t.prototype.getSrc=function(){return this.src},t.prototype.getSeekPercent=function(t){return Math.round(100*t/this.src.length)},t.prototype._stepBuff=function(t){var e=this.buff.substring(0,t);return this.pos+=t,this.buff=this.buff.slice(t),e},t.prototype._getToken=function(){if(""===this.buff)return null;var t,n;return null===(t=this.buff.match(e))?(n=this._stepBuff(this.buff.length),new Nehan.Text(n)):0===t.index?this._parseTag(t[0]):(n=this._stepBuff(t.index),n=Nehan.Utils.trimHeadCRLF(n),new Nehan.Text(n))},t.prototype._getTagContent=function(t){var e=t.name,r=new RegExp("<"+e+"[\\s|>]"),i="",o=n(this.buff,e,r,i);if(o>=0)return{closed:!0,content:this.buff.substring(0,o)};if(!t.hasAttr()&&Nehan.Config.enableAutoCloseTag){var s=this._findAutoClosePos(e);if(s>0)return{closed:!1,content:this.buff.substring(0,s)}}return console.warn("invalid syntax:%s is not closed properly, use rest content",e),{closed:!1,content:this.buff}},t.prototype._findAutoClosePos=function(t){switch(t){case"p":return this._selectClosePos(["address","article","aside","blockquote","div","dl","fieldset","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","main","nav","ol","p","pre","section","table","ul"]);case"dt":case"dd":return this._selectClosePos(["dd","dt"]);case"li":return this._selectClosePos(["li"]);case"thead":case"tbody":case"tfoot":return this._selectClosePos(["thead","tbody","tfoo"]);case"tr":return this._selectClosePos(["tr"]);case"td":case"th":return this._selectClosePos(["td","th"]);default:return-1}},t.prototype._selectClosePos=function(t){var e=t.map(function(t){return this.buff.indexOf("<"+t)}.bind(this)).filter(function(t){return t>0}).sort(function(t,e){return t-e});return 0===e.length?-1:e[0]},t.prototype._parseTag=function(t){var e=new Nehan.Tag(t);this._stepBuff(t.length);var n=e.getName();return Nehan.List.exists(this.singleTagNames,Nehan.Closure.eq(n))?(e._single=!0,e):this._parseChildContentTag(e)},t.prototype._parseChildContentTag=function(t){var e=this._getTagContent(t);return t.setContent(e.content),e.closed?this._stepBuff(e.content.length+t.name.length+3):this._stepBuff(e.content.length),t},t}(),Nehan.TextLexer=function(){function t(t){Nehan.HtmlLexer.call(this,t)}var e=/^(?:\d\d|!\?|!!|\?!|\?\?)/,n=/^\d+\.\d+/,r=/^\d+/,i=/^(?:\d+[.:\/])+\d+(?!\d)/,o=/^(?:\d+,)+\d+/,s=/^&.+?;/,a=/^[a-zA-Z0-9!?]/,h=["ff","fi","fl","ffi","ffl","ſt","st"];return Nehan.Class.extend(t,Nehan.HtmlLexer),t.prototype._getToken=function(){if(""===this.buff)return null;var t;if(t=this._matchCharRef())return this._parseAsCharRef(t);if(t=this._matchWord()){var e=this._parseAsWord(t);if(0===this.buff.indexOf("­")){e.data+="­",this._stepBuff(5);var n=this._getToken();n&&(e.data+=n.data)}return e}return this._parseAsChar()},t.prototype._parseAsChar=function(){var t=this.buff.charCodeAt(0);if(55296<=t&&t<=56319){var e=this.buff.charCodeAt(1);if(e&&56320<=e&&e<=57343)return new Nehan.Char({data:this._stepBuff(2)})}return new Nehan.Char({data:this._stepBuff(1)})},t.prototype._parseAsCharRef=function(t){var e=new Nehan.Char({ref:this._stepBuff(t.length)});if(Nehan.List.exists(h,Nehan.Closure.eq(t))){var n=this._parseAsWord(t);if(n&&n instanceof Nehan.Word)return n.data=t+n.data,n;n&&(this.buff=n.data+this.buff)}return e},t.prototype._parseAsWord=function(t){var s;return 1===t.length?a.test(t)?new Nehan.Tcy(this._stepBuff(1)):new Nehan.Char({data:this._stepBuff(1)}):2===t.length&&e.test(t)?new Nehan.Tcy(this._stepBuff(2)):(s=this._match(o))?new Nehan.Word(this._stepBuff(s.length)):(s=this._match(i))?new Nehan.Word(this._stepBuff(s.length)):(s=this._match(n))?new Nehan.Word(this._stepBuff(s.length)):(s=this._match(r))?s.length<=2?new Nehan.Tcy(this._stepBuff(s.length)):new Nehan.Word(this._stepBuff(s.length)):(s=this._match(/^[^\d]\d{1,2}$/,t),s?new Nehan.Word(this._stepBuff(1)):new Nehan.Word(this._stepBuff(t.length)))},t.prototype._match=function(t,e){e=e||this.buff;var n=e.match(t);return n?n[0]:null},t.prototype._matchWord=function(t){return this._match(Nehan.Config.rexWord,t||null)},t.prototype._matchCharRef=function(t){return this._match(s,t||null)},t}(),Nehan.UprightTextLexer=function(){function t(t){Nehan.TextLexer.call(this,t)}return Nehan.Class.extend(t,Nehan.TextLexer),t.prototype._getToken=function(){if(""===this.buff)return null;var t,e;return(t=this._matchCharRef())?(e=this._stepBuff(t.length),new Nehan.Tcy(e)):(e=this._stepBuff(1),this._matchWord(e)?new Nehan.Tcy(e):new Nehan.Char({data:e}))},t}(),Nehan.TokenStream=function(){function t(t){t=t||{},this.lexer=t.lexer||null,this.tokens=t.tokens||[],this.pos=0,this.lexer&&0===this.tokens.length&&this._loadTokens(t.filter||null)}var e=function(t){var e=t[0],n=t[t.length-1];e&&e instanceof Nehan.Tag&&(e.setFirstChild(!0),e.setOnlyChild(1===t.length)),n&&n instanceof Nehan.Tag&&n.setLastChild(!0)},n=function(t){t[0].setFirstOfType(!0),t[0].setOnlyOfType(1===t.length),t[t.length-1].setLastOfType(!0)};return t.prototype.hasNext=function(){return this.pos0&&t[0]instanceof Nehan.Text&&t[0].isWhiteSpaceOnly()&&(t=t.slice(1)),Nehan.List.iter(t,function(t){if(t instanceof Nehan.Tag!=!1){var e=t.getName();r[e]?r[e].push(t):r[e]=[t]}}),e(t);for(var i in r)n(r[i])},t}(),Nehan.RubyTokenStream=function(){function t(t){this.tokens=this._parse(new Nehan.TokenStream({lexer:new Nehan.HtmlLexer(t)})),this.pos=0}return Nehan.Class.extend(t,Nehan.TokenStream),t.prototype._parse=function(t){for(var e=[];t.hasNext();)e.push(this._parseRuby(t));return e},t.prototype._parseRuby=function(t){for(var e=[],n=null;;){var r=t.get();if(null===r)break;if(r instanceof Nehan.Tag&&"rt"===r.getName()){n=r;break}r instanceof Nehan.Tag&&"rb"===r.getName()&&(e=this._parseRb(r.getContent())),r instanceof Nehan.Text&&(e=this._parseRb(r.getContent()))}return 0===e.length&&null!==n&&(e=this._parseRb(n.getContent()),n=new Nehan.Tag("rt"," ")),e.length>0&&null===n&&(n=new Nehan.Tag("rt"," ")),new Nehan.Ruby(e,n)},t.prototype._parseRb=function(t){return new Nehan.TokenStream({lexer:new Nehan.TextLexer(t)}).getTokens()},t}(),Nehan.DefaultStyle=function(){var t={display:"block","box-sizing":"content-box",float:"start","font-size":"4em",measure:"1em",extent:"1em",padding:{before:"0.1em"},"line-height":"1",onload:function(t){if(!t.isTextVertical()){var e=t.getMarkup(),n=t.getFont(),r=Math.floor(.1*n.size),i=Nehan.TextMetrics.getMeasure(n,e.getContent());t.setCssAttr("measure",i+r+"px")}}},e=function(t){var e=t.getParentFont().size,n=t.getRootFont().size;return{before:0===t.getCurExtent()?0:Math.floor(2*n-.14285*e),after:n}};return{create:function(){return{a:{display:"inline"},abbr:{display:"inline"},address:{display:"inline","font-style":"italic"},area:{},article:{display:"block"},aside:{display:"block"},audio:{},b:{display:"inline","font-weight":"bold"},base:{display:"none"},bdi:{display:"inline"},bdo:{display:"inline"},blockquote:{color:"#666666",display:"block",padding:{start:"1em",end:"1em",before:"0.5em",after:"0.5em"},margin:{after:"1.5em"}},body:{display:"block",flow:"lr-tb","box-sizing":"content-box","hanging-punctuation":"allow-end","text-align":"justify"},br:{display:"inline"},button:{display:"inline"},canvas:{display:"inline"},caption:{display:"table-caption","text-align":"center",margin:{after:"0.5em"}},cite:{display:"inline"},code:{display:"inline"},col:{display:"table-column"},colgroup:{display:"table-column-group"},command:{},datalist:{},dd:{display:"block",margin:{start:"1em",end:"1em",after:"1.6em"}},del:{color:"#666666",display:"inline"},details:{display:"block"},dfn:{display:"inline","font-style":"italic"},div:{display:"block"},dl:{display:"block"},dt:{display:"block","font-weight":"bold",margin:{after:"1em"}},em:{display:"inline","font-style":"italic"},embed:{},fieldset:{display:"block",padding:{start:"1em",end:"0.2em",before:"0.2em",after:"1em"},margin:{after:"1.5em"},"border-width":"1px"},figure:{display:"block"},figcaption:{display:"block","text-align":"center","font-size":"0.8em"},footer:{display:"block"},font:{display:"inline"},form:{display:"block"},h1:{display:"block","font-size":Nehan.Config.headerFontSizes.h1,"font-weight":"bold","line-height":Nehan.Config.headerLineHeight,margin:e},h2:{display:"block","font-size":Nehan.Config.headerFontSizes.h2,"font-weight":"bold","line-height":Nehan.Config.headerLineHeight,margin:e},h3:{display:"block","font-size":Nehan.Config.headerFontSizes.h3,"font-weight":"bold","line-height":Nehan.Config.headerLineHeight,margin:e},h4:{display:"block","font-size":Nehan.Config.headerFontSizes.h4,"font-weight":"bold","line-height":Nehan.Config.headerLineHeight,margin:e},h5:{display:"block","font-size":Nehan.Config.headerFontSizes.h5,"font-weight":"bold","line-height":Nehan.Config.headerLineHeight,margin:e},h6:{display:"block","font-weight":"bold","font-size":Nehan.Config.headerFontSizes.h6,"line-height":Nehan.Config.headerLineHeight,margin:e},head:{display:"none"},header:{display:"block"},hr:{display:"block","box-sizing":"content-box","border-color":"rgba(34,36,38,.15)","border-style":"solid","line-height":"1",margin:{after:"1em"},extent:"1px","border-width":{after:"1px"}},"hr.space":{"border-width":"0px"},"hr.break-before":{"border-width":"0px"},"hr.break-after":{"border-width":"0px"},html:{display:"block"},i:{display:"inline"},iframe:{display:"block"},ins:{},img:{"box-sizing":"content-box",display:"inline"},input:{display:"inline"},kbd:{display:"inline"},keygen:{display:"none"},label:{display:"inline"},legend:{display:"block","font-weight":"bold","line-height":"1.5"},li:{display:"list-item",margin:{after:"0.6em"}},link:{},main:{display:"block"},map:{},mark:{display:"inline"},menu:{display:"block"},meta:{},meter:{display:"inline"},nav:{display:"block"},noscript:{},object:{display:"inline"},ol:{display:"block","list-style-image":"none","list-style-position":"outside","list-style-type":"decimal",margin:{before:"1em"}},optgroup:{},option:{},output:{},p:{display:"block",margin:{after:"1rem"}},param:{display:"none"},pre:{display:"block","white-space":"pre"},progress:{display:"inline"},q:{display:"block"},rb:{display:"inline"},rp:{display:"inline"},ruby:{display:"inline"},rt:{"font-size":"0.5em","line-height":"1.0",display:"inline"},s:{display:"inline"},samp:{display:"inline"},script:{display:"inline"},section:{display:"block"},select:{},small:{display:"inline","font-size":"0.8em"},source:{display:"none"},span:{display:"inline"},strong:{display:"inline","font-weight":"bold"},style:{display:"inline"},sub:{display:"inine"},summary:{display:"inline"},sup:{display:"inine"},table:{display:"table","table-layout":"fixed","background-color":"white","border-collapse":"collapse","border-color":"rgba(34,36,38,.15)","border-style":"solid","border-width":"1px",margin:{start:"0.5em",end:"0.5em",after:"1.6em"}},tbody:{display:"table-row-group","border-collapse":"inherit"},td:{display:"table-cell","border-width":"1px","border-color":"rgba(34,36,38,.15)","border-collapse":"inherit","border-style":"solid",padding:{start:"0.5em",end:"0.5em",before:"0.4em",after:"0.4em"}},textarea:{display:"inline"},tfoot:{display:"table-footer-group","border-width":"1px","border-color":"rgba(34,36,38,.15)","border-collapse":"inherit","border-style":"solid","font-style":"italic"},th:{display:"table-cell","line-height":Nehan.Config.headerLineHeight,"border-width":"1px","border-color":"rgba(34,36,38,.15)","border-collapse":"inherit","border-style":"solid",padding:{start:"0.5em",end:"0.5em",before:"0.4em",after:"0.4em"}},thead:{display:"table-header-group","font-weight":"bold","background-color":"#f9fafb","border-width":"1px","border-color":"rgba(34,36,38,.15)","border-collapse":"inherit","border-style":"solid"},time:{display:"inline"},title:{},tr:{display:"table-row","border-collapse":"inherit","border-color":"rgba(34,36,38,.15)","border-width":"1px","border-style":"solid"},track:{},u:{display:"inline"},ul:{display:"block","list-style-image":"none","list-style-type":"disc","list-style-position":"outside",margin:{before:"1em"}},var:{display:"inline"},video:{display:"inline"},wbr:{display:"inline"},"?xml":{},"!doctype":{},"page-break":{display:"inline"},".rounded":{padding:{before:"1.6em",end:"1.0em",after:"1.6em",start:"1.0em"},"border-radius":"10px"},".xx-large":{"font-size":Nehan.Config.absFontSizes["xx-large"]},".x-large":{"font-size":Nehan.Config.absFontSizes["x-large"]},".large":{"font-size":Nehan.Config.absFontSizes.large},".medium":{"font-size":Nehan.Config.absFontSizes.medium},".small":{"font-size":Nehan.Config.absFontSizes.small},".x-small":{"font-size":Nehan.Config.absFontSizes["x-small"]},".xx-small":{"font-size":Nehan.Config.absFontSizes["xx-small"]},".larger":{"font-size":Nehan.Config.absFontSizes.larger},".smaller":{"font-size":Nehan.Config.absFontSizes.smaller},".content-box":{"box-sizing":"content-box"},".border-box":{"box-sizing":"border-box"},".margin-box":{"box-sizing":"margin-box"},".disp-none":{display:"none"},".disp-block":{display:"block"},".disp-inline":{display:"inline"},".disp-iblock":{display:"inline-block"},".text.align.start":{"text-align":"start"},".ta-start":{"text-align":"start"},".text.align.center":{"text-align":"center"},".ta-center":{"text-align":"center"},".text.align.end":{"text-align":"end"},".ta-end":{"text-align":"end"},".ta-justify":{"text-align":"justify"},".float.start":{float:"start"},".float-start":{float:"start"},".float.end":{float:"end"},".float-end":{float:"end"},".clear-start":{clear:"start"},".clear-end":{clear:"end"},".clear-both":{clear:"both"},".flow-lr-tb":{flow:"lr-tb"},".flow-tb-rl":{flow:"tb-rl"},".flow-tb-lr":{flow:"tb-lr"},".flow-rl-tb":{flow:"rl-tb"},".flow-flip":{flow:"flip"},".lsp-inside":{"list-style-position":"inside"},".lsp-outside":{"list-style-position":"outside"},".lst-none":{"list-style-type":"none"},".lst-decimal":{"list-style-type":"decimal"},".lst-disc":{"list-style-type":"disc"},".lst-circle":{"list-style-type":"circle"},".lst-square":{"list-style-type":"square"},".lst-decimal-leading-zero":{"list-style-type":"decimal-leading-zero"},".lst-lower-alpha":{"list-style-type":"lower-alpha"},".lst-upper-alpha":{"list-style-type":"upper-alpha"},".lst-lower-latin":{"list-style-type":"lower-latin"},".lst-upper-latin":{"list-style-type":"upper-latin"},".lst-lower-roman":{"list-style-type":"lower-roman"},".lst-upper-roman":{"list-style-type":"upper-roman"},".lst-lower-greek":{"list-style-type":"lower-greek"},".lst-upper-greek":{"list-style-type":"upper-greek"},".lst-cjk-ideographic":{"list-style-type":"cjk-ideographic"},".lst-hiragana":{"list-style-type":"hiragana"},".lst-hiragana-iroha":{"list-style-type":"hiragana-iroha"},".lst-katakana":{"list-style-type":"katakana"},".lst-katakana-iroha":{"list-style-type":"katakana-iroha"},".tcy":{"text-combine-upright":"horizontal"},".empha.dot.filled":{"text-emphasis-style":"filled dot"},".empha-dot-filled":{"text-emphasis-style":"filled dot"},".empha.dot.open":{"text-emphasis-style":"open dot"},".empha-dot-open":{"text-emphasis-style":"open dot"},".empha.circle.filled":{"text-emphasis-style":"filled circle"},".empha-circle-filled":{"text-emphasis-style":"filled circle"},".empha.circle.open":{"text-emphasis-style":"open circle"},".empha-circle-open":{"text-emphasis-style":"open circle"},".empha.double.circle.filled":{ "text-emphasis-style":"filled double-circle"},".empha-double-circle-filled":{"text-emphasis-style":"filled double-circle"},".empha.double.circle.open":{"text-emphasis-style":"open double-circle"},".empha-double-circle-open":{"text-emphasis-style":"open double-circle"},".empha.triangle.filled":{"text-emphasis-style":"filled triangle"},".empha-triangle-filled":{"text-emphasis-style":"filled triangle"},".empha.triangle.open":{"text-emphasis-style":"open triangle"},".empha-triangle-open":{"text-emphasis-style":"open triangle"},".empha.sesame.filled":{"text-emphasis-style":"filled sesame"},".empha-sesame-filled":{"text-emphasis-style":"filled sesame"},".empha.sesame.open":{"text-emphasis-style":"open sesame"},".empha-sesame-open":{"text-emphasis-style":"open sesame"},".break-before":{"break-before":"always"},".break-after":{"break-after":"always"},".wb-all":{"word-break":"break-all"},".wb-normal":{"word-break":"normal"},".wb-keep":{"word-break":"keep-all"},"ul ul":{margin:{before:"0"}},"ul ol":{margin:{before:"0"}},"ol ol":{margin:{before:"0"}},"ol ul":{margin:{before:"0"}},".drop-caps::first-letter":t,".dropcaps::first-letter":t,".gap-start":{margin:{start:"1em"}},".gap-end":{margin:{end:"1em"}},".gap-after":{margin:{after:"1em"}},".gap-before":{margin:{before:"1em"}}}}}}(),Nehan.Box=function(){function t(t){t=t||{},this._type=t.type||"block",this.size=t.size||new Nehan.BoxSize(0,0),this.display=t.display||"block",this.context=t.context,this.css=t.css||{},this.content=void 0!==t.content?t.content:null,this.edge=t.edge||null,this.classes=t.classes||[],this.charCount=t.charCount||0,this.breakAfter=t.breakAfter||!1,this.elements=t.elements||[],this.pushed=t.pushed||!1,this.pulled=t.pulled||!1,this.elements.forEach(function(t){t.parent=this}.bind(this))}var e=function(t){return t.reduce(function(t,n){return n instanceof Nehan.Box?t.concat(e(n.elements||[])):n?t.concat(n):t},[])};return t.prototype.isLine=function(){return"line-block"===this._type},t.prototype.isResumableLine=function(t){return!!this.isLine()&&(!this.hasLineBreak&&(!this.hyphenated&&(0!==this.getCacheCount()&&((!this.context.layoutContext||this.context.layoutContext.getInlineMaxMeasure()!==t)&&this.inlineMeasure>"},t.prototype.getDomClassName=function(){return this.classes?this.classes.map(Nehan.Css.addNehanPrefix).join(" "):""},t.prototype.getContent=function(){return this.content||null},t.prototype.getDomHook=function(){var t=this.context.style.getCssAttr("oncreate")||null;return this.isTextBlock()?this.context.style.getCssAttr("ontext")||null:this.isLine()?this.context.style.getCssAttr("online")||t:this.context.style.getCssAttr("onblock")||t},t.prototype.getAttrs=function(){return this.isTextBlock()?null:this.context.style.markup.attrs},t.prototype.getBoxCss=function(){switch(this.display){case"block":return this.getCssBlock();case"inline":return this.getCssInline();case"inline-block":return this.getCssInlineBlock()}return console.error("undefined display:",this.display),{width:0,height:0,display:"none"}},t.prototype.getFlow=function(){return this.context.style.flow},t.prototype.getCssBlock=function(){return this.context.style.getCssBlock(this)},t.prototype.getCssInline=function(){return this.isTextBlock()?this.context.style.getCssTextBlock(this):this.context.style.getCssLineBlock(this)},t.prototype.getCssInlineBlock=function(){return this.context.style.getCssInlineBlock(this)},t.prototype.getCssImage=function(t){return this.context.style.getCssImage(t,this)},t.prototype.getContentMeasure=function(t){return t=t||this.context.style.flow,this.size.getMeasure(t)},t.prototype.getContentExtent=function(t){return t=t||this.context.style.flow,this.size.getExtent(t)},t.prototype.getContentWidth=function(){return this.size.width},t.prototype.getContentHeight=function(){return this.size.height},t.prototype.getEdgeMeasure=function(t){return t=t||this.context.style.flow,this.edge?this.edge.getMeasure(t):0},t.prototype.getEdgeExtent=function(t){return t=t||this.context.style.flow,this.edge?this.edge.getExtent(t):0},t.prototype.getLayoutMeasure=function(t){return t=t||this.context.style.flow,this.context.style.isPositionAbsolute()?0:this.getContentMeasure(t)+this.getEdgeMeasure(t)},t.prototype.getLayoutExtent=function(t){return t=t||this.context.style.flow,this.context.style.isPositionAbsolute()?0:this.getContentExtent(t)+this.getEdgeExtent(t)},t.prototype.clearBorderBefore=function(){return this.edge&&this.edge.clearBorderBefore(this.context.style.flow),this},t.prototype.clearBorderAfter=function(){return this.edge&&this.edge.clearBorderAfter(this.context.style.flow),this},t.prototype.resizeExtent=function(t,e){return this.size.setExtent(t,e),this},t}(),Nehan.DocumentContext=function(){function t(){this.documentLang=Nehan.Config.defaultLang,this.documentType="html",this.documentHeader=null,this.pages=[],this.charPos=0,this.anchors={},this.outlineContexts=[],this.documentId=e++,this.headerId=0,this.blockId=0,this.paragraphId=0,this.lineBreakCount=0}var e=0;return t.prototype.setDocumentType=function(t){this.documentType=t},t.prototype.getDocumentType=function(){return this.documentType},t.prototype.setDocumentHeader=function(t){this.documentHeader=t},t.prototype.getDocumentHeader=function(){return this.documentHeader},t.prototype.stepCharPos=function(t){this.charPos+=t},t.prototype.getCharPos=function(){return this.charPos},t.prototype.getPageNo=function(){return this.pages.length},t.prototype.getPageCount=function(){return this.pages.length},t.prototype.addPage=function(t){this.pages.push(t)},t.prototype.addOutlineContext=function(t){this.outlineContexts.push(t)},t.prototype.addAnchor=function(t){this.anchors[t]=this.getPageNo()},t.prototype.getAnchorPageNo=function(t){return void 0===this.anchors[t]?null:this.anchors[t]},t.prototype.genHeaderId=function(){return[e,this.headerId++].join("-")},t.prototype.genBlockId=function(){return this.blockId++},t.prototype.incLineBreakCount=function(){this.lineBreakCount++},t.prototype.getParagraphId=function(){return[this.blockId,this.lineBreakCount].join("-")},t.prototype.createOutlineElementByName=function(t,e){return this._getOutlineContextByName(t).reduce(function(t,n){var r=this._convertOutlineContextToElement(n,e);return r?t.concat(r):t}.bind(this),[])},t.prototype._getOutlineContextByName=function(t){return this.outlineContexts.filter(function(e){return e.getMarkupName()===t})},t.prototype._convertOutlineContextToElement=function(t,e){var n=Nehan.OutlineContextParser.parse(t);return n?Nehan.SectionTreeConverter.convert(n,e):null},t}(),Nehan.PageEvaluator=function(){function t(t){this.context=t,this.evaluator=this._getEvaluator()}return t.prototype._getEvaluator=function(){var t=this.context.selectors.get("body")||new Nehan.SelectorEntry("body",{flow:Nehan.Config.defaultBoxFlow}),e=t.getEntries().flow||Nehan.Config.defaultBoxFlow;return"tb-rl"===e||"tb-lr"===e?new Nehan.VertEvaluator(this.context):new Nehan.HoriEvaluator(this.context)},t.prototype.evaluate=function(t){return t?new Nehan.Page({tree:t,element:this.evaluator.evaluate(t),text:t.text,percent:t.percent,seekPos:t.seekPos,pageNo:t.pageNo,charPos:t.charPos,charCount:t.charCount}):null},t}(),Nehan.PageParser=function(){function t(t){this.generator=t}var e=Nehan.Closure.animationFrame();return t.prototype.parse=function(t){if(t=Nehan.Obj.merge({},{capturePageText:!1,maxPageCount:Nehan.Config.maxPageCount,onPage:null,onComplete:function(t,e){},onProgress:function(t,e){},onError:function(t){}},t||{}),t.onPage){var e=t.onProgress;t.onProgress=function(n,r){e(n,r);var i=this.generator.context.getPage(n.pageNo);i&&t.onPage(i,r)}.bind(this)}this._setTimeStart(),this._parse(t)},t.prototype._setTimeStart=function(){return this._timeStart=(new Date).getTime(),this._timeStart},t.prototype._getTimeElapsed=function(){return(new Date).getTime()-this._timeStart},t.prototype._parse=function(t){if(!this.generator.hasNext()||this.generator.context.yieldCount>=t.maxPageCount)return void t.onComplete.call(this,this._getTimeElapsed(),this.generator.context);var n=this.generator.yield();n&&(t.capturePageText&&(n.text=n.toString()),t.onProgress.call(this,n,this.generator.context)),e(function(){this._parse(t)}.bind(this))},t}(),Nehan.SelectorContext=function(){function t(t,e,n){this.prop=new Nehan.CssProp(t),this.style=e,this.preloads=n.preloads,this.layoutContext=n.layoutContext,this.documentContext=n.documentContext}return t.prototype.computeRemSize=function(t){var e=this.style.getRootFont().size;return Math.floor(e*t)},t.prototype.computeEmSize=function(t){var e=this.getParentStyle().getFont().size;return Math.floor(e*t)},t.prototype.computePercentMeasure=function(t){var e=this.getParentStyle().contentMeasure;return Math.floor(e*t/100)},t.prototype.computePercentExtent=function(t){var e=this.getParentStyle().contentExtent;return Math.floor(e*t/100)},t.prototype.debug=function(){console.log("[markup]:%s(content:%s)",this.getMarkup().getSrc(),this.getMarkupContent().substring(0,10)),console.log("[property]:%s",this.prop.getName()),console.log("[box-flow]:%s",this.getFlow().toString()),console.log("[cursor]:(cur extent = %d, rest extent = %d)",this.getCurExtent(),this.getRestExtent()),console.log("[font]:%o(parent:%o, root:%o)",this.getFont(),this.getParentFont(),this.getRootFont()),console.log("[font size]:%d(em size:%d)",this.getFont().size,this.getParentFont().size),console.log("[pseudo]:child index:%d(last = %o), type index:%d(last = %o)",this.getChildIndex(),this.isLastChild(),this.getChildIndexOfType(),this.isLastOfType())},t.prototype.find=function(t){return this.style.find(t)},t.prototype.getCurExtent=function(){return this.layoutContext.getBlockCurExtent()},t.prototype.getRestExtent=function(){return this.layoutContext.getBlockRestExtent()},t.prototype.getFlow=function(){return"flow"===this.prop.getName()?this.style.parent.getFlow():this.style.flow||this.style._loadFlow()},t.prototype.getFont=function(){return"font"===this.prop.getName()?(console.warn("can't load font from font property itself."),this.style.parent.getFont()):this.style.font||this.style._loadFont({forceLoad:!0})},t.prototype.getParentFont=function(){return this.style.getParentFont()},t.prototype.getRootFont=function(){return this.style.getRootFont()},t.prototype.getParentStyle=function(){return this.style.parent},t.prototype.getParentFlow=function(){var t=this.getParentStyle();return t?t.flow:Nehan.Display.getStdBoxFlow()},t.prototype.getMarkup=function(){return this.style.markup},t.prototype.getMarkupContent=function(){return this.getMarkup().getContent()},t.prototype.getMarkupContent=function(){return this.getMarkup().getContent()},t.prototype.getRestMeasure=function(){return this.layoutContext?this.layoutContext.getInlineRestMeasure():null},t.prototype.getRestExtent=function(){return this.layoutContext?this.layoutContext.getBlockRestExtent():null},t.prototype.getChildIndex=function(){return this.style.getChildIndex()},t.prototype.getChildIndexOfType=function(){return this.style.getChildIndexOfType()},t.prototype.getCssAttr=function(t,e){return this.style.getCssAttr(t,e)},t.prototype.getPreloadResource=function(){return this.style.getPreloadResource()},t.prototype.isFirstChild=function(){return this.style.isFirstChild()},t.prototype.isFirstOfType=function(){return this.style.isFirstOfType()},t.prototype.isLastChild=function(){return this.style.isLastChild()},t.prototype.isLastOfType=function(){return this.style.isLastOfType()},t.prototype.isOnlyChild=function(){return this.style.isOnlyChild()},t.prototype.isOnlyOfType=function(){return this.style.isOnlyOfType()},t.prototype.isMarkupEmpty=function(){return this.style.isMarkupEmpty()},t.prototype.isTextVertical=function(){return this.getFlow().isTextVertical()},t.prototype.isTextHorizontal=function(){return!1===this.isTextVertical()},t.prototype.setMarkupContent=function(t){return this.getMarkup().setContent(t),this},t.prototype.setCssAttr=function(t,e){return this.style.setCssAttr(t,e),this},t}(),Nehan.DomCreateContext=function(){function t(t,e,n){this.dom=t,this.box=e}return t.prototype.getElement=function(){return this.dom},t.prototype.getBox=function(){return this.box},t.prototype.getParentBox=function(){return this.box.parent},t.prototype.getBoxSize=function(){return this.box.size},t.prototype.getBoxContext=function(){return this.box.context},t.prototype.getParentBoxSize=function(){return this.box.parent.size},t.prototype.getStyle=function(){return this.box.context.style},t.prototype.getParentStyle=function(){return this.box.context.parent.style},t.prototype.getMarkup=function(){return this.getStyle().getMarkup()},t.prototype.getParentMarkup=function(){return this.getParentStyle().getMarkup()},t.prototype.getChildCount=function(){return this.getStyle().getChildCount()},t.prototype.getParentChildCount=function(){return this.getParentStyle().getChildCount()},t.prototype.getChildIndex=function(){return this.getStyle().getChildIndex()},t.prototype.getChildIndexOfType=function(){return this.getStyle().getChildIndexOfType()},t.prototype.getPreloadResource=function(){return this.box.context.style.getPreloadResource()},t.prototype.isTextVertical=function(){return this.getStyle().isTextVertical()},t.prototype.isTextHorizontal=function(){return this.getStyle().isTextHorizontal()},t.prototype.isMarkupEmpty=function(){return this.getStyle().isMarkupEmpty()},t.prototype.isFirstChild=function(){return this.getStyle().isFirstChild()},t.prototype.isFirstOfType=function(){return this.getStyle().isFirstChild()},t.prototype.isOnlyChild=function(){return this.getStyle().isFirstOfType()},t.prototype.isOnlyOfType=function(){return this.getStyle().isOnlyOfType()},t.prototype.isLastChild=function(){return this.getStyle().isLastChild()},t.prototype.isLastOfType=function(){return this.getStyle().isLastOfType()},t}(),Nehan.Style=function(){function t(t,e,n,r){this._initialize(t,e,n,r||{})}return t.prototype._initialize=function(t,e,n,r){this.context=t,this.markup=e,this.markupName=e.getName(),this.parent=n||null,this.children=[],this.next=null,this.prev=null,n&&n.appendChild(this),this.selectorCacheKey=this._computeSelectorCacheKey(),this.managedCss=new Nehan.CssHashSet,this.unmanagedCss=new Nehan.CssHashSet,this.callbackCss=new Nehan.CssHashSet;var i=this.getPreloadResource();i&&this._registerPreloadResource(i),this._registerCssValues(this._loadSelectorCss(e,n)),this._registerCssValues(this._loadInlineCss(e));var o=this.callbackCss.get("onload");o&&o(this._createSelectorContext("onload")),this._registerCssValues(r),this.display=this._loadDisplay(),this.flow=this._loadFlow(),this.boxSizing=this._loadBoxSizing();var s=this._loadColor();s&&(this.color=s);var a=this._loadFont();a&&(this.font=a);var h=this._loadBoxPosition();h&&(this.boxPosition=h);var l=this._loadBorderCollapse();l&&(this.borderCollapse=l);var u=this._loadTextAlign();u&&(this.textAlign=u);var c=this._loadTextEmpha();c&&(this.textEmpha=c);var p=this._loadListStyle();p&&(this.listStyle=p);var f=this._loadFloatDirection();f&&(this.floatDirection=f);var g=this._loadBreakBefore();g&&(this.breakBefore=g);var d=this._loadBreakAfter();d&&(this.breakAfter=d);var y=this._loadWordBreak();y&&(this.wordBreak=y);var m=this._loadWhiteSpace();m&&(this.whiteSpace=m);var x=this._loadHangingPunctuation();x&&(this.hangingPunctuation=x);var C=this._loadEdge(this.flow,this.getFontSize());C&&(this.edge=C),this.staticMeasure=this._loadStaticMeasure(),this.staticExtent=this._loadStaticExtent(),this.initContextSize(this.staticMeasure,this.staticExtent),this.edge&&(this.edge.margin&&Nehan.MarginCancel.cancel(this),this.edge.border&&"collapse"===this.getBorderCollapse()&&"table"!==this.display&&Nehan.BorderCollapse.collapse(this)),this._disableUnmanagedCssProps(this.unmanagedCss)},t.prototype.initContextSize=function(t,e){this.initContextMeasure(t),this.initContextExtent(e)},t.prototype.initContextMeasure=function(t){this.measure=t||this.getParentContentMeasure(),this.contentMeasure=this._computeContentMeasure(this.measure)},t.prototype.initContextExtent=function(t){this.extent=t||this.getParentContentExtent(),this.contentExtent=this._computeContentExtent(this.extent)},t.prototype.updateContextSize=function(t,e){return"marker"===this.markupName||"table"===this.display?this:(this.initContextSize(t,e),Nehan.List.iter(this.children,function(t){t.updateContextSize(null,null)}),this)},t.prototype.appendChild=function(t){if(this.children.length>0){var e=Nehan.List.last(this.children);e.next=t,t.prev=e}this.children.push(t)},t.prototype.removeChild=function(t){var e=Nehan.List.indexOf(this.children,function(e){return e===t});if(e>=0){return this.children.splice(e,1)}return null},t.prototype.isDisabled=function(){return"none"===this.display||(!!Nehan.List.exists(Nehan.Config.disabledMarkups,Nehan.Closure.eq(this.getMarkupName()))||(this.contentMeasure<=0||this.contentExtent<=0||(this.parent&&this.contentMeasure>this.getRootStyle().contentMeasure?(console.warn("too large content %o skipped:(measure = %d, root measure = %d)",this,this.contentMeasure,this.getRootStyle().contentMeasure),!0):!!this.markup.isCloseTag()||!(this.markup.isSingleTag()||!this.isMarkupEmpty()||""!==this.getContent()))))},t.prototype.isBlock=function(){switch(this.display){case"block":case"table":case"table-caption":case"table-header-group":case"table-row-group":case"table-footer-group":case"table-row":case"table-cell":case"list-item":return!0}return!1},t.prototype.isRoot=function(){return"body"===this.getMarkupName()},t.prototype.isInlineBlock=function(){return"inline-block"===this.display&&!1===this.isFloated()},t.prototype.isInline=function(){return"first-line"===this.getMarkupName()||"inline"===this.display},t.prototype.isManagedCssProp=function(t){return Nehan.List.exists(Nehan.Config.managedCssProps,Nehan.Closure.eq(t))},t.prototype.isCallbackCssProp=function(t){return Nehan.List.exists(Nehan.Config.callbackCssProps,Nehan.Closure.eq(t))},t.prototype.isFloatStart=function(){return!!this.floatDirection&&this.floatDirection.isStart()},t.prototype.isFloatEnd=function(){return!!this.floatDirection&&this.floatDirection.isEnd()},t.prototype.isFloated=function(){return this.isFloatStart()||this.isFloatEnd()},t.prototype.isPushed=function(){return null!==this.getMarkupAttr("pushed")},t.prototype.isTableCell=function(){return"table-cell"===this.display},t.prototype.isPulled=function(){return null!==this.getMarkupAttr("pulled")},t.prototype.isLazy=function(){return null!==this.getMarkupAttr("lazy")},t.prototype.isLineBreak=function(){return"br"===this.markupName},t.prototype.isTextEmphaEnable=function(){return!(!this.textEmpha||!this.textEmpha.isEnable())},t.prototype.isTextVertical=function(){return this.flow.isTextVertical()},t.prototype.isTextHorizontal=function(){return this.flow.isTextHorizontal()},t.prototype.isPositionAbsolute=function(){return!!this.boxPosition&&this.boxPosition.isAbsolute()},t.prototype.isPre=function(){return"pre"===this.whiteSpace||"pre-wrap"===this.whiteSpace||"pre-line"===this.whiteSpace},t.prototype.isEmptyAnchor=function(){return this.markup&&this.markup.isAnchorTag()&&this.isMarkupEmpty()},t.prototype.isPageBreak=function(){switch(this.getMarkupName()){case"page-break":case"end-page":return!0;default:return!1}},t.prototype.isBreakBefore=function(){return!!this.breakBefore&&!this.breakBefore.isAvoid()},t.prototype.isBreakAfter=function(){return!!this.breakAfter&&!this.breakAfter.isAvoid()},t.prototype.isNthChild=function(t){return this.getChildNth()===t},t.prototype.isFirstChild=function(){return this.markup.isFirstChild()},t.prototype.isFirstOfType=function(){return this.markup.isFirstOfType()},t.prototype.isLastChild=function(){return this.markup.isLastChild()},t.prototype.isLastOfType=function(){return this.markup.isLastOfType()},t.prototype.isOnlyChild=function(){return this.markup.isOnlyChild()},t.prototype.isOnlyOfType=function(){return this.markup.isOnlyOfType()},t.prototype.find=function(t){return t(this)?this:this.parent?this.parent.find(t):null},t.prototype.not=function(t){return Nehan.List.forall(t,function(t){return!t.test(this)}.bind(this))},t.prototype.matches=function(t){return Nehan.List.exists(t,function(t){return t.test(this)}.bind(this))},t.prototype.lang=function(t){var e=this.getMarkupAttr("lang");return!!e&&Nehan.List.exists(t,Nehan.Closure.eq(e))},t.prototype.isMarkupEmpty=function(){return this.markup.isEmpty()},t.prototype.isWordBreakAll=function(){return this.getWordBreak().isWordBreakAll()},t.prototype.isHyphenationEnable=function(){return this.getWordBreak().isHyphenationEnable()},t.prototype.isHangingPuncEnable=function(){return this.hangingPunctuation&&"allow-end"===this.hangingPunctuation},t.prototype.isContentBox=function(){return"content-box"===this.boxSizing},t.prototype.isBorderBox=function(){return"border-box"===this.boxSizing},t.prototype.isMarginBox=function(){return"margin-box"===this.boxSizing},t.prototype.getAttr=function(t,e){var n=this.getMarkupAttr(t);return void 0!==n&&null!==n?n:(n=this.getCssAttr(t),void 0!==n&&null!==n?n:void 0!==e?e:null)},t.prototype.getMarkupAttr=function(t,e){return"id"===t?this.markup.id:this.markup.getAttr(t,e)},t.prototype.getPropStaticMeasure=function(){switch(this.getMarkupName()){case"img":return"width";default:return this.flow.getPropMeasure()}},t.prototype.getPropStaticExtent=function(){switch(this.getMarkupName()){case"img":return"height";default:return this.flow.getPropExtent()}},t.prototype._evalCssAttr=function(t,e){if("function"==typeof e){var n=this._createSelectorContext(t);return Nehan.CssParser.formatEntry(t,e(n)).value}return"object"==typeof e?Nehan.Obj.map(e,function(t,e){return this._evalCssAttr(t,e)}.bind(this)):e},t.prototype.setCssAttr=function(t,e){e||console.warn("Style::setCssAttr, invalid value %o for %s",e,t);var n=Nehan.CssParser.formatEntry(t,e);(this.isManagedCssProp(n.getPropName())?this.managedCss:this.unmanagedCss).add(n.getPropName(),n.getValue())},t.prototype.getCssAttr=function(t,e){var n;return null!==(n=this.managedCss.get(t))?this._evalCssAttr(t,n):null!==(n=this.unmanagedCss.get(t))?this._evalCssAttr(t,n):(n=this.callbackCss.get(t),null!==n?n:void 0!==e?e:null)},t.prototype.getParentMarkupName=function(){return this.parent?this.parent.getMarkupName():null},t.prototype.getMarkup=function(){return this.markup},t.prototype.getMarkupName=function(){return this.markup.getName()},t.prototype.getMarkupPath=function(){return this.markup.getPath()},t.prototype.getMarkupId=function(){return this.markup.getId()},t.prototype.getMarkupClasses=function(){return this.markup.getClasses()},t.prototype.getMarkupContent=function(){return this.markup.getContent()},t.prototype.getMarkupPos=function(){return this.markup.pos},t.prototype.getMarkupData=function(t){return this.markup.getData(t)},t.prototype.setMarkupAttr=function(t,e){return this.markup.setAttr(t,e)},t.prototype.getContent=function(){var t=this.getCssAttr("content")||this.markup.getContent(),e=this.context.selectors.getValuePe(this,"before");Nehan.Obj.isEmpty(e)||(t=Nehan.Html.tagWrap("::before",e.content||"")+t);var n=this.context.selectors.getValuePe(this,"after");Nehan.Obj.isEmpty(n)||(t+=Nehan.Html.tagWrap("::after",n.content||""));var r=this.context.selectors.getValuePe(this,"first-letter");Nehan.Obj.isEmpty(r)||(t=Nehan.Utils.replaceFirstLetter(t,function(t){return Nehan.Html.tagWrap("::first-letter",t)}));var i=this.context.selectors.getValuePe(this,"first-line");return Nehan.Obj.isEmpty(i)||(t=Nehan.Html.tagWrap("::first-line",t)),t=Nehan.Config.formatTagContent(this.flow,t)||t},t.prototype.getHeaderRank=function(){return this.markup.isHeaderTag()?parseInt(this.markup.getName().substring(1),10):0},t.prototype.getAnchorName=function(){return this.markup.getAttr("name")||""},t.prototype.getSelectorCacheKey=function(){return this.selectorCacheKey},t.prototype.getSelectorCacheKeyPe=function(t){return this.selectorCacheKey+"::"+t},t.prototype.getFont=function(){return this.font||this.getParentFont()},t.prototype.getParentFont=function(){return this.parent?this.parent.getFont():Nehan.Display.getStdFont()},t.prototype.getRootStyle=function(){return this.isRoot()||!this.parent?this:this.parent.getRootStyle()},t.prototype.getRootFont=function(){return this.getRootStyle().getFont()},t.prototype.getFontSize=function(){return this.getFont().size},t.prototype.getFontFamily=function(){return this.getFont().family},t.prototype.getTextAlign=function(){return this.textAlign?this.textAlign:this.parent?this.parent.getTextAlign():Nehan.TextAligns.get("start")},t.prototype.getTextCombineUpright=function(){return this.getCssAttr("text-combine-upright",null)},t.prototype.getTextOrientation=function(){return this.getCssAttr("text-orientation","mixed")},t.prototype.getLetterSpacing=function(){return this.letterSpacing||0},t.prototype.getListStyle=function(){return this.listStyle?this.listStyle:"list-item"===this.display&&this.parent?this.parent.getListStyle()||new Nehan.ListStyle:null},t.prototype.getListMarkerHtml=function(t,e){return e=e||{},this.listStyle?this.listStyle.getMarkerHtml(this.flow,t,e):this.parent?this.parent.getListMarkerHtml(t,e):" "},t.prototype.getWordBreak=function(){return this.wordBreak?this.wordBreak:this.parent?this.parent.getWordBreak():Nehan.WordBreaks.getInitialValue()},t.prototype.getColor=function(){return this.color||(this.parent?this.parent.getColor():new Nehan.Color(Nehan.Config.defaultFontColor))},t.prototype.getBorderCollapse=function(){return this.borderCollapse?"inherit"===this.borderCollapse?this.parent.getBorderCollapse():this.borderCollapse:null},t.prototype.getPreloadResource=function(){var t=this.markup.getData("preloadId",null);return null!==t?this.context.getPreloadResource(t):null},t.prototype.getChildCount=function(){return this.children.length},t.prototype.getChildIndex=function(){return Math.max(0,Nehan.List.indexOf(this.getParentChildren(),function(t){return t===this}.bind(this)))},t.prototype.getChildNth=function(){return this.getChildIndex()+1},t.prototype.getChildIndexOfType=function(){return Math.max(0,Nehan.List.indexOf(this.getParentChildrenOfType(this.getMarkupName()),function(t){return t===this}.bind(this)))},t.prototype.getNthChild=function(t){return this.children[t]||null},t.prototype.getParentChildren=function(){return this.parent?this.parent.children:[]},t.prototype.getParentNthChild=function(t){return this.parent?this.parent.getNthChild(t):null},t.prototype.getParentChildrenOfType=function(t){return this.getParentChildren().filter(function(e){return e.getMarkupName()===t})},t.prototype.getParentFlow=function(){return this.parent?this.parent.flow:this.flow},t.prototype.getParentFontSize=function(){return this.parent?this.parent.getFontSize():Nehan.Config.defaultFontSize},t.prototype.getParentContentMeasure=function(){return this.parent?this.parent.contentMeasure:screen[this.flow.getPropMeasure()]},t.prototype.getParentContentExtent=function(){return this.parent?this.parent.contentExtent:screen[this.flow.getPropExtent()]},t.prototype.getNextSibling=function(){return this.next},t.prototype.getLineHeight=function(){return this.getFont().lineHeight||Nehan.Config.defaultLineHeight},t.prototype.getVerticalAlign=function(){return this.getCssAttr("vertical-align","baseline")},t.prototype.getEmphaTextBlockExtent=function(){return this.textEmpha.getExtent(this.getFontSize())},t.prototype.getRubyTextBlockExtent=function(){var t=this.getFontSize(),e=Math.floor(t*(1+Nehan.Config.defaultRtRate));return t%2==0?e:e+1},t.prototype.getAutoLineExtent=function(){return Math.floor(this.getFontSize()*this.getLineHeight())},t.prototype.getEdgeMeasure=function(t){var e=this.edge||null;return e?e.getMeasure(t||this.flow):0},t.prototype.getEdgeExtent=function(t){var e=this.edge||null;return e?e.getExtent(t||this.flow):0},t.prototype.getEdgeStart=function(t){var e=this.edge||null;return e?e.getStart(t||this.flow):0},t.prototype.getEdgeEnd=function(t){var e=this.edge||null;return e?e.getEnd(t||this.flow):0},t.prototype.getEdgeBefore=function(t){var e=this.edge||null;return e?e.getBefore(t||this.flow):0},t.prototype.getEdgeAfter=function(t){var e=this.edge||null;return e?e.getAfter(t||this.flow):0},t.prototype.getInnerEdgeMeasure=function(t){var e=this.edge||null;return e?e.getInnerMeasureSize(t||this.flow):0},t.prototype.getInnerEdgeExtent=function(t){var e=this.edge||null;return e?e.getInnerExtentSize(t||this.flow):0},t.prototype.getInnerEdgeBefore=function(t){var e=this.edge||null;return e?e.getInnerBefore(t||this.flow):0},t.prototype.getCssBlock=function(t){var e={},n=this.isTextVertical();return e.display="block",this.font&&Nehan.Obj.copy(e,this.font.getCss(this.isRoot()?null:this.getParentFont())),this.parent&&"body"!==this.getMarkupName()&&Nehan.Obj.copy(e,this.parent.flow.getCss()),this.color&&Nehan.Obj.copy(e,this.color.getCss()),this.letterSpacing&&!n&&(e["letter-spacing"]=this.letterSpacing+"px"),this.floatDirection&&Nehan.Obj.copy(e,this.floatDirection.getCss(n)),this.boxPosition&&Nehan.Obj.copy(e,this.boxPosition.getCss()),this.zIndex&&(e["z-index"]=this.zIndex),Nehan.Obj.copy(e,this.unmanagedCss.getValues()),Nehan.Obj.copy(e,t.size.getCss()),t.edge&&Nehan.Obj.copy(e,t.edge.getCss()),Nehan.Obj.copy(e,t.css),e},t.prototype.getCssLineBlock=function(t){var e={};return Nehan.Obj.copy(e,t.size.getCss()),t.edge&&Nehan.Obj.copy(e,t.edge.getCss()),t.isInlineRoot&&(Nehan.Obj.copy(e,this.flow.getCss()),e["line-height"]=this.getFontSize()+"px"),!t.isInlineRoot&&this.font&&Nehan.Obj.copy(e,this.font.getCss(this.getParentFont())),this.color&&Nehan.Obj.copy(e,this.color.getCss()),this.isTextVertical()&&(e.display="block"),Nehan.Obj.copy(e,this.unmanagedCss.getValues()),Nehan.Obj.copy(e,t.css),e["background-color"]=this.getCssAttr("background-color","transparent"),e},t.prototype.getCssTextBlock=function(t){var e={};return Nehan.Obj.copy(e,t.size.getCss()),t.edge&&Nehan.Obj.copy(e,t.edge.getCss()),this.isTextVertical()?(e.display="block",e["line-height"]="1em",Nehan.Env.client.isAppleMobileFamily()&&(e["letter-spacing"]="-0.001em")):(Nehan.Obj.copy(e,this.flow.getCss()),e["line-height"]=t.maxFontSize+"px",("ruby"===this.getMarkupName()||this.isTextEmphaEnable())&&(e.display="inline-block"),t.hangingChar&&delete e["css-float"]),Nehan.Obj.copy(e,this.unmanagedCss.getValues()),Nehan.Obj.copy(e,t.css),e["background-color"]=this.getCssAttr("background-color","transparent"),e},t.prototype.getCssInlineBlock=function(t){var e=this.getCssBlock(t);return this.isTextVertical()?this.isFloated()||delete e["css-float"]:Nehan.Obj.copy(e,this.flow.getCss()),e.display="inline-block",e},t.prototype.getCssImage=function(t,e){var n={};return Nehan.Obj.copy(n,e.size.getCss()),n.display=this.display,(!this.isTextVertical()||this.isPulled()||this.isPushed())&&Nehan.Obj.copy(n,this.flow.getCss()),e.edge&&Nehan.Obj.copy(n,e.edge.getCss()),n},t.prototype._computeSelectorCacheKey=function(){var t=this.parent?[this.parent.getSelectorCacheKey()]:[];return t.push(this.markup.getKey()),t.join(">")}, t.prototype._computeContentMeasure=function(t){switch(this.boxSizing){case"margin-box":return t-this.getEdgeMeasure();case"border-box":return t-this.getInnerEdgeMeasure();case"content-box":default:return t}},t.prototype._computeContentExtent=function(t){switch(this.boxSizing){case"margin-box":return t-this.getEdgeExtent();case"border-box":return t-this.getInnerEdgeExtent();case"content-box":default:return t}},t.prototype._computeFontSize=function(t,e){var n=String(t).replace(/\/.+$/,""),r=Nehan.Config.absFontSizes[n]||n,i=this.getParentFontSize(),o=this._computeUnitSize(r,e,i);return Math.max(1,Math.min(o,Nehan.Config.maxFontSize))},t.prototype._computeLineHeight=function(t){var e=String(t);return e.indexOf("%")>0?parseInt(e,10)/100:parseFloat(t)},t.prototype._computeUnitSize=function(t,e,n){var r=String(t);if(r.indexOf("rem")>0)return Nehan.Utils.getEmSize(parseFloat(r),this.getRootFont().size);if(r.indexOf("em")>0)return Nehan.Utils.getEmSize(parseFloat(r),e);if(r.indexOf("pt")>0)return Nehan.Utils.getPxFromPt(parseFloat(r,10));if(r.indexOf("%")>0)return Nehan.Utils.getPercentValue(parseFloat(r,10),n);var i=parseInt(r,10);return isNaN(i)?0:i},t.prototype._computeCornerSize=function(t,e){var n={},r=this.parent?this.parent.contentMeasure:0,i=this.parent?this.parent.contentExtent:0;for(var o in t)n[o]=[0,0],n[o][0]=this._computeUnitSize(t[o][0],e,r),n[o][1]=this._computeUnitSize(t[o][1],e,i);return n},t.prototype._computeEdgeSize=function(t,e){var n={};for(var r in t)n[r]=this._computeUnitSize(t[r],e);return n},t.prototype._loadSelectorCss=function(t,e){switch(t.getName()){case"::marker":case"::before":case"::after":case"::first-letter":case"::first-line":return this.context.selectors.getValuePe(e,t.getPseudoElementName());default:return this.context.selectors.getValue(this)}},t.prototype._loadInlineCss=function(t){var e=t.getAttr("style");if(null===e)return{};var n=e.indexOf(";")>=0?e.split(";"):[e],r=Nehan.Config.allowedInlineStyleProps||[];return n.reduce(function(t,e){var n=e.split(":");if(n.length>=2){var i=Nehan.Utils.trim(n[0]).toLowerCase(),o=Nehan.Utils.trim(n[1]),s=Nehan.CssParser.formatEntry(i,o),a=s.getPropName(),h=s.getValue();(0===r.length||Nehan.List.exists(r,Nehan.Closure.eq(a)))&&t.add(a,h)}return t},new Nehan.CssHashSet).getValues()},t.prototype._disableUnmanagedCssProps=function(t){this.isTextVertical()&&t.remove("line-height")},t.prototype._registerCssValues=function(t){Nehan.Obj.iter(t,function(t,e){this.isCallbackCssProp(t)?this.callbackCss.add(t,e):this.isManagedCssProp(t)?this.managedCss.add(t,this._evalCssAttr(t,e)):this.unmanagedCss.add(t,this._evalCssAttr(t,e))}.bind(this))},t.prototype._registerPreloadResource=function(t){switch(this.getMarkupName()){case"img":this.markup.setAttr("width",t.getAttr("width")),this.markup.setAttr("height",t.getAttr("height"))}},t.prototype._createSelectorContext=function(t){return new Nehan.SelectorContext(t,this,this.context)},t.prototype._loadDisplay=function(){switch(this.getMarkupName()){case"first-line":return"inline";case"li-marker":case"li-body":return"block";default:return this.getCssAttr("display","inline")}},t.prototype._loadFlow=function(){var t=this.getCssAttr("flow","inherit"),e=this.parent?this.parent.flow:Nehan.Display.getStdBoxFlow();return"inherit"===t?e:"flip"===t?e.getFlipFlow():Nehan.BoxFlows.getByName(t)},t.prototype._loadBoxPosition=function(){var t=this.getCssAttr("position");if(!t)return null;var e=new Nehan.BoxPosition(t),n=this.getFontSize();return Nehan.List.iter(Nehan.Const.cssLogicalBoxDirs,function(t){var r=this.getCssAttr(t);r&&(e[r]=this._computeUnitSize(r,n))}.bind(this)),e},t.prototype._loadBorderCollapse=function(){return this.getCssAttr("border-collapse")},t.prototype._loadColor=function(){var t=this.getCssAttr("color","inherit");return"inherit"!==t?new Nehan.Color(t):null},t.prototype._loadFont=function(t){t=t||{};var e=this.getParentFont(),n=this.getCssAttr("line-height","inherit"),r=this.getCssAttr("font",{size:"inherit",family:"inherit",weight:"inherit",style:"inherit",variant:"inherit",lineHeight:"inherit"});"inherit"!==n&&(r.lineHeight=n);var i=new Nehan.Font(r);return e&&i.inherit(e),i.size!==e.size&&(i.size=this._computeFontSize(i.size,e.size)),i.lineHeight!==e.lineHeight&&(i.lineHeight=this._computeLineHeight(i.lineHeight)),t.forceLoad||this.isRoot()||!i.isEqual(e)?i:null},t.prototype._loadBoxSizing=function(){return this.isLazy()?"content-box":this.getCssAttr("box-sizing","margin-box")},t.prototype._loadEdge=function(t,e){var n=this._loadPadding(t,e),r=this._loadMargin(t,e),i=this._loadBorder(t,e);return null===n&&null===r&&null===i?null:new Nehan.BoxEdge({padding:n,margin:r,border:i})},t.prototype._loadEdgeSize=function(t,e){var n=this.getCssAttr(e);return null===n?null:this._computeEdgeSize(n,t)},t.prototype._loadPadding=function(t,e){var n=this._loadEdgeSize(e,"padding");if(null===n)return null;var r=new Nehan.Padding;return r.setSize(t,n),r},t.prototype._loadMargin=function(t,e){var n=this._loadEdgeSize(e,"margin");if(null===n)return null;var r=new Nehan.Margin;return r.setSize(t,n),this.isInline()&&(r.clearBefore(t),r.clearAfter(t)),r},t.prototype._loadBorder=function(t,e){var n=this._loadEdgeSize(e,"border-width"),r=this.getCssAttr("border-radius");if(null===n&&null===r)return null;var i=new Nehan.Border;n&&i.setSize(t,n),r&&i.setRadius(t,this._computeCornerSize(r,e));var o=this.getCssAttr("border-color");o&&i.setColor(t,o);var s=this.getCssAttr("border-style");return s&&i.setStyle(t,s),i},t.prototype._loadTextAlign=function(){var t=this.getCssAttr("text-align","inherit");return"inherit"!==t?Nehan.TextAligns.get(t):this.getTextAlign()},t.prototype._loadTextEmpha=function(){var t=this.getCssAttr("text-emphasis",null);return null!==t&&t.style&&"none"!==t.style?new Nehan.TextEmpha({style:new Nehan.TextEmphaStyle(t.style),position:new Nehan.TextEmphaPos(t.position||{hori:"over",vert:"right"}),color:t.color?new Nehan.Color(t.color):this.getColor()}):null},t.prototype._loadFloatDirection=function(){var t=this.getCssAttr("float","none");return"none"===t?null:Nehan.FloatDirections.get(t)},t.prototype._loadBreakBefore=function(){var t=this.getCssAttr("break-before");return t?Nehan.Breaks.getBefore(t):null},t.prototype._loadBreakAfter=function(){var t=this.getCssAttr("break-after");return t?Nehan.Breaks.getAfter(t):null},t.prototype._loadWordBreak=function(){var t=(Nehan.WordBreaks.getInitialValue(),this.getCssAttr("word-break","inherit"));return t?Nehan.WordBreaks.getByName(t):null},t.prototype._loadWhiteSpace=function(){var t=this.parent?this.parent.whiteSpace:"normal";return this.getCssAttr("white-space",t)},t.prototype._loadHangingPunctuation=function(){var t=this.parent?this.parent.hangingPunctuation:"none";return this.getCssAttr("hanging-punctuation",t)},t.prototype._loadListStyle=function(){var t=this.getCssAttr("list-style",null);return null===t?null:new Nehan.ListStyle(t)},t.prototype._loadLetterSpacing=function(t){var e=this.getCssAttr("letter-spacing");return e?this._computeUnitSize(e,t):null},t.prototype._loadStaticMeasure=function(){var t=this.getPropStaticMeasure(),e=this.getParentContentMeasure(),n=this.getAttr(t,null)||this.getAttr("measure",null)||this.getCssAttr(t,null)||this.getCssAttr("measure",null);return null===n?null:this._computeUnitSize(n,this.getFontSize(),e)},t.prototype._loadStaticExtent=function(){var t=this.getPropStaticExtent(),e=this.getParentContentExtent(),n=this.getAttr(t,null)||this.getAttr("extent",null)||this.getCssAttr(t,null)||this.getCssAttr("extent",null);return null===n?null:this._computeUnitSize(n,this.getFontSize(),e)},t}(),Nehan.LayoutGenerator=function(){function t(t){this.context=t,this.context.setOwnerGenerator(this),this._onInitialize(this.context)}return t.prototype.hasNext=function(){return this.context.hasNext()},t.prototype.yield=function(){this.context.initLayoutContext();var t=this._yield();if(t&&this._onCreate(t),t&&!this.hasNext()&&this._onComplete(t),++this.context.yieldCount>Nehan.Config.maxYieldCount)throw console.error("[%s]too many yield!:%o",this.context._name,this),"too many yield";return t},t.prototype._yield=function(){throw"_yield is not defined."},t.prototype._popCache=function(){return this.context.popCache()},t.prototype._onInitialize=function(t){},t.prototype._onCreate=function(t){},t.prototype._onComplete=function(t){},t}(),Nehan.BlockGenerator=function(){function t(t){Nehan.LayoutGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.LayoutGenerator),t.prototype._onInitialize=function(t){t.initBlockClear()},t.prototype._onElement=function(t){},t.prototype._yield=function(){var t=this.context.yieldClearance();if(t)return t;if(this.context.isBreakBefore())return null;for(;this.hasNext();){var e=this._getNext();e&&this._onElement(e);var n=this.context.addBlockElement(e);if(n!==Nehan.Results.OK&&n!==Nehan.Results.SKIP){if(n===Nehan.Results.EOF||n===Nehan.Results.BREAK_AFTER||n===Nehan.Results.ZERO||n===Nehan.Results.TOO_MANY_ROLLBACK||n===Nehan.Results.OVERFLOW)break;throw console.error(n),n}}return this._createOutput()},t.prototype._getNext=function(){if(this.context.hasCache())return this._popCache();if(this.context.hasChildLayout()){return this.context.yieldChildLayout()}var t=this.context.stream?this.context.stream.get():null;if(null===t)return null;if(t instanceof Nehan.Text){if(t.isWhiteSpaceOnly())return this._getNext();this.context.stream.prev();return this.context.createInlineRootGenerator().yield()}var e,n=this.context.createChildStyle(t);if(n.isEmptyAnchor())return this.context.addAnchor(n.getAnchorName()),this._getNext();if(n.isDisabled())return this._getNext();if(n.isPageBreak())return this.context.layoutContext.setBreakAfter(!0),null;if(n.isLineBreak())return this.context.createLineBox({maxExtent:this.context.style.getFontSize()});if(n.isFloated()){var r=this.context.createChildBlockGenerator(n);return this.context.createFloatGenerator(r).yield()}return"a"===n.getMarkupName()&&(n.display="inline-block"),n.isInline()||n.isInlineBlock()?(this.context.stream.prev(),e=this.context.createInlineRootGenerator(),e.yield()):(e=this.context.createChildBlockGenerator(n),e.yield())},t.prototype._onComplete=function(t){this.context.isBreakAfter()&&(t.breakAfter=!0)},t.prototype._createOutput=function(){return this.context.createBlockBox()},t}(),Nehan.InlineGenerator=function(){function t(t){Nehan.LayoutGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.LayoutGenerator),t.prototype._yield=function(){for(;this.hasNext();){var t=this._getNext(),e=this.context.addInlineElement(t);if(e!==Nehan.Results.OK&&e!==Nehan.Results.SKIP){if(e===Nehan.Results.EOF||e===Nehan.Results.ZERO||e===Nehan.Results.LINE_BREAK||e===Nehan.Results.TOO_MANY_ROLLBACK||e===Nehan.Results.OVERFLOW)break;throw console.error(e),e}}return t&&t.lineOver&&this.context.child&&!this.context.child.hasNext()&&this.context.stream.skipIf(function(t){return t instanceof Nehan.Tag&&"br"===t.getName()}),this._createOutput()},t.prototype._createOutput=function(){return this.context.createLineBox()},t.prototype._getNext=function(){if(this.context.hasCache())return this._popCache();if(this.context.hasChildLayout())return this.context.yieldChildLayout();var t=this.context.stream.get();if(null===t)return null;if(t instanceof Nehan.Text)return""===t.getContent()?this._getNext():!this.context.isInsidePreBlock()&&t.isWhiteSpaceOnly()?this._getNext():this.context.createChildTextGenerator(t).yield();if(t instanceof Nehan.Tcy||t instanceof Nehan.Word)return this.context.createChildTextGeneratorFromStream(new Nehan.TokenStream({tokens:[t]})).yield();switch(t.getName()){case"br":return this.context.layoutContext.setLineBreak(!0),this.context.style.isPre()||this.context.stream.iterWhile(function(t){return t instanceof Nehan.Text&&t.isWhiteSpaceOnly()}),null;case"wbr":return this._getNext();case"page-break":case"end-page":return this.context.setPageBreak(!0),null}var e=this.context.createChildStyle(t);return e.isEmptyAnchor()?(this.context.addAnchor(e.getAnchorName()),this._getNext()):e.isDisabled()?this._getNext():e.isBlock()?(this.context.stream.prev(),this.context.setTerminate(!0),this.context.layoutContext.setLineBreak(!0),this.context.parent&&this.context.convertInlineToBlock(),null):this.context.createChildInlineGenerator(e).yield()},t}(),Nehan.InlineBlockGenerator=function(){function t(t){Nehan.BlockGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.BlockGenerator),t.prototype._onCreate=function(t){if(t){var e=Nehan.List.maxobj(t.elements,function(t){return t.getContentMeasure()});e&&t.size.setMeasure(this.context.style.flow,e.getContentMeasure())}},t}(),Nehan.TextGenerator=function(){function t(t){Nehan.LayoutGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.LayoutGenerator),t.prototype._yield=function(){for(var t;this.hasNext();){t=this._getNext();var e=this.context.addTextElement(t);if(e!==Nehan.Results.OK&&e!==Nehan.Results.SKIP){if(e===Nehan.Results.EOF||e===Nehan.Results.ZERO||e===Nehan.Results.TOO_MANY_ROLLBACK||e===Nehan.Results.OVERFLOW)break;throw console.error(e),e}}return this._createOutput(t)},t.prototype._createOutput=function(t){return this.context.layoutContext.isInlineEmpty()?null:(this.context.isHyphenateEnable(t)&&this.context.hyphenate(t),this.context.createTextBox())},t.prototype._getNext=function(){if(this.context.hasCache()){return this._popCache()}var t=this.context.stream.get();return null===t?null:Nehan.Token.isWhiteSpace(t)?this._getWhiteSpace(t):this._getText(t)},t.prototype._getWhiteSpace=function(t){return this.context.style.isPre()?this._getWhiteSpacePre(t):(this.context.stream.iterWhile(Nehan.Token.isWhiteSpace),(t.isNewLine()||t.isTabSpace())&&Nehan.Char.call(t,{data:" "}),this._getText(t))},t.prototype._getWhiteSpacePre=function(t){return Nehan.Token.isNewLine(t)?(this.context.layoutContext.setLineBreak(!0),null):this._getText(t)},t.prototype._getText=function(t){if(t.hasMetrics()||this._setTextMetrics(t),t instanceof Nehan.Char||t instanceof Nehan.Tcy||t instanceof Nehan.Ruby)return t;if(t instanceof Nehan.Word)return this._getWord(t);throw console.error("Nehan::TextGenerator, undefined token:",t),"Nehan::TextGenerator, undefined token"},t.prototype._setTextMetrics=function(t){Nehan.Config.kerning&&(t instanceof Nehan.Char&&t.isKerningChar()?this._setTextSpacing(t):t instanceof Nehan.Word&&this._setTextSpacing(t)),t.setMetrics(this.context.style.flow,this.context.style.getFont())},t.prototype._setTextSpacing=function(t){var e=this.context.stream.peek(),n=this.context.layoutContext.getInlineLastElement(),r=e&&Nehan.Token.isText(e)?e:null;Nehan.Spacing.add(t,n,r)},t.prototype._getWord=function(t){var e=this.context.layoutContext.getInlineRestMeasure(),n=t.getAdvance(this.context.style.flow,this.context.style.letterSpacing||0);if(n<=e)return t.setDivided(!1),t;var r=this.context.getInlineRootMaxMeasure();if(n<=r&&!this.context.style.isWordBreakAll())return t;var i=t.cutMeasure(this.context.style.flow,this.context.style.getFont(),e);return t.isDivided()?(""!==t.data&&t.bodySize>0&&this.context.stream.prev(),i.bodySize=Math.min(e,i.bodySize),i):(t.bodySize>=r&&(console.warn("too large word, skipped:[%s]",t.data),t.data="",t.bodySize=0),t)},t.prototype._getMeasure=function(t){return t.getAdvance(this.context.style.flow,this.context.style.letterSpacing||0)},t}(),Nehan.LinkGenerator=function(){function t(t){Nehan.InlineGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.InlineGenerator),t.prototype._onComplete=function(t){this.context.addAnchor()},t}(),Nehan.FirstLineGenerator=function(){function t(t){Nehan.InlineGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.InlineGenerator),t.prototype._onCreate=function(t){if(this.context.isFirstOutput()){var e=this.context.parent,n=this.context.child,r=e.createChildInlineGenerator(e.style,this.context.stream).context;r.child=n,n.updateInlineParent(r)}},t}(),Nehan.LazyGenerator=function(){function t(t){Nehan.LayoutGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.LayoutGenerator),t.prototype.hasNext=function(){return!0!==this.context.terminate},t.prototype._yield=function(){return this.context.terminate?null:this.context.isBreakBefore()?null:(this.context.setTerminate(!0),this.context.isBreakAfter()&&(this.context.lazyOutput.breakAfter=!0),this.context.lazyOutput)},t}(),Nehan.FloatGenerator=function(){function t(t){Nehan.LayoutGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.LayoutGenerator),t.prototype._updateChildParent=function(){this.context.hasNextFloat()||(this.context.child.hasCache()&&this.context.parent.pushCache(this.context.child.popCache()),this.context.child.child&&this.context.child.child.updateParent(this.context.parent))},t.prototype._yield=function(){if(this.context.hasCache())return this._popCache();var t=this.context.yieldFloatStack();if(t.isEmpty()&&this.context.hasNextFloat())return this.context.yieldPageBreak();var e=t.getExtent(),n=this.context.layoutContext.getInlineRestMeasure();return e>this.context.getContextMaxExtent()?(this.context.pushFloatStackCache(t),this.context.yieldPageBreak()):this._yieldFloat(t,n,e)},t.prototype._yieldFloat=function(t,e,n){if(e<=0||n<=0)return this._updateChildParent(),null;if(t.isEmpty())return this.context.yieldFloatSpace(t.getLastGroup(),e,n);var r=this.context.style.flow,i=t.getLastGroup(),o=t.pop(r),s=this._yieldFloat(t,e-o.getMeasure(r),o.getExtent(r)),a=this._wrapInlineSet(o,s,e),h=n-o.getExtent(r);if(h<=0)return this._updateChildParent(),a;var l=this.context.yieldFloatSpace(i,e,h);return this._wrapBlockSet([a,l])},t.prototype._sortFloatRest=function(t,e){var n=t.getElements();return(t.isFloatStart()?n.concat(e):[e].concat(n)).filter(function(t){return null!==t})},t.prototype._wrapInlineSet=function(t,e,n){var r=this.context.style.flow,i=this._sortFloatRest(t,e||null),o=i.length>0?t.getExtent(r):0,s=this.context.yieldWrapBlock(n,o,i);return s.breakAfter=this.context.hasNextFloat(),s},t.prototype._wrapBlockSet=function(t){var e=this.context.style.flow,n=t.filter(function(t){return null!==t}),r=n[0].getLayoutMeasure(e),i=Nehan.List.sum(n,0,function(t){return t.getLayoutExtent(e)});return this.context.yieldWrapBlock(r,i,n)},t}(),Nehan.ParallelGenerator=function(){function t(t){Nehan.BlockGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.BlockGenerator),t.prototype._onInitialize=function(t){Nehan.BlockGenerator.prototype._onInitialize.call(this,t),t.setParallelGenerators(this._createChildGenerators(t)),t.stream=null},t.prototype._createChildGenerators=function(t){throw"_createChildGenerators is not defined."},t.prototype._popCache=function(){var t=this.context.popCache();return t&&t.elements&&t.elements.forEach(function(t){t.breakAfter=!1}),t},t.prototype._onElement=function(t){t.breakAfter=Nehan.List.exists(t.elements,function(t){return t&&t.breakAfter})&&this.hasNext()},t.prototype._getNext=function(){return this.context.hasCache()?this._popCache():this.context.yieldParallelBlocks()||null},t}(),Nehan.SectionRootGenerator=function(){function t(t){Nehan.BlockGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.BlockGenerator),t.prototype._onInitialize=function(t){Nehan.BlockGenerator.prototype._onInitialize.call(this,t),t.startOutlineContext()},t.prototype._onComplete=function(t){this.context.endOutlineContext()},t}(),Nehan.SectionContentGenerator=function(){function t(t){Nehan.BlockGenerator.call(this,t),this.context.startSectionContext()}return Nehan.Class.extend(t,Nehan.BlockGenerator),t.prototype._onComplete=function(t){this.context.endSectionContext()},t}(),Nehan.ParagraphGenerator=function(){function t(t){Nehan.BlockGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.BlockGenerator),t.prototype._onInitialize=function(t){Nehan.BlockGenerator.prototype._onInitialize.call(this,t),t.initParagraphContext()},t}(),Nehan.ListGenerator=function(){function t(t){Nehan.BlockGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.BlockGenerator),t.prototype._onInitialize=function(t){Nehan.BlockGenerator.prototype._onInitialize.call(this,t),t.initListContext()},t}(),Nehan.OutsideListItemGenerator=function(){function t(t){Nehan.ParallelGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.ParallelGenerator),t.prototype._createChildGenerators=function(t){var e=t.getListContext()||{itemCount:0,indentSize:t.style.getFontSize(),bodySize:t.layoutContext.getInlineMaxMeasure()-t.style.getFontSize()},n=t.style.getChildIndex();return[this._createListMarkerGenerator(t,e,n),this._createListBodyGenerator(t,e)]},t.prototype._onElement=function(t){Nehan.ParallelGenerator.prototype._onElement.call(this,t);var e=t.elements||[],n=e[1];n&&n.isVoid()&&(t.elements=[],t.resizeExtent(this.context.style.flow,0))},t.prototype._createListMarkerGenerator=function(t,e,n){var r=t.style.getListMarkerHtml(n+1),i=new Nehan.Tag("::marker",r),o=t.createChildStyle(i,{float:"start",measure:e.indentSize}),s=t.createChildContext(o);return new Nehan.BlockGenerator(s)},t.prototype._createListBodyGenerator=function(t,e){var n=new Nehan.Tag("li-body"),r=t.createChildStyle(n,{display:"block",float:"start",measure:e.bodySize}),i=t.createChildContext(r,{stream:t.stream});return new Nehan.BlockGenerator(i)},t}(),Nehan.InsideListItemGenerator=function(){function t(t){Nehan.BlockGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.BlockGenerator),t.prototype._onInitialize=function(t){Nehan.BlockGenerator.prototype._onInitialize.call(this,t);var e=t.style.getChildIndex(),n=t.style.getListMarkerHtml(e+1)+" ",r=new Nehan.TokenStream({lexer:t.createHtmlLexer(n)});t.stream.tokens=r.getTokens().concat(t.stream.getTokens())},t}(),Nehan.TableGenerator=function(){function t(t){Nehan.BlockGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.BlockGenerator),t.prototype._onInitialize=function(t){Nehan.BlockGenerator.prototype._onInitialize.call(this,t),"auto"===t.style.getCssAttr("table-layout")&&t.initTablePartition(t.stream)},t}(),Nehan.TableRowGenerator=function(){function t(t){Nehan.ParallelGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.ParallelGenerator),t.prototype._createChildGenerators=function(t){return this._getChildStyles(t).map(function(e){return t.createChildBlockGenerator(e)})},t.prototype._getChildStyles=function(t){var e=t.getTablePartition(),n=t.stream,r=n.getTokens(),i=t.style.contentMeasure,o=e?e.getSizes({partitionCount:r.length,measure:t.style.contentMeasure}):[];return r.map(function(e,n){var s=t.createChildStyle(e),a=s.staticMeasure,h=a&&i>=a?a:Math.floor(i/(r.length-n));return o.length>0&&(h=o[n]),i-=h,s.floatDirection=Nehan.FloatDirections.get("start"),s.initContextMeasure(h),s})},t.prototype._getChildTags=function(t){return t.getTokens().filter(Nehan.Closure.isTagName(["td","th"]))},t}(),Nehan.TableCellGenerator=function(){function t(t){Nehan.SectionRootGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.SectionRootGenerator),t}(),Nehan.HeaderGenerator=function(){function t(t){Nehan.BlockGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.BlockGenerator),t.prototype._onComplete=function(t){var e=this.context.startHeaderContext();t.id=Nehan.Css.addNehanHeaderPrefix(e)},t}(),Nehan.BodyGenerator=function(){function t(t){Nehan.SectionRootGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.SectionRootGenerator),t.prototype._onInitialize=function(t){var e=new Nehan.Tag("body",t.text);t.style||(t.style=t.createStyle(e,null)),t.stream||(t.stream=new Nehan.TokenStream({lexer:t.createHtmlLexer(t.text)})),Nehan.SectionRootGenerator.prototype._onInitialize.call(this,t)},t.prototype._createOutput=function(){var t=Nehan.BlockGenerator.prototype._createOutput.call(this);return!t||t.isInvalidSize()?null:(t.seekPos=this.context.stream.getSeekPos(),t.charPos=this.context.documentContext.getCharPos(),t.percent=this.context.stream.getSeekPercent(),t.pageNo=this.context.documentContext.getPageNo(),this.context.documentContext.stepCharPos(t.charCount||0),this.context.documentContext.getPageNo()>=Nehan.Config.maxPageCount&&this.context.setTerminate(!0),this.context.addPage(t),t)},t}(),Nehan.HtmlGenerator=function(){function t(t){Nehan.LayoutGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.LayoutGenerator),t.prototype._yield=function(){return this.context.yieldChildLayout()},t.prototype._onInitialize=function(t){t.stream||(t.stream=t.createHtmlStream(t.text)),t.documentContext.documentLang=t.getLang();for(var e=null;t.stream.hasNext();){var n=t.stream.get();switch(n.getName()){case"head":this._parseDocumentHeader(t,new Nehan.TokenStream({filter:Nehan.Closure.isTagName(["title","meta","link","style","script"]),lexer:t.createHtmlLexer(n.getContent())}));break;case"body":e=n}}e=e||new Nehan.Tag("body",t.stream.getSrc());var r=t.createChildStyle(e),i=t.createChildContext(r);new Nehan.BodyGenerator(i)},t.prototype._parseDocumentHeader=function(t,e){for(var n=new Nehan.DocumentHeader;e.hasNext();){var r=e.get();switch(r.getName()){case"title":n.setTitle(r.getContent());break;case"meta":n.addMeta(r);break;case"link":n.addLink(r);break;case"style":n.addStyle(r);break;case"script":n.addScript(r)}}t.documentContext.setDocumentHeader(n)},t}(),Nehan.DocumentGenerator=function(){function t(t){Nehan.LayoutGenerator.call(this,t)}return Nehan.Class.extend(t,Nehan.LayoutGenerator),t.prototype._yield=function(){return this.context.yieldChildLayout()},t.prototype._onInitialize=function(t){t.stream=t.createDocumentStream(t.text);for(var e=null;t.stream.hasNext();){var n=t.stream.get();switch(n.getName()){case"!doctype":t.documentContext.setDocumentType("html");break;case"html":e=n}}e=e||new Nehan.Tag("html",t.stream.getSrc());var r=t.createChildStyle(e),i=t.createChildContext(r,{stream:t.createHtmlStream(e.getContent())});new Nehan.HtmlGenerator(i)},t}(),Nehan.LayoutEvaluator=function(){function t(t,e){this.context=t,this.direction=e}return t.prototype.evaluate=function(t){return this._getEvaluator(t)._evaluate(t)},t.prototype._getEvaluator=function(t){var e=t.context.style.isTextVertical();return"vert"!==this.direction||e?"hori"===this.direction&&e?new Nehan.VertEvaluator(this.context):this:new Nehan.HoriEvaluator(this.context)},t.prototype._createElement=function(t,e){e=e||{};var n=e.css||{},r=e.attrs?e.attrs instanceof Nehan.TagAttrs?e.attrs.attrs:e.attrs:{},i=e.attrs?e.attrs.dataset:{},o=document.createElement(t);return e.className&&(o.className=e.className),e.content&&(o.innerHTML=e.content),void 0!==e.blockId&&(i.blockId=e.blockId),void 0!==e.paragraphId&&(i.paragraphId=e.paragraphId),Nehan.Obj.iter(n,function(t,e){try{o.style[Nehan.Utils.camelize(t)]=e}catch(n){console.warn("try to set %s:%o, but failed:%o",t,e,n)}}),Nehan.Obj.iter(r,function(t,e){if("id"===t)o[t]=Nehan.Css.addNehanPrefix(e);else if("style"!==t&&"class"!==t)try{o[t]=e}catch(n){console.error("try to set %o to %s but failed.",e,t)}}),Nehan.Obj.copy(o.dataset,i),o},t.prototype._createClearFix=function(t){var e=document.createElement("div");return e.style.clear=t||"both",e},t.prototype._appendChild=function(t,e){e instanceof Array?Nehan.List.iter(e,function(e){this._appendChild(t,e)}.bind(this)):t.appendChild(e)},t.prototype._evaluate=function(t,e){var n=this._evalElementRoot(t,e||{}),r=n.innerHTML?n:t.elements.reduce(function(e,n){return this._appendChild(e,this._evalElementChild(t,n)),n.withBr&&this._appendChild(e,document.createElement("br")),n.withClearFix&&this._appendChild(e,this._createClearFix()),e}.bind(this),n),i=t.getDomHook();return i&&i(new Nehan.DomCreateContext(r,t)),r},t.prototype._evalElementRoot=function(t,e){return e=e||{},this._createElement(e.name||"div",{className:t.getDomClassName(),attrs:t.getAttrs(),content:e.content||t.getContent(),blockId:t.blockId,paragraphId:t.paragraphId,css:e.css||t.getBoxCss()})},t.prototype._evalElementChild=function(t,e){switch(t.display){case"inline":return e instanceof Nehan.Box?this._evalInlineChildElement(t,e):this._evalInlineChildText(t,e);default:return this._evalBlockChildElement(t,e)}},t.prototype._evalBlockChildElement=function(t,e){switch(e.context.style.getMarkupName()){case"img":return this._evalImage(t,e);case"a":return this._evalLink(t,e);default:return this.evaluate(e)}},t.prototype._evalInlineChildElement=function(t,e){switch(e.context.style.getMarkupName()){case"img":return this._evalImage(t,e);case"a":return this._evalLink(t,e);default:return this._evalInlineChildTree(t,e)}},t.prototype._evalInlineChildTree=function(t,e){return this._evaluate(e)},t.prototype._evalInlineChildText=function(t,e){return t.context.style.isTextEmphaEnable()&&Nehan.Token.isEmphaTargetable(e)?this._evalEmpha(t,e):this._evalTextElement(t,e)},t.prototype._evalImage=function(t,e){return this._evaluate(e,{name:"img",css:e.getCssImage(t)})},t.prototype._evalLink=function(t,e){return new Nehan.Uri(e.context.style.getMarkupAttr("href")).getAnchorName()&&e.classes.push("nehan-anchor-link"),this._evalLinkElement(t,e)},t.prototype._evalTextElement=function(t,e){if(e instanceof Nehan.Char)return this._evalChar(t,e);if(e instanceof Nehan.Word)return this._evalWord(t,e);if(e instanceof Nehan.Tcy)return this._evalTcy(t,e);if(e instanceof Nehan.Ruby)return this._evalRuby(t,e);throw console.error("invalid text element:%o",e),"invalid text element"},t}(),Nehan.VertEvaluator=function(){function t(t){Nehan.LayoutEvaluator.call(this,t,"vert")}return Nehan.Class.extend(t,Nehan.LayoutEvaluator),t.prototype._evalLinkElement=function(t,e){return this._evaluate(e,{name:e.isTextBlock()?"div":"a"})},t.prototype._evalRuby=function(t,e){return[this._evalRb(t,e),this._evalRt(t,e)]},t.prototype._evalRb=function(t,e){var n=t.context.createChildStyle(new Nehan.Tag("rb")),r=t.context.createChildContext(n),i=r.createLineBox({elements:e.getRbs()});return this._evaluate(i,{css:e.getCssVertRb(t)})},t.prototype._evalRt=function(t,e){var n=t.context.createChildStyle(e.rt),r=t.context.createChildContext(n),i=new Nehan.InlineGenerator(r),o=i.yield();return Nehan.Obj.copy(o.css,e.getCssVertRt(t)),this._evaluate(o)},t.prototype._evalWord=function(t,e){return Nehan.Env.isTransformEnable?Nehan.Env.client.isTrident()?this._evalWordTransformTrident(t,e):this._evalWordTransform(t,e):Nehan.Env.client.isIE()?this._evalWordIE(t,e):""},t.prototype._evalWordTransform=function(t,e){var n=this._createElement("div",{css:e.getCssVertTrans(t)}),r=this._createElement("div",{content:e.getData(t.getFlow()),className:"nehan-rotate-90",css:e.getCssVertTransBody(t)});return n.appendChild(r),n},t.prototype._evalWordTransformTrident=function(t,e){var n=this._createElement("div",{css:e.getCssVertTrans(t)}),r=this._createElement("div",{content:e.getData(t.getFlow()),css:e.getCssVertTransBodyTrident(t)});return n.appendChild(r),n},t.prototype._evalWordIE=function(t,e){return this._createElement("div",{content:e.getData(t.getFlow()),className:"nehan-vert-ie",css:e.getCssVertTransIE(t)})},t.prototype._evalRotateChar=function(t,e){return Nehan.Env.isTransformEnable?this._evalRotateCharTransform(t,e):Nehan.Env.client.isIE()?this._evalRotateCharIE(t,e):this._evalCharWithBr(t,e)},t.prototype._evalRotateCharTransform=function(t,e){var n=Nehan.Env.client.isIE()&&e.isDash()?e.getCssVertDashIE():{};return this._createElement("div",{content:e.getData(t.getFlow()),className:"nehan-rotate-90",css:n})},t.prototype._evalRotateCharIE=function(t,e){return this._createElement("div",{content:e.getData(t.getFlow()),className:"nehan-vert-ie",css:e.getCssVertRotateCharIE(t)})},t.prototype._evalTcy=function(t,e){var n=Nehan.Env.isTextCombineEnable?["nehan-tcy","nehan-text-combine-upright"]:["nehan-tcy"];return this._createElement("div",{content:e.data,className:n.join(" "),css:e.getCssVert(t)})},t.prototype._evalChar=function(t,e){var n=Nehan.Config.useVerticalGlyphIfEnable&&Nehan.Env.isVerticalGlyphEnable ;return e.isVertChar()?n?this._evalVerticalGlyph(t,e):this._evalImgChar(t,e):e.isSpaceGroup()?this._evalSpace(t,e):e.isTabSpace()?this._evalTabChar(t,e):e.isRotateChar()?n?this._evalVerticalGlyph(t,e):this._evalRotateChar(t,e):e.isSmallKana()?this._evalSmallKana(t,e):e.isPaddingEnable()?this._evalPaddingChar(t,e):t.letterSpacing?this._evalCharLetterSpacing(t,e):e.isSingleHalfChar()?this._evalCharSingleHalfChar(t,e):e.isHalfKana()?this._evalCharHalfKana(t,e):e.isPaddingEnable()?this._evalCharWithSpacing(t,e):this._evalCharWithBr(t,e)},t.prototype._evalCharWithSpacing=function(t,e){return this._createElement("div",{content:e.getData(t.getFlow()),css:e.getCssPadding(t)})},t.prototype._evalCharWithBr=function(t,e){return e.withBr=!e.withoutBr,document.createTextNode(Nehan.Html.unescape(e.getData(t.getFlow())))},t.prototype._evalCharLetterSpacing=function(t,e){return this._createElement("div",{content:e.getData(t.getFlow()),css:e.getCssVertLetterSpacing(t)})},t.prototype._evalCharSingleHalfChar=function(t,e){return this._createElement("div",{content:e.getData(t.getFlow()),css:e.getCssVertSingleHalfChar(t)})},t.prototype._evalCharHalfKana=function(t,e){return this._createElement("div",{content:e.getData(t.getFlow()),css:e.getCssVertHalfKana(t)})},t.prototype._evalEmpha=function(t,e){var n=this._evalEmphaSrc(t,e),r=this._evalEmphaText(t,e),i=this._createElement("div",{className:"nehan-empha-wrap",css:t.context.style.textEmpha.getCssVertEmphaWrap(t,e)});return i.appendChild(n),i.appendChild(r),i},t.prototype._evalEmphaSrc=function(t,e){var n=this._createElement("span",{css:{display:"inline-block"},className:"nehan-empha-src"});e.withoutBr=!0;var r=this._evalChar(t,e);return n.appendChild(r),n},t.prototype._evalEmphaText=function(t,e){return this._createElement("span",{content:t.context.style.textEmpha.getText(),className:"nehan-empha-text",css:e.getCssVertEmphaText(t)})},t.prototype._evalPaddingChar=function(t,e){return this._createElement("div",{content:e.getData(t.getFlow()),css:e.getCssPadding(t)})},t.prototype._evalImgChar=function(t,e){return this._createElement("img",{className:"nehan-img-char",attrs:{src:e.getImgSrc("000000")},css:e.getCssVertImgChar(t)})},t.prototype._evalVerticalGlyph=function(t,e){return this._createElement("div",{content:e.getData(t.getFlow()),className:"nehan-vert-glyph",css:e.getCssVertGlyph(t)})},t.prototype._evalSmallKana=function(t,e){var n=t.context.style.textEmpha&&t.context.style.textEmpha.isEnable()?"span":"div";return this._createElement(n,{content:e.getData(t.getFlow()),css:e.getCssVertSmallKana()})},t.prototype._evalSpace=function(t,e){return this._createElement("div",{content:e.getData(t.getFlow()),className:"nehan-space",css:e.getCssVertSpaceChar(t)})},t.prototype._evalTabChar=function(t,e){return this._createElement("div",{content:" ",className:"nehan-tab",css:e.getCssVertTabChar(t)})},t}(),Nehan.HoriEvaluator=function(){function t(t){Nehan.LayoutEvaluator.call(this,t,"hori")}return Nehan.Class.extend(t,Nehan.LayoutEvaluator),t.prototype._evalInlineChildTree=function(t,e){return this._evaluate(e,{name:"span"})},t.prototype._evalLinkElement=function(t,e){return this._evaluate(e,{name:e.isTextBlock()?"span":"a"})},t.prototype._evalRuby=function(t,e){return[this._evalRt(t,e),this._evalRb(t,e)]},t.prototype._evalRb=function(t,e){var n=t.context.createChildStyle(new Nehan.Tag("rb")),r=t.context.createChildContext(n),i=r.createLineBox({elements:e.getRbs()});return this._evaluate(i,{css:e.getCssHoriRb(t)})},t.prototype._evalRt=function(t,e){return this._createElement("div",{content:e.getRtString(),className:"nehan-rt",css:e.getCssHoriRt(t)})},t.prototype._evalWord=function(t,e){return this._createElement("span",{content:e.getData(t.getFlow()),css:e.getCssHori(t)})},t.prototype._evalTcy=function(t,e){return this._createElement("span",{css:e.getCssHori(t),content:e.data})},t.prototype._evalChar=function(t,e){if(e.isSpaceGroup())return this._evalSpace(t,e);if(e.isTabSpace())return this._evalTabChar(t,e);if(e.isCharRef())return document.createTextNode(Nehan.Html.unescape(e.getData(t.getFlow())));if(e.isKerningChar())return this._evalKerningChar(t,e);if(e.isPaddingEnable())return this._evalCharWithSpacing(t,e);var n=e.getData(t.getFlow());return"&"===n.charAt(0)?document.createTextNode(Nehan.Html.unescape(n)):document.createTextNode(e.getData(t.getFlow()))},t.prototype._evalCharWithSpacing=function(t,e){return this._createElement("span",{content:e.getData(t.getFlow()),css:e.getCssPadding(t)})},t.prototype._evalEmpha=function(t,e){var n=this._evalEmphaSrc(t,e),r=this._evalEmphaText(t,e),i=this._createElement("span",{css:t.context.style.textEmpha.getCssHoriEmphaWrap(t,e)});return i.appendChild(r),i.appendChild(n),i},t.prototype._evalEmphaSrc=function(t,e){return this._createElement("div",{content:e.getData(t.getFlow()),className:"nehan-empha-src",css:e.getCssHoriEmphaSrc(t)})},t.prototype._evalEmphaText=function(t,e){return this._createElement("div",{content:t.context.style.textEmpha.getText(),className:"nehan-empha-text",css:e.getCssHoriEmphaText(t)})},t.prototype._evalKerningChar=function(t,e){var n=e.getCssPadding(t);return e.isKakkoStart()?(n["margin-left"]="-0.5em",this._createElement("span",{content:e.getData(t.getFlow()),className:"nehan-char-kakko-start",css:n})):e.isKakkoEnd()?(n["margin-right"]="-0.5em",this._createElement("span",{content:e.getData(t.getFlow()),className:"nehan-char-kakko-end",css:n})):e.isKutenTouten()?(n["margin-right"]="-0.5em",this._createElement("span",{content:e.getData(t.getFlow()),className:"nehan-char-kuto",css:n})):document.createTextNode(e.getData(t.getFlow()))},t.prototype._evalPaddingChar=function(t,e){return this._createElement("span",{content:e.getData(t.getFlow()),css:e.getCssPadding(t)})},t.prototype._evalSpace=function(t,e){return this._createElement("span",{content:e.getData(t.getFlow()),className:"nehan-space",css:e.getCssHoriSpaceChar(t)})},t.prototype._evalTabChar=function(t,e){return this._createElement("span",{content:" ",className:"nehan-tab",css:e.getCssHoriTabChar(t)})},t}(),Nehan.Results={OK:"ok",SKIP:"skip",EOF:"eof",BREAK_AFTER:"break-after",ZERO:"zero",LINE_BREAK:"line-break",OVERFLOW:"overflow",TOO_MANY_ROLLBACK:"too many rollback"},Nehan.RenderingContext=function(){function t(t){t=t||{},this.yieldCount=0,this.terminate=!1,this.cachedElements=[],this.generator=t.generator||null,this.parent=t.parent||null,this.child=t.child||null,this.style=t.style||null,this.text=t.text||"",this.stream=t.stream||null,this.layoutContext=t.layoutContext||null,this.selectors=t.selectors||new Nehan.Selectors(Nehan.DefaultStyle.create()),this.singleTagNames=t.singleTagNames||new Nehan.LowerNameSet,this.preloads=t.preloads||[],this.documentContext=t.documentContext||new Nehan.DocumentContext,this.pageEvaluator=t.pageEvaluator||new Nehan.PageEvaluator(this)}var e=function(t){return t.reduce(function(t,n){return!n.charCount&&n.elements&&n.elements.length>0?t+e(n.elements):t+(n.charCount||0)},0)};return t.prototype.addPage=function(t){this.documentContext.addPage(t)},t.prototype.addSingleTagName=function(t){this.singleTagNames.add(t)},t.prototype.addSingleTagNames=function(t){this.singleTagNames.addValues(t)},t.prototype.addAnchor=function(t){(t=t||this.getAnchorName())&&this.documentContext.addAnchor(t)},t.prototype.addBlockElement=function(t){if(null===t)return Nehan.Results.EOF;var e=this.style.flow,n=this.getContextMaxExtentForAdd(),r=this.layoutContext.getInlineMaxMeasure(),i=t.getLayoutExtent(e),o=(this.layoutContext.getBlockCount(),this.layoutContext.getBlockCurExtent()),s=o+i;if(s>n){var a=s-n;if(t.edge&&(t.edge.getAfter(e)>=a||i>this.getRootContentExtent())){var h=t.edge.cancelAfter(e,a);s-=h,i-=h}if(s>n&&i>this.getRootContentExtent())return console.warn("skip too large block element:%o(%d)",t,i),Nehan.Results.SKIP}if(t.isResumableLine(r)&&this.hasChildLayout()&&this.child.isInline())return this.child.setResumeLine(t),Nehan.Results.SKIP;if(s<=n&&(this.layoutContext.addBlockElement(t,i),t.hasLineBreak&&this.documentContext.incLineBreakCount()),s>n){var l=this.pushCache(t);if(l!==Nehan.Results.OK)return l}return s>=n&&this.layoutContext.setBreakAfter(!0),t.breakAfter&&this.layoutContext.setBreakAfter(!0),this.layoutContext.isBreakAfter()?Nehan.Results.BREAK_AFTER:Nehan.Results.OK},t.prototype.addInlineElement=function(t){if(null===t)return Nehan.Results.EOF;var e=this.layoutContext.getInlineMaxMeasure(),n=this.getElementLayoutMeasure(t),r=this.layoutContext.getInlineCurMeasure(this.style.flow),i=r+n;if(0===n)return Nehan.Results.ZERO;if(0===this.layoutContext.getInlineElements().length&&i>e&&n>this.getRootContentMeasure())return console.warn("skip too large inline element:%o(%d",t,n),Nehan.Results.SKIP;if(i<=e){if(this.layoutContext.addInlineBoxElement(t,n),t.hangingPunctuation&&this.addHangingPunctuation(t),t.hasLineBreak)return this.layoutContext.setLineBreak(!0),Nehan.Results.LINE_BREAK;if(t.lineOver)return this.layoutContext.setLineOver(!0),Nehan.Results.OVERFLOW}if(i>e){var o=this.pushCache(t);if(o!==Nehan.Results.OK)return o}return i>=e?Nehan.Results.OVERFLOW:Nehan.Results.OK},t.prototype.addTextElement=function(t){if(null===t)return Nehan.Results.EOF;var e=this.layoutContext.getInlineMaxMeasure(),n=this.getTextMeasure(t),r=this.layoutContext.getInlineCurMeasure(this.style.flow),i=r+n,o=this.stream.peek();if(0===n)return Nehan.Results.ZERO;if(0===r&&e===this.style.contentMeasure&&!1===this.style.isPre()&&o instanceof Nehan.Word&&t instanceof Nehan.Char&&t.isWhiteSpace())return Nehan.Results.SKIP;if(i<=e&&this.layoutContext.addInlineTextElement(t,n),i>e){var s=this.pushCache(t);if(s!==Nehan.Results.OK)return s}return i>=e?(this.layoutContext.setLineOver(!0),Nehan.Results.OVERFLOW):Nehan.Results.OK},t.prototype.addHangingPunctuation=function(t){if(t.hangingPunctuation.style===this.style){var e=this.yieldHangingChar(t.hangingPunctuation.data);this.layoutContext.addInlineBoxElement(e,0)}else this.layoutContext.setHangingPunctuation(t.hangingPunctuation)},t.prototype.clearCache=function(t){this.cachedElements=[]},t.prototype.convertInlineToBlock=function(){this.parent&&this.parent.isInline()&&this.parent.convertInlineToBlock(),this.style.isBlock()&&this.child&&this.child.isInline()&&(this.child.generator=this.createChildBlockGenerator(this.child.style,this.child.stream),this.child.generator.context=this.child)},t.prototype.create=function(e){return new t({parent:e.parent||null,style:e.style||null,stream:e.stream||null,layoutContext:this.layoutContext||null,selectors:this.selectors,preloads:this.preloads,singleTagNames:this.singleTagNames,documentContext:this.documentContext,pageEvaluator:this.pageEvaluator})},t.prototype.createHtmlLexer=function(t){return new Nehan.HtmlLexer(t,{singleTagNames:this.singleTagNames.getValues()})},t.prototype.createDocumentStream=function(t){var e=new Nehan.TokenStream({filter:Nehan.Closure.isTagName(["!doctype","html"]),lexer:this.createHtmlLexer(t)});return e.isEmptyTokens()&&(e.tokens=[new Nehan.Tag("html",t)]),e},t.prototype.createHtmlStream=function(t){var e=new Nehan.TokenStream({filter:Nehan.Closure.isTagName(["head","body"]),lexer:this.createHtmlLexer(t)});return e.isEmptyTokens()&&(e.tokens=[new Nehan.Tag("body",t)]),e},t.prototype.createRootGenerator=function(t){switch(t){case"document":return new Nehan.DocumentGenerator(this);case"html":return new Nehan.HtmlGenerator(this);default:return new Nehan.BodyGenerator(this)}},t.prototype.createFlipLayoutContext=function(){var t=this.getParentRestExtent(),e=this.getParentContentMeasure();return new Nehan.LayoutContext(new Nehan.BlockContext(e),new Nehan.InlineContext(t))},t.prototype.createInlineLayoutContext=function(){return new Nehan.LayoutContext(new Nehan.BlockContext(this.getContextMaxExtent()),new Nehan.InlineContext(this.getContextMaxMeasure()))},t.prototype.createBlockLayoutContext=function(){return new Nehan.LayoutContext(new Nehan.BlockContext(this.getContextMaxExtent()),new Nehan.InlineContext(this.style.contentMeasure))},t.prototype.createInlineBlockLayoutContext=function(){return new Nehan.LayoutContext(new Nehan.BlockContext(this.getContextMaxExtent()),new Nehan.InlineContext(this.getContextMaxMeasure()))},t.prototype.createLayoutContext=function(){return this.hasFlipFlow()?this.createFlipLayoutContext():this.style&&"html"!==this.style.getMarkupName()?this.isInline()?this.createInlineLayoutContext():this.style.isInlineBlock()?this.createInlineBlockLayoutContext():this.createBlockLayoutContext():null},t.prototype.createListMarkerOption=function(t){return t.getListStyle().isImageList()?{width:t.getFontSize(),height:t.getFontSize()}:{}},t.prototype.createListContext=function(){var t=this.stream.getTokens(),e=t.length,n=0;return t.forEach(function(t,e){var r=this.createTmpChildStyle(t),i=this.createChildContext(r),o=new Nehan.Tag("::marker"),s=this.createListMarkerOption(r),a=this.style.getListMarkerHtml(e+1,s);o.setContent(a);var h=i.createTmpChildStyle(o),l=i.createChildContext(h),u=new Nehan.InlineGenerator(l).yield(),c=u?u.getLayoutMeasure():0;n=Math.max(n,c)}.bind(this)),n=Math.max(this.style.getFontSize(),Math.floor((1+Nehan.Config.defaultListSpacingRate)*n)),{itemCount:e,indentSize:n,bodySize:this.style.contentMeasure-n}},t.prototype.createTablePartition=function(t){for(var e,n=new Nehan.PartitionHashSet;t.hasNext();){var r=t.get();if(null===r)break;if(r instanceof Nehan.Tag!=!1)switch(r.getName()){case"tbody":case"thead":case"tfoot":e=r.getContent();var i=this.createTablePartition(new Nehan.TokenStream({filter:Nehan.Closure.isTagName(["tr"]),lexer:this.createHtmlLexer(e)}));n=n.union(i);break;case"tr":e=r.getContent();var o=new Nehan.TokenStream({filter:Nehan.Closure.isTagName(["td","th"]),lexer:this.createHtmlLexer(e)}).getTokens(),s=o.length,a=this.createCellPartition(o);n.add(s,a)}}return t.rewind(),n},t.prototype.createCellPartition=function(t){var e=t.length,n=t.map(function(t){return this.createCellPartitionUnit(t,e)}.bind(this));return new Nehan.Partition(n)},t.prototype.createCellPartitionUnit=function(t,e){var n=t.getAttr("measure")||t.getAttr("width")||null;if(n)return new Nehan.PartitionUnit({weight:n,isStatic:!0});var r=(t.getContent(),t.getContent().replace(/
/g,"\n").replace(/
/g,"\n").split("\n")),i=Nehan.List.maxobj(r,function(t){return t.length}),o=Math.floor(this.style.contentMeasure/2),s=Math.floor(this.style.contentMeasure/(2*e)),a=i.length*this.style.getFontSize();return a=Math.max(s,Math.min(a,o)),a=Math.max(this.style.getFontSize(),a),new Nehan.PartitionUnit({weight:a,isStatic:!1})},t.prototype.createOutlineElement=function(t){return this.createOutlineElementByName("body",t||{})},t.prototype.createOutlineElementByName=function(t,e){var n=this.documentContext.createOutlineElementByName(t,e);return n.length>0?n[0]:null},t.prototype.createChildContext=function(t,e){return e=e||{},this.child=this.create({parent:this,style:t,stream:e.stream||this.createStream(t)}),t.context=this.child,this.child},t.prototype.createStyle=function(t,e,n){return new Nehan.Style(this,t,e,n||{})},t.prototype.createChildStyle=function(t,e){return new Nehan.Style(this,t,this.style,e||{})},t.prototype.createTmpChildStyle=function(t,e){var n=this.createChildStyle(t,e);return this.style.removeChild(n),n},t.prototype.createStream=function(t){var e=t.getMarkupName(),n=t.getContent();if("horizontal"===t.getTextCombineUpright()||"tcy"===e)return new Nehan.TokenStream({tokens:[new Nehan.Tcy(n)]});switch(e){case"html":var r=new Nehan.TokenStream({filter:Nehan.Closure.isTagName(["head","body"]),lexer:this.createHtmlLexer(n)});return r.isEmptyTokens()&&(r.tokens=[new Nehan.Tag("body",n)]),r;case"tbody":case"thead":case"tfoot":return new Nehan.TokenStream({filter:Nehan.Closure.isTagName(["tr"]),lexer:this.createHtmlLexer(n)});case"tr":return new Nehan.TokenStream({filter:Nehan.Closure.isTagName(["td","th"]),lexer:this.createHtmlLexer(n)});case"ul":case"ol":return new Nehan.TokenStream({filter:Nehan.Closure.isTagName(["li"]),lexer:this.createHtmlLexer(n)});case"word":return new Nehan.TokenStream({tokens:[new Nehan.Word(n)]});case"ruby":return new Nehan.RubyTokenStream(n);default:return new Nehan.TokenStream({lexer:this.createHtmlLexer(n)})}},t.prototype.createListItemGenerator=function(t){return t.style.getListStyle().isOutside()?new Nehan.OutsideListItemGenerator(t):new Nehan.InsideListItemGenerator(t)},t.prototype.createFloatGenerator=function(t){var e=this.layoutContext.getInlineMaxMeasure(),n=t.context.style.contentMeasure,r=[t];if(n>e)return this.stream.prev(),t.context.lazyOutput=this.yieldWhiteSpace(),new Nehan.LazyGenerator(t.context);this.stream.iterWhile(function(t){if(t instanceof Nehan.Text&&t.isWhiteSpaceOnly())return!0;if(t instanceof Nehan.Tag==!1)return!1;var i=this.createChildStyle(t);if(!i.isFloated())return this.style.removeChild(i),!1;if((n+=i.contentMeasure)>e)return this.style.removeChild(i),!1;var o=this.createChildBlockGenerator(i);return r.push(o),!0}.bind(this));var i=this.createTmpChildStyle(new Nehan.Tag("float-root"),{display:"block"}),o=this.createChildContext(i);o.floatedGenerators=r;var s=o.createChildStyle(new Nehan.Tag("space"),{display:"block"}),a=o.createChildContext(s,{stream:this.stream});new Nehan.BlockGenerator(a);return new Nehan.FloatGenerator(o)},t.prototype.createChildBlockGenerator=function(t,e){e=e||this.createStream(t);var n=this.createChildContext(t,{stream:e}),r=n.yieldBlockDirect();if(r)return n.lazyOutput=r,new Nehan.LazyGenerator(n);switch(t.display){case"list-item":return this.createListItemGenerator(n);case"table":return new Nehan.TableGenerator(n);case"table-row":return new Nehan.TableRowGenerator(n);case"table-cell":return new Nehan.TableCellGenerator(n)}switch(t.getMarkupName()){case"details":case"blockquote":case"figure":case"fieldset":return new Nehan.SectionRootGenerator(n);case"section":case"article":case"nav":case"aside":return new Nehan.SectionContentGenerator(n);case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":return new Nehan.HeaderGenerator(n);case"ul":case"ol":return new Nehan.ListGenerator(n);case"p":return new Nehan.ParagraphGenerator(n);default:return new Nehan.BlockGenerator(n)}},t.prototype.createInlineRootGenerator=function(){return this.createChildInlineGenerator(this.style,this.stream)},t.prototype.createChildInlineGenerator=function(t,e){var n=this.createChildContext(t,{stream:e||this.createStream(t)}),r=n.yieldInlineDirect(n);if(r)return n.lazyOutput=r,new Nehan.LazyGenerator(n);if(this.parent&&this.parent.style!==t&&t.isInlineBlock())return new Nehan.InlineBlockGenerator(n);switch(t.getMarkupName()){case"::first-line":return new Nehan.FirstLineGenerator(n);case"ruby":return new Nehan.TextGenerator(n);case"a":return new Nehan.LinkGenerator(n);default:return new Nehan.InlineGenerator(n)}},t.prototype.createTextStream=function(t){switch(this.style.getTextOrientation()){case"sideways":return new Nehan.TokenStream({tokens:[new Nehan.Word(t.getContent())]});case"upright":return new Nehan.TokenStream({lexer:new Nehan.UprightTextLexer(t.getContent())});case"mixed":default:return new Nehan.TokenStream({lexer:new Nehan.TextLexer(t.getContent())})}},t.prototype.createChildTextGenerator=function(t){return new Nehan.TextGenerator(this.createChildContext(this.style,{stream:this.createTextStream(t)}))},t.prototype.createChildTextGeneratorFromStream=function(t){return new Nehan.TextGenerator(this.createChildContext(this.style,{stream:t}))},t.prototype.createBlockBoxClasses=function(){var t=["nehan-block","nehan-"+this.getMarkupName()];return this.style.markup.isHeaderTag()&&t.push("nehan-header"),t=t.concat(this.style.markup.getClasses())},t.prototype.createLineBoxClasses=function(){var t=["nehan-inline","nehan-inline-"+this.style.flow.getName()];return t=t.concat(this.style.markup.getClasses()),this.isInlineRoot()||t.concat("nehan-"+this.getMarkupName()),t},t.prototype.createBlockBoxContextEdge=function(){if(!this.style.edge)return null;if("hr"===this.style.getMarkupName())return this.style.edge;var t=this.isFirstOutput(),e=!this.hasNext();if(t&&e)return this.style.edge;var n=this.style.edge.clone();return t||n.clearBefore(this.style.flow),e||n.clearAfter(this.style.flow),n},t.prototype.createBlockBox=function(t){t=t||{};var n=t.elements||this.layoutContext.getBlockElements(),r=void 0!==t.measure?t.measure:this.layoutContext.getInlineMaxMeasure(),i=this.getBlockBoxOutputExtent(t.extent||null),o=e(n);return new Nehan.Box({display:"inline-block"===this.style.display?this.style.display:"block",type:"block",size:this.style.flow.getBoxSize(r,i),edge:t.noEdge?null:this.createBlockBoxContextEdge(),context:this,elements:n,content:void 0!==t.content?t.content:null,classes:this.createBlockBoxClasses(),charCount:o,breakAfter:this.layoutContext.isBreakAfter(),pushed:this.style.isPushed(),pulled:this.style.isPulled()})},t.prototype.createLineBox=function(t){t=t||{};var e=this.isInlineRoot(),n=t.elements||this.layoutContext.getInlineElements(),r=e?this.getContextMaxMeasure():this.layoutContext.getInlineCurMeasure(),i=t.maxExtent||this.layoutContext.getInlineMaxExtent()||this.style.getFontSize()||this.staticExtent;if(this.style.staticMeasure&&!e&&(r=this.style.contentMeasure),n.length>0&&Nehan.List.forall(n,function(t){return t instanceof Nehan.Box!=!1&&0===t.getLayoutExtent()}))return this.yieldPageBreak();var o=this.style.flow.getBoxSize(r,i),s=t.charCount||this.layoutContext.getInlineCharCount(),a=new Nehan.Box({type:"line-block",display:"inline",size:o,context:this,elements:n,classes:this.createLineBoxClasses(),charCount:s,edge:this.style.edge&&!e?this.style.edge:null,content:t.content||null});a.maxFontSize=this.layoutContext.getInlineMaxFontSize(),a.maxExtent=this.layoutContext.getInlineMaxExtent(),a.hasLineBreak=this.layoutContext.hasLineBreak(),a.lineOver=this.layoutContext.isLineOver(),a.hangingPunctuation=this.layoutContext.getHangingPunctuation(),a.isDecorated=Nehan.List.exists(n,function(t){return t instanceof Nehan.Box&&(t.isDecorated||t.isDecoratedText())}),a.isInlineRoot=e;var h=this.style.getTextAlign();if(e){a.lineNo=t.lineNo,a.hyphenated=this.layoutContext.isHyphenated(),a.inlineMeasure=this.layoutContext.getInlineCurMeasure(),a.classes.push("nehan-root-line"),h.isCenter()||h.isEnd()?h.setAlign(a):h.isJustify()&&!this.isFloatSpace()&&h.setJustify(a);var l=this.style.getLineHeight();Nehan.LineHeight.set(this.style.flow,a,l),this.layoutContext.incBlockLineNo()}return Nehan.VerticalAlign.setBaseline(this.style.flow,a),!e&&h.isJustify()&&this.layoutContext.isLineOver()&&this.style.isOnlyChild()&&!1===this.isFloatSpace()&&this.parent&&this.parent.isInlineRoot()&&this.parent.layoutContext.getInlineMaxMeasure()===this.layoutContext.getInlineMaxMeasure()&&(a.size.setMeasure(this.getFlow(),this.layoutContext.getInlineMaxMeasure()),a.inlineMeasure=this.layoutContext.getInlineCurMeasure(),h.setJustify(a)),this.parent&&this.parent.stream&&(a.pos=Math.max(0,this.parent.stream.getPos()-1)),0!==a.elements.length||a.hasLineBreak||(a.edge=null,a.resizeExtent(this.style.flow,0)),a},t.prototype.createTextBox=function(t){t=t||{};var e=t.elements||this.layoutContext.getInlineElements(),n=this.layoutContext.getInlineMaxExtent()||this.style.getFontSize(),r=t.measure||this.layoutContext.getInlineCurMeasure();this.layoutContext.isInlineEmpty()?n=0:this.style.isTextEmphaEnable()?n=this.style.getEmphaTextBlockExtent():"ruby"===this.style.getMarkupName()&&(n=this.style.getRubyTextBlockExtent());var i=this.layoutContext.getInlineCharCount(),o=new Nehan.Box({size:this.style.flow.getBoxSize(r,n),context:this,type:"text-block",display:"inline",elements:e,classes:["nehan-text-block"].concat(this.style.markup.getClasses()),charCount:i,content:void 0!==t.content?t.content:null});return o.maxFontSize=this.layoutContext.getInlineMaxFontSize()||this.style.getFontSize(),o.maxExtent=n,o.hasLineBreak=this.layoutContext.hasLineBreak(),o.hyphenated=this.layoutContext.isHyphenated(),o.lineOver=this.layoutContext.isLineOver(),o.hangingPunctuation=this.layoutContext.getHangingPunctuation(),o.isEmpty=this.layoutContext.isInlineEmpty(),this.parent&&this.parent.stream&&(o.pos=Math.max(0,this.parent.stream.getPos()-1)),o},t.prototype.debugBlockBox=function(t){console.info("[create block box]%o(%s)\n box.breakAfter:%o, context.breakAfter:%o, box.isVoid:%o",t,t.toString(),t.breakAfter,this.layoutContext.isBreakAfter(),t.isVoid())},t.prototype.debugBlockPush=function(t,e){var n=this.getName(),r=t.size,i=this.layoutContext.block,o=t.toString(),s=this.getContextMaxExtentForAdd(),a=i.curExtent,h=a+e,l=this.parent&&this.parent.layoutContext?this.parent.layoutContext.getBlockRestExtent():this.layoutContext.getBlockRestExtent();console.log("[add block] %s:%o(%dx%d), e(%d/%d) -> e(%d/%d), +%d(prest:%d)\n%s",n,t,r.width,r.height,a,s,h,s,e,l,o),h>s&&console.warn("over %c%d","color:red",h-s)},t.prototype.debugInlinePush=function(t,e){var n=this.getName(),r=this.layoutContext.inline,i=t.toString(),o=r.maxMeasure,s=r.curMeasure,a=s+e;console.log("[add inline] %s:%o(%s), m(%d/%d) -> m(%d/%d), +%d",n,t,i,s,o,a,o,e)},t.prototype.debugTextPush=function(t,e){var n=this.getName(),r=this.layoutContext.inline,i=t.data||"",o=r.maxMeasure,s=r.curMeasure,a=s+e;console.log("[add text] %s:%o(%s), m(%d/%d) -> m(%d/%d), +%d",n,t,i,s,o,a,o,e)},t.prototype.endOutlineContext=function(){this.documentContext.addOutlineContext(this.getOutlineContext())},t.prototype.endSectionContext=function(){this.getOutlineContext().add({name:"end-section",type:this.getMarkupName()})},t.prototype.extend=function(e){return new t({parent:e.parent||this.parent,style:e.style||this.style,stream:e.stream||this.stream,layoutContext:this.layoutContext||this.layoutContext,selectors:this.selectors,preloads:this.preloads,singleTagNames:this.singleTagNames,documentContext:this.documentContext,pageEvaluator:this.pageEvaluator})},t.prototype.find=function(t){return t(this)?this:this.parent?this.parent.find(t):null},t.prototype.genBlockId=function(){return this.documentContext.genBlockId()},t.prototype.genRootBlockId=function(){return this.documentContext.genRootBlockId()},t.prototype.getDocumentLang=function(){return this.documentContext.documentLang},t.prototype.getLang=function(){return this.style.getMarkupAttr("lang")||""},t.prototype.getFlow=function(){return this.style.flow},t.prototype.getMarkupName=function(){return this.style?this.style.getMarkupName():""},t.prototype.getMarkupPath=function(){return this.style?this.style.getMarkupPath():""},t.prototype.getMarkupAttr=function(t){return this.style?this.style.getMarkupAttr(t):""},t.prototype.getDisplay=function(){return this.style?this.style.display:""},t.prototype.getFontSize=function(){return this.style?this.style.getFontSize():Nehan.Config.defaultFontSize},t.prototype.getAnchorName=function(){return this.style.getAnchorName()},t.prototype.getStreamTokens=function(){return this.stream?this.stream.tokens:[]},t.prototype.getRootContentExtent=function(){return this.style.getRootStyle().contentExtent},t.prototype.getRootContentMeasure=function(){return this.style.getRootStyle().contentMeasure},t.prototype.getWritingDirection=function(){return"vert"},t.prototype.getPage=function(t){var e=this.documentContext.pages[t]||null;return e instanceof Nehan.Box?(e=this.pageEvaluator.evaluate(e),this.documentContext.pages[t]=e,e):e},t.prototype.getPageCount=function(){return this.documentContext.getPageCount()},t.prototype.getChildContext=function(){return this.child||null},t.prototype.getPreloadResource=function(t){return this.preloads[t]||null},t.prototype.getContent=function(){return this.stream?this.stream.getSrc():""},t.prototype.getListContext=function(){return this.listContext?this.listContext:this.parent?this.parent.getListContext():null},t.prototype.getBlockRestExtent=function(){return this.layoutContext.getBlockRestExtent()},t.prototype.getContextMaxMeasure=function(){if("rt"===this.style.getMarkupName())return this.parent.layoutContext.getInlineMaxMeasure();var t=this.parent&&this.parent.layoutContext?this.parent.layoutContext.getInlineRestMeasure():this.style.contentMeasure;return Math.min(t,this.style.contentMeasure)},t.prototype.getInlineRootMaxMeasure=function(){var t=this.find(function(t){return t.isInlineRoot()});return(t?t.layoutContext:this.layoutContext).getInlineMaxMeasure()},t.prototype.getEdgeExtent=function(){return this.generator instanceof Nehan.TextGenerator?0:this.isInlineRoot()?0:this.style.getEdgeExtent(this.style.flow)},t.prototype.getInnerEdgeBefore=function(){return this.generator instanceof Nehan.TextGenerator?0:this.isInlineRoot()?0:this.style.getInnerEdgeBefore(this.style.flow)},t.prototype.getEdgeBefore=function(){return this.generator instanceof Nehan.TextGenerator?0:this.isInlineRoot()?0:this.style.getEdgeBefore()},t.prototype.getEdgeAfter=function(){return this.generator instanceof Nehan.TextGenerator?0:this.isInlineRoot()?0:this.style.getEdgeAfter()},t.prototype.getBlockBoxOutputExtent=function(t){var e=this.layoutContext.getBlockCurExtent(),n=this.style.staticExtent||null,r=this.style.contentExtent,i=this.isFloatSpace();this.style.isInlineBlock();return 0!==e||this.style.isLazy()?this.isBody()?r:i?Math.min(e,r):n?r:t||e:0},t.prototype.getParentRestExtent=function(){return this.parent&&this.parent.layoutContext?this.parent.layoutContext.getBlockRestExtent():null},t.prototype.getParentContentMeasure=function(){return this.parent&&this.parent.layoutContext?this.parent.layoutContext.getInlineMaxMeasure():null},t.prototype.getContextMaxExtent=function(){var t=this.getParentRestExtent()||this.style.extent,e=this.style.staticExtent?Math.min(t,this.style.staticExtent):t;switch(this.style.boxSizing){case"content-box":return e;case"border-box":return this.isFirstOutput()?Math.max(0,e-this.getInnerEdgeBefore()):e;case"margin-box":default:return this.isFirstOutput()?Math.max(0,e-this.getEdgeBefore()):e}},t.prototype.getContextMaxExtentForAdd=function(){var t=this.layoutContext.getBlockMaxExtent(),e=this.getEdgeAfter();return this.hasNext()?t:t-e},t.prototype.getElementLayoutExtent=function(t){return t.getLayoutExtent(this.style.flow)},t.prototype.getElementLayoutMeasure=function(t){return t.getLayoutMeasure(this.style.flow)},t.prototype.getTextMeasure=function(t){return t.getAdvance(this.style.flow,this.style.letterSpacing||0)},t.prototype.getName=function(){var t=this.getMarkupPath();return this.generator instanceof Nehan.DocumentGenerator?"(root)":this.generator instanceof Nehan.TextGenerator?t+"(text)":this.generator instanceof Nehan.InlineGenerator?t+"(inline)":this.generator instanceof Nehan.InlineBlockGenerator?t+"(iblock)":this.generator instanceof Nehan.BlockGenerator?t+"(block)"+(this.hasFlipFlow()?":flip":""):t+"("+this.getDisplay()+")"},t.prototype.getAnchorPageNo=function(t){return this.documentContext.getAnchorPageNo(t)},t.prototype.getParentStyle=function(){return this.parent?this.parent.style:null},t.prototype.getHeaderRank=function(){return this.style?this.style.getHeaderRank():0},t.prototype.getTablePartition=function(){return this.tablePartition?this.tablePartition:this.parent?this.parent.getTablePartition():null},t.prototype.getOutlineContext=function(){return this.outlineContext||(this.parent?this.parent.getOutlineContext():null)},t.prototype.getSiblingContext=function(){if("rt"===this.getMarkupName())return null;for(var t=this.parent;t&&t.style===this.style;)t=t.parent||null;return t||this.parent||null},t.prototype.getSiblingStyle=function(){var t=this.getSiblingContext();return t&&t.style?t.style:null},t.prototype.getSiblingStream=function(){var t=this.getSiblingContext();return t&&t.stream?t.stream:null},t.prototype.hasNext=function(){return!this.terminate&&(!!this.hasCache()||!this.isLazy()&&(!(!this.child||!this.hasChildLayout())||(!(!this.floatGenerators||!this.hasNextFloat())||(!(!this.parallelGenerators||!this.hasNextParallelLayout())||!!this.stream&&this.stream.hasNext()))))},t.prototype.hasChildLayout=function(){ return this.child&&this.child.generator&&this.child.generator.hasNext()},t.prototype.hasNextFloat=function(){return this.floatedGenerators&&Nehan.List.exists(this.floatedGenerators,function(t){return t.hasNext()})},t.prototype.hasNextParallelLayout=function(){return this.parallelGenerators&&Nehan.List.exists(this.parallelGenerators,function(t){return t.hasNext()})},t.prototype.hasCache=function(){return this.cachedElements.length>0},t.prototype.hasFloatStackCache=function(){return this.floatStackCaches&&this.floatStackCaches.length>0},t.prototype.hasStaticExtent=function(){return void 0!==this.style.staticExtent},t.prototype.hasStaticMeasure=function(){return void 0!==this.style.staticMeasure},t.prototype.hasFlipFlow=function(){return!(!this.parent||!this.parent.style||this.isBody())&&this.parent.style.flow!==this.style.flow},t.prototype.hyphenateSibling=function(t,e){var n=e.stream.peek(),r=this.layoutContext.getInlineLastElement(),i=n instanceof Nehan.Text?n.getHeadChar():null;if(!(this.layoutContext.getInlineRestMeasure()>e.getFontSize()))return this.style.isHangingPuncEnable()&&i&&i.isHeadNg()?(n.cutHeadChar(),void this.layoutContext.setHangingPunctuation({data:i,style:this.getSiblingStyle()})):void(r&&r instanceof Nehan.Char&&r.isTailNg()&&this.layoutContext.getInlineElements().length>1&&(this.layoutContext.popInlineElement(),this.stream.setPos(r.pos),this.layoutContext.setLineBreak(!0),this.layoutContext.setHyphenated(!0),this.clearCache()))},t.prototype.hyphenate=function(t){var e=this.peekLastCache()||this.stream.peek();if(null===e){var n=this.getSiblingContext();return void(n&&n.stream&&n.layoutContext&&this.hyphenateSibling(t,n))}var r=this.stream.peek();r=r&&e.pos===r.pos?this.stream.peek(1):r;if(this.style.isHangingPuncEnable()&&function(t,e){return t instanceof Nehan.Char&&t.isHeadNg()&&!(e instanceof Nehan.Char&&e.isHeadNg())}(e,r))return this.layoutContext.addInlineTextElement(e,0),r?this.stream.setPos(r.pos):this.stream.get(),this.layoutContext.setLineBreak(!0),this.layoutContext.setHyphenated(!0),void this.clearCache();var i=this.layoutContext.hyphenateSweep(e);if(i){var o=i.bodySize||0;Math.abs(i.pos-e.pos)>1&&(o=Math.abs(i.pos-e.pos)*this.style.getFontSize()),this.layoutContext.addInlineMeasure(-1*o),this.stream.setPos(i.pos),this.layoutContext.setLineBreak(!0),this.layoutContext.setHyphenated(!0),this.clearCache()}},t.prototype.initLayoutContext=function(){this.layoutContext=this.createLayoutContext(),this.layoutContext,this.hasFlipFlow()&&this.updateContextSize(this.layoutContext.getInlineMaxMeasure(),this.layoutContext.getBlockMaxExtent()),this.resumeLine&&(this.layoutContext.resumeLine(this.resumeLine),this.resumeLine=null)},t.prototype.initBlockClear=function(){var t=this.style.getCssAttr("clear");t&&(this.clear=new Nehan.Clear(t))},t.prototype.initListContext=function(){return this.listContext=this.createListContext(),this.listContext},t.prototype.initParagraphContext=function(){this.style.setMarkupAttr("data-paragraph-id",this.documentContext.paragraphId++)},t.prototype.initTablePartition=function(t){this.tablePartition=this.createTablePartition(t)},t.prototype.isBody=function(){return"body"===this.getMarkupName()},t.prototype.isListBody=function(){return"li-body"===this.getMarkupName()},t.prototype.isInline=function(){return this.style.isInline()||this.generator instanceof Nehan.TextGenerator||this.generator instanceof Nehan.InlineGenerator},t.prototype.isInlineRoot=function(){return!!this.isBody()||(!!this.isListBody()||(!this.parent||this.parent.style===this.style)&&(!(this.generator instanceof Nehan.TextGenerator)&&(this.generator instanceof Nehan.InlineGenerator||this.generator instanceof Nehan.InlineBlockGenerator)))},t.prototype.isBreakBefore=function(){return this.isFirstOutput()&&this.style.isBreakBefore()},t.prototype.isBreakAfter=function(){return!this.hasNext()&&this.style.isBreakAfter()},t.prototype.isFirstOutput=function(){return 0===this.yieldCount},t.prototype.isTextVertical=function(){return this.style.isTextVertical()},t.prototype.isFloatStart=function(){return!!this.style&&this.style.isFloatStart()},t.prototype.isFloatEnd=function(){return!!this.style&&this.style.isFloatEnd()},t.prototype.isFloatSpace=function(){return"space"===this.style.getMarkupName()},t.prototype.isLazy=function(){return this.style&&this.style.isLazy()},t.prototype.isHyphenateEnable=function(t){return!this.layoutContext.isInlineEmpty()&&(!this.layoutContext.hasLineBreak()&&(!!this.style.isHyphenationEnable()&&(!!(t&&t.getAdvance&&t.getAdvance()>this.style.getFontSize())||!(this.layoutContext.getInlineRestMeasure()>=this.style.getFontSize()))))},t.prototype.isInsidePreBlock=function(){return this.parent&&this.parent.style.isPre()},t.prototype.peekLastCache=function(){return Nehan.List.last(this.cachedElements)},t.prototype.peekSiblingNextToken=function(){var t=this.getSiblingStream();return t?t.peek():null},t.prototype.peekSiblingNextHeadChar=function(){var t,e=this.peekSiblingNextToken();return e instanceof Nehan.Text?(t=e.getContent().substring(0,1),new Nehan.Char({data:t})):null},t.prototype.popCache=function(){var t=this.cachedElements.pop();return t&&(t.breakAfter=!1,t.lineOver&&(t.lineOver=!1,t.edge&&t.edge.clearEnd(this.getFlow()))),t},t.prototype.popFloatStackCache=function(){return this.floatStackCaches.pop()},t.prototype.prefetchContext=function(t){return t.reduce(function(t,e){var n=t.createChildStyle(e);return t.createChildContext(n)}.bind(this),this)},t.prototype.pushCache=function(t){t instanceof Nehan.Box?t.getLayoutExtent(this.style.flow):t.bodySize;return t.cacheCount=(t.cacheCount||0)+1,t.cacheCount>=Nehan.Config.maxRollbackCount?(console.error("too many rollback! context:%o, element:%o(%s)",this,t,this.stringOfElement(t)),this.setTerminate(!0),Nehan.Results.TOO_MANY_ROLLBACK):(this.cachedElements.push(t),Nehan.Results.OK)},t.prototype.pushFloatStackCache=function(t){this.floatStackCaches=this.floatStackCaches||[],this.floatStackCaches.push(t)},t.prototype.setTerminate=function(t){this.terminate=t},t.prototype.setOwnerGenerator=function(t){this.generator=t,this._name=this.getName()},t.prototype.setParallelGenerators=function(t){this.parallelGenerators=t},t.prototype.setResumeLine=function(t){this.resumeLine=t},t.prototype.setPageBreak=function(t){this.isInline()&&this.parent?this.parent.setPageBreak(t):this.layoutContext&&this.layoutContext.setBreakAfter(t)},t.prototype.setStyle=function(t,e){return"function"==typeof e&&(e={onload:e}),this.selectors.setValue(t,e),this},t.prototype.setStyles=function(t){for(var e in t)this.setStyle(e,t[e]);return this},t.prototype.startOutlineContext=function(){this.outlineContext=new Nehan.OutlineContext(this.getMarkupName())},t.prototype.startSectionContext=function(){this.getOutlineContext().add({name:"start-section",type:this.getMarkupName(),pageNo:this.documentContext.getPageNo()})},t.prototype.startHeaderContext=function(){var t=this.documentContext.genHeaderId();return this.getOutlineContext().add({name:"set-header",headerId:t,pageNo:this.documentContext.getPageNo(),type:this.getMarkupName(),rank:this.style.getHeaderRank(),title:this.style.getContent()}),t},t.prototype.stringOfElement=function(t){return t instanceof Nehan.Box?t.toString():t.data||""},t.prototype.updateContextStaticSize=function(t,e){this.style.staticMeasure=t,this.style.staticExtent=e,this.style.updateContextSize(t,e)},t.prototype.updateContextSize=function(t,e){this.style.updateContextSize(t,e)},t.prototype.updateParent=function(t){this.isInline()&&this.updateInlineParent(t),this.updateBlockParent(t)},t.prototype.updateBlockParent=function(t){this.parent=t,t.child=this,this.updateContextSize(t.style.contentMeasure,t.style.contentExtent),this.child&&this.child.updateParent(this)},t.prototype.updateInlineParent=function(t){this.style=t.style,this.parent=t,t.child=this;var e=this.peekLastCache();e&&this.generator instanceof Nehan.TextGenerator&&e.setMetrics&&e.setMetrics(this.style.flow,this.style.getFont()),this.child&&this.child.updateParent(this)},t.prototype.yieldChildLayout=function(){return this.child.generator.yield()},t.prototype.yieldWrapBlock=function(t,e,n){return new Nehan.Box({size:this.style.flow.getBoxSize(t,e),display:"block",context:this,elements:n})},t.prototype.yieldPageBreak=function(){return new Nehan.Box({display:"block",context:this,size:new Nehan.BoxSize(0,0),breakAfter:!0})},t.prototype.yieldWhiteSpace=function(){return new Nehan.Box({display:"block",context:this,size:this.style.flow.getBoxSize(this.layoutContext.getInlineMaxMeasure(),this.layoutContext.getBlockMaxExtent()),elements:[]})},t.prototype.yieldClearance=function(){if(!this.clear||!this.parent||!this.parent.floatGroup)return null;var t=this.parent.floatGroup,e=t.getFloatDirection(),n=e.getName();return t.isLast()&&this.clear.hasDirection(n)?(this.clear.setDone(n),this.yieldWhiteSpace()):this.clear.isDoneAll()?null:this.yieldWhiteSpace()},t.prototype.yieldEmpty=function(t){var e=new Nehan.Box({display:this.getDisplay(),context:this,size:new Nehan.BoxSize(0,0)});return e.isEmpty=!0,Nehan.Obj.copy(e,t||{}),e},t.prototype.yieldBlockDirect=function(){if(this.style.isLazy())return this.yieldLazyBlock();switch(this.style.getMarkupName()){case"img":return this.yieldImage();case"hr":return this.yieldHorizontalRule()}return null},t.prototype.yieldInlineDirect=function(t){if(this.style.isLazy())return this.yieldLazyInline(t);switch(this.style.getMarkupName()){case"img":return this.yieldImage()}return null},t.prototype.yieldLazyInline=function(t){return new Nehan.Box({type:"line-block",display:"inline-block",context:this,size:this.style.flow.getBoxSize(this.style.contentMeasure,this.style.contentExtent),content:this.style.getContent()})},t.prototype.yieldLazyBlock=function(){return this.createBlockBox({measure:this.style.contentMeasure,extent:this.style.contentExtent,content:this.style.getContent()})},t.prototype.yieldImage=function(){var t=this.style.contentMeasure||this.style.getFontSize(),e=this.style.contentExtent||this.style.getFontSize();return new Nehan.Box({display:this.style.display,size:new Nehan.BoxSize(t,e),context:this,edge:this.style.edge||null,classes:["nehan-image"].concat(this.style.markup.getClasses()),pushed:this.style.isPushed(),pulled:this.style.isPulled(),breakAfter:this.style.isBreakAfter()})},t.prototype.yieldHorizontalRule=function(){return this.createBlockBox({elements:[],extent:2})},t.prototype.yieldHangingChar=function(t){t.setMetrics(this.style.flow,this.style.getFont());var e=this.style.getFontSize(),n=this.createTextBox({elements:[t],measure:t.bodySize,extent:e,charCount:0,maxExtent:e,maxFontSize:e});return n.hangingChar=!0,n},t.prototype.yieldParallelBlocks=function(t){var e=this.parallelGenerators.map(function(t){return t.yield()});if(e.every(Nehan.Closure.eq(null)))return null;var n=this.style.flow,r=Nehan.List.maxobj(e,function(t){return t?t.getLayoutExtent(n):0}),i=this.layoutContext.getInlineMaxMeasure(),o=r.getLayoutExtent(n),s=r.getContentExtent(n),a=e.map(function(t,e){var r=this.parallelGenerators[e].context;return null===t?r.createBlockBox({elements:[],extent:s}):t.resizeExtent(n,s)}.bind(this));return this.yieldWrapBlock(i,o,a)},t.prototype.yieldFloatStack=function(){if(this.hasFloatStackCache())return this.popFloatStackCache();var t=[],e=[];return Nehan.List.iter(this.floatedGenerators,function(n){var r=n.yield();!r||r.getContentExtent()<=0||(n.context.isFloatStart()?t.push(r):n.context.isFloatEnd()&&e.push(r))}),new Nehan.FloatGroupStack(this.style.flow,t,e)},t.prototype.yieldFloatSpace=function(t,e,n){return this.child.updateContextStaticSize(e,n),this.child.floatGroup=t,this.yieldChildLayout()},t}(),Nehan.MathJax=function(){var t=function(e,n){MathJax.Hub.Queue(function(){var r=e.getElementsByTagName("span")[1];if(!r)return n.retry>=n.maxRetry?(console.warn("Nehan.MathJax::typeset failed"),void n.onError("exceeds retry max")):void setTimeout(function(){n.retry++,t(e,n)},n.retryWait);n.onComplete(r)}),MathJax.Hub.Typeset(e)};return{typeset:function(e,n){n=n||{},n.retry=0,n.maxRetry=n.maxRetry||Nehan.Config.mathjax.maxRetryCount,n.retryWait=n.retryWait||Nehan.Config.mathjax.retryWait,n.onComplete=n.onComplete||function(){},n.onError=n.onError||function(){},t(e,n)}}}(),Nehan.Preload=function(){var t=function(t,e){var n=t.length;return t[n]=e.setAttr("data-preload-id",n),e},e=function(e){e.html=e.html.replace(/(]*>)/g,function(n,r){var i=new Nehan.Tag(r);return i.hasAttr("width")&&i.hasAttr("height")?n:i.hasAttr("src")?t(e.resources,i).toString():n})},n=function(e){e.html=e.html.replace(/(]*>)([\s|\S]*?)<\/math>/g,function(n,r,i){var o=new Nehan.Tag(r,i);return t(e.resources,o).toString()+i+""})},r=function(t){var e=0,n=t.resources.length;return function(r){e++,t.onProgress({max:n,cur:e,res:r}),e>=n&&t.onComplete(t)}},i=function(t,e){var n=new Image;n.onload=function(){t.setAttr("width",n.width),t.setAttr("height",n.height),e(t)},n.onerror=function(){e(t)},n.src=t.getAttr("src")},o=function(t,e){var n=document.createElement("div");n.innerHTML=t.getContent(),n.style.display="inline-block",n.style.opacity=0,n.style.fontSize=Nehan.Config.defaultFontSize+"px",document.body.appendChild(n),Nehan.MathJax.typeset(n,{onComplete:function(r){t.element=r,t.setAttr("measure",r.scrollWidth),t.setAttr("extent",r.scrollHeight),e(t),document.body.removeChild(n)},onError:function(r){console.warn("Nehan.MathJax.typeset failed for %o(%s)",t,r),t.element=n,t.setAttr("measure",0),t.setAttr("extent",0),e(t);try{document.body.removeChild(n)}catch(t){}}})},s=Nehan.Closure.animationFrame(),a=function(t,e){if(!(t.loadingIndex>=t.resources.length)){var n=t.resources[t.loadingIndex];switch(n.getName()){case"img":i(n,e);break;case"math":o(n,e)}t.loadingIndex++,s(function(){a(t,e)})}},h=function(t){t.tagNames.forEach(function(r){switch(r){case"img":e(t);break;case"math":"undefined"!=typeof MathJax&&n(t)}})};return{start:function(t,e){e=e||{};var n={html:Nehan.Html.normalize(t),tagNames:e.tagNames||[],resources:[],loadingIndex:0,onProgress:e.onProgress||function(t){},onComplete:e.onComplete||function(t){}};if(h(n),0===n.resources.length)return void n.onComplete(n);var i=r(n);a(n,i)}}}(),Nehan.Document=function(){function t(){this.text="no text",this.styles={},this.preloads=[],this.generator=null}return t.prototype.render=function(t){return t=t||{},Nehan.Preload.start(this.text,{tagNames:Nehan.Config.preloadMarkups,onProgress:t.onPreloadProgress||function(){},onComplete:function(e){var n=e.html,r=e.resources;this.generator=Nehan.createRootGenerator({root:t.root||Nehan.Config.defaultRoot,text:n,styles:this.styles,preloads:r}),new Nehan.PageParser(this.generator).parse(t)}.bind(this)}),this},t.prototype.getPage=function(t){return this.generator&&this.generator.context?this.generator.context.getPage(t):null},t.prototype.getPageCount=function(t){return this.generator&&this.generator.context?this.generator.context.getPageCount():0},t.prototype.setContent=function(t){return this.text=t,this},t.prototype.getContent=function(){return this.text},t.prototype.setStyle=function(t,e){var n=this.styles[t]||{};for(var r in e)n[r]=e[r];return this.styles[t]=n,this},t.prototype.setStyles=function(t){for(var e in t)this.setStyle(e,t[e]);return this},t.prototype.getAnchorPageNo=function(t){return this.generator&&this.generator.context?this.generator.context.getAnchorPageNo(t):-1},t.prototype.createOutlineElement=function(t){return this.generator&&this.generator.context?this.generator.context.createOutlineElementByName("body",t):null},t}(),Nehan.globalStyles=Nehan.globalStyles||{},Nehan.globalSingleTagNames=new Nehan.LowerNameSet,Nehan.setStyle=function(t,e){var n=Nehan.globalStyles[t]||{};for(var r in e)n[r]=e[r];return Nehan.globalStyles[t]=n,this},Nehan.setStyles=function(t){for(var e in t)Nehan.setStyle(e,t[e]);return this},Nehan.addSingleTagName=function(t){return Nehan.globalSingleTagNames.add(t),this},Nehan.addSingleTagNames=function(t){return Nehan.globalSingleTagNames.addValues(t),this},Nehan.createRootGenerator=function(t){return t=t||{},new Nehan.RenderingContext({text:t.text||"no text",preloads:t.preloads||[],singleTagNames:(new Nehan.LowerNameSet).addValues(Nehan.Config.defaultSingleTagNames).addValues(Nehan.globalSingleTagNames.getValues())}).setStyles(Nehan.globalStyles).setStyles(t.styles||{}).createRootGenerator(t.root||Nehan.Config.defaultRoot)},Nehan.createRootContext=function(t){return Nehan.createRootGenerator(t||{}).context};