"use strict";var pluginIndexCache,allPluginsCache,__defProp=Object.defineProperty,__getOwnPropDesc=Object.getOwnPropertyDescriptor,__getOwnPropNames=Object.getOwnPropertyNames,__hasOwnProp=Object.prototype.hasOwnProperty,__export=(t,e)=>{for(var i in e)__defProp(t,i,{get:e[i],enumerable:!0})},__copyProps=(e,i,r,o)=>{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:!(o=__getOwnPropDesc(i,t))||o.enumerable});return e},__toCommonJS=t=>__copyProps(__defProp({},"__esModule",{value:!0}),t),plugin_index_exports={},tw=(__export(plugin_index_exports,{after:()=>after,name:()=>name,platforms:()=>platforms,startup:()=>startup,synchronous:()=>synchronous}),module.exports=__toCommonJS(plugin_index_exports),$tw),asPluginInfoList=t=>t,searchLock=!1,name="cpl-plugin-index",platforms=["browser"],after=["startup"],synchronous=!0,handleSearchPlugins=(t,e)=>{if(!searchLock&&void 0!==allPluginsCache&&pluginIndexCache){searchLock=!0;try{if(t.length<3)tw.wiki.addTiddler({title:e,text:JSON.stringify(allPluginsCache),type:"application/json"}),searchLock=!1;else{tw.wiki.addTiddler({title:"$:/temp/CPL-Repo/searching-plugin",text:"yes"});const p=new Set(t.split(/\s+/).map(t=>t.toLowerCase()).slice(0,10));var i=pluginIndexCache.map(t=>{let e=0;for(const r of["title","author","name"]){var i=t[r];if("string"==typeof i)for(const o of p)i.toLowerCase().includes(o)&&(e+=10)}if(t.tags)for(const n of tw.utils.parseStringArray(t.tags))p.has(n.toLowerCase())&&(e+=5);if("string"==typeof t.description)for(const a of p)t.description.toLowerCase().includes(a)&&(e+=2);if("string"==typeof t.description)for(const s of p)t.description.toLowerCase().includes(s)&&(e+=1);return[t.title,e]}).filter(([,t])=>0<t).sort((t,e)=>e[1]-t[1]).map(([t])=>t);tw.wiki.addTiddler({title:e,text:JSON.stringify(i),type:"application/json"}),tw.wiki.deleteTiddler("$:/temp/CPL-Repo/searching-plugin")}}catch(r){console.error(r),tw.wiki.addTiddler({title:"$:/temp/CPL-Repo/searching-plugin",text:String(r)})}finally{searchLock=!1}}},startup=()=>{tw.rootWidget.addEventListener("cpl-process-plugin-index",t=>{var e=t.paramObject?.data;if(e)try{tw.wiki.addTiddler({title:"$:/temp/CPL-Repo/getting-plugins-index",text:"yes"});var i,r=asPluginInfoList(JSON.parse(e)),o={},n={},a={},s=[],p=new Set;for(const d of r)if(o[d.title]=d,s.push(d.title),d.category&&"Unknown"!==d.category&&(n[d.category]??=[],n[d.category].push(d.title)),d.author&&(a[d.author]??=[],a[d.author].push(d.title)),d.title.startsWith("$:/languages")||4!==d.title.split("/").length||(i=d.title.split("/")[2])!==d.author&&(a[i]??=[],a[i].push(d.title)),d.tags)for(const c of tw.utils.parseStringArray(d.tags))p.add(c);pluginIndexCache=r,allPluginsCache=s,tw.wiki.addTiddler({title:"$:/temp/CPL-Repo/plugins-index",text:JSON.stringify(o),type:"application/json"}),tw.wiki.addTiddler({title:"$:/temp/CPL-Repo/categories",text:JSON.stringify(n),type:"application/json"}),tw.wiki.addTiddler({title:"$:/temp/CPL-Repo/authors",text:JSON.stringify(a),type:"application/json"}),tw.wiki.addTiddler({title:"$:/temp/CPL-Repo/tags",text:JSON.stringify(Array.from(p)),type:"application/json"}),tw.wiki.deleteTiddler("$:/temp/CPL-Repo/getting-plugins-index")}catch(l){console.error(l),tw.wiki.addTiddler({title:"$:/temp/CPL-Repo/getting-plugins-index",text:String(l)})}}),tw.rootWidget.addEventListener("cpl-search-plugins",t=>{var e=t.paramObject??{},i=e.query??"",e=e.saveTo??"";e&&handleSearchPlugins(i,e)})};