OcttKB/Wiki-OcttKB/plugins/echarts/$__plugins_Gk0Wk_echarts_wi...

9 lines
8.7 KiB
JSON

[
{
"title": "$:/plugins/Gk0Wk/echarts/widget.js",
"text": "\"use strict\";var __create=Object.create,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty,__copyProps=(e,i,r,s)=>{if(i&&\"object\"==typeof i||\"function\"==typeof i)for(let t of __getOwnPropNames(i))__hasOwnProp.call(e,t)||t===r||__defProp(e,t,{get:()=>i[t],enumerable:!(s=__getOwnPropDesc(i,t))||s.enumerable});return e},__toESM=(t,e,i)=>(i=null!=t?__create(__getProtoOf(t)):{},__copyProps(!e&&t&&t.__esModule?i:__defProp(i,\"default\",{value:t,enumerable:!0}),t)),import_widget=require(\"$:/core/modules/widgets/widget.js\"),ECharts=__toESM(require(\"$:/plugins/Gk0Wk/echarts/echarts.min.js\")),echartWidgets=new Set,Function_=Function;if($tw.browser){globalThis.echarts=ECharts;try{$tw.modules.forEachModuleOfType(\"echarts-extension\",(t,e)=>{var i,r,s,n,h;\"$:/plugins/Gk0Wk/echarts-stat/ecStat.min.js\"===t&&(({transform:{histogram:r,clustering:s,regression:n},statistics:h}=e),null!=(i=ECharts.registerTransform)&&i(r),null!=(r=ECharts.registerTransform)&&r(s),null!=(i=ECharts.registerTransform)&&i(n),globalThis.EChartsStat=h)})}catch(error){console.error(error)}setInterval(()=>{var t=[];for(const i of echartWidgets)document.contains(i.containerDom)||(unmountAddon(i.tiddlerTitle,i.state,i.echartsInstance),i.clearInstance(),t.push(i));var e=t.length;for(let r=0;r<e;r++)echartWidgets[\"delete\"](t[r])},1e3)}var unmountAddon=(t,e,i)=>{var r,s,n,h,a;try{i.off(\"restore\"),t&&\"application/javascript\"===(null==(s=null==(r=$tw.wiki.getTiddler(t))?void 0:r.fields)?void 0:s.type)&&(a=(null!=(n=(h=require(t))[\"default\"])?n:h)[\"onUnmount\"],\"function\"==typeof a)&&a(e)}catch(error){console.error(error)}},nextId=0,EChartsWidget=class extends import_widget.widget{constructor(){super(...arguments),this.uuid=\"gk0wk-echarts-container-\"+nextId++,this.width=\"100%\",this.height=\"300px\",this[\"class\"]=\"gk0wk-echarts-body\",this.fillSidebar=!0,this.renderer=\"canvas\"}initialise(t,e){super.initialise(t,e),this.computeAttributes()}execute(){switch(this.tiddlerTitle=this.getAttribute(\"$tiddler\",\"\")||void 0,this.width=this.getAttribute(\"$width\",\"100%\"),this.height=this.getAttribute(\"$height\",\"300px\"),this[\"class\"]=this.getAttribute(\"$class\",\"gk0wk-echarts-body\"),this.fillSidebar=\"true\"===this.getAttribute(\"$fillSidebar\",\"true\").toLowerCase(),this.getAttribute(\"$theme\",\"auto\")){case\"light\":this.theme=void 0;break;case\"dark\":this.theme=\"dark\";break;default:this.theme=0<$tw.wiki.filterTiddlers(\"[{$:/palette}field:color-scheme[dark]]\").length?\"dark\":void 0}this.renderer=\"svg\"===this.getAttribute(\"$renderer\",\"canvas\")?\"svg\":\"canvas\",this.text=this.getAttribute(\"$text\",\"\").trim()||void 0,this.throttle=Math.max($tw.utils.getAnimationDuration()||100,100)}render(t,e){this.parentDomNode=t,this.execute(),this.containerDom=$tw.utils.domMaker(\"div\",{\"class\":this[\"class\"],document:this.document,style:{width:this.width,height:this.height}}),this.containerDom.id=this.uuid,t.insertBefore(this.containerDom,e),this.domNodes.push(this.containerDom);try{if(!(this.tiddlerTitle&&$tw.wiki.getTiddler(this.tiddlerTitle)||this.text))throw new Error(\"Widget need either $tiddler or $text attribute!\");var i=t.isTiddlyWikiFakeDom;this.rebuildInstance(i),this.initAddon(),this.renderAddon(),i?(Number.isSafeInteger(Number(this.width.replace(\"px\",\"\")))&&Number.isSafeInteger(Number(this.height.replace(\"px\",\"\")))||console.error(\"If you require SSR(server side render), you need to define $height and $width with format like '300px'\"),this.parentDomNode.innerHTML=this.echartsInstance.renderToSVGString()):echartWidgets.add(this)}catch(error){console.error(error),this.containerDom.innerText=String(error),this.containerDom.style.color=\"white\",this.containerDom.style.background=\"red\",this.containerDom.style.fontSize=\"12px\"}}refresh(s){return this.timer&&clearTimeout(this.timer),this.timer=setTimeout(()=>{this.timer=void 0;var t,e=this.tiddlerTitle;const i=this.computeAttributes();let r=0;if(0<$tw.utils.count(i)){let e=0;$tw.utils.each([\"$theme\",\"$fillSidebar\",\"$renderer\"],t=>{void 0!==i[t]&&e++}),0<e&&(r|=2),i.$class&&(e++,this[\"class\"]=this.getAttribute(\"$class\",\"gk0wk-echarts-body\"),this.containerDom.className=this[\"class\"]),i.$width&&(e++,this.width=this.getAttribute(\"$width\",\"100%\"),this.containerDom.style.width=this.width),i.$height&&(e++,this.height=this.getAttribute(\"$height\",\"300px\"),this.containerDom.style.height=this.height),$tw.utils.count(i)>e&&(r|=1)}void 0!==this.text||1&r||!(this.tiddlerTitle&&s[this.tiddlerTitle]||this.askForAddonUpdate(s,i))||(r|=1),this.execute(),2&r?!(t=this.rebuildInstance())||1&r?(unmountAddon(void 0!==this.text?void 0:e,this.state,this.echartsInstance),this.initAddon(),this.renderAddon()):this.echartsInstance.setOption(t):1&r&&this.renderAddon()},this.throttle),!1}askForAddonUpdate(t,e){var i,r,s,n,h,a,o;try{return this.tiddlerTitle&&$tw.wiki.getTiddler(this.tiddlerTitle)?\"text/vnd.tiddlywiki\"===(n=(s=$tw.wiki.getTiddler(this.tiddlerTitle).fields).type||\"text/vnd.tiddlywiki\")||\"application/json\"===n?(this._state=JSON.stringify($tw.wiki.filterTiddlers(s[\"echarts-refresh-trigger\"])),this._state!==this.state):\"application/javascript\"===n&&(void 0===(o=null!=(r=(a=null!=(i=(h=require(this.tiddlerTitle))[\"default\"])?i:h).shouldUpdate)?r:a.shouldRefresh)||(\"string\"==typeof o?(this._state=JSON.stringify($tw.wiki.filterTiddlers(o)),this._state!==this.state):\"function\"!=typeof o||o(this.state,t,e))):!1}catch(error){return console.error(error),!1}}clearInstance(){let t;return this.echartsInstance&&(t=this.echartsInstance.getOption(),this.echartsInstance.isDisposed()||this.echartsInstance.dispose(),this.echartsInstance=void 0),this.containerDom.innerHTML=\"\",this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=void 0),t}rebuildInstance(t=!1){var e=this.clearInstance();return this.echartsInstance=ECharts.init(t?null:this.containerDom,this.theme,t?{ssr:!0,renderer:\"svg\",height:Number(this.height.replace(\"px\",\"\"))||300,width:Number(this.width.replace(\"px\",\"\"))||400}:{renderer:this.renderer}),this.echartsInstance.setOption({darkMode:\"dark\"===this.theme,backgroundColor:\"transparent\"}),globalThis.ResizeObserver&&$tw.browser&&!t&&(this.resizeObserver=new ResizeObserver(r=>{requestAnimationFrame(()=>{var e;if(this.echartsInstance){var i=document.querySelector(\".tc-sidebar-scrollable\");let t=r[0].contentRect[\"height\"];this.fillSidebar&&null!=(e=null==i?void 0:i.contains)&&e.call(i,this.containerDom)&&(t=window.innerHeight-this.parentDomNode.getBoundingClientRect().top-(Number(getComputedStyle(i).paddingBottom.replace(\"px\",\"\"))||0)),this.echartsInstance.resize({width:r[0].contentRect.width,height:t})}})}),this.resizeObserver.observe(this.containerDom)),e}initAddon(){var t,e,i;try{if(void 0===this.text){if(!this.tiddlerTitle||!$tw.wiki.getTiddler(this.tiddlerTitle))return;var r=$tw.wiki.getTiddler(this.tiddlerTitle).fields,s=r.type||\"text/vnd.tiddlywiki\";if(\"text/vnd.tiddlywiki\"===s||\"application/json\"===s)this.state=null!=(t=this._state)?t:JSON.stringify($tw.wiki.filterTiddlers(r[\"echarts-refresh-trigger\"])),this._state=void 0;else{if(\"application/javascript\"!==s)return;var n=require(this.tiddlerTitle),h=null!=(e=n[\"default\"])?e:n,a=null!=(i=h.onMount)?i:h.onInit;\"function\"==typeof a&&(this.state=a(this.echartsInstance,this.attributes,this))}}this.echartsInstance.on(\"restore\",()=>this.renderAddon())}catch(error){console.error(error)}}async renderAddon(){var t;this.echartsInstance.showLoading();try{if(void 0===this.text){if(!this.tiddlerTitle||!$tw.wiki.getTiddler(this.tiddlerTitle))return void this.echartsInstance.hideLoading();var e,i=$tw.wiki.getTiddler(this.tiddlerTitle).fields.type||\"text/vnd.tiddlywiki\";\"text/vnd.tiddlywiki\"===i?this.echartsInstance.setOption(JSON.parse($tw.wiki.renderTiddler(\"text/plain\",this.tiddlerTitle,{variables:this.attributes}))):\"application/json\"===i?this.echartsInstance.setOption(JSON.parse($tw.wiki.getTiddlerText(this.tiddlerTitle))):\"application/javascript\"===i&&(null!=(t=(e=require(this.tiddlerTitle))[\"default\"])?t:e).onUpdate(this.echartsInstance,this.state,this.attributes)}else new Function_(\"myChart\",\"chartDom\",\"echarts\",\"$tw\",`var option;${this.text};if (option instanceof Object) myChart.setOption(option);`)(this.echartsInstance,this.containerDom,ECharts,$tw)}catch(error){console.error(error)}this.echartsInstance.hideLoading()}};exports.echarts=EChartsWidget;",
"Modern.TiddlyDev#Origin": "widget.ts",
"module-type": "widget",
"type": "application/javascript"
}
]