@dajiaoai/algeo-sdk 1.2.0 → 2.4.2

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.
@@ -0,0 +1,33 @@
1
+ import { AlgeoError, type AlgeoEmbedMode, type EmbedInitOptions, type EmbedEventMessage, type SaveRequestMessage, type ReadyEvent } from './shared';
2
+ export declare abstract class EmbeddedTarget<EventMap extends {
3
+ ready: ReadyEvent;
4
+ }, EventName extends keyof EventMap & string, ListenerMap extends Record<EventName, (event: any) => void>> {
5
+ protected readonly container: HTMLElement;
6
+ protected readonly embedMode: AlgeoEmbedMode;
7
+ protected iframe?: HTMLIFrameElement;
8
+ protected pending: Map<string, {
9
+ resolve: (value: unknown) => void;
10
+ reject: (err: AlgeoError) => void;
11
+ }>;
12
+ private listenerBuckets;
13
+ private messageHandler?;
14
+ private destroyed;
15
+ protected _ready: boolean;
16
+ protected _version: string | null;
17
+ protected constructor(container: HTMLElement, embedMode: AlgeoEmbedMode);
18
+ get ready(): boolean;
19
+ get version(): string | null;
20
+ on<T extends EventName>(event: T, listener: ListenerMap[T]): () => void;
21
+ protected getListeners<T extends EventName>(event: T): ListenerMap[T][];
22
+ off<T extends EventName>(event: T, listener: ListenerMap[T]): void;
23
+ protected emit<T extends EventName>(event: T, payload: EventMap[T]): void;
24
+ protected handleEventMessage(_event: Extract<EventMap[EventName], EmbedEventMessage>): void;
25
+ protected acceptsEventMessage(): boolean;
26
+ protected handleRequestMessage(_message: SaveRequestMessage, _sourceWindow: Window): boolean;
27
+ private cleanupMessageHandler;
28
+ private cleanupIframe;
29
+ private resetRuntimeState;
30
+ protected init(options: EmbedInitOptions): Promise<void>;
31
+ protected post<T>(type: string, payload: Record<string, unknown>): Promise<T>;
32
+ destroy(): Promise<void>;
33
+ }
package/dist/index.d.ts CHANGED
@@ -1,75 +1,6 @@
1
- /**
2
- * 大角几何内嵌画板 SDK
3
- * 绑定 DOM 容器,自动创建 iframe 并封装 postMessage 通信
4
- */
5
- import { AlgeoError, type AlgeoErrorPayload, type FileContentV10, EMBED_ERROR_CODES } from '@dajiaoai/algeo-protocol';
6
- /** SDK 版本号,构建时由 rollup 注入 */
7
- export declare const VERSION = "__ALGEO_SDK_VERSION__";
8
- /** 从协议层 re-export,供外部使用 */
9
- export type { FileContentV10, AlgeoErrorPayload };
10
- export { AlgeoError, EMBED_ERROR_CODES };
11
- export interface AlgeoSdkOptions {
12
- /** 内嵌页基础 URL,默认 https://dajiaoai.com */
13
- baseUrl?: string;
14
- /** 初始加载的内容 ID,可选 */
15
- initialId?: string;
16
- }
17
- export interface LoadShareByIdResult {
18
- success: true;
19
- }
20
- export interface LoadFileResult {
21
- success: true;
22
- }
23
- export interface SwitchSlideResult {
24
- success: true;
25
- }
26
- export interface GetSlideCountResult {
27
- count: number;
28
- }
29
- export interface ReplResult {
30
- output: string;
31
- }
32
- /**
33
- * 大角几何内嵌画板 SDK
34
- */
35
- export declare class AlgeoSdk {
36
- private container;
37
- private iframe?;
38
- private pending;
39
- private messageHandler?;
40
- private _ready;
41
- private _version;
42
- /** 是否已就绪(收到 iframe ready 通知) */
43
- get ready(): boolean;
44
- /** 内嵌页协议版本 */
45
- get version(): string | null;
46
- constructor(container: HTMLElement);
47
- static create(container: HTMLElement, options?: AlgeoSdkOptions): Promise<AlgeoSdk>;
48
- init(options?: AlgeoSdkOptions): Promise<void>;
49
- private post;
50
- /**
51
- * 按分享 ID 加载内容
52
- */
53
- loadShareById(id: string): Promise<LoadShareByIdResult>;
54
- /**
55
- * 加载完整文件内容(覆盖式)
56
- */
57
- loadFile(content: FileContentV10): Promise<LoadFileResult>;
58
- /**
59
- * 切换到指定索引的画板
60
- */
61
- switchSlide(index: number): Promise<SwitchSlideResult>;
62
- /**
63
- * 查询画板数量
64
- */
65
- getSlideCount(): Promise<GetSlideCountResult>;
66
- /**
67
- * 执行 REPL 指令,返回面向 AI 的文档/文本内容
68
- * @param command REPL 可用的单个 command 指令,如 help、list、list_slides、eval 等
69
- */
70
- repl(command: string): Promise<ReplResult>;
71
- /**
72
- * 销毁实例,移除 iframe 与事件监听
73
- */
74
- destroy(): void;
75
- }
1
+ export { AlgeoError, EMBED_ERROR_CODES, VERSION } from './shared';
2
+ export type { FileContentV10 } from '@dajiaoai/algeo-protocol';
3
+ export type { AlgeoCreateOptions, AlgeoEditorAuthOptions, AlgeoEditorCreateOptions, AlgeoEditorSaveResult, AlgeoEditorUiConfig, AlgeoEmbedMode, AlgeoErrorPayload, AlgeoPresentationCreateOptions, ContentChangeEvent, DocumentApi, EmbeddedEditorEventListenerMap, EmbeddedEditorEventMap, EmbeddedEditorEventName, EmbeddedPresentationEventListenerMap, EmbeddedPresentationEventMap, EmbeddedPresentationEventName, GetContentResult, GetSlideCountResult, HistoryApi, LoadFileResult, LoadShareByIdResult, ModeApi, ReadyEvent, ReplResult, SlideChangeEvent, SlideIndexResult, SlidesApi, SwitchSlideResult, SaveEvent, } from './shared';
4
+ export { EmbeddedPresentation } from './embedded-presentation';
5
+ export { EmbeddedEditor } from './embedded-editor';
6
+ export { AlgeoSdk, create, createEditor, createPresentation, type EmbeddedInstance, } from './sdk';
package/dist/sdk.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { EmbeddedEditor } from './embedded-editor';
2
+ import { EmbeddedPresentation } from './embedded-presentation';
3
+ import { type AlgeoCreateOptions, type AlgeoEditorCreateOptions, type AlgeoPresentationCreateOptions } from './shared';
4
+ export type EmbeddedInstance = EmbeddedEditor | EmbeddedPresentation;
5
+ export declare class AlgeoSdk {
6
+ private constructor();
7
+ static create(container: HTMLElement, options: AlgeoCreateOptions): Promise<EmbeddedInstance>;
8
+ static createEditor(container: HTMLElement, options?: AlgeoEditorCreateOptions): Promise<EmbeddedEditor>;
9
+ static createPresentation(container: HTMLElement, options?: AlgeoPresentationCreateOptions): Promise<EmbeddedPresentation>;
10
+ }
11
+ export declare function create(container: HTMLElement, options: {
12
+ baseUrl?: string;
13
+ mode: 'editor';
14
+ editor: AlgeoEditorCreateOptions;
15
+ }): Promise<EmbeddedEditor>;
16
+ export declare function create(container: HTMLElement, options: {
17
+ baseUrl?: string;
18
+ mode: 'presentation';
19
+ presentation: AlgeoPresentationCreateOptions;
20
+ }): Promise<EmbeddedPresentation>;
21
+ export declare function createEditor(container: HTMLElement, options?: AlgeoEditorCreateOptions): Promise<EmbeddedEditor>;
22
+ export declare function createPresentation(container: HTMLElement, options?: AlgeoPresentationCreateOptions): Promise<EmbeddedPresentation>;
@@ -0,0 +1,171 @@
1
+ import { AlgeoError, type AlgeoErrorPayload, type EmbedReadyMessage, type EmbedResponseMessage, type FileContentV10, EMBED_ERROR_CODES } from '@dajiaoai/algeo-protocol';
2
+ /** SDK 版本号,构建时由 rollup 注入 */
3
+ export declare const VERSION = "__ALGEO_SDK_VERSION__";
4
+ /** 从协议层 re-export,供外部使用 */
5
+ export type { FileContentV10, AlgeoErrorPayload };
6
+ export { AlgeoError, EMBED_ERROR_CODES };
7
+ export declare const EMBED_TIMEOUT_MS = 30000;
8
+ export interface AlgeoSdkOptions {
9
+ /** 内嵌页基础 URL,默认 https://dajiaoai.com */
10
+ baseUrl?: string;
11
+ /** 内嵌模式,默认 presentation */
12
+ mode?: AlgeoEmbedMode;
13
+ /** 初始加载的内容 ID,可选 */
14
+ initialId?: string;
15
+ }
16
+ export type AlgeoEmbedMode = 'presentation' | 'editor';
17
+ export interface AlgeoEditorAuthOptions {
18
+ appId: string;
19
+ }
20
+ export interface AlgeoEditorUiConfig {
21
+ navbar?: boolean;
22
+ slidePanel?: boolean;
23
+ toolboxPanel?: boolean;
24
+ algebraPanel?: boolean;
25
+ docPanel?: boolean;
26
+ }
27
+ export type AlgeoEditorSaveResult = {
28
+ status: 'success';
29
+ } | {
30
+ status: 'error';
31
+ message: string;
32
+ };
33
+ export interface AlgeoEditorCreateOptions {
34
+ auth?: AlgeoEditorAuthOptions;
35
+ shareId?: string;
36
+ initialContent?: FileContentV10;
37
+ ui?: AlgeoEditorUiConfig;
38
+ }
39
+ export interface AlgeoPresentationCreateOptions {
40
+ shareId?: string;
41
+ }
42
+ export type AlgeoCreateOptions = {
43
+ baseUrl?: string;
44
+ mode: 'editor';
45
+ editor: AlgeoEditorCreateOptions;
46
+ } | {
47
+ baseUrl?: string;
48
+ mode: 'presentation';
49
+ presentation: AlgeoPresentationCreateOptions;
50
+ };
51
+ export interface ReadyEvent {
52
+ type: 'ready';
53
+ mode: AlgeoEmbedMode;
54
+ version: string | null;
55
+ }
56
+ export interface ContentChangeEvent {
57
+ type: 'contentChange';
58
+ source: 'loadContent' | 'loadFile' | 'loadShareById' | 'initialContent' | 'user';
59
+ content?: FileContentV10;
60
+ shareId?: string;
61
+ }
62
+ export interface SlideChangeEvent {
63
+ type: 'slideChange';
64
+ index: number;
65
+ }
66
+ export interface SaveRequestEvent {
67
+ type: 'save';
68
+ content: FileContentV10;
69
+ stage: 'request';
70
+ }
71
+ export interface SaveSuccessEvent {
72
+ type: 'save';
73
+ content: FileContentV10;
74
+ stage: 'success';
75
+ }
76
+ export type SaveEvent = SaveRequestEvent | SaveSuccessEvent;
77
+ export interface SaveRequestMessage {
78
+ type: 'save';
79
+ requestId: string;
80
+ content: FileContentV10;
81
+ }
82
+ export interface EmbeddedEditorEventMap {
83
+ ready: ReadyEvent;
84
+ contentChange: ContentChangeEvent;
85
+ slideChange: SlideChangeEvent;
86
+ save: SaveEvent;
87
+ }
88
+ export interface EmbeddedPresentationEventMap {
89
+ ready: ReadyEvent;
90
+ }
91
+ export type EmbeddedEditorEventName = keyof EmbeddedEditorEventMap;
92
+ export type EmbeddedPresentationEventName = keyof EmbeddedPresentationEventMap;
93
+ export type EmbeddedEditorEventListenerMap = {
94
+ ready: (event: ReadyEvent) => void;
95
+ contentChange: (event: ContentChangeEvent) => void;
96
+ slideChange: (event: SlideChangeEvent) => void;
97
+ save: (event: SaveEvent) => void | AlgeoEditorSaveResult | Promise<void | AlgeoEditorSaveResult>;
98
+ };
99
+ export type EmbeddedPresentationEventListenerMap = {
100
+ [K in EmbeddedPresentationEventName]: (event: EmbeddedPresentationEventMap[K]) => void;
101
+ };
102
+ export interface LoadShareByIdResult {
103
+ success: true;
104
+ }
105
+ export interface LoadFileResult {
106
+ success: true;
107
+ }
108
+ export interface SwitchSlideResult {
109
+ success: true;
110
+ }
111
+ export interface GetSlideCountResult {
112
+ count: number;
113
+ }
114
+ export interface ReplResult {
115
+ output: string;
116
+ }
117
+ export interface SlideIndexResult {
118
+ index: number;
119
+ }
120
+ export interface GetContentResult {
121
+ content: FileContentV10;
122
+ }
123
+ export interface GetHistoryStateResult {
124
+ count: number;
125
+ currentIndex: number;
126
+ canUndo: boolean;
127
+ canRedo: boolean;
128
+ }
129
+ export interface DocumentApi {
130
+ loadContent(content: FileContentV10): Promise<void>;
131
+ getContent(): Promise<FileContentV10>;
132
+ }
133
+ export interface SlidesApi {
134
+ getCount(): number;
135
+ getCurrentIndex(): number;
136
+ switchTo(index: number): Promise<void>;
137
+ add(): Promise<SlideIndexResult>;
138
+ addAt(index: number): Promise<SlideIndexResult>;
139
+ remove(index: number): Promise<void>;
140
+ duplicate(index: number, targetIndex?: number): Promise<SlideIndexResult>;
141
+ reorder(fromIndex: number, toIndex: number): Promise<void>;
142
+ }
143
+ export interface HistoryApi {
144
+ getCount(): number;
145
+ getCurrentIndex(): number;
146
+ undo(): Promise<void>;
147
+ redo(): Promise<void>;
148
+ jumpTo(index: number): Promise<void>;
149
+ canUndo(): boolean;
150
+ canRedo(): boolean;
151
+ clear(): Promise<void>;
152
+ }
153
+ export interface ModeApi {
154
+ getUiConfig(): AlgeoEditorUiConfig;
155
+ setUiConfig(config: Partial<AlgeoEditorUiConfig>): Promise<void>;
156
+ }
157
+ export declare function generateRequestId(): string;
158
+ export declare function isResponseMessage(msg: unknown): msg is EmbedResponseMessage;
159
+ export declare function isReadyMessage(msg: unknown): msg is EmbedReadyMessage;
160
+ export type EmbedEventMessage = ContentChangeEvent | SlideChangeEvent | SaveSuccessEvent;
161
+ export declare function isSaveRequestMessage(msg: unknown): msg is SaveRequestMessage;
162
+ export declare function isEmbedEventMessage(msg: unknown): msg is EmbedEventMessage;
163
+ export declare function normalizeBaseUrl(baseUrl: string): string;
164
+ export declare function normalizeMode(mode?: AlgeoEmbedMode): AlgeoEmbedMode;
165
+ export declare function getEmbedPath(mode: AlgeoEmbedMode): string;
166
+ export interface EmbedInitOptions extends AlgeoSdkOptions {
167
+ auth?: AlgeoEditorAuthOptions;
168
+ }
169
+ export declare function buildEmbedSrc(options: EmbedInitOptions): string;
170
+ export type KnownEventName = 'ready' | 'contentChange' | 'slideChange' | 'save';
171
+ export type TEventName<T extends string> = Extract<T, KnownEventName>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dajiaoai/algeo-sdk",
3
- "version": "1.2.0",
3
+ "version": "2.4.2",
4
4
  "description": "大角几何内嵌画板 SDK,支持 iframe 挂载与 postMessage 通信",
5
5
  "main": "dist/algeo-sdk.cjs.js",
6
6
  "module": "dist/algeo-sdk.esm.js",
@@ -13,7 +13,8 @@
13
13
  "scripts": {
14
14
  "build": "rollup -c",
15
15
  "typecheck": "tsc --noEmit",
16
- "examples": "npx serve ."
16
+ "examples": "npx serve .",
17
+ "release": "npm run build && npm publish --access public"
17
18
  },
18
19
  "keywords": [
19
20
  "algeo",
@@ -41,6 +42,6 @@
41
42
  "typescript": "^5.9.3"
42
43
  },
43
44
  "dependencies": {
44
- "@dajiaoai/algeo-protocol": "^1.0.0"
45
+ "@dajiaoai/algeo-protocol": "^1.3.0"
45
46
  }
46
- }
47
+ }