@baron1996/klinecharts-runtime 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +1 -1
  2. package/dist/drawing/capabilities.d.ts +36 -0
  3. package/dist/drawing/capabilities.d.ts.map +1 -0
  4. package/dist/drawing/capabilities.js +1 -0
  5. package/dist/drawing/legacy-runtime-capability.d.ts +8 -0
  6. package/dist/drawing/legacy-runtime-capability.d.ts.map +1 -0
  7. package/dist/drawing/legacy-runtime-capability.js +92 -0
  8. package/dist/drawing/projection-service.d.ts +80 -0
  9. package/dist/drawing/projection-service.d.ts.map +1 -0
  10. package/dist/drawing/projection-service.js +523 -0
  11. package/dist/drawing/runtime-capability-descriptor.d.ts +28 -0
  12. package/dist/drawing/runtime-capability-descriptor.d.ts.map +1 -0
  13. package/dist/drawing/runtime-capability-descriptor.js +1 -0
  14. package/dist/drawing/scene-runtime-factory.d.ts +15 -0
  15. package/dist/drawing/scene-runtime-factory.d.ts.map +1 -0
  16. package/dist/drawing/scene-runtime-factory.js +27 -0
  17. package/dist/drawing/session-controller.d.ts +53 -0
  18. package/dist/drawing/session-controller.d.ts.map +1 -0
  19. package/dist/drawing/session-controller.js +339 -0
  20. package/dist/drawing/workspace-events.d.ts +66 -0
  21. package/dist/drawing/workspace-events.d.ts.map +1 -0
  22. package/dist/drawing/workspace-events.js +12 -0
  23. package/dist/drawing/workspace-runtime.d.ts +60 -0
  24. package/dist/drawing/workspace-runtime.d.ts.map +1 -0
  25. package/dist/drawing/workspace-runtime.js +328 -0
  26. package/dist/index.d.ts +8 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +8 -1
  29. package/dist/runtime.d.ts +29 -3
  30. package/dist/runtime.d.ts.map +1 -1
  31. package/dist/runtime.js +97 -1
  32. package/dist/toolbar/standard-toolbar-styles.d.ts.map +1 -1
  33. package/dist/toolbar/standard-toolbar-styles.js +18 -0
  34. package/dist/toolbar/standard-toolbar.d.ts +4 -2
  35. package/dist/toolbar/standard-toolbar.d.ts.map +1 -1
  36. package/dist/toolbar/standard-toolbar.js +187 -31
  37. package/dist/toolbar/toolbar-icons.d.ts +26 -0
  38. package/dist/toolbar/toolbar-icons.d.ts.map +1 -1
  39. package/dist/toolbar/toolbar-icons.js +13 -0
  40. package/dist/toolbar/toolbar-tools.d.ts +6 -1
  41. package/dist/toolbar/toolbar-tools.d.ts.map +1 -1
  42. package/dist/toolbar/toolbar-tools.js +6 -0
  43. package/dist/types.d.ts +7 -4
  44. package/dist/types.d.ts.map +1 -1
  45. package/package.json +4 -3
