2025-09-24 18:35:28 +08:00

2 lines
5.7 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"],i=flarum.core.compat["common/components/TextEditor"];var a=t.n(i);const l=flarum.core.compat["common/components/TextEditorButton"];var s=t.n(l),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=function(){document.querySelectorAll(".coyote-pulse-viewer").forEach(function(t){if(!t.getAttribute("data-pulse-rendered")){var e=!1,n=[],r=t.getAttribute("data-pulse"),o=t.getAttribute("data-title")?t.getAttribute("data-title"):"自定义波形",i=t.getAttribute("data-version")?t.getAttribute("data-version"):"3";if(r){var a;t.innerHTML+='<div class="pulse-title-box"><span class="pulse-title">波形: '+(o&&o.length>12?o.slice(0,12)+"...":o)+'</span><span class="pulse-version">v'+i+'</span><button class="Button Button--primary hasIcon pulse-download-btn"><i class="fas fa-file-download"></i></button></div>',"3"!=i&&(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],i=o.split("/"),a=o.match(/^(\d+,\d+,\d+=)?/);if(a&&a[1]){var l=o.substring(a[0].length).split("/");if(2!==l.length)return!1;e=l[0].split(","),n=l[1].split(",")}else{if(2!==i.length)return!1;e=i[0].split(","),n=i[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}(r)||(e=!0,n.push("解析失败,请检查数据格式是否正确")),e?(null==(a=t.querySelector(".pulse-download-btn"))||a.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,i=e[0].split("=");if(2===i.length){var a=i[0],l=i[1],s=a.split(",").map(Number),d=(s[0],s[1]);s[2],o=d||1,e[0]=l}return e.forEach(function(t){var e=t.split("/"),o=e[0],i=e[1],a=o.split(",").map(Number),l=a[0],s=a[1],d=a[2],p=a[3],f=a[4],m=c[d];if(0!==f)for(var v=i.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,i){var a,c=o.split("-").map(Number),d=c[0],f=(c[1],d),m=n-e+10*i,h=100-f;a=1===p?u[l]:2===p?u[l+Math.floor((s-l)*((v.length*t+i)/(v.length*b)))]:3===p?u[l+Math.floor((s-l)*i/v.length)]:4===p?u[l+Math.floor(t/b*(s-l))]:u[l];var g=.5,y=Math.floor(100/a);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 '}(r),t.setAttribute("data-pulse-rendered","1");var l=t.querySelector(".pulse-download-btn");l&&l.addEventListener("click",function(){var t=new Blob([r],{type:"text/plain"}),e=document.createElement("a");e.href=URL.createObjectURL(t),e.download=o+".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)(a().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$/,""),i=n.match(/^pulse-(.+?)-\d+$/),a='[pulse title="'+(i?i[1]:n)+'"]'+o.result+"[/pulse]";null==(t=e.attrs)||null==(t=t.composer)||t.editor.insertAtCursor(a)},o.readAsText(r)}}),document.body.appendChild(t),t.click(),document.body.removeChild(t)}}),81)}),d(),document.body.addEventListener("contentupdated",d),new MutationObserver(function(){d()}).observe(document.body,{childList:!0,subtree:!0})})})(),module.exports={}})();
//# sourceMappingURL=forum.js.map