@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.
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES.md +46 -0
- package/assets/skill/SKILL.md +7 -6
- package/assets/skill/cli-reference.md +14 -6
- package/assets/skill/mcp-reference.md +4 -1
- package/assets/spa-production.json.gz +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.0.0.zip +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.0.0.zip.sha256 +1 -0
- package/browser-extension/dist/chunk-4tc9v0ja.js +74 -0
- package/browser-extension/dist/manifest.json +1 -1
- package/browser-extension/dist/preview.html +1 -1
- package/browser-extension/dist/service-worker.js +32 -33
- package/bunfig.toml +2 -0
- package/package.json +40 -26
- package/spec/cli.md +30 -11
- package/spec/db/schema.sql +146 -1
- package/spec/mcp.md +26 -0
- package/src/app/context-runtime-types.ts +3 -0
- package/src/app/context-runtime.ts +2 -0
- package/src/cli/commands/ask.ts +6 -1
- package/src/cli/commands/daemon.ts +21 -8
- package/src/cli/commands/embed.ts +77 -41
- package/src/cli/commands/mcp/install.ts +20 -0
- package/src/cli/commands/mcp/paths.ts +25 -0
- package/src/cli/commands/mcp/status.ts +6 -0
- package/src/cli/detach.ts +3 -2
- package/src/cli/program.ts +6 -0
- package/src/config/types.ts +3 -3
- package/src/converters/adapters/markitdownTs/adapter.ts +1 -2
- package/src/converters/adapters/officeparser/adapter.ts +1 -2
- package/src/converters/versions.ts +6 -8
- package/src/core/context-evidence.ts +8 -4
- package/src/core/job-manager.ts +95 -13
- package/src/core/network-boundary-inventory.ts +10 -0
- package/src/core/shutdown-budget.ts +45 -0
- package/src/embed/backlog.ts +107 -4
- package/src/embed/batch.ts +42 -2
- package/src/embed/fingerprint.ts +16 -0
- package/src/embed/retry.ts +113 -5
- package/src/embed/variant-backlog.ts +105 -0
- package/src/embed/variant-plan.ts +62 -0
- package/src/embed/variant-retry.ts +113 -0
- package/src/ingestion/graph-reconciliation.ts +327 -0
- package/src/ingestion/sync.ts +9 -272
- package/src/llm/http-inference.ts +6 -0
- package/src/llm/httpEmbedding.ts +37 -6
- package/src/llm/httpGeneration.ts +18 -3
- package/src/llm/httpRerank.ts +23 -5
- package/src/llm/inference-cancellation.ts +168 -0
- package/src/llm/inference-scope.ts +202 -0
- package/src/llm/lazy-ports.ts +115 -0
- package/src/llm/native-worker/client.ts +541 -0
- package/src/llm/native-worker/dispatcher.ts +228 -0
- package/src/llm/native-worker/embedding-identity.ts +33 -0
- package/src/llm/native-worker/entry.ts +173 -0
- package/src/llm/native-worker/errors.ts +32 -0
- package/src/llm/native-worker/evaluation.ts +16 -0
- package/src/llm/native-worker/owned-exit.ts +108 -0
- package/src/llm/native-worker/owner.ts +141 -0
- package/src/llm/native-worker/ports.ts +317 -0
- package/src/llm/native-worker/protocol.ts +442 -0
- package/src/llm/native-worker/runtime-config.ts +92 -0
- package/src/llm/nodeLlamaCpp/adapter.ts +77 -20
- package/src/llm/nodeLlamaCpp/embedding.ts +130 -46
- package/src/llm/nodeLlamaCpp/generation.ts +34 -5
- package/src/llm/nodeLlamaCpp/lifecycle-options.ts +99 -0
- package/src/llm/nodeLlamaCpp/lifecycle.ts +209 -204
- package/src/llm/nodeLlamaCpp/rerank-capacity.ts +111 -0
- package/src/llm/nodeLlamaCpp/rerank.ts +118 -27
- package/src/llm/nodeLlamaCpp/simulator-handle.ts +73 -0
- package/src/llm/nodeLlamaCpp/simulator-install.ts +124 -0
- package/src/llm/nodeLlamaCpp/simulator-session.ts +240 -0
- package/src/llm/nodeLlamaCpp/simulator-types.ts +80 -0
- package/src/llm/types.ts +35 -5
- package/src/mcp/context.ts +27 -0
- package/src/mcp/http-transport.ts +12 -10
- package/src/mcp/server.ts +3 -0
- package/src/mcp/tool-profile.ts +30 -8
- package/src/mcp/tools/context.ts +8 -11
- package/src/mcp/tools/embed.ts +1 -1
- package/src/mcp/tools/index-cmd.ts +1 -1
- package/src/mcp/tools/index.ts +10 -8
- package/src/mcp/tools/query.ts +14 -30
- package/src/mcp/tools/vsearch.ts +1 -1
- package/src/pipeline/answer.ts +23 -3
- package/src/pipeline/claim-verifier.ts +6 -0
- package/src/pipeline/expansion.ts +43 -40
- package/src/pipeline/explain.ts +6 -2
- package/src/pipeline/filters.ts +63 -0
- package/src/pipeline/fusion.ts +29 -9
- package/src/pipeline/graph-retrieval.ts +29 -9
- package/src/pipeline/hybrid.ts +198 -55
- package/src/pipeline/hydration.ts +161 -0
- package/src/pipeline/owner-fusion.ts +87 -0
- package/src/pipeline/rerank.ts +35 -11
- package/src/pipeline/search.ts +13 -2
- package/src/pipeline/types.ts +5 -3
- package/src/pipeline/vsearch.ts +87 -7
- package/src/sdk/client.ts +47 -3
- package/src/sdk/embed.ts +63 -39
- package/src/serve/background-runtime.ts +1 -1
- package/src/serve/context.ts +41 -56
- package/src/serve/embed-scheduler.ts +58 -35
- package/src/serve/public/components/IndexingProgress.tsx +46 -60
- package/src/serve/public/globals.built.css +1 -1
- package/src/serve/public/lib/shiki-language-ids.ts +14 -0
- package/src/serve/resident-admission.ts +36 -36
- package/src/serve/resident-background-work.ts +20 -2
- package/src/serve/resident-request.ts +11 -5
- package/src/serve/resident-runtime.ts +97 -61
- package/src/serve/resident-shutdown.ts +153 -0
- package/src/serve/routes/api.ts +3 -1
- package/src/serve/server.ts +47 -26
- package/src/store/migrations/028-vector-variants.ts +54 -0
- package/src/store/migrations/029-graph-reference-state.ts +77 -0
- package/src/store/migrations/index.ts +4 -0
- package/src/store/sqlite/adapter.ts +251 -183
- package/src/store/sqlite/eligibility.ts +174 -0
- package/src/store/sqlite/graph-edge-application.ts +66 -0
- package/src/store/sqlite/graph-reference-state.ts +194 -0
- package/src/store/sqlite/legacy-vector-ownership.ts +79 -0
- package/src/store/types.ts +80 -12
- package/src/store/vector/eligibility.ts +36 -0
- package/src/store/vector/freshness.ts +33 -6
- package/src/store/vector/lazy.ts +81 -0
- package/src/store/vector/sqlite-vec.ts +106 -54
- package/src/store/vector/stats.ts +14 -3
- package/src/store/vector/types.ts +35 -2
- package/src/store/vector/variant-search.ts +192 -0
- package/src/store/vector/variants.ts +451 -0
- package/vendor/converters/markitdown-ts/LICENSE +21 -0
- package/vendor/converters/markitdown-ts/dist/index.cjs +1180 -0
- package/vendor/converters/markitdown-ts/dist/index.d.cts +46 -0
- package/vendor/converters/markitdown-ts/dist/index.d.mts +46 -0
- package/vendor/converters/markitdown-ts/dist/index.d.ts +46 -0
- package/vendor/converters/markitdown-ts/dist/index.mjs +1152 -0
- package/vendor/converters/markitdown-ts/package.json +77 -0
- package/vendor/converters/officeparser/LICENSE +21 -0
- package/vendor/converters/officeparser/dist/OfficeConverter.d.ts +47 -0
- package/vendor/converters/officeparser/dist/OfficeConverter.js +76 -0
- package/vendor/converters/officeparser/dist/OfficeGenerator.d.ts +23 -0
- package/vendor/converters/officeparser/dist/OfficeGenerator.js +73 -0
- package/vendor/converters/officeparser/dist/OfficeParser.d.ts +106 -0
- package/vendor/converters/officeparser/dist/OfficeParser.js +332 -0
- package/vendor/converters/officeparser/dist/cli.d.ts +28 -0
- package/vendor/converters/officeparser/dist/cli.js +381 -0
- package/vendor/converters/officeparser/dist/defaults.d.ts +41 -0
- package/vendor/converters/officeparser/dist/defaults.js +218 -0
- package/vendor/converters/officeparser/dist/generators/BaseGenerator.d.ts +107 -0
- package/vendor/converters/officeparser/dist/generators/BaseGenerator.js +248 -0
- package/vendor/converters/officeparser/dist/generators/ChunkingGenerator.d.ts +82 -0
- package/vendor/converters/officeparser/dist/generators/ChunkingGenerator.js +797 -0
- package/vendor/converters/officeparser/dist/generators/CsvGenerator.d.ts +38 -0
- package/vendor/converters/officeparser/dist/generators/CsvGenerator.js +245 -0
- package/vendor/converters/officeparser/dist/generators/EpubGenerator.d.ts +43 -0
- package/vendor/converters/officeparser/dist/generators/EpubGenerator.js +315 -0
- package/vendor/converters/officeparser/dist/generators/HtmlGenerator.d.ts +59 -0
- package/vendor/converters/officeparser/dist/generators/HtmlGenerator.js +1942 -0
- package/vendor/converters/officeparser/dist/generators/MarkdownGenerator.d.ts +96 -0
- package/vendor/converters/officeparser/dist/generators/MarkdownGenerator.js +1175 -0
- package/vendor/converters/officeparser/dist/generators/PdfGenerator.d.ts +22 -0
- package/vendor/converters/officeparser/dist/generators/PdfGenerator.js +194 -0
- package/vendor/converters/officeparser/dist/generators/RtfGenerator.d.ts +29 -0
- package/vendor/converters/officeparser/dist/generators/RtfGenerator.js +316 -0
- package/vendor/converters/officeparser/dist/generators/TextGenerator.d.ts +13 -0
- package/vendor/converters/officeparser/dist/generators/TextGenerator.js +201 -0
- package/vendor/converters/officeparser/dist/index.d.ts +60 -0
- package/vendor/converters/officeparser/dist/index.js +72 -0
- package/vendor/converters/officeparser/dist/index.mjs +18 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.d.ts +2621 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.iife.js +1336 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.mjs +1335 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.slim.d.ts +2621 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.slim.iife.js +1336 -0
- package/vendor/converters/officeparser/dist/officeparser.browser.slim.mjs +1335 -0
- package/vendor/converters/officeparser/dist/parsers/CsvParser.d.ts +9 -0
- package/vendor/converters/officeparser/dist/parsers/CsvParser.js +115 -0
- package/vendor/converters/officeparser/dist/parsers/EpubParser.d.ts +8 -0
- package/vendor/converters/officeparser/dist/parsers/EpubParser.js +217 -0
- package/vendor/converters/officeparser/dist/parsers/ExcelParser.d.ts +32 -0
- package/vendor/converters/officeparser/dist/parsers/ExcelParser.js +736 -0
- package/vendor/converters/officeparser/dist/parsers/HtmlParser.d.ts +2 -0
- package/vendor/converters/officeparser/dist/parsers/HtmlParser.js +1287 -0
- package/vendor/converters/officeparser/dist/parsers/MarkdownParser.d.ts +2 -0
- package/vendor/converters/officeparser/dist/parsers/MarkdownParser.js +1272 -0
- package/vendor/converters/officeparser/dist/parsers/OpenOfficeParser.d.ts +31 -0
- package/vendor/converters/officeparser/dist/parsers/OpenOfficeParser.js +1819 -0
- package/vendor/converters/officeparser/dist/parsers/PdfParser.d.ts +67 -0
- package/vendor/converters/officeparser/dist/parsers/PdfParser.js +848 -0
- package/vendor/converters/officeparser/dist/parsers/PowerPointParser.d.ts +32 -0
- package/vendor/converters/officeparser/dist/parsers/PowerPointParser.js +950 -0
- package/vendor/converters/officeparser/dist/parsers/RtfParser.d.ts +187 -0
- package/vendor/converters/officeparser/dist/parsers/RtfParser.js +1801 -0
- package/vendor/converters/officeparser/dist/parsers/WordParser.d.ts +79 -0
- package/vendor/converters/officeparser/dist/parsers/WordParser.js +1177 -0
- package/vendor/converters/officeparser/dist/sbom.cdx.json +1763 -0
- package/vendor/converters/officeparser/dist/types.d.ts +2507 -0
- package/vendor/converters/officeparser/dist/types.js +107 -0
- package/vendor/converters/officeparser/dist/utils/astUtils.d.ts +16 -0
- package/vendor/converters/officeparser/dist/utils/astUtils.js +33 -0
- package/vendor/converters/officeparser/dist/utils/chartUtils.d.ts +6 -0
- package/vendor/converters/officeparser/dist/utils/chartUtils.js +257 -0
- package/vendor/converters/officeparser/dist/utils/configUtils.d.ts +44 -0
- package/vendor/converters/officeparser/dist/utils/configUtils.js +315 -0
- package/vendor/converters/officeparser/dist/utils/dateUtils.d.ts +17 -0
- package/vendor/converters/officeparser/dist/utils/dateUtils.js +69 -0
- package/vendor/converters/officeparser/dist/utils/envUtils.d.ts +29 -0
- package/vendor/converters/officeparser/dist/utils/envUtils.js +152 -0
- package/vendor/converters/officeparser/dist/utils/errorUtils.d.ts +72 -0
- package/vendor/converters/officeparser/dist/utils/errorUtils.js +245 -0
- package/vendor/converters/officeparser/dist/utils/imageUtils.d.ts +66 -0
- package/vendor/converters/officeparser/dist/utils/imageUtils.js +133 -0
- package/vendor/converters/officeparser/dist/utils/mathUtils.d.ts +42 -0
- package/vendor/converters/officeparser/dist/utils/mathUtils.js +385 -0
- package/vendor/converters/officeparser/dist/utils/moduleLoader.d.ts +18 -0
- package/vendor/converters/officeparser/dist/utils/moduleLoader.js +106 -0
- package/vendor/converters/officeparser/dist/utils/ocrUtils.d.ts +42 -0
- package/vendor/converters/officeparser/dist/utils/ocrUtils.js +428 -0
- package/vendor/converters/officeparser/dist/utils/sanitize.d.ts +148 -0
- package/vendor/converters/officeparser/dist/utils/sanitize.js +344 -0
- package/vendor/converters/officeparser/dist/utils/sheetUtils.d.ts +7 -0
- package/vendor/converters/officeparser/dist/utils/sheetUtils.js +35 -0
- package/vendor/converters/officeparser/dist/utils/styleMapper.d.ts +36 -0
- package/vendor/converters/officeparser/dist/utils/styleMapper.js +224 -0
- package/vendor/converters/officeparser/dist/utils/xmlUtils.d.ts +163 -0
- package/vendor/converters/officeparser/dist/utils/xmlUtils.js +461 -0
- package/vendor/converters/officeparser/dist/utils/zipUtils.d.ts +134 -0
- package/vendor/converters/officeparser/dist/utils/zipUtils.js +337 -0
- package/vendor/converters/officeparser/package.json +147 -0
- package/vendor/converters/upstream-manifest.json +124 -0
- package/vendor/dependency-fixes/README.md +77 -0
- package/vendor/dependency-fixes/vendor-converters.py +83 -0
- package/browser-extension/artifacts/gno-browser-clipper-v1.45.1.zip +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v1.45.1.zip.sha256 +0 -1
- package/browser-extension/dist/chunk-627emwpj.js +0 -75
- /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;
|