@@ -0,0 +1,328 @@
1
+ import { parseChartScene, parseDrawableWorkspaceDocument, parseDrawingDocument, serializeCanonicalDrawableWorkspace, } from '@baron1996/kline-scene-schema';
2
+ import { MainSeriesPresentationError, STANDARD_CLOSE_LINE_PRESENTATION, } from '@baron1996/klinecharts-adapter';
3
+ import { DrawingProjectionService, } from './projection-service.js';
4
+ import { getSceneRuntime } from './scene-runtime-factory.js';
5
+ import { DrawingSessionController, DrawingSessionError, } from './session-controller.js';
6
+ import { deepFreeze, WORKSPACE_EVENT_PROTOCOL, WORKSPACE_EVENT_PROTOCOL_VERSION, } from './workspace-events.js';
7
+ function drawingToSnapshot(drawing) {
8
+ return {
9
+ id: drawing.id,
10
+ type: drawing.type,
11
+ target: structuredClone(drawing.target),
12
+ geometry: structuredClone(drawing.geometry),
13
+ styles: structuredClone(drawing.styles),
14
+ locked: drawing.locked,
15
+ visible: drawing.visible,
16
+ zLevel: drawing.zLevel,
17
+ mode: drawing.mode,
18
+ };
19
+ }
20
+ function snapshotToDrawing(snapshot) {
21
+ return {
22
+ id: snapshot.id,
23
+ type: snapshot.type,
24
+ target: structuredClone(snapshot.target),
25
+ geometry: structuredClone(snapshot.geometry),
26
+ styles: structuredClone(snapshot.styles),
27
+ locked: snapshot.locked,
28
+ visible: snapshot.visible,
29
+ zLevel: snapshot.zLevel,
30
+ mode: snapshot.mode,
31
+ };
32
+ }
33
+ /**
34
+ * 组合 Scene Adapter、Drawing 会话与公共能力的工作区 Runtime。
35
+ * confirmed 文档唯一权威;宿主持久化只消费候选事件。
36
+ */
37
+ export class DrawableWorkspaceRuntime {
38
+ #container;
39
+ #workspace;
40
+ #engine;
41
+ #session;
42
+ #projectionService = new DrawingProjectionService();
43
+ #registration;
44
+ #runtimeId;
45
+ #listeners = new Set();
46
+ #sequence = 0;
47
+ #destroyed = false;
48
+ #scene;
49
+ constructor(container, workspace, engine, options) {
50
+ this.#container = container;
51
+ this.#workspace = workspace;
52
+ this.#engine = engine;
53
+ this.#runtimeId = `drawable-workspace-${Math.random().toString(36).slice(2)}`;
54
+ this.#scene = workspace.scene.document;
55
+ this.#registration = getSceneRuntime(workspace.scene.kind);
56
+ this.#session = new DrawingSessionController({
57
+ runtimeId: this.#runtimeId,
58
+ commitMode: options.commitMode,
59
+ engine,
60
+ projectionService: this.#projectionService,
61
+ scene: this.#projectionScene(),
62
+ valueAxes: workspace.drawings.coordinateSystem.valueAxes,
63
+ target: this.#registration.defaultTarget,
64
+ scopeKey: workspace.drawings.scopeKey,
65
+ timezone: workspace.drawings.coordinateSystem.timezone,
66
+ buildDocument: (drawings) => this.#buildDocument(drawings),
67
+ emit: (event) => this.#emit(event),
68
+ });
69
+ this.#session.restoreConfirmed(workspace.drawings.drawings.map((drawing) => drawingToSnapshot(drawing)));
70
+ if (options.onEvent !== undefined) {
71
+ this.#listeners.add(options.onEvent);
72
+ }
73
+ }
74
+ static async create(container, value, options) {
75
+ const workspace = parseDrawableWorkspaceDocument(value);
76
+ const registration = getSceneRuntime(workspace.scene.kind);
77
+ const engine = await registration.createAdapter(container, workspace);
78
+ return new DrawableWorkspaceRuntime(container, workspace, engine, options);
79
+ }
80
+ startDrawing(type, options) {
81
+ return this.#session.startCreate(type, options);
82
+ }
83
+ listDrawings() {
84
+ return this.#session.confirmedDrawings;
85
+ }
86
+ getDrawing(id) {
87
+ return this.#session.confirmedDrawings.find((drawing) => drawing.id === id);
88
+ }
89
+ updateDrawingStyles(id, styles) {
90
+ return this.#session.updateDrawingStyles(id, styles);
91
+ }
92
+ updateDrawingText(id, text) {
93
+ return this.#session.updateDrawingText(id, text);
94
+ }
95
+ removeDrawing(id) {
96
+ return this.#session.removeDrawing(id);
97
+ }
98
+ requestDrawingDelete(id) {
99
+ this.removeDrawing(id);
100
+ }
101
+ selectDrawing(id) {
102
+ this.#session.selectDrawing(id);
103
+ }
104
+ getSelectedDrawingId() {
105
+ return this.#session.selectedId ?? undefined;
106
+ }
107
+ hitTestDrawing(point) {
108
+ return this.#engine.hitTestDrawing(point);
109
+ }
110
+ subscribe(listener) {
111
+ this.#listeners.add(listener);
112
+ return () => {
113
+ this.#listeners.delete(listener);
114
+ };
115
+ }
116
+ getRuntimeCapabilityDescriptor(options = {}) {
117
+ this.#assertUsable();
118
+ const kind = this.#sceneKind();
119
+ const supportedScales = kind === 'chart'
120
+ ? ['linear', 'logarithmic']
121
+ : ['linear'];
122
+ const activeScale = kind === 'chart'
123
+ ? this.#activeScale()
124
+ : 'linear';
125
+ return {
126
+ drawingTypes: [
127
+ 'horizontalRayLine', 'horizontalSegment', 'horizontalStraightLine',
128
+ 'verticalRayLine', 'verticalSegment', 'verticalStraightLine',
129
+ 'rayLine', 'segment', 'straightLine', 'priceLine',
130
+ 'priceChannelLine', 'parallelStraightLine', 'fibonacciLine', 'brush',
131
+ 'simpleAnnotation', 'simpleTag',
132
+ 'priceMeasurement', 'rectangle', 'arrow', 'crossLine', 'callout', 'text',
133
+ ],
134
+ valueAxis: {
135
+ supportedScales,
136
+ activeScale,
137
+ mutable: kind === 'chart',
138
+ },
139
+ exportArtifact: {
140
+ kind: 'drawable-workspace',
141
+ mediaType: 'application/json',
142
+ defaultFileName: 'drawable-workspace.json',
143
+ },
144
+ mainSeriesPresentation: kind === 'chart'
145
+ ? {
146
+ presentations: [
147
+ { type: 'candle_solid' },
148
+ { type: 'candle_stroke' },
149
+ { type: 'candle_up_stroke' },
150
+ { type: 'candle_down_stroke' },
151
+ { type: 'ohlc' },
152
+ STANDARD_CLOSE_LINE_PRESENTATION,
153
+ ],
154
+ activeType: this.#scene.chart.candle.type,
155
+ mutable: true,
156
+ }
157
+ : null,
158
+ hostActions: options.hostActions ?? [],
159
+ };
160
+ }
161
+ exportDrawingDocument() {
162
+ this.#assertUsable();
163
+ return parseDrawingDocument(this.#buildDocument(this.#session.confirmedDrawings));
164
+ }
165
+ exportWorkspace() {
166
+ this.#assertUsable();
167
+ const drawings = this.exportDrawingDocument();
168
+ const workspace = {
169
+ ...structuredClone(this.#workspace),
170
+ scene: {
171
+ kind: this.#sceneKind(),
172
+ document: structuredClone(this.#scene),
173
+ },
174
+ drawings,
175
+ binding: {
176
+ scopeKey: drawings.scopeKey,
177
+ timezone: drawings.coordinateSystem.timezone,
178
+ valueAxes: drawings.coordinateSystem.valueAxes,
179
+ },
180
+ };
181
+ return parseDrawableWorkspaceDocument(workspace);
182
+ }
183
+ exportArtifact(fileName = 'drawable-workspace.json') {
184
+ this.#assertUsable();
185
+ return {
186
+ bytes: serializeCanonicalDrawableWorkspace(this.exportWorkspace()),
187
+ mediaType: 'application/json',
188
+ fileName,
189
+ };
190
+ }
191
+ async setValueAxisScale(scale) {
192
+ this.#assertUsable();
193
+ if (this.#sceneKind() !== 'chart') {
194
+ throw new Error('VALUE_AXIS_SCALE_UNSUPPORTED: time-series Workspaces are linear-only.');
195
+ }
196
+ const scene = this.#scene;
197
+ const paneIndex = scene.panes.findIndex((pane) => pane.kind === 'candle');
198
+ const axisIndex = scene.panes[paneIndex].yAxes.findIndex((axis) => axis.role === 'primary');
199
+ const candidate = parseChartScene({
200
+ ...structuredClone(scene),
201
+ panes: scene.panes.map((pane, index) => index === paneIndex
202
+ ? {
203
+ ...structuredClone(pane),
204
+ yAxes: pane.yAxes.map((axis, axisIndexValue) => axisIndexValue === axisIndex
205
+ ? { ...structuredClone(axis), scale }
206
+ : axis),
207
+ }
208
+ : pane),
209
+ });
210
+ this.#assertSceneProjection(candidate);
211
+ const engine = this.#engine;
212
+ await engine.setPriceScale(scale);
213
+ this.#scene = candidate;
214
+ this.#emit({ type: 'value-axis-scale-changed', scale });
215
+ return structuredClone(candidate);
216
+ }
217
+ setMainSeriesPresentation(presentation) {
218
+ this.#assertUsable();
219
+ if (this.#sceneKind() !== 'chart') {
220
+ throw new MainSeriesPresentationError('MAIN_SERIES_PRESENTATION_UNSUPPORTED', '/chart/candle', 'time-series Workspaces do not support main series presentation.');
221
+ }
222
+ const engine = this.#engine;
223
+ const result = engine.applyMainSeriesPresentation(presentation);
224
+ this.#scene = this.#engine.exportScene();
225
+ this.#emit({
226
+ type: 'main-series-presentation-changed',
227
+ activeType: result.activeType,
228
+ });
229
+ return result;
230
+ }
231
+ replaceScene(scene) {
232
+ this.#assertUsable();
233
+ const candidate = this.#registration.parseScene(scene);
234
+ if ((this.#sceneKind() === 'chart' && !('panes' in candidate)) ||
235
+ (this.#sceneKind() === 'time-series' && !('series' in candidate))) {
236
+ throw new Error('DRAWABLE_SCENE_KIND_UNSUPPORTED: cross-kind replacement is rejected.');
237
+ }
238
+ this.#assertSceneProjection(candidate);
239
+ const engine = this.#engine;
240
+ const applied = engine.replaceScene(candidate);
241
+ this.#scene = applied;
242
+ this.#emit({ type: 'scene-replaced', scene: { kind: this.#sceneKind(), document: applied } });
243
+ return structuredClone(applied);
244
+ }
245
+ commitDrawingChange(requestId, canonicalHash) {
246
+ return this.#session.commitDrawingChange(requestId, canonicalHash);
247
+ }
248
+ rejectDrawingChange(requestId) {
249
+ return this.#session.rejectDrawingChange(requestId);
250
+ }
251
+ requestHostAction(actionId, drawingId) {
252
+ this.#emit({
253
+ type: 'host-action-requested',
254
+ actionId,
255
+ drawingId: drawingId ?? null,
256
+ });
257
+ }
258
+ destroy() {
259
+ if (this.#destroyed) {
260
+ return;
261
+ }
262
+ this.#destroyed = true;
263
+ this.#session.destroy();
264
+ this.#engine.dispose();
265
+ this.#listeners.clear();
266
+ this.#emit({ type: 'destroyed' });
267
+ }
268
+ #buildDocument(drawings) {
269
+ const workspace = this.#workspace;
270
+ return parseDrawingDocument({
271
+ schema: '@baron1996/drawing-document',
272
+ version: 1,
273
+ scopeKey: workspace.drawings.scopeKey,
274
+ coordinateSystem: structuredClone(workspace.drawings.coordinateSystem),
275
+ drawings: drawings.map((snapshot) => snapshotToDrawing(snapshot)),
276
+ metadata: {},
277
+ });
278
+ }
279
+ #projectionScene() {
280
+ return {
281
+ kind: this.#sceneKind(),
282
+ document: this.#scene,
283
+ };
284
+ }
285
+ #assertSceneProjection(scene) {
286
+ this.#projectionService.projectDocument({
287
+ scene: {
288
+ kind: this.#sceneKind(),
289
+ document: scene,
290
+ },
291
+ drawings: this.exportDrawingDocument(),
292
+ });
293
+ }
294
+ #activeScale() {
295
+ const scene = this.#scene;
296
+ return scene.panes
297
+ .find((pane) => pane.kind === 'candle')
298
+ ?.yAxes.find((axis) => axis.role === 'primary')?.scale ?? 'linear';
299
+ }
300
+ #sceneKind() {
301
+ return 'panes' in this.#scene ? 'chart' : 'time-series';
302
+ }
303
+ #emit(event) {
304
+ const envelope = deepFreeze({
305
+ protocol: WORKSPACE_EVENT_PROTOCOL,
306
+ protocolVersion: WORKSPACE_EVENT_PROTOCOL_VERSION,
307
+ runtimeId: this.#runtimeId,
308
+ sequence: ++this.#sequence,
309
+ ...event,
310
+ });
311
+ for (const listener of this.#listeners) {
312
+ try {
313
+ listener(structuredClone(envelope));
314
+ }
315
+ catch {
316
+ // 单个监听器抛错不改变状态、不阻断其他监听器。
317
+ }
318
+ }
319
+ }
320
+ #assertUsable() {
321
+ if (this.#destroyed || this.#session.state === 'terminal-error') {
322
+ throw new DrawingSessionError('DRAWABLE_WORKSPACE_RUNTIME_DESTROYED', '/', 'The Workspace Runtime is in a destroy-only state.');
323
+ }
324
+ }
325
+ }
326
+ export async function createDrawableWorkspaceRuntime(container, workspace, options) {
327
+ return DrawableWorkspaceRuntime.create(container, workspace, options);
328
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  /** Web Runtime npm 包版本;ChartScene runtimeVersion 是独立的数据契约版本。 */
2
- export declare const WEB_RUNTIME_PACKAGE_VERSION: "0.3.0";
2
+ export declare const WEB_RUNTIME_PACKAGE_VERSION: "0.4.0";
3
3
  export { SUPPORTED_OVERLAYS } from '@baron1996/klinecharts-adapter';
4
+ export * from './drawing/capabilities.js';
5
+ export * from './drawing/projection-service.js';
6
+ export * from './drawing/runtime-capability-descriptor.js';
7
+ export * from './drawing/scene-runtime-factory.js';
8
+ export * from './drawing/session-controller.js';
9
+ export * from './drawing/workspace-events.js';
10
+ export * from './drawing/workspace-runtime.js';
4
11
  export * from './runtime.js';
5
12
  export * from './time-series-runtime.js';
6
13
  export * from './time-series-types.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,eAAO,MAAM,2BAA2B,EAAG,OAAgB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,eAAO,MAAM,2BAA2B,EAAG,OAAgB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,oCAAoC,CAAC;AACnD,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,13 @@
1
1
  /** Web Runtime npm 包版本;ChartScene runtimeVersion 是独立的数据契约版本。 */
2
- export const WEB_RUNTIME_PACKAGE_VERSION = '0.3.0';
2
+ export const WEB_RUNTIME_PACKAGE_VERSION = '0.4.0';
3
3
  export { SUPPORTED_OVERLAYS } from '@baron1996/klinecharts-adapter';
4
+ export * from './drawing/capabilities.js';
5
+ export * from './drawing/projection-service.js';
6
+ export * from './drawing/runtime-capability-descriptor.js';
7
+ export * from './drawing/scene-runtime-factory.js';
8
+ export * from './drawing/session-controller.js';
9
+ export * from './drawing/workspace-events.js';
10
+ export * from './drawing/workspace-runtime.js';
4
11
  export * from './runtime.js';
5
12
  export * from './time-series-runtime.js';
6
13
  export * from './time-series-types.js';
package/dist/runtime.d.ts CHANGED
@@ -1,12 +1,14 @@
1
- import type { ChartScene, SceneOverlay } from '@baron1996/kline-scene-schema';
2
- import { type OverlayHitResult, type PixelCoordinate } from '@baron1996/klinecharts-adapter';
1
+ import { type ChartScene, type SceneOverlay } from '@baron1996/kline-scene-schema';
2
+ import { type EngineDrawingSnapshot, type EnginePixelCoordinate, type MainSeriesPresentation, type OverlayHitResult, type PixelCoordinate } from '@baron1996/klinecharts-adapter';
3
+ import type { DrawingRuntimeCapability, RuntimeAuxiliaryCapability } from './drawing/capabilities.js';
4
+ import type { HostActionDescriptor, RuntimeCapabilityDescriptor } from './drawing/runtime-capability-descriptor.js';
3
5
  import type { KLineSceneRuntimeListener, KLineSceneRuntimeOptions, PriceScale, StartOverlayDrawingOptions, SupportedOverlayType } from './types.js';
4
6
  export declare const DEFAULT_OVERLAY_STYLES: SceneOverlay['styles'];
5
7
  /**
6
8
  * 面向 Web、离线 HTML 和测试渲染器的纯场景 Runtime。
7
9
  * 该类没有撤销/重做栈,也不公开 KLineCharts Chart 实例。
8
10
  */
9
- export declare class KLineSceneRuntime {
11
+ export declare class KLineSceneRuntime implements DrawingRuntimeCapability, RuntimeAuxiliaryCapability {
10
12
  #private;
11
13
  private constructor();
12
14
  static create(container: HTMLElement, value: unknown, options?: KLineSceneRuntimeOptions): Promise<KLineSceneRuntime>;
@@ -19,6 +21,30 @@ export declare class KLineSceneRuntime {
19
21
  }, paneId?: string): PixelCoordinate;
20
22
  hitTestOverlay(point: PixelCoordinate): OverlayHitResult | null;
21
23
  startOverlayDrawing(type: SupportedOverlayType, options?: StartOverlayDrawingOptions): string;
24
+ getRuntimeCapabilityDescriptor(options?: Readonly<{
25
+ readonly hostActions?: readonly HostActionDescriptor[];
26
+ }>): RuntimeCapabilityDescriptor;
27
+ setValueAxisScale(scale: PriceScale): Promise<ChartScene>;
28
+ setMainSeriesPresentation(presentation: MainSeriesPresentation): {
29
+ readonly activeType: string;
30
+ };
31
+ startDrawing(type: SupportedOverlayType, options?: Omit<StartOverlayDrawingOptions, 'paneId' | 'text'> & {
32
+ readonly text?: string;
33
+ }): string;
34
+ listDrawings(): readonly EngineDrawingSnapshot[];
35
+ getDrawing(id: string): EngineDrawingSnapshot | undefined;
36
+ updateDrawingStyles(id: string, styles: SceneOverlay['styles']): EngineDrawingSnapshot;
37
+ updateDrawingText(id: string, text: string): EngineDrawingSnapshot;
38
+ removeDrawing(id: string): boolean;
39
+ requestDrawingDelete(id: string): void;
40
+ getSelectedDrawingId(): string | undefined;
41
+ selectDrawing(id: string | null): void;
42
+ hitTestDrawing(point: EnginePixelCoordinate): string | null;
43
+ exportArtifact(fileName?: string): {
44
+ bytes: Uint8Array;
45
+ mediaType: 'application/json';
46
+ fileName: string;
47
+ };
22
48
  addOverlay(overlay: SceneOverlay): SceneOverlay;
23
49
  updateOverlay(overlay: SceneOverlay): SceneOverlay;
24
50
  updateOverlayStyles(id: string, styles: SceneOverlay['styles']): SceneOverlay;
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":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Scene, } from '@baron1996/kline-scene-schema';
1
2
  import { parseChartScene, SceneError, } from '@baron1996/kline-scene-schema';
2
- import { KLineChartsSceneAdapter, } from '@baron1996/klinecharts-adapter';
3
+ import { KLineChartsSceneAdapter, STANDARD_CLOSE_LINE_PRESENTATION, SUPPORTED_OVERLAYS, } from '@baron1996/klinecharts-adapter';
4
+ import { overlayToDrawingSnapshot } from './drawing/legacy-runtime-capability.js';
3
5
  import { RuntimeEventBus } from './events.js';
4
6
  import { runRuntimeTeardowns } from './lifecycle.js';
5
7
  export const DEFAULT_OVERLAY_STYLES = {
@@ -60,6 +62,7 @@ export class KLineSceneRuntime {
60
62
  this.#events.emit(toRuntimeEvent(event));
61
63
  });
62
64
  }
65
+ #defaultFileName = 'kline-scene.json';
63
66
  static async create(container, value, options = {}) {
64
67
  try {
65
68
  const scene = parseChartScene(value);
@@ -144,6 +147,99 @@ export class KLineSceneRuntime {
144
147
  };
145
148
  return this.#adapter.startOverlayDrawing(request);
146
149
  }
150
+ getRuntimeCapabilityDescriptor(options = {}) {
151
+ const scene = this.getScene();
152
+ const pane = scene.panes.find((candidate) => candidate.kind === 'candle');
153
+ const primaryAxis = pane?.yAxes.find((axis) => axis.role === 'primary');
154
+ const supportedScales = scene.runtime.runtimeVersion === '0.2.0'
155
+ ? ['linear', 'logarithmic']
156
+ : ['linear'];
157
+ return {
158
+ drawingTypes: [...SUPPORTED_OVERLAYS],
159
+ valueAxis: {
160
+ supportedScales,
161
+ activeScale: primaryAxis?.scale ?? 'linear',
162
+ mutable: true,
163
+ },
164
+ exportArtifact: {
165
+ kind: 'chart-scene',
166
+ mediaType: 'application/json',
167
+ defaultFileName: this.#defaultFileName,
168
+ },
169
+ hostActions: options.hostActions ?? [],
170
+ mainSeriesPresentation: {
171
+ presentations: [
172
+ { type: 'candle_solid' },
173
+ { type: 'candle_stroke' },
174
+ { type: 'candle_up_stroke' },
175
+ { type: 'candle_down_stroke' },
176
+ { type: 'ohlc' },
177
+ STANDARD_CLOSE_LINE_PRESENTATION,
178
+ ],
179
+ activeType: scene.chart.candle.type,
180
+ mutable: true,
181
+ },
182
+ };
183
+ }
184
+ setValueAxisScale(scale) {
185
+ return this.setPriceScale(scale);
186
+ }
187
+ setMainSeriesPresentation(presentation) {
188
+ return this.#adapter.applyMainSeriesPresentation(presentation);
189
+ }
190
+ startDrawing(type, options) {
191
+ const resolved = options === undefined
192
+ ? {}
193
+ : options;
194
+ return this.startOverlayDrawing(type, resolved);
195
+ }
196
+ listDrawings() {
197
+ return this.listOverlays().map((overlay) => overlayToDrawingSnapshot(overlay, this.getScene().period));
198
+ }
199
+ getDrawing(id) {
200
+ const overlay = this.getOverlay(id);
201
+ return overlay === undefined
202
+ ? undefined
203
+ : overlayToDrawingSnapshot(overlay, this.getScene().period);
204
+ }
205
+ updateDrawingStyles(id, styles) {
206
+ return overlayToDrawingSnapshot(this.updateOverlayStyles(id, styles), this.getScene().period);
207
+ }
208
+ updateDrawingText(id, text) {
209
+ const overlay = this.getOverlay(id);
210
+ if (overlay === undefined) {
211
+ throw new SceneError('INVALID_REFERENCE', `/overlays/${id}`, `Overlay ${id} does not exist.`);
212
+ }
213
+ if (overlay.type !== 'simpleTag' &&
214
+ overlay.type !== 'simpleAnnotation' &&
215
+ overlay.type !== 'callout' &&
216
+ overlay.type !== 'text') {
217
+ throw new SceneError('SCENE_SCHEMA_INVALID', `/overlays/${id}/text`, 'Text updates are only supported on text Drawing types.');
218
+ }
219
+ return overlayToDrawingSnapshot(this.updateOverlay({ ...overlay, text }), this.getScene().period);
220
+ }
221
+ removeDrawing(id) {
222
+ return this.removeOverlay(id);
223
+ }
224
+ requestDrawingDelete(id) {
225
+ this.requestOverlayDelete(id);
226
+ }
227
+ getSelectedDrawingId() {
228
+ return this.getSelectedOverlayId();
229
+ }
230
+ selectDrawing(id) {
231
+ this.#adapter.selectDrawing(id);
232
+ }
233
+ hitTestDrawing(point) {
234
+ return this.#adapter.hitTestOverlay(point)?.overlayId ?? null;
235
+ }
236
+ exportArtifact(fileName = this.#defaultFileName) {
237
+ return {
238
+ bytes: serializeCanonicalScene(this.exportScene()),
239
+ mediaType: 'application/json',
240
+ fileName,
241
+ };
242
+ }
147
243
  addOverlay(overlay) {
148
244
  this.#assertActive();
149
245
  return structuredClone(this.#adapter.addOverlay(structuredClone(overlay)));
@@ -1 +1 @@
1
- {"version":3,"file":"standard-toolbar-styles.d.ts","sourceRoot":"","sources":["../../src/toolbar/standard-toolbar-styles.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,QA4PnC,CAAC"}
1
+ {"version":3,"file":"standard-toolbar-styles.d.ts","sourceRoot":"","sources":["../../src/toolbar/standard-toolbar-styles.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,uBAAuB,QA8QnC,CAAC"}
@@ -250,4 +250,22 @@ export const STANDARD_TOOLBAR_STYLES = String.raw `
250
250
  transition: none;
251
251
  }
252
252
  }
253
+
254
+ .baron-kline-context-menu {
255
+ position: fixed;
256
+ z-index: 1000;
257
+ display: none;
258
+ flex-direction: column;
259
+ gap: 8px;
260
+ min-width: 180px;
261
+ padding: 10px;
262
+ border: 1px solid rgba(203, 210, 224, 1);
263
+ border-radius: 10px;
264
+ background: rgba(255, 255, 255, 0.98);
265
+ box-shadow: 0 12px 32px rgba(23, 32, 51, 0.16);
266
+ }
267
+
268
+ .baron-kline-context-menu--visible {
269
+ display: flex;
270
+ }
253
271
  `;
@@ -1,5 +1,7 @@
1
- import type { KLineSceneRuntime } from '../runtime.js';
1
+ import type { DrawingRuntimeCapability, RuntimeAuxiliaryCapability } from '../drawing/capabilities.js';
2
2
  import type { StandardToolbar, StandardToolbarOptions } from '../types.js';
3
+ type StandardDrawingRuntime = DrawingRuntimeCapability & RuntimeAuxiliaryCapability;
3
4
  /** 创建不含撤销/重做的标准离线编辑工具栏。 */
4
- export declare function createStandardToolbar(container: HTMLElement, runtime: KLineSceneRuntime, options?: StandardToolbarOptions): StandardToolbar;
5
+ export declare function createStandardToolbar(container: HTMLElement, runtime: StandardDrawingRuntime, options?: StandardToolbarOptions): StandardToolbar;
6
+ export {};
5
7
  //# sourceMappingURL=standard-toolbar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"standard-toolbar.d.ts","sourceRoot":"","sources":["../../src/toolbar/standard-toolbar.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EACX,eAAe,EACf,sBAAsB,EAEtB,MAAM,aAAa,CAAC;AA8NrB,2BAA2B;AAC3B,wBAAgB,qBAAqB,CACpC,SAAS,EAAE,WAAW,EACtB,OAAO,EAAE,iBAAiB,EAC1B,OAAO,GAAE,sBAA2B,GAClC,eAAe,CA4NjB"}
1
+ {"version":3,"file":"standard-toolbar.d.ts","sourceRoot":"","sources":["../../src/toolbar/standard-toolbar.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,wBAAwB,EACxB,0BAA0B,EAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACX,eAAe,EACf,sBAAsB,EAEtB,MAAM,aAAa,CAAC;AAyCrB,KAAK,sBAAsB,GAAG,wBAAwB,GAAG,0BAA0B,CAAC;AA0LpF,2BAA2B;AAC3B,wBAAgB,qBAAqB,CACpC,SAAS,EAAE,WAAW,EACtB,OAAO,EAAE,sBAAsB,EAC/B,OAAO,GAAE,sBAA2B,GAClC,eAAe,CA2YjB"}