@poe-platform/safe-bash 0.1.652 → 0.1.654
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/pandoc/ast-types.d.ts +54 -0
- package/dist/pandoc/ast.d.ts +14 -0
- package/dist/pandoc/cli.d.ts +13 -0
- package/dist/pandoc/engine.d.ts +5 -0
- package/dist/pandoc/errors.d.ts +13 -0
- package/dist/pandoc/execution.d.ts +47 -0
- package/dist/pandoc/formats/index.d.ts +2 -0
- package/dist/pandoc/formats.d.ts +76 -0
- package/dist/pandoc/index.d.ts +14 -0
- package/dist/pandoc/inspection.d.ts +5 -0
- package/dist/pandoc/safe-bash.d.ts +38 -0
- package/dist/pandoc/types.d.ts +229 -0
- package/dist/pdf/default-font.d.ts +4 -0
- package/dist/pdf/errors.d.ts +4 -0
- package/dist/pdf/index.d.ts +32 -0
- package/dist/pdf/model.d.ts +92 -0
- package/dist/safe-bash/chunks/{chunk-IX6VL7KM.js → chunk-43HWIHXB.js} +122 -81
- package/dist/safe-bash/chunks/chunk-43HWIHXB.js.map +7 -0
- package/dist/safe-bash/chunks/{chunk-MQJRBELV.js → chunk-EYC5LGC7.js} +2 -2
- package/dist/safe-bash/chunks/chunk-EYC5LGC7.js.map +7 -0
- package/dist/safe-bash/chunks/chunk-Y7MAMRAF.js +143 -0
- package/dist/safe-bash/chunks/chunk-Y7MAMRAF.js.map +7 -0
- package/dist/safe-bash/commands/node/index.browser.js +1 -1
- package/dist/safe-bash/commands/pandoc/index.d.ts +11 -0
- package/dist/safe-bash/commands/pandoc/index.d.ts.map +1 -0
- package/dist/safe-bash/commands/pandoc/index.js +112084 -0
- package/dist/safe-bash/commands/pandoc/index.js.map +7 -0
- package/dist/safe-bash/commands/python/diagnostics.d.ts +42 -0
- package/dist/safe-bash/commands/python/diagnostics.d.ts.map +1 -0
- package/dist/safe-bash/commands/python/diagnostics.js +68 -0
- package/dist/safe-bash/commands/python/diagnostics.js.map +1 -0
- package/dist/safe-bash/commands/python/index.browser.js +7 -2
- package/dist/safe-bash/commands/python/index.d.ts +4 -0
- package/dist/safe-bash/commands/python/index.d.ts.map +1 -1
- package/dist/safe-bash/commands/python/index.js +120 -67
- package/dist/safe-bash/commands/python/index.js.map +1 -1
- package/dist/safe-bash/commands/python/node.js +2 -2
- package/dist/safe-bash/commands/python/node.js.map +1 -1
- package/dist/safe-bash/commands/python/worker.browser.js +41 -12
- package/dist/safe-bash/commands/python/worker.browser.js.map +2 -2
- package/dist/safe-bash/commands/python/worker.d.ts.map +1 -1
- package/dist/safe-bash/commands/python/worker.js +41 -12
- package/dist/safe-bash/commands/python/worker.js.map +1 -1
- package/dist/safe-bash/core.browser.js +8 -3
- package/dist/safe-bash/core.browser.js.map +1 -1
- package/package.json +9 -3
- package/dist/safe-bash/chunks/chunk-IX6VL7KM.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-JZDO5MC3.js +0 -77
- package/dist/safe-bash/chunks/chunk-JZDO5MC3.js.map +0 -7
- package/dist/safe-bash/chunks/chunk-MQJRBELV.js.map +0 -7
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type Attr = readonly [string, readonly string[], readonly (readonly [string, string])[]];
|
|
2
|
+
export type Target = readonly [string, string];
|
|
3
|
+
type Tagged<T extends string, C> = {
|
|
4
|
+
readonly t: T;
|
|
5
|
+
readonly c: C;
|
|
6
|
+
};
|
|
7
|
+
type Empty<T extends string> = {
|
|
8
|
+
readonly t: T;
|
|
9
|
+
};
|
|
10
|
+
export type Inline = Tagged<"Str", string> | Empty<"Space" | "SoftBreak" | "LineBreak"> | Tagged<"Emph" | "Underline" | "Strong" | "Strikeout" | "Superscript" | "Subscript" | "SmallCaps", readonly Inline[]> | Tagged<"Quoted", readonly ["SingleQuote" | "DoubleQuote", readonly Inline[]]> | Tagged<"Cite", readonly [readonly Citation[], readonly Inline[]]> | Tagged<"Code", readonly [Attr, string]> | Tagged<"Math", readonly ["InlineMath" | "DisplayMath", string]> | Tagged<"RawInline", readonly [string, string]> | Tagged<"Link" | "Image", readonly [Attr, readonly Inline[], Target]> | Tagged<"Note", readonly Block[]> | Tagged<"Span", readonly [Attr, readonly Inline[]]>;
|
|
11
|
+
export interface Citation {
|
|
12
|
+
readonly citationId: string;
|
|
13
|
+
readonly citationPrefix: readonly Inline[];
|
|
14
|
+
readonly citationSuffix: readonly Inline[];
|
|
15
|
+
readonly citationMode: "AuthorInText" | "SuppressAuthor" | "NormalCitation";
|
|
16
|
+
readonly citationNoteNum: number;
|
|
17
|
+
readonly citationHash: number;
|
|
18
|
+
}
|
|
19
|
+
export type Alignment = "AlignLeft" | "AlignRight" | "AlignCenter" | "AlignDefault";
|
|
20
|
+
export type Caption = readonly [readonly Inline[] | null, readonly Block[]];
|
|
21
|
+
export type ColSpec = readonly [Alignment, Empty<"ColWidthDefault"> | Tagged<"ColWidth", number>];
|
|
22
|
+
export type Cell = readonly [Attr, Alignment, number, number, readonly Block[]];
|
|
23
|
+
export type Row = readonly [Attr, readonly Cell[]];
|
|
24
|
+
export type TableHead = readonly [Attr, readonly Row[]];
|
|
25
|
+
export type TableBody = readonly [Attr, number, readonly Row[], readonly Row[]];
|
|
26
|
+
export type Block = Tagged<"Plain" | "Para", readonly Inline[]> | Tagged<"LineBlock", readonly (readonly Inline[])[]> | Tagged<"CodeBlock", readonly [Attr, string]> | Tagged<"RawBlock", readonly [string, string]> | Tagged<"BlockQuote", readonly Block[]> | Tagged<"OrderedList", readonly [
|
|
27
|
+
readonly [
|
|
28
|
+
number,
|
|
29
|
+
("DefaultStyle" | "Example" | "Decimal" | "LowerRoman" | "UpperRoman" | "LowerAlpha" | "UpperAlpha"),
|
|
30
|
+
"DefaultDelim" | "Period" | "OneParen" | "TwoParens"
|
|
31
|
+
],
|
|
32
|
+
readonly (readonly Block[])[]
|
|
33
|
+
]> | Tagged<"BulletList", readonly (readonly Block[])[]> | Tagged<"DefinitionList", readonly (readonly [readonly Inline[], readonly (readonly Block[])[]])[]> | Tagged<"Header", readonly [number, Attr, readonly Inline[]]> | Empty<"HorizontalRule"> | Tagged<"Div", readonly [Attr, readonly Block[]]> | Tagged<"Figure", readonly [Attr, Caption, readonly Block[]]> | Tagged<"Table", readonly [Attr, Caption, readonly ColSpec[], TableHead, readonly TableBody[], TableHead]>;
|
|
34
|
+
export type MetaValue = MetaMap | Tagged<"MetaList", readonly MetaValue[]> | Tagged<"MetaBool", boolean> | Tagged<"MetaString", string> | Tagged<"MetaInlines", readonly Inline[]> | Tagged<"MetaBlocks", readonly Block[]>;
|
|
35
|
+
/** Sidecars are never embedded in serialized document data. */
|
|
36
|
+
export interface SourcePosition {
|
|
37
|
+
readonly path: string;
|
|
38
|
+
readonly source: string;
|
|
39
|
+
readonly line: number;
|
|
40
|
+
readonly column: number;
|
|
41
|
+
}
|
|
42
|
+
export interface LossDiagnostic {
|
|
43
|
+
readonly path: string;
|
|
44
|
+
readonly feature: string;
|
|
45
|
+
readonly message: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function assertNever(value: never): never;
|
|
48
|
+
export interface MetaMap {
|
|
49
|
+
readonly t: "MetaMap";
|
|
50
|
+
readonly c: {
|
|
51
|
+
readonly [key: string]: MetaValue;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Document } from "./types.js";
|
|
2
|
+
export { AstError } from "./errors.js";
|
|
3
|
+
export interface AstLimits {
|
|
4
|
+
readonly depth: number;
|
|
5
|
+
readonly nodes: number;
|
|
6
|
+
readonly text: number;
|
|
7
|
+
readonly attributes: number;
|
|
8
|
+
readonly tableCells: number;
|
|
9
|
+
readonly references: number;
|
|
10
|
+
readonly resourceBytes: number;
|
|
11
|
+
}
|
|
12
|
+
/** Identity normalization retains a bounded owned AST by design. */
|
|
13
|
+
export declare function normalizeDocument(value: unknown, options?: Partial<AstLimits>): Document;
|
|
14
|
+
export declare function normalizeDocumentCooperatively(value: unknown, options: Partial<AstLimits>, cooperate: (units: number) => Promise<void>, reserve?: (key: keyof AstLimits, units: number) => void): Promise<Document>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ConversionOptions, InputSource } from "./types.js";
|
|
2
|
+
export interface CommandInputs {
|
|
3
|
+
readonly cwd?: string;
|
|
4
|
+
readonly stdin?: AsyncIterable<Uint8Array> | Iterable<Uint8Array>;
|
|
5
|
+
readFile?(path: string, signal: AbortSignal): Promise<Uint8Array>;
|
|
6
|
+
writeFile?(path: string, bytes: Uint8Array, signal: AbortSignal): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
/** Parsing creates lazy inputs. Only the validated converter may acquire them. */
|
|
9
|
+
export declare function parseConversionArgs(args: readonly string[], files: CommandInputs, signal: AbortSignal): {
|
|
10
|
+
options: ConversionOptions;
|
|
11
|
+
operands: readonly InputSource[] | undefined;
|
|
12
|
+
destination?: string;
|
|
13
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { PandocError } from "./errors.js";
|
|
2
|
+
import type { ConversionContext, ConversionOptions, ConversionResult, Document, InputSource, ReadOptions, WriteOptions } from "./types.js";
|
|
3
|
+
export declare function readDocument(input: InputSource, options: ReadOptions, context: ConversionContext): Promise<Document>;
|
|
4
|
+
export declare function writeDocument(document: Document, options: WriteOptions, context: ConversionContext): Promise<ConversionResult>;
|
|
5
|
+
export declare function convert(inputs: readonly InputSource[], options: ConversionOptions, context: ConversionContext): Promise<ConversionResult>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Diagnostic, DiagnosticCode, Operation } from "./types.js";
|
|
2
|
+
export declare class AstError extends Error {
|
|
3
|
+
readonly code: "E_AST" | "E_LIMIT";
|
|
4
|
+
readonly path: string;
|
|
5
|
+
constructor(code: "E_AST" | "E_LIMIT", path: string, message: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class PandocError extends Error implements Diagnostic {
|
|
8
|
+
readonly code: DiagnosticCode;
|
|
9
|
+
readonly operation: Operation;
|
|
10
|
+
readonly format?: string | undefined;
|
|
11
|
+
readonly location?: string | undefined;
|
|
12
|
+
constructor(code: DiagnosticCode, operation: Operation, message: string, format?: string | undefined, location?: string | undefined);
|
|
13
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AdapterContext, ConversionContext, Diagnostic, DiagnosticCode, Limits, Operation } from "./types.js";
|
|
2
|
+
/** Finite hard ceilings; callers may only lower them. No ambient environment settings. */
|
|
3
|
+
export declare const defaultLimits: Limits;
|
|
4
|
+
type Chunks = AsyncIterable<Uint8Array> | Iterable<Uint8Array>;
|
|
5
|
+
export declare class ExecutionContext implements AdapterContext {
|
|
6
|
+
readonly operation: Operation;
|
|
7
|
+
readonly context: ConversionContext;
|
|
8
|
+
readonly limits: Limits;
|
|
9
|
+
readonly signal: AbortSignal | undefined;
|
|
10
|
+
readonly resources: AdapterContext["resources"];
|
|
11
|
+
private readonly usage;
|
|
12
|
+
private readonly cursors;
|
|
13
|
+
private readonly notices;
|
|
14
|
+
private readonly cleanups;
|
|
15
|
+
private readonly closedSignal;
|
|
16
|
+
private failure;
|
|
17
|
+
private closing;
|
|
18
|
+
private outputComplete;
|
|
19
|
+
private completingOutput;
|
|
20
|
+
private outputStarted;
|
|
21
|
+
private pendingOutput;
|
|
22
|
+
private sinceYield;
|
|
23
|
+
constructor(operation: Operation, context: ConversionContext);
|
|
24
|
+
fail(code: DiagnosticCode, message: string): never;
|
|
25
|
+
checkpoint(units?: number): void;
|
|
26
|
+
bound(key: keyof Limits, actual: number): void;
|
|
27
|
+
charge(key: keyof Limits, units: number): void;
|
|
28
|
+
remaining(key: keyof Limits): number;
|
|
29
|
+
cooperate(units?: number): Promise<void>;
|
|
30
|
+
progress(id: string, cursor: number): void;
|
|
31
|
+
decodeEntity(code: number): string;
|
|
32
|
+
/** Decode only parser-selected RTF text runs, never control/binary sections. */
|
|
33
|
+
decodeCodepage(bytes: Uint8Array, codepage?: 1252 | 28591): Promise<string>;
|
|
34
|
+
retainBinaryBlock(bytes: Uint8Array): Uint8Array;
|
|
35
|
+
report(diagnostic: Diagnostic): void;
|
|
36
|
+
snapshotDiagnostics(): readonly Diagnostic[];
|
|
37
|
+
/** Cancellation races awaited capabilities; it cannot preempt synchronous host JavaScript. */
|
|
38
|
+
call<T>(callback: () => Promise<T>): Promise<T>;
|
|
39
|
+
consume(chunks: Chunks, accept: (bytes: Uint8Array) => Promise<void>, budgets?: readonly (keyof Limits)[]): Promise<void>;
|
|
40
|
+
acquire(chunks: Chunks, additionalBudget?: keyof Limits): Promise<Uint8Array>;
|
|
41
|
+
decodeUtf8(chunks: Chunks): Promise<string>;
|
|
42
|
+
emit(bytes: Uint8Array): Promise<void>;
|
|
43
|
+
completeOutput(): Promise<void>;
|
|
44
|
+
close(): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
export declare function createExecutionContext(operation: Operation, context?: ConversionContext): ExecutionContext;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ConversionContext, Limits, Operation, ReaderCapability, WriterCapability } from "./types.js";
|
|
2
|
+
export { coreFormats } from "./formats/index.js";
|
|
3
|
+
export type Direction = "read" | "write";
|
|
4
|
+
export interface FormatDescriptor {
|
|
5
|
+
/** Defaults to one operand. Explicit document mode merges ASTs in order. */
|
|
6
|
+
readonly operands?: "join" | "documents";
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly aliases?: Partial<Record<Direction, readonly string[]>>;
|
|
9
|
+
readonly read: boolean;
|
|
10
|
+
readonly write: boolean;
|
|
11
|
+
readonly media: "text" | "binary";
|
|
12
|
+
readonly inputEncoding: "utf8" | "bytes";
|
|
13
|
+
readonly inputBudget?: keyof Limits;
|
|
14
|
+
readonly suffixes: readonly string[];
|
|
15
|
+
readonly extensions: Readonly<Record<string, boolean>>;
|
|
16
|
+
readonly options: Readonly<Record<Direction, readonly string[]>>;
|
|
17
|
+
readonly reader?: ReaderCapability;
|
|
18
|
+
readonly writer?: WriterCapability;
|
|
19
|
+
}
|
|
20
|
+
export interface FormatCapability extends Omit<FormatDescriptor, "read" | "write" | "reader" | "writer"> {
|
|
21
|
+
readonly read: {
|
|
22
|
+
readonly allowed: boolean;
|
|
23
|
+
readonly available: boolean;
|
|
24
|
+
};
|
|
25
|
+
readonly write: {
|
|
26
|
+
readonly allowed: boolean;
|
|
27
|
+
readonly available: boolean;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface FormatSelection {
|
|
31
|
+
readonly descriptor: FormatDescriptor;
|
|
32
|
+
readonly extensions: Readonly<Record<string, boolean>>;
|
|
33
|
+
}
|
|
34
|
+
export declare function createFormatRegistry(descriptors?: readonly FormatDescriptor[], context?: ConversionContext, operation?: Operation): {
|
|
35
|
+
parse: (source: string, direction?: Direction) => FormatSelection;
|
|
36
|
+
resolve(source: string, direction: Direction): {
|
|
37
|
+
reader: ReaderCapability | undefined;
|
|
38
|
+
writer: WriterCapability | undefined;
|
|
39
|
+
descriptor: FormatDescriptor;
|
|
40
|
+
extensions: Readonly<Record<string, boolean>>;
|
|
41
|
+
};
|
|
42
|
+
list(direction: Direction): readonly string[];
|
|
43
|
+
listExtensions(source: string, direction?: Direction): readonly string[];
|
|
44
|
+
infer(path: string, direction: Direction): string;
|
|
45
|
+
validateOptions(source: string, direction: Direction, options: readonly string[]): void;
|
|
46
|
+
capabilities: readonly Readonly<{
|
|
47
|
+
read: Readonly<{
|
|
48
|
+
allowed: boolean;
|
|
49
|
+
available: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
write: Readonly<{
|
|
52
|
+
allowed: boolean;
|
|
53
|
+
available: boolean;
|
|
54
|
+
}>;
|
|
55
|
+
suffixes: readonly string[];
|
|
56
|
+
extensions: Readonly<{
|
|
57
|
+
[x: string]: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
options: Readonly<{
|
|
60
|
+
read: readonly string[];
|
|
61
|
+
write: readonly string[];
|
|
62
|
+
}>;
|
|
63
|
+
aliases?: Readonly<{
|
|
64
|
+
write?: readonly string[];
|
|
65
|
+
read?: readonly string[];
|
|
66
|
+
}>;
|
|
67
|
+
operands?: "join" | "documents";
|
|
68
|
+
name: string;
|
|
69
|
+
media: "text" | "binary";
|
|
70
|
+
inputEncoding: "utf8" | "bytes";
|
|
71
|
+
inputBudget?: keyof Limits;
|
|
72
|
+
reader?: ReaderCapability;
|
|
73
|
+
writer?: WriterCapability;
|
|
74
|
+
}>[];
|
|
75
|
+
};
|
|
76
|
+
export declare const formatCapabilities: readonly FormatCapability[];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { convert, readDocument, writeDocument, PandocError } from "./engine.js";
|
|
2
|
+
export { createFormatRegistry, coreFormats, formatCapabilities } from "./formats.js";
|
|
3
|
+
export type { FormatCapability, FormatDescriptor, FormatSelection, Direction } from "./formats.js";
|
|
4
|
+
export type { AdapterContext, ConversionContext, ConversionOptions, MetadataObject, MetadataValue, ConversionResult, Diagnostic, DiagnosticCode, Document, Input, InputSource, StreamingInput, Limits, Node, Operation, OutputCapability, StreamingOutputCapability, ReadOptions, ReaderCapability, Resource, ResourceCapability, ResourceFileSystem, SerializedDocument, WriteOptions, PdfOptions, EpubOptions, WriterCapability } from "./types.js";
|
|
5
|
+
export { normalizeDocument, normalizeDocumentCooperatively, AstError } from "./ast.js";
|
|
6
|
+
export { createExecutionContext, ExecutionContext, defaultLimits } from "./execution.js";
|
|
7
|
+
export type { AstLimits } from "./ast.js";
|
|
8
|
+
export { assertNever } from "./ast-types.js";
|
|
9
|
+
export type { Attr, Target, Inline, Block, MetaValue, Citation, Alignment, Caption, ColSpec, Cell, Row, TableHead, TableBody, SourcePosition, LossDiagnostic } from "./ast-types.js";
|
|
10
|
+
export { inspectFormats, inspectCommand } from "./inspection.js";
|
|
11
|
+
export { createFormatInspectionCommand, createPandocCommand } from "./safe-bash.js";
|
|
12
|
+
export type { FormatInspectionContext, PandocCommandContext } from "./safe-bash.js";
|
|
13
|
+
export { parseConversionArgs } from "./cli.js";
|
|
14
|
+
export type { CommandInputs } from "./cli.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ConversionContext } from "./types.js";
|
|
2
|
+
/** Information modes are validated without acquiring conversion inputs. */
|
|
3
|
+
export declare function inspectCommand(args: readonly string[], context?: ConversionContext): string | undefined;
|
|
4
|
+
/** SDK counterpart of the three format inspection flags. No input/output I/O. */
|
|
5
|
+
export declare function inspectFormats(args: readonly string[], context?: ConversionContext): string;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ConversionContext, ResourceFileSystem } from "./types.js";
|
|
2
|
+
import type { CommandInputs } from "./cli.js";
|
|
3
|
+
/** Structural subset of safe-bash CommandContext: no filesystem or ambient host access. */
|
|
4
|
+
export interface FormatInspectionContext {
|
|
5
|
+
readonly args: readonly string[];
|
|
6
|
+
readonly signal: AbortSignal;
|
|
7
|
+
readonly stdout: {
|
|
8
|
+
write(bytes: Uint8Array): Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
readonly stderr: {
|
|
11
|
+
write(bytes: Uint8Array): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export interface PandocCommandContext extends FormatInspectionContext, CommandInputs {
|
|
15
|
+
readonly fs?: ResourceFileSystem & {
|
|
16
|
+
readFile(path: string, options?: {
|
|
17
|
+
signal?: AbortSignal;
|
|
18
|
+
}): Promise<Uint8Array>;
|
|
19
|
+
};
|
|
20
|
+
readonly stdin: AsyncIterable<Uint8Array> | Iterable<Uint8Array>;
|
|
21
|
+
}
|
|
22
|
+
/** Opt-in conversion adapter. File access requires explicit injected callbacks;
|
|
23
|
+
* all conversion and limits belong to the SDK. It never invokes native tools. */
|
|
24
|
+
export declare function createPandocCommand(capabilities?: Omit<ConversionContext, "output" | "signal" | "resources" | "resourceFiles" | "resourceCwd">): {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
execute(context: PandocCommandContext): Promise<{
|
|
28
|
+
exitCode: number;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
/** Opt-in safe-bash command for registry inspection; conversion command wiring is separate. */
|
|
32
|
+
export declare function createFormatInspectionCommand(capabilities?: ConversionContext): {
|
|
33
|
+
name: string;
|
|
34
|
+
description: string;
|
|
35
|
+
execute(context: FormatInspectionContext): Promise<{
|
|
36
|
+
exitCode: number;
|
|
37
|
+
}>;
|
|
38
|
+
};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { FormatSelection } from "./formats.js";
|
|
2
|
+
import type { Block, Inline, MetaValue } from "./ast-types.js";
|
|
3
|
+
import type { PageBox, SuppliedFont } from "../pdf/index.js";
|
|
4
|
+
export type Node = Block | Inline;
|
|
5
|
+
export interface Resource {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly bytes: Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
export interface Document {
|
|
10
|
+
readonly blocks: readonly Block[];
|
|
11
|
+
readonly metadata: Readonly<Record<string, MetaValue>>;
|
|
12
|
+
readonly resources: readonly Resource[];
|
|
13
|
+
readonly language?: string;
|
|
14
|
+
readonly direction?: "ltr" | "rtl" | "auto";
|
|
15
|
+
}
|
|
16
|
+
export interface Input {
|
|
17
|
+
readonly source?: string;
|
|
18
|
+
readonly bytes: Uint8Array;
|
|
19
|
+
/** Present for UTF-8 formats after per-input BOM/newline normalization. */
|
|
20
|
+
readonly text?: string;
|
|
21
|
+
/** VFS source directory for image resolution; source is the diagnostic identity. */
|
|
22
|
+
readonly base?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface StreamingInput {
|
|
25
|
+
readonly source?: string;
|
|
26
|
+
readonly chunks: AsyncIterable<Uint8Array> | Iterable<Uint8Array>;
|
|
27
|
+
readonly base?: string;
|
|
28
|
+
}
|
|
29
|
+
export type InputSource = Input | StreamingInput;
|
|
30
|
+
export type SerializedDocument = {
|
|
31
|
+
readonly kind: "text";
|
|
32
|
+
readonly text: string;
|
|
33
|
+
} | {
|
|
34
|
+
readonly kind: "binary";
|
|
35
|
+
readonly bytes: Uint8Array;
|
|
36
|
+
};
|
|
37
|
+
export type ConversionResult = SerializedDocument & {
|
|
38
|
+
readonly diagnostics: readonly Diagnostic[];
|
|
39
|
+
};
|
|
40
|
+
export type Operation = "read" | "write" | "convert";
|
|
41
|
+
export type DiagnosticCode = "E_FORMAT_REQUIRED" | "E_FORMAT" | "E_EXTENSION" | "E_OPTION" | "E_METADATA" | "E_CAPABILITY" | "E_UNSUPPORTED_FEATURE" | "E_AST" | "E_ENCODING" | "E_PARSE" | "E_LIMIT" | "E_CANCELLED" | "E_IO" | "E_RESOURCE" | "E_INTERNAL" | "E_WARNINGS" | "W_TABLE_LOSS" | "W_PRESENTATION_LOSS" | "W_LAYOUT_UNMEASURED" | "W_RAW_CONTENT" | "W_METADATA_CONFLICT" | "W_RESOURCE_MISSING";
|
|
42
|
+
export interface Diagnostic {
|
|
43
|
+
readonly code: DiagnosticCode;
|
|
44
|
+
readonly operation: Operation;
|
|
45
|
+
readonly message: string;
|
|
46
|
+
readonly format?: string | undefined;
|
|
47
|
+
readonly location?: string | undefined;
|
|
48
|
+
}
|
|
49
|
+
export interface Limits {
|
|
50
|
+
readonly inputBytes: number;
|
|
51
|
+
readonly resourceBytes: number;
|
|
52
|
+
readonly outputBytes: number;
|
|
53
|
+
readonly nodes: number;
|
|
54
|
+
readonly depth: number;
|
|
55
|
+
readonly work: number;
|
|
56
|
+
readonly retainedBytes: number;
|
|
57
|
+
readonly text: number;
|
|
58
|
+
readonly attributes: number;
|
|
59
|
+
readonly tableCells: number;
|
|
60
|
+
/** Delimited reader ceilings: decoded UTF-16 units per field, records including header, columns. */
|
|
61
|
+
readonly tableFieldText: number;
|
|
62
|
+
readonly tableRows: number;
|
|
63
|
+
readonly tableColumns: number;
|
|
64
|
+
readonly resources: number;
|
|
65
|
+
readonly diagnostics: number;
|
|
66
|
+
readonly references: number;
|
|
67
|
+
readonly entities: number;
|
|
68
|
+
readonly entityBytes: number;
|
|
69
|
+
readonly compressedBytes: number;
|
|
70
|
+
readonly expandedBytes: number;
|
|
71
|
+
readonly parts: number;
|
|
72
|
+
readonly xmlDepth: number;
|
|
73
|
+
readonly xmlNodes: number;
|
|
74
|
+
readonly binaryBytes: number;
|
|
75
|
+
readonly macros: number;
|
|
76
|
+
readonly includes: number;
|
|
77
|
+
readonly directives: number;
|
|
78
|
+
readonly fonts: number;
|
|
79
|
+
readonly glyphs: number;
|
|
80
|
+
readonly pages: number;
|
|
81
|
+
readonly objects: number;
|
|
82
|
+
readonly images: number;
|
|
83
|
+
readonly layoutWork: number;
|
|
84
|
+
}
|
|
85
|
+
export interface ReadOptions {
|
|
86
|
+
readonly from: string;
|
|
87
|
+
}
|
|
88
|
+
export interface PdfOptions {
|
|
89
|
+
readonly pageSize?: "a4" | "letter";
|
|
90
|
+
readonly orientation?: "portrait" | "landscape";
|
|
91
|
+
readonly margin?: number;
|
|
92
|
+
/** Only mono is currently supplied; other named families fail E_CAPABILITY. */
|
|
93
|
+
readonly font?: "serif" | "sans" | "mono";
|
|
94
|
+
readonly fontSize?: number;
|
|
95
|
+
readonly lineHeight?: number;
|
|
96
|
+
}
|
|
97
|
+
export interface EpubOptions {
|
|
98
|
+
readonly title?: string;
|
|
99
|
+
readonly language?: string;
|
|
100
|
+
readonly identifier?: string;
|
|
101
|
+
/** Split before headings at this level or shallower; 1 through 6. */
|
|
102
|
+
readonly chapterLevel?: number;
|
|
103
|
+
}
|
|
104
|
+
export interface WriteOptions {
|
|
105
|
+
/** Opt into format metadata defaults; absent means strict explicit metadata. */
|
|
106
|
+
readonly yes?: boolean;
|
|
107
|
+
readonly pdf?: PdfOptions;
|
|
108
|
+
readonly epub?: EpubOptions;
|
|
109
|
+
/** PDF-only geometry in points, equivalent to --pdf-page WIDTH,HEIGHT,MARGIN. */
|
|
110
|
+
readonly pdfPage?: PageBox;
|
|
111
|
+
/** Ordered supplied sfnt sources; replaces the packaged font. CLI: repeat --pdf-font PATH. */
|
|
112
|
+
readonly pdfFonts?: readonly InputSource[];
|
|
113
|
+
/** Ordered VFS directories, replacing the source-directory search when present. */
|
|
114
|
+
readonly resourcePath?: readonly string[];
|
|
115
|
+
/** Extract image resources into this VFS directory; never download media implicitly. */
|
|
116
|
+
readonly extractMedia?: string;
|
|
117
|
+
readonly failIfWarnings?: boolean;
|
|
118
|
+
/** Ordered parsed JSON maps. Later values win; null deletes a key. */
|
|
119
|
+
readonly metadataJson?: readonly MetadataObject[];
|
|
120
|
+
/** Explicit JSON inputs only. No ambient files are loaded. */
|
|
121
|
+
readonly metadataFiles?: readonly InputSource[];
|
|
122
|
+
readonly wrap?: "none";
|
|
123
|
+
readonly to: string;
|
|
124
|
+
readonly standalone?: boolean;
|
|
125
|
+
readonly metadata?: Readonly<Record<string, MetaValue>>;
|
|
126
|
+
readonly rawContent?: "reject" | "escape" | "retain";
|
|
127
|
+
/** Strict by default; explicitly permit diagnosed table text projections. */
|
|
128
|
+
readonly lossy?: boolean;
|
|
129
|
+
}
|
|
130
|
+
export interface ConversionOptions extends ReadOptions, WriteOptions {
|
|
131
|
+
}
|
|
132
|
+
export interface MetadataObject {
|
|
133
|
+
readonly [key: string]: MetadataValue;
|
|
134
|
+
}
|
|
135
|
+
export type MetadataValue = string | number | boolean | null | readonly MetadataValue[] | MetadataObject;
|
|
136
|
+
/** Explicit trusted adapters; their format conformance is not established by this seam. */
|
|
137
|
+
export interface AdapterContext {
|
|
138
|
+
readonly yes?: boolean | undefined;
|
|
139
|
+
readonly pdf?: PdfOptions | undefined;
|
|
140
|
+
readonly epub?: EpubOptions | undefined;
|
|
141
|
+
readonly pdfPage?: PageBox | undefined;
|
|
142
|
+
readonly pdfFonts?: readonly SuppliedFont[] | undefined;
|
|
143
|
+
/** Parser origin sidecar; never serialized into the AST. */
|
|
144
|
+
resourceTarget?(target: object, line: number, origin?: {
|
|
145
|
+
readonly base?: string;
|
|
146
|
+
readonly source?: string;
|
|
147
|
+
}): void;
|
|
148
|
+
readonly operation?: Operation;
|
|
149
|
+
readonly lossy?: boolean;
|
|
150
|
+
readonly standalone?: boolean;
|
|
151
|
+
readonly rawContent?: "reject" | "escape" | "retain" | undefined;
|
|
152
|
+
readonly signal: AbortSignal | undefined;
|
|
153
|
+
readonly limits: Limits;
|
|
154
|
+
readonly resources: ResourceCapability | undefined;
|
|
155
|
+
checkpoint(units?: number): void;
|
|
156
|
+
/** Reserve aggregate capacity before allocating or extending parser/writer data. */
|
|
157
|
+
charge(key: keyof Limits, units: number): void;
|
|
158
|
+
/** Check a gauge (e.g. nesting depth) without accumulating it. */
|
|
159
|
+
bound(key: keyof Limits, actual: number): void;
|
|
160
|
+
cooperate(units?: number): Promise<void>;
|
|
161
|
+
decodeUtf8(chunks: AsyncIterable<Uint8Array> | Iterable<Uint8Array>): Promise<string>;
|
|
162
|
+
/** Reserve entity expansion before constructing its Unicode scalar. */
|
|
163
|
+
decodeEntity(code: number): string;
|
|
164
|
+
decodeCodepage(bytes: Uint8Array, codepage?: 1252 | 28591): Promise<string>;
|
|
165
|
+
retainBinaryBlock(bytes: Uint8Array): Uint8Array;
|
|
166
|
+
report(diagnostic: Diagnostic): void;
|
|
167
|
+
/** Strictly advancing cursor for pagination and other iterative layouts. */
|
|
168
|
+
progress(id: string, cursor: number): void;
|
|
169
|
+
}
|
|
170
|
+
export interface ResourceCapability {
|
|
171
|
+
resolve(id: string, base: string | undefined, signal: AbortSignal | undefined): Promise<Uint8Array>;
|
|
172
|
+
}
|
|
173
|
+
export interface ReaderCapability {
|
|
174
|
+
readonly format: string;
|
|
175
|
+
read(input: Input, context: AdapterContext, selection?: FormatSelection): Promise<Document>;
|
|
176
|
+
}
|
|
177
|
+
export interface WriterCapability {
|
|
178
|
+
readonly format: string;
|
|
179
|
+
readonly math?: "source";
|
|
180
|
+
write(document: Document, context: AdapterContext, selection?: FormatSelection): Promise<SerializedDocument>;
|
|
181
|
+
}
|
|
182
|
+
/** publish must provide atomic publication; it receives owned bytes and must honor cancellation. */
|
|
183
|
+
export interface OutputCapability {
|
|
184
|
+
publish(bytes: Uint8Array, signal: AbortSignal | undefined): Promise<void>;
|
|
185
|
+
}
|
|
186
|
+
/** Streaming hosts may expose partial output on failure; close must report commit failure. */
|
|
187
|
+
export interface StreamingOutputCapability {
|
|
188
|
+
write(bytes: Uint8Array, signal: AbortSignal | undefined): Promise<void>;
|
|
189
|
+
close(signal: AbortSignal | undefined): Promise<void>;
|
|
190
|
+
abort(reason: unknown): Promise<void>;
|
|
191
|
+
}
|
|
192
|
+
export interface ConversionContext {
|
|
193
|
+
/** Only this configured filesystem may supply/extract local image resources. */
|
|
194
|
+
readonly resourceFiles?: ResourceFileSystem;
|
|
195
|
+
readonly resourceCwd?: string;
|
|
196
|
+
readonly reader?: ReaderCapability;
|
|
197
|
+
readonly writer?: WriterCapability;
|
|
198
|
+
readonly resources?: ResourceCapability;
|
|
199
|
+
readonly output?: OutputCapability | StreamingOutputCapability;
|
|
200
|
+
readonly limits?: Partial<Limits>;
|
|
201
|
+
readonly signal?: AbortSignal;
|
|
202
|
+
/** Trusted event-loop scheduler, chiefly for deterministic host/test integration. */
|
|
203
|
+
readonly yield?: () => Promise<void>;
|
|
204
|
+
}
|
|
205
|
+
/** Structural VFS subset. ENOENT alone permits search continuation. Providers
|
|
206
|
+
* retain authority over their namespace; lexical checks are not a sandbox.
|
|
207
|
+
* Without provider transactions, completed writes survive later failures. */
|
|
208
|
+
export interface ResourceFileSystem {
|
|
209
|
+
lstat(path: string, options?: {
|
|
210
|
+
signal?: AbortSignal;
|
|
211
|
+
}): Promise<{
|
|
212
|
+
readonly type: string;
|
|
213
|
+
}>;
|
|
214
|
+
readStream?(path: string, options?: {
|
|
215
|
+
signal?: AbortSignal;
|
|
216
|
+
}): AsyncIterable<Uint8Array> | Iterable<Uint8Array>;
|
|
217
|
+
readFile?(path: string, options?: {
|
|
218
|
+
signal?: AbortSignal;
|
|
219
|
+
maxBytes?: number;
|
|
220
|
+
}): Promise<Uint8Array>;
|
|
221
|
+
mkdir(path: string, options?: {
|
|
222
|
+
recursive?: boolean;
|
|
223
|
+
signal?: AbortSignal;
|
|
224
|
+
}): Promise<void>;
|
|
225
|
+
writeFile(path: string, bytes: Uint8Array, options?: {
|
|
226
|
+
signal?: AbortSignal;
|
|
227
|
+
flag?: "wx";
|
|
228
|
+
}): Promise<void>;
|
|
229
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { LayoutDocument, PdfContext, PdfLimits } from "./model.js";
|
|
2
|
+
export type * from "./model.js";
|
|
3
|
+
export { PdfError } from "./errors.js";
|
|
4
|
+
export declare function pdfCapabilities(): {
|
|
5
|
+
readonly profile: "PDF-1.7-supplied-fonts-ltr";
|
|
6
|
+
readonly reference: "Adobe PDF Reference sixth edition, November 2006";
|
|
7
|
+
readonly scripts: readonly ["Latin", "Greek", "Cyrillic"];
|
|
8
|
+
readonly fonts: readonly ["sfnt-TrueType-glyf"];
|
|
9
|
+
readonly png: "static-noninterlaced-8bit";
|
|
10
|
+
readonly jpeg: "8bit-gray-rgb-adobe-cmyk";
|
|
11
|
+
readonly images: readonly ["png", "jpeg"];
|
|
12
|
+
readonly tables: "rectangular-unspanned";
|
|
13
|
+
readonly encryption: false;
|
|
14
|
+
readonly javascript: false;
|
|
15
|
+
readonly attachments: false;
|
|
16
|
+
readonly accessibility: {
|
|
17
|
+
readonly tagged: false;
|
|
18
|
+
readonly readingOrder: "not-guaranteed";
|
|
19
|
+
readonly pdfUA: false;
|
|
20
|
+
};
|
|
21
|
+
readonly conformance: {
|
|
22
|
+
readonly pdfA: false;
|
|
23
|
+
};
|
|
24
|
+
readonly text: {
|
|
25
|
+
readonly unicodeMapping: "supported-scalars";
|
|
26
|
+
readonly extraction: "not-guaranteed";
|
|
27
|
+
readonly searchable: "not-guaranteed";
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare const defaultPdfLimits: Readonly<PdfLimits>;
|
|
31
|
+
export declare function renderPdf(document: LayoutDocument, context?: PdfContext): Promise<Uint8Array>;
|
|
32
|
+
export { suppliedDefaultFont } from "./default-font.js";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/** Coordinates and dimensions are PDF points; flow uses top-down placement. */
|
|
2
|
+
export interface PageBox {
|
|
3
|
+
readonly width: number;
|
|
4
|
+
readonly height: number;
|
|
5
|
+
readonly margin: number;
|
|
6
|
+
}
|
|
7
|
+
export interface SuppliedFont {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly bytes: Uint8Array;
|
|
10
|
+
}
|
|
11
|
+
export interface TextRun {
|
|
12
|
+
readonly text: string;
|
|
13
|
+
readonly font?: string;
|
|
14
|
+
readonly size?: number;
|
|
15
|
+
readonly link?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface PaginationConstraints {
|
|
18
|
+
readonly breakBefore?: boolean;
|
|
19
|
+
readonly keepTogether?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface Paragraph extends PaginationConstraints {
|
|
22
|
+
/** Optional flat outline entry targeting the first placed line. */
|
|
23
|
+
readonly outline?: string;
|
|
24
|
+
readonly kind: "paragraph";
|
|
25
|
+
readonly runs: readonly TextRun[];
|
|
26
|
+
readonly spaceAfter?: number;
|
|
27
|
+
readonly keepWithNext?: boolean;
|
|
28
|
+
readonly indent?: number;
|
|
29
|
+
readonly widows?: number;
|
|
30
|
+
readonly orphans?: number;
|
|
31
|
+
readonly longWord?: "wrap" | "error";
|
|
32
|
+
}
|
|
33
|
+
export interface ImageBlock extends PaginationConstraints {
|
|
34
|
+
readonly kind: "image";
|
|
35
|
+
readonly bytes: Uint8Array;
|
|
36
|
+
readonly media: "png" | "jpeg";
|
|
37
|
+
readonly width: number;
|
|
38
|
+
readonly height: number;
|
|
39
|
+
readonly fit?: "contain" | "natural";
|
|
40
|
+
}
|
|
41
|
+
/** Rectangular unspanned tables; leading header rows repeat on continuation pages. */
|
|
42
|
+
export interface TableBlock extends PaginationConstraints {
|
|
43
|
+
readonly kind: "table";
|
|
44
|
+
readonly rows: readonly (readonly Paragraph[])[];
|
|
45
|
+
readonly widths: readonly number[];
|
|
46
|
+
readonly headerRows?: number;
|
|
47
|
+
readonly rowSplit?: "error" | "lines";
|
|
48
|
+
}
|
|
49
|
+
export type LayoutBlock = Paragraph | ImageBlock | TableBlock;
|
|
50
|
+
export interface PdfMetadata {
|
|
51
|
+
readonly title?: string;
|
|
52
|
+
readonly author?: string;
|
|
53
|
+
readonly subject?: string;
|
|
54
|
+
readonly keywords?: readonly string[];
|
|
55
|
+
}
|
|
56
|
+
export interface LayoutDocument {
|
|
57
|
+
readonly metadata?: PdfMetadata;
|
|
58
|
+
readonly page?: PageBox;
|
|
59
|
+
readonly lineHeight?: number;
|
|
60
|
+
readonly fonts: readonly SuppliedFont[];
|
|
61
|
+
readonly blocks: readonly LayoutBlock[];
|
|
62
|
+
}
|
|
63
|
+
export interface PdfLimits {
|
|
64
|
+
readonly fontBytes: number;
|
|
65
|
+
readonly fonts: number;
|
|
66
|
+
readonly glyphs: number;
|
|
67
|
+
readonly pages: number;
|
|
68
|
+
readonly objects: number;
|
|
69
|
+
readonly images: number;
|
|
70
|
+
readonly imageBytes: number;
|
|
71
|
+
readonly decodedImageBytes: number;
|
|
72
|
+
readonly layoutWork: number;
|
|
73
|
+
readonly outputBytes: number;
|
|
74
|
+
}
|
|
75
|
+
export interface PdfContext {
|
|
76
|
+
/** Top-down boxes of emitted content, for consumers inspecting layout. Page is one-based. */
|
|
77
|
+
readonly onPlacement?: (box: Placement) => void;
|
|
78
|
+
readonly signal?: AbortSignal | undefined;
|
|
79
|
+
readonly limits?: Partial<PdfLimits>;
|
|
80
|
+
/** Called before each admitted allocation/work unit, permitting shared host budgets. */
|
|
81
|
+
readonly charge?: (key: keyof PdfLimits, amount: number) => void;
|
|
82
|
+
readonly yield?: () => Promise<void>;
|
|
83
|
+
}
|
|
84
|
+
export interface Placement {
|
|
85
|
+
readonly kind: "text" | "image" | "cell";
|
|
86
|
+
readonly page: number;
|
|
87
|
+
readonly x: number;
|
|
88
|
+
readonly y: number;
|
|
89
|
+
readonly width: number;
|
|
90
|
+
readonly height: number;
|
|
91
|
+
readonly text?: string;
|
|
92
|
+
}
|