@note3/utils 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/chunk-44UQ54GR.min.js +2 -0
  2. package/dist/chunk-44UQ54GR.min.js.map +1 -0
  3. package/dist/chunk-KHOUPFOL.min.js +1 -0
  4. package/dist/chunk-KY36PVHK.min.js +2 -0
  5. package/dist/chunk-KY36PVHK.min.js.map +1 -0
  6. package/dist/chunk-LDNVHZO7.min.js +2 -0
  7. package/dist/chunk-LDNVHZO7.min.js.map +1 -0
  8. package/dist/chunk-POX3PUJK.min.js +2 -0
  9. package/dist/chunk-POX3PUJK.min.js.map +1 -0
  10. package/dist/index.d.ts +5 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.min.js +1 -1
  13. package/dist/note3-regex-constants.d.ts +21 -0
  14. package/dist/note3-regex-constants.d.ts.map +1 -0
  15. package/dist/note3-regex-constants.min.js +2 -0
  16. package/dist/note3-regex-constants.min.js.map +1 -0
  17. package/dist/note3-utils-nodeps.d.ts +22 -0
  18. package/dist/note3-utils-nodeps.d.ts.map +1 -0
  19. package/dist/note3-utils-nodeps.min.js +2 -0
  20. package/dist/note3-utils-nodeps.min.js.map +1 -0
  21. package/dist/queries.d.ts +53 -0
  22. package/dist/queries.d.ts.map +1 -0
  23. package/dist/queries.min.js +2 -0
  24. package/dist/queries.min.js.map +1 -0
  25. package/dist/relation-ordering.d.ts +13 -0
  26. package/dist/relation-ordering.d.ts.map +1 -0
  27. package/dist/relation-ordering.min.js +2 -0
  28. package/dist/relation-ordering.min.js.map +1 -0
  29. package/dist/types.d.ts +20 -0
  30. package/dist/types.d.ts.map +1 -0
  31. package/dist/types.min.js +2 -0
  32. package/dist/types.min.js.map +1 -0
  33. package/package.json +2 -1
  34. package/dist/chunk-Z5VZCNIS.min.js +0 -11
  35. package/dist/chunk-Z5VZCNIS.min.js.map +0 -1
  36. package/dist/worker.d.ts +0 -6
  37. package/dist/worker.d.ts.map +0 -1
  38. package/dist/worker.min.js +0 -2
  39. /package/dist/{worker.min.js.map → chunk-KHOUPFOL.min.js.map} +0 -0
