2025-09-25 20:29:30 +08:00

2 lines
6.0 KiB
JavaScript
Generated

(()=>{var t={n:e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return t.d(n,{a:n}),n},d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};(()=>{"use strict";const e=flarum.core.compat["common/app"];t.n(e)().initializers.add("klxf/flarum-coyote-pulse-viewer",function(){console.log("[klxf/flarum-coyote-pulse-viewer] Hello, forum and admin!")});const n=flarum.core.compat["forum/app"];var r=t.n(n);const o=flarum.core.compat["common/extend"],a=flarum.core.compat["common/components/TextEditor"];var l=t.n(a);const i=flarum.core.compat["common/components/TextEditorButton"];var s=t.n(i),u=[10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,85,90,95,100,110,120,130,140,150,160,170,180,190,200,233,266,300,333,366,400,450,500,550,600,700,800,900,1e3],c=[.1,.2,.3,.4,.5,.6,.7,.8,.9,1,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4,4.1,4.2,4.3,4.4,4.5,4.6,4.7,4.8,4.9,5,5.2,5.4,5.6,5.8,6,6.2,6.4,6.6,6.8,7,7.2,7.4,7.6,7.8,8,8.5,9,9.5,10,11,12,13,14,15,16,17,18,19,20,23.4,26.6,30,33.4,36.6,40,45,50,55,60,70,80,90,100,120,140,160,180,200,250,300];const d=flarum.core.compat["forum/components/LogInModal"];var p=t.n(d);const f=function(){document.querySelectorAll(".coyote-pulse-viewer").forEach(function(t){if(!t.getAttribute("data-pulse-rendered")){var e=!1,n=[],o=(t.getAttribute("data-pulse")||"").replace(/\r?\n|\r/g,""),a=t.getAttribute("data-title")?t.getAttribute("data-title"):"自定义波形",l=t.getAttribute("data-version")?t.getAttribute("data-version"):"3";if(o){var i;t.innerHTML+='<div class="pulse-title-box"><span class="pulse-title">波形: '+(a&&a.length>12?a.slice(0,12)+"...":a)+'</span><span class="pulse-version">v'+l+'</span><button class="Button Button--primary hasIcon pulse-download-btn"><i class="fas fa-file-download"></i></button></div>',"3"!=l&&(e=!0,n.push("目前仅支持 v3 版本的波形数据")),function(t){if(!t.startsWith("Dungeonlab+pulse:"))return!1;var e,n,r=t.substring(17).split("+section+"),o=r[0],a=o.split("/"),l=o.match(/^(\d+,\d+,\d+=)?/);if(l&&l[1]){var i=o.substring(l[0].length).split("/");if(2!==i.length)return!1;e=i[0].split(","),n=i[1].split(",")}else{if(2!==a.length)return!1;e=a[0].split(","),n=a[1].split(",")}if(5!==e.length)return!1;if(!e.every(function(t){return/^\d+$/.test(t)}))return!1;if(!n.every(function(t){return/^-?\d+(\.\d+)?-\d+$/.test(t)}))return!1;for(var s=1;s<r.length;s++){var u=r[s].split("/");if(2!==u.length)return!1;var c=u[0].split(",");if(5!==c.length)return!1;if(!c.every(function(t){return/^\d+$/.test(t)}))return!1;if(!u[1].split(",").every(function(t){return/^-?\d+(\.\d+)?-\d+$/.test(t)}))return!1}return!0}(o)||(e=!0,n.push("解析失败,请检查数据格式是否正确")),e?(null==(i=t.querySelector(".pulse-download-btn"))||i.remove(),t.innerHTML+='<div class="pulse-warning"><i class="fas fa-exclamation-circle"></i> 错误:'+n.join("; ")+"</div>"):t.innerHTML+=function(t){var e=t.replace("Dungeonlab+pulse:","").split("+section+"),n=0,r="";n+=0;var o=1,a=e[0].split("=");if(2===a.length){var l=a[0],i=a[1],s=l.split(",").map(Number),d=(s[0],s[1]);s[2],o=d||1,e[0]=i}return e.forEach(function(t){var e=t.split("/"),o=e[0],a=e[1],l=o.split(",").map(Number),i=l[0],s=l[1],d=l[2],p=l[3],f=l[4],m=c[d];if(0!==f)for(var v=a.split(","),h=10*v.length,b=Math.ceil(m/(h/100)),g=function(t){var e=10*v.length;n+=e,v.forEach(function(o,a){var l,c=o.split("-").map(Number),d=c[0],f=(c[1],d),m=n-e+10*a,h=100-f;l=1===p?u[i]:2===p?u[i+Math.floor((s-i)*((v.length*t+a)/(v.length*b)))]:3===p?u[i+Math.floor((s-i)*a/v.length)]:4===p?u[i+Math.floor(t/b*(s-i))]:u[i];var g=.5,y=Math.floor(100/l);if(y>0){var w=(10-y*g)/y;w<0&&(w=0);for(var x=0;x<y;x++){var L=m+x*(g+w);r+='<rect x="'+L+'" y="'+h+'" width="'+g+'" height="'+f+'" fill="#ffe99d" />',r+='<rect x="'+(L+g)+'" y="'+h+'" width="'+w+'" height="'+f+'" fill="#1a1a1a" />'}}else r+='<rect x="'+m+'" y="'+h+'" width="10" height="'+f+'" fill="#1a1a1a" />'})},y=0;y<b;y++)g(y)}),'\n\t\t\t <svg width="300" height="100" viewBox="0 0 100 100">\n\t\t\t <g>\n\t\t\t '+r+'\n\t\t\t \n\t\t\t <animateTransform\n\t\t\t attributeName="transform"\n\t\t\t attributeType="XML"\n\t\t\t type="translate"\n\t\t\t from="200"\n\t\t\t to="'+(-(n+=0)-100)+'"\n\t\t\t dur="'+(n+100)/(50*o)+'s"\n\t\t\t repeatCount="indefinite"\n\t\t\t />\n\t\t\t \n\t\t\t </g>\n\t\t\t </svg>\n\t\t\t '}(o),t.setAttribute("data-pulse-rendered","1");var s=t.querySelector(".pulse-download-btn");s&&s.addEventListener("click",function(){if(r().forum.attribute("klxf-coyote-pulse-viewer.download-must-login")&&null==r().session.user)return r().alerts.show({type:"warn"},"请先登录以下载波形文件"),void r().modal.show(p());var t=new Blob([o],{type:"text/plain"}),e=document.createElement("a");e.href=URL.createObjectURL(t),e.download=a+".pulse",document.body.appendChild(e),e.click(),document.body.removeChild(e),URL.revokeObjectURL(e.href)})}}})};r().initializers.add("klxf-coyote-pulse-viewer",function(){(0,o.extend)(l().prototype,"toolbarItems",function(t){var e=this;t.add("pulse-file-upload",m(s(),{icon:"fas fa-file-import",title:"波形分享",onclick:function(){var t=document.createElement("input");t.type="file",t.accept=".pulse",t.style.display="none",t.addEventListener("change",function(){var n,r=null==(n=t.files)?void 0:n[0];if(r){var o=new FileReader;o.onload=function(){var t,n=r.name.replace(/\.pulse$/,""),a=n.match(/^pulse-(.+?)-\d+$/),l='[pulse title="'+(a?a[1]:n)+'"]'+o.result+"[/pulse]";null==(t=e.attrs)||null==(t=t.composer)||t.editor.insertAtCursor(l)},o.readAsText(r)}}),document.body.appendChild(t),t.click(),document.body.removeChild(t)}}),81)}),f(),document.body.addEventListener("contentupdated",f),new MutationObserver(function(){f()}).observe(document.body,{childList:!0,subtree:!0})})})(),module.exports={}})();
//# sourceMappingURL=forum.js.map