@web-ppt/edit-core 0.6.0-beta.1 → 0.8.0-beta.1
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/CHANGELOG.md +26 -0
- package/README.md +8 -0
- package/dist/agent/base64.d.ts +2 -0
- package/dist/agent/errors.d.ts +9 -0
- package/dist/agent/generated-schema.d.ts +6038 -0
- package/dist/agent/generated-validator.d.ts +6 -0
- package/dist/agent/index.d.ts +6 -0
- package/dist/agent/query.d.ts +3 -0
- package/dist/agent/session.d.ts +33 -0
- package/dist/agent/targets.d.ts +5 -0
- package/dist/agent/tools.d.ts +2 -0
- package/dist/agent/types.d.ts +126 -0
- package/dist/agent/validation.d.ts +2 -0
- package/dist/agent.js +46364 -0
- package/dist/commands/types.d.ts +23 -23
- package/dist/fill/api.d.ts +29 -0
- package/dist/fill/chart-seed-chart.d.ts +7 -0
- package/dist/fill/chart-seed-workbook.d.ts +12 -0
- package/dist/fill/chart-seed-xml.d.ts +12 -0
- package/dist/fill/chart-seed.d.ts +17 -0
- package/dist/fill/content.d.ts +16 -0
- package/dist/fill/errors.d.ts +10 -0
- package/dist/fill/generated-schema.d.ts +291 -0
- package/dist/fill/generated-validator.d.ts +6 -0
- package/dist/fill/index.d.ts +10 -0
- package/dist/fill/layouts.d.ts +24 -0
- package/dist/fill/package.d.ts +2 -0
- package/dist/fill/repair.d.ts +32 -0
- package/dist/fill/text-validation.d.ts +3 -0
- package/dist/fill/types.d.ts +60 -0
- package/dist/fill/validation.d.ts +10 -0
- package/dist/fill.js +12 -0
- package/dist/generate.js +53 -53
- package/dist/index-2ti1e4_F.js +411 -0
- package/dist/index-BbsPmmoy.js +4046 -0
- package/dist/save/notes-master.d.ts +12 -0
- package/dist/save.js +650 -484
- package/dist/{slide-parts-D0o_DDhi.js → slide-parts-zyOP9lia.js} +5 -5
- package/dist/types.d.ts +4 -4
- package/package.json +13 -3
- package/schemas/agent-tools.schema.json +7999 -0
- package/schemas/template-fill.schema.json +371 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { agentToolSchema } from './generated-schema';
|
|
2
|
+
export { listAgentTools } from './tools';
|
|
3
|
+
export { AgentSession, createAgentSession, openAgentSession } from './session';
|
|
4
|
+
export type { AgentSessionOptions } from './session';
|
|
5
|
+
export { AgentToolError } from './errors';
|
|
6
|
+
export type { AgentCommand, AgentDescribeInput, AgentEditInput, AgentElementInput, AgentElementQuery, AgentElementResult, AgentEmptyInput, AgentHistoryState, AgentLintInput, AgentMutationResult, AgentRenderInput, AgentRenderResult, AgentSaveResult, AgentToolDescriptor, AgentToolFailure, AgentToolInput, AgentToolInputMap, AgentToolName, AgentToolOutputMap, AgentToolResult, } from './types';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Presentation, TextMeasure } from '@web-ppt/core';
|
|
2
|
+
import type { NodeRasterizer } from '@web-ppt/core/node';
|
|
3
|
+
import { Editor } from '@web-ppt/edit-core';
|
|
4
|
+
import type { EditDoc } from '@web-ppt/edit-core';
|
|
5
|
+
import type { LayoutLintOptions } from '../lint/types';
|
|
6
|
+
import type { AgentToolInput, AgentToolName, AgentToolResult } from './types';
|
|
7
|
+
export interface AgentSessionOptions {
|
|
8
|
+
readonly idPrefix?: string;
|
|
9
|
+
readonly lint?: LayoutLintOptions;
|
|
10
|
+
readonly measureText?: TextMeasure;
|
|
11
|
+
readonly rasterize?: NodeRasterizer;
|
|
12
|
+
readonly presentation?: Presentation;
|
|
13
|
+
}
|
|
14
|
+
export declare class AgentSession {
|
|
15
|
+
readonly editor: Editor;
|
|
16
|
+
private readonly options;
|
|
17
|
+
private readonly ownsDoc;
|
|
18
|
+
private active;
|
|
19
|
+
constructor(editor: Editor, options?: AgentSessionOptions, ownsDoc?: boolean);
|
|
20
|
+
get doc(): EditDoc;
|
|
21
|
+
call<T extends AgentToolName>(name: T, input: AgentToolInput<T>): Promise<AgentToolResult<T>>;
|
|
22
|
+
dispose(): void;
|
|
23
|
+
private dispatch;
|
|
24
|
+
private edit;
|
|
25
|
+
private replay;
|
|
26
|
+
private mutation;
|
|
27
|
+
private observe;
|
|
28
|
+
private lintOptions;
|
|
29
|
+
private render;
|
|
30
|
+
private save;
|
|
31
|
+
}
|
|
32
|
+
export declare function createAgentSession(doc: EditDoc, options?: AgentSessionOptions): AgentSession;
|
|
33
|
+
export declare function openAgentSession(bytes: Uint8Array, options?: AgentSessionOptions): Promise<AgentSession>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Command } from '../commands/types';
|
|
2
|
+
import type { DesignTarget, EditDoc } from '../types';
|
|
3
|
+
export declare function assertCommandTargets(doc: EditDoc, command: Command, index: number): void;
|
|
4
|
+
export declare function assertBatchTargets(doc: EditDoc, commands: readonly Command[]): void;
|
|
5
|
+
export declare function commonDesignTarget(doc: EditDoc, commands: readonly Command[]): DesignTarget | null;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { LayoutCheck, LayoutLintReport } from '../lint/types';
|
|
2
|
+
import type { PresentationDescription } from '../describe/types';
|
|
3
|
+
import type { AddImageCommand as EditAddImageCommand, Command, ReplaceImageCommand as EditReplaceImageCommand, SetBackgroundImageCommand as EditSetBackgroundImageCommand, TextRange } from '../commands/types';
|
|
4
|
+
import type { TableCellAddress } from '../types';
|
|
5
|
+
type JsonBytes<T> = T extends {
|
|
6
|
+
readonly bytes: Uint8Array;
|
|
7
|
+
} ? {
|
|
8
|
+
readonly [K in keyof T]: K extends 'bytes' ? string : T[K];
|
|
9
|
+
} : T;
|
|
10
|
+
type BinaryCommand = EditAddImageCommand | EditReplaceImageCommand | EditSetBackgroundImageCommand;
|
|
11
|
+
export type AddImageCommand = JsonBytes<EditAddImageCommand>;
|
|
12
|
+
export type ReplaceImageCommand = JsonBytes<EditReplaceImageCommand>;
|
|
13
|
+
export type SetBackgroundImageCommand = JsonBytes<EditSetBackgroundImageCommand>;
|
|
14
|
+
/** 与 Editor 命令一一对应;图片字节在 JSON 传输中使用 Base64。 */
|
|
15
|
+
export type AgentCommand = Exclude<Command, BinaryCommand> | AddImageCommand | ReplaceImageCommand | SetBackgroundImageCommand;
|
|
16
|
+
export interface AgentDescribeInput {
|
|
17
|
+
readonly maxChars?: number;
|
|
18
|
+
}
|
|
19
|
+
export type AgentElementQuery = 'describe' | 'fill' | 'stroke' | 'effects' | 'crop' | 'link' | 'run' | 'paragraph' | 'body';
|
|
20
|
+
export interface AgentElementInput {
|
|
21
|
+
readonly id: string;
|
|
22
|
+
readonly query: AgentElementQuery;
|
|
23
|
+
readonly range?: TextRange;
|
|
24
|
+
readonly cell?: TableCellAddress;
|
|
25
|
+
}
|
|
26
|
+
export interface AgentLintInput {
|
|
27
|
+
readonly checks?: readonly LayoutCheck[];
|
|
28
|
+
readonly canvasColor?: string;
|
|
29
|
+
readonly overlapRatio?: number;
|
|
30
|
+
readonly imageDeviation?: number;
|
|
31
|
+
readonly tolerancePx?: number;
|
|
32
|
+
readonly maxIssues?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface AgentRenderInput {
|
|
35
|
+
readonly slideNumber: number;
|
|
36
|
+
readonly format: 'svg' | 'png';
|
|
37
|
+
readonly scale?: number;
|
|
38
|
+
}
|
|
39
|
+
export interface AgentEditInput {
|
|
40
|
+
/** @minItems 1 */
|
|
41
|
+
readonly commands: readonly AgentCommand[];
|
|
42
|
+
readonly lint?: AgentLintInput;
|
|
43
|
+
}
|
|
44
|
+
export interface AgentEmptyInput {
|
|
45
|
+
readonly [key: string]: never;
|
|
46
|
+
}
|
|
47
|
+
/** 每个属性是一种工具;校验时只提交当前工具对应的单属性对象。 */
|
|
48
|
+
export interface AgentToolInputMap {
|
|
49
|
+
readonly describe?: AgentDescribeInput;
|
|
50
|
+
readonly element?: AgentElementInput;
|
|
51
|
+
readonly lint?: AgentLintInput;
|
|
52
|
+
readonly render?: AgentRenderInput;
|
|
53
|
+
readonly edit?: AgentEditInput;
|
|
54
|
+
readonly undo?: AgentEmptyInput;
|
|
55
|
+
readonly redo?: AgentEmptyInput;
|
|
56
|
+
readonly save?: AgentEmptyInput;
|
|
57
|
+
}
|
|
58
|
+
export type AgentToolName = keyof AgentToolInputMap;
|
|
59
|
+
export type AgentToolInput<T extends AgentToolName> = NonNullable<AgentToolInputMap[T]>;
|
|
60
|
+
export interface AgentToolDescriptor {
|
|
61
|
+
readonly name: AgentToolName;
|
|
62
|
+
readonly description: string;
|
|
63
|
+
readonly inputSchema: Readonly<Record<string, unknown>>;
|
|
64
|
+
}
|
|
65
|
+
export interface AgentElementResult {
|
|
66
|
+
readonly id: string;
|
|
67
|
+
readonly query: AgentElementQuery;
|
|
68
|
+
readonly value: unknown;
|
|
69
|
+
}
|
|
70
|
+
export interface AgentRenderResult {
|
|
71
|
+
readonly slideNumber: number;
|
|
72
|
+
readonly format: 'svg' | 'png';
|
|
73
|
+
readonly data: string;
|
|
74
|
+
}
|
|
75
|
+
export interface AgentHistoryState {
|
|
76
|
+
readonly undoCount: number;
|
|
77
|
+
readonly redoCount: number;
|
|
78
|
+
}
|
|
79
|
+
export interface AgentMutationResult {
|
|
80
|
+
readonly affectedElements: readonly string[];
|
|
81
|
+
readonly affectedSlides: readonly string[];
|
|
82
|
+
readonly lint: {
|
|
83
|
+
readonly status: 'ok';
|
|
84
|
+
readonly slideNumbers: readonly number[];
|
|
85
|
+
readonly report: LayoutLintReport | null;
|
|
86
|
+
} | {
|
|
87
|
+
readonly status: 'failed';
|
|
88
|
+
readonly slideNumbers: readonly number[];
|
|
89
|
+
readonly reason: string;
|
|
90
|
+
readonly message: string;
|
|
91
|
+
};
|
|
92
|
+
readonly history: AgentHistoryState;
|
|
93
|
+
}
|
|
94
|
+
export interface AgentSaveResult {
|
|
95
|
+
readonly bytes: string;
|
|
96
|
+
readonly saveMode: 'patch' | 'generated';
|
|
97
|
+
readonly packageMode: 'identity' | 'passthrough' | 'repacked';
|
|
98
|
+
readonly fallbackReason: string | null;
|
|
99
|
+
readonly preservedEntries: number;
|
|
100
|
+
readonly rewrittenEntries: number;
|
|
101
|
+
}
|
|
102
|
+
export interface AgentToolOutputMap {
|
|
103
|
+
readonly describe: PresentationDescription;
|
|
104
|
+
readonly element: AgentElementResult;
|
|
105
|
+
readonly lint: LayoutLintReport;
|
|
106
|
+
readonly render: AgentRenderResult;
|
|
107
|
+
readonly edit: AgentMutationResult;
|
|
108
|
+
readonly undo: AgentMutationResult;
|
|
109
|
+
readonly redo: AgentMutationResult;
|
|
110
|
+
readonly save: AgentSaveResult;
|
|
111
|
+
}
|
|
112
|
+
export interface AgentToolFailure {
|
|
113
|
+
readonly ok: false;
|
|
114
|
+
readonly error: {
|
|
115
|
+
readonly reason: string;
|
|
116
|
+
readonly message: string;
|
|
117
|
+
readonly commandIndex: number | null;
|
|
118
|
+
readonly elementId: string | null;
|
|
119
|
+
readonly slideNumber: number | null;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export type AgentToolResult<T extends AgentToolName> = {
|
|
123
|
+
readonly ok: true;
|
|
124
|
+
readonly value: AgentToolOutputMap[T];
|
|
125
|
+
} | AgentToolFailure;
|
|
126
|
+
export {};
|