dsh-plugin-zotero 0.2.0 → 0.4.0

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 (214) hide show
  1. package/README.md +39 -24
  2. package/client/client.js +28119 -2121
  3. package/client/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
  4. package/client/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
  5. package/client/pdfjs/cmaps/78-H.bcmap +0 -0
  6. package/client/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
  7. package/client/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
  8. package/client/pdfjs/cmaps/78-V.bcmap +0 -0
  9. package/client/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
  10. package/client/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
  11. package/client/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
  12. package/client/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
  13. package/client/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
  14. package/client/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
  15. package/client/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
  16. package/client/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
  17. package/client/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
  18. package/client/pdfjs/cmaps/Add-H.bcmap +0 -0
  19. package/client/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
  20. package/client/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
  21. package/client/pdfjs/cmaps/Add-V.bcmap +0 -0
  22. package/client/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
  23. package/client/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
  24. package/client/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
  25. package/client/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
  26. package/client/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
  27. package/client/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
  28. package/client/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
  29. package/client/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
  30. package/client/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
  31. package/client/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
  32. package/client/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
  33. package/client/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
  34. package/client/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
  35. package/client/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
  36. package/client/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
  37. package/client/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
  38. package/client/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
  39. package/client/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
  40. package/client/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
  41. package/client/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
  42. package/client/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
  43. package/client/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
  44. package/client/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
  45. package/client/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
  46. package/client/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
  47. package/client/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
  48. package/client/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
  49. package/client/pdfjs/cmaps/B5-H.bcmap +0 -0
  50. package/client/pdfjs/cmaps/B5-V.bcmap +0 -0
  51. package/client/pdfjs/cmaps/B5pc-H.bcmap +0 -0
  52. package/client/pdfjs/cmaps/B5pc-V.bcmap +0 -0
  53. package/client/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
  54. package/client/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
  55. package/client/pdfjs/cmaps/CNS1-H.bcmap +0 -0
  56. package/client/pdfjs/cmaps/CNS1-V.bcmap +0 -0
  57. package/client/pdfjs/cmaps/CNS2-H.bcmap +0 -0
  58. package/client/pdfjs/cmaps/CNS2-V.bcmap +3 -0
  59. package/client/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
  60. package/client/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
  61. package/client/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
  62. package/client/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
  63. package/client/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
  64. package/client/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
  65. package/client/pdfjs/cmaps/EUC-H.bcmap +0 -0
  66. package/client/pdfjs/cmaps/EUC-V.bcmap +0 -0
  67. package/client/pdfjs/cmaps/Ext-H.bcmap +0 -0
  68. package/client/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
  69. package/client/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
  70. package/client/pdfjs/cmaps/Ext-V.bcmap +0 -0
  71. package/client/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
  72. package/client/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
  73. package/client/pdfjs/cmaps/GB-H.bcmap +4 -0
  74. package/client/pdfjs/cmaps/GB-V.bcmap +0 -0
  75. package/client/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
  76. package/client/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
  77. package/client/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
  78. package/client/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
  79. package/client/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
  80. package/client/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
  81. package/client/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
  82. package/client/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
  83. package/client/pdfjs/cmaps/GBT-H.bcmap +0 -0
  84. package/client/pdfjs/cmaps/GBT-V.bcmap +0 -0
  85. package/client/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
  86. package/client/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
  87. package/client/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
  88. package/client/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
  89. package/client/pdfjs/cmaps/H.bcmap +0 -0
  90. package/client/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
  91. package/client/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
  92. package/client/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
  93. package/client/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
  94. package/client/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
  95. package/client/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
  96. package/client/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
  97. package/client/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
  98. package/client/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
  99. package/client/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
  100. package/client/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
  101. package/client/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
  102. package/client/pdfjs/cmaps/Hankaku.bcmap +0 -0
  103. package/client/pdfjs/cmaps/Hiragana.bcmap +0 -0
  104. package/client/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
  105. package/client/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
  106. package/client/pdfjs/cmaps/KSC-H.bcmap +0 -0
  107. package/client/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
  108. package/client/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
  109. package/client/pdfjs/cmaps/KSC-V.bcmap +0 -0
  110. package/client/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
  111. package/client/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
  112. package/client/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
  113. package/client/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
  114. package/client/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
  115. package/client/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
  116. package/client/pdfjs/cmaps/Katakana.bcmap +0 -0
  117. package/client/pdfjs/cmaps/LICENSE +36 -0
  118. package/client/pdfjs/cmaps/NWP-H.bcmap +0 -0
  119. package/client/pdfjs/cmaps/NWP-V.bcmap +0 -0
  120. package/client/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
  121. package/client/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
  122. package/client/pdfjs/cmaps/Roman.bcmap +0 -0
  123. package/client/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
  124. package/client/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
  125. package/client/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
  126. package/client/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
  127. package/client/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
  128. package/client/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
  129. package/client/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
  130. package/client/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
  131. package/client/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
  132. package/client/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
  133. package/client/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
  134. package/client/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
  135. package/client/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
  136. package/client/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
  137. package/client/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
  138. package/client/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
  139. package/client/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
  140. package/client/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
  141. package/client/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
  142. package/client/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
  143. package/client/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
  144. package/client/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
  145. package/client/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
  146. package/client/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
  147. package/client/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
  148. package/client/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
  149. package/client/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
  150. package/client/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
  151. package/client/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
  152. package/client/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
  153. package/client/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
  154. package/client/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
  155. package/client/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
  156. package/client/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
  157. package/client/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
  158. package/client/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
  159. package/client/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
  160. package/client/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
  161. package/client/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
  162. package/client/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
  163. package/client/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
  164. package/client/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
  165. package/client/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
  166. package/client/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
  167. package/client/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
  168. package/client/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
  169. package/client/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
  170. package/client/pdfjs/cmaps/V.bcmap +0 -0
  171. package/client/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
  172. package/client/pdfjs/pdf.worker.min.mjs +29 -0
  173. package/client/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
  174. package/client/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
  175. package/client/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
  176. package/client/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
  177. package/client/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
  178. package/client/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
  179. package/client/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
  180. package/client/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
  181. package/client/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
  182. package/client/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
  183. package/client/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
  184. package/client/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
  185. package/client/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
  186. package/client/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
  187. package/client/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
  188. package/client/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
  189. package/client/pdfjs/wasm/LICENSE_JBIG2 +196 -0
  190. package/client/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
  191. package/client/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  192. package/client/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  193. package/client/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
  194. package/client/pdfjs/wasm/LICENSE_QCMS +21 -0
  195. package/client/pdfjs/wasm/jbig2.wasm +0 -0
  196. package/client/pdfjs/wasm/jbig2_nowasm_fallback.js +15 -0
  197. package/client/pdfjs/wasm/openjpeg.wasm +0 -0
  198. package/client/pdfjs/wasm/openjpeg_nowasm_fallback.js +17 -0
  199. package/client/pdfjs/wasm/qcms_bg.wasm +0 -0
  200. package/client/pdfjs/wasm/quickjs-eval.js +16 -0
  201. package/client/pdfjs/wasm/quickjs-eval.wasm +0 -0
  202. package/lib/host/router.d.ts +1 -0
  203. package/lib/host/router.js +194 -5
  204. package/lib/host/static.d.ts +9 -0
  205. package/lib/host/static.js +100 -0
  206. package/lib/index.js +7 -1
  207. package/lib/zotero/annotations.d.ts +6 -1
  208. package/lib/zotero/annotations.js +6 -1
  209. package/lib/zotero/client.d.ts +51 -2
  210. package/lib/zotero/client.js +239 -15
  211. package/lib/zotero/config.d.ts +4 -0
  212. package/lib/zotero/config.js +4 -0
  213. package/lib/zotero/types.d.ts +34 -2
  214. package/package.json +3 -2
