@gmickel/gno 1.45.1 → 2.0.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 (236) hide show
  1. package/README.md +1 -1
  2. package/THIRD_PARTY_NOTICES.md +46 -0
  3. package/assets/skill/SKILL.md +7 -6
  4. package/assets/skill/cli-reference.md +14 -6
  5. package/assets/skill/mcp-reference.md +4 -1
  6. package/assets/spa-production.json.gz +0 -0
  7. package/browser-extension/artifacts/gno-browser-clipper-v2.0.0.zip +0 -0
  8. package/browser-extension/artifacts/gno-browser-clipper-v2.0.0.zip.sha256 +1 -0
  9. package/browser-extension/dist/chunk-4tc9v0ja.js +74 -0
  10. package/browser-extension/dist/manifest.json +1 -1
  11. package/browser-extension/dist/preview.html +1 -1
  12. package/browser-extension/dist/service-worker.js +32 -33
  13. package/bunfig.toml +2 -0
  14. package/package.json +40 -26
  15. package/spec/cli.md +30 -11
  16. package/spec/db/schema.sql +146 -1
  17. package/spec/mcp.md +26 -0
  18. package/src/app/context-runtime-types.ts +3 -0
  19. package/src/app/context-runtime.ts +2 -0
  20. package/src/cli/commands/ask.ts +6 -1
  21. package/src/cli/commands/daemon.ts +21 -8
  22. package/src/cli/commands/embed.ts +77 -41
  23. package/src/cli/commands/mcp/install.ts +20 -0
  24. package/src/cli/commands/mcp/paths.ts +25 -0
  25. package/src/cli/commands/mcp/status.ts +6 -0
  26. package/src/cli/detach.ts +3 -2
  27. package/src/cli/program.ts +6 -0
  28. package/src/config/types.ts +3 -3
  29. package/src/converters/adapters/markitdownTs/adapter.ts +1 -2
  30. package/src/converters/adapters/officeparser/adapter.ts +1 -2
  31. package/src/converters/versions.ts +6 -8
  32. package/src/core/context-evidence.ts +8 -4
  33. package/src/core/job-manager.ts +95 -13
  34. package/src/core/network-boundary-inventory.ts +10 -0
  35. package/src/core/shutdown-budget.ts +45 -0
  36. package/src/embed/backlog.ts +107 -4
  37. package/src/embed/batch.ts +42 -2
  38. package/src/embed/fingerprint.ts +16 -0
  39. package/src/embed/retry.ts +113 -5
  40. package/src/embed/variant-backlog.ts +105 -0
  41. package/src/embed/variant-plan.ts +62 -0
  42. package/src/embed/variant-retry.ts +113 -0
  43. package/src/ingestion/graph-reconciliation.ts +327 -0
  44. package/src/ingestion/sync.ts +9 -272
  45. package/src/llm/http-inference.ts +6 -0
  46. package/src/llm/httpEmbedding.ts +37 -6
  47. package/src/llm/httpGeneration.ts +18 -3
  48. package/src/llm/httpRerank.ts +23 -5
  49. package/src/llm/inference-cancellation.ts +168 -0
  50. package/src/llm/inference-scope.ts +202 -0
  51. package/src/llm/lazy-ports.ts +115 -0
  52. package/src/llm/native-worker/client.ts +541 -0
  53. package/src/llm/native-worker/dispatcher.ts +228 -0
  54. package/src/llm/native-worker/embedding-identity.ts +33 -0
  55. package/src/llm/native-worker/entry.ts +173 -0
  56. package/src/llm/native-worker/errors.ts +32 -0
  57. package/src/llm/native-worker/evaluation.ts +16 -0
  58. package/src/llm/native-worker/owned-exit.ts +108 -0
  59. package/src/llm/native-worker/owner.ts +141 -0
  60. package/src/llm/native-worker/ports.ts +317 -0
  61. package/src/llm/native-worker/protocol.ts +442 -0
  62. package/src/llm/native-worker/runtime-config.ts +92 -0
  63. package/src/llm/nodeLlamaCpp/adapter.ts +77 -20
  64. package/src/llm/nodeLlamaCpp/embedding.ts +130 -46
  65. package/src/llm/nodeLlamaCpp/generation.ts +34 -5
  66. package/src/llm/nodeLlamaCpp/lifecycle-options.ts +99 -0
  67. package/src/llm/nodeLlamaCpp/lifecycle.ts +209 -204
  68. package/src/llm/nodeLlamaCpp/rerank-capacity.ts +111 -0
  69. package/src/llm/nodeLlamaCpp/rerank.ts +118 -27
  70. package/src/llm/nodeLlamaCpp/simulator-handle.ts +73 -0
  71. package/src/llm/nodeLlamaCpp/simulator-install.ts +124 -0
  72. package/src/llm/nodeLlamaCpp/simulator-session.ts +240 -0
  73. package/src/llm/nodeLlamaCpp/simulator-types.ts +80 -0
  74. package/src/llm/types.ts +35 -5
  75. package/src/mcp/context.ts +27 -0
  76. package/src/mcp/http-transport.ts +12 -10
  77. package/src/mcp/server.ts +3 -0
  78. package/src/mcp/tool-profile.ts +30 -8
  79. package/src/mcp/tools/context.ts +8 -11
  80. package/src/mcp/tools/embed.ts +1 -1
  81. package/src/mcp/tools/index-cmd.ts +1 -1
  82. package/src/mcp/tools/index.ts +10 -8
  83. package/src/mcp/tools/query.ts +14 -30
  84. package/src/mcp/tools/vsearch.ts +1 -1
  85. package/src/pipeline/answer.ts +23 -3
  86. package/src/pipeline/claim-verifier.ts +6 -0
  87. package/src/pipeline/expansion.ts +43 -40
  88. package/src/pipeline/explain.ts +6 -2
  89. package/src/pipeline/filters.ts +63 -0
  90. package/src/pipeline/fusion.ts +29 -9
  91. package/src/pipeline/graph-retrieval.ts +29 -9
  92. package/src/pipeline/hybrid.ts +198 -55
  93. package/src/pipeline/hydration.ts +161 -0
  94. package/src/pipeline/owner-fusion.ts +87 -0
  95. package/src/pipeline/rerank.ts +35 -11
  96. package/src/pipeline/search.ts +13 -2
  97. package/src/pipeline/types.ts +5 -3
  98. package/src/pipeline/vsearch.ts +87 -7
  99. package/src/sdk/client.ts +47 -3
  100. package/src/sdk/embed.ts +63 -39
  101. package/src/serve/background-runtime.ts +1 -1
  102. package/src/serve/context.ts +41 -56
  103. package/src/serve/embed-scheduler.ts +58 -35
  104. package/src/serve/public/components/IndexingProgress.tsx +46 -60
  105. package/src/serve/public/globals.built.css +1 -1
  106. package/src/serve/public/lib/shiki-language-ids.ts +14 -0
  107. package/src/serve/resident-admission.ts +36 -36
  108. package/src/serve/resident-background-work.ts +20 -2
  109. package/src/serve/resident-request.ts +11 -5
  110. package/src/serve/resident-runtime.ts +97 -61
  111. package/src/serve/resident-shutdown.ts +153 -0
  112. package/src/serve/routes/api.ts +3 -1
  113. package/src/serve/server.ts +47 -26
  114. package/src/store/migrations/028-vector-variants.ts +54 -0
  115. package/src/store/migrations/029-graph-reference-state.ts +77 -0
  116. package/src/store/migrations/index.ts +4 -0
  117. package/src/store/sqlite/adapter.ts +251 -183
  118. package/src/store/sqlite/eligibility.ts +174 -0
  119. package/src/store/sqlite/graph-edge-application.ts +66 -0
  120. package/src/store/sqlite/graph-reference-state.ts +194 -0
  121. package/src/store/sqlite/legacy-vector-ownership.ts +79 -0
  122. package/src/store/types.ts +80 -12
  123. package/src/store/vector/eligibility.ts +36 -0
  124. package/src/store/vector/freshness.ts +33 -6
  125. package/src/store/vector/lazy.ts +81 -0
  126. package/src/store/vector/sqlite-vec.ts +106 -54
  127. package/src/store/vector/stats.ts +14 -3
  128. package/src/store/vector/types.ts +35 -2
  129. package/src/store/vector/variant-search.ts +192 -0
  130. package/src/store/vector/variants.ts +451 -0
  131. package/vendor/converters/markitdown-ts/LICENSE +21 -0
  132. package/vendor/converters/markitdown-ts/dist/index.cjs +1180 -0
  133. package/vendor/converters/markitdown-ts/dist/index.d.cts +46 -0
  134. package/vendor/converters/markitdown-ts/dist/index.d.mts +46 -0
  135. package/vendor/converters/markitdown-ts/dist/index.d.ts +46 -0
  136. package/vendor/converters/markitdown-ts/dist/index.mjs +1152 -0
  137. package/vendor/converters/markitdown-ts/package.json +77 -0
  138. package/vendor/converters/officeparser/LICENSE +21 -0
  139. package/vendor/converters/officeparser/dist/OfficeConverter.d.ts +47 -0
  140. package/vendor/converters/officeparser/dist/OfficeConverter.js +76 -0
  141. package/vendor/converters/officeparser/dist/OfficeGenerator.d.ts +23 -0
  142. package/vendor/converters/officeparser/dist/OfficeGenerator.js +73 -0
  143. package/vendor/converters/officeparser/dist/OfficeParser.d.ts +106 -0
  144. package/vendor/converters/officeparser/dist/OfficeParser.js +332 -0
  145. package/vendor/converters/officeparser/dist/cli.d.ts +28 -0
  146. package/vendor/converters/officeparser/dist/cli.js +381 -0
  147. package/vendor/converters/officeparser/dist/defaults.d.ts +41 -0
  148. package/vendor/converters/officeparser/dist/defaults.js +218 -0
  149. package/vendor/converters/officeparser/dist/generators/BaseGenerator.d.ts +107 -0
  150. package/vendor/converters/officeparser/dist/generators/BaseGenerator.js +248 -0
  151. package/vendor/converters/officeparser/dist/generators/ChunkingGenerator.d.ts +82 -0
  152. package/vendor/converters/officeparser/dist/generators/ChunkingGenerator.js +797 -0
  153. package/vendor/converters/officeparser/dist/generators/CsvGenerator.d.ts +38 -0
  154. package/vendor/converters/officeparser/dist/generators/CsvGenerator.js +245 -0
  155. package/vendor/converters/officeparser/dist/generators/EpubGenerator.d.ts +43 -0
  156. package/vendor/converters/officeparser/dist/generators/EpubGenerator.js +315 -0
  157. package/vendor/converters/officeparser/dist/generators/HtmlGenerator.d.ts +59 -0
  158. package/vendor/converters/officeparser/dist/generators/HtmlGenerator.js +1942 -0
  159. package/vendor/converters/officeparser/dist/generators/MarkdownGenerator.d.ts +96 -0
  160. package/vendor/converters/officeparser/dist/generators/MarkdownGenerator.js +1175 -0
  161. package/vendor/converters/officeparser/dist/generators/PdfGenerator.d.ts +22 -0
  162. package/vendor/converters/officeparser/dist/generators/PdfGenerator.js +194 -0
  163. package/vendor/converters/officeparser/dist/generators/RtfGenerator.d.ts +29 -0
  164. package/vendor/converters/officeparser/dist/generators/RtfGenerator.js +316 -0
  165. package/vendor/converters/officeparser/dist/generators/TextGenerator.d.ts +13 -0
  166. package/vendor/converters/officeparser/dist/generators/TextGenerator.js +201 -0
  167. package/vendor/converters/officeparser/dist/index.d.ts +60 -0
  168. package/vendor/converters/officeparser/dist/index.js +72 -0
  169. package/vendor/converters/officeparser/dist/index.mjs +18 -0
  170. package/vendor/converters/officeparser/dist/officeparser.browser.d.ts +2621 -0
  171. package/vendor/converters/officeparser/dist/officeparser.browser.iife.js +1336 -0
  172. package/vendor/converters/officeparser/dist/officeparser.browser.mjs +1335 -0
  173. package/vendor/converters/officeparser/dist/officeparser.browser.slim.d.ts +2621 -0
  174. package/vendor/converters/officeparser/dist/officeparser.browser.slim.iife.js +1336 -0
  175. package/vendor/converters/officeparser/dist/officeparser.browser.slim.mjs +1335 -0
  176. package/vendor/converters/officeparser/dist/parsers/CsvParser.d.ts +9 -0
  177. package/vendor/converters/officeparser/dist/parsers/CsvParser.js +115 -0
  178. package/vendor/converters/officeparser/dist/parsers/EpubParser.d.ts +8 -0
  179. package/vendor/converters/officeparser/dist/parsers/EpubParser.js +217 -0
  180. package/vendor/converters/officeparser/dist/parsers/ExcelParser.d.ts +32 -0
  181. package/vendor/converters/officeparser/dist/parsers/ExcelParser.js +736 -0
  182. package/vendor/converters/officeparser/dist/parsers/HtmlParser.d.ts +2 -0
  183. package/vendor/converters/officeparser/dist/parsers/HtmlParser.js +1287 -0
  184. package/vendor/converters/officeparser/dist/parsers/MarkdownParser.d.ts +2 -0
  185. package/vendor/converters/officeparser/dist/parsers/MarkdownParser.js +1272 -0
  186. package/vendor/converters/officeparser/dist/parsers/OpenOfficeParser.d.ts +31 -0
  187. package/vendor/converters/officeparser/dist/parsers/OpenOfficeParser.js +1819 -0
  188. package/vendor/converters/officeparser/dist/parsers/PdfParser.d.ts +67 -0
  189. package/vendor/converters/officeparser/dist/parsers/PdfParser.js +848 -0
  190. package/vendor/converters/officeparser/dist/parsers/PowerPointParser.d.ts +32 -0
  191. package/vendor/converters/officeparser/dist/parsers/PowerPointParser.js +950 -0
  192. package/vendor/converters/officeparser/dist/parsers/RtfParser.d.ts +187 -0
  193. package/vendor/converters/officeparser/dist/parsers/RtfParser.js +1801 -0
  194. package/vendor/converters/officeparser/dist/parsers/WordParser.d.ts +79 -0
  195. package/vendor/converters/officeparser/dist/parsers/WordParser.js +1177 -0
  196. package/vendor/converters/officeparser/dist/sbom.cdx.json +1763 -0
  197. package/vendor/converters/officeparser/dist/types.d.ts +2507 -0
  198. package/vendor/converters/officeparser/dist/types.js +107 -0
  199. package/vendor/converters/officeparser/dist/utils/astUtils.d.ts +16 -0
  200. package/vendor/converters/officeparser/dist/utils/astUtils.js +33 -0
  201. package/vendor/converters/officeparser/dist/utils/chartUtils.d.ts +6 -0
  202. package/vendor/converters/officeparser/dist/utils/chartUtils.js +257 -0
  203. package/vendor/converters/officeparser/dist/utils/configUtils.d.ts +44 -0
  204. package/vendor/converters/officeparser/dist/utils/configUtils.js +315 -0
  205. package/vendor/converters/officeparser/dist/utils/dateUtils.d.ts +17 -0
  206. package/vendor/converters/officeparser/dist/utils/dateUtils.js +69 -0
  207. package/vendor/converters/officeparser/dist/utils/envUtils.d.ts +29 -0
  208. package/vendor/converters/officeparser/dist/utils/envUtils.js +152 -0
  209. package/vendor/converters/officeparser/dist/utils/errorUtils.d.ts +72 -0
  210. package/vendor/converters/officeparser/dist/utils/errorUtils.js +245 -0
  211. package/vendor/converters/officeparser/dist/utils/imageUtils.d.ts +66 -0
  212. package/vendor/converters/officeparser/dist/utils/imageUtils.js +133 -0
  213. package/vendor/converters/officeparser/dist/utils/mathUtils.d.ts +42 -0
  214. package/vendor/converters/officeparser/dist/utils/mathUtils.js +385 -0
  215. package/vendor/converters/officeparser/dist/utils/moduleLoader.d.ts +18 -0
  216. package/vendor/converters/officeparser/dist/utils/moduleLoader.js +106 -0
  217. package/vendor/converters/officeparser/dist/utils/ocrUtils.d.ts +42 -0
  218. package/vendor/converters/officeparser/dist/utils/ocrUtils.js +428 -0
  219. package/vendor/converters/officeparser/dist/utils/sanitize.d.ts +148 -0
  220. package/vendor/converters/officeparser/dist/utils/sanitize.js +344 -0
  221. package/vendor/converters/officeparser/dist/utils/sheetUtils.d.ts +7 -0
  222. package/vendor/converters/officeparser/dist/utils/sheetUtils.js +35 -0
  223. package/vendor/converters/officeparser/dist/utils/styleMapper.d.ts +36 -0
  224. package/vendor/converters/officeparser/dist/utils/styleMapper.js +224 -0
  225. package/vendor/converters/officeparser/dist/utils/xmlUtils.d.ts +163 -0
  226. package/vendor/converters/officeparser/dist/utils/xmlUtils.js +461 -0
  227. package/vendor/converters/officeparser/dist/utils/zipUtils.d.ts +134 -0
  228. package/vendor/converters/officeparser/dist/utils/zipUtils.js +337 -0
  229. package/vendor/converters/officeparser/package.json +147 -0
  230. package/vendor/converters/upstream-manifest.json +124 -0
  231. package/vendor/dependency-fixes/README.md +77 -0
  232. package/vendor/dependency-fixes/vendor-converters.py +83 -0
  233. package/browser-extension/artifacts/gno-browser-clipper-v1.45.1.zip +0 -0
  234. package/browser-extension/artifacts/gno-browser-clipper-v1.45.1.zip.sha256 +0 -1
  235. package/browser-extension/dist/chunk-627emwpj.js +0 -75
  236. /package/browser-extension/dist/{chunk-ydfx5d7p.css → chunk-z74y8n8c.css} +0 -0
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextGenerator = void 0;
4
+ const BaseGenerator_js_1 = require("./BaseGenerator.js");
5
+ const escapeRegExpChars = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
6
+ /**
7
+ * Separator between table/sheet cells on the paths that don't render an aligned grid (a `table`
8
+ * with `preserveLayout` off, and `sheet`/`row`/`cell`, which never go through `renderTable`).
9
+ * A tab is the conventional plain-text column delimiter and, unlike a space, survives a value that
10
+ * already contains spaces.
11
+ */
12
+ const CELL_SEPARATOR = '\t';
13
+ /**
14
+ * Generates plain text from an AST.
15
+ */
16
+ class TextGenerator extends BaseGenerator_js_1.BaseGenerator {
17
+ constructor(ast, config) {
18
+ super('text', ast, config);
19
+ }
20
+ /**
21
+ * Generates plain text by concatenating text content from nodes.
22
+ */
23
+ async generate() {
24
+ let output = '';
25
+ const newline = this.config.textConfig.newlineDelimiter;
26
+ // Add Metadata Header
27
+ const meta = this.effectiveMetadata;
28
+ if (this.config.renderMetadata && meta) {
29
+ // The header is a structured `Key: value` block terminated by a rule, and consumers
30
+ // parse it as such. A value containing a line break would forge extra fields - a title
31
+ // of "Real\nAuthor: Attacker" renders an Author line the document never had - so line
32
+ // breaks are folded to spaces, matching how CsvGenerator guards its `#` comment block.
33
+ // Plain text has no code-execution context, but fabricated structure is still a lie
34
+ // about the document, and every AST string is treated as attacker-controlled.
35
+ const oneLine = (value) => String(value ?? '').replace(/[\r\n]+/g, ' ');
36
+ if (meta.title)
37
+ output += `Title: ${oneLine(meta.title)}${newline}`;
38
+ if (meta.author)
39
+ output += `Author: ${oneLine(meta.author)}${newline}`;
40
+ // Guarded like HtmlGenerator's toIsoDate: a malformed date must not render the literal
41
+ // "Invalid Date" into the header as if it were the document's creation time.
42
+ if (meta.created) {
43
+ const created = new Date(meta.created);
44
+ if (!isNaN(created.getTime()))
45
+ output += `Created: ${oneLine(created.toLocaleString())}${newline}`;
46
+ }
47
+ output += `-------------------${newline}${newline}`;
48
+ }
49
+ const processor = async (node, childrenOutput) => {
50
+ // Return raw text for text nodes
51
+ if (node.type === 'text' || node.type === 'code') {
52
+ return node.text || '';
53
+ }
54
+ // Handle explicit breaks
55
+ if (node.type === 'break') {
56
+ return newline;
57
+ }
58
+ if (node.type === 'image') {
59
+ if (!this.config.includeImages)
60
+ return '';
61
+ const meta = node.metadata;
62
+ return `[Image: ${meta?.altText || meta?.attachmentName || 'Untitled'}]${newline}`;
63
+ }
64
+ if (node.type === 'embed') {
65
+ const meta = node.metadata;
66
+ return meta?.url ? `[${meta.embedType === 'youtube' ? 'YouTube' : 'Embed'}: ${meta.url}]${newline}` : '';
67
+ }
68
+ if (node.type === 'admonition') {
69
+ const meta = node.metadata;
70
+ if (childrenOutput.trim() === '')
71
+ return '';
72
+ const label = (meta?.admonitionType || 'note').toUpperCase();
73
+ return `[${label}] ${childrenOutput.trim()}${newline}`;
74
+ }
75
+ if (node.type === 'table' && this.config.textConfig.preserveLayout) {
76
+ return await this.renderTable(node, processor, newline);
77
+ }
78
+ if (node.type === 'list' && this.config.textConfig.preserveLayout) {
79
+ const meta = node.metadata;
80
+ const indentSpaces = ' '.repeat(4);
81
+ const indent = indentSpaces.repeat(meta?.indentation || 0);
82
+ const marker = meta?.listType === 'ordered' ? `${(meta.itemIndex ?? 0) + 1}. ` : '- ';
83
+ return `${indent}${marker}${childrenOutput.trimStart()}` + (childrenOutput.endsWith(newline) ? '' : newline);
84
+ }
85
+ // Cells need an explicit separator between them. Without one they concatenate into a
86
+ // single run - "ITEM" + "NEEDED" becomes "ITEMNEEDED", which is unreadable and loses the
87
+ // cell boundary entirely. This was previously masked for spreadsheets only because
88
+ // XLSX/ODS cell values happen to carry a trailing non-breaking space in the source data,
89
+ // so they *appeared* separated; formats whose cell text has no trailing whitespace (MD,
90
+ // HTML) collided outright. Relying on the data to supply a delimiter isn't a separator.
91
+ //
92
+ // Applies to the paths that don't go through renderTable: a `table` when preserveLayout
93
+ // is off, and `sheet`/`row`/`cell` always, since a sheet is not a `table` node.
94
+ if (node.type === 'cell') {
95
+ // Only when the cell doesn't already end in a line break. Cell content varies by
96
+ // source: DOCX/ODT/RTF wrap it in a paragraph, which emits its own newline and so
97
+ // already separates cells, while MD/HTML/XLSX hold bare text that would otherwise
98
+ // collide. Appending unconditionally would push a stray tab onto the formats that
99
+ // were already correct - measured, not assumed: doing so moved DOCX from 6 to 178
100
+ // line-edits away from toText().
101
+ if (childrenOutput === '' || childrenOutput.endsWith(newline))
102
+ return childrenOutput;
103
+ return childrenOutput + CELL_SEPARATOR;
104
+ }
105
+ // Append newline for block-level elements to maintain structure.
106
+ const blockTypes = ['paragraph', 'heading', 'row', 'sheet', 'slide', 'note', 'list', 'table', 'code'];
107
+ if (node.type === 'row') {
108
+ // Trailing separator on the final cell is an artifact of appending one per cell, not
109
+ // content, so drop it rather than leaving every row ending in a stray tab.
110
+ const row = childrenOutput.endsWith(CELL_SEPARATOR)
111
+ ? childrenOutput.slice(0, -CELL_SEPARATOR.length)
112
+ : childrenOutput;
113
+ if (row === '')
114
+ return '';
115
+ return row + (row.endsWith(newline) ? '' : newline);
116
+ }
117
+ if (blockTypes.includes(node.type)) {
118
+ // Drop a block only when it is genuinely empty, not merely whitespace. A paragraph
119
+ // containing spaces is content the document actually holds - discarding it silently
120
+ // deletes an author's blank-but-not-empty line, and disagreed with every parser's
121
+ // own toTextSync, which filters on `!== ''` rather than on trimmed emptiness.
122
+ if (childrenOutput === '')
123
+ return '';
124
+ return childrenOutput + (childrenOutput.endsWith(newline) ? '' : newline);
125
+ }
126
+ // Fallback for node types with no explicit handling above. Prefer rendered children,
127
+ // but fall back to the node's own text when it has none: a `chart` carries its whole
128
+ // data series in `text` with zero child nodes, and a CSV `comment` likewise, so
129
+ // returning only `childrenOutput` silently dropped both. Every parser's own toTextSync
130
+ // reads `node.text`, so this is what the rest of the library already does - and it
131
+ // covers any future node type of the same shape rather than just the two known today.
132
+ if (!childrenOutput && node.text) {
133
+ return node.text + (node.text.endsWith(newline) ? '' : newline);
134
+ }
135
+ return childrenOutput;
136
+ };
137
+ for (const node of this.ast.content) {
138
+ output += await this.processNodeRecursive(node, processor);
139
+ }
140
+ if (this.collectedNotes.length > 0 && this.config.textConfig.renderNotes) {
141
+ output += `${newline}${newline}--- Notes ---${newline}`;
142
+ for (const note of this.collectedNotes) {
143
+ output += await this.processNodeRecursive(note, processor);
144
+ }
145
+ }
146
+ // Every block-level node above unconditionally appends its own trailing `newline` as a
147
+ // separator from whatever sibling follows - including, unavoidably, the very last one,
148
+ // which has no sibling to separate from - and renderTable below unconditionally *prepends*
149
+ // one too, as a separator from whatever precedes it (also unavoidably applied when a table
150
+ // is the very first/only node). Both are pure generator artifacts, never part of the
151
+ // document's actual content, so a run of exactly this delimiter at either end is the only
152
+ // thing safe to strip. Nothing else is: not leading/trailing spaces or tabs (e.g. an
153
+ // intentionally-indented opening line, or trailing spaces on the last line - both real
154
+ // content), and not any whitespace that isn't composed of this exact repeated delimiter. A
155
+ // blanket trim()/trimEnd() would silently destroy all of those.
156
+ const d = escapeRegExpChars(newline);
157
+ const leadingOrTrailingArtifact = new RegExp(`^(?:${d})+|(?:${d})+$`, 'g');
158
+ return {
159
+ value: output.replace(leadingOrTrailingArtifact, ''),
160
+ messages: this.messages
161
+ };
162
+ }
163
+ async renderTable(node, processor, newline) {
164
+ if (!node.children || node.children.length === 0)
165
+ return '';
166
+ const rows = [];
167
+ const colWidths = [];
168
+ for (const rowNode of node.children) {
169
+ // Manual check for onNode in table rows since we are bypassing processNodeRecursive for rows here
170
+ const override = await this.handleOnNode(rowNode);
171
+ if (override === false)
172
+ continue;
173
+ if (typeof override === 'string') {
174
+ rows.push([override]);
175
+ continue;
176
+ }
177
+ const row = [];
178
+ if (rowNode.children) {
179
+ for (let i = 0; i < rowNode.children.length; i++) {
180
+ const cellNode = rowNode.children[i];
181
+ const cellText = (await this.processNodeRecursive(cellNode, processor))
182
+ .trim()
183
+ .replace(/\r?\n/g, ' ');
184
+ row.push(cellText);
185
+ colWidths[i] = Math.max(colWidths[i] || 0, cellText.length);
186
+ }
187
+ }
188
+ rows.push(row);
189
+ }
190
+ let tableOutput = newline;
191
+ for (const row of rows) {
192
+ tableOutput += '| ';
193
+ for (let i = 0; i < row.length; i++) {
194
+ tableOutput += (row[i] || '').padEnd(colWidths[i] || 0) + ' | ';
195
+ }
196
+ tableOutput += newline;
197
+ }
198
+ return tableOutput + newline;
199
+ }
200
+ }
201
+ exports.TextGenerator = TextGenerator;
@@ -0,0 +1,60 @@
1
+ /**
2
+ * officeparser - Universal Office Document Parser
3
+ *
4
+ * A comprehensive Node.js library for parsing Microsoft Office and OpenDocument files
5
+ * into structured Abstract Syntax Trees (AST) with full formatting information.
6
+ *
7
+ * **Supported Formats:**
8
+ * - Microsoft Office: DOCX, XLSX, PPTX (Office Open XML)
9
+ * - OpenDocument: ODT, ODP, ODS (ODF)
10
+ * - Portable: PDF
11
+ * - Legacy: RTF (Rich Text Format)
12
+ * - Web/Plain: CSV, MD, HTML
13
+ * - E-book: EPUB
14
+ *
15
+ * **Key Features:**
16
+ * - Unified AST output across all formats
17
+ * - Rich text formatting (bold, italic, colors, fonts, etc.)
18
+ * - Document structure (headings, lists, tables)
19
+ * - Image extraction with optional OCR
20
+ * - Metadata extraction
21
+ * - TypeScript support with full type definitions
22
+ *
23
+ * **Quick Start:**
24
+ * ```typescript
25
+ * import { OfficeParser } from 'officeparser';
26
+ *
27
+ * const ast = await OfficeParser.parseOffice('document.docx', {
28
+ * extractAttachments: true,
29
+ * ocr: true,
30
+ * includeRawContent: false
31
+ * });
32
+ *
33
+ * console.log(ast.toText()); // Plain text output
34
+ * console.log(ast.content); // Structured content tree
35
+ * console.log(ast.metadata); // Document metadata
36
+ * ```
37
+ *
38
+ * **Main Exports:**
39
+ * - `OfficeParser` - Main parser class
40
+ * - `OfficeGenerator` - Main generator class for document conversion
41
+ * - `OfficeParserConfig` - Configuration interface
42
+ * - `GeneratorConfig` - Generator configuration interface
43
+ * - `OfficeParserAST` - AST result interface
44
+ * - `OfficeContentNode` - Content tree node interface
45
+ * - All type definitions
46
+
47
+ *
48
+ * @packageDocumentation
49
+ * @module officeparser
50
+ */
51
+ import { OfficeParser } from './OfficeParser.js';
52
+ import { OfficeGenerator } from './OfficeGenerator.js';
53
+ import { OfficeConverter } from './OfficeConverter.js';
54
+ import { OfficeParserConfig, OfficeParserAST, OfficeContentNode, OfficeAttachment, OfficeMetadata, TextFormatting, BlobLike, SupportedFileType, OfficeContentNodeType, OfficeMimeType, SlideMetadata, SheetMetadata, HeadingMetadata, ListMetadata, CellMetadata, ImageMetadata, PageMetadata, ContentMetadata, BreakMetadata, GeneratorConfig, SupportedDestination, UniversalGeneratorFormat, ChunkingConfig, ChunkingStrategy, FixedSizeChunkingConfig, DocumentStructureChunkingConfig, SemanticChunkingConfig, OfficeChunk, OfficeConverterConfig, OfficeErrorType, OfficeWarningType, OfficeError, ConversionResult, HtmlGeneratorConfig, HtmlParserConfig, MdGeneratorConfig, CsvGeneratorConfig, PdfGeneratorConfig, RtfGeneratorConfig, TextGeneratorConfig, MarkdownDialectConfig, MarkdownDialectPreset, StandaloneConfig, MetadataOverrides, FallbackToHtmlConfig, HtmlInjectionConfig, OcrConfig, DecompressionLimits, TextMetadata, TableMetadata, CodeMetadata, NoteMetadata, AdmonitionMetadata, EmbedMetadata, ChartMetadata, CommentMetadata, HeaderFooterMetadata, IndentationMetadata, ParagraphMetadata } from './types.js';
55
+ declare const parseOffice: typeof OfficeParser.parseOffice;
56
+ declare const terminateOcr: typeof OfficeParser.terminateOcr;
57
+ declare const convert: typeof OfficeConverter.convert;
58
+ declare const generate: typeof OfficeGenerator.generate;
59
+ export { OfficeParser, parseOffice, terminateOcr, OfficeParserConfig, OfficeParserAST, OfficeContentNode, OfficeAttachment, OfficeMetadata, TextFormatting, BlobLike, SupportedFileType, OfficeContentNodeType, OfficeMimeType, SlideMetadata, SheetMetadata, HeadingMetadata, ListMetadata, CellMetadata, ImageMetadata, PageMetadata, ContentMetadata, BreakMetadata, OfficeGenerator, GeneratorConfig, SupportedDestination, UniversalGeneratorFormat, ChunkingConfig, ChunkingStrategy, FixedSizeChunkingConfig, DocumentStructureChunkingConfig, SemanticChunkingConfig, OfficeChunk, OfficeConverter, OfficeConverterConfig, convert, generate, OfficeErrorType, OfficeWarningType, OfficeError, ConversionResult, HtmlGeneratorConfig, HtmlParserConfig, MdGeneratorConfig, CsvGeneratorConfig, PdfGeneratorConfig, RtfGeneratorConfig, TextGeneratorConfig, MarkdownDialectConfig, MarkdownDialectPreset, StandaloneConfig, MetadataOverrides, FallbackToHtmlConfig, HtmlInjectionConfig, OcrConfig, DecompressionLimits, TextMetadata, TableMetadata, CodeMetadata, NoteMetadata, AdmonitionMetadata, EmbedMetadata, ChartMetadata, CommentMetadata, HeaderFooterMetadata, IndentationMetadata, ParagraphMetadata, };
60
+ export default OfficeParser;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ /**
3
+ * officeparser - Universal Office Document Parser
4
+ *
5
+ * A comprehensive Node.js library for parsing Microsoft Office and OpenDocument files
6
+ * into structured Abstract Syntax Trees (AST) with full formatting information.
7
+ *
8
+ * **Supported Formats:**
9
+ * - Microsoft Office: DOCX, XLSX, PPTX (Office Open XML)
10
+ * - OpenDocument: ODT, ODP, ODS (ODF)
11
+ * - Portable: PDF
12
+ * - Legacy: RTF (Rich Text Format)
13
+ * - Web/Plain: CSV, MD, HTML
14
+ * - E-book: EPUB
15
+ *
16
+ * **Key Features:**
17
+ * - Unified AST output across all formats
18
+ * - Rich text formatting (bold, italic, colors, fonts, etc.)
19
+ * - Document structure (headings, lists, tables)
20
+ * - Image extraction with optional OCR
21
+ * - Metadata extraction
22
+ * - TypeScript support with full type definitions
23
+ *
24
+ * **Quick Start:**
25
+ * ```typescript
26
+ * import { OfficeParser } from 'officeparser';
27
+ *
28
+ * const ast = await OfficeParser.parseOffice('document.docx', {
29
+ * extractAttachments: true,
30
+ * ocr: true,
31
+ * includeRawContent: false
32
+ * });
33
+ *
34
+ * console.log(ast.toText()); // Plain text output
35
+ * console.log(ast.content); // Structured content tree
36
+ * console.log(ast.metadata); // Document metadata
37
+ * ```
38
+ *
39
+ * **Main Exports:**
40
+ * - `OfficeParser` - Main parser class
41
+ * - `OfficeGenerator` - Main generator class for document conversion
42
+ * - `OfficeParserConfig` - Configuration interface
43
+ * - `GeneratorConfig` - Generator configuration interface
44
+ * - `OfficeParserAST` - AST result interface
45
+ * - `OfficeContentNode` - Content tree node interface
46
+ * - All type definitions
47
+
48
+ *
49
+ * @packageDocumentation
50
+ * @module officeparser
51
+ */
52
+ Object.defineProperty(exports, "__esModule", { value: true });
53
+ exports.OfficeWarningType = exports.OfficeErrorType = exports.generate = exports.convert = exports.OfficeConverter = exports.OfficeGenerator = exports.terminateOcr = exports.parseOffice = exports.OfficeParser = void 0;
54
+ const OfficeParser_js_1 = require("./OfficeParser.js");
55
+ Object.defineProperty(exports, "OfficeParser", { enumerable: true, get: function () { return OfficeParser_js_1.OfficeParser; } });
56
+ const OfficeGenerator_js_1 = require("./OfficeGenerator.js");
57
+ Object.defineProperty(exports, "OfficeGenerator", { enumerable: true, get: function () { return OfficeGenerator_js_1.OfficeGenerator; } });
58
+ const OfficeConverter_js_1 = require("./OfficeConverter.js");
59
+ Object.defineProperty(exports, "OfficeConverter", { enumerable: true, get: function () { return OfficeConverter_js_1.OfficeConverter; } });
60
+ const types_js_1 = require("./types.js");
61
+ Object.defineProperty(exports, "OfficeErrorType", { enumerable: true, get: function () { return types_js_1.OfficeErrorType; } });
62
+ Object.defineProperty(exports, "OfficeWarningType", { enumerable: true, get: function () { return types_js_1.OfficeWarningType; } });
63
+ const parseOffice = OfficeParser_js_1.OfficeParser.parseOffice;
64
+ exports.parseOffice = parseOffice;
65
+ const terminateOcr = OfficeParser_js_1.OfficeParser.terminateOcr;
66
+ exports.terminateOcr = terminateOcr;
67
+ const convert = OfficeConverter_js_1.OfficeConverter.convert;
68
+ exports.convert = convert;
69
+ const generate = OfficeGenerator_js_1.OfficeGenerator.generate;
70
+ exports.generate = generate;
71
+ // Default export for backward compatibility
72
+ exports.default = OfficeParser_js_1.OfficeParser;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * ESM wrapper for officeparser
3
+ *
4
+ * AUTO-GENERATED — do not edit manually.
5
+ * Generated by scripts/generate-esm-wrapper.js during build.
6
+ *
7
+ * This file re-exports from the CJS build (dist/index.js) to provide
8
+ * proper ESM named exports without duplicating the source code.
9
+ */
10
+
11
+ import _module from './index.js';
12
+
13
+ // Named exports
14
+ const { OfficeParser, parseOffice, terminateOcr, OfficeGenerator, OfficeConverter, convert, generate, OfficeErrorType, OfficeWarningType } = _module;
15
+ export { OfficeParser, parseOffice, terminateOcr, OfficeGenerator, OfficeConverter, convert, generate, OfficeErrorType, OfficeWarningType };
16
+
17
+ // Default export
18
+ export default _module.default ?? _module;