@gmickel/gno 1.46.0 → 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 (230) 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/spa-production.json.gz +0 -0
  5. package/browser-extension/artifacts/gno-browser-clipper-v2.0.0.zip +0 -0
  6. package/browser-extension/artifacts/gno-browser-clipper-v2.0.0.zip.sha256 +1 -0
  7. package/browser-extension/dist/chunk-4tc9v0ja.js +74 -0
  8. package/browser-extension/dist/manifest.json +1 -1
  9. package/browser-extension/dist/preview.html +1 -1
  10. package/browser-extension/dist/service-worker.js +32 -33
  11. package/bunfig.toml +2 -0
  12. package/package.json +40 -26
  13. package/spec/cli.md +21 -4
  14. package/spec/db/schema.sql +146 -1
  15. package/spec/mcp.md +26 -0
  16. package/src/app/context-runtime-types.ts +3 -0
  17. package/src/app/context-runtime.ts +2 -0
  18. package/src/cli/commands/ask.ts +6 -1
  19. package/src/cli/commands/daemon.ts +21 -8
  20. package/src/cli/commands/embed.ts +77 -41
  21. package/src/cli/detach.ts +3 -2
  22. package/src/config/types.ts +3 -3
  23. package/src/converters/adapters/markitdownTs/adapter.ts +1 -2
  24. package/src/converters/adapters/officeparser/adapter.ts +1 -2
  25. package/src/converters/versions.ts +6 -8
  26. package/src/core/context-evidence.ts +8 -4
  27. package/src/core/job-manager.ts +95 -13
  28. package/src/core/network-boundary-inventory.ts +10 -0
  29. package/src/core/shutdown-budget.ts +45 -0
  30. package/src/embed/backlog.ts +107 -4
  31. package/src/embed/batch.ts +42 -2
  32. package/src/embed/fingerprint.ts +16 -0
  33. package/src/embed/retry.ts +113 -5
  34. package/src/embed/variant-backlog.ts +105 -0
  35. package/src/embed/variant-plan.ts +62 -0
  36. package/src/embed/variant-retry.ts +113 -0
  37. package/src/ingestion/graph-reconciliation.ts +327 -0
  38. package/src/ingestion/sync.ts +9 -272
  39. package/src/llm/http-inference.ts +6 -0
  40. package/src/llm/httpEmbedding.ts +37 -6
  41. package/src/llm/httpGeneration.ts +18 -3
  42. package/src/llm/httpRerank.ts +23 -5
  43. package/src/llm/inference-cancellation.ts +168 -0
  44. package/src/llm/inference-scope.ts +202 -0
  45. package/src/llm/lazy-ports.ts +115 -0
  46. package/src/llm/native-worker/client.ts +541 -0
  47. package/src/llm/native-worker/dispatcher.ts +228 -0
  48. package/src/llm/native-worker/embedding-identity.ts +33 -0
  49. package/src/llm/native-worker/entry.ts +173 -0
  50. package/src/llm/native-worker/errors.ts +32 -0
  51. package/src/llm/native-worker/evaluation.ts +16 -0
  52. package/src/llm/native-worker/owned-exit.ts +108 -0
  53. package/src/llm/native-worker/owner.ts +141 -0
  54. package/src/llm/native-worker/ports.ts +317 -0
  55. package/src/llm/native-worker/protocol.ts +442 -0
  56. package/src/llm/native-worker/runtime-config.ts +92 -0
  57. package/src/llm/nodeLlamaCpp/adapter.ts +77 -20
  58. package/src/llm/nodeLlamaCpp/embedding.ts +130 -46
  59. package/src/llm/nodeLlamaCpp/generation.ts +34 -5
  60. package/src/llm/nodeLlamaCpp/lifecycle-options.ts +99 -0
  61. package/src/llm/nodeLlamaCpp/lifecycle.ts +209 -204
  62. package/src/llm/nodeLlamaCpp/rerank-capacity.ts +111 -0
  63. package/src/llm/nodeLlamaCpp/rerank.ts +118 -27
  64. package/src/llm/nodeLlamaCpp/simulator-handle.ts +73 -0
  65. package/src/llm/nodeLlamaCpp/simulator-install.ts +124 -0
  66. package/src/llm/nodeLlamaCpp/simulator-session.ts +240 -0
  67. package/src/llm/nodeLlamaCpp/simulator-types.ts +80 -0
  68. package/src/llm/types.ts +35 -5
  69. package/src/mcp/context.ts +27 -0
  70. package/src/mcp/http-transport.ts +12 -10
  71. package/src/mcp/server.ts +3 -0
  72. package/src/mcp/tool-profile.ts +30 -8
  73. package/src/mcp/tools/context.ts +8 -11
  74. package/src/mcp/tools/embed.ts +1 -1
  75. package/src/mcp/tools/index-cmd.ts +1 -1
  76. package/src/mcp/tools/index.ts +10 -8
  77. package/src/mcp/tools/query.ts +14 -30
  78. package/src/mcp/tools/vsearch.ts +1 -1
  79. package/src/pipeline/answer.ts +23 -3
  80. package/src/pipeline/claim-verifier.ts +6 -0
  81. package/src/pipeline/expansion.ts +43 -40
  82. package/src/pipeline/explain.ts +6 -2
  83. package/src/pipeline/filters.ts +63 -0
  84. package/src/pipeline/fusion.ts +29 -9
  85. package/src/pipeline/graph-retrieval.ts +29 -9
  86. package/src/pipeline/hybrid.ts +198 -55
  87. package/src/pipeline/hydration.ts +161 -0
  88. package/src/pipeline/owner-fusion.ts +87 -0
  89. package/src/pipeline/rerank.ts +35 -11
  90. package/src/pipeline/search.ts +13 -2
  91. package/src/pipeline/types.ts +5 -3
  92. package/src/pipeline/vsearch.ts +87 -7
  93. package/src/sdk/client.ts +47 -3
  94. package/src/sdk/embed.ts +63 -39
  95. package/src/serve/background-runtime.ts +1 -1
  96. package/src/serve/context.ts +41 -56
  97. package/src/serve/embed-scheduler.ts +58 -35
  98. package/src/serve/public/components/IndexingProgress.tsx +46 -60
  99. package/src/serve/public/globals.built.css +1 -1
  100. package/src/serve/public/lib/shiki-language-ids.ts +14 -0
  101. package/src/serve/resident-admission.ts +36 -36
  102. package/src/serve/resident-background-work.ts +20 -2
  103. package/src/serve/resident-request.ts +11 -5
  104. package/src/serve/resident-runtime.ts +97 -61
  105. package/src/serve/resident-shutdown.ts +153 -0
  106. package/src/serve/routes/api.ts +3 -1
  107. package/src/serve/server.ts +47 -26
  108. package/src/store/migrations/028-vector-variants.ts +54 -0
  109. package/src/store/migrations/029-graph-reference-state.ts +77 -0
  110. package/src/store/migrations/index.ts +4 -0
  111. package/src/store/sqlite/adapter.ts +251 -183
  112. package/src/store/sqlite/eligibility.ts +174 -0
  113. package/src/store/sqlite/graph-edge-application.ts +66 -0
  114. package/src/store/sqlite/graph-reference-state.ts +194 -0
  115. package/src/store/sqlite/legacy-vector-ownership.ts +79 -0
  116. package/src/store/types.ts +80 -12
  117. package/src/store/vector/eligibility.ts +36 -0
  118. package/src/store/vector/freshness.ts +33 -6
  119. package/src/store/vector/lazy.ts +81 -0
  120. package/src/store/vector/sqlite-vec.ts +106 -54
  121. package/src/store/vector/stats.ts +14 -3
  122. package/src/store/vector/types.ts +35 -2
  123. package/src/store/vector/variant-search.ts +192 -0
  124. package/src/store/vector/variants.ts +451 -0
  125. package/vendor/converters/markitdown-ts/LICENSE +21 -0
  126. package/vendor/converters/markitdown-ts/dist/index.cjs +1180 -0
  127. package/vendor/converters/markitdown-ts/dist/index.d.cts +46 -0
  128. package/vendor/converters/markitdown-ts/dist/index.d.mts +46 -0
  129. package/vendor/converters/markitdown-ts/dist/index.d.ts +46 -0
  130. package/vendor/converters/markitdown-ts/dist/index.mjs +1152 -0
  131. package/vendor/converters/markitdown-ts/package.json +77 -0
  132. package/vendor/converters/officeparser/LICENSE +21 -0
  133. package/vendor/converters/officeparser/dist/OfficeConverter.d.ts +47 -0
  134. package/vendor/converters/officeparser/dist/OfficeConverter.js +76 -0
  135. package/vendor/converters/officeparser/dist/OfficeGenerator.d.ts +23 -0
  136. package/vendor/converters/officeparser/dist/OfficeGenerator.js +73 -0
  137. package/vendor/converters/officeparser/dist/OfficeParser.d.ts +106 -0
  138. package/vendor/converters/officeparser/dist/OfficeParser.js +332 -0
  139. package/vendor/converters/officeparser/dist/cli.d.ts +28 -0
  140. package/vendor/converters/officeparser/dist/cli.js +381 -0
  141. package/vendor/converters/officeparser/dist/defaults.d.ts +41 -0
  142. package/vendor/converters/officeparser/dist/defaults.js +218 -0
  143. package/vendor/converters/officeparser/dist/generators/BaseGenerator.d.ts +107 -0
  144. package/vendor/converters/officeparser/dist/generators/BaseGenerator.js +248 -0
  145. package/vendor/converters/officeparser/dist/generators/ChunkingGenerator.d.ts +82 -0
  146. package/vendor/converters/officeparser/dist/generators/ChunkingGenerator.js +797 -0
  147. package/vendor/converters/officeparser/dist/generators/CsvGenerator.d.ts +38 -0
  148. package/vendor/converters/officeparser/dist/generators/CsvGenerator.js +245 -0
  149. package/vendor/converters/officeparser/dist/generators/EpubGenerator.d.ts +43 -0
  150. package/vendor/converters/officeparser/dist/generators/EpubGenerator.js +315 -0
  151. package/vendor/converters/officeparser/dist/generators/HtmlGenerator.d.ts +59 -0
  152. package/vendor/converters/officeparser/dist/generators/HtmlGenerator.js +1942 -0
  153. package/vendor/converters/officeparser/dist/generators/MarkdownGenerator.d.ts +96 -0
  154. package/vendor/converters/officeparser/dist/generators/MarkdownGenerator.js +1175 -0
  155. package/vendor/converters/officeparser/dist/generators/PdfGenerator.d.ts +22 -0
  156. package/vendor/converters/officeparser/dist/generators/PdfGenerator.js +194 -0
  157. package/vendor/converters/officeparser/dist/generators/RtfGenerator.d.ts +29 -0
  158. package/vendor/converters/officeparser/dist/generators/RtfGenerator.js +316 -0
  159. package/vendor/converters/officeparser/dist/generators/TextGenerator.d.ts +13 -0
  160. package/vendor/converters/officeparser/dist/generators/TextGenerator.js +201 -0
  161. package/vendor/converters/officeparser/dist/index.d.ts +60 -0
  162. package/vendor/converters/officeparser/dist/index.js +72 -0
  163. package/vendor/converters/officeparser/dist/index.mjs +18 -0
  164. package/vendor/converters/officeparser/dist/officeparser.browser.d.ts +2621 -0
  165. package/vendor/converters/officeparser/dist/officeparser.browser.iife.js +1336 -0
  166. package/vendor/converters/officeparser/dist/officeparser.browser.mjs +1335 -0
  167. package/vendor/converters/officeparser/dist/officeparser.browser.slim.d.ts +2621 -0
  168. package/vendor/converters/officeparser/dist/officeparser.browser.slim.iife.js +1336 -0
  169. package/vendor/converters/officeparser/dist/officeparser.browser.slim.mjs +1335 -0
  170. package/vendor/converters/officeparser/dist/parsers/CsvParser.d.ts +9 -0
  171. package/vendor/converters/officeparser/dist/parsers/CsvParser.js +115 -0
  172. package/vendor/converters/officeparser/dist/parsers/EpubParser.d.ts +8 -0
  173. package/vendor/converters/officeparser/dist/parsers/EpubParser.js +217 -0
  174. package/vendor/converters/officeparser/dist/parsers/ExcelParser.d.ts +32 -0
  175. package/vendor/converters/officeparser/dist/parsers/ExcelParser.js +736 -0
  176. package/vendor/converters/officeparser/dist/parsers/HtmlParser.d.ts +2 -0
  177. package/vendor/converters/officeparser/dist/parsers/HtmlParser.js +1287 -0
  178. package/vendor/converters/officeparser/dist/parsers/MarkdownParser.d.ts +2 -0
  179. package/vendor/converters/officeparser/dist/parsers/MarkdownParser.js +1272 -0
  180. package/vendor/converters/officeparser/dist/parsers/OpenOfficeParser.d.ts +31 -0
  181. package/vendor/converters/officeparser/dist/parsers/OpenOfficeParser.js +1819 -0
  182. package/vendor/converters/officeparser/dist/parsers/PdfParser.d.ts +67 -0
  183. package/vendor/converters/officeparser/dist/parsers/PdfParser.js +848 -0
  184. package/vendor/converters/officeparser/dist/parsers/PowerPointParser.d.ts +32 -0
  185. package/vendor/converters/officeparser/dist/parsers/PowerPointParser.js +950 -0
  186. package/vendor/converters/officeparser/dist/parsers/RtfParser.d.ts +187 -0
  187. package/vendor/converters/officeparser/dist/parsers/RtfParser.js +1801 -0
  188. package/vendor/converters/officeparser/dist/parsers/WordParser.d.ts +79 -0
  189. package/vendor/converters/officeparser/dist/parsers/WordParser.js +1177 -0
  190. package/vendor/converters/officeparser/dist/sbom.cdx.json +1763 -0
  191. package/vendor/converters/officeparser/dist/types.d.ts +2507 -0
  192. package/vendor/converters/officeparser/dist/types.js +107 -0
  193. package/vendor/converters/officeparser/dist/utils/astUtils.d.ts +16 -0
  194. package/vendor/converters/officeparser/dist/utils/astUtils.js +33 -0
  195. package/vendor/converters/officeparser/dist/utils/chartUtils.d.ts +6 -0
  196. package/vendor/converters/officeparser/dist/utils/chartUtils.js +257 -0
  197. package/vendor/converters/officeparser/dist/utils/configUtils.d.ts +44 -0
  198. package/vendor/converters/officeparser/dist/utils/configUtils.js +315 -0
  199. package/vendor/converters/officeparser/dist/utils/dateUtils.d.ts +17 -0
  200. package/vendor/converters/officeparser/dist/utils/dateUtils.js +69 -0
  201. package/vendor/converters/officeparser/dist/utils/envUtils.d.ts +29 -0
  202. package/vendor/converters/officeparser/dist/utils/envUtils.js +152 -0
  203. package/vendor/converters/officeparser/dist/utils/errorUtils.d.ts +72 -0
  204. package/vendor/converters/officeparser/dist/utils/errorUtils.js +245 -0
  205. package/vendor/converters/officeparser/dist/utils/imageUtils.d.ts +66 -0
  206. package/vendor/converters/officeparser/dist/utils/imageUtils.js +133 -0
  207. package/vendor/converters/officeparser/dist/utils/mathUtils.d.ts +42 -0
  208. package/vendor/converters/officeparser/dist/utils/mathUtils.js +385 -0
  209. package/vendor/converters/officeparser/dist/utils/moduleLoader.d.ts +18 -0
  210. package/vendor/converters/officeparser/dist/utils/moduleLoader.js +106 -0
  211. package/vendor/converters/officeparser/dist/utils/ocrUtils.d.ts +42 -0
  212. package/vendor/converters/officeparser/dist/utils/ocrUtils.js +428 -0
  213. package/vendor/converters/officeparser/dist/utils/sanitize.d.ts +148 -0
  214. package/vendor/converters/officeparser/dist/utils/sanitize.js +344 -0
  215. package/vendor/converters/officeparser/dist/utils/sheetUtils.d.ts +7 -0
  216. package/vendor/converters/officeparser/dist/utils/sheetUtils.js +35 -0
  217. package/vendor/converters/officeparser/dist/utils/styleMapper.d.ts +36 -0
  218. package/vendor/converters/officeparser/dist/utils/styleMapper.js +224 -0
  219. package/vendor/converters/officeparser/dist/utils/xmlUtils.d.ts +163 -0
  220. package/vendor/converters/officeparser/dist/utils/xmlUtils.js +461 -0
  221. package/vendor/converters/officeparser/dist/utils/zipUtils.d.ts +134 -0
  222. package/vendor/converters/officeparser/dist/utils/zipUtils.js +337 -0
  223. package/vendor/converters/officeparser/package.json +147 -0
  224. package/vendor/converters/upstream-manifest.json +124 -0
  225. package/vendor/dependency-fixes/README.md +77 -0
  226. package/vendor/dependency-fixes/vendor-converters.py +83 -0
  227. package/browser-extension/artifacts/gno-browser-clipper-v1.46.0.zip +0 -0
  228. package/browser-extension/artifacts/gno-browser-clipper-v1.46.0.zip.sha256 +0 -1
  229. package/browser-extension/dist/chunk-627emwpj.js +0 -75
  230. /package/browser-extension/dist/{chunk-ydfx5d7p.css → chunk-z74y8n8c.css} +0 -0