Binary file
@@ -0,0 +1,16 @@
1
+ /* THIS FILE IS GENERATED - DO NOT EDIT */
2
+ async function QuickJS(moduleArg={}){var moduleRtn;var e=moduleArg,aa=import.meta.url,h="",m;try{h=(new URL(".",aa)).href}catch{}m=async a=>{a=await fetch(a,{credentials:"same-origin"});if(a.ok)return a.arrayBuffer();throw Error(a.status+" : "+a.url);};var q=console.error.bind(console),r,t=!1,u,v,w,x=!1;function y(){var a=z.buffer;A=new Int8Array(a);new Int16Array(a);B=new Uint8Array(a);new Uint16Array(a);C=new Int32Array(a);D=new Uint32Array(a);new Float32Array(a);new Float64Array(a);new BigInt64Array(a);new BigUint64Array(a)}
3
+ function E(a){e.onAbort?.(a);a=`Aborted(${a})`;q(a);t=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");w?.(a);throw a;}var F;async function ba(a){if(!r)try{var b=await m(a);return new Uint8Array(b)}catch{}if(a==F&&r)a=new Uint8Array(r);else throw"both async and sync fetching of the wasm failed";return a}async function ca(a,b){try{var c=await ba(a);return await WebAssembly.instantiate(c,b)}catch(d){q(`failed to asynchronously prepare wasm: ${d}`),E(d)}}
4
+ async function da(a){var b=F;if(!r)try{var c=fetch(b,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(c,a)}catch(d){q(`wasm streaming compile failed: ${d}`),q("falling back to ArrayBuffer instantiation")}return ca(b,a)}class G{name="ExitStatus";constructor(a){this.message=`Program terminated with exit(${a})`;this.status=a}}
5
+ var C,A,D,B,H=a=>{for(;a.length>0;)a.shift()(e)},I=[],J=[],ea=()=>{var a=e.preRun.shift();J.push(a)},K=!0,L=0,fa=[0,31,60,91,121,152,182,213,244,274,305,335],ha=[0,31,59,90,120,151,181,212,243,273,304,334],M={},N=a=>{if(!(a instanceof G||a=="unwind"))throw a;},O=a=>{u=a;K||L>0||(e.onExit?.(a),t=!0);throw new G(a);},ia=a=>{if(!t)try{a()}catch(b){N(b)}finally{if(!(K||L>0))try{u=a=u,O(a)}catch(b){N(b)}}},P=(a,b,c)=>{var d=B;if(c>0){c=b+c-1;for(var g=0;g<a.length;++g){var f=a.codePointAt(g);if(f<=127){if(b>=
6
+ c)break;d[b++]=f}else if(f<=2047){if(b+1>=c)break;d[b++]=192|f>>6;d[b++]=128|f&63}else if(f<=65535){if(b+2>=c)break;d[b++]=224|f>>12;d[b++]=128|f>>6&63;d[b++]=128|f&63}else{if(b+3>=c)break;d[b++]=240|f>>18;d[b++]=128|f>>12&63;d[b++]=128|f>>6&63;d[b++]=128|f&63;g++}}d[b]=0}},ja=new TextDecoder,Q=a=>{if(a){for(var b=a,c=B,d=b+void 0;c[b]&&!(b>=d);)++b;a=ja.decode(B.subarray(a,b))}else a="";return a},R=a=>{for(var b=0,c=0;c<a.length;++c){var d=a.charCodeAt(c);d<=127?b++:d<=2047?b+=2:d>=55296&&d<=57343?
7
+ (b+=4,++c):b+=3}return b},T=a=>{var b=R(a)+1,c=S(b);c&&P(a,c,b);return c};function U(){}var la=(a,b,c,d)=>{var g={string:k=>{var n=0;if(k!==null&&k!==void 0&&k!==0){n=R(k)+1;var X=V(n);P(k,X,n);n=X}return n},array:k=>{var n=V(k.length);A.set(k,n);return n}};a=e["_"+a];var f=[],p=0;if(d)for(var l=0;l<d.length;l++){var Y=g[c[l]];Y?(p===0&&(p=W()),f[l]=Y(d[l])):f[l]=d[l]}c=a(...f);return c=function(k){p!==0&&ka(p);return b==="string"?Q(k):b==="boolean"?!!k:k}(c)};
8
+ U=(a,b,c)=>{a=Q(a);b=b!==null?JSON.parse(Q(b)):[];try{let d=e.externalCall(a,b);return d?T(d):null}catch(d){return e.HEAPU8[c]=1,T(d.message)}};e.noExitRuntime&&(K=e.noExitRuntime);e.printErr&&(q=e.printErr);e.wasmBinary&&(r=e.wasmBinary);if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.shift()();e.ccall=la;e.cwrap=(a,b,c,d)=>{var g=!c||c.every(f=>f==="number"||f==="boolean");return b!=="string"&&g&&!d?e["_"+a]:(...f)=>la(a,b,c,f,d)};
9
+ e.stringToNewUTF8=T;
10
+ var S,ma,ka,V,W,z,na={e:()=>E(""),a:()=>{K=!1;L=0},b:function(a,b){a=a<-9007199254740992||a>9007199254740992?NaN:Number(a);a=new Date(a*1E3);C[b>>2]=a.getSeconds();C[b+4>>2]=a.getMinutes();C[b+8>>2]=a.getHours();C[b+12>>2]=a.getDate();C[b+16>>2]=a.getMonth();C[b+20>>2]=a.getFullYear()-1900;C[b+24>>2]=a.getDay();var c=a.getFullYear();C[b+28>>2]=(c%4!==0||c%100===0&&c%400!==0?ha:fa)[a.getMonth()]+a.getDate()-1|0;C[b+36>>2]=-(a.getTimezoneOffset()*60);c=(new Date(a.getFullYear(),6,1)).getTimezoneOffset();
11
+ var d=(new Date(a.getFullYear(),0,1)).getTimezoneOffset();C[b+32>>2]=(c!=d&&a.getTimezoneOffset()==Math.min(d,c))|0},i:(a,b)=>{M[a]&&(clearTimeout(M[a].id),delete M[a]);if(!b)return 0;var c=setTimeout(()=>{delete M[a];ia(()=>ma(a,performance.now()))},b);M[a]={id:c,A:b};return 0},c:(a,b,c,d)=>{var g=(new Date).getFullYear(),f=(new Date(g,0,1)).getTimezoneOffset();g=(new Date(g,6,1)).getTimezoneOffset();D[a>>2]=Math.max(f,g)*60;C[b>>2]=Number(f!=g);b=p=>{var l=Math.abs(p);return`UTC${p>=0?"-":"+"}${String(Math.floor(l/
12
+ 60)).padStart(2,"0")}${String(l%60).padStart(2,"0")}`};a=b(f);b=b(g);g<f?(P(a,c,17),P(b,d,17)):(P(a,d,17),P(b,c,17))},g:U,f:function(a,b){a=Q(a);try{var c=window.JSON.parse(a)}catch(d){c=a}b!==0?window.alert(a):window.console.log("DUMP",c)},d:()=>Date.now(),j:a=>{var b=B.length;a>>>=0;if(a>2147483648)return!1;for(var c=1;c<=4;c*=2){var d=b*(1+.2/c);d=Math.min(d,a+100663296);a:{d=(Math.min(2147483648,Math.ceil(Math.max(a,d)/65536)*65536)-z.buffer.byteLength+65535)/65536|0;try{z.grow(d);y();var g=1;
13
+ break a}catch(f){}g=void 0}if(g)return!0}return!1},m:function(a){a=Q(a);window.console.log(a)},h:function(a){a=Q(a);return Date.parse(a)},l:function(a,b,c,d){a=Q(a);b=Q(b);c=Q(c);c=`Quickjs -- ${a}: ${b}\n${c}`;d!==0?window.alert(c):window.console.error(c)},k:O},Z;
14
+ Z=await (async function(){function a(c){c=Z=c.exports;e._evalInSandbox=c.p;e._nukeSandbox=c.q;e._init=c.r;e._commFun=c.s;e._dumpMemoryUse=c.t;S=c.u;e._free=c.v;ma=c.w;ka=c.x;V=c.y;W=c.z;z=c.n;y();return Z}var b={a:na};if(e.instantiateWasm)return new Promise(c=>{e.instantiateWasm(b,(d,g)=>{c(a(d,g))})});F??=e.locateFile?e.locateFile?e.locateFile("quickjs-eval.wasm",h):h+"quickjs-eval.wasm":(new URL("quickjs-eval.wasm",import.meta.url)).href;return function(c){return a(c.instance)}(await da(b))}());
15
+ (function(){function a(){e.calledRun=!0;if(!t){x=!0;Z.o();v?.(e);e.onRuntimeInitialized?.();if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;){var b=e.postRun.shift();I.push(b)}H(I)}}if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)ea();H(J);e.setStatus?(e.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>e.setStatus(""),1);a()},1)):a()})();x?moduleRtn=e:moduleRtn=new Promise((a,b)=>{v=a;w=b});
16
+ ;return moduleRtn}export default QuickJS;
@@ -23,5 +23,6 @@ export interface HandlerDeps {
23
23
  */
24
24
  syncTools?: () => Promise<zotero.McpToolInfo[]>;
25
25
  }