@@ -0,0 +1,2 @@
1
+ import{b as r,c as s}from"./chunk-LDNVHZO7.min.js";import{a as f}from"./chunk-KY36PVHK.min.js";function I(o,e){return!(e.en&&o.en!==e.en||e.at&&o.at!==e.at||e.vl!==void 0&&o.vl!==e.vl)}function y(o,e){return o.applogs.filter(t=>I(t,{at:"relation/childOf",vl:e})).map(t=>t.en)}function g(o,e){let n=new Set,t=new Set;for(let l of o.applogs)l.at==="relation/block"&&l.vl===e&&n.add(l.en);for(let l of n)for(let i of o.applogs)i.en===l&&i.at==="relation/childOf"&&i.vl!==null&&t.add(i.vl);return Array.from(t)}function c(o,e){let n={id:e};for(let t of o.applogs)if(t.en===e)switch(t.at){case"relation/block":n.block=t.vl;break;case"relation/childOf":n.childOf=t.vl;break;case"relation/after":n.after=t.vl;break;case"relation/isExpanded":n.isExpanded=t.vl;break;case"relation/isMirror":n.isMirror=t.vl;break;case"relation/isReply":n.isReply=t.vl;break;case"isDeleted":n.isDeleted=t.vl;break}return!n.block||n.childOf===void 0?null:n}function E(o,e){let t=o.applogs.filter(l=>l.at==="relation/childOf"&&l.vl===e).map(l=>l.en).map(l=>c(o,l)).filter(l=>l!==null);return f(t)}function b(o,e){return o.applogs.filter(t=>t.at==="relation/block"&&t.vl===e).map(t=>t.en).map(t=>c(o,t)).filter(t=>t!==null)}function u(o,e){let n=o.applogs.find(t=>t.en===e&&t.at==="block/content");return n?r(n.vl):null}function k(o,e){let n=u(o,e);return n?s(n):null}function v(o){let e=new Set;for(let i of o.applogs)i.at==="block/content"&&e.add(i.en);let n=new Set,t=new Map;for(let i of o.applogs)i.at==="relation/block"&&t.set(i.vl,i.en);for(let[i,p]of t)for(let a of o.applogs)if(a.en===p&&a.at==="relation/childOf"){a.vl!==null&&n.add(i);break}return Array.from(e).filter(i=>!n.has(i)).sort()}export{y as a,g as b,E as c,b as d,u as e,k as f,v as g};
2
+ //# sourceMappingURL=chunk-44UQ54GR.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/queries.ts"],"sourcesContent":["import type { Applog, EntityID } from '@wovin/core/applog'\nimport type { Thread } from '@wovin/core/thread'\nimport type { RelationInfo } from './types'\nimport { parseBlockContentValue, tiptapToPlaintext, type TiptapContent } from './note3-utils-nodeps'\nimport { orderRelations } from './relation-ordering'\n\n/**\n * Helper to match applog against a pattern\n */\nfunction matchesPattern(applog: Applog, pattern: { en?: EntityID; at?: string; vl?: any }): boolean {\n\tif (pattern.en && applog.en !== pattern.en) return false\n\tif (pattern.at && applog.at !== pattern.at) return false\n\tif (pattern.vl !== undefined && applog.vl !== pattern.vl) return false\n\treturn true\n}\n\n/**\n * Get all child block IDs for a given parent block\n * @param thread - The thread to query\n * @param parentId - The parent block's entity ID\n * @returns Array of child block IDs (unordered - use getChildRelations for ordered)\n */\nexport function getChildIDs(thread: Thread, parentId: EntityID): EntityID[] {\n\tconst applogs = thread.applogs.filter(log =>\n\t\tmatchesPattern(log, { at: 'relation/childOf', vl: parentId })\n\t)\n\treturn applogs.map(log => log.en)\n}\n\n/**\n * Get all parent block IDs for a given block\n * @param thread - The thread to query\n * @param blockId - The block's entity ID\n * @returns Array of parent block IDs (usually just one, but can be multiple)\n */\nexport function getParentIDs(thread: Thread, blockId: EntityID): EntityID[] {\n\t// Find all relations where this block is the child\n\tconst relationIDs = new Set<EntityID>()\n\tconst parentIDs = new Set<EntityID>()\n\n\tfor (const log of thread.applogs) {\n\t\t// Find relations that reference this block\n\t\tif (log.at === 'relation/block' && log.vl === blockId) {\n\t\t\trelationIDs.add(log.en)\n\t\t}\n\t}\n\n\t// For each relation, find its parent\n\tfor (const relID of relationIDs) {\n\t\tfor (const log of thread.applogs) {\n\t\t\tif (log.en === relID && log.at === 'relation/childOf' && log.vl !== null) {\n\t\t\t\tparentIDs.add(log.vl as EntityID)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn Array.from(parentIDs)\n}\n\n/**\n * Build RelationInfo object from applogs for a specific relation entity\n */\nfunction buildRelationInfo(thread: Thread, relationID: EntityID): RelationInfo | null {\n\tconst attrs: Partial<RelationInfo> = { id: relationID }\n\n\tfor (const log of thread.applogs) {\n\t\tif (log.en !== relationID) continue\n\n\t\tswitch (log.at) {\n\t\t\tcase 'relation/block':\n\t\t\t\tattrs.block = log.vl as EntityID\n\t\t\t\tbreak\n\t\t\tcase 'relation/childOf':\n\t\t\t\tattrs.childOf = log.vl as EntityID\n\t\t\t\tbreak\n\t\t\tcase 'relation/after':\n\t\t\t\tattrs.after = log.vl as EntityID | null\n\t\t\t\tbreak\n\t\t\tcase 'relation/isExpanded':\n\t\t\t\tattrs.isExpanded = log.vl as boolean\n\t\t\t\tbreak\n\t\t\tcase 'relation/isMirror':\n\t\t\t\tattrs.isMirror = log.vl as boolean\n\t\t\t\tbreak\n\t\t\tcase 'relation/isReply':\n\t\t\t\tattrs.isReply = log.vl as boolean\n\t\t\t\tbreak\n\t\t\tcase 'isDeleted':\n\t\t\t\tattrs.isDeleted = log.vl as boolean\n\t\t\t\tbreak\n\t\t}\n\t}\n\n\t// Validate required fields\n\tif (!attrs.block || attrs.childOf === undefined) {\n\t\treturn null\n\t}\n\n\treturn attrs as RelationInfo\n}\n\n/**\n * Get ordered child relations for a given parent block\n * @param thread - The thread to query\n * @param parentId - The parent block's entity ID\n * @returns Ordered array of RelationInfo objects\n */\nexport function getChildRelations(thread: Thread, parentId: EntityID): RelationInfo[] {\n\t// Find all relation IDs for this parent\n\tconst relationIDs = thread.applogs\n\t\t.filter(log => log.at === 'relation/childOf' && log.vl === parentId)\n\t\t.map(log => log.en)\n\n\t// Build RelationInfo objects\n\tconst relations = relationIDs\n\t\t.map(relID => buildRelationInfo(thread, relID))\n\t\t.filter((rel): rel is RelationInfo => rel !== null)\n\n\t// Order them\n\treturn orderRelations(relations)\n}\n\n/**\n * Get parent relations (placements) for a given block\n * @param thread - The thread to query\n * @param blockId - The block's entity ID\n * @returns Array of RelationInfo objects (unordered)\n */\nexport function getParentRelations(thread: Thread, blockId: EntityID): RelationInfo[] {\n\t// Find all relation IDs where this block is referenced\n\tconst relationIDs = thread.applogs\n\t\t.filter(log => log.at === 'relation/block' && log.vl === blockId)\n\t\t.map(log => log.en)\n\n\t// Build RelationInfo objects\n\treturn relationIDs\n\t\t.map(relID => buildRelationInfo(thread, relID))\n\t\t.filter((rel): rel is RelationInfo => rel !== null)\n}\n\n/**\n * Get the content of a block as TiptapContent\n * @param thread - The thread to query\n * @param blockId - The block's entity ID\n * @returns TiptapContent object or null if not found\n */\nexport function getContent(thread: Thread, blockId: EntityID): TiptapContent | null {\n\tconst contentLog = thread.applogs.find(log =>\n\t\tlog.en === blockId && log.at === 'block/content'\n\t)\n\n\tif (!contentLog) return null\n\n\treturn parseBlockContentValue(contentLog.vl as string)\n}\n\n/**\n * Get the plain text content of a block\n * @param thread - The thread to query\n * @param blockId - The block's entity ID\n * @returns Plain text string or null if not found\n */\nexport function getContentText(thread: Thread, blockId: EntityID): string | null {\n\tconst content = getContent(thread, blockId)\n\tif (!content) return null\n\treturn tiptapToPlaintext(content)\n}\n\n/**\n * Get all root block IDs (blocks without parents)\n * @param thread - The thread to query\n * @returns Array of root block IDs, sorted by entity ID\n */\nexport function getRootIDs(thread: Thread): EntityID[] {\n\t// Find all blocks (entities with block/content attribute)\n\tconst allBlockIDs = new Set<EntityID>()\n\tfor (const log of thread.applogs) {\n\t\tif (log.at === 'block/content') {\n\t\t\tallBlockIDs.add(log.en)\n\t\t}\n\t}\n\n\t// Find all blocks that have parent relations\n\tconst blocksWithParents = new Set<EntityID>()\n\tconst relationsByBlock = new Map<EntityID, EntityID>() // block -> relation\n\n\tfor (const log of thread.applogs) {\n\t\tif (log.at === 'relation/block') {\n\t\t\trelationsByBlock.set(log.vl as EntityID, log.en)\n\t\t}\n\t}\n\n\t// Check which relations have non-null parents\n\tfor (const [blockID, relationID] of relationsByBlock) {\n\t\tfor (const log of thread.applogs) {\n\t\t\tif (log.en === relationID && log.at === 'relation/childOf') {\n\t\t\t\tif (log.vl !== null) {\n\t\t\t\t\tblocksWithParents.add(blockID)\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n\n\t// Root blocks = all blocks - blocks with parents\n\tconst rootBlocks = Array.from(allBlockIDs).filter(id => !blocksWithParents.has(id))\n\n\t// Sort by entity ID for determinism\n\treturn rootBlocks.sort()\n}\n"],"mappings":"+FASA,SAASA,EAAeC,EAAgBC,EAA4D,CAGnG,MAFI,EAAAA,EAAQ,IAAMD,EAAO,KAAOC,EAAQ,IACpCA,EAAQ,IAAMD,EAAO,KAAOC,EAAQ,IACpCA,EAAQ,KAAO,QAAaD,EAAO,KAAOC,EAAQ,GAEvD,CAQO,SAASC,EAAYC,EAAgBC,EAAgC,CAI3E,OAHgBD,EAAO,QAAQ,OAAOE,GACrCN,EAAeM,EAAK,CAAE,GAAI,mBAAoB,GAAID,CAAS,CAAC,CAC7D,EACe,IAAIC,GAAOA,EAAI,EAAE,CACjC,CAQO,SAASC,EAAaH,EAAgBI,EAA+B,CAE3E,IAAMC,EAAc,IAAI,IAClBC,EAAY,IAAI,IAEtB,QAAWJ,KAAOF,EAAO,QAEpBE,EAAI,KAAO,kBAAoBA,EAAI,KAAOE,GAC7CC,EAAY,IAAIH,EAAI,EAAE,EAKxB,QAAWK,KAASF,EACnB,QAAWH,KAAOF,EAAO,QACpBE,EAAI,KAAOK,GAASL,EAAI,KAAO,oBAAsBA,EAAI,KAAO,MACnEI,EAAU,IAAIJ,EAAI,EAAc,EAKnC,OAAO,MAAM,KAAKI,CAAS,CAC5B,CAKA,SAASE,EAAkBR,EAAgBS,EAA2C,CACrF,IAAMC,EAA+B,CAAE,GAAID,CAAW,EAEtD,QAAWP,KAAOF,EAAO,QACxB,GAAIE,EAAI,KAAOO,EAEf,OAAQP,EAAI,GAAI,CACf,IAAK,iBACJQ,EAAM,MAAQR,EAAI,GAClB,MACD,IAAK,mBACJQ,EAAM,QAAUR,EAAI,GACpB,MACD,IAAK,iBACJQ,EAAM,MAAQR,EAAI,GAClB,MACD,IAAK,sBACJQ,EAAM,WAAaR,EAAI,GACvB,MACD,IAAK,oBACJQ,EAAM,SAAWR,EAAI,GACrB,MACD,IAAK,mBACJQ,EAAM,QAAUR,EAAI,GACpB,MACD,IAAK,YACJQ,EAAM,UAAYR,EAAI,GACtB,KACF,CAID,MAAI,CAACQ,EAAM,OAASA,EAAM,UAAY,OAC9B,KAGDA,CACR,CAQO,SAASC,EAAkBX,EAAgBC,EAAoC,CAOrF,IAAMW,EALcZ,EAAO,QACzB,OAAOE,GAAOA,EAAI,KAAO,oBAAsBA,EAAI,KAAOD,CAAQ,EAClE,IAAIC,GAAOA,EAAI,EAAE,EAIjB,IAAIK,GAASC,EAAkBR,EAAQO,CAAK,CAAC,EAC7C,OAAQM,GAA6BA,IAAQ,IAAI,EAGnD,OAAOC,EAAeF,CAAS,CAChC,CAQO,SAASG,EAAmBf,EAAgBI,EAAmC,CAOrF,OALoBJ,EAAO,QACzB,OAAOE,GAAOA,EAAI,KAAO,kBAAoBA,EAAI,KAAOE,CAAO,EAC/D,IAAIF,GAAOA,EAAI,EAAE,EAIjB,IAAIK,GAASC,EAAkBR,EAAQO,CAAK,CAAC,EAC7C,OAAQM,GAA6BA,IAAQ,IAAI,CACpD,CAQO,SAASG,EAAWhB,EAAgBI,EAAyC,CACnF,IAAMa,EAAajB,EAAO,QAAQ,KAAKE,GACtCA,EAAI,KAAOE,GAAWF,EAAI,KAAO,eAClC,EAEA,OAAKe,EAEEC,EAAuBD,EAAW,EAAY,EAF7B,IAGzB,CAQO,SAASE,EAAenB,EAAgBI,EAAkC,CAChF,IAAMgB,EAAUJ,EAAWhB,EAAQI,CAAO,EAC1C,OAAKgB,EACEC,EAAkBD,CAAO,EADX,IAEtB,CAOO,SAASE,EAAWtB,EAA4B,CAEtD,IAAMuB,EAAc,IAAI,IACxB,QAAWrB,KAAOF,EAAO,QACpBE,EAAI,KAAO,iBACdqB,EAAY,IAAIrB,EAAI,EAAE,EAKxB,IAAMsB,EAAoB,IAAI,IACxBC,EAAmB,IAAI,IAE7B,QAAWvB,KAAOF,EAAO,QACpBE,EAAI,KAAO,kBACduB,EAAiB,IAAIvB,EAAI,GAAgBA,EAAI,EAAE,EAKjD,OAAW,CAACwB,EAASjB,CAAU,IAAKgB,EACnC,QAAWvB,KAAOF,EAAO,QACxB,GAAIE,EAAI,KAAOO,GAAcP,EAAI,KAAO,mBAAoB,CACvDA,EAAI,KAAO,MACdsB,EAAkB,IAAIE,CAAO,EAE9B,KACD,CAQF,OAHmB,MAAM,KAAKH,CAAW,EAAE,OAAOI,GAAM,CAACH,EAAkB,IAAIG,CAAE,CAAC,EAGhE,KAAK,CACxB","names":["matchesPattern","applog","pattern","getChildIDs","thread","parentId","log","getParentIDs","blockId","relationIDs","parentIDs","relID","buildRelationInfo","relationID","attrs","getChildRelations","relations","rel","orderRelations","getParentRelations","getContent","contentLog","parseBlockContentValue","getContentText","content","tiptapToPlaintext","getRootIDs","allBlockIDs","blocksWithParents","relationsByBlock","blockID","id"]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-KHOUPFOL.min.js.map
@@ -0,0 +1,2 @@
1
+ function u(s){if(!s?.length)return[];let o=s.filter(e=>!e.isDeleted).slice();o.sort((e,n)=>e.id<n.id?-1:1);let r=new Set(o.map(e=>e.childOf));if(r.size!==1)throw new Error(`[orderRelations] All relations must have the same parent. Found ${r.size} different parents: ${Array.from(r).join(", ")}`);let t=[],d=new Map,f=new Map;for(let e of o)d.set(e.id,e),f.set(e.block,e);function l(e,n=[]){if(n.includes(e.id)){let i=[...n,e.id].join(" \u2192 ");throw new Error(`[orderRelations] Circular reference detected in relation ordering: ${i}`)}if(n.push(e.id),!e.after)t.unshift(e.id);else{let i=f.get(e.after);if(!i)t.push(e.id);else{t.includes(i.id)||l(i,n);let p=t.indexOf(i.id);p===-1?(console.warn(`[orderRelations] Could not find position after placing relation ${i.id}. Adding relation ${e.id} to end.`),t.push(e.id)):t.splice(p+1,0,e.id)}}let c=o.indexOf(e);c!==-1&&o.splice(c,1)}for(;o.length;){let e=o[0];l(e)}let a=[];for(let e of t){let n=d.get(e);n&&a.push(n)}return a}export{u as a};
2
+ //# sourceMappingURL=chunk-KY36PVHK.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/relation-ordering.ts"],"sourcesContent":["import type { EntityID } from '@wovin/core/applog'\nimport type { RelationInfo } from './types'\n\n/**\n * Orders relations based on their 'after' field (sibling ordering).\n *\n * This is a pure function that takes relations and returns them in the correct order\n * based on their 'after' field, which specifies which sibling block each relation should come after.\n *\n * @param relations - Array of relations to order (all must have same childOf)\n * @returns Ordered array of relations\n * @throws Error if relations have different parents or if circular references are detected\n */\nexport function orderRelations(originalList: readonly RelationInfo[]): RelationInfo[] {\n\tif (!originalList?.length) return []\n\n\t// Filter out deleted relations and create mutable working copy\n\tconst list = originalList.filter(rel => !rel.isDeleted).slice()\n\n\t// Sort by ID to make it deterministic\n\tlist.sort((a, b) => (a.id < b.id) ? -1 : 1)\n\n\t// Validate all relations have the same parent\n\tconst uniqueParents = new Set(list.map(rel => rel.childOf))\n\tif (uniqueParents.size !== 1) {\n\t\tthrow new Error(\n\t\t\t`[orderRelations] All relations must have the same parent. ` +\n\t\t\t`Found ${uniqueParents.size} different parents: ${Array.from(uniqueParents).join(', ')}`\n\t\t)\n\t}\n\n\tconst orderedRelationIDs: EntityID[] = []\n\tconst relIDMap = new Map<EntityID, RelationInfo>()\n\tconst blockToRel = new Map<EntityID, RelationInfo>()\n\n\tfor (const rel of list) {\n\t\trelIDMap.set(rel.id, rel)\n\t\tblockToRel.set(rel.block, rel)\n\t}\n\n\tfunction placeRecursively(rel: RelationInfo, trace: EntityID[] = []) {\n\t\t// Detect circular references\n\t\tif (trace.includes(rel.id)) {\n\t\t\tconst cycle = [...trace, rel.id].join(' → ')\n\t\t\tthrow new Error(\n\t\t\t\t`[orderRelations] Circular reference detected in relation ordering: ${cycle}`\n\t\t\t)\n\t\t}\n\t\ttrace.push(rel.id)\n\n\t\tif (!rel.after) {\n\t\t\t// No 'after' means this goes at the top\n\t\t\torderedRelationIDs.unshift(rel.id)\n\t\t} else {\n\t\t\t// Find the relation we should be after\n\t\t\tconst relWeAreAfter = blockToRel.get(rel.after)\n\t\t\tif (!relWeAreAfter) {\n\t\t\t\t// Referenced block doesn't exist or isn't a child - add to bottom\n\t\t\t\torderedRelationIDs.push(rel.id)\n\t\t\t} else {\n\t\t\t\t// Recursively place the relation we're after (if not already placed)\n\t\t\t\tif (!orderedRelationIDs.includes(relWeAreAfter.id)) {\n\t\t\t\t\tplaceRecursively(relWeAreAfter, trace)\n\t\t\t\t}\n\n\t\t\t\tconst posOfNodeWeAreAfter = orderedRelationIDs.indexOf(relWeAreAfter.id)\n\t\t\t\tif (posOfNodeWeAreAfter === -1) {\n\t\t\t\t\t// This shouldn't happen, but if it does, add to end\n\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t`[orderRelations] Could not find position after placing relation ${relWeAreAfter.id}. ` +\n\t\t\t\t\t\t`Adding relation ${rel.id} to end.`\n\t\t\t\t\t)\n\t\t\t\t\torderedRelationIDs.push(rel.id)\n\t\t\t\t} else {\n\t\t\t\t\t// Insert right after the relation we're supposed to be after\n\t\t\t\t\torderedRelationIDs.splice(posOfNodeWeAreAfter + 1, 0, rel.id)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Remove from 'to be placed' list\n\t\tconst index = list.indexOf(rel)\n\t\tif (index !== -1) {\n\t\t\tlist.splice(index, 1)\n\t\t}\n\t}\n\n\t// Place all relations\n\twhile (list.length) {\n\t\tconst toPlace = list[0]\n\t\tplaceRecursively(toPlace)\n\t}\n\n\t// Build final ordered list\n\tconst sortedList: RelationInfo[] = []\n\tfor (const relID of orderedRelationIDs) {\n\t\tconst rel = relIDMap.get(relID)\n\t\tif (rel) {\n\t\t\tsortedList.push(rel)\n\t\t}\n\t}\n\n\treturn sortedList\n}\n"],"mappings":"AAaO,SAASA,EAAeC,EAAuD,CACrF,GAAI,CAACA,GAAc,OAAQ,MAAO,CAAC,EAGnC,IAAMC,EAAOD,EAAa,OAAOE,GAAO,CAACA,EAAI,SAAS,EAAE,MAAM,EAG9DD,EAAK,KAAK,CAACE,EAAGC,IAAOD,EAAE,GAAKC,EAAE,GAAM,GAAK,CAAC,EAG1C,IAAMC,EAAgB,IAAI,IAAIJ,EAAK,IAAIC,GAAOA,EAAI,OAAO,CAAC,EAC1D,GAAIG,EAAc,OAAS,EAC1B,MAAM,IAAI,MACT,mEACSA,EAAc,IAAI,uBAAuB,MAAM,KAAKA,CAAa,EAAE,KAAK,IAAI,CAAC,EACvF,EAGD,IAAMC,EAAiC,CAAC,EAClCC,EAAW,IAAI,IACfC,EAAa,IAAI,IAEvB,QAAWN,KAAOD,EACjBM,EAAS,IAAIL,EAAI,GAAIA,CAAG,EACxBM,EAAW,IAAIN,EAAI,MAAOA,CAAG,EAG9B,SAASO,EAAiBP,EAAmBQ,EAAoB,CAAC,EAAG,CAEpE,GAAIA,EAAM,SAASR,EAAI,EAAE,EAAG,CAC3B,IAAMS,EAAQ,CAAC,GAAGD,EAAOR,EAAI,EAAE,EAAE,KAAK,UAAK,EAC3C,MAAM,IAAI,MACT,sEAAsES,CAAK,EAC5E,CACD,CAGA,GAFAD,EAAM,KAAKR,EAAI,EAAE,EAEb,CAACA,EAAI,MAERI,EAAmB,QAAQJ,EAAI,EAAE,MAC3B,CAEN,IAAMU,EAAgBJ,EAAW,IAAIN,EAAI,KAAK,EAC9C,GAAI,CAACU,EAEJN,EAAmB,KAAKJ,EAAI,EAAE,MACxB,CAEDI,EAAmB,SAASM,EAAc,EAAE,GAChDH,EAAiBG,EAAeF,CAAK,EAGtC,IAAMG,EAAsBP,EAAmB,QAAQM,EAAc,EAAE,EACnEC,IAAwB,IAE3B,QAAQ,KACP,mEAAmED,EAAc,EAAE,qBAChEV,EAAI,EAAE,UAC1B,EACAI,EAAmB,KAAKJ,EAAI,EAAE,GAG9BI,EAAmB,OAAOO,EAAsB,EAAG,EAAGX,EAAI,EAAE,CAE9D,CACD,CAGA,IAAMY,EAAQb,EAAK,QAAQC,CAAG,EAC1BY,IAAU,IACbb,EAAK,OAAOa,EAAO,CAAC,CAEtB,CAGA,KAAOb,EAAK,QAAQ,CACnB,IAAMc,EAAUd,EAAK,CAAC,EACtBQ,EAAiBM,CAAO,CACzB,CAGA,IAAMC,EAA6B,CAAC,EACpC,QAAWC,KAASX,EAAoB,CACvC,IAAMJ,EAAMK,EAAS,IAAIU,CAAK,EAC1Bf,GACHc,EAAW,KAAKd,CAAG,CAErB,CAEA,OAAOc,CACR","names":["orderRelations","originalList","list","rel","a","b","uniqueParents","orderedRelationIDs","relIDMap","blockToRel","placeRecursively","trace","cycle","relWeAreAfter","posOfNodeWeAreAfter","index","toPlace","sortedList","relID"]}
@@ -0,0 +1,2 @@
1
+ import{l as i,m as p,n as c,o}from"./chunk-POX3PUJK.min.js";function T(t){return{type:"doc",content:[{type:"paragraph",content:t.length?[{type:"text",text:t}]:void 0}]}}function u(t){return t==null?t:t.startsWith("{")?JSON.parse(t):T(t)}function s(t){return t?.content?.map(n=>n?.content).flatMap(n=>n?.map(e=>e?.text)).join("")}function f(t){return r(i,t)}function h(t){return r(p,t)}function C(t){return r(c,t)}function A(t){return r(o,t)}function r(t,n){let e=t.exec(n);return e&&e[2].toLocaleLowerCase()}function E(t,n,e){if(!t.exec(e))return null;let a=n.exec(g(e));return a&&a[2].toLocaleLowerCase()}function _(t,n=o){return n.global||(n=new RegExp(n.source,`${n.flags}g`)),Array.from(t.matchAll(n)).map(e=>e[0])}function g(t){return s(u(t))}export{T as a,u as b,s as c,f as d,h as e,C as f,A as g,r as h,E as i,_ as j,g as k};
2
+ //# sourceMappingURL=chunk-LDNVHZO7.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/note3-utils-nodeps.ts"],"sourcesContent":["import {\n\tRE_ANY_TAG_WITHCONTEXT,\n\tRE_AT_TAG_WITHCONTEXT,\n\tRE_HASH_TAG_WITHCONTEXT,\n\tRE_PLUS_TAG_WITHCONTEXT,\n} from './note3-regex-constants'\n\nexport type TiptapContent = Record<string, any>\n\n// HACK This module exposes utilities without pulling in the entire app\n\nexport function plaintextStringToTiptap(value: string) {\n\treturn {\n\t\ttype: 'doc',\n\t\tcontent: [\n\t\t\t{\n\t\t\t\ttype: 'paragraph',\n\t\t\t\tcontent: !value.length\n\t\t\t\t\t? undefined\n\t\t\t\t\t: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext: value,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t},\n\t\t],\n\t}\n}\nexport function parseBlockContentValue(value: string) {\n\tif (value === null || value === undefined) {\n\t\treturn value\n\t}\n\tif (!value.startsWith('{')) {\n\t\t// HACK too lazy to do migrations yet\n\t\treturn plaintextStringToTiptap(value)\n\t}\n\treturn JSON.parse(value)\n}\n\nexport function tiptapToPlaintext(tiptap: TiptapContent) {\n\t// HACK: works for now, but...\n\treturn tiptap?.content?.map(c => c?.content).flatMap(c => c?.map(c => c?.text)).join('') as string | null\n}\n\nexport function plainContentMatchHashTag(content: string) {\n\treturn plainContentMatchTagGeneric(RE_HASH_TAG_WITHCONTEXT, content)\n}\nexport function plainContentMatchPlusTag(content: string) {\n\treturn plainContentMatchTagGeneric(RE_PLUS_TAG_WITHCONTEXT, content)\n}\nexport function plainContentMatchAtTag(content: string) {\n\treturn plainContentMatchTagGeneric(RE_AT_TAG_WITHCONTEXT, content)\n}\nexport function plainContentMatchAnyTag(content: string) {\n\treturn plainContentMatchTagGeneric(RE_ANY_TAG_WITHCONTEXT, content)\n}\nexport function plainContentMatchTagGeneric(regex: RegExp, content: string) {\n\tconst match = regex.exec(content)\n\treturn match && match[2].toLocaleLowerCase()\n}\nexport function rawContentMatchTag(regexCheap: RegExp, regex: RegExp, vl) {\n\tconst cheapMatch = regexCheap.exec(vl) // (i) cheap match before parsing tiptap content\n\tif (!cheapMatch) return null\n\tconst match = regex.exec(contentVlToPlaintext(vl)) // HACK: use materialized view\n\treturn match && match[2].toLocaleLowerCase()\n}\n\nexport function getAllTagsInText(text: string, regex = RE_ANY_TAG_WITHCONTEXT) {\n\tif (!regex.global) regex = new RegExp(regex.source, `${regex.flags}g`)\n\treturn Array.from(text.matchAll(regex)).map(match => match[0])\n}\nexport function contentVlToPlaintext(content: string) {\n\treturn tiptapToPlaintext(parseBlockContentValue(content))\n}\n"],"mappings":"4DAWO,SAASA,EAAwBC,EAAe,CACtD,MAAO,CACN,KAAM,MACN,QAAS,CACR,CACC,KAAM,YACN,QAAUA,EAAM,OAEb,CACD,CACC,KAAM,OACN,KAAMA,CACP,CACD,EANE,MAOJ,CACD,CACD,CACD,CACO,SAASC,EAAuBD,EAAe,CACrD,OAAIA,GAAU,KACNA,EAEHA,EAAM,WAAW,GAAG,EAIlB,KAAK,MAAMA,CAAK,EAFfD,EAAwBC,CAAK,CAGtC,CAEO,SAASE,EAAkBC,EAAuB,CAExD,OAAOA,GAAQ,SAAS,IAAIC,GAAKA,GAAG,OAAO,EAAE,QAAQA,GAAKA,GAAG,IAAIA,GAAKA,GAAG,IAAI,CAAC,EAAE,KAAK,EAAE,CACxF,CAEO,SAASC,EAAyBC,EAAiB,CACzD,OAAOC,EAA4BC,EAAyBF,CAAO,CACpE,CACO,SAASG,EAAyBH,EAAiB,CACzD,OAAOC,EAA4BG,EAAyBJ,CAAO,CACpE,CACO,SAASK,EAAuBL,EAAiB,CACvD,OAAOC,EAA4BK,EAAuBN,CAAO,CAClE,CACO,SAASO,EAAwBP,EAAiB,CACxD,OAAOC,EAA4BO,EAAwBR,CAAO,CACnE,CACO,SAASC,EAA4BQ,EAAeT,EAAiB,CAC3E,IAAMU,EAAQD,EAAM,KAAKT,CAAO,EAChC,OAAOU,GAASA,EAAM,CAAC,EAAE,kBAAkB,CAC5C,CACO,SAASC,EAAmBC,EAAoBH,EAAeI,EAAI,CAEzE,GAAI,CADeD,EAAW,KAAKC,CAAE,EACpB,OAAO,KACxB,IAAMH,EAAQD,EAAM,KAAKK,EAAqBD,CAAE,CAAC,EACjD,OAAOH,GAASA,EAAM,CAAC,EAAE,kBAAkB,CAC5C,CAEO,SAASK,EAAiBC,EAAcP,EAAQD,EAAwB,CAC9E,OAAKC,EAAM,SAAQA,EAAQ,IAAI,OAAOA,EAAM,OAAQ,GAAGA,EAAM,KAAK,GAAG,GAC9D,MAAM,KAAKO,EAAK,SAASP,CAAK,CAAC,EAAE,IAAIC,GAASA,EAAM,CAAC,CAAC,CAC9D,CACO,SAASI,EAAqBd,EAAiB,CACrD,OAAOJ,EAAkBD,EAAuBK,CAAO,CAAC,CACzD","names":["plaintextStringToTiptap","value","parseBlockContentValue","tiptapToPlaintext","tiptap","c","plainContentMatchHashTag","content","plainContentMatchTagGeneric","RE_HASH_TAG_WITHCONTEXT","plainContentMatchPlusTag","RE_PLUS_TAG_WITHCONTEXT","plainContentMatchAtTag","RE_AT_TAG_WITHCONTEXT","plainContentMatchAnyTag","RE_ANY_TAG_WITHCONTEXT","regex","match","rawContentMatchTag","regexCheap","vl","contentVlToPlaintext","getAllTagsInText","text"]}
@@ -0,0 +1,2 @@
1
+ var s={content:[{type:"paragraph"}],type:"doc"},c=2,T=new RegExp("[a-zA-Z0-9_:+/-]"),r=new RegExp("[a-zA-Z]"),e=new RegExp(`(?=${T.source}*${r.source})${T.source}{${c},}`),E=new RegExp(`#(${e.source})`),t=new RegExp(`\\+(${e.source})`),p=new RegExp(`@(${e.source})`),R=new RegExp(`([#+@])(${e.source})`),o=/(^|\s|\()/,_=/(\b|$)/,n=new RegExp(`${o.source}#(${e.source})${_.source}`),x=new RegExp(`${o.source}\\+(${e.source})${_.source}`),A=new RegExp(`${o.source}@(${e.source})${_.source}`),$=new RegExp(`${o.source}([#+@])(${e.source})${_.source}`);export{s as a,c as b,T as c,r as d,e,E as f,t as g,p as h,R as i,o as j,_ as k,n as l,x as m,A as n,$ as o};
2
+ //# sourceMappingURL=chunk-POX3PUJK.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/note3-regex-constants.ts"],"sourcesContent":["// Regex constants for tag matching in note3\n// Extracted to separate file to avoid heavy dependencies\n\n// HACK regexp lints are too complex for 10pm\n/* eslint-disable regexp/no-empty-capturing-group */\n/* eslint-disable regexp/prefer-w */\n/* eslint-disable regexp/use-ignore-case */\nexport const TIPTAP_EMPTY = { content: [{ type: 'paragraph' }], type: 'doc' }\nexport const TAG_MIN_LENGTH = 2 // HACK: for sanity of query performance // ? but are short queries really not needed?\nexport const RE_TAG_BODY_CHAR = new RegExp(`[a-zA-Z0-9_:+/-]`)\nexport const RE_TAG_BODY_REQUIRED_CHAR = new RegExp(`[a-zA-Z]`)\nexport const RE_TAG_BODY = new RegExp(\n\t`(?=${RE_TAG_BODY_CHAR.source}*${RE_TAG_BODY_REQUIRED_CHAR.source})` // Lookahead to ensure at least one letter char in the tag name\n\t\t+ `${RE_TAG_BODY_CHAR.source}{${TAG_MIN_LENGTH},}`,\n)\nexport const RE_HASH_TAG_ONLY = new RegExp(`#(${RE_TAG_BODY.source})`)\nexport const RE_PLUS_TAG_ONLY = new RegExp(`\\\\+(${RE_TAG_BODY.source})`)\nexport const RE_AT_TAG_ONLY = new RegExp(`@(${RE_TAG_BODY.source})`)\nexport const RE_ANY_TAG_ONLY = new RegExp(`([#+@])(${RE_TAG_BODY.source})`)\n// context-aware matching\n\nexport const RE_TAG_CONTEXT_PRE = /(^|\\s|\\()/\nexport const RE_TAG_CONTEXT_POST = /(\\b|$)/ // (i) \\b also matches if the tag continues with e.g. /\nexport const RE_HASH_TAG_WITHCONTEXT = new RegExp(`${RE_TAG_CONTEXT_PRE.source}#(${RE_TAG_BODY.source})${RE_TAG_CONTEXT_POST.source}`)\nexport const RE_PLUS_TAG_WITHCONTEXT = new RegExp(`${RE_TAG_CONTEXT_PRE.source}\\\\+(${RE_TAG_BODY.source})${RE_TAG_CONTEXT_POST.source}`)\nexport const RE_AT_TAG_WITHCONTEXT = new RegExp(`${RE_TAG_CONTEXT_PRE.source}@(${RE_TAG_BODY.source})${RE_TAG_CONTEXT_POST.source}`)\nexport const RE_ANY_TAG_WITHCONTEXT = new RegExp(`${RE_TAG_CONTEXT_PRE.source}([#+@])(${RE_TAG_BODY.source})${RE_TAG_CONTEXT_POST.source}`)\n"],"mappings":"AAOO,IAAMA,EAAe,CAAE,QAAS,CAAC,CAAE,KAAM,WAAY,CAAC,EAAG,KAAM,KAAM,EAC/DC,EAAiB,EACjBC,EAAmB,IAAI,OAAO,kBAAkB,EAChDC,EAA4B,IAAI,OAAO,UAAU,EACjDC,EAAc,IAAI,OAC9B,MAAMF,EAAiB,MAAM,IAAIC,EAA0B,MAAM,IAC3DD,EAAiB,MAAM,IAAID,CAAc,IAChD,EACaI,EAAmB,IAAI,OAAO,KAAKD,EAAY,MAAM,GAAG,EACxDE,EAAmB,IAAI,OAAO,OAAOF,EAAY,MAAM,GAAG,EAC1DG,EAAiB,IAAI,OAAO,KAAKH,EAAY,MAAM,GAAG,EACtDI,EAAkB,IAAI,OAAO,WAAWJ,EAAY,MAAM,GAAG,EAG7DK,EAAqB,YACrBC,EAAsB,SACtBC,EAA0B,IAAI,OAAO,GAAGF,EAAmB,MAAM,KAAKL,EAAY,MAAM,IAAIM,EAAoB,MAAM,EAAE,EACxHE,EAA0B,IAAI,OAAO,GAAGH,EAAmB,MAAM,OAAOL,EAAY,MAAM,IAAIM,EAAoB,MAAM,EAAE,EAC1HG,EAAwB,IAAI,OAAO,GAAGJ,EAAmB,MAAM,KAAKL,EAAY,MAAM,IAAIM,EAAoB,MAAM,EAAE,EACtHI,EAAyB,IAAI,OAAO,GAAGL,EAAmB,MAAM,WAAWL,EAAY,MAAM,IAAIM,EAAoB,MAAM,EAAE","names":["TIPTAP_EMPTY","TAG_MIN_LENGTH","RE_TAG_BODY_CHAR","RE_TAG_BODY_REQUIRED_CHAR","RE_TAG_BODY","RE_HASH_TAG_ONLY","RE_PLUS_TAG_ONLY","RE_AT_TAG_ONLY","RE_ANY_TAG_ONLY","RE_TAG_CONTEXT_PRE","RE_TAG_CONTEXT_POST","RE_HASH_TAG_WITHCONTEXT","RE_PLUS_TAG_WITHCONTEXT","RE_AT_TAG_WITHCONTEXT","RE_ANY_TAG_WITHCONTEXT"]}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  export * from './helpers';
2
2
  export * from './map';
3
- export * from './worker';
3
+ export * from './note3-regex-constants';
4
+ export * from './note3-utils-nodeps';
5
+ export * from './queries';
6
+ export * from './types';
7
+ export * from './relation-ordering';
4
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA;AACzB,cAAc,OAAO,CAAA;AACrB,cAAc,yBAAyB,CAAA;AACvC,cAAc,sBAAsB,CAAA;AACpC,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,qBAAqB,CAAA"}
package/dist/index.min.js CHANGED
@@ -1,2 +1,2 @@
1
- import{a as o,b as r,c as e,d as f,e as m}from"./chunk-PA6WBVCJ.min.js";import{a as p}from"./chunk-IFY2JCCQ.min.js";import{a as t}from"./chunk-Z5VZCNIS.min.js";import"./chunk-MXMMU6NF.min.js";export{p as SetMap,e as asyncIterableToArray,f as blobToAsyncIterable,t as destroyWorker,o as lazyVal,r as racePromises,m as recurseWithLoopProtection};
1
+ import"./chunk-KHOUPFOL.min.js";import{a as o,b as r,c as e,d as f,e as m}from"./chunk-PA6WBVCJ.min.js";import{a as p}from"./chunk-IFY2JCCQ.min.js";import{a as H,b as I,c as J,d as K,e as L,f as M,g as N}from"./chunk-44UQ54GR.min.js";import{a as u,b as v,c as w,d as y,e as z,f as A,g as B,h as C,i as D,j as E,k as F}from"./chunk-LDNVHZO7.min.js";import{a as t,b as x,c as a,d as b,e as c,f as d,g,h,i,j,k,l,m as n,n as q,o as s}from"./chunk-POX3PUJK.min.js";import{a as G}from"./chunk-KY36PVHK.min.js";import"./chunk-MXMMU6NF.min.js";export{i as RE_ANY_TAG_ONLY,s as RE_ANY_TAG_WITHCONTEXT,h as RE_AT_TAG_ONLY,q as RE_AT_TAG_WITHCONTEXT,d as RE_HASH_TAG_ONLY,l as RE_HASH_TAG_WITHCONTEXT,g as RE_PLUS_TAG_ONLY,n as RE_PLUS_TAG_WITHCONTEXT,c as RE_TAG_BODY,a as RE_TAG_BODY_CHAR,b as RE_TAG_BODY_REQUIRED_CHAR,k as RE_TAG_CONTEXT_POST,j as RE_TAG_CONTEXT_PRE,p as SetMap,x as TAG_MIN_LENGTH,t as TIPTAP_EMPTY,e as asyncIterableToArray,f as blobToAsyncIterable,F as contentVlToPlaintext,E as getAllTagsInText,H as getChildIDs,J as getChildRelations,L as getContent,M as getContentText,I as getParentIDs,K as getParentRelations,N as getRootIDs,o as lazyVal,G as orderRelations,v as parseBlockContentValue,B as plainContentMatchAnyTag,A as plainContentMatchAtTag,y as plainContentMatchHashTag,z as plainContentMatchPlusTag,C as plainContentMatchTagGeneric,u as plaintextStringToTiptap,r as racePromises,D as rawContentMatchTag,m as recurseWithLoopProtection,w as tiptapToPlaintext};
2
2
  //# sourceMappingURL=index.min.js.map
@@ -0,0 +1,21 @@
1
+ export declare const TIPTAP_EMPTY: {
2
+ content: {
3
+ type: string;
4
+ }[];
5
+ type: string;
6
+ };
7
+ export declare const TAG_MIN_LENGTH = 2;
8
+ export declare const RE_TAG_BODY_CHAR: RegExp;
9
+ export declare const RE_TAG_BODY_REQUIRED_CHAR: RegExp;
10
+ export declare const RE_TAG_BODY: RegExp;
11
+ export declare const RE_HASH_TAG_ONLY: RegExp;
12
+ export declare const RE_PLUS_TAG_ONLY: RegExp;
13
+ export declare const RE_AT_TAG_ONLY: RegExp;
14
+ export declare const RE_ANY_TAG_ONLY: RegExp;
15
+ export declare const RE_TAG_CONTEXT_PRE: RegExp;
16
+ export declare const RE_TAG_CONTEXT_POST: RegExp;
17
+ export declare const RE_HASH_TAG_WITHCONTEXT: RegExp;
18
+ export declare const RE_PLUS_TAG_WITHCONTEXT: RegExp;
19
+ export declare const RE_AT_TAG_WITHCONTEXT: RegExp;
20
+ export declare const RE_ANY_TAG_WITHCONTEXT: RegExp;
21
+ //# sourceMappingURL=note3-regex-constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"note3-regex-constants.d.ts","sourceRoot":"","sources":["../src/note3-regex-constants.ts"],"names":[],"mappings":"AAOA,eAAO,MAAM,YAAY;;;;;CAAoD,CAAA;AAC7E,eAAO,MAAM,cAAc,IAAI,CAAA;AAC/B,eAAO,MAAM,gBAAgB,QAAiC,CAAA;AAC9D,eAAO,MAAM,yBAAyB,QAAyB,CAAA;AAC/D,eAAO,MAAM,WAAW,QAGvB,CAAA;AACD,eAAO,MAAM,gBAAgB,QAAyC,CAAA;AACtE,eAAO,MAAM,gBAAgB,QAA2C,CAAA;AACxE,eAAO,MAAM,cAAc,QAAyC,CAAA;AACpE,eAAO,MAAM,eAAe,QAA+C,CAAA;AAG3E,eAAO,MAAM,kBAAkB,QAAc,CAAA;AAC7C,eAAO,MAAM,mBAAmB,QAAW,CAAA;AAC3C,eAAO,MAAM,uBAAuB,QAAkG,CAAA;AACtI,eAAO,MAAM,uBAAuB,QAAoG,CAAA;AACxI,eAAO,MAAM,qBAAqB,QAAkG,CAAA;AACpI,eAAO,MAAM,sBAAsB,QAAwG,CAAA"}
@@ -0,0 +1,2 @@
1
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}from"./chunk-POX3PUJK.min.js";import"./chunk-MXMMU6NF.min.js";export{i as RE_ANY_TAG_ONLY,o as RE_ANY_TAG_WITHCONTEXT,h as RE_AT_TAG_ONLY,n as RE_AT_TAG_WITHCONTEXT,f as RE_HASH_TAG_ONLY,l as RE_HASH_TAG_WITHCONTEXT,g as RE_PLUS_TAG_ONLY,m as RE_PLUS_TAG_WITHCONTEXT,e as RE_TAG_BODY,c as RE_TAG_BODY_CHAR,d as RE_TAG_BODY_REQUIRED_CHAR,k as RE_TAG_CONTEXT_POST,j as RE_TAG_CONTEXT_PRE,b as TAG_MIN_LENGTH,a as TIPTAP_EMPTY};
2
+ //# sourceMappingURL=note3-regex-constants.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,22 @@
1
+ export type TiptapContent = Record<string, any>;
2
+ export declare function plaintextStringToTiptap(value: string): {
3
+ type: string;
4
+ content: {
5
+ type: string;
6
+ content: {
7
+ type: string;
8
+ text: string;
9
+ }[];
10
+ }[];
11
+ };
12
+ export declare function parseBlockContentValue(value: string): any;
13
+ export declare function tiptapToPlaintext(tiptap: TiptapContent): string | null;
14
+ export declare function plainContentMatchHashTag(content: string): string;
15
+ export declare function plainContentMatchPlusTag(content: string): string;
16
+ export declare function plainContentMatchAtTag(content: string): string;
17
+ export declare function plainContentMatchAnyTag(content: string): string;
18
+ export declare function plainContentMatchTagGeneric(regex: RegExp, content: string): string;
19
+ export declare function rawContentMatchTag(regexCheap: RegExp, regex: RegExp, vl: any): string;
20
+ export declare function getAllTagsInText(text: string, regex?: RegExp): string[];
21
+ export declare function contentVlToPlaintext(content: string): string;
22
+ //# sourceMappingURL=note3-utils-nodeps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"note3-utils-nodeps.d.ts","sourceRoot":"","sources":["../src/note3-utils-nodeps.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAI/C,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM;;;;;;;;;EAiBpD;AACD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,OASnD;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAEsC,MAAM,GAAG,IAAI,CACzG;AAED,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,UAEvD;AACD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,UAEvD;AACD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,UAErD;AACD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,UAEtD;AACD,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,UAGzE;AACD,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,KAAA,UAKvE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAyB,YAG5E;AACD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,UAEnD"}
@@ -0,0 +1,2 @@
1
+ import{a,b,c,d,e,f,g,h,i,j,k}from"./chunk-LDNVHZO7.min.js";import"./chunk-POX3PUJK.min.js";import"./chunk-MXMMU6NF.min.js";export{k as contentVlToPlaintext,j as getAllTagsInText,b as parseBlockContentValue,g as plainContentMatchAnyTag,f as plainContentMatchAtTag,d as plainContentMatchHashTag,e as plainContentMatchPlusTag,h as plainContentMatchTagGeneric,a as plaintextStringToTiptap,i as rawContentMatchTag,c as tiptapToPlaintext};
2
+ //# sourceMappingURL=note3-utils-nodeps.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,53 @@
1
+ import type { EntityID } from '@wovin/core/applog';
2
+ import type { Thread } from '@wovin/core/thread';
3
+ import type { RelationInfo } from './types';
4
+ import { type TiptapContent } from './note3-utils-nodeps';
5
+ /**
6
+ * Get all child block IDs for a given parent block
7
+ * @param thread - The thread to query
8
+ * @param parentId - The parent block's entity ID
9
+ * @returns Array of child block IDs (unordered - use getChildRelations for ordered)
10
+ */
11
+ export declare function getChildIDs(thread: Thread, parentId: EntityID): EntityID[];
12
+ /**
13
+ * Get all parent block IDs for a given block
14
+ * @param thread - The thread to query
15
+ * @param blockId - The block's entity ID
16
+ * @returns Array of parent block IDs (usually just one, but can be multiple)
17
+ */
18
+ export declare function getParentIDs(thread: Thread, blockId: EntityID): EntityID[];
19
+ /**
20
+ * Get ordered child relations for a given parent block
21
+ * @param thread - The thread to query
22
+ * @param parentId - The parent block's entity ID
23
+ * @returns Ordered array of RelationInfo objects
24
+ */
25
+ export declare function getChildRelations(thread: Thread, parentId: EntityID): RelationInfo[];
26
+ /**
27
+ * Get parent relations (placements) for a given block
28
+ * @param thread - The thread to query
29
+ * @param blockId - The block's entity ID
30
+ * @returns Array of RelationInfo objects (unordered)
31
+ */
32
+ export declare function getParentRelations(thread: Thread, blockId: EntityID): RelationInfo[];
33
+ /**
34
+ * Get the content of a block as TiptapContent
35
+ * @param thread - The thread to query
36
+ * @param blockId - The block's entity ID
37
+ * @returns TiptapContent object or null if not found
38
+ */
39
+ export declare function getContent(thread: Thread, blockId: EntityID): TiptapContent | null;
40
+ /**
41
+ * Get the plain text content of a block
42
+ * @param thread - The thread to query
43
+ * @param blockId - The block's entity ID
44
+ * @returns Plain text string or null if not found
45
+ */
46
+ export declare function getContentText(thread: Thread, blockId: EntityID): string | null;
47
+ /**
48
+ * Get all root block IDs (blocks without parents)
49
+ * @param thread - The thread to query
50
+ * @returns Array of root block IDs, sorted by entity ID
51
+ */
52
+ export declare function getRootIDs(thread: Thread): EntityID[];
53
+ //# sourceMappingURL=queries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAA6C,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAapG;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAK1E;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,QAAQ,EAAE,CAsB1E;AA4CD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,YAAY,EAAE,CAapF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,YAAY,EAAE,CAUpF;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,aAAa,GAAG,IAAI,CAQlF;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAI/E;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,CAoCrD"}
@@ -0,0 +1,2 @@
1
+ import{a,b,c,d,e,f,g}from"./chunk-44UQ54GR.min.js";import"./chunk-LDNVHZO7.min.js";import"./chunk-POX3PUJK.min.js";import"./chunk-KY36PVHK.min.js";import"./chunk-MXMMU6NF.min.js";export{a as getChildIDs,c as getChildRelations,e as getContent,f as getContentText,b as getParentIDs,d as getParentRelations,g as getRootIDs};
2
+ //# sourceMappingURL=queries.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,13 @@
1
+ import type { RelationInfo } from './types';
2
+ /**
3
+ * Orders relations based on their 'after' field (sibling ordering).
4
+ *
5
+ * This is a pure function that takes relations and returns them in the correct order
6
+ * based on their 'after' field, which specifies which sibling block each relation should come after.
7
+ *
8
+ * @param relations - Array of relations to order (all must have same childOf)
9
+ * @returns Ordered array of relations
10
+ * @throws Error if relations have different parents or if circular references are detected
11
+ */
12
+ export declare function orderRelations(originalList: readonly RelationInfo[]): RelationInfo[];
13
+ //# sourceMappingURL=relation-ordering.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"relation-ordering.d.ts","sourceRoot":"","sources":["../src/relation-ordering.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAE3C;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,YAAY,EAAE,SAAS,YAAY,EAAE,GAAG,YAAY,EAAE,CA0FpF"}
@@ -0,0 +1,2 @@
1
+ import{a}from"./chunk-KY36PVHK.min.js";import"./chunk-MXMMU6NF.min.js";export{a as orderRelations};
2
+ //# sourceMappingURL=relation-ordering.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,20 @@
1
+ import type { EntityID } from '@wovin/core/applog';
2
+ export interface RelationInfo {
3
+ /** The relation's entity ID */
4
+ id: EntityID;
5
+ /** The child block ID */
6
+ block: EntityID;
7
+ /** The parent block ID */
8
+ childOf: EntityID;
9
+ /** Sibling ordering - ID of the block this should come after */
10
+ after: EntityID | null;
11
+ /** Whether the relation is expanded in UI */
12
+ isExpanded?: boolean;
13
+ /** Whether this is a mirror relation */
14
+ isMirror?: boolean;
15
+ /** Whether this is a reply relation */
16
+ isReply?: boolean;
17
+ /** Whether the relation is deleted */
18
+ isDeleted?: boolean;
19
+ }
20
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAElD,MAAM,WAAW,YAAY;IAC5B,+BAA+B;IAC/B,EAAE,EAAE,QAAQ,CAAA;IACZ,yBAAyB;IACzB,KAAK,EAAE,QAAQ,CAAA;IACf,0BAA0B;IAC1B,OAAO,EAAE,QAAQ,CAAA;IACjB,gEAAgE;IAChE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;IACtB,6CAA6C;IAC7C,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,uCAAuC;IACvC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,sCAAsC;IACtC,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB"}
@@ -0,0 +1,2 @@
1
+ import"./chunk-KHOUPFOL.min.js";
2
+ //# sourceMappingURL=types.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@note3/utils",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "main": "./dist/index.min.js",
@@ -27,6 +27,7 @@
27
27
  "bundle": false
