basb-cli
Version:
Blog as Second Brain!
3 lines (2 loc) • 5.52 kB
JavaScript
class e extends Error{constructor(e){super(),this.message=`"${e}" is a abstract method that should be overrided.`}}let t={homepage:"https://www.example.com/",title:"Blog as Second Brain",description:"Blog as Second Brain",language:"en",pageSize:20,preview:{port:3030,liveReload:!0},catalog:{enable:!0},fab:{enable:!0,buttons:["catalogSwitcher","downsizeText","enlargeText","backToParent","backToTop"]},rss:{enable:!0,size:50},newest:{enable:!0,pageSize:40},search:{enable:!0,pageThreshold:3e4},echartsOptions:{tooltip:{show:!0,backgroundColor:"rgb(255,255,255,.9)"}},qrcodeOptions:{width:256,height:256}};try{t=(await import("../../user/build.config.js")).default}catch{}const r=t,n=r.language,o=["zh","en"];const s=function(e){for(const[t,r]of Object.entries(o))if(e===r)return(...e)=>e[t];return console.warn("Unexpected language: "+e),(...e)=>e[1]}(n);class a{static loadErrMsg=s("加载失败","load error");static renderErrMsg=s("渲染失败","render error");name="";_module=null;_targetElList=null;async importModule(t){throw new e("importModule")}async beforeRender(e){}loadCondition(t){throw new e("loadCondition")}renderItem(t){throw new e("renderItem")}renderAll(e){for(const e of this._targetElList())try{this.renderItem(e)}catch(t){this.renderErrResolver(t,e)}}loadErrResolver(e){console.error(e),this._targetElList().forEach((e=>e.textContent=this.name+" "+a.loadErrMsg))}renderErrResolver(e,t){console.error(e),t.textContent=this.name+" "+a.renderErrMsg}async render(e){if(this.loadCondition(e)){if(null===this._module)try{this._module=await this.importModule(e)}catch(e){return void this.loadErrResolver(e)}await this.beforeRender(e),this.renderAll(e)}}}class i extends a{static loadErrMsg=s("图表加载失败","Chart load error");static renderErrMsg=s("图表渲染失败","Chart render error");name=void 0;loadCondition(){return!0}loadErrResolver(e){console.error(e),this._targetElList().forEach((e=>e.textContent=i.loadErrMsg))}renderErrResolver(e,t){console.error(e),t.textContent=i.renderErrMsg}renderItem(t,r){throw new e("renderItem")}renderAll(){for(const e of this._targetElList()){const t=e.__ChartContent__;try{this.renderItem(e,t)}catch(t){this.renderErrResolver(t,e)}}}}function l(e={},t={}){for(const r of Object.keys(t)){const n="object"==typeof e[r],o="object"==typeof t[r],s=r in e;if(!s||n)if(s&&n)o&&l(e[r],t[r]);else if(!s)if(o){let n;n="undefined"!=typeof structuredClone?structuredClone(t[r]):JSON.parse(JSON.stringify(t[r])),e[r]=n}else e[r]=t[r]}return e}function c(e,t){let r=null;return function(...n){r&&clearTimeout(r),r=setTimeout((()=>e(...n)),t)}}const d=new class{events=new Map;emit(e,...t){const r=this.events.get(e);r&&r.forEach((e=>{e.apply(null,t)}))}on(e,t){const r=this.events.get(e);r?r.push(t):this.events.set(e,[t])}off(e,t){const r=this.events.get(e);if(r)if(1===r.length)this.events.delete(e);else{const e=r.indexOf(t);r.splice(e,1)}}};let[h,u,m]=[null,null,null];const p=r.echartsOptions;function f(e={},t){const r=["width","height","color","backgroundColor","darkMode","textStyle","aria","axisPointer","animation","animationThreshold","animationDuration","animationEasing","animationDelay","animationDurationUpdate","animationEasingUpdate","animationDelayUpdate","stateAnimation","blendMode","hoverLayerThreshold","options","useUTC","media"];for(const n in e)if(!r.includes(n))if("series"!==n){switch(n){case"xAxis":case"yAxis":t.components.add("grid");continue;case"radiusAxis":case"angleAxis":t.components.add("polar");continue;case"parallelAxis":t.components.add("parallel");continue}t.components.add(n)}else{const{series:r}=e;if(!(r instanceof Array)){t.charts.add(r.type);continue}for(const e of r)"type"in e&&t.charts.add(e.type)}}const g=new class extends i{_targetElList=()=>document.querySelectorAll(".echarts-container");#e=new MutationObserver((e=>{for(const e of this._targetElList())this._module.dispose(e),this.renderItem(e)}));#t(){this._targetElList().forEach((e=>h.getInstanceByDom(e).resize()))}#r(e,t){t.width&&(e.style.minWidth="100%",e.style.width=t.width+"px",delete t.width),t.height&&(e.style.height=t.height+"px",delete t.height)}renderItem(e){this.#r(e,e.__ChartOptions__);const t=document.body.classList.contains("dark"),r=t?"another-dark":"light",n=this._module.init(e,r),o=structuredClone(p),s=function(e,t){let r=e;if(t&&"calendar"in e){const t={splitLine:{lineStyle:{color:"white"}},dayLabel:{color:"#eee"},monthLabel:{color:"#eee"},itemStyle:{color:"none",borderWidth:.5}};e.calendar instanceof Array?e.calendar.forEach((e=>l(e,t))):l(e.calendar,t)}return r}(structuredClone(e.__ChartOptions__),t),a=l(o,s);n.setOption(a)}async beforeRender(){const e=Array.from(this._targetElList()).map((e=>e.__ChartOptions__));try{await async function(e){const t={charts:new Set,components:new Set};f(p,t),e.forEach((e=>f(e,t)));const r=Array.from(t.charts).map(u),n=Array.from(t.components).map(m);await Promise.all(r.concat(n)).then(h.use)}(e)}catch(e){this.loadErrResolver(e)}}async importModule(){const[e,t]=await Promise.all([import("../libs/echarts/core.js"),import("./echartsAnotherDarkTheme.min.js")]);h=e.default,u=e.importChart,m=e.importComponent,h.registerTheme("another-dark",t.default);const r=document.body;return this.#e.observe(r,{attributes:!0,attributeFilter:["class"]}),d.on("catalog-toggle",(()=>{setTimeout(this.#t.bind(this),1e3)})),window.addEventListener("resize",c(this.#t.bind(this),200)),h}};var y=g.render.bind(g);export{i as C,a as D,d as a,r as c,c as d,y as e,s as l};
//# sourceMappingURL=echarts.min.js.map