@baron1996/klinecharts-runtime 0.9.15 → 0.9.16

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/README.md CHANGED
@@ -4,7 +4,7 @@ Browser editing runtime and standard annotation toolbar for deterministic KLineC
4
4
  ChartScene files.
5
5
 
6
6
  ```bash
7
- npm install --save-exact @baron1996/kline-scene-schema@0.9.15 @baron1996/klinecharts-runtime@0.9.15
7
+ npm install --save-exact @baron1996/kline-scene-schema@0.9.16 @baron1996/klinecharts-runtime@0.9.16
8
8
  ```
9
9
 
10
10
  ```ts
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Web Runtime npm 包版本;ChartScene runtimeVersion 是独立的数据契约版本。 */
2
- export declare const WEB_RUNTIME_PACKAGE_VERSION: "0.9.15";
2
+ export declare const WEB_RUNTIME_PACKAGE_VERSION: "0.9.16";
3
3
  export { SUPPORTED_OVERLAYS } from '@baron1996/klinecharts-adapter';
4
4
  export * from './cross-period/coordinator.js';
5
5
  export * from './drawing/capabilities.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Web Runtime npm 包版本;ChartScene runtimeVersion 是独立的数据契约版本。 */
2
- export const WEB_RUNTIME_PACKAGE_VERSION = '0.9.15';
2
+ export const WEB_RUNTIME_PACKAGE_VERSION = '0.9.16';
3
3
  export { SUPPORTED_OVERLAYS } from '@baron1996/klinecharts-adapter';
4
4
  export * from './cross-period/coordinator.js';
5
5
  export * from './drawing/capabilities.js';
@@ -1 +1 @@
1
- {"version":3,"file":"chart-workspace-toolbar.d.ts","sourceRoot":"","sources":["../../src/toolbar/chart-workspace-toolbar.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,gCAAgC,EAChC,wBAAwB,EACxB,8BAA8B,EAC9B,0BAA0B,EAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAYxF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barIcon } from './toolbar-icons.js';
6
6
  import { OVERLAY_TOOL_PRESENTATIONS, TEXT_OVERLAY_TYPES, TOOLBAR_GROUPS, } from './toolbar-tools.js';
7
7
  let nextWorkspaceToolbarId = 1;
8
+ function resolvePortalHost(anchor) {
9
+ const fullscreenElement = document.fullscreenElement;
10
+ return fullscreenElement !== null && fullscreenElement.contains(anchor)
11
+ ? fullscreenElement
12
+ : document.body;
13
+ }
8
14
  function runtimeStateCapability(runtime) {
9
15
  const candidate = runtime;
10
16
  return typeof candidate.getRuntimeState === 'function' &&
@@ -12,6 +18,12 @@ function runtimeStateCapability(runtime) {
12
18
  ? candidate
13
19
  : undefined;
14
20
  }
21
+ function workspaceEventCapability(runtime) {
22
+ const candidate = runtime;
23
+ return typeof candidate.subscribe === 'function'
24
+ ? candidate
25
+ : undefined;
26
+ }
15
27
  function createButton(options) {
16
28
  const button = document.createElement('button');
17
29
  button.type = 'button';
@@ -39,7 +51,7 @@ function createPopover(button, id, cleanupCallbacks) {
39
51
  element.hidden = true;
40
52
  button.setAttribute('aria-controls', id);
41
53
  button.setAttribute('aria-expanded', 'false');
42
- document.body.append(element);
54
+ resolvePortalHost(button).append(element);
43
55
  const position = () => {
44
56
  const anchor = button.getBoundingClientRect();
45
57
  const bounds = element.getBoundingClientRect();
@@ -53,6 +65,10 @@ function createPopover(button, id, cleanupCallbacks) {
53
65
  element.hidden = true;
54
66
  };
55
67
  const open = () => {
68
+ const portalHost = resolvePortalHost(button);
69
+ if (element.parentNode !== portalHost) {
70
+ portalHost.append(element);
71
+ }
56
72
  element.hidden = false;
57
73
  position();
58
74
  button.setAttribute('aria-expanded', 'true');
@@ -86,15 +102,26 @@ function createPopover(button, id, cleanupCallbacks) {
86
102
  }
87
103
  };
88
104
  const handleViewportChange = () => close();
105
+ const handleFullscreenChange = () => {
106
+ const portalHost = resolvePortalHost(button);
107
+ if (element.parentNode !== portalHost) {
108
+ portalHost.append(element);
109
+ }
110
+ if (!element.hidden) {
111
+ position();
112
+ }
113
+ };
89
114
  button.addEventListener('click', handleButtonClick);
90
115
  document.addEventListener('pointerdown', handleOutsidePointer, true);
91
116
  document.addEventListener('keydown', handleKeyDown);
117
+ document.addEventListener('fullscreenchange', handleFullscreenChange);
92
118
  window.addEventListener('resize', handleViewportChange);
93
119
  window.addEventListener('scroll', handleViewportChange, true);
94
120
  cleanupCallbacks.push(() => {
95
121
  button.removeEventListener('click', handleButtonClick);
96
122
  document.removeEventListener('pointerdown', handleOutsidePointer, true);
97
123
  document.removeEventListener('keydown', handleKeyDown);
124
+ document.removeEventListener('fullscreenchange', handleFullscreenChange);
98
125
  window.removeEventListener('resize', handleViewportChange);
99
126
  window.removeEventListener('scroll', handleViewportChange, true);
100
127
  });
@@ -114,19 +141,29 @@ function createTooltip(cleanupCallbacks) {
114
141
  tooltip.setAttribute('role', 'tooltip');
115
142
  tooltip.hidden = true;
116
143
  document.body.append(tooltip);
144
+ let activeButton = null;
117
145
  const hide = () => {
118
146
  tooltip.hidden = true;
147
+ activeButton = null;
148
+ };
149
+ const position = (button) => {
150
+ const bounds = button.getBoundingClientRect();
151
+ const tooltipBounds = tooltip.getBoundingClientRect();
152
+ const left = Math.min(bounds.right + 8, window.innerWidth - tooltipBounds.width - 8);
153
+ const top = Math.min(Math.max(8, bounds.top + (bounds.height - tooltipBounds.height) / 2), window.innerHeight - tooltipBounds.height - 8);
154
+ tooltip.style.left = `${Math.round(left)}px`;
155
+ tooltip.style.top = `${Math.round(top)}px`;
119
156
  };
120
157
  const bind = (button, label) => {
121
158
  const show = () => {
122
- const bounds = button.getBoundingClientRect();
159
+ activeButton = button;
160
+ const portalHost = resolvePortalHost(button);
161
+ if (tooltip.parentNode !== portalHost) {
162
+ portalHost.append(tooltip);
163
+ }
123
164
  tooltip.textContent = label;
124
165
  tooltip.hidden = false;
125
- const tooltipBounds = tooltip.getBoundingClientRect();
126
- const left = Math.min(bounds.right + 8, window.innerWidth - tooltipBounds.width - 8);
127
- const top = Math.min(Math.max(8, bounds.top + (bounds.height - tooltipBounds.height) / 2), window.innerHeight - tooltipBounds.height - 8);
128
- tooltip.style.left = `${Math.round(left)}px`;
129
- tooltip.style.top = `${Math.round(top)}px`;
166
+ position(button);
130
167
  };
131
168
  button.addEventListener('mouseenter', show);
132
169
  button.addEventListener('mouseleave', hide);
@@ -139,6 +176,18 @@ function createTooltip(cleanupCallbacks) {
139
176
  button.removeEventListener('blur', hide);
140
177
  });
141
178
  };
179
+ const handleFullscreenChange = () => {
180
+ if (activeButton === null || tooltip.hidden) {
181
+ return;
182
+ }
183
+ const portalHost = resolvePortalHost(activeButton);
184
+ if (tooltip.parentNode !== portalHost) {
185
+ portalHost.append(tooltip);
186
+ }
187
+ position(activeButton);
188
+ };
189
+ document.addEventListener('fullscreenchange', handleFullscreenChange);
190
+ cleanupCallbacks.push(() => document.removeEventListener('fullscreenchange', handleFullscreenChange));
142
191
  return { bind, hide, destroy: () => tooltip.remove() };
143
192
  }
144
193
  function applyHostActionState(control, state) {
@@ -547,6 +596,11 @@ export function createChartWorkspaceToolbar(containers, runtime, options = {}) {
547
596
  left.append(section);
548
597
  }
549
598
  }
599
+ const clearDrawingToolSelection = () => {
600
+ for (const button of overlayButtons) {
601
+ button.setAttribute('aria-pressed', 'false');
602
+ }
603
+ };
550
604
  const drawingActions = createSection('标注操作');
551
605
  const clearButton = createButton({ label: '清空全部标注', icon: 'clearAll' });
552
606
  clearButton.dataset.action = 'clear-all';
@@ -567,6 +621,18 @@ export function createChartWorkspaceToolbar(containers, runtime, options = {}) {
567
621
  left.append(drawingActions);
568
622
  containers.top.append(top);
569
623
  containers.left.append(left);
624
+ const eventCapability = workspaceEventCapability(runtime);
625
+ if (eventCapability !== undefined) {
626
+ cleanupCallbacks.push(eventCapability.subscribe((event) => {
627
+ if ((event.type === 'drawing-candidate' && event.operation === 'create') ||
628
+ event.type === 'drawing-committed' ||
629
+ event.type === 'drawing-rejected' ||
630
+ (event.type === 'selection-changed' && event.id === null) ||
631
+ event.type === 'workspace-error') {
632
+ clearDrawingToolSelection();
633
+ }
634
+ }));
635
+ }
570
636
  const stateCapability = runtimeStateCapability(runtime);
571
637
  let runtimeReady = stateCapability === undefined;
572
638
  let hostDataDisabled = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baron1996/klinecharts-runtime",
3
- "version": "0.9.15",
3
+ "version": "0.9.16",
4
4
  "description": "Web runtime for deterministic KLineCharts scenes.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -39,8 +39,8 @@
39
39
  "typecheck": "tsc -p tsconfig.json --noEmit"
40
40
  },
41
41
  "dependencies": {
42
- "@baron1996/kline-scene-schema": "0.9.15",
43
- "@baron1996/klinecharts-adapter": "0.9.15",
42
+ "@baron1996/kline-scene-schema": "0.9.16",
43
+ "@baron1996/klinecharts-adapter": "0.9.16",
44
44
  "@js-temporal/polyfill": "0.5.1"
45
45
  }
46
46
  }