formatferry 1.0.2 → 1.0.4
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/dist/index.js +4 -5
- package/package.json +2 -2
- package/dist/commands/auth.d.ts +0 -17
- package/dist/commands/auth.d.ts.map +0 -1
- package/dist/commands/auth.js +0 -102
- package/dist/commands/auth.js.map +0 -1
- package/dist/commands/batch.d.ts +0 -10
- package/dist/commands/batch.d.ts.map +0 -1
- package/dist/commands/batch.js +0 -92
- package/dist/commands/batch.js.map +0 -1
- package/dist/commands/convert.d.ts +0 -26
- package/dist/commands/convert.d.ts.map +0 -1
- package/dist/commands/convert.js +0 -198
- package/dist/commands/convert.js.map +0 -1
- package/dist/config-store.d.ts +0 -27
- package/dist/config-store.d.ts.map +0 -1
- package/dist/config-store.js +0 -58
- package/dist/config-store.js.map +0 -1
- package/dist/entitlement.d.ts +0 -11
- package/dist/entitlement.d.ts.map +0 -1
- package/dist/entitlement.js +0 -91
- package/dist/entitlement.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/packages/cli/src/commands/auth.d.ts +0 -17
- package/dist/packages/cli/src/commands/auth.d.ts.map +0 -1
- package/dist/packages/cli/src/commands/auth.js +0 -102
- package/dist/packages/cli/src/commands/auth.js.map +0 -1
- package/dist/packages/cli/src/commands/batch.d.ts +0 -10
- package/dist/packages/cli/src/commands/batch.d.ts.map +0 -1
- package/dist/packages/cli/src/commands/batch.js +0 -92
- package/dist/packages/cli/src/commands/batch.js.map +0 -1
- package/dist/packages/cli/src/commands/convert.d.ts +0 -26
- package/dist/packages/cli/src/commands/convert.d.ts.map +0 -1
- package/dist/packages/cli/src/commands/convert.js +0 -198
- package/dist/packages/cli/src/commands/convert.js.map +0 -1
- package/dist/packages/cli/src/config-store.d.ts +0 -27
- package/dist/packages/cli/src/config-store.d.ts.map +0 -1
- package/dist/packages/cli/src/config-store.js +0 -58
- package/dist/packages/cli/src/config-store.js.map +0 -1
- package/dist/packages/cli/src/entitlement.d.ts +0 -11
- package/dist/packages/cli/src/entitlement.d.ts.map +0 -1
- package/dist/packages/cli/src/entitlement.js +0 -91
- package/dist/packages/cli/src/entitlement.js.map +0 -1
- package/dist/packages/cli/src/index.d.ts +0 -2
- package/dist/packages/cli/src/index.d.ts.map +0 -1
- package/dist/packages/cli/src/index.js +0 -28
- package/dist/packages/cli/src/index.js.map +0 -1
- package/dist/packages/cli/src/shim.d.ts +0 -2
- package/dist/packages/cli/src/shim.d.ts.map +0 -1
- package/dist/packages/cli/src/shim.js +0 -21
- package/dist/packages/cli/src/shim.js.map +0 -1
- package/dist/shim.d.ts +0 -2
- package/dist/shim.d.ts.map +0 -1
- package/dist/shim.js +0 -21
- package/dist/shim.js.map +0 -1
- package/dist/src/shared/adapters/docx-adapter.d.ts +0 -85
- package/dist/src/shared/adapters/docx-adapter.d.ts.map +0 -1
- package/dist/src/shared/adapters/docx-adapter.js +0 -164
- package/dist/src/shared/adapters/docx-adapter.js.map +0 -1
- package/dist/src/shared/adapters/pdf-adapter.d.ts +0 -94
- package/dist/src/shared/adapters/pdf-adapter.d.ts.map +0 -1
- package/dist/src/shared/adapters/pdf-adapter.js +0 -322
- package/dist/src/shared/adapters/pdf-adapter.js.map +0 -1
- package/dist/src/shared/adapters/spreadsheet-adapter.d.ts +0 -98
- package/dist/src/shared/adapters/spreadsheet-adapter.d.ts.map +0 -1
- package/dist/src/shared/adapters/spreadsheet-adapter.js +0 -424
- package/dist/src/shared/adapters/spreadsheet-adapter.js.map +0 -1
- package/dist/src/shared/atlassian-detector.d.ts +0 -6
- package/dist/src/shared/atlassian-detector.d.ts.map +0 -1
- package/dist/src/shared/atlassian-detector.js +0 -23
- package/dist/src/shared/atlassian-detector.js.map +0 -1
- package/dist/src/shared/conversion-engine.d.ts +0 -114
- package/dist/src/shared/conversion-engine.d.ts.map +0 -1
- package/dist/src/shared/conversion-engine.js +0 -790
- package/dist/src/shared/conversion-engine.js.map +0 -1
- package/dist/src/shared/entitlement-service.d.ts +0 -42
- package/dist/src/shared/entitlement-service.d.ts.map +0 -1
- package/dist/src/shared/entitlement-service.js +0 -38
- package/dist/src/shared/entitlement-service.js.map +0 -1
- package/dist/src/shared/input-sanitizer.d.ts +0 -93
- package/dist/src/shared/input-sanitizer.d.ts.map +0 -1
- package/dist/src/shared/input-sanitizer.js +0 -527
- package/dist/src/shared/input-sanitizer.js.map +0 -1
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Cross-platform config store for FormatFerry CLI.
|
|
3
|
-
*
|
|
4
|
-
* Config path:
|
|
5
|
-
* - POSIX: ~/.config/formatferry/config.json (Req 9.2)
|
|
6
|
-
* - Windows: %APPDATA%\formatferry\config.json (Req 9.2)
|
|
7
|
-
*
|
|
8
|
-
* File permissions:
|
|
9
|
-
* - POSIX: 0o600 (owner read/write only) (Req 9.5)
|
|
10
|
-
* - Windows: 0o600 is silently ignored by Node.js — security relies on
|
|
11
|
-
* %APPDATA% being inside the user's profile directory, which is protected
|
|
12
|
-
* by Windows NTFS user account ACLs. No additional code is needed.
|
|
13
|
-
*
|
|
14
|
-
* Corrupted or missing config → returns null → Free tier (Req 10.7)
|
|
15
|
-
*/
|
|
16
|
-
import envPaths from 'env-paths';
|
|
17
|
-
import { readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
18
|
-
import { dirname } from 'path';
|
|
19
|
-
const paths = envPaths('formatferry', { suffix: '' });
|
|
20
|
-
// Exported so tests can override via module-level patching
|
|
21
|
-
export let CONFIG_PATH = `${paths.config}/config.json`;
|
|
22
|
-
/** Override the config path (for testing only). */
|
|
23
|
-
export function _setConfigPathForTesting(p) {
|
|
24
|
-
CONFIG_PATH = p;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Read the stored config. Returns `null` if the file is missing or corrupted.
|
|
28
|
-
* Silently discards errors so the CLI always falls back to free tier (Req 10.7).
|
|
29
|
-
*/
|
|
30
|
-
export function readConfig() {
|
|
31
|
-
try {
|
|
32
|
-
const raw = readFileSync(CONFIG_PATH, 'utf-8');
|
|
33
|
-
return JSON.parse(raw);
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
return null; // Missing or corrupted → Free tier
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Persist config to disk. Creates parent directories as needed.
|
|
41
|
-
* Sets mode 0o600 on POSIX (owner read/write only) per Req 9.5.
|
|
42
|
-
*/
|
|
43
|
-
export function writeConfig(config) {
|
|
44
|
-
mkdirSync(dirname(CONFIG_PATH), { recursive: true });
|
|
45
|
-
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), { mode: 0o600 });
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Reset the config to an empty object (effectively clearing all stored values).
|
|
49
|
-
* Silently ignores errors (e.g. if the file doesn't exist yet).
|
|
50
|
-
*/
|
|
51
|
-
export function clearConfig() {
|
|
52
|
-
try {
|
|
53
|
-
mkdirSync(dirname(CONFIG_PATH), { recursive: true });
|
|
54
|
-
writeFileSync(CONFIG_PATH, '{}', { mode: 0o600 });
|
|
55
|
-
}
|
|
56
|
-
catch { /* ignore */ }
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=config-store.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config-store.js","sourceRoot":"","sources":["../../../../src/config-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;AAEtD,2DAA2D;AAC3D,MAAM,CAAC,IAAI,WAAW,GAAG,GAAG,KAAK,CAAC,MAAM,cAAc,CAAC;AAEvD,mDAAmD;AACnD,MAAM,UAAU,wBAAwB,CAAC,CAAS;IAChD,WAAW,GAAG,CAAC,CAAC;AAClB,CAAC;AAWD;;;GAGG;AACH,MAAM,UAAU,UAAU;IACxB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAiB,CAAC;IACzC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC,CAAC,mCAAmC;IAClD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC9C,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACrD,aAAa,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAC/E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,IAAI,CAAC;QACH,SAAS,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACrD,aAAa,CAAC,WAAW,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC,CAAC,YAAY,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI startup license validation with caching (Design §5.5)
|
|
3
|
-
* Validates: Requirements 10.1–10.7
|
|
4
|
-
*/
|
|
5
|
-
import { type EntitlementProvider } from '../../../src/shared/entitlement-service.js';
|
|
6
|
-
/**
|
|
7
|
-
* Resolve the entitlement provider for the current CLI session.
|
|
8
|
-
* Called once at CLI startup before any command runs.
|
|
9
|
-
*/
|
|
10
|
-
export declare function resolveEntitlement(): Promise<EntitlementProvider>;
|
|
11
|
-
//# sourceMappingURL=entitlement.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entitlement.d.ts","sourceRoot":"","sources":["../../../../src/entitlement.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAGL,KAAK,mBAAmB,EAGzB,MAAM,4CAA4C,CAAC;AAepD;;;GAGG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,mBAAmB,CAAC,CA0FvE"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI startup license validation with caching (Design §5.5)
|
|
3
|
-
* Validates: Requirements 10.1–10.7
|
|
4
|
-
*/
|
|
5
|
-
import { readConfig, writeConfig, clearConfig } from './config-store.js';
|
|
6
|
-
import { FreeEntitlementProvider, CachedEntitlementProvider, } from '../../../src/shared/entitlement-service.js';
|
|
7
|
-
const LICENSE_SERVER_URL = 'https://formatferry.vibingfun.com';
|
|
8
|
-
const VALIDATE_ENDPOINT = `${LICENSE_SERVER_URL}/v1/licenses/validate`;
|
|
9
|
-
const STARTUP_TIMEOUT_MS = 2_000;
|
|
10
|
-
const STALE_CACHE_DAYS = 7;
|
|
11
|
-
/**
|
|
12
|
-
* Resolve the entitlement provider for the current CLI session.
|
|
13
|
-
* Called once at CLI startup before any command runs.
|
|
14
|
-
*/
|
|
15
|
-
export async function resolveEntitlement() {
|
|
16
|
-
// Req 10.7: Corrupted ConfigStore → silently discard, free tier
|
|
17
|
-
let config;
|
|
18
|
-
try {
|
|
19
|
-
config = readConfig();
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
return new FreeEntitlementProvider();
|
|
23
|
-
}
|
|
24
|
-
if (!config || !config.licenseKey) {
|
|
25
|
-
return new FreeEntitlementProvider();
|
|
26
|
-
}
|
|
27
|
-
const { licenseKey, lastValidated } = config;
|
|
28
|
-
// Req 10.1: Ping License Server with 2s timeout
|
|
29
|
-
let data = null;
|
|
30
|
-
let networkError = false;
|
|
31
|
-
try {
|
|
32
|
-
const controller = new AbortController();
|
|
33
|
-
const timer = setTimeout(() => controller.abort(), STARTUP_TIMEOUT_MS);
|
|
34
|
-
const response = await fetch(VALIDATE_ENDPOINT, {
|
|
35
|
-
method: 'POST',
|
|
36
|
-
headers: { 'Content-Type': 'application/json' },
|
|
37
|
-
body: JSON.stringify({ key: licenseKey }),
|
|
38
|
-
signal: controller.signal,
|
|
39
|
-
});
|
|
40
|
-
clearTimeout(timer);
|
|
41
|
-
data = (await response.json());
|
|
42
|
-
}
|
|
43
|
-
catch {
|
|
44
|
-
networkError = true;
|
|
45
|
-
}
|
|
46
|
-
if (!networkError && data !== null) {
|
|
47
|
-
// Req 10.6: Revoked → delete key, downgrade to free
|
|
48
|
-
if (data.revoked) {
|
|
49
|
-
clearConfig();
|
|
50
|
-
return new FreeEntitlementProvider();
|
|
51
|
-
}
|
|
52
|
-
if (!data.valid) {
|
|
53
|
-
return new FreeEntitlementProvider();
|
|
54
|
-
}
|
|
55
|
-
// Req 10.2 + 10.4: valid → update cache with fresh data + ISO 8601 timestamp
|
|
56
|
-
const freshState = {
|
|
57
|
-
tier: data.tier ?? 'premium',
|
|
58
|
-
features: (data.features ?? []),
|
|
59
|
-
expiresAt: data.expiresAt ?? null,
|
|
60
|
-
lastValidated: new Date().toISOString(),
|
|
61
|
-
};
|
|
62
|
-
writeConfig({
|
|
63
|
-
...config,
|
|
64
|
-
tier: freshState.tier,
|
|
65
|
-
features: freshState.features,
|
|
66
|
-
expiresAt: freshState.expiresAt,
|
|
67
|
-
lastValidated: freshState.lastValidated,
|
|
68
|
-
});
|
|
69
|
-
return new CachedEntitlementProvider(freshState);
|
|
70
|
-
}
|
|
71
|
-
// Req 10.3 + 10.5: Network error/timeout — check cache age
|
|
72
|
-
const cacheAgeMs = lastValidated
|
|
73
|
-
? Date.now() - new Date(lastValidated).getTime()
|
|
74
|
-
: Infinity;
|
|
75
|
-
const staleCacheMs = STALE_CACHE_DAYS * 24 * 60 * 60 * 1000;
|
|
76
|
-
if (cacheAgeMs < staleCacheMs) {
|
|
77
|
-
// Req 10.3: Fresh cache → use cached entitlements
|
|
78
|
-
const cachedState = {
|
|
79
|
-
tier: config.tier ?? 'free',
|
|
80
|
-
features: (config.features ?? []),
|
|
81
|
-
expiresAt: config.expiresAt ?? null,
|
|
82
|
-
lastValidated: lastValidated ?? '',
|
|
83
|
-
};
|
|
84
|
-
return new CachedEntitlementProvider(cachedState);
|
|
85
|
-
}
|
|
86
|
-
// Req 10.5: Stale cache + unreachable → warn stderr, free tier
|
|
87
|
-
process.stderr.write('Warning: Could not reach license server and cached license is older than 7 days. ' +
|
|
88
|
-
'Operating in free tier. Please reconnect to validate your license.\n');
|
|
89
|
-
return new FreeEntitlementProvider();
|
|
90
|
-
}
|
|
91
|
-
//# sourceMappingURL=entitlement.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entitlement.js","sourceRoot":"","sources":["../../../../src/entitlement.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACL,uBAAuB,EACvB,yBAAyB,GAI1B,MAAM,4CAA4C,CAAC;AAEpD,MAAM,kBAAkB,GAAG,mCAAmC,CAAC;AAC/D,MAAM,iBAAiB,GAAG,GAAG,kBAAkB,uBAAuB,CAAC;AACvE,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAU3B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,gEAAgE;IAChE,IAAI,MAAqC,CAAC;IAC1C,IAAI,CAAC;QACH,MAAM,GAAG,UAAU,EAAE,CAAC;IACxB,CAAC;IAAC,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IACF,OAAO,IAAI,uBAAuB,EAAE,CAAC;AACvC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,WAAW,CAAC"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
// Entry point — shim MUST be imported first to set up DOM globals before any shared modules
|
|
2
|
-
import './shim.js';
|
|
3
|
-
import { program } from 'commander';
|
|
4
|
-
import { convertCommand } from './commands/convert.js';
|
|
5
|
-
import { authCommand } from './commands/auth.js';
|
|
6
|
-
// Version is read from package.json at build time
|
|
7
|
-
const VERSION = '0.1.0';
|
|
8
|
-
program
|
|
9
|
-
.name('formatferry')
|
|
10
|
-
.version(VERSION)
|
|
11
|
-
.description('Convert HTML, DOCX, PDF, XLSX to Markdown')
|
|
12
|
-
.option('-i, --input <path>', 'Input file path')
|
|
13
|
-
.option('-o, --output <path>', 'Output file path')
|
|
14
|
-
.option('-f, --format <format>', 'Markdown format (github, commonmark, discord, reddit, rmarkdown)', 'github')
|
|
15
|
-
.option('--url <url>', 'Fetch article from URL')
|
|
16
|
-
.option('--batch <glob>', 'Batch convert files (Premium)')
|
|
17
|
-
.option('--output-dir <dir>', 'Output directory for batch')
|
|
18
|
-
.action(convertCommand);
|
|
19
|
-
// Auth subcommand
|
|
20
|
-
program
|
|
21
|
-
.command('auth')
|
|
22
|
-
.description('Manage license key authentication')
|
|
23
|
-
.option('--license-key <key>', 'Activate a license key')
|
|
24
|
-
.option('--status', 'Show current license status')
|
|
25
|
-
.option('--logout', 'Remove stored license key')
|
|
26
|
-
.action(authCommand);
|
|
27
|
-
program.parse();
|
|
28
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/index.ts"],"names":[],"mappings":"AAAA,4FAA4F;AAC5F,OAAO,WAAW,CAAC;AACnB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,kDAAkD;AAClD,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB,OAAO;KACJ,IAAI,CAAC,aAAa,CAAC;KACnB,OAAO,CAAC,OAAO,CAAC;KAChB,WAAW,CAAC,2CAA2C,CAAC;KACxD,MAAM,CAAC,oBAAoB,EAAE,iBAAiB,CAAC;KAC/C,MAAM,CAAC,qBAAqB,EAAE,kBAAkB,CAAC;KACjD,MAAM,CAAC,uBAAuB,EAAE,kEAAkE,EAAE,QAAQ,CAAC;KAC7G,MAAM,CAAC,aAAa,EAAE,wBAAwB,CAAC;KAC/C,MAAM,CAAC,gBAAgB,EAAE,+BAA+B,CAAC;KACzD,MAAM,CAAC,oBAAoB,EAAE,4BAA4B,CAAC;KAC1D,MAAM,CAAC,cAAc,CAAC,CAAC;AAE1B,kBAAkB;AAClB,OAAO;KACJ,OAAO,CAAC,MAAM,CAAC;KACf,WAAW,CAAC,mCAAmC,CAAC;KAChD,MAAM,CAAC,qBAAqB,EAAE,wBAAwB,CAAC;KACvD,MAAM,CAAC,UAAU,EAAE,6BAA6B,CAAC;KACjD,MAAM,CAAC,UAAU,EAAE,2BAA2B,CAAC;KAC/C,MAAM,CAAC,WAAW,CAAC,CAAC;AAEvB,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shim.d.ts","sourceRoot":"","sources":["../../../../src/shim.ts"],"names":[],"mappings":""}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global DOM shim for Node.js CLI context.
|
|
3
|
-
*
|
|
4
|
-
* This file MUST be imported as the very first import in index.ts.
|
|
5
|
-
* It assigns linkedom-backed globals to satisfy third-party libraries
|
|
6
|
-
* (e.g. turndown) that contain hardcoded checks for window.document.
|
|
7
|
-
*
|
|
8
|
-
* Compatibility outcome (Task 5.4): linkedom compatible.
|
|
9
|
-
* Smoke test (src/tests/shim-smoke.test.ts) confirmed that linkedom-backed
|
|
10
|
-
* globals satisfy turndown and DOMPurify without errors. No jsdom fallback needed.
|
|
11
|
-
*/
|
|
12
|
-
import { parseHTML } from 'linkedom';
|
|
13
|
-
const { document, window } = parseHTML('<!DOCTYPE html><html><body></body></html>');
|
|
14
|
-
// Satisfy turndown's hardcoded window.document checks
|
|
15
|
-
globalThis.window = window;
|
|
16
|
-
globalThis.document = document;
|
|
17
|
-
globalThis.DOMParser = window.DOMParser;
|
|
18
|
-
globalThis.Node = window.Node;
|
|
19
|
-
globalThis.HTMLElement = window.HTMLElement;
|
|
20
|
-
globalThis.HTMLTableElement = window.HTMLTableElement;
|
|
21
|
-
//# sourceMappingURL=shim.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shim.js","sourceRoot":"","sources":["../../../../src/shim.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,2CAA2C,CAAC,CAAC;AAEpF,sDAAsD;AACrD,UAAsC,CAAC,MAAM,GAAG,MAAM,CAAC;AACvD,UAAsC,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC3D,UAAsC,CAAC,SAAS,GAAI,MAA4C,CAAC,SAAS,CAAC;AAC3G,UAAsC,CAAC,IAAI,GAAI,MAAuC,CAAC,IAAI,CAAC;AAC5F,UAAsC,CAAC,WAAW,GAAI,MAA8C,CAAC,WAAW,CAAC;AACjH,UAAsC,CAAC,gBAAgB,GAAI,MAAmD,CAAC,gBAAgB,CAAC"}
|
package/dist/shim.d.ts
DELETED
package/dist/shim.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shim.d.ts","sourceRoot":"","sources":["../src/shim.ts"],"names":[],"mappings":""}
|
package/dist/shim.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Global DOM shim for Node.js CLI context.
|
|
3
|
-
*
|
|
4
|
-
* This file MUST be imported as the very first import in index.ts.
|
|
5
|
-
* It assigns linkedom-backed globals to satisfy third-party libraries
|
|
6
|
-
* (e.g. turndown) that contain hardcoded checks for window.document.
|
|
7
|
-
*
|
|
8
|
-
* Compatibility outcome (Task 5.4): linkedom compatible.
|
|
9
|
-
* Smoke test (src/tests/shim-smoke.test.ts) confirmed that linkedom-backed
|
|
10
|
-
* globals satisfy turndown and DOMPurify without errors. No jsdom fallback needed.
|
|
11
|
-
*/
|
|
12
|
-
import { parseHTML } from 'linkedom';
|
|
13
|
-
const { document, window } = parseHTML('<!DOCTYPE html><html><body></body></html>');
|
|
14
|
-
// Satisfy turndown's hardcoded window.document checks
|
|
15
|
-
globalThis.window = window;
|
|
16
|
-
globalThis.document = document;
|
|
17
|
-
globalThis.DOMParser = window.DOMParser;
|
|
18
|
-
globalThis.Node = window.Node;
|
|
19
|
-
globalThis.HTMLElement = window.HTMLElement;
|
|
20
|
-
globalThis.HTMLTableElement = window.HTMLTableElement;
|
|
21
|
-
//# sourceMappingURL=shim.js.map
|
package/dist/shim.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shim.js","sourceRoot":"","sources":["../src/shim.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,2CAA2C,CAAC,CAAC;AAEpF,sDAAsD;AACrD,UAAsC,CAAC,MAAM,GAAG,MAAM,CAAC;AACvD,UAAsC,CAAC,QAAQ,GAAG,QAAQ,CAAC;AAC3D,UAAsC,CAAC,SAAS,GAAI,MAA4C,CAAC,SAAS,CAAC;AAC3G,UAAsC,CAAC,IAAI,GAAI,MAAuC,CAAC,IAAI,CAAC;AAC5F,UAAsC,CAAC,WAAW,GAAI,MAA8C,CAAC,WAAW,CAAC;AACjH,UAAsC,CAAC,gBAAgB,GAAI,MAAmD,CAAC,gBAAgB,CAAC"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOCX Adapter Module
|
|
3
|
-
*
|
|
4
|
-
* Converts DOCX files to HTML using Mammoth.js for processing through
|
|
5
|
-
* the existing ConversionEngine pipeline.
|
|
6
|
-
*
|
|
7
|
-
* Requirements: 1.1, 1.3, 1.4, 1.5, 1.6
|
|
8
|
-
*/
|
|
9
|
-
/** Image reference extracted from DOCX */
|
|
10
|
-
export interface ImageReference {
|
|
11
|
-
/** Original filename from the DOCX */
|
|
12
|
-
filename: string;
|
|
13
|
-
/** Image width in pixels (if available) */
|
|
14
|
-
width?: number;
|
|
15
|
-
/** Image height in pixels (if available) */
|
|
16
|
-
height?: number;
|
|
17
|
-
/** Alt text from the document */
|
|
18
|
-
altText?: string;
|
|
19
|
-
/** Content type (e.g., 'image/png') */
|
|
20
|
-
contentType?: string;
|
|
21
|
-
}
|
|
22
|
-
/** Document metadata extracted from DOCX */
|
|
23
|
-
export interface DocumentMetadata {
|
|
24
|
-
/** Document title (if available) */
|
|
25
|
-
title?: string;
|
|
26
|
-
/** Document author (if available) */
|
|
27
|
-
author?: string;
|
|
28
|
-
/** Number of images in the document */
|
|
29
|
-
imageCount: number;
|
|
30
|
-
}
|
|
31
|
-
/** Result of parsing a DOCX file */
|
|
32
|
-
export interface DocxParseResult {
|
|
33
|
-
/** HTML content extracted from the DOCX */
|
|
34
|
-
html: string;
|
|
35
|
-
/** Images found in the document */
|
|
36
|
-
images: ImageReference[];
|
|
37
|
-
/** Document metadata */
|
|
38
|
-
metadata: DocumentMetadata;
|
|
39
|
-
/** Any warnings generated during parsing */
|
|
40
|
-
warnings: string[];
|
|
41
|
-
}
|
|
42
|
-
/** Error thrown when DOCX parsing fails */
|
|
43
|
-
export declare class DocxParseError extends Error {
|
|
44
|
-
readonly code: 'CORRUPTED' | 'INVALID_FORMAT' | 'PARSE_ERROR';
|
|
45
|
-
readonly originalError?: Error | undefined;
|
|
46
|
-
constructor(message: string, code: 'CORRUPTED' | 'INVALID_FORMAT' | 'PARSE_ERROR', originalError?: Error | undefined);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Reset image counter (primarily for testing)
|
|
50
|
-
*/
|
|
51
|
-
export declare function resetImageCounter(): void;
|
|
52
|
-
/**
|
|
53
|
-
* DOCX Adapter class
|
|
54
|
-
*
|
|
55
|
-
* Handles conversion of DOCX files to HTML using Mammoth.js.
|
|
56
|
-
* Images are converted to placeholder text rather than base64 data
|
|
57
|
-
* to keep output clean and avoid bloating the markdown.
|
|
58
|
-
*/
|
|
59
|
-
export declare class DocxAdapter {
|
|
60
|
-
private mammoth;
|
|
61
|
-
/**
|
|
62
|
-
* Load the Mammoth library if not already loaded
|
|
63
|
-
*/
|
|
64
|
-
private ensureMammothLoaded;
|
|
65
|
-
/**
|
|
66
|
-
* Parse a DOCX file and convert it to HTML
|
|
67
|
-
*
|
|
68
|
-
* @param arrayBuffer - The DOCX file content as an ArrayBuffer
|
|
69
|
-
* @returns Promise resolving to the parse result with HTML and metadata
|
|
70
|
-
* @throws DocxParseError if the file cannot be parsed
|
|
71
|
-
*/
|
|
72
|
-
parseToHtml(arrayBuffer: ArrayBuffer): Promise<DocxParseResult>;
|
|
73
|
-
/**
|
|
74
|
-
* Extract raw text from a DOCX file (without formatting)
|
|
75
|
-
*
|
|
76
|
-
* @param arrayBuffer - The DOCX file content as an ArrayBuffer
|
|
77
|
-
* @returns Promise resolving to the raw text content
|
|
78
|
-
*/
|
|
79
|
-
extractRawText(arrayBuffer: ArrayBuffer): Promise<string>;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Singleton instance for convenience
|
|
83
|
-
*/
|
|
84
|
-
export declare const docxAdapter: DocxAdapter;
|
|
85
|
-
//# sourceMappingURL=docx-adapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docx-adapter.d.ts","sourceRoot":"","sources":["../../../../../../src/shared/adapters/docx-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,0CAA0C;AAC1C,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,2CAA2C;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iCAAiC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,4CAA4C;AAC5C,MAAM,WAAW,gBAAgB;IAC/B,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,mCAAmC;IACnC,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,wBAAwB;IACxB,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,2CAA2C;AAC3C,qBAAa,cAAe,SAAQ,KAAK;aAGrB,IAAI,EAAE,WAAW,GAAG,gBAAgB,GAAG,aAAa;aACpD,aAAa,CAAC,EAAE,KAAK;gBAFrC,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,WAAW,GAAG,gBAAgB,GAAG,aAAa,EACpD,aAAa,CAAC,EAAE,KAAK,YAAA;CAKxC;AAOD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,IAAI,CAExC;AAED;;;;;;GAMG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAA2B;IAE1C;;OAEG;YACW,mBAAmB;IAOjC;;;;;;OAMG;IACG,WAAW,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,eAAe,CAAC;IAsHrE;;;;;OAKG;IACG,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;CAehE;AAED;;GAEG;AACH,eAAO,MAAM,WAAW,aAAoB,CAAC"}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DOCX Adapter Module
|
|
3
|
-
*
|
|
4
|
-
* Converts DOCX files to HTML using Mammoth.js for processing through
|
|
5
|
-
* the existing ConversionEngine pipeline.
|
|
6
|
-
*
|
|
7
|
-
* Requirements: 1.1, 1.3, 1.4, 1.5, 1.6
|
|
8
|
-
*/
|
|
9
|
-
import { loadLibrary } from '@/shared/dynamic-loader';
|
|
10
|
-
/** Error thrown when DOCX parsing fails */
|
|
11
|
-
export class DocxParseError extends Error {
|
|
12
|
-
code;
|
|
13
|
-
originalError;
|
|
14
|
-
constructor(message, code, originalError) {
|
|
15
|
-
super(message);
|
|
16
|
-
this.code = code;
|
|
17
|
-
this.originalError = originalError;
|
|
18
|
-
this.name = 'DocxParseError';
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Counter for generating unique image IDs
|
|
23
|
-
*/
|
|
24
|
-
let imageCounter = 0;
|
|
25
|
-
/**
|
|
26
|
-
* Reset image counter (primarily for testing)
|
|
27
|
-
*/
|
|
28
|
-
export function resetImageCounter() {
|
|
29
|
-
imageCounter = 0;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* DOCX Adapter class
|
|
33
|
-
*
|
|
34
|
-
* Handles conversion of DOCX files to HTML using Mammoth.js.
|
|
35
|
-
* Images are converted to placeholder text rather than base64 data
|
|
36
|
-
* to keep output clean and avoid bloating the markdown.
|
|
37
|
-
*/
|
|
38
|
-
export class DocxAdapter {
|
|
39
|
-
mammoth = null;
|
|
40
|
-
/**
|
|
41
|
-
* Load the Mammoth library if not already loaded
|
|
42
|
-
*/
|
|
43
|
-
async ensureMammothLoaded() {
|
|
44
|
-
if (!this.mammoth) {
|
|
45
|
-
this.mammoth = await loadLibrary('mammoth');
|
|
46
|
-
}
|
|
47
|
-
return this.mammoth;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Parse a DOCX file and convert it to HTML
|
|
51
|
-
*
|
|
52
|
-
* @param arrayBuffer - The DOCX file content as an ArrayBuffer
|
|
53
|
-
* @returns Promise resolving to the parse result with HTML and metadata
|
|
54
|
-
* @throws DocxParseError if the file cannot be parsed
|
|
55
|
-
*/
|
|
56
|
-
async parseToHtml(arrayBuffer) {
|
|
57
|
-
const mammoth = await this.ensureMammothLoaded();
|
|
58
|
-
const images = [];
|
|
59
|
-
const warnings = [];
|
|
60
|
-
try {
|
|
61
|
-
// Custom image converter that creates placeholder text instead of base64
|
|
62
|
-
// This satisfies Requirement 1.5: no base64 embedding
|
|
63
|
-
const imageConverter = {
|
|
64
|
-
__mammothType: 'image-converter',
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
-
_convert: async (image) => {
|
|
67
|
-
imageCounter++;
|
|
68
|
-
const imageId = imageCounter;
|
|
69
|
-
// Extract image information
|
|
70
|
-
const contentType = image.contentType || 'image/unknown';
|
|
71
|
-
const altText = image.altText || '';
|
|
72
|
-
// Generate a filename based on content type
|
|
73
|
-
const extension = contentType.split('/')[1] || 'bin';
|
|
74
|
-
const filename = `image-${imageId}.${extension}`;
|
|
75
|
-
// Store image reference
|
|
76
|
-
const imageRef = {
|
|
77
|
-
filename,
|
|
78
|
-
contentType,
|
|
79
|
-
altText: altText || undefined,
|
|
80
|
-
};
|
|
81
|
-
images.push(imageRef);
|
|
82
|
-
// Return a placeholder src that will be converted to text
|
|
83
|
-
// Using a data URI with a special marker that we'll replace
|
|
84
|
-
return { src: `[IMAGE: ${filename}${altText ? ` - ${altText}` : ''}]` };
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
// Convert DOCX to HTML using Mammoth
|
|
88
|
-
// Mammoth handles: headings, bold, italic, lists, tables (Req 1.3, 1.4, 1.6)
|
|
89
|
-
const result = await mammoth.convertToHtml({
|
|
90
|
-
arrayBuffer,
|
|
91
|
-
}, {
|
|
92
|
-
// Use custom image converter to avoid base64 embedding
|
|
93
|
-
convertImage: imageConverter,
|
|
94
|
-
});
|
|
95
|
-
// Process Mammoth messages into warnings
|
|
96
|
-
if (result.messages && Array.isArray(result.messages)) {
|
|
97
|
-
for (const msg of result.messages) {
|
|
98
|
-
if (msg && typeof msg === 'object' && 'message' in msg) {
|
|
99
|
-
const message = msg.message;
|
|
100
|
-
const type = msg.type;
|
|
101
|
-
if (type === 'warning' || type === 'error') {
|
|
102
|
-
warnings.push(message);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
// Post-process HTML to convert image placeholders to proper text
|
|
108
|
-
let html = result.value || '';
|
|
109
|
-
// Replace img tags with placeholder src to plain text placeholders
|
|
110
|
-
html = html.replace(/<img[^>]*src="(\[IMAGE:[^\]]+\])"[^>]*>/gi, (_, placeholder) => `<p><em>${placeholder}</em></p>`);
|
|
111
|
-
return {
|
|
112
|
-
html,
|
|
113
|
-
images,
|
|
114
|
-
metadata: {
|
|
115
|
-
imageCount: images.length,
|
|
116
|
-
},
|
|
117
|
-
warnings,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
catch (error) {
|
|
121
|
-
// Handle specific Mammoth errors
|
|
122
|
-
const errorMessage = error instanceof Error ? error.message.toLowerCase() : String(error).toLowerCase();
|
|
123
|
-
// Check for format issues first (more specific)
|
|
124
|
-
if (errorMessage.includes('not a valid') ||
|
|
125
|
-
errorMessage.includes('not a zip') ||
|
|
126
|
-
errorMessage.includes('missing required') ||
|
|
127
|
-
errorMessage.includes('missing file')) {
|
|
128
|
-
throw new DocxParseError('This file does not appear to be a valid DOCX document.', 'INVALID_FORMAT', error instanceof Error ? error : undefined);
|
|
129
|
-
}
|
|
130
|
-
// Check for common corruption indicators
|
|
131
|
-
if (errorMessage.includes('could not find') ||
|
|
132
|
-
errorMessage.includes('invalid') ||
|
|
133
|
-
errorMessage.includes('unexpected') ||
|
|
134
|
-
errorMessage.includes('corrupted') ||
|
|
135
|
-
errorMessage.includes('end of data')) {
|
|
136
|
-
throw new DocxParseError('Unable to read this file. It may be corrupted. Try opening it in Word first to verify it\'s valid.', 'CORRUPTED', error instanceof Error ? error : undefined);
|
|
137
|
-
}
|
|
138
|
-
// Generic parse error
|
|
139
|
-
throw new DocxParseError(`Failed to parse DOCX file: ${error instanceof Error ? error.message : String(error)}`, 'PARSE_ERROR', error instanceof Error ? error : undefined);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Extract raw text from a DOCX file (without formatting)
|
|
144
|
-
*
|
|
145
|
-
* @param arrayBuffer - The DOCX file content as an ArrayBuffer
|
|
146
|
-
* @returns Promise resolving to the raw text content
|
|
147
|
-
*/
|
|
148
|
-
async extractRawText(arrayBuffer) {
|
|
149
|
-
const mammoth = await this.ensureMammothLoaded();
|
|
150
|
-
try {
|
|
151
|
-
const result = await mammoth.extractRawText({ arrayBuffer });
|
|
152
|
-
return result.value || '';
|
|
153
|
-
}
|
|
154
|
-
catch (error) {
|
|
155
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
156
|
-
throw new DocxParseError(`Failed to extract text from DOCX: ${errorMessage}`, 'PARSE_ERROR', error instanceof Error ? error : undefined);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Singleton instance for convenience
|
|
162
|
-
*/
|
|
163
|
-
export const docxAdapter = new DocxAdapter();
|
|
164
|
-
//# sourceMappingURL=docx-adapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"docx-adapter.js","sourceRoot":"","sources":["../../../../../../src/shared/adapters/docx-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAmB,MAAM,yBAAyB,CAAC;AAsCvE,2CAA2C;AAC3C,MAAM,OAAO,cAAe,SAAQ,KAAK;IAGrB;IACA;IAHlB,YACE,OAAe,EACC,IAAoD,EACpD,aAAqB;QAErC,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAgD;QACpD,kBAAa,GAAb,aAAa,CAAQ;QAGrC,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED;;GAEG;AACH,IAAI,YAAY,GAAG,CAAC,CAAC;AAErB;;GAEG;AACH,MAAM,UAAU,iBAAiB;IAC/B,YAAY,GAAG,CAAC,CAAC;AACnB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,OAAO,WAAW;IACd,OAAO,GAAsB,IAAI,CAAC;IAE1C;;OAEG;IACK,KAAK,CAAC,mBAAmB;QAC/B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAClB,IAAI,CAAC,OAAO,GAAG,MAAM,WAAW,CAAC,SAAS,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,WAAW,CAAC,WAAwB;QACxC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACjD,MAAM,MAAM,GAAqB,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,IAAI,CAAC;YACH,yEAAyE;YACzE,sDAAsD;YACtD,MAAM,cAAc,GAAG;gBACrB,aAAa,EAAE,iBAA0B;gBACzC,8DAA8D;gBAC9D,QAAQ,EAAE,KAAK,EAA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AM,CAAC,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PDF Adapter Module
|
|
3
|
-
*
|
|
4
|
-
* Converts PDF files to text/HTML using PDF.js for processing through
|
|
5
|
-
* the existing ConversionEngine pipeline.
|
|
6
|
-
*
|
|
7
|
-
* Requirements: 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8
|
|
8
|
-
*/
|
|
9
|
-
/** Page information extracted from PDF */
|
|
10
|
-
export interface PdfPageInfo {
|
|
11
|
-
/** Page number (1-indexed) */
|
|
12
|
-
pageNumber: number;
|
|
13
|
-
/** Text content extracted from the page */
|
|
14
|
-
textContent: string;
|
|
15
|
-
/** Whether the page contains images */
|
|
16
|
-
hasImages: boolean;
|
|
17
|
-
/** Viewport width for multi-column detection */
|
|
18
|
-
viewportWidth?: number;
|
|
19
|
-
}
|
|
20
|
-
/** PDF metadata extracted during parsing */
|
|
21
|
-
export interface PdfMetadata {
|
|
22
|
-
/** Document title (if available) */
|
|
23
|
-
title?: string;
|
|
24
|
-
/** Document author (if available) */
|
|
25
|
-
author?: string;
|
|
26
|
-
/** Total number of pages */
|
|
27
|
-
pageCount: number;
|
|
28
|
-
/** Whether the PDF is text-based (has text layer) */
|
|
29
|
-
isTextBased: boolean;
|
|
30
|
-
}
|
|
31
|
-
/** Result of parsing a PDF file */
|
|
32
|
-
export interface PdfParseResult {
|
|
33
|
-
/** HTML content with page markers */
|
|
34
|
-
html: string;
|
|
35
|
-
/** Information about each page */
|
|
36
|
-
pages: PdfPageInfo[];
|
|
37
|
-
/** Document metadata */
|
|
38
|
-
metadata: PdfMetadata;
|
|
39
|
-
/** Whether the PDF is text-based */
|
|
40
|
-
isTextBased: boolean;
|
|
41
|
-
/** Any warnings generated during parsing */
|
|
42
|
-
warnings: string[];
|
|
43
|
-
}
|
|
44
|
-
/** Error thrown when PDF parsing fails */
|
|
45
|
-
export declare class PdfParseError extends Error {
|
|
46
|
-
readonly code: 'CORRUPTED' | 'PASSWORD_PROTECTED' | 'IMAGE_ONLY' | 'PARSE_ERROR';
|
|
47
|
-
readonly originalError?: Error | undefined;
|
|
48
|
-
constructor(message: string, code: 'CORRUPTED' | 'PASSWORD_PROTECTED' | 'IMAGE_ONLY' | 'PARSE_ERROR', originalError?: Error | undefined);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* PDF Adapter class
|
|
52
|
-
*
|
|
53
|
-
* Handles conversion of PDF files to HTML using PDF.js.
|
|
54
|
-
* Extracts text content and adds page markers between pages.
|
|
55
|
-
*/
|
|
56
|
-
export declare class PdfAdapter {
|
|
57
|
-
private pdfjs;
|
|
58
|
-
/**
|
|
59
|
-
* Load the PDF.js library if not already loaded
|
|
60
|
-
*/
|
|
61
|
-
private ensurePdfjsLoaded;
|
|
62
|
-
/**
|
|
63
|
-
* Parse a PDF file and convert it to HTML with page markers
|
|
64
|
-
*
|
|
65
|
-
* @param arrayBuffer - The PDF file content as an ArrayBuffer
|
|
66
|
-
* @param onProgress - Optional progress callback (0-1)
|
|
67
|
-
* @returns Promise resolving to the parse result with HTML and metadata
|
|
68
|
-
* @throws PdfParseError if the file cannot be parsed
|
|
69
|
-
*/
|
|
70
|
-
parseToText(arrayBuffer: ArrayBuffer, onProgress?: (progress: number) => void): Promise<PdfParseResult>;
|
|
71
|
-
/**
|
|
72
|
-
* Convert parsed pages to HTML with page markers
|
|
73
|
-
*
|
|
74
|
-
* Requirement 3.5: Insert page markers between pages
|
|
75
|
-
*
|
|
76
|
-
* Note: We use a <div> element with data-page-marker attribute instead of
|
|
77
|
-
* HTML comments because DOMPurify strips comments by default. The marker
|
|
78
|
-
* element survives sanitization and is converted to the comment format
|
|
79
|
-
* after sanitization in the file processor pipeline.
|
|
80
|
-
*/
|
|
81
|
-
private pagesToHtml;
|
|
82
|
-
/**
|
|
83
|
-
* Get the number of pages in a PDF without full parsing
|
|
84
|
-
*
|
|
85
|
-
* @param arrayBuffer - The PDF file content as an ArrayBuffer
|
|
86
|
-
* @returns Promise resolving to the page count
|
|
87
|
-
*/
|
|
88
|
-
getPageCount(arrayBuffer: ArrayBuffer): Promise<number>;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Singleton instance for convenience
|
|
92
|
-
*/
|
|
93
|
-
export declare const pdfAdapter: PdfAdapter;
|
|
94
|
-
//# sourceMappingURL=pdf-adapter.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pdf-adapter.d.ts","sourceRoot":"","sources":["../../../../../../src/shared/adapters/pdf-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,0CAA0C;AAC1C,MAAM,WAAW,WAAW;IAC1B,8BAA8B;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,SAAS,EAAE,OAAO,CAAC;IACnB,gDAAgD;IAChD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,4CAA4C;AAC5C,MAAM,WAAW,WAAW;IAC1B,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4BAA4B;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,mCAAmC;AACnC,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,kCAAkC;IAClC,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,wBAAwB;IACxB,QAAQ,EAAE,WAAW,CAAC;IACtB,oCAAoC;IACpC,WAAW,EAAE,OAAO,CAAC;IACrB,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,0CAA0C;AAC1C,qBAAa,aAAc,SAAQ,KAAK;aAGp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