diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c31c14d..24b806a 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -24,10 +24,9 @@ jobs: run: | npm install -g yarn yarn - yarn workspace @summarizer/worker build - yarn workspace @summarizer/logseq build + yarn build mkdir ${{ env.PLUGIN_NAME }} - cp README.md logseq/package.json logseq/icon.png logseq/demo.gif ${{ env.PLUGIN_NAME }} + cp README.md logseq/icon.png logseq/demo.gif ${{ env.PLUGIN_NAME }} mv logseq/dist ${{ env.PLUGIN_NAME }} zip -r ${{ env.PLUGIN_NAME }}.zip ${{ env.PLUGIN_NAME }} ls diff --git a/.gitignore b/.gitignore index 05fa468..a547bf3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,24 @@ -node_modules/ -yarn-error.log -.DS_store +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..0f9c3e6 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "sumy"] + path = sumy + url = git@github.com:miso-belica/sumy.git diff --git a/README.md b/README.md index 05a73c9..34b870b 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,8 @@ Super WIP!!! May not work ## Development 1. yarn -2. yarn workspace @summarizer/worker build -3. yarn workspace @summarizer/logseq build -4. Load the unpacked plugin +2. yarn build +3. Load the unpacked plugin from `dist` ## Icon diff --git a/logseq/demo.gif b/demo.gif similarity index 100% rename from logseq/demo.gif rename to demo.gif diff --git a/logseq/index.html b/index.html similarity index 100% rename from logseq/index.html rename to index.html diff --git a/logseq/index.js b/index.js similarity index 73% rename from logseq/index.js rename to index.js index f206373..cbc1521 100644 --- a/logseq/index.js +++ b/index.js @@ -1,5 +1,7 @@ import "@logseq/libs"; -import createWorker from "@summarizer/worker"; +import PromiseWorker from "promise-worker"; +import InlineWorker from "./worker.js?worker&inline"; +import wheels from "./wheels"; const showError = (err) => { logseq.App.showMsg(err.toString(), "error"); @@ -25,13 +27,22 @@ const settingsSchema = [ ]; let worker; +async function main() { + worker = new PromiseWorker(new InlineWorker()); -function main() { - worker = createWorker(); + await worker.postMessage({ + type: "init", + urls: { + pyodide: logseq.resolveResourceFullUrl("pyodide/pyodide.js"), + punkt: logseq.resolveResourceFullUrl("punkt.zip"), + }, + wheels: wheels.map((wheel) => + logseq.resolveResourceFullUrl(`wheels/${wheel}`) + ), + }); logseq.Editor.registerSlashCommand("Summary", async () => { try { - console.log("settings", logseq.settings); const { language, numberOfSentences } = logseq.settings; const { content, uuid } = await logseq.Editor.getCurrentBlock(); const summary = await worker.postMessage({ diff --git a/logseq/.gitignore b/logseq/.gitignore deleted file mode 100644 index a547bf3..0000000 --- a/logseq/.gitignore +++ /dev/null @@ -1,24 +0,0 @@ -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -pnpm-debug.log* -lerna-debug.log* - -node_modules -dist -dist-ssr -*.local - -# Editor directories and files -.vscode/* -!.vscode/extensions.json -.idea -.DS_Store -*.suo -*.ntvs* -*.njsproj -*.sln -*.sw? diff --git a/logseq/dist/assets/index.8e3ea1aa.js b/logseq/dist/assets/index.8e3ea1aa.js deleted file mode 100644 index 1dbf1c1..0000000 --- a/logseq/dist/assets/index.8e3ea1aa.js +++ /dev/null @@ -1,10 +0,0 @@ -var jn=Object.defineProperty;var ln=Object.getOwnPropertySymbols;var _n=Object.prototype.hasOwnProperty,Cn=Object.prototype.propertyIsEnumerable;var vn=(U,B,K)=>B in U?jn(U,B,{enumerable:!0,configurable:!0,writable:!0,value:K}):U[B]=K,wn=(U,B)=>{for(var K in B||(B={}))_n.call(B,K)&&vn(U,K,B[K]);if(ln)for(var K of ln(B))Cn.call(B,K)&&vn(U,K,B[K]);return U};var xn=(U,B)=>{var K={};for(var rt in U)_n.call(U,rt)&&B.indexOf(rt)<0&&(K[rt]=U[rt]);if(U!=null&&ln)for(var rt of ln(U))B.indexOf(rt)<0&&Cn.call(U,rt)&&(K[rt]=U[rt]);return K};var N=(U,B,K)=>(vn(U,typeof B!="symbol"?B+"":B,K),K);const Ln=function(){const B=document.createElement("link").relList;if(B&&B.supports&&B.supports("modulepreload"))return;for(const V of document.querySelectorAll('link[rel="modulepreload"]'))rt(V);new MutationObserver(V=>{for(const ut of V)if(ut.type==="childList")for(const R of ut.addedNodes)R.tagName==="LINK"&&R.rel==="modulepreload"&&rt(R)}).observe(document,{childList:!0,subtree:!0});function K(V){const ut={};return V.integrity&&(ut.integrity=V.integrity),V.referrerpolicy&&(ut.referrerPolicy=V.referrerpolicy),V.crossorigin==="use-credentials"?ut.credentials="include":V.crossorigin==="anonymous"?ut.credentials="omit":ut.credentials="same-origin",ut}function rt(V){if(V.ep)return;V.ep=!0;const ut=K(V);fetch(V.href,ut)}};Ln();var un=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},Sn={exports:{}};/*! For license information please see lsplugin.user.js.LICENSE.txt */(function(U,B){(function(K,rt){U.exports=rt()})(self,function(){return(()=>{var K={227:(R,d,v)=>{var O=v(155);d.formatArgs=function(L){if(L[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+L[0]+(this.useColors?"%c ":" ")+"+"+R.exports.humanize(this.diff),!this.useColors)return;const T="color: "+this.color;L.splice(1,0,T,"color: inherit");let h=0,l=0;L[0].replace(/%[a-zA-Z%]/g,g=>{g!=="%%"&&(h++,g==="%c"&&(l=h))}),L.splice(l,0,T)},d.save=function(L){try{L?d.storage.setItem("debug",L):d.storage.removeItem("debug")}catch{}},d.load=function(){let L;try{L=d.storage.getItem("debug")}catch{}return!L&&O!==void 0&&"env"in O&&(L=O.env.DEBUG),L},d.useColors=function(){return!(typeof window=="undefined"||!window.process||window.process.type!=="renderer"&&!window.process.__nwjs)||(typeof navigator=="undefined"||!navigator.userAgent||!navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))&&(typeof document!="undefined"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window!="undefined"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||typeof navigator!="undefined"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))},d.storage=function(){try{return localStorage}catch{}}(),d.destroy=(()=>{let L=!1;return()=>{L||(L=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),d.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],d.log=console.debug||console.log||(()=>{}),R.exports=v(447)(d);const{formatters:_}=R.exports;_.j=function(L){try{return JSON.stringify(L)}catch(T){return"[UnexpectedJSONParseError]: "+T.message}}},447:(R,d,v)=>{R.exports=function(O){function _(h){let l,g=null;function m(...E){if(!m.enabled)return;const X=m,H=Number(new Date),D=H-(l||H);X.diff=D,X.prev=l,X.curr=H,l=H,E[0]=_.coerce(E[0]),typeof E[0]!="string"&&E.unshift("%O");let C=0;E[0]=E[0].replace(/%([a-zA-Z%])/g,(F,i)=>{if(F==="%%")return"%";C++;const a=_.formatters[i];if(typeof a=="function"){const f=E[C];F=a.call(X,f),E.splice(C,1),C--}return F}),_.formatArgs.call(X,E),(X.log||_.log).apply(X,E)}return m.namespace=h,m.useColors=_.useColors(),m.color=_.selectColor(h),m.extend=L,m.destroy=_.destroy,Object.defineProperty(m,"enabled",{enumerable:!0,configurable:!1,get:()=>g===null?_.enabled(h):g,set:E=>{g=E}}),typeof _.init=="function"&&_.init(m),m}function L(h,l){const g=_(this.namespace+(l===void 0?":":l)+h);return g.log=this.log,g}function T(h){return h.toString().substring(2,h.toString().length-2).replace(/\.\*\?$/,"*")}return _.debug=_,_.default=_,_.coerce=function(h){return h instanceof Error?h.stack||h.message:h},_.disable=function(){const h=[..._.names.map(T),..._.skips.map(T).map(l=>"-"+l)].join(",");return _.enable(""),h},_.enable=function(h){let l;_.save(h),_.names=[],_.skips=[];const g=(typeof h=="string"?h:"").split(/[\s,]+/),m=g.length;for(l=0;l{_[h]=O[h]}),_.names=[],_.skips=[],_.formatters={},_.selectColor=function(h){let l=0;for(let g=0;g1?A-1:0),st=1;st/gm),jt=h(/^data-[\-\w.\u00B7-\uFFFF]/),mt=h(/^aria-[\-\w]+$/),et=h(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|cid|xmpp):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),St=h(/^(?:\w+script|data):/i),Tt=h(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Lt=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(M){return typeof M}:function(M){return M&&typeof Symbol=="function"&&M.constructor===Symbol&&M!==Symbol.prototype?"symbol":typeof M};function _t(M){if(Array.isArray(M)){for(var W=0,A=Array(M.length);W0&&arguments[0]!==void 0?arguments[0]:Ut(),A=function(o){return M(o)};if(A.version="2.3.1",A.removed=[],!W||!W.document||W.document.nodeType!==9)return A.isSupported=!1,A;var it=W.document,st=W.document,Vt=W.DocumentFragment,Me=W.HTMLTemplateElement,re=W.Node,Ge=W.Element,ue=W.NodeFilter,Yt=W.NamedNodeMap,Ne=Yt===void 0?W.NamedNodeMap||W.MozNamedAttrMap:Yt,ze=W.Text,dn=W.Comment,pn=W.DOMParser,ke=W.trustedTypes,Dt=Ge.prototype,Ue=yt(Dt,"cloneNode"),Ae=yt(Dt,"nextSibling"),He=yt(Dt,"childNodes"),de=yt(Dt,"parentNode");if(typeof Me=="function"){var pe=st.createElement("template");pe.content&&pe.content.ownerDocument&&(st=pe.content.ownerDocument)}var Et=le(ke,it),Xe=Et&&Qt?Et.createHTML(""):"",fe=st,he=fe.implementation,fn=fe.createNodeIterator,hn=fe.createDocumentFragment,nt=fe.getElementsByTagName,Be=it.importNode,Jt={};try{Jt=pt(st).documentMode?st.documentMode:{}}catch{}var At={};A.isSupported=typeof de=="function"&&he&&he.createHTMLDocument!==void 0&&Jt!==9;var me=bt,ge=Pt,Pe=jt,Oe=mt,mn=St,Ve=Tt,Fe=et,vt=null,Ye=Z({},[].concat(_t(Gt),_t(Bt),_t(c),_t(j),_t(xt))),Ct=null,De=Z({},[].concat(_t(ft),_t($),_t(lt),_t(ht))),je=null,ye=null,Je=!0,Le=!0,Ke=!1,Ht=!1,Kt=!1,be=!1,Te=!1,$t=!1,ve=!1,$e=!0,Qt=!1,we=!0,Ee=!0,oe=!1,qt={},Xt=null,Re=Z({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]),ie=null,Qe=Z({},["audio","video","img","source","image","track"]),se=null,qe=Z({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),_e="http://www.w3.org/1998/Math/MathML",Rt="http://www.w3.org/2000/svg",Nt="http://www.w3.org/1999/xhtml",Ce=Nt,xe=!1,te=null,gn=st.createElement("form"),ae=function(o){te&&te===o||(o&&(o===void 0?"undefined":Lt(o))==="object"||(o={}),o=pt(o),vt="ALLOWED_TAGS"in o?Z({},o.ALLOWED_TAGS):Ye,Ct="ALLOWED_ATTR"in o?Z({},o.ALLOWED_ATTR):De,se="ADD_URI_SAFE_ATTR"in o?Z(pt(qe),o.ADD_URI_SAFE_ATTR):qe,ie="ADD_DATA_URI_TAGS"in o?Z(pt(Qe),o.ADD_DATA_URI_TAGS):Qe,Xt="FORBID_CONTENTS"in o?Z({},o.FORBID_CONTENTS):Re,je="FORBID_TAGS"in o?Z({},o.FORBID_TAGS):{},ye="FORBID_ATTR"in o?Z({},o.FORBID_ATTR):{},qt="USE_PROFILES"in o&&o.USE_PROFILES,Je=o.ALLOW_ARIA_ATTR!==!1,Le=o.ALLOW_DATA_ATTR!==!1,Ke=o.ALLOW_UNKNOWN_PROTOCOLS||!1,Ht=o.SAFE_FOR_TEMPLATES||!1,Kt=o.WHOLE_DOCUMENT||!1,$t=o.RETURN_DOM||!1,ve=o.RETURN_DOM_FRAGMENT||!1,$e=o.RETURN_DOM_IMPORT!==!1,Qt=o.RETURN_TRUSTED_TYPE||!1,Te=o.FORCE_BODY||!1,we=o.SANITIZE_DOM!==!1,Ee=o.KEEP_CONTENT!==!1,oe=o.IN_PLACE||!1,Fe=o.ALLOWED_URI_REGEXP||Fe,Ce=o.NAMESPACE||Nt,Ht&&(Le=!1),ve&&($t=!0),qt&&(vt=Z({},[].concat(_t(xt))),Ct=[],qt.html===!0&&(Z(vt,Gt),Z(Ct,ft)),qt.svg===!0&&(Z(vt,Bt),Z(Ct,$),Z(Ct,ht)),qt.svgFilters===!0&&(Z(vt,c),Z(Ct,$),Z(Ct,ht)),qt.mathMl===!0&&(Z(vt,j),Z(Ct,lt),Z(Ct,ht))),o.ADD_TAGS&&(vt===Ye&&(vt=pt(vt)),Z(vt,o.ADD_TAGS)),o.ADD_ATTR&&(Ct===De&&(Ct=pt(Ct)),Z(Ct,o.ADD_ATTR)),o.ADD_URI_SAFE_ATTR&&Z(se,o.ADD_URI_SAFE_ATTR),o.FORBID_CONTENTS&&(Xt===Re&&(Xt=pt(Xt)),Z(Xt,o.FORBID_CONTENTS)),Ee&&(vt["#text"]=!0),Kt&&Z(vt,["html","head","body"]),vt.table&&(Z(vt,["tbody"]),delete je.tbody),T&&T(o),te=o)},tn=Z({},["mi","mo","mn","ms","mtext"]),en=Z({},["foreignobject","desc","title","annotation-xml"]),ee=Z({},Bt);Z(ee,c),Z(ee,b);var Ze=Z({},j);Z(Ze,ot);var yn=function(o){var I=de(o);I&&I.tagName||(I={namespaceURI:Nt,tagName:"template"});var w=F(o.tagName),q=F(I.tagName);if(o.namespaceURI===Rt)return I.namespaceURI===Nt?w==="svg":I.namespaceURI===_e?w==="svg"&&(q==="annotation-xml"||tn[q]):Boolean(ee[w]);if(o.namespaceURI===_e)return I.namespaceURI===Nt?w==="math":I.namespaceURI===Rt?w==="math"&&en[q]:Boolean(Ze[w]);if(o.namespaceURI===Nt){if(I.namespaceURI===Rt&&!en[q]||I.namespaceURI===_e&&!tn[q])return!1;var at=Z({},["title","style","font","a","script"]);return!Ze[w]&&(at[w]||!ee[w])}return!1},Zt=function(o){C(A.removed,{element:o});try{o.parentNode.removeChild(o)}catch{try{o.outerHTML=Xe}catch{o.remove()}}},nn=function(o,I){try{C(A.removed,{attribute:I.getAttributeNode(o),from:I})}catch{C(A.removed,{attribute:null,from:I})}if(I.removeAttribute(o),o==="is"&&!Ct[o])if($t||ve)try{Zt(I)}catch{}else try{I.setAttribute(o,"")}catch{}},Wt=function(o){var I=void 0,w=void 0;if(Te)o=""+o;else{var q=i(o,/^[\r\n\t ]+/);w=q&&q[0]}var at=Et?Et.createHTML(o):o;if(Ce===Nt)try{I=new pn().parseFromString(at,"text/html")}catch{}if(!I||!I.documentElement){I=he.createDocument(Ce,"template",null);try{I.documentElement.innerHTML=xe?"":at}catch{}}var It=I.body||I.documentElement;return o&&w&&It.insertBefore(st.createTextNode(w),It.childNodes[0]||null),Ce===Nt?nt.call(I,Kt?"html":"body")[0]:Kt?I.documentElement:It},ce=function(o){return fn.call(o.ownerDocument||o,o,ue.SHOW_ELEMENT|ue.SHOW_COMMENT|ue.SHOW_TEXT,null,!1)},rn=function(o){return!(o instanceof ze||o instanceof dn||typeof o.nodeName=="string"&&typeof o.textContent=="string"&&typeof o.removeChild=="function"&&o.attributes instanceof Ne&&typeof o.removeAttribute=="function"&&typeof o.setAttribute=="function"&&typeof o.namespaceURI=="string"&&typeof o.insertBefore=="function")},zt=function(o){return(re===void 0?"undefined":Lt(re))==="object"?o instanceof re:o&&(o===void 0?"undefined":Lt(o))==="object"&&typeof o.nodeType=="number"&&typeof o.nodeName=="string"},Mt=function(o,I,w){At[o]&&H(At[o],function(q){q.call(A,I,w,te)})},on=function(o){var I=void 0;if(Mt("beforeSanitizeElements",o,null),rn(o)||i(o.nodeName,/[\u0080-\uFFFF]/))return Zt(o),!0;var w=F(o.nodeName);if(Mt("uponSanitizeElement",o,{tagName:w,allowedTags:vt}),!zt(o.firstElementChild)&&(!zt(o.content)||!zt(o.content.firstElementChild))&&P(/<[/\w]/g,o.innerHTML)&&P(/<[/\w]/g,o.textContent)||w==="select"&&P(/