26
+ export declare function isTrusted(req: IncomingMessage): boolean;
26
27
  /** 构造挂在 `webServer` 上的前缀路由处理器。 */
27
28
  export declare function createHandler(deps?: HandlerDeps): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
@@ -5,6 +5,8 @@
5
5
  * 信任栅栏:拒绝 `sec-fetch-site: cross-site`,且 Host 头必须是回环地址
6
6
  * (防御 DNS rebinding)。只读端点,无需会话 cookie。
7
7
  */
8
+ import { spawn } from 'node:child_process';
9
+ import { createReadStream } from 'node:fs';
8
10
  import * as zotero from '../zotero/client.js';
9
11
  import { ZoteroError } from '../zotero/client.js';
10
12
  import { DEFAULT_LIMIT, getSettings, ROUTE_PREFIX } from '../zotero/config.js';
@@ -16,7 +18,7 @@ function isLoopbackHost(hostHeader) {
16
18
  const host = hostHeader.replace(/:\d+$/u, '').toLowerCase();
17
19
  return host === 'localhost' || host === '127.0.0.1' || host === '[::1]' || host === '::1';
18
20
  }
19
- function isTrusted(req) {
21
+ export function isTrusted(req) {
20
22
  const site = req.headers['sec-fetch-site'];
21
23
  if (typeof site === 'string' && site.toLowerCase() === 'cross-site')
22
24
  return false;
@@ -99,18 +101,43 @@ async function handleItems(res, params) {
99
101
  }
100
102
  const collectionKey = params.get('collectionKey') ?? undefined;
101
103
  const q = params.get('q') ?? undefined;
104
+ const tags = params.getAll('tag').map((tag) => tag.trim()).filter((tag) => tag !== '');
105
+ const tagMode = params.get('tagMode') === 'any' ? 'any' : 'all';
102
106
  const limit = clampLimit(params.get('limit'));
103
107
  const offset = parseOffset(params.get('offset'));
104
108
  const result = await zotero.listItems({
105
109
  scope: scopeParam === null ? undefined : scopeParam,
106
110
  collectionKey,
107
111
  q,
112
+ tags,
113
+ tagMode,
108
114
  limit,
109
115
  offset,
110
116
  });
111
117
  const data = { total: result.total, items: result.items };
112
118
  ok(res, data);
113
119
  }
120
+ async function handleTags(res) {
121
+ const data = await zotero.listTags();
122
+ ok(res, data);
123
+ }
124
+ /** 当前范围内的标签用量(供标签面板列出范围标签)。 */
125
+ async function handleTagUsage(res, params) {
126
+ const scopeParam = params.get('scope');
127
+ if (scopeParam !== null && !isScope(scopeParam)) {
128
+ fail(res, 400, 'bad_request', `未知 scope ${scopeParam}`);
129
+ return;
130
+ }
131
+ const collectionKeys = params.getAll('collectionKey')
132
+ .map((key) => key.trim())
133
+ .filter((key) => key !== '');
134
+ const data = await zotero.listTagUsage({
135
+ scope: scopeParam === null ? undefined : scopeParam,
136
+ collectionKeys: collectionKeys.length === 0 ? undefined : collectionKeys,
137
+ q: params.get('q') ?? undefined,
138
+ });
139
+ ok(res, data);
140
+ }
114
141
  async function handleItem(res, params) {
115
142
  const key = params.get('key');
116
143
  if (!key) {
@@ -131,13 +158,157 @@ async function handleCollectionBib(res, params) {
131
158
  const data = await zotero.getCollectionBib(key, style);
132
159
  ok(res, data);
133
160
  }
161
+ /** Zotero key:8 位,字母表排除了易混淆的 0 / 1 / O。 */
162
+ const KEY_PATTERN = /^[23456789ABCDEFGHIJKLMNPQRSTUVWXYZ]{8}$/u;
163
+ /** 允许直接流式读取的附件类型;后续加 Word 等格式只需在此追加。 */
164
+ const SERVABLE_TYPES = new Set(['application/pdf']);
165
+ /** 只支持单段 Range;`null` 表示无 Range,`'invalid'` 表示应回 416。 */
166
+ function parseRange(header, size) {
167
+ if (header === undefined || header.trim() === '')
168
+ return null;
169
+ const match = /^bytes=(\d*)-(\d*)$/u.exec(header.trim());
170
+ if (match === null)
171
+ return 'invalid';
172
+ const rawStart = match[1] ?? '';
173
+ const rawEnd = match[2] ?? '';
174
+ if (rawStart === '' && rawEnd === '')
175
+ return 'invalid';
176
+ let start;
177
+ let end;
178
+ if (rawStart === '') {
179
+ const suffix = Number.parseInt(rawEnd, 10);
180
+ if (!Number.isFinite(suffix) || suffix <= 0)
181
+ return 'invalid';
182
+ start = Math.max(0, size - suffix);
183
+ end = size - 1;
184
+ }
185
+ else {
186
+ start = Number.parseInt(rawStart, 10);
187
+ end = rawEnd === '' ? size - 1 : Number.parseInt(rawEnd, 10);
188
+ }
189
+ if (!Number.isFinite(start) || !Number.isFinite(end) || start >= size || start > end)
190
+ return 'invalid';
191
+ return { start, end: Math.min(end, size - 1) };
192
+ }
193
+ /** RFC 5987 的 `filename*` 编码。 */
194
+ function encodeFilename(filename) {
195
+ return encodeURIComponent(filename).replace(/['()*]/gu, (char) => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
196
+ }
197
+ async function handleFile(req, res, params) {
198
+ const key = params.get('key') ?? '';
199
+ if (!KEY_PATTERN.test(key)) {
200
+ fail(res, 400, 'bad_request', '附件 key 格式不合法');
201
+ return;
202
+ }
203
+ const file = await zotero.getAttachmentFile(key);
204
+ const contentType = file.contentType.split(';')[0].trim().toLowerCase();
205
+ if (!SERVABLE_TYPES.has(contentType)) {
206
+ fail(res, 415, 'bad_request', `暂不支持预览 ${file.contentType || '该附件类型'}`);
207
+ return;
208
+ }
209
+ const range = parseRange(req.headers.range, file.size);
210
+ if (range === 'invalid') {
211
+ res.writeHead(416, {
212
+ 'content-range': `bytes */${file.size}`,
213
+ 'cache-control': 'no-store',
214
+ });
215
+ res.end();
216
+ return;
217
+ }
218
+ const headers = {
219
+ 'content-type': contentType,
220
+ 'content-disposition': `inline; filename*=UTF-8''${encodeFilename(file.filename)}`,
221
+ 'accept-ranges': 'bytes',
222
+ 'cache-control': 'no-store',
223
+ 'x-content-type-options': 'nosniff',
224
+ };
225
+ let stream;
226
+ if (range === null) {
227
+ headers['content-length'] = file.size;
228
+ res.writeHead(200, headers);
229
+ stream = createReadStream(file.path);
230
+ }
231
+ else {
232
+ headers['content-range'] = `bytes ${range.start}-${range.end}/${file.size}`;
233
+ headers['content-length'] = range.end - range.start + 1;
234
+ res.writeHead(206, headers);
235
+ stream = createReadStream(file.path, { start: range.start, end: range.end });
236
+ }
237
+ stream.on('error', () => res.destroy());
238
+ stream.pipe(res);
239
+ }
240
+ /** 用系统默认处理器打开 `zotero://` URL;参数数组传递,不经过 shell。 */
241
+ function openExternal(url) {
242
+ const command = process.platform === 'darwin'
243
+ ? 'open'
244
+ : process.platform === 'win32'
245
+ ? 'rundll32'
246
+ : 'xdg-open';
247
+ const args = process.platform === 'win32'
248
+ ? ['url.dll,FileProtocolHandler', url]
249
+ : [url];
250
+ return new Promise((resolvePromise, reject) => {
251
+ const child = spawn(command, args, { detached: true, stdio: 'ignore' });
252
+ child.once('spawn', () => {
253
+ child.unref();
254
+ resolvePromise();
255
+ });
256
+ child.once('error', (error) => {
257
+ reject(new ZoteroError('internal_error', `无法打开 Zotero:${error.message}`));
258
+ });
259
+ });
260
+ }
261
+ /** 读取小请求体;超过上限直接拒绝,避免被大 body 拖住。 */
262
+ async function readBody(req, limit) {
263
+ const chunks = [];
264
+ let size = 0;
265
+ for await (const chunk of req) {
266
+ const buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
267
+ size += buffer.length;
268
+ if (size > limit)
269
+ throw new ZoteroError('bad_request', '请求体过大');
270
+ chunks.push(buffer);
271
+ }
272
+ return Buffer.concat(chunks).toString('utf8');
273
+ }
274
+ async function handleOpenInZotero(req, res) {
275
+ let input;
276
+ try {
277
+ input = JSON.parse(await readBody(req, 4096));
278
+ }
279
+ catch (error) {
280
+ if (error instanceof ZoteroError)
281
+ throw error;
282
+ fail(res, 400, 'bad_request', '请求体不是合法 JSON');
283
+ return;
284
+ }
285
+ const record = (typeof input === 'object' && input !== null ? input : {});
286
+ const key = typeof record.key === 'string' ? record.key : '';
287
+ const kind = record.kind === 'item' || record.kind === 'attachment' ? record.kind : null;
288
+ if (!KEY_PATTERN.test(key) || kind === null) {
289
+ fail(res, 400, 'bad_request', 'key 或 kind 不合法');
290
+ return;
291
+ }
292
+ let url = `zotero://select/library/items/${key}`;
293
+ if (kind === 'attachment') {
294
+ if (record.page !== undefined
295
+ && (typeof record.page !== 'number'
296
+ || !Number.isInteger(record.page)
297
+ || record.page < 1
298
+ || record.page > 10000)) {
299
+ fail(res, 400, 'bad_request', 'page 必须是 1–10000 的整数');
300
+ return;
301
+ }
302
+ url = `zotero://open-pdf/library/items/${key}`;
303
+ if (record.page !== undefined)
304
+ url += `?page=${record.page}`;
305
+ }
306
+ await openExternal(url);
307
+ ok(res, { opened: true });
308
+ }
134
309
  /** 构造挂在 `webServer` 上的前缀路由处理器。 */
135
310
  export function createHandler(deps = {}) {
136
311
  return async (req, res) => {
137
- if (req.method !== 'GET') {
138
- fail(res, 405, 'bad_request', `仅支持 GET,收到 ${req.method ?? '未知'}`);
139
- return;
140
- }
141
312
  if (!isTrusted(req)) {
142
313
  fail(res, 403, 'bad_request', '拒绝非回环来源的请求');
143
314
  return;
@@ -148,6 +319,12 @@ export function createHandler(deps = {}) {
148
319
  return;
149
320
  }
150
321
  const action = url.pathname.slice(ROUTE_PREFIX.length);
322
+ const method = req.method ?? 'GET';
323
+ const allowedMethod = action === 'open-in-zotero' ? 'POST' : 'GET';
324
+ if (method !== allowedMethod) {
325
+ fail(res, 405, 'bad_request', `该端点仅支持 ${allowedMethod},收到 ${method}`);
326
+ return;
327
+ }
151
328
  try {
152
329
  switch (action) {
153
330
  case 'health':
@@ -159,12 +336,24 @@ export function createHandler(deps = {}) {
159
336
  case 'items':
160
337
  await handleItems(res, url.searchParams);
161
338
  return;
339
+ case 'tags':
340
+ await handleTags(res);
341
+ return;
342
+ case 'tag-usage':
343
+ await handleTagUsage(res, url.searchParams);
344
+ return;
162
345
  case 'item':
163
346
  await handleItem(res, url.searchParams);
164
347
  return;
165
348
  case 'collection-bib':
166
349
  await handleCollectionBib(res, url.searchParams);
167
350
  return;
351
+ case 'file':
352
+ await handleFile(req, res, url.searchParams);
353
+ return;
354
+ case 'open-in-zotero':
355
+ await handleOpenInZotero(req, res);
356
+ return;
168
357
  case 'mcp-tools':
169
358
  await handleMcpTools(res, deps);
170
359
  return;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * PDF.js 静态资产:`GET /dsh-zotero/static/*`。
3
+ *
4
+ * 只服务 `client/pdfjs/` 下的白名单内容(Worker、cmaps、标准字体、wasm),
5
+ * 不做通用静态服务器。路径在 `path.resolve` 后必须仍落在资产根内,
6
+ * 因此 `..`、绝对路径、跨平台分隔符都穿不出去。
7
+ */
8
+ import type { IncomingMessage, ServerResponse } from 'node:http';
9
+ export declare function createStaticHandler(): (req: IncomingMessage, res: ServerResponse) => Promise<void>;
@@ -0,0 +1,100 @@
1
+ /**
2
+ * PDF.js 静态资产:`GET /dsh-zotero/static/*`。
3
+ *
4
+ * 只服务 `client/pdfjs/` 下的白名单内容(Worker、cmaps、标准字体、wasm),
5
+ * 不做通用静态服务器。路径在 `path.resolve` 后必须仍落在资产根内,
6
+ * 因此 `..`、绝对路径、跨平台分隔符都穿不出去。
7
+ */
8
+ import { createReadStream } from 'node:fs';
9
+ import { stat } from 'node:fs/promises';
10
+ import { extname, resolve, sep } from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { STATIC_ROUTE_PREFIX } from '../zotero/config.js';
13
+ import { isTrusted } from './router.js';
14
+ /** `lib/host/static.js` → 包根 `client/pdfjs/`。 */
15
+ const ASSET_ROOT = fileURLToPath(new URL('../../client/pdfjs/', import.meta.url));
16
+ /** 白名单:根下单个 Worker 文件 + 三个资产目录。 */
17
+ const ALLOWED_DIRECTORIES = ['cmaps/', 'standard_fonts/', 'wasm/'];
18
+ const ALLOWED_FILES = new Set(['pdf.worker.min.mjs', 'pdf.worker.mjs']);
19
+ const MIME = {
20
+ '.mjs': 'text/javascript; charset=utf-8',
21
+ '.js': 'text/javascript; charset=utf-8',
22
+ '.wasm': 'application/wasm',
23
+ '.bcmap': 'application/octet-stream',
24
+ '.pfb': 'application/x-font-type1',
25
+ '.ttf': 'font/ttf',
26
+ '.otf': 'font/otf',
27
+ '.woff': 'font/woff',
28
+ '.woff2': 'font/woff2',
29
+ '.ttc': 'font/collection',
30
+ '.icc': 'application/vnd.iccprofile',
31
+ };
32
+ function fail(res, status, message) {
33
+ res.writeHead(status, { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' });
34
+ res.end(message);
35
+ }
36
+ /** 校验并还原相对路径;非法返回 null。 */
37
+ function relativePath(pathname) {
38
+ if (!pathname.startsWith(STATIC_ROUTE_PREFIX))
39
+ return null;
40
+ let relative;
41
+ try {
42
+ relative = decodeURIComponent(pathname.slice(STATIC_ROUTE_PREFIX.length));
43
+ }
44
+ catch {
45
+ return null;
46
+ }
47
+ if (relative === '' || relative.includes('\\') || relative.includes('\0'))
48
+ return null;
49
+ const segments = relative.split('/');
50
+ if (segments.some((segment) => segment === '' || segment === '.' || segment === '..'))
51
+ return null;
52
+ if (!ALLOWED_FILES.has(relative) && !ALLOWED_DIRECTORIES.some((prefix) => relative.startsWith(prefix))) {
53
+ return null;
54
+ }
55
+ return relative;
56
+ }
57
+ export function createStaticHandler() {
58
+ return async (req, res) => {
59
+ if (req.method !== 'GET') {
60
+ fail(res, 405, '仅支持 GET');
61
+ return;
62
+ }
63
+ if (!isTrusted(req)) {
64
+ fail(res, 403, '拒绝非回环来源的请求');
65
+ return;
66
+ }
67
+ const url = new URL(req.url ?? '/', `http://${req.headers.host ?? '127.0.0.1'}`);
68
+ const relative = relativePath(url.pathname);
69
+ if (relative === null) {
70
+ fail(res, 404, '未知静态资源');
71
+ return;
72
+ }
73
+ const full = resolve(ASSET_ROOT, relative);
74
+ if (!full.startsWith(ASSET_ROOT.endsWith(sep) ? ASSET_ROOT : ASSET_ROOT + sep)) {
75
+ fail(res, 404, '未知静态资源');
76
+ return;
77
+ }
78
+ let stats;
79
+ try {
80
+ stats = await stat(full);
81
+ }
82
+ catch {
83
+ fail(res, 404, '静态资源不存在');
84
+ return;
85
+ }
86
+ if (!stats.isFile()) {
87
+ fail(res, 404, '静态资源不存在');
88
+ return;
89
+ }
90
+ res.writeHead(200, {
91
+ 'content-type': MIME[extname(full).toLowerCase()] ?? 'application/octet-stream',
92
+ 'content-length': stats.size,
93
+ 'cache-control': 'public, max-age=86400',
94
+ 'x-content-type-options': 'nosniff',
95
+ });
96
+ const stream = createReadStream(full);
97
+ stream.on('error', () => res.destroy());
98
+ stream.pipe(res);
99
+ };
100
+ }
package/lib/index.js CHANGED
@@ -16,8 +16,9 @@
16
16
  import Schema from '@deepseek-ai/schemastery';
17
17
  import { McpToolBridge } from './host/mcp-bridge.js';
18
18
  import { createHandler } from './host/router.js';
19
+ import { createStaticHandler } from './host/static.js';
19
20
  import { listMcpTools } from './zotero/client.js';
20
- import { DEFAULT_LIMIT, FULLTEXT_MAX_BYTES, MCP_PROBE_TIMEOUT_MS, MCP_URL, REQUEST_TIMEOUT_MS, ROUTE_MATCH, setSettingsReader, ZOTERO_BASE, } from './zotero/config.js';
21
+ import { DEFAULT_LIMIT, FULLTEXT_MAX_BYTES, MCP_PROBE_TIMEOUT_MS, MCP_URL, REQUEST_TIMEOUT_MS, ROUTE_MATCH, setSettingsReader, STATIC_ROUTE_MATCH, ZOTERO_BASE, } from './zotero/config.js';
21
22
  export const name = 'dsh-plugin-zotero';
22
23
  /**
23
24
  * 插件配置 schema(逐字段 volatile)。
@@ -72,5 +73,10 @@ export function apply(ctx, config) {
72
73
  syncTools: async () => (bridge ? bridge.sync() : listMcpTools()),
73
74
  });
74
75
  hostCtx.effect(() => webServer.register({ kind: 'prefix', path: ROUTE_MATCH, handler }), 'dsh-plugin-zotero: http routes');
76
+ hostCtx.effect(() => webServer.register({
77
+ kind: 'prefix',
78
+ path: STATIC_ROUTE_MATCH,
79
+ handler: createStaticHandler(),
80
+ }), 'dsh-plugin-zotero: static assets');
75
81
  });
76
82
  }
@@ -6,7 +6,7 @@
6
6
  * 通过 map 把折叠下标还原成原文下标。
7
7
  */
8
8
  import type { ZoteroFulltext } from './types.js';
9
- /** Host 侧归一化后的标注(已过滤为非高亮/划线之外的条目)。 */
9
+ /** Host 侧归一化后的标注。 */
10
10
  export interface RawAnnotation {
11
11
  key: string;
12
12
  attachmentKey: string;
@@ -17,6 +17,11 @@ export interface RawAnnotation {
17
17
  pageLabel: string;
18
18
  /** 零填充的 `annotationSortIndex`,可按字典序比较。 */
19
19
  sortIndex: string;
20
+ /** PDF 页位置;缺失或墨迹标注为 null。 */
21
+ position: {
22
+ pageIndex: number;
23
+ rects: [number, number, number, number][];
24
+ } | null;
20
25
  }
21
26
  /**
22
27
  * 为每条标注计算它在 `fulltext.content` 里的区间。
@@ -5,6 +5,8 @@
5
5
  * 这里做「去空白 + 全角 ASCII 转半角」的 1:1 折叠,再在折叠串上查找,
6
6
  * 通过 map 把折叠下标还原成原文下标。
7
7
  */
8
+ /** 可以锚定到全文纯文本的标注类型(其余类型只用于 PDF 坐标叠加)。 */
9
+ const TEXT_TYPES = new Set(['highlight', 'underline']);
8
10
  /** 空白与软连字符:PDF 抽取会插入,匹配时忽略。 */
9
11
  const IGNORED = /[\s\u00ad]/u;
10
12
  /** 单条标注最多收集多少个候选位置(防止单字标注把内存打满)。 */
@@ -66,7 +68,10 @@ export function anchorAnnotations(annotations, fulltext) {
66
68
  const attachmentKey = fulltext?.attachmentKey ?? '';
67
69
  let prevEnd = 0;
68
70
  return annotations.map((annotation) => {
69
- if (folded === null || annotation.attachmentKey !== attachmentKey || annotation.text === '') {
71
+ if (folded === null
72
+ || !TEXT_TYPES.has(annotation.type)
73
+ || annotation.attachmentKey !== attachmentKey
74
+ || annotation.text === '') {
70
75
  return { ...annotation, range: null };
71
76
  }
72
77
  const query = fold(annotation.text).text;
@@ -13,7 +13,7 @@
13
13
  * - `?include=bib` 会让响应**丢掉 `data`**,因此条目详情与 bib 必须分两次请求。
14
14
  */
15
15
  import { type RawAnnotation } from './annotations.js';
16
- import type { ApiErrorCode, ZoteroCollection, ZoteroFulltext, ZoteroHealth, ZoteroItemDetail, ZoteroItemScope, ZoteroItemSummary } from './types.js';
16
+ import type { ApiErrorCode, ZoteroAttachmentFile, ZoteroCollection, ZoteroFulltext, ZoteroHealth, ZoteroItemDetail, ZoteroItemScope, ZoteroItemSummary, ZoteroTags } from './types.js';
17
17
  /** 归一化后的 Zotero 访问错误。 */
18
18
  export declare class ZoteroError extends Error {
19
19
  readonly code: ApiErrorCode;
@@ -27,6 +27,13 @@ interface RawCreator {
27
27
  }
28
28
  interface RawTag {
29
29
  tag?: string;
30
+ /** 条目 `data.tags` 上的类型(0 自动标签,1 手动标签);`/tags` 端点在 `meta.type`。 */
31
+ type?: number;
32
+ meta?: {
33
+ /** 0 自动标签,1 手动标签。 */
34
+ type?: number;
35
+ numItems?: number;
36
+ };
30
37
  }
31
38
  interface RawItemData {
32
39
  itemType?: string;
@@ -53,6 +60,8 @@ interface RawItemData {
53
60
  annotationColor?: string;
54
61
  annotationPageLabel?: string;
55
62
  annotationSortIndex?: string;
63
+ /** JSON 字符串:`{pageIndex, rects}`;缺失或墨迹标注没有。 */
64
+ annotationPosition?: string;
56
65
  dateModified?: string;
57
66
  }
58
67
  interface RawEnclosure {
@@ -101,11 +110,43 @@ export declare function callMcpTool(name: string, args: unknown, signal?: AbortS
101
110
  export declare function getLibraryName(): Promise<string>;
102
111
  /** 全量分类(扁平,含 parentCollection 与 numItems)。 */
103
112
  export declare function listCollections(): Promise<ZoteroCollection[]>;
113
+ /**
114
+ * 文库级标签列表。
115
+ *
116
+ * 本地 API 没有「按分类的标签」端点(`/tags` 上的 `collectionKey` / `q` 实测被忽略),
117
+ * 所以计数是**全库**的;范围用量另走 {@link listTagUsage}。
118
+ * 按名称去重(同名标签只可能来自分页重复),`meta.type` / `numItems` 缺失时
119
+ * 分别按手动标签与 0 处理,避免 UI 出现 `NaN`。
120
+ */
121
+ export declare function listTags(): Promise<ZoteroTags>;
122
+ export interface ListTagUsageOptions {
123
+ /** 虚拟分类范围;缺省或 `library` 走真实分类/全库。 */
124
+ scope?: ZoteroItemScope;
125
+ /**
126
+ * 真实分类 key 列表(可含子目录);空/缺省 = 全库。
127
+ * 分类本身不含子分类条目,子树集合由调用方展开后传进来。
128
+ */
129
+ collectionKeys?: readonly string[];
130
+ /** 与条目列表同一个搜索词,标签可用性才跟列表口径一致。 */
131
+ q?: string;
132
+ }
133
+ /**
134
+ * 当前范围(分类 / 虚拟分类 + 搜索词)内的标签用量。
135
+ *
136
+ * 只能扫条目现算:逐页取范围内的顶层条目,读每条的 `data.tags` 累加计数。
137
+ * 传多个 `collectionKeys` 时分目录扫描,并按条目 key 去重——同一篇条目可能
138
+ * 同时挂在父分类与子分类里,不能重复计数。超过 `USAGE_SCAN_MAX` 条的大范围
139
+ * 按前若干页截断,超大目录可能漏掉靠后的标签(本地 API 没有按分类列标签的端点)。
140
+ */
141
+ export declare function listTagUsage(options: ListTagUsageOptions): Promise<ZoteroTags>;
104
142
  export interface ListItemsOptions {
105
143
  /** 虚拟分类范围;缺省或 `library` 走真实分类/全库。 */
106
144
  scope?: ZoteroItemScope;
107
145
  collectionKey?: string;
108
146
  q?: string;
147
+ /** 标签过滤:AND(默认)逐个 `tag=`,OR 合并成 `tag=A || B`。 */
148
+ tags?: readonly string[];
149
+ tagMode?: 'all' | 'any';
109
150
  limit: number;
110
151
  offset: number;
111
152
  }
@@ -117,7 +158,7 @@ export declare function listItems(options: ListItemsOptions): Promise<{
117
158
  /** 子条目(附件 / 笔记)。 */
118
159
  export declare function getItemChildren(key: string): Promise<RawItem[]>;
119
160
  /**
120
- * 条目下所有 PDF 附件上的高亮与划线。
161
+ * 条目下所有 PDF 附件上的标注。
121
162
  *
122
163
  * 必须显式带 `itemType=annotation`:实测 `/children` 不带参数时不返回标注。
123
164
  * 失败降级为空数组——标注是详情的附加信息,不能拖垮整个条目。
@@ -125,6 +166,14 @@ export declare function getItemChildren(key: string): Promise<RawItem[]>;
125
166
  export declare function getItemAnnotations(key: string): Promise<RawAnnotation[]>;
126
167
  /** 附件全文;仅附件条目可用。 */
127
168
  export declare function getItemFulltext(attachmentKey: string): Promise<ZoteroFulltext | null>;
169
+ /**
170
+ * 解析附件在磁盘上的真实路径。
171
+ *
172
+ * 路径只来自 Zotero 条目 JSON 的 `links.enclosure.href`(`file://` URL),
173
+ * 客户端传来的任何路径都不接受。`lstat` 拒绝目录与非普通文件;
174
+ * 链接附件(`linkMode: linked_file`)同样走这里,不限制必须在 storage 下。
175
+ */
176
+ export declare function getAttachmentFile(key: string): Promise<ZoteroAttachmentFile>;
128
177
  /** 单条条目的 CSL HTML(`format=bib`);失败返回 null。 */
129
178
  export declare function getItemBib(key: string, style: string): Promise<string | null>;
130
179
  /** 条目详情:元数据 + 附件 + 笔记 + 标注 + 首个可读附件全文 + CSL。 */