diff --git a/api/electron.mjs b/api/electron.mjs index 1201f57..f39be56 100644 --- a/api/electron.mjs +++ b/api/electron.mjs @@ -15,12 +15,7 @@ * access to the electron BrowserWindow instance for the current window * see https://www.electronjs.org/docs/latest/api/browser-window * @type {BrowserWindow} - * - * @env win32 - * @env linux - * @env darwin - * @runtime client - * @runtime menu + * @runtime electron (renderer process) */ export const browser = globalThis.__enhancerElectronApi?.browser; @@ -28,12 +23,7 @@ export const browser = globalThis.__enhancerElectronApi?.browser; * access to the electron webFrame instance for the current page * see https://www.electronjs.org/docs/latest/api/web-frame * @type {webFrame} - * - * @env win32 - * @env linux - * @env darwin - * @runtime client - * @runtime menu + * @runtime electron (renderer process) */ export const webFrame = globalThis.__enhancerElectronApi?.webFrame; @@ -44,12 +34,7 @@ export const webFrame = globalThis.__enhancerElectronApi?.webFrame; * @param {string=} namespace - a prefix for the message to categorise * it as e.g. enhancer-related. this should not be changed unless replicating * builtin ipc events. - * - * @env win32 - * @env linux - * @env darwin - * @runtime client - * @runtime menu + * @runtime electron (renderer process) */ export const sendMessage = (channel, data, namespace = 'notion-enhancer') => { if (globalThis.__enhancerElectronApi) { @@ -64,12 +49,7 @@ export const sendMessage = (channel, data, namespace = 'notion-enhancer') => { * @param {string=} namespace - a prefix for the message to categorise * it as e.g. enhancer-related. this should not be changed unless replicating * builtin ipc events. - * - * @env win32 - * @env linux - * @env darwin - * @runtime client - * @runtime menu + * @runtime electron (renderer process) */ export const sendMessageToHost = (channel, data, namespace = 'notion-enhancer') => { if (globalThis.__enhancerElectronApi) { @@ -85,15 +65,41 @@ export const sendMessageToHost = (channel, data, namespace = 'notion-enhancer') * @param {string=} namespace - a prefix for the message to categorise * it as e.g. enhancer-related. this should not be changed unless replicating * builtin ipc events. - * - * @env win32 - * @env linux - * @env darwin - * @runtime client - * @runtime menu + * @runtime electron (renderer process) */ export const onMessage = (channel, callback, namespace = 'notion-enhancer') => { if (globalThis.__enhancerElectronApi) { globalThis.__enhancerElectronApi.ipcRenderer.onMessage(channel, callback, namespace); } }; + +/** + * require() notion app files + * @param {string} path - within notion/resources/app/ e.g. main/createWindow.js + * @runtime electron (main process) + */ +export const notionRequire = (path) => { + return globalThis.__enhancerElectronApi + ? globalThis.__enhancerElectronApi.notionRequire(path) + : null; +}; + +/** + * get all available app windows excluding the menu + * @runtime electron (main process) + */ +export const getNotionWindows = () => { + return globalThis.__enhancerElectronApi + ? globalThis.__enhancerElectronApi.getNotionWindows() + : null; +}; + +/** + * get the currently focused notion window + * @runtime electron (main process) + */ +export const getFocusedNotionWindow = () => { + return globalThis.__enhancerElectronApi + ? globalThis.__enhancerElectronApi.getFocusedNotionWindow() + : null; +}; diff --git a/api/env.mjs b/api/env.mjs index d8a1c06..36598e6 100644 --- a/api/env.mjs +++ b/api/env.mjs @@ -44,14 +44,3 @@ export const focusNotion = env.focusNotion; * @type {function} */ export const reload = env.reload; - -/** - * require() notion app files - * @param {string} path - within notion/resources/app/ e.g. main/createWindow.js - * - * @env win32 - * @env linux - * @env darwin - * @runtime electron - */ -export const notionRequire = env.notionRequire; diff --git a/api/fs.mjs b/api/fs.mjs index a6e40ab..bf20afe 100644 --- a/api/fs.mjs +++ b/api/fs.mjs @@ -50,10 +50,6 @@ export const isFile = fs.isFile; /** * get an absolute path to files within notion * @param {string} path - relative to the root notion/resources/app/ e.g. renderer/search.js - * - * @env win32 - * @env linux - * @env darwin * @runtime electron */ export const notionPath = fs.notionPath; diff --git a/api/index.cjs b/api/index.cjs index aaea141..ab42feb 100644 --- a/api/index.cjs +++ b/api/index.cjs @@ -1,21 +1,21 @@ -var ce=Object.defineProperty;var Ge=e=>ce(e,"__esModule",{value:!0});var g=(e,t)=>{Ge(e);for(var n in t)ce(e,n,{get:t[n],enumerable:!0})};g(exports,{components:()=>N,electron:()=>V,env:()=>E,fmt:()=>h,fs:()=>u,notion:()=>K,registry:()=>y,storage:()=>_,web:()=>o});var E={};g(E,{focusMenu:()=>De,focusNotion:()=>et,name:()=>Qe,notionRequire:()=>nt,reload:()=>tt,version:()=>Ye});"use strict";var le=globalThis.__enhancerElectronApi.platform,de=globalThis.__enhancerElectronApi.version,pe=globalThis.__enhancerElectronApi.focusMenu,ue=globalThis.__enhancerElectronApi.focusNotion,he=globalThis.__enhancerElectronApi.reload,fe=globalThis.__enhancerElectronApi.notionRequire;"use strict";var Qe=le,Ye=de,De=pe,et=ue,tt=he,nt=fe;var u={};g(u,{getJSON:()=>st,getText:()=>ot,isFile:()=>it,localPath:()=>rt,notionPath:()=>at});"use strict";var L=e=>`notion://www.notion.so/__notion-enhancer/${e}`,me=(e,t={})=>{if(e.startsWith("http"))return fetch(e,t).then(n=>n.json());try{return globalThis.__enhancerElectronApi.nodeRequire(`notion-enhancer/${e}`)}catch{return fetch(L(e),t).then(r=>r.json())}},ye=(e,t={})=>{if(e.startsWith("http"))return fetch(e,t).then(n=>n.text());try{let n=globalThis.__enhancerElectronApi.nodeRequire("fs"),{resolve:r}=globalThis.__enhancerElectronApi.nodeRequire("path");return n.readFileSync(r(`${__dirname}/../../${e}`))}catch{return fetch(L(e),t).then(r=>r.text())}},ge=async e=>{try{let t=globalThis.__enhancerElectronApi.nodeRequire("fs"),{resolve:n}=globalThis.__enhancerElectronApi.nodeRequire("path");if(e.startsWith("http"))await fetch(e);else try{t.existsSync(n(`${__dirname}/../../${e}`))}catch{await fetch(L(e))}return!0}catch{return!1}},ve=globalThis.__enhancerElectronApi.notionPath;"use strict";var rt=L,st=me,ot=ye,it=ge,at=ve;var _={};g(_,{addChangeListener:()=>pt,db:()=>dt,get:()=>ct,removeChangeListener:()=>ut,set:()=>lt});"use strict";var F=(e,t=void 0)=>globalThis.__enhancerElectronApi.db.get(e,t),H=(e,t)=>globalThis.__enhancerElectronApi.db.set(e,t),we=(e,t=F,n=H)=>(typeof e=="string"&&(e=[e]),{get:(r=[],s=void 0)=>t([...e,...r],s),set:(r,s)=>n([...e,...r],s)}),be=e=>globalThis.__enhancerElectronApi.db.addChangeListener(e),xe=e=>globalThis.__enhancerElectronApi.db.removeChangeListener(e);"use strict";var ct=F,lt=H,dt=we,pt=be,ut=xe;var V={};g(V,{browser:()=>ht,onMessage:()=>gt,sendMessage:()=>mt,sendMessageToHost:()=>yt,webFrame:()=>ft});"use strict";var ht=globalThis.__enhancerElectronApi?.browser,ft=globalThis.__enhancerElectronApi?.webFrame,mt=(e,t,n="notion-enhancer")=>{globalThis.__enhancerElectronApi&&globalThis.__enhancerElectronApi.ipcRenderer.sendMessage(e,t,n)},yt=(e,t,n="notion-enhancer")=>{globalThis.__enhancerElectronApi&&globalThis.__enhancerElectronApi.ipcRenderer.sendMessageToHost(e,t,n)},gt=(e,t,n="notion-enhancer")=>{globalThis.__enhancerElectronApi&&globalThis.__enhancerElectronApi.ipcRenderer.onMessage(e,t,n)};var K={};g(K,{create:()=>bt,get:()=>$e,getPageID:()=>M,getSpaceID:()=>S,getUserID:()=>_e,search:()=>vt,set:()=>wt,sign:()=>_t,upload:()=>xt});"use strict";var m=e=>(e?.length===32&&!e.includes("-")&&(e=e.replace(/([\d\w]{8})([\d\w]{4})([\d\w]{4})([\d\w]{4})([\d\w]{12})/,"$1-$2-$3-$4-$5")),e),_e=()=>JSON.parse(localStorage["LRU:KeyValueStore2:current-user-id"]||{}).value,M=()=>m(o.queryParams().get("p")||location.pathname.split(/(-|\/)/g).reverse()[0]),I,S=async()=>(I||(I=(await $e(M())).space_id),I),$e=async(e,t="block")=>(e=m(e),(await u.getJSON("https://www.notion.so/api/v3/getRecordValues",{headers:{"Content-Type":"application/json"},body:JSON.stringify({requests:[{table:t,id:e}]}),method:"POST"})).results[0].value),vt=async(e="",t=20,n=S())=>(n=m(await n),await u.getJSON("https://www.notion.so/api/v3/search",{headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"BlocksInSpace",query:e,spaceId:n,limit:t,filters:{isDeletedOnly:!1,excludeTemplates:!1,isNavigableOnly:!1,requireEditPermissions:!1,ancestors:[],createdBy:[],editedBy:[],lastEditedTime:{},createdTime:{}},sort:"Relevance",source:"quick_find"}),method:"POST"})),wt=async({recordID:e,recordTable:t="block",spaceID:n=S(),path:r=[]},s={})=>{n=m(await n),e=m(e);let c=await u.getJSON("https://www.notion.so/api/v3/saveTransactions",{headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:h.uuidv4(),transactions:[{id:h.uuidv4(),spaceId:n,operations:[{pointer:{table:t,id:e,spaceId:n},path:r,command:r.length?"set":"update",args:s}]}]}),method:"POST"});return c.errorId?c:!0},bt=async({recordValue:e={},recordTable:t="block"}={},{prepend:n=!1,siblingID:r=void 0,parentID:s=M(),parentTable:c="block",spaceID:a=S(),userID:i=_e()}={})=>{a=m(await a),s=m(s),r=m(r);let d=m(e?.id??h.uuidv4()),x=[],A={type:"text",id:d,version:0,created_time:new Date().getTime(),last_edited_time:new Date().getTime(),parent_id:s,parent_table:c,alive:!0,created_by_table:"notion_user",created_by_id:i,last_edited_by_table:"notion_user",last_edited_by_id:i,space_id:a,permissions:[{type:"user_permission",role:"editor",user_id:i}]};c==="space"?(s=a,A.parent_id=a,x.push("pages"),A.type="page"):c==="collection_view"?(x.push("page_sort"),A.type="page"):x.push("content");let ae=await u.getJSON("https://www.notion.so/api/v3/saveTransactions",{headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:h.uuidv4(),transactions:[{id:h.uuidv4(),spaceId:a,operations:[{pointer:{table:c,id:s,spaceId:a},path:x,command:n?"listBefore":"listAfter",args:{...r?{after:r}:{},id:d}},{pointer:{table:t,id:d,spaceId:a},path:[],command:"set",args:{...A,...e}}]}]}),method:"POST"});return ae.errorId?ae:d},xt=async(e,{pageID:t=M(),spaceID:n=S()}={})=>{n=m(await n),t=m(t);let r=await u.getJSON("https://www.notion.so/api/v3/getUploadFileUrl",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({bucket:"secure",name:e.name,contentType:e.type,record:{table:"block",id:t,spaceId:n}})});return r.errorId?r:(fetch(r.signedPutUrl,{method:"PUT",headers:{"content-type":e.type},body:e}),r.url)},_t=(e,t,n="block")=>(e.startsWith("/")&&(e=`https://notion.so${e}`),e.includes("secure.notion-static.com")&&(e=new URL(e),e=`https://www.notion.so/signed/${encodeURIComponent(e.origin+e.pathname)}?table=${n}&id=${t}`),e);var h={};g(h,{is:()=>Tt,rgbContrast:()=>Et,rgbLogShade:()=>jt,slugger:()=>$t,uuidv4:()=>At});"use strict";var $t=(e,t=new Set)=>{e=e.replace(/\s/g,"-").replace(/[^A-Za-z0-9-_]/g,"").toLowerCase();let n=0,r=e;for(;t.has(r);)n++,r=`${e}-${n}`;return r},At=()=>crypto?.randomUUID?crypto.randomUUID():([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)),jt=(e,t)=>{var n=parseInt,r=Math.round,[s,c,t,a]=t.split(","),i=e<0,d=i?0:e*255**2,i=i?1+e:1-e;return"rgb"+(a?"a(":"(")+r((i*n(s[3]=="a"?s.slice(5):s.slice(4))**2+d)**.5)+","+r((i*n(c)**2+d)**.5)+","+r((i*n(t)**2+d)**.5)+(a?","+a:")")},Et=(e,t,n)=>Math.sqrt(.299*(e*e)+.587*(t*t)+.114*(n*n))>165.75?"rgb(0,0,0)":"rgb(255,255,255)",Lt={alphanumeric:/^[\w\.-]+$/,uuid:/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,semver:/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/i,email:/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i,url:/^[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,64}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/i,color:/^(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\b|(?:rgb|hsl)a?\([^\)]*\)$/i};function St(e,t){let n=e.match(t);return!!(n&&n.length)}var Tt=async(e,t,{extension:n=""}={})=>{if(n=!e||!e.endsWith||e.endsWith(n),Array.isArray(t))return t.includes(e);switch(t){case"array":return Array.isArray(e);case"object":return e&&typeof e=="object"&&!Array.isArray(e);case"undefined":case"boolean":case"number":return typeof e===t&&n;case"string":return typeof e===t&&n;case"alphanumeric":case"uuid":case"semver":case"email":case"url":case"color":return typeof e=="string"&&St(e,Lt[t])&&n;case"file":return typeof e=="string"&&e&&await u.isFile(e)&&n}return!1};var y={};g(y,{core:()=>je,db:()=>Ut,enabled:()=>zt,errors:()=>Jt,get:()=>D,list:()=>Y,optionDefault:()=>Le,optionTypes:()=>Mt,profileDB:()=>X,profileName:()=>Ee,supportedEnvs:()=>qt});"use strict";var l=async(e,t,n,r,{extension:s="",error:c=`invalid ${t} (${s?`${s} `:""}${r}): ${JSON.stringify(n)}`,optional:a=!1}={})=>{let i;for(let d of Array.isArray(r)?[r]:r.split("|"))if(d==="file"?i=n&&!n.startsWith("http")?await h.is(`repo/${e._dir}/${n}`,d,{extension:s}):!1:i=await h.is(n,d,{extension:s}),i)break;return i||a&&await h.is(n,"undefined")?!0:(c&&e._err(c),!1)},kt=async e=>(e.environments=e.environments??y.supportedEnvs,await l(e,"environments",e.environments,"array")?e.environments.map(n=>l(e,"environments.env",n,y.supportedEnvs)):!1),Ct=async e=>{if(!await l(e,"tags",e.tags,"array"))return!1;let n=["core","extension","theme","integration"];if(!e.tags.filter(i=>n.includes(i)).length)return e._err(`invalid tags (must contain at least one of 'core', 'extension', 'theme' or 'integration'): +var ce=Object.defineProperty;var Xe=e=>ce(e,"__esModule",{value:!0});var y=(e,t)=>{Xe(e);for(var n in t)ce(e,n,{get:t[n],enumerable:!0})};y(exports,{components:()=>R,electron:()=>I,env:()=>j,fmt:()=>h,fs:()=>u,notion:()=>K,registry:()=>g,storage:()=>_,web:()=>o});var j={};y(j,{focusMenu:()=>Ye,focusNotion:()=>De,name:()=>Ge,reload:()=>et,version:()=>Qe});"use strict";var le=globalThis.__enhancerElectronApi.platform,de=globalThis.__enhancerElectronApi.version,pe=globalThis.__enhancerElectronApi.focusMenu,ue=globalThis.__enhancerElectronApi.focusNotion,he=globalThis.__enhancerElectronApi.reload;"use strict";var Ge=le,Qe=de,Ye=pe,De=ue,et=he;var u={};y(u,{getJSON:()=>nt,getText:()=>rt,isFile:()=>st,localPath:()=>tt,notionPath:()=>ot});"use strict";var T=e=>`notion://www.notion.so/__notion-enhancer/${e}`,fe=(e,t={})=>{if(e.startsWith("http"))return fetch(e,t).then(n=>n.json());try{return globalThis.__enhancerElectronApi.nodeRequire(`notion-enhancer/${e}`)}catch{return fetch(T(e),t).then(r=>r.json())}},me=(e,t={})=>{if(e.startsWith("http"))return fetch(e,t).then(n=>n.text());try{let n=globalThis.__enhancerElectronApi.nodeRequire("fs"),{resolve:r}=globalThis.__enhancerElectronApi.nodeRequire("path");return n.readFileSync(r(`${__dirname}/../../${e}`))}catch{return fetch(T(e),t).then(r=>r.text())}},ge=async e=>{try{let t=globalThis.__enhancerElectronApi.nodeRequire("fs"),{resolve:n}=globalThis.__enhancerElectronApi.nodeRequire("path");if(e.startsWith("http"))await fetch(e);else try{t.existsSync(n(`${__dirname}/../../${e}`))}catch{await fetch(T(e))}return!0}catch{return!1}},ye=globalThis.__enhancerElectronApi.notionPath;"use strict";var tt=T,nt=fe,rt=me,st=ge,ot=ye;var _={};y(_,{addChangeListener:()=>lt,db:()=>ct,get:()=>it,removeChangeListener:()=>dt,set:()=>at});"use strict";var F=(e,t=void 0)=>globalThis.__enhancerElectronApi.db.get(e,t),H=(e,t)=>globalThis.__enhancerElectronApi.db.set(e,t),ve=(e,t=F,n=H)=>(typeof e=="string"&&(e=[e]),{get:(r=[],s=void 0)=>t([...e,...r],s),set:(r,s)=>n([...e,...r],s)}),we=e=>globalThis.__enhancerElectronApi.db.addChangeListener(e),be=e=>globalThis.__enhancerElectronApi.db.removeChangeListener(e);"use strict";var it=F,at=H,ct=ve,lt=we,dt=be;var I={};y(I,{browser:()=>pt,getFocusedNotionWindow:()=>vt,getNotionWindows:()=>yt,notionRequire:()=>gt,onMessage:()=>mt,sendMessage:()=>ht,sendMessageToHost:()=>ft,webFrame:()=>ut});"use strict";var pt=globalThis.__enhancerElectronApi?.browser,ut=globalThis.__enhancerElectronApi?.webFrame,ht=(e,t,n="notion-enhancer")=>{globalThis.__enhancerElectronApi&&globalThis.__enhancerElectronApi.ipcRenderer.sendMessage(e,t,n)},ft=(e,t,n="notion-enhancer")=>{globalThis.__enhancerElectronApi&&globalThis.__enhancerElectronApi.ipcRenderer.sendMessageToHost(e,t,n)},mt=(e,t,n="notion-enhancer")=>{globalThis.__enhancerElectronApi&&globalThis.__enhancerElectronApi.ipcRenderer.onMessage(e,t,n)},gt=e=>globalThis.__enhancerElectronApi?globalThis.__enhancerElectronApi.notionRequire(e):null,yt=()=>globalThis.__enhancerElectronApi?globalThis.__enhancerElectronApi.getNotionWindows():null,vt=()=>globalThis.__enhancerElectronApi?globalThis.__enhancerElectronApi.getFocusedNotionWindow():null;var K={};y(K,{create:()=>xt,get:()=>_e,getPageID:()=>M,getSpaceID:()=>L,getUserID:()=>xe,search:()=>wt,set:()=>bt,sign:()=>$t,upload:()=>_t});"use strict";var m=e=>(e?.length===32&&!e.includes("-")&&(e=e.replace(/([\d\w]{8})([\d\w]{4})([\d\w]{4})([\d\w]{4})([\d\w]{12})/,"$1-$2-$3-$4-$5")),e),xe=()=>JSON.parse(localStorage["LRU:KeyValueStore2:current-user-id"]||{}).value,M=()=>m(o.queryParams().get("p")||location.pathname.split(/(-|\/)/g).reverse()[0]),V,L=async()=>(V||(V=(await _e(M())).space_id),V),_e=async(e,t="block")=>(e=m(e),(await u.getJSON("https://www.notion.so/api/v3/getRecordValues",{headers:{"Content-Type":"application/json"},body:JSON.stringify({requests:[{table:t,id:e}]}),method:"POST"})).results[0].value),wt=async(e="",t=20,n=L())=>(n=m(await n),await u.getJSON("https://www.notion.so/api/v3/search",{headers:{"Content-Type":"application/json"},body:JSON.stringify({type:"BlocksInSpace",query:e,spaceId:n,limit:t,filters:{isDeletedOnly:!1,excludeTemplates:!1,isNavigableOnly:!1,requireEditPermissions:!1,ancestors:[],createdBy:[],editedBy:[],lastEditedTime:{},createdTime:{}},sort:"Relevance",source:"quick_find"}),method:"POST"})),bt=async({recordID:e,recordTable:t="block",spaceID:n=L(),path:r=[]},s={})=>{n=m(await n),e=m(e);let c=await u.getJSON("https://www.notion.so/api/v3/saveTransactions",{headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:h.uuidv4(),transactions:[{id:h.uuidv4(),spaceId:n,operations:[{pointer:{table:t,id:e,spaceId:n},path:r,command:r.length?"set":"update",args:s}]}]}),method:"POST"});return c.errorId?c:!0},xt=async({recordValue:e={},recordTable:t="block"}={},{prepend:n=!1,siblingID:r=void 0,parentID:s=M(),parentTable:c="block",spaceID:a=L(),userID:i=xe()}={})=>{a=m(await a),s=m(s),r=m(r);let d=m(e?.id??h.uuidv4()),x=[],A={type:"text",id:d,version:0,created_time:new Date().getTime(),last_edited_time:new Date().getTime(),parent_id:s,parent_table:c,alive:!0,created_by_table:"notion_user",created_by_id:i,last_edited_by_table:"notion_user",last_edited_by_id:i,space_id:a,permissions:[{type:"user_permission",role:"editor",user_id:i}]};c==="space"?(s=a,A.parent_id=a,x.push("pages"),A.type="page"):c==="collection_view"?(x.push("page_sort"),A.type="page"):x.push("content");let ae=await u.getJSON("https://www.notion.so/api/v3/saveTransactions",{headers:{"Content-Type":"application/json"},body:JSON.stringify({requestId:h.uuidv4(),transactions:[{id:h.uuidv4(),spaceId:a,operations:[{pointer:{table:c,id:s,spaceId:a},path:x,command:n?"listBefore":"listAfter",args:{...r?{after:r}:{},id:d}},{pointer:{table:t,id:d,spaceId:a},path:[],command:"set",args:{...A,...e}}]}]}),method:"POST"});return ae.errorId?ae:d},_t=async(e,{pageID:t=M(),spaceID:n=L()}={})=>{n=m(await n),t=m(t);let r=await u.getJSON("https://www.notion.so/api/v3/getUploadFileUrl",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({bucket:"secure",name:e.name,contentType:e.type,record:{table:"block",id:t,spaceId:n}})});return r.errorId?r:(fetch(r.signedPutUrl,{method:"PUT",headers:{"content-type":e.type},body:e}),r.url)},$t=(e,t,n="block")=>(e.startsWith("/")&&(e=`https://notion.so${e}`),e.includes("secure.notion-static.com")&&(e=new URL(e),e=`https://www.notion.so/signed/${encodeURIComponent(e.origin+e.pathname)}?table=${n}&id=${t}`),e);var h={};y(h,{is:()=>kt,rgbContrast:()=>Tt,rgbLogShade:()=>jt,slugger:()=>At,uuidv4:()=>Et});"use strict";var At=(e,t=new Set)=>{e=e.replace(/\s/g,"-").replace(/[^A-Za-z0-9-_]/g,"").toLowerCase();let n=0,r=e;for(;t.has(r);)n++,r=`${e}-${n}`;return r},Et=()=>crypto?.randomUUID?crypto.randomUUID():([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16)),jt=(e,t)=>{var n=parseInt,r=Math.round,[s,c,t,a]=t.split(","),i=e<0,d=i?0:e*255**2,i=i?1+e:1-e;return"rgb"+(a?"a(":"(")+r((i*n(s[3]=="a"?s.slice(5):s.slice(4))**2+d)**.5)+","+r((i*n(c)**2+d)**.5)+","+r((i*n(t)**2+d)**.5)+(a?","+a:")")},Tt=(e,t,n)=>Math.sqrt(.299*(e*e)+.587*(t*t)+.114*(n*n))>165.75?"rgb(0,0,0)":"rgb(255,255,255)",Lt={alphanumeric:/^[\w\.-]+$/,uuid:/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,semver:/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/i,email:/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/i,url:/^[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,64}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)$/i,color:/^(?:#|0x)(?:[a-f0-9]{3}|[a-f0-9]{6})\b|(?:rgb|hsl)a?\([^\)]*\)$/i};function St(e,t){let n=e.match(t);return!!(n&&n.length)}var kt=async(e,t,{extension:n=""}={})=>{if(n=!e||!e.endsWith||e.endsWith(n),Array.isArray(t))return t.includes(e);switch(t){case"array":return Array.isArray(e);case"object":return e&&typeof e=="object"&&!Array.isArray(e);case"undefined":case"boolean":case"number":return typeof e===t&&n;case"string":return typeof e===t&&n;case"alphanumeric":case"uuid":case"semver":case"email":case"url":case"color":return typeof e=="string"&&St(e,Lt[t])&&n;case"file":return typeof e=="string"&&e&&await u.isFile(e)&&n}return!1};var g={};y(g,{core:()=>Ae,db:()=>Wt,enabled:()=>Ut,errors:()=>zt,get:()=>D,list:()=>Y,optionDefault:()=>je,optionTypes:()=>Jt,profileDB:()=>X,profileName:()=>Ee,supportedEnvs:()=>Mt});"use strict";var l=async(e,t,n,r,{extension:s="",error:c=`invalid ${t} (${s?`${s} `:""}${r}): ${JSON.stringify(n)}`,optional:a=!1}={})=>{let i;for(let d of Array.isArray(r)?[r]:r.split("|"))if(d==="file"?i=n&&!n.startsWith("http")?await h.is(`repo/${e._dir}/${n}`,d,{extension:s}):!1:i=await h.is(n,d,{extension:s}),i)break;return i||a&&await h.is(n,"undefined")?!0:(c&&e._err(c),!1)},Ct=async e=>(e.environments=e.environments??g.supportedEnvs,await l(e,"environments",e.environments,"array")?e.environments.map(n=>l(e,"environments.env",n,g.supportedEnvs)):!1),Pt=async e=>{if(!await l(e,"tags",e.tags,"array"))return!1;let n=["core","extension","theme","integration"];if(!e.tags.filter(i=>n.includes(i)).length)return e._err(`invalid tags (must contain at least one of 'core', 'extension', 'theme' or 'integration'): ${JSON.stringify(e.tags)}`),!1;let s=e.tags.includes("theme"),c=e.tags.includes("light")||e.tags.includes("dark"),a=e.tags.includes("light")&&e.tags.includes("dark");return s&&(!c||a)?(e._err(`invalid tags (themes must be either 'light' or 'dark', not neither or both): - ${JSON.stringify(e.tags)}`),!1):e.tags.map(i=>l(e,"tags.tag",i,"string"))},Pt=async e=>await l(e,"authors",e.authors,"array")?e.authors.map(n=>[l(e,"authors.author.name",n.name,"string"),l(e,"authors.author.email",n.email,"email",{optional:!0}),l(e,"authors.author.homepage",n.homepage,"url"),l(e,"authors.author.avatar",n.avatar,"url")]):!1,Ot=async e=>{if(!await l(e,"css",e.css,"object"))return!1;let n=[];for(let r of["frame","client","menu"]){if(!e.css[r])continue;let s=await l(e,`css.${r}`,e.css[r],"array");s&&(s=e.css[r].map(c=>l(e,`css.${r}.file`,c,"file",{extension:".css"}))),n.push(s)}return n},Rt=async e=>{if(!await l(e,"js",e.js,"object"))return!1;let n=[];for(let r of["frame","client","menu"]){if(!e.js[r])continue;let s=await l(e,`js.${r}`,e.js[r],"array");s&&(s=e.js[r].map(c=>l(e,`js.${r}.file`,c,"file",{extension:".mjs"}))),n.push(s)}if(e.js.electron)if(await l(e,"js.electron",e.js.electron,"array"))for(let s of e.js.electron){if(!await l(e,"js.electron.file",s,"object")){n.push(!1);continue}n.push([l(e,"js.electron.file.source",s.source,"file",{extension:".cjs"}),l(e,"js.electron.file.target",s.target,"string",{extension:".js"})])}else n.push(!1);return n},Nt=async e=>{if(!await l(e,"options",e.options,"array"))return!1;let n=[];for(let r of e.options){let s="options.option";if(!await l(e,`${s}.type`,r.type,y.optionTypes)){n.push(!1);continue}switch(r.environments=r.environments??y.supportedEnvs,n.push([l(e,`${s}.key`,r.key,"alphanumeric"),l(e,`${s}.label`,r.label,"string"),l(e,`${s}.tooltip`,r.tooltip,"string",{optional:!0}),l(e,`${s}.environments`,r.environments,"array").then(a=>a?r.environments.map(i=>l(e,`${s}.environments.env`,i,y.supportedEnvs)):!1)]),r.type){case"toggle":n.push(l(e,`${s}.value`,r.value,"boolean"));break;case"select":{let a=await l(e,`${s}.values`,r.values,"array");a&&(a=r.values.map(i=>l(e,`${s}.values.value`,i,"string"))),n.push(a);break}case"text":case"hotkey":n.push(l(e,`${s}.value`,r.value,"string"));break;case"number":case"color":n.push(l(e,`${s}.value`,r.value,r.type));break;case"file":{let a=await l(e,`${s}.extensions`,r.extensions,"array");a&&(a=r.extensions.map(i=>l(e,`${s}.extensions.extension`,i,"string"))),n.push(a);break}}}return n};async function Ae(e){let t=[l(e,"name",e.name,"string"),l(e,"id",e.id,"uuid"),l(e,"version",e.version,"semver"),kt(e),l(e,"description",e.description,"string"),l(e,"preview",e.preview,"file|url",{optional:!0}),Ct(e),Pt(e),Ot(e),Rt(e),Nt(e)];do t=await Promise.all(t.flat(1/0));while(t.some(n=>Array.isArray(n)));return t.every(n=>n)}"use strict";var je=["a6621988-551d-495a-97d8-3c568bca2e9e","0f0bf8b6-eae6-4273-b307-8fc43f2ee082","36a2ffc9-27ff-480e-84a7-c7700a7d232d"],qt=["linux","win32","darwin","extension"],Mt=["toggle","select","text","number","color","file","hotkey"],Ee=async()=>_.get(["currentprofile"],"default"),X=async()=>_.db(["profiles",await Ee()]),G,Q=[],Y=async(e=t=>!0)=>{G||(G=new Promise(async(n,r)=>{let s=[];for(let c of await u.getJSON("repo/registry.json"))try{let a={...await u.getJSON(`repo/${c}/mod.json`),_dir:c,_err:i=>Q.push({source:c,message:i})};await Ae(a)&&s.push(a)}catch{Q.push({source:c,message:"invalid mod.json"})}n(s)}));let t=[];for(let n of await G)await e(n)&&t.push(n);return t},Jt=async()=>(await Y(),Q),D=async e=>(await Y(t=>t.id===e))[0],zt=async e=>(await D(e)).environments.includes(E.name)?je.includes(e)?!0:(await X()).get(["_mods",e],!1):!1,Le=async(e,t)=>{let n=await D(e),r=n.options.find(s=>s.key===t);if(!!r)switch(r.type){case"toggle":case"text":case"number":case"color":case"hotkey":return r.value;case"select":return r.values[0];case"file":return}},Ut=async e=>{let t=await X();return _.db([e],async(n,r=void 0)=>(typeof n=="string"&&(n=[n]),n.length===2&&(r=await Le(e,n[1])??r),t.get(n,r)),t.set)};var o={};g(o,{addDocumentObserver:()=>Xt,addHotkeyListener:()=>It,copyToClipboard:()=>Ht,empty:()=>Wt,escape:()=>Te,html:()=>Ce,loadStylesheet:()=>Ft,queryParams:()=>Bt,raw:()=>ke,readFromClipboard:()=>Vt,removeDocumentObserver:()=>Gt,removeHotkeyListener:()=>Kt,render:()=>Pe,whenReady:()=>Zt});"use strict";var Se=!1,T=[],ee,J=[],te=[],Zt=(e=[])=>new Promise((t,n)=>{let r=()=>{let s=setInterval(c,100);function c(){!e.every(i=>document.querySelector(i))||(clearInterval(s),t(!0))}c()};document.readyState!=="complete"?document.addEventListener("readystatechange",s=>{document.readyState==="complete"&&r()}):r()}),Bt=()=>new URLSearchParams(window.location.search),Te=e=>e.replace(/&/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""").replace(/\\/g,"\"),ke=(e,...t)=>{let n=e.map(r=>r+(["string","number"].includes(typeof t[0])?t.shift():Te(JSON.stringify(t.shift(),null,2)??""))).join("");return n.includes("
r.trim()).filter(r=>r.length).join(" ")},Ce=(e,...t)=>{let n=document.createRange().createContextualFragment(ke(e,...t));return n.children.length===1?n.children[0]:n.children},Pe=(e,...t)=>(t=t.map(n=>n instanceof HTMLCollection?[...n]:n).flat(1/0).filter(n=>n),e.append(...t),e),Wt=e=>{for(;e.firstChild&&e.removeChild(e.firstChild););return e},Ft=e=>{let t=Ce`l(e,"tags.tag",i,"string"))},Ot=async e=>await l(e,"authors",e.authors,"array")?e.authors.map(n=>[l(e,"authors.author.name",n.name,"string"),l(e,"authors.author.email",n.email,"email",{optional:!0}),l(e,"authors.author.homepage",n.homepage,"url"),l(e,"authors.author.avatar",n.avatar,"url")]):!1,Nt=async e=>{if(!await l(e,"css",e.css,"object"))return!1;let n=[];for(let r of["frame","client","menu"]){if(!e.css[r])continue;let s=await l(e,`css.${r}`,e.css[r],"array");s&&(s=e.css[r].map(c=>l(e,`css.${r}.file`,c,"file",{extension:".css"}))),n.push(s)}return n},Rt=async e=>{if(!await l(e,"js",e.js,"object"))return!1;let n=[];for(let r of["frame","client","menu"]){if(!e.js[r])continue;let s=await l(e,`js.${r}`,e.js[r],"array");s&&(s=e.js[r].map(c=>l(e,`js.${r}.file`,c,"file",{extension:".mjs"}))),n.push(s)}if(e.js.electron)if(await l(e,"js.electron",e.js.electron,"array"))for(let s of e.js.electron){if(!await l(e,"js.electron.file",s,"object")){n.push(!1);continue}n.push([l(e,"js.electron.file.source",s.source,"file",{extension:".cjs"}),l(e,"js.electron.file.target",s.target,"string",{extension:".js"})])}else n.push(!1);return n},qt=async e=>{if(!await l(e,"options",e.options,"array"))return!1;let n=[];for(let r of e.options){let s="options.option";if(!await l(e,`${s}.type`,r.type,g.optionTypes)){n.push(!1);continue}switch(r.environments=r.environments??g.supportedEnvs,n.push([l(e,`${s}.key`,r.key,"alphanumeric"),l(e,`${s}.label`,r.label,"string"),l(e,`${s}.tooltip`,r.tooltip,"string",{optional:!0}),l(e,`${s}.environments`,r.environments,"array").then(a=>a?r.environments.map(i=>l(e,`${s}.environments.env`,i,g.supportedEnvs)):!1)]),r.type){case"toggle":n.push(l(e,`${s}.value`,r.value,"boolean"));break;case"select":{let a=await l(e,`${s}.values`,r.values,"array");a&&(a=r.values.map(i=>l(e,`${s}.values.value`,i,"string"))),n.push(a);break}case"text":case"hotkey":n.push(l(e,`${s}.value`,r.value,"string"));break;case"number":case"color":n.push(l(e,`${s}.value`,r.value,r.type));break;case"file":{let a=await l(e,`${s}.extensions`,r.extensions,"array");a&&(a=r.extensions.map(i=>l(e,`${s}.extensions.extension`,i,"string"))),n.push(a);break}}}return n};async function $e(e){let t=[l(e,"name",e.name,"string"),l(e,"id",e.id,"uuid"),l(e,"version",e.version,"semver"),Ct(e),l(e,"description",e.description,"string"),l(e,"preview",e.preview,"file|url",{optional:!0}),Pt(e),Ot(e),Nt(e),Rt(e),qt(e)];do t=await Promise.all(t.flat(1/0));while(t.some(n=>Array.isArray(n)));return t.every(n=>n)}"use strict";var Ae=["a6621988-551d-495a-97d8-3c568bca2e9e","0f0bf8b6-eae6-4273-b307-8fc43f2ee082","36a2ffc9-27ff-480e-84a7-c7700a7d232d"],Mt=["linux","win32","darwin","extension"],Jt=["toggle","select","text","number","color","file","hotkey"],Ee=async()=>_.get(["currentprofile"],"default"),X=async()=>_.db(["profiles",await Ee()]),G,Q=[],Y=async(e=t=>!0)=>{G||(G=new Promise(async(n,r)=>{let s=[];for(let c of await u.getJSON("repo/registry.json"))try{let a={...await u.getJSON(`repo/${c}/mod.json`),_dir:c,_err:i=>Q.push({source:c,message:i})};await $e(a)&&s.push(a)}catch{Q.push({source:c,message:"invalid mod.json"})}n(s)}));let t=[];for(let n of await G)await e(n)&&t.push(n);return t},zt=async()=>(await Y(),Q),D=async e=>(await Y(t=>t.id===e))[0],Ut=async e=>(await D(e)).environments.includes(j.name)?Ae.includes(e)?!0:(await X()).get(["_mods",e],!1):!1,je=async(e,t)=>{let n=await D(e),r=n.options.find(s=>s.key===t);if(!!r)switch(r.type){case"toggle":case"text":case"number":case"color":case"hotkey":return r.value;case"select":return r.values[0];case"file":return}},Wt=async e=>{let t=await X();return _.db([e],async(n,r=void 0)=>(typeof n=="string"&&(n=[n]),n.length===2&&(r=await je(e,n[1])??r),t.get(n,r)),t.set)};var o={};y(o,{addDocumentObserver:()=>Gt,addHotkeyListener:()=>Kt,copyToClipboard:()=>It,empty:()=>Ft,escape:()=>Le,html:()=>ke,loadStylesheet:()=>Ht,queryParams:()=>Bt,raw:()=>Se,readFromClipboard:()=>Vt,removeDocumentObserver:()=>Qt,removeHotkeyListener:()=>Xt,render:()=>Ce,whenReady:()=>Zt});"use strict";var Te=!1,S=[],ee,J=[],te=[],Zt=(e=[])=>new Promise((t,n)=>{let r=()=>{let s=setInterval(c,100);function c(){!e.every(i=>document.querySelector(i))||(clearInterval(s),t(!0))}c()};document.readyState!=="complete"?document.addEventListener("readystatechange",s=>{document.readyState==="complete"&&r()}):r()}),Bt=()=>new URLSearchParams(window.location.search),Le=e=>e.replace(/&/g,"&").replace(//g,">").replace(/'/g,"'").replace(/"/g,""").replace(/\\/g,"\"),Se=(e,...t)=>{let n=e.map(r=>r+(["string","number"].includes(typeof t[0])?t.shift():Le(JSON.stringify(t.shift(),null,2)??""))).join("");return n.includes("r.trim()).filter(r=>r.length).join(" ")},ke=(e,...t)=>{let n=document.createRange().createContextualFragment(Se(e,...t));return n.children.length===1?n.children[0]:n.children},Ce=(e,...t)=>(t=t.map(n=>n instanceof HTMLCollection?[...n]:n).flat(1/0).filter(n=>n),e.append(...t),e),Ft=e=>{for(;e.firstChild&&e.removeChild(e.firstChild););return e},Ht=e=>{let t=ke``;return Pe(document.head,t),t},Ht=async e=>{try{await navigator.clipboard.writeText(e)}catch{let t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}},Vt=()=>navigator.clipboard.readText(),Oe=(e,t)=>{if(document.activeElement.nodeName==="INPUT"&&!t.listenInInput)return;t.keys.every(s=>{s=s.toLowerCase();let c={metaKey:["meta","os","win","cmd","command"],ctrlKey:["ctrl","control"],shiftKey:["shift"],altKey:["alt"]};for(let a in c)if(c[a].includes(s)&&e[a])return!0;if(s==="space"&&(s=" "),s==="plus"&&(s="+"),s===e.key.toLowerCase())return!0})&&t.callback(e)},It=(e,t,{listenInInput:n=!1,keydown:r=!1}={})=>{typeof e=="string"&&(e=e.split("+")),T.push({keys:e,callback:t,listenInInput:n,keydown:r}),Se||(Se=!0,document.addEventListener("keyup",s=>{for(let c of T.filter(({keydown:a})=>!a))Oe(s,c)}),document.addEventListener("keydown",s=>{for(let c of T.filter(({keydown:a})=>a))Oe(s,c)}))},Kt=e=>{T=T.filter(t=>t.callback!==e)},Xt=(e,t=[])=>{if(!ee){let n=r=>{for(;r.length;){let s=r.shift(),c=(i,d)=>i instanceof Element&&(i.matches(d)||i.matches(`${d} *`)||i.querySelector(d)),a=i=>s.target.matches(i)||s.target.matches(`${i} *`)||[...s.addedNodes].some(d=>c(d,i));for(let i of J)(!i.selectors.length||i.selectors.some(a))&&i.callback(s)}};ee=new MutationObserver((r,s)=>{te.length||requestIdleCallback(()=>n(te)),te.push(...r)}),ee.observe(document.body,{childList:!0,subtree:!0,attributes:!0})}J.push({callback:e,selectors:t})},Gt=e=>{J=J.filter(t=>t.callback!==e)};var N={};g(N,{addCornerAction:()=>Xe,addPanelView:()=>Ie,addTooltip:()=>Ne,feather:()=>qe});"use strict";var Re,p,Qt=e=>[...e.getClientRects()].reduce((t,n)=>t.some(r=>r.y===n.y)?t:[...t,n],[]).length,Yt=async(e,t,n)=>{p.style.top="0px",p.style.left="0px";let r=e.getBoundingClientRect(),{offsetWidth:s,offsetHeight:c}=p,a=6,i=r.x,d=Math.floor(r.y);if(["top","bottom"].includes(t)){t==="top"&&(d-=c+a),t==="bottom"&&(d+=r.height+a),i-=s/2-r.width/2,p.style.left=`${i}px`,p.style.top=`${d}px`;let x=()=>Qt(p.firstElementChild)>n,A=x();for(;x();)p.style.left=`${window.innerWidth-i>i?i++:i--}px`;A&&(i+=window.innerWidth-i>i?a:-a,p.style.left=`${i}px`),p.style.textAlign="center"}return["left","right"].includes(t)&&(d-=c/2-r.height/2,t==="left"&&(i-=s+a),t==="right"&&(i+=r.width+a),p.style.left=`${i}px`,p.style.top=`${d}px`,p.style.textAlign="start"),!0},Ne=async(e,t,{delay:n=100,offsetDirection:r="bottom",maxLines:s=1}={})=>{Re||(Re=o.loadStylesheet("api/components/tooltip.css"),p=o.html``,o.render(document.body,p)),globalThis.markdownit||await import(u.localPath("dep/markdown-it.min.js"));let c=markdownit({linkify:!0});t instanceof Element||(t=o.html`+ />`;return Ce(document.head,t),t},It=async e=>{try{await navigator.clipboard.writeText(e)}catch{let t=document.createElement("textarea");t.value=e,t.setAttribute("readonly",""),t.style.position="absolute",t.style.left="-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}},Vt=()=>navigator.clipboard.readText(),Pe=(e,t)=>{if(document.activeElement.nodeName==="INPUT"&&!t.listenInInput)return;let r={metaKey:["meta","os","win","cmd","command"],ctrlKey:["ctrl","control"],shiftKey:["shift"],altKey:["alt"]};if(!!t.keys.every(c=>{c=c.toLowerCase();for(let a in r)if(r[a].includes(c)&&e[a])return r[a]=[],!0;if(c==="space"&&(c=" "),c==="plus"&&(c="+"),c===e.key.toLowerCase())return!0})){for(let c in r){let a=e[c],i=r[c].length>0;if(a&&i)return}t.callback(e)}},Kt=(e,t,{listenInInput:n=!1,keydown:r=!1}={})=>{typeof e=="string"&&(e=e.split("+")),S.push({keys:e,callback:t,listenInInput:n,keydown:r}),Te||(Te=!0,document.addEventListener("keyup",s=>{for(let c of S.filter(({keydown:a})=>!a))Pe(s,c)}),document.addEventListener("keydown",s=>{for(let c of S.filter(({keydown:a})=>a))Pe(s,c)}))},Xt=e=>{S=S.filter(t=>t.callback!==e)},Gt=(e,t=[])=>{if(!ee){let n=r=>{for(;r.length;){let s=r.shift(),c=(i,d)=>i instanceof Element&&(i.matches(d)||i.matches(`${d} *`)||i.querySelector(d)),a=i=>s.target.matches(i)||s.target.matches(`${i} *`)||[...s.addedNodes].some(d=>c(d,i));for(let i of J)(!i.selectors.length||i.selectors.some(a))&&i.callback(s)}};ee=new MutationObserver((r,s)=>{te.length||requestIdleCallback(()=>n(te)),te.push(...r)}),ee.observe(document.body,{childList:!0,subtree:!0,attributes:!0})}J.push({callback:e,selectors:t})},Qt=e=>{J=J.filter(t=>t.callback!==e)};var R={};y(R,{addCornerAction:()=>Ke,addPanelView:()=>Ie,addTooltip:()=>Ne,feather:()=>Re});"use strict";var Oe,p,Yt=e=>[...e.getClientRects()].reduce((t,n)=>t.some(r=>r.y===n.y)?t:[...t,n],[]).length,Dt=async(e,t,n)=>{p.style.top="0px",p.style.left="0px";let r=e.getBoundingClientRect(),{offsetWidth:s,offsetHeight:c}=p,a=6,i=r.x,d=Math.floor(r.y);if(["top","bottom"].includes(t)){t==="top"&&(d-=c+a),t==="bottom"&&(d+=r.height+a),i-=s/2-r.width/2,p.style.left=`${i}px`,p.style.top=`${d}px`;let x=()=>Yt(p.firstElementChild)>n,A=x();for(;x();)p.style.left=`${window.innerWidth-i>i?i++:i--}px`;A&&(i+=window.innerWidth-i>i?a:-a,p.style.left=`${i}px`),p.style.textAlign="center"}return["left","right"].includes(t)&&(d-=c/2-r.height/2,t==="left"&&(i-=s+a),t==="right"&&(i+=r.width+a),p.style.left=`${i}px`,p.style.top=`${d}px`,p.style.textAlign="start"),!0},Ne=async(e,t,{delay:n=100,offsetDirection:r="bottom",maxLines:s=1}={})=>{Oe||(Oe=o.loadStylesheet("api/components/tooltip.css"),p=o.html``,o.render(document.body,p)),globalThis.markdownit||await import(u.localPath("dep/markdown-it.min.js"));let c=markdownit({linkify:!0});t instanceof Element||(t=o.html``);let a;e.addEventListener("mouseover",async i=>{a||(a=setTimeout(async()=>{e.matches(":hover")&&p.style.display!=="block"&&(p.style.display="block",o.render(o.empty(p),t),Dt(e,r,s),await p.animate([{opacity:0},{opacity:1}],{duration:65}).finished),a=void 0},n))}),e.addEventListener("mouseout",async i=>{a=void 0,p.style.display==="block"&&!e.matches(":hover")&&(await p.animate([{opacity:1},{opacity:0}],{duration:65}).finished,p.style.display="")})};"use strict";var ne,Re=async(e,t={})=>(ne||(ne=o.html`${await u.getText("dep/feather-sprite.svg")}`),t.style=((t.style?t.style+";":"")+"stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;fill:none;").trim(),t.viewBox="0 0 24 24",``);"use strict";var k=[],en=o.raw``,Me,w,z,v,$,C,j,Je,ze,re,f,Ue,U,P,Z,se,b,oe,O,B="data-enhancer-panel-pinned",W=()=>$.hasAttribute(B),R=()=>{let e=[z,v,C,$].filter(t=>t);if(W()){ie();for(let t of e)t.removeAttribute(B)}else for(let t of e)t.setAttribute(B,"true");w.set(["panel.pinned"],W())},Ze=async()=>{document.documentElement.style.setProperty("--component--panel-width",f+"px"),w.set(["panel.width"],f)},Be=e=>{e.preventDefault(),re=!0,f=ze+(Je-e.clientX),f<190&&(f=190),f>480&&(f=480),$.style.width=f+"px",C.style.width=f+"px",z.style.paddingRight=f+"px",v&&(v.style.right=f+"px")},We=e=>{$.style.width="",C.style.width="",z.style.paddingRight="",v&&(v.style.right=""),Ze(),j.style.cursor="",document.body.removeEventListener("mousemove",Be),document.body.removeEventListener("mouseup",We)},en=e=>{Je=e.clientX,ze=f,j.style.cursor="auto",document.body.addEventListener("mousemove",Be),document.body.addEventListener("mouseup",We)},tn=()=>document.body.contains(b),Fe=()=>{if(!W())return R();o.render(Ue,O),o.empty(b);for(let t of k){let n=P.contains(t.$title),r=o.render(o.html``,o.render(o.html``,t.$icon.cloneNode(!0),t.$title.cloneNode(!0)));r.addEventListener("click",()=>{Ve(t),w.set(["panel.open"],t.id)}),o.render(b,r)}let e=Z.getBoundingClientRect();o.render(o.empty(O),o.render(o.html``,o.render(o.html``,b))),b.querySelector("[data-open]").focus(),b.animate([{opacity:0},{opacity:1}],{duration:200}),document.addEventListener("keydown",He)},ie=()=>{document.removeEventListener("keydown",He),b.animate([{opacity:1},{opacity:0}],{duration:200}).onfinish=()=>O.remove()},He=e=>{if(tn())switch(e.key){case"Escape":ie(),e.stopPropagation();break;case"Enter":document.activeElement.click(),e.stopPropagation();break;case"ArrowUp":(e.target.previousElementSibling||e.target.parentElement.lastElementChild).focus(),e.stopPropagation();break;case"ArrowDown":(e.target.nextElementSibling||e.target.parentElement.firstElementChild).focus(),e.stopPropagation();break}},Ve=e=>{let t=k.find(({$content:n})=>document.contains(n));o.render(o.empty(P),o.render(o.html``,e.$icon,e.$title)),e.onFocus(),o.render(o.empty(se),e.$content),t&&t.onBlur()};async function nn(){await o.whenReady([".notion-frame"]),z=document.querySelector(".notion-frame"),$=o.html``,C=o.html``,j=o.html`${t.split(` `).map(i=>c.renderInline(i)).join("`);let a;e.addEventListener("mouseover",async i=>{a||(a=setTimeout(async()=>{e.matches(":hover")&&p.style.display!=="block"&&(p.style.display="block",o.render(o.empty(p),t),Yt(e,r,s),await p.animate([{opacity:0},{opacity:1}],{duration:65}).finished),a=void 0},n))}),e.addEventListener("mouseout",async i=>{a=void 0,p.style.display==="block"&&!e.matches(":hover")&&(await p.animate([{opacity:1},{opacity:0}],{duration:65}).finished,p.style.display="")})};"use strict";var ne,qe=async(e,t={})=>(ne||(ne=o.html`${await u.getText("dep/feather-sprite.svg")}`),t.style=((t.style?t.style+";":"")+"stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;fill:none;").trim(),t.viewBox="0 0 24 24",``);"use strict";var k=[],Dt=o.raw`
")} -`,P=o.html``,Z=o.render(o.html``,P),se=o.html``,b=o.html``,oe=o.html`- ${Dt} -`,O=o.html``;let e='.notion-cursor-listener > div[style*="flex-end"]',t=()=>{document.contains(v)||(v=document.querySelector(e),W()&&v&&v.setAttribute(B,"true"))};v=document.querySelector(e),o.addDocumentObserver(t,[e]),await w.get(["panel.pinned"])&&R(),o.addHotkeyListener(await w.get(["panel.hotkey"]),R),U.addEventListener("click",r=>{r.stopPropagation(),R()}),o.render($,o.render(Z,P,oe,U),se,j),await rn(),await sn();let n='.notion-cursor-listener > .notion-sidebar-container ~ [style^="position: absolute"]';await o.whenReady([n]),document.querySelector(n).before(C,$)}async function rn(){f=await w.get(["panel.width"],240),Ze(),j.addEventListener("mousedown",en),j.addEventListener("click",()=>{re?re=!1:R()})}async function sn(){Ue=document.querySelector(".notion-app-inner"),Z.addEventListener("click",Fe),oe.addEventListener("click",Fe),O.addEventListener("click",ie)}var Ie=async({id:e,icon:t,title:n,$content:r,onFocus:s=()=>{},onBlur:c=()=>{}})=>{Me||(Me=o.loadStylesheet("api/components/panel.css")),w||(w=await y.db("36a2ffc9-27ff-480e-84a7-c7700a7d232d")),U||(U=o.html``);let a={id:e,$icon:o.render(o.html``,t instanceof Element?t:o.html`${t}`),$title:o.render(o.html``,n),$content:r,onFocus:s,onBlur:c};k.push(a),k.length===1&&await nn(),(k.length===1||await w.get(["panel.open"])===e)&&Ve(a)};"use strict";var Ke,q,Xe=async(e,t)=>{Ke||(Ke=o.loadStylesheet("api/components/corner-action.css"),q=o.html``),await o.whenReady([".notion-help-button"]);let n=document.querySelector(".notion-help-button"),r=document.querySelector(".onboarding-checklist-button");r&&q.prepend(r),q.prepend(n),o.render(document.querySelector(".notion-app-inner > .notion-cursor-listener"),q);let s=o.html` `;return s.addEventListener("click",t),o.render(q,s),s};"use strict";"use strict"; + `,qe,w,z,v,$,C,E,Me,Je,re,f,ze,U,P,W,se,b,oe,O,Z="data-enhancer-panel-pinned",B=()=>$.hasAttribute(Z),N=()=>{let e=[z,v,C,$].filter(t=>t);if(B()){ie();for(let t of e)t.removeAttribute(Z)}else for(let t of e)t.setAttribute(Z,"true");w.set(["panel.pinned"],B())},Ue=async()=>{document.documentElement.style.setProperty("--component--panel-width",f+"px"),w.set(["panel.width"],f)},We=e=>{e.preventDefault(),re=!0,f=Je+(Me-e.clientX),f<190&&(f=190),f>480&&(f=480),$.style.width=f+"px",C.style.width=f+"px",z.style.paddingRight=f+"px",v&&(v.style.right=f+"px")},Ze=e=>{$.style.width="",C.style.width="",z.style.paddingRight="",v&&(v.style.right=""),Ue(),E.style.cursor="",document.body.removeEventListener("mousemove",We),document.body.removeEventListener("mouseup",Ze)},tn=e=>{Me=e.clientX,Je=f,E.style.cursor="auto",document.body.addEventListener("mousemove",We),document.body.addEventListener("mouseup",Ze)},nn=()=>document.body.contains(b),Be=()=>{if(!B())return N();o.render(ze,O),o.empty(b);for(let t of k){let n=P.contains(t.$title),r=o.render(o.html``,o.render(o.html``,t.$icon.cloneNode(!0),t.$title.cloneNode(!0)));r.addEventListener("click",()=>{He(t),w.set(["panel.open"],t.id)}),o.render(b,r)}let e=W.getBoundingClientRect();o.render(o.empty(O),o.render(o.html``,o.render(o.html``,b))),b.querySelector("[data-open]").focus(),b.animate([{opacity:0},{opacity:1}],{duration:200}),document.addEventListener("keydown",Fe)},ie=()=>{document.removeEventListener("keydown",Fe),b.animate([{opacity:1},{opacity:0}],{duration:200}).onfinish=()=>O.remove()},Fe=e=>{if(nn())switch(e.key){case"Escape":ie(),e.stopPropagation();break;case"Enter":document.activeElement.click(),e.stopPropagation();break;case"ArrowUp":(e.target.previousElementSibling||e.target.parentElement.lastElementChild).focus(),e.stopPropagation();break;case"ArrowDown":(e.target.nextElementSibling||e.target.parentElement.firstElementChild).focus(),e.stopPropagation();break}},He=e=>{let t=k.find(({$content:n})=>document.contains(n));o.render(o.empty(P),o.render(o.html``,e.$icon,e.$title)),e.onFocus(),o.render(o.empty(se),e.$content),t&&t.onBlur()};async function rn(){await o.whenReady([".notion-frame"]),z=document.querySelector(".notion-frame"),$=o.html``,C=o.html``,E=o.html`- ${await N.feather("chevrons-right")} -`,P=o.html``,W=o.render(o.html``,P),se=o.html``,b=o.html``,oe=o.html`+ ${en} +`,O=o.html``;let e='.notion-cursor-listener > div[style*="flex-end"]',t=()=>{document.contains(v)||(v=document.querySelector(e),B()&&v&&v.setAttribute(Z,"true"))};v=document.querySelector(e),o.addDocumentObserver(t,[e]),await w.get(["panel.pinned"])&&N(),o.addHotkeyListener(await w.get(["panel.hotkey"]),N),U.addEventListener("click",r=>{r.stopPropagation(),N()}),o.render($,o.render(W,P,oe,U),se,E),await sn(),await on();let n='.notion-cursor-listener > .notion-sidebar-container ~ [style^="position: absolute"]';await o.whenReady([n]),document.querySelector(n).before(C,$)}async function sn(){f=await w.get(["panel.width"],240),Ue(),E.addEventListener("mousedown",tn),E.addEventListener("click",()=>{re?re=!1:N()})}async function on(){ze=document.querySelector(".notion-app-inner"),W.addEventListener("click",Be),oe.addEventListener("click",Be),O.addEventListener("click",ie)}var Ie=async({id:e,icon:t,title:n,$content:r,onFocus:s=()=>{},onBlur:c=()=>{}})=>{qe||(qe=o.loadStylesheet("api/components/panel.css")),w||(w=await g.db("36a2ffc9-27ff-480e-84a7-c7700a7d232d")),U||(U=o.html``);let a={id:e,$icon:o.render(o.html``,t instanceof Element?t:o.html`${t}`),$title:o.render(o.html``,n),$content:r,onFocus:s,onBlur:c};k.push(a),k.length===1&&await rn(),(k.length===1||await w.get(["panel.open"])===e)&&He(a)};"use strict";var Ve,q,Ke=async(e,t)=>{Ve||(Ve=o.loadStylesheet("api/components/corner-action.css"),q=o.html``),await o.whenReady([".notion-help-button"]);let n=document.querySelector(".notion-help-button"),r=document.querySelector(".onboarding-checklist-button");r&&q.prepend(r),q.prepend(n),o.render(document.querySelector(".notion-app-inner > .notion-cursor-listener"),q);let s=o.html` `;return s.addEventListener("click",t),o.render(q,s),s};"use strict";"use strict"; diff --git a/api/web.mjs b/api/web.mjs index 42a0f25..b247f3c 100644 --- a/api/web.mjs +++ b/api/web.mjs @@ -169,23 +169,35 @@ export const readFromClipboard = () => { const triggerHotkeyListener = (event, hotkey) => { const inInput = document.activeElement.nodeName === 'INPUT' && !hotkey.listenInInput; if (inInput) return; - const pressed = hotkey.keys.every((key) => { - key = key.toLowerCase(); - const modifiers = { + const modifiers = { metaKey: ['meta', 'os', 'win', 'cmd', 'command'], ctrlKey: ['ctrl', 'control'], shiftKey: ['shift'], altKey: ['alt'], - }; - for (const modifier in modifiers) { - const pressed = modifiers[modifier].includes(key) && event[modifier]; - if (pressed) return true; - } - if (key === 'space') key = ' '; - if (key === 'plus') key = '+'; - if (key === event.key.toLowerCase()) return true; - }); - if (pressed) hotkey.callback(event); + }, + pressed = hotkey.keys.every((key) => { + key = key.toLowerCase(); + for (const modifier in modifiers) { + const pressed = modifiers[modifier].includes(key) && event[modifier]; + if (pressed) { + // mark modifier as part of hotkey + modifiers[modifier] = []; + return true; + } + } + if (key === 'space') key = ' '; + if (key === 'plus') key = '+'; + if (key === event.key.toLowerCase()) return true; + }); + if (!pressed) return; + // test for modifiers not in hotkey + // e.g. to differentiate ctrl+x from ctrl+shift+x + for (const modifier in modifiers) { + const modifierPressed = event[modifier], + modifierNotInHotkey = modifiers[modifier].length > 0; + if (modifierPressed && modifierNotInHotkey) return; + } + hotkey.callback(event); }; /**+ ${await R.feather("chevrons-right")} +