28
28
  },
29
29
  "dependencies": {
30
+ "@wovin/core": "0.0.18",
30
31
  "besonders-logger": "1.0.2",
31
32
  "comlink": "^4.4.2",
32
33
  "core-js": "^3.45.1",
@@ -1,11 +0,0 @@
1
- var g=Symbol("Comlink.proxy"),d=Symbol("Comlink.endpoint"),a=Symbol("Comlink.releaseProxy"),p=Symbol("Comlink.finalizer"),E=Symbol("Comlink.thrown");function l(e){return e.constructor.name==="MessagePort"}function u(e){l(e)&&e.close()}function f(e){return m(e,new Map,{type:"RELEASE"}).then(()=>{u(e)})}var n=new WeakMap,w="FinalizationRegistry"in globalThis&&new FinalizationRegistry(e=>{let r=(n.get(e)||0)-1;n.set(e,r),r===0&&f(e)});function m(e,r,s,i){return new Promise(c=>{let t=y();r.set(t,c),e.start&&e.start(),e.postMessage(Object.assign({id:t},s),i)})}function y(){return new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")}var o=Symbol("getEndpoint");function P(e){e[o].terminate(),e[a]()}export{P as a};
2
- /*! Bundled license information:
3
-
4
- comlink/dist/esm/comlink.mjs:
5
- (**
6
- * @license
7
- * Copyright 2019 Google LLC
8
- * SPDX-License-Identifier: Apache-2.0
9
- *)
10
- */
11
- //# sourceMappingURL=chunk-Z5VZCNIS.min.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../node_modules/.pnpm/comlink@4.4.2/node_modules/comlink/src/comlink.ts","../../../../node_modules/.pnpm/vite-plugin-comlink@5.3.0_comlink@4.4.2_vite@7.1.7/node_modules/vite-plugin-comlink/dist/symbol.js","../src/worker.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2019 Google LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport {\n Endpoint,\n EventSource,\n Message,\n MessageType,\n PostMessageWithOrigin,\n WireValue,\n WireValueType,\n} from \"./protocol\";\nexport type { Endpoint };\n\nexport const proxyMarker = Symbol(\"Comlink.proxy\");\nexport const createEndpoint = Symbol(\"Comlink.endpoint\");\nexport const releaseProxy = Symbol(\"Comlink.releaseProxy\");\nexport const finalizer = Symbol(\"Comlink.finalizer\");\n\nconst throwMarker = Symbol(\"Comlink.thrown\");\n\n/**\n * Interface of values that were marked to be proxied with `comlink.proxy()`.\n * Can also be implemented by classes.\n */\nexport interface ProxyMarked {\n [proxyMarker]: true;\n}\n\n/**\n * Takes a type and wraps it in a Promise, if it not already is one.\n * This is to avoid `Promise<Promise<T>>`.\n *\n * This is the inverse of `Unpromisify<T>`.\n */\ntype Promisify<T> = T extends Promise<unknown> ? T : Promise<T>;\n/**\n * Takes a type that may be Promise and unwraps the Promise type.\n * If `P` is not a Promise, it returns `P`.\n *\n * This is the inverse of `Promisify<T>`.\n */\ntype Unpromisify<P> = P extends Promise<infer T> ? T : P;\n\n/**\n * Takes the raw type of a remote property and returns the type that is visible to the local thread on the proxy.\n *\n * Note: This needs to be its own type alias, otherwise it will not distribute over unions.\n * See https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types\n */\ntype RemoteProperty<T> =\n // If the value is a method, comlink will proxy it automatically.\n // Objects are only proxied if they are marked to be proxied.\n // Otherwise, the property is converted to a Promise that resolves the cloned value.\n T extends Function | ProxyMarked ? Remote<T> : Promisify<T>;\n\n/**\n * Takes the raw type of a property as a remote thread would see it through a proxy (e.g. when passed in as a function\n * argument) and returns the type that the local thread has to supply.\n *\n * This is the inverse of `RemoteProperty<T>`.\n *\n * Note: This needs to be its own type alias, otherwise it will not distribute over unions. See\n * https://www.typescriptlang.org/docs/handbook/advanced-types.html#distributive-conditional-types\n */\ntype LocalProperty<T> = T extends Function | ProxyMarked\n ? Local<T>\n : Unpromisify<T>;\n\n/**\n * Proxies `T` if it is a `ProxyMarked`, clones it otherwise (as handled by structured cloning and transfer handlers).\n */\nexport type ProxyOrClone<T> = T extends ProxyMarked ? Remote<T> : T;\n/**\n * Inverse of `ProxyOrClone<T>`.\n */\nexport type UnproxyOrClone<T> = T extends RemoteObject<ProxyMarked>\n ? Local<T>\n : T;\n\n/**\n * Takes the raw type of a remote object in the other thread and returns the type as it is visible to the local thread\n * when proxied with `Comlink.proxy()`.\n *\n * This does not handle call signatures, which is handled by the more general `Remote<T>` type.\n *\n * @template T The raw type of a remote object as seen in the other thread.\n */\nexport type RemoteObject<T> = { [P in keyof T]: RemoteProperty<T[P]> };\n/**\n * Takes the type of an object as a remote thread would see it through a proxy (e.g. when passed in as a function\n * argument) and returns the type that the local thread has to supply.\n *\n * This does not handle call signatures, which is handled by the more general `Local<T>` type.\n *\n * This is the inverse of `RemoteObject<T>`.\n *\n * @template T The type of a proxied object.\n */\nexport type LocalObject<T> = { [P in keyof T]: LocalProperty<T[P]> };\n\n/**\n * Additional special comlink methods available on each proxy returned by `Comlink.wrap()`.\n */\nexport interface ProxyMethods {\n [createEndpoint]: () => Promise<MessagePort>;\n [releaseProxy]: () => void;\n}\n\n/**\n * Takes the raw type of a remote object, function or class in the other thread and returns the type as it is visible to\n * the local thread from the proxy return value of `Comlink.wrap()` or `Comlink.proxy()`.\n */\nexport type Remote<T> =\n // Handle properties\n RemoteObject<T> &\n // Handle call signature (if present)\n (T extends (...args: infer TArguments) => infer TReturn\n ? (\n ...args: { [I in keyof TArguments]: UnproxyOrClone<TArguments[I]> }\n ) => Promisify<ProxyOrClone<Unpromisify<TReturn>>>\n : unknown) &\n // Handle construct signature (if present)\n // The return of construct signatures is always proxied (whether marked or not)\n (T extends { new (...args: infer TArguments): infer TInstance }\n ? {\n new (\n ...args: {\n [I in keyof TArguments]: UnproxyOrClone<TArguments[I]>;\n }\n ): Promisify<Remote<TInstance>>;\n }\n : unknown) &\n // Include additional special comlink methods available on the proxy.\n ProxyMethods;\n\n/**\n * Expresses that a type can be either a sync or async.\n */\ntype MaybePromise<T> = Promise<T> | T;\n\n/**\n * Takes the raw type of a remote object, function or class as a remote thread would see it through a proxy (e.g. when\n * passed in as a function argument) and returns the type the local thread has to supply.\n *\n * This is the inverse of `Remote<T>`. It takes a `Remote<T>` and returns its original input `T`.\n */\nexport type Local<T> =\n // Omit the special proxy methods (they don't need to be supplied, comlink adds them)\n Omit<LocalObject<T>, keyof ProxyMethods> &\n // Handle call signatures (if present)\n (T extends (...args: infer TArguments) => infer TReturn\n ? (\n ...args: { [I in keyof TArguments]: ProxyOrClone<TArguments[I]> }\n ) => // The raw function could either be sync or async, but is always proxied automatically\n MaybePromise<UnproxyOrClone<Unpromisify<TReturn>>>\n : unknown) &\n // Handle construct signature (if present)\n // The return of construct signatures is always proxied (whether marked or not)\n (T extends { new (...args: infer TArguments): infer TInstance }\n ? {\n new (\n ...args: {\n [I in keyof TArguments]: ProxyOrClone<TArguments[I]>;\n }\n ): // The raw constructor could either be sync or async, but is always proxied automatically\n MaybePromise<Local<Unpromisify<TInstance>>>;\n }\n : unknown);\n\nconst isObject = (val: unknown): val is object =>\n (typeof val === \"object\" && val !== null) || typeof val === \"function\";\n\n/**\n * Customizes the serialization of certain values as determined by `canHandle()`.\n *\n * @template T The input type being handled by this transfer handler.\n * @template S The serialized type sent over the wire.\n */\nexport interface TransferHandler<T, S> {\n /**\n * Gets called for every value to determine whether this transfer handler\n * should serialize the value, which includes checking that it is of the right\n * type (but can perform checks beyond that as well).\n */\n canHandle(value: unknown): value is T;\n\n /**\n * Gets called with the value if `canHandle()` returned `true` to produce a\n * value that can be sent in a message, consisting of structured-cloneable\n * values and/or transferrable objects.\n */\n serialize(value: T): [S, Transferable[]];\n\n /**\n * Gets called to deserialize an incoming value that was serialized in the\n * other thread with this transfer handler (known through the name it was\n * registered under).\n */\n deserialize(value: S): T;\n}\n\n/**\n * Internal transfer handle to handle objects marked to proxy.\n */\nconst proxyTransferHandler: TransferHandler<object, MessagePort> = {\n canHandle: (val): val is ProxyMarked =>\n isObject(val) && (val as ProxyMarked)[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n },\n};\n\ninterface ThrownValue {\n [throwMarker]: unknown; // just needs to be present\n value: unknown;\n}\ntype SerializedThrownValue =\n | { isError: true; value: Error }\n | { isError: false; value: unknown };\ntype PendingListenersMap = Map<\n string,\n (value: WireValue | PromiseLike<WireValue>) => void\n>;\n\n/**\n * Internal transfer handler to handle thrown exceptions.\n */\nconst throwTransferHandler: TransferHandler<\n ThrownValue,\n SerializedThrownValue\n> = {\n canHandle: (value): value is ThrownValue =>\n isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized: SerializedThrownValue;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack,\n },\n };\n } else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(\n new Error(serialized.value.message),\n serialized.value\n );\n }\n throw serialized.value;\n },\n};\n\n/**\n * Allows customizing the serialization of certain values.\n */\nexport const transferHandlers = new Map<\n string,\n TransferHandler<unknown, unknown>\n>([\n [\"proxy\", proxyTransferHandler],\n [\"throw\", throwTransferHandler],\n]);\n\nfunction isAllowedOrigin(\n allowedOrigins: (string | RegExp)[],\n origin: string\n): boolean {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === \"*\") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n}\n\nexport function expose(\n obj: any,\n ep: Endpoint = globalThis as any,\n allowedOrigins: (string | RegExp)[] = [\"*\"]\n) {\n ep.addEventListener(\"message\", function callback(ev: MessageEvent) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin '${ev.origin}' for comlink proxy`);\n return;\n }\n const { id, type, path } = {\n path: [] as string[],\n ...(ev.data as Message),\n };\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj, prop) => obj[prop], obj);\n const rawValue = path.reduce((obj, prop) => obj[prop], obj);\n switch (type) {\n case MessageType.GET:\n {\n returnValue = rawValue;\n }\n break;\n case MessageType.SET:\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case MessageType.APPLY:\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case MessageType.CONSTRUCT:\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case MessageType.ENDPOINT:\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case MessageType.RELEASE:\n {\n returnValue = undefined;\n }\n break;\n default:\n return;\n }\n } catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue)\n .catch((value) => {\n return { value, [throwMarker]: 0 };\n })\n .then((returnValue) => {\n const [wireValue, transferables] = toWireValue(returnValue);\n ep.postMessage({ ...wireValue, id }, transferables);\n if (type === MessageType.RELEASE) {\n // detach and deactive after sending release response above.\n ep.removeEventListener(\"message\", callback as any);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === \"function\") {\n obj[finalizer]();\n }\n }\n })\n .catch((error) => {\n // Send Serialization Error To Caller\n const [wireValue, transferables] = toWireValue({\n value: new TypeError(\"Unserializable return value\"),\n [throwMarker]: 0,\n });\n ep.postMessage({ ...wireValue, id }, transferables);\n });\n } as any);\n if (ep.start) {\n ep.start();\n }\n}\n\nfunction isMessagePort(endpoint: Endpoint): endpoint is MessagePort {\n return endpoint.constructor.name === \"MessagePort\";\n}\n\nfunction closeEndPoint(endpoint: Endpoint) {\n if (isMessagePort(endpoint)) endpoint.close();\n}\n\nexport function wrap<T>(ep: Endpoint, target?: any): Remote<T> {\n const pendingListeners : PendingListenersMap = new Map();\n\n ep.addEventListener(\"message\", function handleMessage(ev: Event) {\n const { data } = ev as MessageEvent;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n\n try {\n resolver(data);\n } finally {\n pendingListeners.delete(data.id);\n }\n });\n\n return createProxy<T>(ep, pendingListeners, [], target) as any;\n}\n\nfunction throwIfProxyReleased(isReleased: boolean) {\n if (isReleased) {\n throw new Error(\"Proxy has been released and is not useable\");\n }\n}\n\nfunction releaseEndpoint(ep: Endpoint) {\n return requestResponseMessage(ep, new Map(), {\n type: MessageType.RELEASE,\n }).then(() => {\n closeEndPoint(ep);\n });\n}\n\ninterface FinalizationRegistry<T> {\n new (cb: (heldValue: T) => void): FinalizationRegistry<T>;\n register(\n weakItem: object,\n heldValue: T,\n unregisterToken?: object | undefined\n ): void;\n unregister(unregisterToken: object): void;\n}\ndeclare var FinalizationRegistry: FinalizationRegistry<Endpoint>;\n\nconst proxyCounter = new WeakMap<Endpoint, number>();\nconst proxyFinalizers =\n \"FinalizationRegistry\" in globalThis &&\n new FinalizationRegistry((ep: Endpoint) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\n\nfunction registerProxy(proxy: object, ep: Endpoint) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy, ep, proxy);\n }\n}\n\nfunction unregisterProxy(proxy: object) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy);\n }\n}\n\nfunction createProxy<T>(\n ep: Endpoint,\n pendingListeners: PendingListenersMap,\n path: (string | number | symbol)[] = [],\n target: object = function () {}\n): Remote<T> {\n let isProxyReleased = false;\n const proxy = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === \"then\") {\n if (path.length === 0) {\n return { then: () => proxy };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: MessageType.GET,\n path: path.map((p) => p.toString()),\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n // FIXME: ES6 Proxy Handler `set` methods are supposed to return a\n // boolean. To show good will, we return true asynchronously ¯\\_(ツ)_/¯\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(\n ep,\n pendingListeners,\n {\n type: MessageType.SET,\n path: [...path, prop].map((p) => p.toString()),\n value,\n },\n transferables\n ).then(fromWireValue) as any;\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if ((last as any) === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: MessageType.ENDPOINT,\n }).then(fromWireValue);\n }\n // We just pretend that `bind()` didn’t happen.\n if (last === \"bind\") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(\n ep,\n pendingListeners,\n {\n type: MessageType.APPLY,\n path: path.map((p) => p.toString()),\n argumentList,\n },\n transferables\n ).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(\n ep,\n pendingListeners,\n {\n type: MessageType.CONSTRUCT,\n path: path.map((p) => p.toString()),\n argumentList,\n },\n transferables\n ).then(fromWireValue);\n },\n });\n registerProxy(proxy, ep);\n return proxy as any;\n}\n\nfunction myFlat<T>(arr: (T | T[])[]): T[] {\n return Array.prototype.concat.apply([], arr);\n}\n\nfunction processArguments(argumentList: any[]): [WireValue[], Transferable[]] {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n}\n\nconst transferCache = new WeakMap<any, Transferable[]>();\nexport function transfer<T>(obj: T, transfers: Transferable[]): T {\n transferCache.set(obj, transfers);\n return obj;\n}\n\nexport function proxy<T extends {}>(obj: T): T & ProxyMarked {\n return Object.assign(obj, { [proxyMarker]: true }) as any;\n}\n\nexport function windowEndpoint(\n w: PostMessageWithOrigin,\n context: EventSource = globalThis,\n targetOrigin = \"*\"\n): Endpoint {\n return {\n postMessage: (msg: any, transferables: Transferable[]) =>\n w.postMessage(msg, targetOrigin, transferables),\n addEventListener: context.addEventListener.bind(context),\n removeEventListener: context.removeEventListener.bind(context),\n };\n}\n\nfunction toWireValue(value: any): [WireValue, Transferable[]] {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: WireValueType.HANDLER,\n name,\n value: serializedValue,\n },\n transferables,\n ];\n }\n }\n return [\n {\n type: WireValueType.RAW,\n value,\n },\n transferCache.get(value) || [],\n ];\n}\n\nfunction fromWireValue(value: WireValue): any {\n switch (value.type) {\n case WireValueType.HANDLER:\n return transferHandlers.get(value.name)!.deserialize(value.value);\n case WireValueType.RAW:\n return value.value;\n }\n}\n\nfunction requestResponseMessage(\n ep: Endpoint,\n pendingListeners: PendingListenersMap,\n msg: Message,\n transfers?: Transferable[]\n): Promise<WireValue> {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage({ id, ...msg }, transfers);\n});\n}\n\nfunction generateUUID(): string {\n return new Array(4)\n .fill(0)\n .map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16))\n .join(\"-\");\n}\n","// src/symbol.ts\nimport { wrap as comlink_wrap } from \"comlink\";\nimport {\n proxy,\n proxyMarker,\n finalizer,\n releaseProxy,\n createEndpoint\n} from \"comlink\";\nvar endpointSymbol = Symbol(\"getEndpoint\");\nvar wrap = (ep) => {\n const wrapped = comlink_wrap(ep);\n return new Proxy(wrapped, {\n get(target, prop, receiver) {\n if (prop === endpointSymbol) return ep;\n return Reflect.get(target, prop, receiver);\n }\n });\n};\nexport {\n createEndpoint,\n endpointSymbol,\n finalizer,\n proxy,\n proxyMarker,\n releaseProxy,\n wrap\n};\n","import { releaseProxy } from 'comlink'\nimport { endpointSymbol } from 'vite-plugin-comlink/symbol'\n\nexport interface ComlinkWorkerInstanceType {\n\treadonly [endpointSymbol]: Worker\n}\n\nexport function destroyWorker(worker: ComlinkWorkerInstanceType) {\n\t// https://github.com/mathe42/vite-plugin-comlink/pull/138\n\tworker[endpointSymbol].terminate()\n\n\tworker[releaseProxy]() // fly to GC land, little proxy!\n}\n"],"mappings":"IAiBaA,EAAc,OAAO,eAAe,EACpCC,EAAiB,OAAO,kBAAkB,EAC1CC,EAAe,OAAO,sBAAsB,EAC5CC,EAAY,OAAO,mBAAmB,EAE7CC,EAAc,OAAO,gBAAgB,EA+W3C,SAASC,EAAcC,EAAkB,CACvC,OAAOA,EAAS,YAAY,OAAS,aACvC,CAEA,SAASC,EAAcD,EAAkB,CACnCD,EAAcC,CAAQ,GAAGA,EAAS,MAAK,CAC7C,CA+BA,SAASE,EAAgBC,EAAY,CACnC,OAAOC,EAAuBD,EAAI,IAAI,IAAO,CAC3C,KAAyB,SAC1B,CAAA,EAAE,KAAK,IAAK,CACXE,EAAcF,CAAE,CAClB,CAAC,CACH,CAaA,IAAMG,EAAe,IAAI,QACnBC,EACJ,yBAA0B,YAC1B,IAAI,qBAAsBJ,GAAgB,CACxC,IAAMK,GAAYF,EAAa,IAAIH,CAAE,GAAK,GAAK,EAC/CG,EAAa,IAAIH,EAAIK,CAAQ,EACzBA,IAAa,GACfN,EAAgBC,CAAE,CAEtB,CAAC,EAyKH,SAASM,EACPC,EACAC,EACAC,EACAC,EAA0B,CAE1B,OAAO,IAAI,QAASC,GAAW,CAC7B,IAAMC,EAAKC,EAAY,EACvBL,EAAiB,IAAII,EAAID,CAAO,EAC5BJ,EAAG,OACLA,EAAG,MAAK,EAEVA,EAAG,YAAc,OAAA,OAAA,CAAA,GAAAK,CAAE,EAAKH,CAAG,EAAIC,CAAS,CAC5C,CAAC,CACD,CAEA,SAASG,GAAY,CACnB,OAAO,IAAI,MAAM,CAAC,EACf,KAAK,CAAC,EACN,IAAI,IAAM,KAAK,MAAM,KAAK,OAAM,EAAK,OAAO,gBAAgB,EAAE,SAAS,EAAE,CAAC,EAC1E,KAAK,GAAG,CACb,CC3nBA,IAAIC,EAAiB,OAAO,aAAa,ECFlC,SAASC,EAAcC,EAAmC,CAEhEA,EAAOC,CAAc,EAAE,UAAU,EAEjCD,EAAOE,CAAY,EAAE,CACtB","names":["proxyMarker","createEndpoint","releaseProxy","finalizer","throwMarker","isMessagePort","endpoint","closeEndPoint","releaseEndpoint","ep","requestResponseMessage","closeEndPoint","proxyCounter","proxyFinalizers","newCount","requestResponseMessage","ep","pendingListeners","msg","transfers","resolve","id","generateUUID","endpointSymbol","destroyWorker","worker","endpointSymbol","releaseProxy"]}
package/dist/worker.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { endpointSymbol } from 'vite-plugin-comlink/symbol';
2
- export interface ComlinkWorkerInstanceType {
3
- readonly [endpointSymbol]: Worker;
4
- }
5
- export declare function destroyWorker(worker: ComlinkWorkerInstanceType): void;
6
- //# sourceMappingURL=worker.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAE3D,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CACjC;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,yBAAyB,QAK9D"}
@@ -1,2 +0,0 @@
1
- import{a}from"./chunk-Z5VZCNIS.min.js";import"./chunk-MXMMU6NF.min.js";export{a as destroyWorker};
2
- //# sourceMappingURL=worker.min.js.map