@@ -0,0 +1,9 @@
1
+ import { FullOfficeParserConfig, OfficeParserAST } from '../types.js';
2
+ /**
3
+ * Parses a CSV file and extracts a single sheet with rows and cells.
4
+ *
5
+ * @param buffer - The CSV file as a Buffer
6
+ * @param config - Parser configuration
7
+ * @returns A promise resolving to the parsed AST
8
+ */
9
+ export declare const parseCsv: (buffer: Buffer, config: FullOfficeParserConfig) => Promise<OfficeParserAST>;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCsv = void 0;
4
+ const astUtils_js_1 = require("../utils/astUtils.js");
5
+ const errorUtils_js_1 = require("../utils/errorUtils.js");
6
+ /**
7
+ * Parses a CSV file and extracts a single sheet with rows and cells.
8
+ *
9
+ * @param buffer - The CSV file as a Buffer
10
+ * @param config - Parser configuration
11
+ * @returns A promise resolving to the parsed AST
12
+ */
13
+ const parseCsv = async (buffer, config) => {
14
+ // Honour cancellation requests before the character-by-character parsing loop starts.
15
+ // CSV has no OCR or async I/O, but very large files can still occupy the thread for a
16
+ // noticeable duration, so short-circuiting on an aborted signal is still worthwhile.
17
+ (0, errorUtils_js_1.checkAbortSignal)(config.abortSignal);
18
+ const textStr = buffer.toString('utf-8');
19
+ const delimiter = config.csvDelimiter;
20
+ const records = [];
21
+ let currentRow = [];
22
+ let currentCell = '';
23
+ let inQuotes = false;
24
+ for (let i = 0; i < textStr.length; i++) {
25
+ const char = textStr[i];
26
+ const nextChar = textStr[i + 1];
27
+ if (inQuotes) {
28
+ if (char === '"') {
29
+ if (nextChar === '"') {
30
+ currentCell += '"';
31
+ i++; // Skip the escaped quote
32
+ }
33
+ else {
34
+ inQuotes = false;
35
+ }
36
+ }
37
+ else {
38
+ currentCell += char;
39
+ }
40
+ }
41
+ else {
42
+ if (char === '"') {
43
+ inQuotes = true;
44
+ }
45
+ else if (textStr.substring(i, i + delimiter.length) === delimiter) {
46
+ currentRow.push(currentCell);
47
+ currentCell = '';
48
+ i += delimiter.length - 1; // Skip the rest of the delimiter
49
+ }
50
+ else if (char === '\n') {
51
+ currentRow.push(currentCell);
52
+ records.push(currentRow);
53
+ currentRow = [];
54
+ currentCell = '';
55
+ }
56
+ else if (char === '\r') {
57
+ // Ignore carriage return outside of quotes
58
+ }
59
+ else {
60
+ currentCell += char;
61
+ }
62
+ }
63
+ }
64
+ if (currentCell !== '' || currentRow.length > 0) {
65
+ currentRow.push(currentCell);
66
+ records.push(currentRow);
67
+ }
68
+ // Filter out trailing empty row if the file ended with a newline
69
+ if (records.length > 0 && records[records.length - 1].length === 1 && records[records.length - 1][0] === '') {
70
+ records.pop();
71
+ }
72
+ const rows = [];
73
+ records.forEach((record, rowIndex) => {
74
+ // Handle comment rows
75
+ if (record.length === 1 && record[0].startsWith('#')) {
76
+ rows.push({
77
+ type: 'comment',
78
+ text: record[0]
79
+ });
80
+ return;
81
+ }
82
+ const cells = [];
83
+ record.forEach((val, colIndex) => {
84
+ if (val && val.trim() !== '') {
85
+ const cellMeta = { row: rowIndex, col: colIndex };
86
+ cells.push({
87
+ type: 'cell',
88
+ text: val,
89
+ metadata: cellMeta,
90
+ children: [{ type: 'text', text: val }]
91
+ });
92
+ }
93
+ });
94
+ if (cells.length > 0) {
95
+ rows.push({
96
+ type: 'row',
97
+ children: cells
98
+ });
99
+ }
100
+ });
101
+ const sheetMeta = { sheetName: 'Sheet1' };
102
+ const sheetNode = {
103
+ type: 'sheet',
104
+ metadata: sheetMeta,
105
+ children: rows,
106
+ rawContent: config.includeRawContent ? textStr : undefined
107
+ };
108
+ const toTextSync = () => {
109
+ return records.map((record) => record.filter(cell => cell.trim() !== '').join(config.newlineDelimiter))
110
+ .join(config.newlineDelimiter)
111
+ .replace(/\n{3,}/g, '\n\n');
112
+ };
113
+ return (0, astUtils_js_1.createAST)('csv', { title: 'Sheet1' }, [sheetNode], [], config, undefined, toTextSync);
114
+ };
115
+ exports.parseCsv = parseCsv;
@@ -0,0 +1,8 @@
1
+ import { FullOfficeParserConfig, OfficeParserAST } from '../types.js';
2
+ /**
3
+ * Parses an EPUB file (a ZIP archive of XHTML content plus an OPF manifest) into the
4
+ * unified OfficeParserAST. Each spine item is parsed via the existing `HtmlParser` and
5
+ * the resulting content/attachments are concatenated in reading order - EPUB is
6
+ * essentially a sequence of XHTML documents, so there's no need for a bespoke content model.
7
+ */
8
+ export declare const parseEpub: (buffer: Buffer, config: FullOfficeParserConfig) => Promise<OfficeParserAST>;
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseEpub = void 0;
4
+ const types_js_1 = require("../types.js");
5
+ const astUtils_js_1 = require("../utils/astUtils.js");
6
+ const dateUtils_js_1 = require("../utils/dateUtils.js");
7
+ const errorUtils_js_1 = require("../utils/errorUtils.js");
8
+ const imageUtils_js_1 = require("../utils/imageUtils.js");
9
+ const xmlUtils_js_1 = require("../utils/xmlUtils.js");
10
+ const zipUtils_js_1 = require("../utils/zipUtils.js");
11
+ const HtmlParser_js_1 = require("./HtmlParser.js");
12
+ /**
13
+ * Resolves a manifest-relative href against the OPF file's directory, collapsing
14
+ * `./` and `../` segments the way a normal filesystem path resolver would.
15
+ */
16
+ const resolveOpfPath = (opfDir, href) => {
17
+ const parts = (opfDir + href).split('/');
18
+ const resolved = [];
19
+ for (const part of parts) {
20
+ if (part === '.' || part === '')
21
+ continue;
22
+ if (part === '..')
23
+ resolved.pop();
24
+ else
25
+ resolved.push(part);
26
+ }
27
+ return resolved.join('/');
28
+ };
29
+ /**
30
+ * Parses an EPUB file (a ZIP archive of XHTML content plus an OPF manifest) into the
31
+ * unified OfficeParserAST. Each spine item is parsed via the existing `HtmlParser` and
32
+ * the resulting content/attachments are concatenated in reading order - EPUB is
33
+ * essentially a sequence of XHTML documents, so there's no need for a bespoke content model.
34
+ */
35
+ const parseEpub = async (buffer, config) => {
36
+ (0, errorUtils_js_1.checkAbortSignal)(config.abortSignal);
37
+ const files = await (0, zipUtils_js_1.extractFiles)(buffer, (path) => /META-INF\/container\.xml$/i.test(path)
38
+ || /\.opf$/i.test(path)
39
+ || /\.(xhtml|html|htm)$/i.test(path)
40
+ || (!!config.extractAttachments && /\.(png|jpe?g|gif|svg|webp)$/i.test(path)), config.decompressionLimits, config);
41
+ // The OPF path is authoritative via META-INF/container.xml; fall back to scanning
42
+ // for any .opf file for malformed archives that skip the container manifest.
43
+ let opfPath;
44
+ const containerFile = files.find(f => /META-INF\/container\.xml$/i.test(f.path));
45
+ if (containerFile) {
46
+ const containerXml = (0, xmlUtils_js_1.parseXmlString)(containerFile.content.toString('utf-8'));
47
+ const rootfile = (0, xmlUtils_js_1.getFirstElementByTagName)(containerXml, 'rootfile');
48
+ opfPath = rootfile ? (0, xmlUtils_js_1.getAttribute)(rootfile, 'full-path') : undefined;
49
+ }
50
+ const opfFile = (opfPath && files.find(f => f.path === opfPath)) || files.find(f => /\.opf$/i.test(f.path));
51
+ if (!opfFile) {
52
+ throw (0, errorUtils_js_1.getOfficeError)(types_js_1.OfficeErrorType.REQUIRED_PART_MISSING, config, { fileType: 'epub', part: 'OPF package document (.opf)' });
53
+ }
54
+ const opfDir = opfFile.path.includes('/') ? opfFile.path.substring(0, opfFile.path.lastIndexOf('/') + 1) : '';
55
+ const opfXml = (0, xmlUtils_js_1.parseXmlString)(opfFile.content.toString('utf-8'));
56
+ // ─── Metadata (Dublin Core) ─────────────────────────────────────────────
57
+ const metadata = {};
58
+ const metadataEl = (0, xmlUtils_js_1.getFirstElementByTagName)(opfXml, 'metadata');
59
+ if (metadataEl) {
60
+ const nativeProps = {};
61
+ const dcText = (tag) => (0, xmlUtils_js_1.getElementsByTagName)(metadataEl, tag)[0]?.textContent || undefined;
62
+ const title = dcText('dc:title');
63
+ if (title) {
64
+ metadata.title = title;
65
+ nativeProps.title = title;
66
+ }
67
+ const creator = dcText('dc:creator');
68
+ if (creator) {
69
+ metadata.author = creator;
70
+ nativeProps.creator = creator;
71
+ }
72
+ const description = dcText('dc:description');
73
+ if (description) {
74
+ metadata.description = description;
75
+ nativeProps.description = description;
76
+ }
77
+ const subject = dcText('dc:subject');
78
+ if (subject) {
79
+ metadata.subject = subject;
80
+ nativeProps.subject = subject;
81
+ }
82
+ const dateStr = dcText('dc:date');
83
+ if (dateStr) {
84
+ nativeProps.date = dateStr;
85
+ metadata.created = (0, dateUtils_js_1.parseOfficeDate)(dateStr) || (isNaN(Date.parse(dateStr)) ? undefined : new Date(dateStr));
86
+ }
87
+ const publisher = dcText('dc:publisher');
88
+ if (publisher)
89
+ nativeProps.publisher = publisher;
90
+ const language = dcText('dc:language');
91
+ if (language)
92
+ nativeProps.language = language;
93
+ const identifier = dcText('dc:identifier');
94
+ if (identifier)
95
+ nativeProps.identifier = identifier;
96
+ // Calibre/EPUB2-style <meta name="..." content="..."> refinements
97
+ for (const metaTag of (0, xmlUtils_js_1.getElementsByTagName)(metadataEl, 'meta')) {
98
+ const name = (0, xmlUtils_js_1.getAttribute)(metaTag, 'name');
99
+ const content = (0, xmlUtils_js_1.getAttribute)(metaTag, 'content');
100
+ if (name && content)
101
+ nativeProps[name] = content;
102
+ }
103
+ if (Object.keys(nativeProps).length > 0)
104
+ metadata.nativeProperties = nativeProps;
105
+ }
106
+ // ─── Manifest: id -> {href, mediaType} ──────────────────────────────────
107
+ const manifest = new Map();
108
+ let coverImageId;
109
+ for (const item of (0, xmlUtils_js_1.getElementsByTagName)(opfXml, 'item')) {
110
+ const id = (0, xmlUtils_js_1.getAttribute)(item, 'id');
111
+ const href = (0, xmlUtils_js_1.getAttribute)(item, 'href');
112
+ const mediaType = (0, xmlUtils_js_1.getAttribute)(item, 'media-type') || '';
113
+ if (id && href)
114
+ manifest.set(id, { href, mediaType });
115
+ if (((0, xmlUtils_js_1.getAttribute)(item, 'properties') || '').split(/\s+/).includes('cover-image'))
116
+ coverImageId = id;
117
+ }
118
+ if (!coverImageId) {
119
+ // EPUB2-style cover declaration: <meta name="cover" content="{manifest id}">
120
+ const coverMeta = metadataEl && (0, xmlUtils_js_1.getElementsByTagName)(metadataEl, 'meta').find(m => (0, xmlUtils_js_1.getAttribute)(m, 'name') === 'cover');
121
+ coverImageId = coverMeta ? (0, xmlUtils_js_1.getAttribute)(coverMeta, 'content') : undefined;
122
+ }
123
+ // ─── Spine: ordered reading order of XHTML documents ────────────────────
124
+ const spineHrefs = [];
125
+ for (const itemref of (0, xmlUtils_js_1.getElementsByTagName)(opfXml, 'itemref')) {
126
+ const idref = (0, xmlUtils_js_1.getAttribute)(itemref, 'idref');
127
+ const item = idref ? manifest.get(idref) : undefined;
128
+ if (item && /html/i.test(item.mediaType))
129
+ spineHrefs.push(item.href);
130
+ }
131
+ const content = [];
132
+ const attachments = [];
133
+ // Map each in-zip image resource by its resolved path, so inline <img> references can
134
+ // be resolved to real bytes (EPUB images are separate files referenced by relative
135
+ // path, unlike DOCX's embedded parts).
136
+ const imageByPath = new Map();
137
+ if (config.extractAttachments) {
138
+ for (const [, item] of manifest) {
139
+ if (!item.mediaType.startsWith('image/'))
140
+ continue;
141
+ const p = resolveOpfPath(opfDir, item.href);
142
+ const f = files.find(ff => ff.path === p);
143
+ if (f)
144
+ imageByPath.set(p, { content: f.content, mediaType: item.mediaType });
145
+ }
146
+ }
147
+ const referencedImagePaths = new Set();
148
+ for (const href of spineHrefs) {
149
+ (0, errorUtils_js_1.checkAbortSignal)(config.abortSignal);
150
+ const xhtmlPath = resolveOpfPath(opfDir, href.split('#')[0]);
151
+ const xhtmlFile = files.find(f => f.path === xhtmlPath);
152
+ if (!xhtmlFile)
153
+ continue;
154
+ let xhtml = xhtmlFile.content.toString('utf-8');
155
+ if (config.extractAttachments && imageByPath.size > 0) {
156
+ // Inline each referenced image as a data URI so HtmlParser extracts it as an
157
+ // attachment (with a real image node linked by name) - the same treatment
158
+ // DOCX images get, and what makes the image survive conversion to any format.
159
+ const xhtmlDir = xhtmlPath.includes('/') ? xhtmlPath.substring(0, xhtmlPath.lastIndexOf('/') + 1) : '';
160
+ xhtml = xhtml.replace(/(<img\b[^>]*\bsrc=")([^"]+)(")/gi, (full, pre, src, post) => {
161
+ if (/^(data:|https?:|\/\/)/i.test(src))
162
+ return full;
163
+ const resolved = resolveOpfPath(xhtmlDir, src.split('#')[0].split('?')[0]);
164
+ const img = imageByPath.get(resolved);
165
+ if (!img)
166
+ return full;
167
+ referencedImagePaths.add(resolved);
168
+ return `${pre}data:${img.mediaType};base64,${img.content.toString('base64')}${post}`;
169
+ });
170
+ }
171
+ const chapterAst = await (0, HtmlParser_js_1.parseHtml)(Buffer.from(xhtml, 'utf-8'), config);
172
+ content.push(...chapterAst.content);
173
+ attachments.push(...chapterAst.attachments);
174
+ }
175
+ // Keep manifest images that were NOT referenced inline (e.g. cover art, or images used
176
+ // only as CSS list-style bullets) as attachments so the raw assets aren't lost - DOCX
177
+ // likewise exposes such images as attachments even without an inline image node.
178
+ if (config.extractAttachments) {
179
+ const customProperties = {};
180
+ for (const [id, item] of manifest) {
181
+ if (!item.mediaType.startsWith('image/'))
182
+ continue;
183
+ const p = resolveOpfPath(opfDir, item.href);
184
+ const img = imageByPath.get(p);
185
+ if (!img || referencedImagePaths.has(p))
186
+ continue;
187
+ const attachment = (0, imageUtils_js_1.createAttachment)(item.href.split('/').pop() || item.href, img.content);
188
+ attachments.push(attachment);
189
+ if (id === coverImageId)
190
+ customProperties.coverImageName = attachment.name;
191
+ }
192
+ if (Object.keys(customProperties).length > 0) {
193
+ metadata.customProperties = { ...metadata.customProperties, ...customProperties };
194
+ }
195
+ }
196
+ const toTextSync = () => content.map(n => {
197
+ const getText = (node) => {
198
+ if (node.type === 'text' || node.type === 'code')
199
+ return node.text || '';
200
+ if (node.type === 'break')
201
+ return '\n';
202
+ if (node.type === 'embed')
203
+ return node.metadata?.url || '';
204
+ if (node.type === 'image')
205
+ return node.metadata?.altText || '';
206
+ if (node.children) {
207
+ const isBlock = ['table', 'row', 'list', 'sheet', 'slide', 'admonition'].includes(node.type);
208
+ return node.children.map(getText).join(isBlock ? config.newlineDelimiter : '');
209
+ }
210
+ return '';
211
+ };
212
+ return getText(n);
213
+ }).join(config.newlineDelimiter)
214
+ .replace(/\n{3,}/g, '\n\n');
215
+ return (0, astUtils_js_1.createAST)('epub', metadata, content, attachments, config, undefined, toTextSync);
216
+ };
217
+ exports.parseEpub = parseEpub;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Excel Spreadsheet (XLSX) Parser
3
+ *
4
+ * **XLSX Format Overview:**
5
+ * XLSX is the default format for Microsoft Excel since Office 2007, based on OOXML.
6
+ *
7
+ * **File Structure:**
8
+ * - `xl/workbook.xml` - Workbook structure and sheet list
9
+ * - `xl/worksheets/sheet1.xml` - Individual sheet data
10
+ * - `xl/sharedStrings.xml` - Shared string table (cell text)
11
+ * - `xl/styles.xml` - Cell styling information
12
+ * - `xl/drawings/*` - Charts and drawings
13
+ * - `xl/media/*` - Embedded images
14
+ *
15
+ * **Key Elements:**
16
+ * - `<row>` - Table row with row index
17
+ * - `<c r="A1">` - Cell with reference (A1, B2, etc.)
18
+ * - `<v>` - Cell value (number or shared string index)
19
+ * - `<t="s">` - Cell type (s=string, n=number, b=boolean)
20
+ *
21
+ * @module ExcelParser
22
+ * @see https://www.ecma-international.org/publications-and-standards/standards/ecma-376/
23
+ */
24
+ import { FullOfficeParserConfig, OfficeParserAST } from '../types.js';
25
+ /**
26
+ * Parses an Excel spreadsheet (.xlsx) and extracts sheets, rows, and cells.
27
+ *
28
+ * @param buffer - The XLSX file as a Buffer
29
+ * @param config - Parser configuration
30
+ * @returns A promise resolving to the parsed AST
31
+ */
32
+ export declare const parseExcel: (buffer: Buffer, config: FullOfficeParserConfig) => Promise<OfficeParserAST>;