@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.
- package/README.md +1 -1
- package/THIRD_PARTY_NOTICES.md +46 -0
- package/assets/skill/SKILL.md +7 -6
- 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 +21 -4
- 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/detach.ts +3 -2
- 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.46.0.zip +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v1.46.0.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,315 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFullGeneratorConfig = isFullGeneratorConfig;
|
|
4
|
+
exports.isFullParserConfig = isFullParserConfig;
|
|
5
|
+
exports.resolveParserConfig = resolveParserConfig;
|
|
6
|
+
exports.resolveGeneratorConfig = resolveGeneratorConfig;
|
|
7
|
+
exports.isValidContainerWidth = isValidContainerWidth;
|
|
8
|
+
const defaults_js_1 = require("../defaults.js");
|
|
9
|
+
const types_js_1 = require("../types.js");
|
|
10
|
+
const errorUtils_js_1 = require("./errorUtils.js");
|
|
11
|
+
/**
|
|
12
|
+
* Keys that must never be copied from a caller-supplied config onto one of our objects.
|
|
13
|
+
*
|
|
14
|
+
* A config that arrived via `JSON.parse` can carry `__proto__` as a genuine **own enumerable**
|
|
15
|
+
* property (an object *literal* cannot - there `__proto__` invokes the setter at parse time),
|
|
16
|
+
* which is exactly the shape of a host application accepting a JSON config blob. Copying that
|
|
17
|
+
* key reaches `Object.prototype` and corrupts every object in the process.
|
|
18
|
+
*
|
|
19
|
+
* `constructor` and `prototype` are included because they are the other two names that reach a
|
|
20
|
+
* prototype through an ordinary property write.
|
|
21
|
+
*/
|
|
22
|
+
const PROTOTYPE_POLLUTION_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
23
|
+
/**
|
|
24
|
+
* Returns a copy of `source` with prototype-reaching keys removed.
|
|
25
|
+
*
|
|
26
|
+
* Needed before `Object.assign`, which does **not** pollute `Object.prototype` (it writes via
|
|
27
|
+
* `[[Set]]`, so `__proto__` invokes the inherited setter rather than creating an own property) -
|
|
28
|
+
* but that setter is not inert: it **replaces the target's prototype**, so the returned config
|
|
29
|
+
* silently inherits attacker-chosen properties for every field the defaults don't set as an own
|
|
30
|
+
* property. Narrower than global pollution, still wrong. Do not "simplify" this away on the
|
|
31
|
+
* grounds that `Object.assign` is safe; it is safe only against the *global* variant.
|
|
32
|
+
*/
|
|
33
|
+
function withoutPrototypeKeys(source) {
|
|
34
|
+
const safe = {};
|
|
35
|
+
for (const key of Object.keys(source)) {
|
|
36
|
+
if (PROTOTYPE_POLLUTION_KEYS.has(key))
|
|
37
|
+
continue;
|
|
38
|
+
safe[key] = source[key];
|
|
39
|
+
}
|
|
40
|
+
return safe;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Deep clones an object, specifically handling arrays and plain objects.
|
|
44
|
+
*/
|
|
45
|
+
function deepClone(obj) {
|
|
46
|
+
if (obj === null || typeof obj !== 'object') {
|
|
47
|
+
return obj;
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(obj)) {
|
|
50
|
+
return obj.map((item) => deepClone(item));
|
|
51
|
+
}
|
|
52
|
+
const cloned = {};
|
|
53
|
+
for (const key in obj) {
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
55
|
+
cloned[key] = deepClone(obj[key]);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return cloned;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Checks if a configuration object is a FullGeneratorConfig.
|
|
62
|
+
*/
|
|
63
|
+
function isFullGeneratorConfig(config) {
|
|
64
|
+
return !!(config &&
|
|
65
|
+
typeof config === 'object' &&
|
|
66
|
+
'textConfig' in config &&
|
|
67
|
+
'htmlConfig' in config &&
|
|
68
|
+
'pdfConfig' in config &&
|
|
69
|
+
'csvConfig' in config &&
|
|
70
|
+
'onNode' in config);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Checks if a configuration object is a FullOfficeParserConfig.
|
|
74
|
+
*/
|
|
75
|
+
function isFullParserConfig(config) {
|
|
76
|
+
return !!(config &&
|
|
77
|
+
typeof config === 'object' &&
|
|
78
|
+
'ocrConfig' in config &&
|
|
79
|
+
typeof config.ocrConfig === 'object' &&
|
|
80
|
+
'language' in config.ocrConfig &&
|
|
81
|
+
'workerPath' in config.ocrConfig);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resolves a full parser configuration by merging defaults and user-provided overrides.
|
|
85
|
+
*
|
|
86
|
+
* The returned object always belongs solely to the caller of this function. That matters
|
|
87
|
+
* because a parse installs per-call state on the config it is handed, such as the collector
|
|
88
|
+
* that gathers warnings for one document's `ast.warnings`. Returning the caller's own object
|
|
89
|
+
* would attach that state to an object they may reuse, so a second parse would append its
|
|
90
|
+
* warnings to the first document's already-returned AST, and each parse would retain the
|
|
91
|
+
* previous one's state for as long as the config lived.
|
|
92
|
+
*
|
|
93
|
+
* Only the configuration containers are copied. Callbacks and `abortSignal` keep their
|
|
94
|
+
* identity, since a copy of an `AbortSignal` would no longer be tied to its controller.
|
|
95
|
+
*
|
|
96
|
+
* @param userConfig - Optional configuration provided by the user
|
|
97
|
+
* @returns A fully populated configuration object, owned by the caller
|
|
98
|
+
*/
|
|
99
|
+
function resolveParserConfig(userConfig) {
|
|
100
|
+
if (isFullParserConfig(userConfig)) {
|
|
101
|
+
const resolved = { ...userConfig };
|
|
102
|
+
resolved.ocrConfig = { ...userConfig.ocrConfig };
|
|
103
|
+
if (userConfig.ocrConfig?.timeout) {
|
|
104
|
+
resolved.ocrConfig.timeout = { ...userConfig.ocrConfig.timeout };
|
|
105
|
+
}
|
|
106
|
+
resolved.decompressionLimits = {
|
|
107
|
+
...(userConfig.decompressionLimits ?? defaults_js_1.DEFAULT_OFFICE_PARSER_CONFIG.decompressionLimits)
|
|
108
|
+
};
|
|
109
|
+
if (userConfig.htmlParserConfig) {
|
|
110
|
+
resolved.htmlParserConfig = { ...userConfig.htmlParserConfig };
|
|
111
|
+
}
|
|
112
|
+
return resolved;
|
|
113
|
+
}
|
|
114
|
+
// 1. Start with full defaults (deep cloned)
|
|
115
|
+
const config = deepClone(defaults_js_1.DEFAULT_OFFICE_PARSER_CONFIG);
|
|
116
|
+
if (!userConfig) {
|
|
117
|
+
return config;
|
|
118
|
+
}
|
|
119
|
+
// 2. Merge user config
|
|
120
|
+
// We handle ocrConfig, decompressionLimits, and htmlParserConfig specially to avoid
|
|
121
|
+
// shallow-overwriting the whole nested objects
|
|
122
|
+
const { ocrConfig, decompressionLimits, htmlParserConfig, ...rest } = userConfig;
|
|
123
|
+
Object.assign(config, withoutPrototypeKeys(rest));
|
|
124
|
+
if (decompressionLimits) {
|
|
125
|
+
config.decompressionLimits = {
|
|
126
|
+
...config.decompressionLimits,
|
|
127
|
+
...decompressionLimits,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
if (htmlParserConfig) {
|
|
131
|
+
config.htmlParserConfig = {
|
|
132
|
+
...config.htmlParserConfig,
|
|
133
|
+
...htmlParserConfig,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (ocrConfig) {
|
|
137
|
+
const { timeout, ...ocrRest } = ocrConfig;
|
|
138
|
+
config.ocrConfig = {
|
|
139
|
+
...config.ocrConfig,
|
|
140
|
+
...ocrRest,
|
|
141
|
+
timeout: {
|
|
142
|
+
autoTerminate: timeout?.autoTerminate !== undefined ? timeout.autoTerminate : config.ocrConfig.timeout.autoTerminate,
|
|
143
|
+
workerLoad: timeout?.workerLoad !== undefined ? timeout.workerLoad : config.ocrConfig.timeout.workerLoad,
|
|
144
|
+
recognition: timeout?.recognition !== undefined ? timeout.recognition : config.ocrConfig.timeout.recognition,
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// 3. Handle legacy ocrLanguage mapping if not explicitly set in ocrConfig
|
|
149
|
+
if (userConfig.ocrLanguage && !userConfig.ocrConfig?.language) {
|
|
150
|
+
config.ocrConfig.language = userConfig.ocrLanguage;
|
|
151
|
+
}
|
|
152
|
+
// 4. Propagate the top-level abortSignal to ocrConfig so the OCR subsystem is aware of it
|
|
153
|
+
if (config.abortSignal) {
|
|
154
|
+
config.ocrConfig.abortSignal = config.abortSignal;
|
|
155
|
+
}
|
|
156
|
+
return config;
|
|
157
|
+
}
|
|
158
|
+
/** The per-destination and metadata sub-objects a generator config groups its settings into. */
|
|
159
|
+
const GENERATOR_CONFIG_CONTAINERS = [
|
|
160
|
+
'metadataOverrides', 'htmlConfig', 'mdConfig', 'pdfConfig',
|
|
161
|
+
'csvConfig', 'textConfig', 'rtfConfig', 'chunksConfig',
|
|
162
|
+
];
|
|
163
|
+
/**
|
|
164
|
+
* Copies a generator config's containers so writes during generation cannot reach the caller.
|
|
165
|
+
*
|
|
166
|
+
* One level is enough: the containers are what generation writes to. Everything else is copied
|
|
167
|
+
* by reference on purpose, since callbacks, `styleMap` and `abortSignal` are values whose
|
|
168
|
+
* identity matters, and a duplicated `AbortSignal` would no longer be tied to its controller.
|
|
169
|
+
*
|
|
170
|
+
* @param source - The caller's configuration
|
|
171
|
+
* @returns An equivalent configuration owned by us
|
|
172
|
+
*/
|
|
173
|
+
function copyGeneratorConfigContainers(source) {
|
|
174
|
+
const copy = { ...source };
|
|
175
|
+
for (const key of GENERATOR_CONFIG_CONTAINERS) {
|
|
176
|
+
const container = source[key];
|
|
177
|
+
if (container && typeof container === 'object')
|
|
178
|
+
copy[key] = { ...container };
|
|
179
|
+
}
|
|
180
|
+
return copy;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Resolves a full, destination-specific configuration by merging defaults,
|
|
184
|
+
* AST-level settings, and user-provided overrides.
|
|
185
|
+
*
|
|
186
|
+
* As with {@link resolveParserConfig}, the returned object belongs solely to the caller of this
|
|
187
|
+
* function, so that per-run normalization cannot edit a config the caller still holds.
|
|
188
|
+
*
|
|
189
|
+
* @param destination - The target format
|
|
190
|
+
* @param userConfig - Optional configuration provided by the user
|
|
191
|
+
* @param astConfig - Optional configuration from the source AST (for inheritance)
|
|
192
|
+
* @returns A fully populated configuration object, owned by the caller
|
|
193
|
+
*/
|
|
194
|
+
function resolveGeneratorConfig(destination, astConfig, userConfig) {
|
|
195
|
+
// Already complete, so nothing to merge. Still copied rather than handed straight back, for
|
|
196
|
+
// the same reason as resolveParserConfig: generation writes to the config it is given. The
|
|
197
|
+
// width check below normalizes an invalid `containerWidth` to 'auto', and doing that to the
|
|
198
|
+
// caller's own object both edits a value they still hold and silences the warning on every
|
|
199
|
+
// later run, so the same config would report a problem once and then appear clean.
|
|
200
|
+
if (isFullGeneratorConfig(userConfig) && !astConfig) {
|
|
201
|
+
const resolved = copyGeneratorConfigContainers(userConfig);
|
|
202
|
+
validateHtmlConfigWidth(resolved.htmlConfig, resolved);
|
|
203
|
+
return resolved;
|
|
204
|
+
}
|
|
205
|
+
// 1. Start with full defaults (deep cloned to avoid reference sharing)
|
|
206
|
+
const config = deepClone(defaults_js_1.DEFAULT_GENERATOR_CONFIG);
|
|
207
|
+
// 2. Merge common properties and sub-configs
|
|
208
|
+
if (userConfig) {
|
|
209
|
+
// Extract sub-configs to avoid shallow-overwriting the whole sub-config objects
|
|
210
|
+
const { htmlConfig, mdConfig, pdfConfig, csvConfig, textConfig, rtfConfig, chunksConfig, ...commonProps } = userConfig;
|
|
211
|
+
Object.assign(config, withoutPrototypeKeys(commonProps));
|
|
212
|
+
// Merge sub-configs individually, ignoring undefined properties to preserve defaults
|
|
213
|
+
const mergeSubConfig = (target, source) => {
|
|
214
|
+
if (!source)
|
|
215
|
+
return;
|
|
216
|
+
for (const key in source) {
|
|
217
|
+
// Both guards are load-bearing and neither subsumes the other. The own-property
|
|
218
|
+
// check (matching deepClone above) stops inherited enumerable properties, which
|
|
219
|
+
// matters once anything else in the process has already polluted a prototype. It
|
|
220
|
+
// does NOT stop this attack on its own: `JSON.parse('{"__proto__":{...}}')` yields
|
|
221
|
+
// `__proto__` as an own enumerable key, so it passes hasOwnProperty and would be
|
|
222
|
+
// written straight through to Object.prototype by the recursion below.
|
|
223
|
+
if (!Object.prototype.hasOwnProperty.call(source, key))
|
|
224
|
+
continue;
|
|
225
|
+
if (PROTOTYPE_POLLUTION_KEYS.has(key))
|
|
226
|
+
continue;
|
|
227
|
+
if (source[key] !== undefined) {
|
|
228
|
+
// Deep merge plain objects (like injections or margin)
|
|
229
|
+
if (typeof source[key] === 'object' &&
|
|
230
|
+
source[key] !== null &&
|
|
231
|
+
!Array.isArray(source[key]) &&
|
|
232
|
+
!(source[key] instanceof Function) &&
|
|
233
|
+
!(source[key] instanceof Date) &&
|
|
234
|
+
!(source[key] instanceof RegExp) &&
|
|
235
|
+
!(source[key] instanceof Buffer)) {
|
|
236
|
+
if (!target[key] || typeof target[key] !== 'object') {
|
|
237
|
+
target[key] = {};
|
|
238
|
+
}
|
|
239
|
+
mergeSubConfig(target[key], source[key]);
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
target[key] = source[key];
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
if (htmlConfig)
|
|
248
|
+
mergeSubConfig(config.htmlConfig, htmlConfig);
|
|
249
|
+
if (mdConfig)
|
|
250
|
+
mergeSubConfig(config.mdConfig, mdConfig);
|
|
251
|
+
if (pdfConfig)
|
|
252
|
+
mergeSubConfig(config.pdfConfig, pdfConfig);
|
|
253
|
+
if (csvConfig)
|
|
254
|
+
mergeSubConfig(config.csvConfig, csvConfig);
|
|
255
|
+
if (textConfig)
|
|
256
|
+
mergeSubConfig(config.textConfig, textConfig);
|
|
257
|
+
if (rtfConfig)
|
|
258
|
+
mergeSubConfig(config.rtfConfig, rtfConfig);
|
|
259
|
+
if (chunksConfig)
|
|
260
|
+
mergeSubConfig(config.chunksConfig, chunksConfig);
|
|
261
|
+
}
|
|
262
|
+
// 3. Inherit from AST config if not explicitly provided
|
|
263
|
+
if (astConfig) {
|
|
264
|
+
if (userConfig?.onWarning === undefined) {
|
|
265
|
+
config.onWarning = astConfig.onWarning || config.onWarning;
|
|
266
|
+
}
|
|
267
|
+
// Inherit newlineDelimiter for text-based generators
|
|
268
|
+
const astNewline = astConfig.newlineDelimiter;
|
|
269
|
+
if (astNewline && ['text', 'md', 'rtf'].includes(destination)) {
|
|
270
|
+
// If user didn't specify a newline delimiter in their specific config, use AST's
|
|
271
|
+
if (destination === 'text' && userConfig?.textConfig?.newlineDelimiter === undefined) {
|
|
272
|
+
config.textConfig.newlineDelimiter = astNewline;
|
|
273
|
+
}
|
|
274
|
+
// For MD and RTF, they use common newline settings or internal defaults.
|
|
275
|
+
// We ensure the resolved config reflects this if possible, or generators can check astConfig directly.
|
|
276
|
+
// Since FullGeneratorConfig doesn't have an 'mdConfig', we rely on the generator implementation.
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
validateHtmlConfigWidth(config.htmlConfig, config);
|
|
280
|
+
return config;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Validates the containerWidth option for HTML generation.
|
|
284
|
+
* Can be 'auto', a positive number, or a positive CSS length/percentage string.
|
|
285
|
+
*/
|
|
286
|
+
function isValidContainerWidth(width) {
|
|
287
|
+
if (width === 'auto')
|
|
288
|
+
return true;
|
|
289
|
+
if (typeof width === 'number') {
|
|
290
|
+
return Number.isFinite(width) && width > 0;
|
|
291
|
+
}
|
|
292
|
+
if (typeof width === 'string') {
|
|
293
|
+
const val = width.trim().toLowerCase();
|
|
294
|
+
if (val === 'auto')
|
|
295
|
+
return true;
|
|
296
|
+
const match = val.match(/^((?:\d*\.)?\d+)(px|%|em|rem|vw|vh|vmin|vmax|ch|in|cm|mm|pt|pc)?$/);
|
|
297
|
+
if (!match)
|
|
298
|
+
return false;
|
|
299
|
+
const numericValue = parseFloat(match[1]);
|
|
300
|
+
return numericValue > 0;
|
|
301
|
+
}
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Emits a warning and falls back to 'auto' if the HTML containerWidth is invalid.
|
|
306
|
+
*/
|
|
307
|
+
function validateHtmlConfigWidth(htmlConfig, config) {
|
|
308
|
+
if (htmlConfig?.containerWidth !== undefined) {
|
|
309
|
+
const width = htmlConfig.containerWidth;
|
|
310
|
+
if (!isValidContainerWidth(width)) {
|
|
311
|
+
(0, errorUtils_js_1.logWarning)(types_js_1.OfficeWarningType.INVALID_CONTAINER_WIDTH, config, width);
|
|
312
|
+
htmlConfig.containerWidth = 'auto';
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Date Parsing Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides robust functions for parsing date strings from various office formats.
|
|
5
|
+
* Handles standard ISO dates, PDF-specific date formats, and malformed strings.
|
|
6
|
+
*
|
|
7
|
+
* @module dateUtils
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Parses a date string into a Date object.
|
|
11
|
+
* Handles standard ISO formats and falls back to native parsing.
|
|
12
|
+
* Returns undefined instead of "Invalid Date" if parsing fails.
|
|
13
|
+
*
|
|
14
|
+
* @param dateString - The date string to parse
|
|
15
|
+
* @returns Parsed Date object or undefined if parsing fails
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseOfficeDate(dateString: string | undefined): Date | undefined;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Date Parsing Utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides robust functions for parsing date strings from various office formats.
|
|
6
|
+
* Handles standard ISO dates, PDF-specific date formats, and malformed strings.
|
|
7
|
+
*
|
|
8
|
+
* @module dateUtils
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.parseOfficeDate = parseOfficeDate;
|
|
12
|
+
/**
|
|
13
|
+
* Parses a date string into a Date object.
|
|
14
|
+
* Handles standard ISO formats and falls back to native parsing.
|
|
15
|
+
* Returns undefined instead of "Invalid Date" if parsing fails.
|
|
16
|
+
*
|
|
17
|
+
* @param dateString - The date string to parse
|
|
18
|
+
* @returns Parsed Date object or undefined if parsing fails
|
|
19
|
+
*/
|
|
20
|
+
function parseOfficeDate(dateString) {
|
|
21
|
+
if (!dateString)
|
|
22
|
+
return undefined;
|
|
23
|
+
try {
|
|
24
|
+
// PDF-specific format detection: D:YYYYMMDDHHmmSSOHH'mm'
|
|
25
|
+
if (dateString.startsWith('D:')) {
|
|
26
|
+
return parsePdfDate(dateString);
|
|
27
|
+
}
|
|
28
|
+
const date = new Date(dateString);
|
|
29
|
+
return isNaN(date.getTime()) ? undefined : date;
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Internal helper for PDF-specific date format: D:YYYYMMDDHHmmSSOHH'mm'
|
|
37
|
+
* @param dateString - The PDF date string
|
|
38
|
+
*/
|
|
39
|
+
function parsePdfDate(dateString) {
|
|
40
|
+
try {
|
|
41
|
+
// Remove "D:" prefix
|
|
42
|
+
let str = dateString.slice(2);
|
|
43
|
+
// Extract components: YYYYMMDDHHmmSS
|
|
44
|
+
const year = parseInt(str.slice(0, 4), 10);
|
|
45
|
+
const month = parseInt(str.slice(4, 6), 10) - 1; // 0-indexed
|
|
46
|
+
const day = parseInt(str.slice(6, 8), 10) || 1;
|
|
47
|
+
const hour = parseInt(str.slice(8, 10), 10) || 0;
|
|
48
|
+
const minute = parseInt(str.slice(10, 12), 10) || 0;
|
|
49
|
+
const second = parseInt(str.slice(12, 14), 10) || 0;
|
|
50
|
+
// Handle timezone if present
|
|
51
|
+
const tzMatch = str.slice(14).match(/([+-Z])(\d{2})'?(\d{2})?'?/);
|
|
52
|
+
if (tzMatch) {
|
|
53
|
+
if (tzMatch[1] === 'Z') {
|
|
54
|
+
return new Date(Date.UTC(year, month, day, hour, minute, second));
|
|
55
|
+
}
|
|
56
|
+
const tzSign = tzMatch[1] === '-' ? -1 : 1;
|
|
57
|
+
const tzHours = parseInt(tzMatch[2], 10) || 0;
|
|
58
|
+
const tzMinutes = parseInt(tzMatch[3], 10) || 0;
|
|
59
|
+
const offset = tzSign * (tzHours * 60 + tzMinutes);
|
|
60
|
+
// Create date in UTC and adjust for timezone
|
|
61
|
+
const utc = Date.UTC(year, month, day, hour, minute, second);
|
|
62
|
+
return new Date(utc - offset * 60000);
|
|
63
|
+
}
|
|
64
|
+
return new Date(year, month, day, hour, minute, second);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment detection and safe utility wrappers.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Detect if we are running in a browser environment.
|
|
6
|
+
*/
|
|
7
|
+
export declare const isBrowser: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Supported Node.js-only features that require explicit guarding for browser compatibility.
|
|
10
|
+
*/
|
|
11
|
+
export type NodeFeature = 'fs' | 'path-parsing' | 'pdf-worker-auto-resolution';
|
|
12
|
+
/**
|
|
13
|
+
* Throws an error if attempted to use Node.js-specific features in the browser.
|
|
14
|
+
*
|
|
15
|
+
* @param feature - The Node.js feature being accessed
|
|
16
|
+
* @throws {Error} Clear error message directing browser users to use Buffers
|
|
17
|
+
*/
|
|
18
|
+
export declare function assertNode(feature: NodeFeature): void;
|
|
19
|
+
/**
|
|
20
|
+
* Polyfills environment features not available globally (required for Node.js < 20).
|
|
21
|
+
* This shim provides enough properties for pdfjs-dist 5.x to calculate
|
|
22
|
+
* text coordinates and transformations, and guards against modern RegExp flags.
|
|
23
|
+
*/
|
|
24
|
+
export declare function ensureEnvPolyfills(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Backward-compatible alias for ensureEnvPolyfills.
|
|
27
|
+
* @deprecated Use ensureEnvPolyfills instead.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ensureDomMatrix: typeof ensureEnvPolyfills;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Environment detection and safe utility wrappers.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ensureDomMatrix = exports.isBrowser = void 0;
|
|
7
|
+
exports.assertNode = assertNode;
|
|
8
|
+
exports.ensureEnvPolyfills = ensureEnvPolyfills;
|
|
9
|
+
/**
|
|
10
|
+
* Detect if we are running in a browser environment.
|
|
11
|
+
*/
|
|
12
|
+
exports.isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
|
13
|
+
const types_js_1 = require("../types.js");
|
|
14
|
+
const errorUtils_js_1 = require("./errorUtils.js");
|
|
15
|
+
/**
|
|
16
|
+
* Human-readable descriptions for Node-only features.
|
|
17
|
+
*/
|
|
18
|
+
const readableFeatures = {
|
|
19
|
+
'fs': 'direct file system access',
|
|
20
|
+
'path-parsing': 'parsing from file path string',
|
|
21
|
+
'pdf-worker-auto-resolution': 'automatic PDF worker resolution from node_modules'
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Throws an error if attempted to use Node.js-specific features in the browser.
|
|
25
|
+
*
|
|
26
|
+
* @param feature - The Node.js feature being accessed
|
|
27
|
+
* @throws {Error} Clear error message directing browser users to use Buffers
|
|
28
|
+
*/
|
|
29
|
+
function assertNode(feature) {
|
|
30
|
+
if (exports.isBrowser) {
|
|
31
|
+
throw (0, errorUtils_js_1.getOfficeError)(types_js_1.OfficeErrorType.FEATURE_NOT_SUPPORTED_IN_BROWSER, undefined, readableFeatures[feature]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Polyfills environment features not available globally (required for Node.js < 20).
|
|
36
|
+
* This shim provides enough properties for pdfjs-dist 5.x to calculate
|
|
37
|
+
* text coordinates and transformations, and guards against modern RegExp flags.
|
|
38
|
+
*/
|
|
39
|
+
function ensureEnvPolyfills() {
|
|
40
|
+
if (typeof global !== 'undefined') {
|
|
41
|
+
// 1. DOMMatrix Polyfill (Node.js < 20)
|
|
42
|
+
if (!global.DOMMatrix) {
|
|
43
|
+
global.DOMMatrix = class DOMMatrix {
|
|
44
|
+
a;
|
|
45
|
+
b;
|
|
46
|
+
c;
|
|
47
|
+
d;
|
|
48
|
+
e;
|
|
49
|
+
f;
|
|
50
|
+
constructor(init) {
|
|
51
|
+
if (Array.isArray(init) && init.length >= 6) {
|
|
52
|
+
this.a = init[0];
|
|
53
|
+
this.b = init[1];
|
|
54
|
+
this.c = init[2];
|
|
55
|
+
this.d = init[3];
|
|
56
|
+
this.e = init[4];
|
|
57
|
+
this.f = init[5];
|
|
58
|
+
}
|
|
59
|
+
else if (typeof init === 'object' && init !== null) {
|
|
60
|
+
this.a = init.a;
|
|
61
|
+
this.b = init.b;
|
|
62
|
+
this.c = init.c;
|
|
63
|
+
this.d = init.d;
|
|
64
|
+
this.e = init.e;
|
|
65
|
+
this.f = init.f;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
this.a = this.d = 1;
|
|
69
|
+
this.b = this.c = this.e = this.f = 0;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Standard matrix property aliases for compatibility
|
|
73
|
+
get m11() { return this.a; }
|
|
74
|
+
get m12() { return this.b; }
|
|
75
|
+
get m21() { return this.c; }
|
|
76
|
+
get m22() { return this.d; }
|
|
77
|
+
get m41() { return this.e; }
|
|
78
|
+
get m42() { return this.f; }
|
|
79
|
+
multiply(other) {
|
|
80
|
+
return new DOMMatrix([
|
|
81
|
+
this.a * other.a + this.c * other.b,
|
|
82
|
+
this.b * other.a + this.d * other.b,
|
|
83
|
+
this.a * other.c + this.c * other.d,
|
|
84
|
+
this.b * other.c + this.d * other.d,
|
|
85
|
+
this.a * other.e + this.c * other.f + this.e,
|
|
86
|
+
this.b * other.e + this.d * other.f + this.f
|
|
87
|
+
]);
|
|
88
|
+
}
|
|
89
|
+
inverse() {
|
|
90
|
+
const det = this.a * this.d - this.b * this.c;
|
|
91
|
+
if (det === 0)
|
|
92
|
+
return new DOMMatrix();
|
|
93
|
+
return new DOMMatrix([
|
|
94
|
+
this.d / det,
|
|
95
|
+
-this.b / det,
|
|
96
|
+
-this.c / det,
|
|
97
|
+
this.a / det,
|
|
98
|
+
(this.c * this.f - this.d * this.e) / det,
|
|
99
|
+
(this.b * this.e - this.a * this.f) / det
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
transformPoint(point) {
|
|
103
|
+
const x = point?.x ?? 0;
|
|
104
|
+
const y = point?.y ?? 0;
|
|
105
|
+
return {
|
|
106
|
+
x: x * this.a + y * this.c + this.e,
|
|
107
|
+
y: x * this.b + y * this.d + this.f
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
// 2. ImageData Polyfill (Node.js < 20)
|
|
113
|
+
if (!global.ImageData) {
|
|
114
|
+
global.ImageData = class ImageData {
|
|
115
|
+
width;
|
|
116
|
+
height;
|
|
117
|
+
data;
|
|
118
|
+
constructor(data, width, height) {
|
|
119
|
+
this.data = data;
|
|
120
|
+
this.width = width;
|
|
121
|
+
this.height = height;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
// 3. RegExp 'v' flag Polyfill (Node.js < 20)
|
|
126
|
+
// Modern dependencies (file-type 22+, pdfjs-dist 5+) might use the 'v' flag.
|
|
127
|
+
// We wrap the constructor to downgrade 'v' to 'u' in Node 18.
|
|
128
|
+
const OriginalRegExp = global.RegExp;
|
|
129
|
+
try {
|
|
130
|
+
new OriginalRegExp('', 'v');
|
|
131
|
+
}
|
|
132
|
+
catch (e) {
|
|
133
|
+
// 'v' flag is not supported (Node 18), apply fallback wrapper
|
|
134
|
+
const RegExpWrapper = function (pattern, flags) {
|
|
135
|
+
if (typeof flags === 'string' && flags.includes('v')) {
|
|
136
|
+
// Fallback 'v' to 'u' (Unicode sets to Unicode)
|
|
137
|
+
return new OriginalRegExp(pattern, flags.replace('v', 'u'));
|
|
138
|
+
}
|
|
139
|
+
return new OriginalRegExp(pattern, flags);
|
|
140
|
+
};
|
|
141
|
+
// Maintain prototype chain and static methods
|
|
142
|
+
RegExpWrapper.prototype = OriginalRegExp.prototype;
|
|
143
|
+
Object.setPrototypeOf(RegExpWrapper, OriginalRegExp);
|
|
144
|
+
global.RegExp = RegExpWrapper;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Backward-compatible alias for ensureEnvPolyfills.
|
|
150
|
+
* @deprecated Use ensureEnvPolyfills instead.
|
|
151
|
+
*/
|
|
152
|
+
exports.ensureDomMatrix = ensureEnvPolyfills;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Handling Utilities
|
|
3
|
+
*
|
|
4
|
+
* This module provides centralized error management for the OfficeParser library.
|
|
5
|
+
* It defines standard error types, messages, and handling logic to ensure
|
|
6
|
+
* consistent error reporting across all parsers and the main entry point.
|
|
7
|
+
*/
|
|
8
|
+
import { OfficeError, OfficeErrorType, OfficeParserConfig, OfficeWarningType } from '../types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Creates a formatted warning message for a specific warning type.
|
|
11
|
+
*
|
|
12
|
+
* @param type - The type of warning
|
|
13
|
+
* @param info - Optional additional information
|
|
14
|
+
* @returns The formatted warning message string
|
|
15
|
+
*/
|
|
16
|
+
export declare const getWarningMessage: (type: OfficeWarningType, info?: any) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Creates, optionally logs to console, and returns a formatted OfficeParser error.
|
|
19
|
+
*
|
|
20
|
+
* @param type - The type of error
|
|
21
|
+
* @param config - Optional parser configuration (checks outputErrorToConsole)
|
|
22
|
+
* @param info - Optional additional information
|
|
23
|
+
* @returns The Error object to be thrown
|
|
24
|
+
*/
|
|
25
|
+
export declare const getOfficeError: (type: OfficeErrorType, config?: OfficeParserConfig, info?: any) => OfficeError;
|
|
26
|
+
/**
|
|
27
|
+
* Wraps an existing error with OfficeParser context and performs corruption detection.
|
|
28
|
+
* Optionally logs the error to console.
|
|
29
|
+
*
|
|
30
|
+
* An error already built by {@link getOfficeError} is returned untouched: it carries an
|
|
31
|
+
* `officeIssue`, meaning it has been reported once and already bears the `[OfficeParser]: `
|
|
32
|
+
* header. Re-wrapping it would report the same issue a second time, prepend a second header,
|
|
33
|
+
* and flatten its specific error code to `FILE_CORRUPTED`. This is a marker check on the error
|
|
34
|
+
* object rather than a test against its message text, so it stays independent of wording.
|
|
35
|
+
*
|
|
36
|
+
* **Important**: Do NOT pass AbortErrors to this function. AbortErrors (err.name === 'AbortError')
|
|
37
|
+
* represent deliberate user cancellation and must be re-thrown as-is from the catch block so that
|
|
38
|
+
* callers can reliably detect them via `err.name === 'AbortError'` or `err instanceof DOMException`.
|
|
39
|
+
* This function always returns a plain `new Error(...)`, which would strip the AbortError identity.
|
|
40
|
+
*
|
|
41
|
+
* @param error - The original error object
|
|
42
|
+
* @param config - Parser configuration
|
|
43
|
+
* @param filePath - Optional file path for context
|
|
44
|
+
* @returns The wrapped Error object to be thrown
|
|
45
|
+
*/
|
|
46
|
+
export declare const getWrappedError: (error: any, config: OfficeParserConfig, filePath?: string) => Error;
|
|
47
|
+
/**
|
|
48
|
+
* Centralized logging utility for non-fatal warnings or issues.
|
|
49
|
+
* Routes messages to config.onWarning if provided, or console.warn/error
|
|
50
|
+
* if config.outputErrorToConsole is true.
|
|
51
|
+
*
|
|
52
|
+
* @param messageOrType - The warning message or warning type
|
|
53
|
+
* @param config - Optional parser configuration
|
|
54
|
+
* @param info - Optional additional information for dynamic messages or context
|
|
55
|
+
* @param error - Optional original error object
|
|
56
|
+
*/
|
|
57
|
+
export declare const logWarning: (type: OfficeWarningType, config?: OfficeParserConfig, info?: any, error?: any) => void;
|
|
58
|
+
/**
|
|
59
|
+
* Creates and returns a standard AbortError (DOMException if available).
|
|
60
|
+
* Used when the user signals cancellation of the parser operation.
|
|
61
|
+
*
|
|
62
|
+
* @returns Error object representing the abort action
|
|
63
|
+
*/
|
|
64
|
+
export declare const getAbortError: () => Error;
|
|
65
|
+
/**
|
|
66
|
+
* Checks the provided AbortSignal and throws an AbortError if it was aborted.
|
|
67
|
+
* Helps cleanly interrupt loops and asynchronous phases of parsing.
|
|
68
|
+
*
|
|
69
|
+
* @param signal - Optional AbortSignal to inspect
|
|
70
|
+
* @throws {DOMException} If the signal has been aborted
|
|
71
|
+
*/
|
|
72
|
+
export declare const checkAbortSignal: (signal?: AbortSignal | null) => void;
|