@ray-js/ipc-player-integration 0.0.70 → 0.0.72-beta.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.
@@ -1,9 +1,13 @@
1
- import { FullScreen, ToggleVerticalFull } from '../widgets';
1
+ import { FullScreen, ToggleVerticalFull, FloatWindow } from '../widgets';
2
2
  import { ComponentConfig } from '../interface';
3
3
  export declare const defaultTopLeftContent: ComponentConfig[];
4
4
  export declare const defaultTopRightContent: ComponentConfig[];
5
5
  export declare const defaultBottomLeftContent: ComponentConfig[];
6
6
  export declare const defaultBottomRightContent: ({
7
+ id: string;
8
+ content: typeof FloatWindow;
9
+ hidden?: undefined;
10
+ } | {
7
11
  id: string;
8
12
  content: typeof ToggleVerticalFull;
9
13
  hidden: boolean;
@@ -4,7 +4,7 @@ const _excluded = ["title", "duration"];
4
4
  import { getCameraConfigInfo } from '@ray-js/ray-ipc-utils';
5
5
  import { IntercomMode, MuteMode, ClarityType } from '@ray-js/ray-ipc-utils/lib/interface';
6
6
  import { createUseCtx } from './ctx';
7
- import { FullSmallIntercom, VerticalSmallIntercom, BatteryFull, Battery, Screenshot, TempHumidity, Signal4G, RecordVideo, FullScreen, VideoBitKBP, Muted, Floodlight, Siren, TryExperience, Resolution, Ptz, MultiPtz, TileTip, PtzMoveableTip, LandscapeTip, TileActions, MoveablePtzControl, SwitchLayout, ToggleVerticalFull, RealTimeMagnification, ZoomTurntableEntry } from '../widgets';
7
+ import { FullSmallIntercom, VerticalSmallIntercom, BatteryFull, Battery, Screenshot, TempHumidity, Signal4G, RecordVideo, FullScreen, VideoBitKBP, Muted, Floodlight, Siren, TryExperience, Resolution, Ptz, MultiPtz, TileTip, PtzMoveableTip, LandscapeTip, TileActions, MoveablePtzControl, SwitchLayout, ToggleVerticalFull, FloatWindow, RealTimeMagnification, ZoomTurntableEntry } from '../widgets';
8
8
  import { authorizeStatus } from '../utils/authorize';
9
9
  import { PlayState } from '../interface';
10
10
  import { landscapeTipId, moveablePtzControlId, multiPtzId, ptzMoveableTipId, tileActionsId, tileTipId } from '../ui/constant';
@@ -79,6 +79,9 @@ export const defaultBottomRightContent = [{
79
79
  id: 'SwitchLayout',
80
80
  content: SwitchLayout,
81
81
  hidden: true
82
+ }, {
83
+ id: 'FloatWindow',
84
+ content: FloatWindow
82
85
  }, {
83
86
  id: 'ToggleVerticalFull',
84
87
  content: ToggleVerticalFull,
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { ComponentConfig, UseCtx, WidgetId } from '../../interface';
3
3
  import { FullScreen } from '../../widgets';
4
+ import type { FloatWindowOptions } from '../../widgets/floatWindow';
4
5
  type Ctx = ReturnType<UseCtx>;
5
6
  export type InitPlayerWidgetsOptions = {
6
7
  verticalResolutionCustomClick?: boolean;
@@ -20,6 +21,8 @@ export type InitPlayerWidgetsOptions = {
20
21
  showZoomTurntable?: boolean;
21
22
  directionControlProps?: Partial<React.ComponentProps<typeof FullScreen>['directionControlProps']>;
22
23
  hideSmartImageQualityState?: boolean;
24
+ /** Panel-owned eligibility and click action. Omitted means hidden. */
25
+ floatWindow?: FloatWindowOptions;
23
26
  topLeftContent?: ComponentConfig[];
24
27
  topRightContent?: ComponentConfig[];
25
28
  bottomLeftContent?: ComponentConfig[];
@@ -67,6 +67,10 @@ export async function initPlayerWidgets(ctx, options) {
67
67
  }
68
68
  ctx.addContent('bottomLeft', newDefaultBottomLeftContent);
69
69
  const newDefaultBottomRightContent = _cloneDeep(options.bottomRightContent || defaultBottomRightContent);
70
+ const floatWindowIndex = newDefaultBottomRightContent.findIndex(item => item.id === 'FloatWindow');
71
+ if (floatWindowIndex !== -1) {
72
+ newDefaultBottomRightContent[floatWindowIndex].initProps = _objectSpread(_objectSpread({}, newDefaultBottomRightContent[floatWindowIndex].initProps), options.floatWindow);
73
+ }
70
74
  const fullScreenIndex = newDefaultBottomRightContent.findIndex(item => item.id === 'FullScreen');
71
75
  if (fullScreenIndex !== -1) {
72
76
  // @ts-ignore
@@ -14,7 +14,7 @@ export type IpcContext = {
14
14
  };
15
15
  export type RetAtom<T> = PrimitiveAtom<T> & WithInitialValue<T>;
16
16
  export type ScreenType = 'full' | 'vertical';
17
- export type WidgetId = 'BatteryFull' | 'TempHumidity' | 'VideoBitKBP' | 'FullSmallIntercom' | 'Screenshot' | 'RecordVideo' | 'Muted' | 'Floodlight' | 'Siren' | 'TryExperience' | 'VerticalSmallIntercom' | 'Ptz' | 'Resolution' | 'FullScreen' | 'RealTimeMagnification' | 'ZoomTurntableEntry' | 'moveablePtzControlId';
17
+ export type WidgetId = 'BatteryFull' | 'TempHumidity' | 'VideoBitKBP' | 'FullSmallIntercom' | 'Screenshot' | 'RecordVideo' | 'Muted' | 'Floodlight' | 'Siren' | 'TryExperience' | 'VerticalSmallIntercom' | 'Ptz' | 'Resolution' | 'FullScreen' | 'FloatWindow' | 'RealTimeMagnification' | 'ZoomTurntableEntry' | 'moveablePtzControlId';
18
18
  export declare const enum PlayerStreamStatus {
19
19
  UnknownException = -1000,
20
20
  ConnectSuccess = 1001,
@@ -0,0 +1,11 @@
1
+ /** Minimum CSS-pixel gap between the two control groups, including the scroll arrow. */
2
+ export declare const BOTTOM_CONTROL_SAFE_GAP = 45;
3
+ type Rect = {
4
+ left: number;
5
+ right: number;
6
+ width: number;
7
+ };
8
+ /** The right wrapper can occupy 40% while its buttons only occupy part of it. */
9
+ export declare function getOccupiedRightWidth(wrap?: Rect, items?: Rect[]): number | undefined;
10
+ export declare function getReservedRightWidth(measured: number | null, fallback: number | string): number | string;
11
+ export {};
@@ -0,0 +1,19 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.filter.js";
3
+ import "core-js/modules/esnext.iterator.map.js";
4
+ /** Minimum CSS-pixel gap between the two control groups, including the scroll arrow. */
5
+ export const BOTTOM_CONTROL_SAFE_GAP = 45;
6
+ /** The right wrapper can occupy 40% while its buttons only occupy part of it. */
7
+ export function getOccupiedRightWidth(wrap, items) {
8
+ if (!wrap || !Number.isFinite(wrap.right) || !Array.isArray(items)) return undefined;
9
+ const visible = items.filter(item => item.width > 0 && Number.isFinite(item.left));
10
+ if (!visible.length) return 0;
11
+ const width = wrap.right - Math.min(...visible.map(item => item.left));
12
+ return width > 0 ? Math.ceil(width) : undefined;
13
+ }
14
+ export function getReservedRightWidth(measured, fallback) {
15
+ if (measured === 0) return 0;
16
+ const width = measured !== null && measured > 0 ? measured : fallback;
17
+ if (typeof width === 'number') return width > 0 ? Math.ceil(width) + BOTTOM_CONTROL_SAFE_GAP : 0;
18
+ return `calc(${width} + ${BOTTOM_CONTROL_SAFE_GAP}px)`;
19
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,64 @@
1
+ import { getOccupiedRightWidth, getReservedRightWidth } from './bottomControlLayout';
2
+ describe('bottom controls safety boundary', () => {
3
+ it.each([375, 667, 1024])('leaves >=45px before the actual buttons at width %s', width => {
4
+ const right = getOccupiedRightWidth({
5
+ left: width * 0.6,
6
+ right: width,
7
+ width: width * 0.4
8
+ }, [0, 1, 2].map(i => ({
9
+ left: width - 120 + i * 40,
10
+ right: width - 80 + i * 40,
11
+ width: 40
12
+ })));
13
+ const leftViewportRight = width - Number(getReservedRightWidth(right, '40%'));
14
+ // Both visible left controls and the arrow are clipped inside this viewport.
15
+ expect(width - 120 - leftViewportRight).toBeGreaterThanOrEqual(45);
16
+ });
17
+ it('measures buttons overflowing the fixed wrapper on a narrow screen', () => {
18
+ const measured = getOccupiedRightWidth({
19
+ left: 240,
20
+ right: 400,
21
+ width: 160
22
+ }, [{
23
+ left: 200,
24
+ right: 400,
25
+ width: 200
26
+ }]);
27
+ expect(getReservedRightWidth(measured, '40%')).toBe(245);
28
+ });
29
+ it('reclaims space when the small-window button disappears', () => {
30
+ const wrap = {
31
+ left: 225,
32
+ right: 375,
33
+ width: 150
34
+ };
35
+ const full = getOccupiedRightWidth(wrap, [{
36
+ left: 255,
37
+ right: 375,
38
+ width: 120
39
+ }]);
40
+ const reduced = getOccupiedRightWidth(wrap, [{
41
+ left: 295,
42
+ right: 375,
43
+ width: 80
44
+ }]);
45
+ expect(Number(getReservedRightWidth(full, 188)) - Number(getReservedRightWidth(reduced, 188))).toBe(40);
46
+ });
47
+ it('ignores zero-width placeholders and reserves nothing for an empty group', () => {
48
+ expect(getOccupiedRightWidth({
49
+ left: 225,
50
+ right: 375,
51
+ width: 150
52
+ }, [{
53
+ left: 0,
54
+ right: 0,
55
+ width: 0
56
+ }])).toBe(0);
57
+ expect(getReservedRightWidth(0, 188)).toBe(0);
58
+ });
59
+ it('keeps a safe fallback when native measurement is unavailable', () => {
60
+ expect(getOccupiedRightWidth(undefined, undefined)).toBeUndefined();
61
+ expect(getReservedRightWidth(null, '40%')).toBe('calc(40% + 45px)');
62
+ expect(getReservedRightWidth(null, 188)).toBe(233);
63
+ });
64
+ });
@@ -28,12 +28,6 @@ const VERTICAL_PEEK_WIDTH = 34;
28
28
  // 平铺档内容与右下角按钮之间的最小安全间距
29
29
  const VERTICAL_FLAT_SAFE_GAP = 8;
30
30
 
31
- // 收紧态(.ipc-player-bottom-left-content-container-tight)下每项省下的宽度:
32
- // 竖屏 item 左右 padding 由 12px 收到 10px,中间项左右各省 2px;
33
- // 首项只省右侧 2px —— 左侧 16px 是内容起始留白,要和其余三个角落对齐,不能动。
34
- const TIGHT_SAVE_FIRST = 2;
35
- const TIGHT_SAVE_OTHER = 4;
36
-
37
31
  // 左下角子元素统一类名(由 ui.tsx 渲染时挂上),用于 selectAll 逐项测量
38
32
  const ITEM_CLASS = 'bottom-left-item-container';
39
33
  const BottomLeftContent = _ref => {
@@ -123,11 +117,6 @@ const BottomLeftContent = _ref => {
123
117
  // 这类变化 bottomLeftContent.length 捕获不到,由 widget 主动 emit。
124
118
  const [resizeSignal, setResizeSignal] = useState(0);
125
119
 
126
- // 是否收紧 item 间距(窄屏专用,判定见下方 useEffect)。
127
- // 只升不降:收紧后各项变窄 → 重测 → 可能又判成“放得下”→ 取消收紧 → 又放不下,
128
- // 那就是一个自激振荡。锁存住,只在横竖屏切换时随其余测量值一起清零。
129
- const [tightened, setTightened] = useState(false);
130
-
131
120
  // 滑动期间暂停整体的自动隐藏,滑动停止后再恢复(无原生 scrollend,用防抖判定结束)
132
121
  const scrollingRef = useRef(false);
133
122
  const scrollEndTimerRef = useRef();
@@ -143,7 +132,6 @@ const BottomLeftContent = _ref => {
143
132
  setContentWidth(0);
144
133
  setWrapWidth(0);
145
134
  setItemWidths([]);
146
- setTightened(false);
147
135
  }, [screenType]);
148
136
 
149
137
  // 程序化滚动目标只在动画期间短暂受控,之后释放为非受控,避免回弹影响手动拖动
@@ -196,36 +184,6 @@ const BottomLeftContent = _ref => {
196
184
  if (want > availableWidth) return 0;
197
185
  return want;
198
186
  })();
199
- /**
200
- * 收紧后前 4 项能省下多少(估算:按每项的 padding 差值累加)。
201
- * 逐项宽是实测值,收紧后的真实宽度未必精确等于这个差值,作为“够不够”的预判足够。
202
- */
203
- const tightenSaving = (() => {
204
- const n = Math.min(measuredCount, VERTICAL_FLAT_MAX);
205
- if (n <= 0) return 0;
206
- return TIGHT_SAVE_FIRST + TIGHT_SAVE_OTHER * (n - 1);
207
- })();
208
-
209
- /**
210
- * 是否要把 item 间距从 12px 收到 10px。
211
- *
212
- * 两头都不收:
213
- * - **本来就放得下**(宽屏):不动,保持 12px 的宽松间距 —— 不为个别窄屏机型
214
- * 让全量机型的图标挤在一起;
215
- * - **收紧了也放不下**(更窄的屏 / 3 镜头的转盘胶囊):白挤一遍换不回箭头的
216
- * 专属落位区,不如保住观感,让箭头压在第 4 项右缘上(见下方 hasArrowRoom)。
217
- *
218
- * 只有“差一点、收紧刚好够”这一段才收 —— 这正是真机上遇到的那一档。
219
- */
220
- useEffect(() => {
221
- if (tightened) return;
222
- if (!isScrollMode || measuredCount === 0 || !(availableWidth > 0)) return;
223
- const want = firstFourWidth + VERTICAL_PEEK_WIDTH;
224
- if (want <= availableWidth) return;
225
- if (want - tightenSaving > availableWidth) return;
226
- setTightened(true);
227
- }, [tightened, isScrollMode, measuredCount, availableWidth, firstFourWidth, tightenSaving]);
228
-
229
187
  /**
230
188
  * 竖屏 scroll 档一律出箭头。
231
189
  *
@@ -324,9 +282,7 @@ const BottomLeftContent = _ref => {
324
282
  // reservedRight 决定 ScrollView 可视宽度(右下角内容异步加载后会从 0 变为实际宽度)
325
283
  reservedRight,
326
284
  // playState:视频就绪后 overlay 可能重新布局,需重新测量
327
- playState, bottomLeftContent === null || bottomLeftContent === void 0 ? void 0 : bottomLeftContent.length, shouldHide, showBadge, wrapCls, scrollCls, contentCls, scrollResetKey, resizeSignal,
328
- // 收紧后各项 padding 变小,必须重测一遍逐项宽,否则分档还在用收紧前的旧值
329
- tightened]);
285
+ playState, bottomLeftContent === null || bottomLeftContent === void 0 ? void 0 : bottomLeftContent.length, shouldHide, showBadge, wrapCls, scrollCls, contentCls, scrollResetKey, resizeSignal]);
330
286
 
331
287
  // 子元素主动上报宽度变化 → 重跑测量,及时更新横滑箭头与右边缘淡出
332
288
  useEffect(() => {
@@ -362,6 +318,7 @@ const BottomLeftContent = _ref => {
362
318
  const isButtonHint = scrollHintMode === 'button';
363
319
  // button 模式:溢出且未到末端即常显(不受 dismissed 影响);pulse 模式:保留拖动后消失的旧逻辑。
364
320
  // compact 档(<= 4 个但摆不下)不出箭头:那点空间要留给元素本身,箭头只会遮更多
321
+ const showRightHint = isOverflow && !atEnd && !isCompact && (!isVertical || isScrollMode) && (isButtonHint || !isDismissed);
365
322
 
366
323
  // 右侧还有未滚到头的内容时,启用右边缘淡出,把没完全露出的元素渐隐隐藏(横竖屏都生效)
367
324
  const fadeRightEdge = isOverflow && !atEnd;
@@ -398,6 +355,7 @@ const BottomLeftContent = _ref => {
398
355
  right: rightCss,
399
356
  height: showBadge ? `${coverHeight + 30}px` : `${coverHeight}px`,
400
357
  boxSizing: 'border-box',
358
+ overflow: 'hidden',
401
359
  display: 'flex',
402
360
  flexDirection: 'column',
403
361
  justifyContent: 'flex-start',
@@ -417,7 +375,22 @@ const BottomLeftContent = _ref => {
417
375
  trialRemainingSec: trialRemainingSec,
418
376
  onSubscribe: handleTrialSubscribe,
419
377
  onCountdownEnd: handleCountdownEnd
420
- })), /*#__PURE__*/React.createElement(ScrollView, {
378
+ })), /*#__PURE__*/React.createElement(View, {
379
+ className: clsx('ipc-player-bottom-left-scroll-viewport', {
380
+ 'ipc-player-bottom-left-scroll-fademask': fadeRightEdge,
381
+ 'ipc-player-bottom-left-scroll-fademask--narrow': fadeRightEdge && isScrollMode,
382
+ 'ipc-player-bottom-left-scroll-fademask--arrow': fadeRightEdge && showRightHint
383
+ }),
384
+ style: {
385
+ width: verticalScrollWidth > 0 ? `${verticalScrollWidth}px` : '100%',
386
+ height: `${containerHeight}px`,
387
+ position: 'relative',
388
+ top: `${coverHeight - containerHeight}px`,
389
+ marginTop: showBadge ? '-2px' : 0,
390
+ overflow: 'hidden',
391
+ flexShrink: 0
392
+ }
393
+ }, /*#__PURE__*/React.createElement(ScrollView, {
421
394
  key: scrollResetKey,
422
395
  scrollX: true,
423
396
  scrollLeft: scrollTo,
@@ -452,29 +425,17 @@ const BottomLeftContent = _ref => {
452
425
  }
453
426
  }
454
427
  },
455
- className: clsx(scrollCls, {
456
- 'ipc-player-bottom-left-scroll-fademask': fadeRightEdge,
457
- // 竖屏 scroll 档一律用窄渐变(34px,只覆盖箭头那块)。
458
- // 原条件是「锁宽成功」,可没锁宽时可视区右缘同样压着第 4 项,
459
- // 72px 的宽渐变会把宽 widget(转盘胶囊约 100px)淡掉一大半。
460
- // 横屏 isScrollMode 恒为 false,仍走 72px 宽渐变,行为不变。
461
- 'ipc-player-bottom-left-scroll-fademask--narrow': fadeRightEdge && isScrollMode
462
- }),
428
+ className: scrollCls,
463
429
  style: {
464
430
  paddingBottom: `${paddingBottomPx}px`,
465
431
  paddingLeft: `${paddingLeftPx}px`,
466
432
  paddingRight: `${paddingRightPx}px`,
467
- width: verticalScrollWidth > 0 ? `${verticalScrollWidth}px` : '100%',
468
- height: `${containerHeight}px`,
469
- position: 'relative',
470
- top: `${coverHeight - containerHeight}px`,
471
- marginTop: showBadge ? '-2px' : 0,
433
+ width: '100%',
434
+ height: '100%',
472
435
  whiteSpace: 'nowrap'
473
436
  }
474
437
  }, /*#__PURE__*/React.createElement(View, {
475
- className: clsx('ipc-player-bottom-left-content-container', contentCls, {
476
- 'ipc-player-bottom-left-content-container-tight': tightened
477
- }),
438
+ className: clsx('ipc-player-bottom-left-content-container', contentCls),
478
439
  style: {
479
440
  display: 'inline-flex',
480
441
  flexDirection: 'row',
@@ -489,7 +450,7 @@ const BottomLeftContent = _ref => {
489
450
  height: '1px',
490
451
  flexShrink: 0
491
452
  }
492
- }))), isOverflow && !atEnd && !isCompact && (!isVertical || isScrollMode) && (isButtonHint || !isDismissed) && /*#__PURE__*/React.createElement(CoverView, {
453
+ })))), showRightHint && /*#__PURE__*/React.createElement(CoverView, {
493
454
  className: clsx('ipc-player-bottom-left-scroll-hint', {
494
455
  'ipc-player-bottom-left-scroll-hint--button': isButtonHint
495
456
  }),
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,138 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.map.js";
3
+ import "core-js/modules/esnext.iterator.reduce.js";
4
+ import React from 'react';
5
+ import ReactDOM from 'react-dom';
6
+ import { act, Simulate } from 'react-dom/test-utils';
7
+ import { atom } from 'jotai';
8
+ import BottomLeftContent from './bottomLeftContent';
9
+ jest.mock('@ray-js/ray', () => {
10
+ const React = require('react');
11
+ return {
12
+ View: 'div',
13
+ CoverView: 'div',
14
+ ScrollView: _ref => {
15
+ let {
16
+ children,
17
+ onScroll,
18
+ className,
19
+ style
20
+ } = _ref;
21
+ return React.createElement('div', {
22
+ onScroll,
23
+ className,
24
+ style
25
+ }, children);
26
+ }
27
+ };
28
+ });
29
+ jest.mock('./hooks', () => ({
30
+ useComponentHideState: () => [false]
31
+ }));
32
+ jest.mock('../widgets/trialBadge', () => ({
33
+ TrialBadge: () => null,
34
+ useTrialBadge: () => ({
35
+ showTrialBadge: false
36
+ })
37
+ }));
38
+ describe('left toolbar fade', () => {
39
+ let container;
40
+ let widths;
41
+ let available;
42
+ beforeEach(() => {
43
+ jest.useFakeTimers();
44
+ container = document.createElement('div');
45
+ document.body.appendChild(container);
46
+ widths = [49, 45, 44, 56, 55];
47
+ available = 204;
48
+ global.ty = {
49
+ createSelectorQuery: () => {
50
+ const query = {
51
+ select: () => query,
52
+ selectAll: () => query,
53
+ boundingClientRect: () => query,
54
+ exec: cb => {
55
+ const total = widths.reduce((a, b) => a + b, 0);
56
+ cb([{
57
+ width: available
58
+ }, {
59
+ left: 0,
60
+ width: available
61
+ }, {
62
+ width: total
63
+ }, {
64
+ left: total
65
+ }, widths.map(width => ({
66
+ width
67
+ }))]);
68
+ }
69
+ };
70
+ return query;
71
+ }
72
+ };
73
+ });
74
+ afterEach(() => {
75
+ act(() => {
76
+ ReactDOM.unmountComponentAtNode(container);
77
+ });
78
+ container.remove();
79
+ jest.clearAllTimers();
80
+ jest.useRealTimers();
81
+ });
82
+ const render = () => {
83
+ const ctx = {
84
+ devId: 'camera',
85
+ screenType: atom('vertical'),
86
+ isVerticalFullLayout: atom(false),
87
+ playState: atom(1),
88
+ brandColor: atom('#0085ff'),
89
+ bottomLeftContent: atom([]),
90
+ event: {
91
+ on: jest.fn(),
92
+ off: jest.fn(),
93
+ emit: jest.fn()
94
+ }
95
+ };
96
+ act(() => {
97
+ ReactDOM.render(/*#__PURE__*/React.createElement(BottomLeftContent, {
98
+ ctx: ctx,
99
+ reservedRight: 171
100
+ }, widths.map((width, i) => /*#__PURE__*/React.createElement("div", {
101
+ className: "bottom-left-item-container",
102
+ key: width
103
+ }, i))), container);
104
+ });
105
+ act(() => {
106
+ jest.advanceTimersByTime(60);
107
+ });
108
+ };
109
+ it('fades clipped content in a fixed viewport while keeping the arrow outside the mask', () => {
110
+ render();
111
+ const viewport = container.querySelector('.ipc-player-bottom-left-scroll-viewport');
112
+ const arrow = container.querySelector('.ipc-player-bottom-left-scroll-hint');
113
+ expect(viewport.classList.contains('ipc-player-bottom-left-scroll-fademask--arrow')).toBe(true);
114
+ expect(viewport.style.overflow).toBe('hidden');
115
+ expect(arrow).not.toBeNull();
116
+ expect(viewport.contains(arrow)).toBe(false);
117
+ const scroll = viewport.firstElementChild;
118
+ expect(scroll.classList.contains('ipc-player-bottom-left-scroll-fademask')).toBe(false);
119
+ });
120
+ it('removes both the fade and arrow after scrolling to the final item', () => {
121
+ render();
122
+ const scroll = container.querySelector('.ipc-player-bottom-left-scroll-viewport').firstElementChild;
123
+ act(() => {
124
+ Simulate.scroll(scroll, {
125
+ scrollLeft: 999
126
+ });
127
+ });
128
+ expect(container.querySelector('.ipc-player-bottom-left-scroll-fademask')).toBeNull();
129
+ expect(container.querySelector('.ipc-player-bottom-left-scroll-hint')).toBeNull();
130
+ });
131
+ it('leaves a toolbar that fits completely opaque', () => {
132
+ widths = [49, 45, 44, 56];
133
+ available = 280;
134
+ render();
135
+ expect(container.querySelector('.ipc-player-bottom-left-scroll-fademask')).toBeNull();
136
+ expect(container.querySelector('.ipc-player-bottom-left-scroll-hint')).toBeNull();
137
+ });
138
+ });
@@ -10,10 +10,10 @@ type Props = {
10
10
  */
11
11
  width?: number | string;
12
12
  /**
13
- * 右下角实际渲染宽度的上报回调(竖屏用)。
13
+ * 右下角实际可见按钮占用宽度的上报回调(横竖屏通用)。
14
14
  * 左下角据此决定自己能摆多宽 —— 右边挂几个功能都能自动让位,不再靠固定常量拍脑袋。
15
15
  */
16
- onWidthChange?: (width: number) => void;
16
+ onWidthChange?: (width: number | null) => void;
17
17
  };
18
18
  declare const BottomRightContent: ({ ctx, children, width, onWidthChange }: Props) => React.JSX.Element;
19
19
  export default BottomRightContent;
@@ -1,10 +1,12 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import React, { useEffect, useRef } from 'react';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
3
  import { CoverView, View } from '@ray-js/ray';
4
4
  import clsx from 'clsx';
5
5
  import { useStore } from '../ctx/store';
6
6
  import { useComponentHideState } from './hooks';
7
7
  import { getBottomCoverHeight } from './bottomCoverHeight';
8
+ import { getOccupiedRightWidth } from './bottomControlLayout';
9
+ import { bottomRightContentResize } from './constant';
8
10
 
9
11
  // 用唯一 className 在 createSelectorQuery 中区分多个实例,避免互相干扰
10
12
  let rightClsSeq = 0;
@@ -29,20 +31,30 @@ const BottomRightContent = _ref => {
29
31
  const [shouldHide] = useComponentHideState();
30
32
  const idRef = useRef(++rightClsSeq);
31
33
  const wrapCls = `ipc-br-wrap-${idRef.current}`;
32
- const lastWidthRef = useRef(0);
34
+ const lastWidthRef = useRef(null);
35
+ const [resizeSignal, setResizeSignal] = useState(0);
36
+ useEffect(() => {
37
+ const resize = () => setResizeSignal(value => value + 1);
38
+ ctx.event.on(bottomRightContentResize, resize);
39
+ return () => ctx.event.off(bottomRightContentResize, resize);
40
+ }, [ctx.event]);
33
41
 
34
42
  // 实测自身宽度并上报。按钮是异步 / 按 dp 条件渲染的,宽度会在首测之后才长大,
35
43
  // 因此和左下角一样在时间窗内轮询,值没变时不重复上报。
36
44
  useEffect(() => {
37
45
  let timer;
38
46
  let attempts = 0;
47
+ let active = true;
48
+ lastWidthRef.current = null;
49
+ onWidthChange === null || onWidthChange === void 0 || onWidthChange(null);
39
50
  const measure = () => {
40
51
  const query = ty.createSelectorQuery();
41
52
  query.select(`.${wrapCls}`).boundingClientRect();
53
+ query.selectAll(`.${wrapCls} .bottom-right-item-container`).boundingClientRect();
42
54
  query.exec(res => {
43
- var _res$;
44
- const w = (res === null || res === void 0 || (_res$ = res[0]) === null || _res$ === void 0 ? void 0 : _res$.width) || 0;
45
- if (w > 0 && Math.abs(w - lastWidthRef.current) >= 1) {
55
+ if (!active) return;
56
+ const w = getOccupiedRightWidth(res === null || res === void 0 ? void 0 : res[0], res === null || res === void 0 ? void 0 : res[1]);
57
+ if (w !== undefined && (lastWidthRef.current === null || Math.abs(w - lastWidthRef.current) >= 1)) {
46
58
  lastWidthRef.current = w;
47
59
  onWidthChange === null || onWidthChange === void 0 || onWidthChange(w);
48
60
  }
@@ -55,9 +67,10 @@ const BottomRightContent = _ref => {
55
67
  };
56
68
  timer = setTimeout(measure, 60);
57
69
  return () => {
70
+ active = false;
58
71
  if (timer) clearTimeout(timer);
59
72
  };
60
- }, [screenType, playState, bottomRightContent === null || bottomRightContent === void 0 ? void 0 : bottomRightContent.length, shouldHide, wrapCls, onWidthChange]);
73
+ }, [screenType, playState, bottomRightContent, shouldHide, wrapCls, onWidthChange, resizeSignal]);
61
74
  const containerHeight = screenType === 'vertical' ? 48 : 58;
62
75
  const coverHeight = getBottomCoverHeight(screenType, isVerticalFullLayout, shouldHide);
63
76
 
@@ -74,7 +87,7 @@ const BottomRightContent = _ref => {
74
87
  className: clsx('ipc-player-bottom-right-content-wrap', wrapCls),
75
88
  style: _objectSpread({
76
89
  // 竖屏归 0:这 10px 是纯空白,且计入实测宽后又被 reservedRight 带给左下角,
77
- // 等于左下角白让 10px。与右下角按钮的间距统一由 BOTTOM_RIGHT_SAFE_GAP 负责。
90
+ // 等于左下角白让 10px。安全距离由左侧视口单独预留。
78
91
  paddingLeft: '0',
79
92
  height: `${coverHeight}px`,
80
93
  boxSizing: 'border-box'
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,144 @@
1
+ import React from 'react';
2
+ import ReactDOM from 'react-dom';
3
+ import { act } from 'react-dom/test-utils';
4
+ import { atom } from 'jotai';
5
+ import BottomRightContent from './bottomRightContent';
6
+ import { bottomRightContentResize } from './constant';
7
+ jest.mock('@ray-js/ray', () => ({
8
+ View: 'div',
9
+ CoverView: 'div'
10
+ }));
11
+ jest.mock('./hooks', () => ({
12
+ useComponentHideState: () => [false]
13
+ }));
14
+ describe('actual right-control measurement', () => {
15
+ let container;
16
+ let resize;
17
+ let ctx;
18
+ let result;
19
+ let pending;
20
+ let callback;
21
+ beforeEach(() => {
22
+ jest.useFakeTimers();
23
+ container = document.createElement('div');
24
+ document.body.appendChild(container);
25
+ callback = jest.fn();
26
+ result = [{
27
+ left: 400,
28
+ right: 800,
29
+ width: 400
30
+ }, [{
31
+ left: 680,
32
+ right: 800,
33
+ width: 120
34
+ }]];
35
+ global.ty = {
36
+ createSelectorQuery: () => {
37
+ const query = {
38
+ select: () => query,
39
+ selectAll: () => query,
40
+ boundingClientRect: () => query,
41
+ exec: cb => {
42
+ if (result) cb(result);else pending = cb;
43
+ }
44
+ };
45
+ return query;
46
+ }
47
+ };
48
+ ctx = {
49
+ screenType: atom('full'),
50
+ isVerticalFullLayout: atom(false),
51
+ playState: atom(1),
52
+ bottomRightContent: atom([]),
53
+ event: {
54
+ on: jest.fn((name, cb) => {
55
+ if (name === bottomRightContentResize) resize = cb;
56
+ }),
57
+ off: jest.fn()
58
+ }
59
+ };
60
+ });
61
+ afterEach(() => {
62
+ act(() => {
63
+ ReactDOM.unmountComponentAtNode(container);
64
+ });
65
+ container.remove();
66
+ jest.clearAllTimers();
67
+ jest.useRealTimers();
68
+ });
69
+ const render = () => act(() => {
70
+ ReactDOM.render(/*#__PURE__*/React.createElement(BottomRightContent, {
71
+ ctx: ctx,
72
+ width: "40%",
73
+ onWidthChange: callback
74
+ }, /*#__PURE__*/React.createElement("div", {
75
+ className: "bottom-right-item-container"
76
+ })), container);
77
+ });
78
+ it('measures occupied buttons while keeping the right group in its existing 40% wrapper', () => {
79
+ render();
80
+ act(() => {
81
+ jest.advanceTimersByTime(60);
82
+ });
83
+ expect(callback).toHaveBeenLastCalledWith(120);
84
+ expect(container.firstChild.style.width).toBe('40%');
85
+ });
86
+ it('remeasures a visibility change after polling has finished and clears stale width first', () => {
87
+ render();
88
+ act(() => {
89
+ jest.advanceTimersByTime(6500);
90
+ });
91
+ result = [{
92
+ left: 400,
93
+ right: 800,
94
+ width: 400
95
+ }, [{
96
+ left: 640,
97
+ right: 800,
98
+ width: 160
99
+ }]];
100
+ act(() => resize());
101
+ expect(callback).toHaveBeenLastCalledWith(null);
102
+ act(() => {
103
+ jest.advanceTimersByTime(60);
104
+ });
105
+ expect(callback).toHaveBeenLastCalledWith(160);
106
+ });
107
+ it('reports an empty group instead of keeping the last nonempty width', () => {
108
+ render();
109
+ act(() => {
110
+ jest.advanceTimersByTime(60);
111
+ });
112
+ result = [{
113
+ left: 400,
114
+ right: 800,
115
+ width: 400
116
+ }, []];
117
+ act(() => resize());
118
+ act(() => {
119
+ jest.advanceTimersByTime(60);
120
+ });
121
+ expect(callback).toHaveBeenLastCalledWith(0);
122
+ });
123
+ it('ignores a measurement callback after unmount', () => {
124
+ result = undefined;
125
+ render();
126
+ act(() => {
127
+ jest.advanceTimersByTime(60);
128
+ });
129
+ act(() => {
130
+ ReactDOM.unmountComponentAtNode(container);
131
+ });
132
+ callback.mockClear();
133
+ act(() => pending([{
134
+ left: 400,
135
+ right: 800,
136
+ width: 400
137
+ }, [{
138
+ left: 680,
139
+ right: 800,
140
+ width: 120
141
+ }]]));
142
+ expect(callback).not.toHaveBeenCalled();
143
+ });
144
+ });
@@ -70,3 +70,5 @@ export declare const decodeClarityDic: {
70
70
  AUTO: string;
71
71
  AUDIO: string;
72
72
  };
73
+ /** A right-hand widget changed its actual visibility without changing the content list. */
74
+ export declare const bottomRightContentResize = "bottomRightContentResize";
@@ -78,4 +78,7 @@ export const decodeClarityDic = {
78
78
  AUTO: 'auto',
79
79
  // 自动
80
80
  AUDIO: 'audio' // 音频模式
81
- };
81
+ };
82
+
83
+ /** A right-hand widget changed its actual visibility without changing the content list. */
84
+ export const bottomRightContentResize = 'bottomRightContentResize';
package/lib/ui/ui.js CHANGED
@@ -16,8 +16,9 @@ import { PlayState, PlayerStreamStatus, MultiCameraScreenMode } from '../interfa
16
16
  import { useCtx } from '../ctx/ctx.composition';
17
17
  import { useStore, updateAtom } from '../ctx/store';
18
18
  import { UIEventContext } from './context';
19
- import { showAllComponent, hideAllComponent, playerTap, startTimeToHideAllComponent, pauseTimeToHideAllComponent, decodeClarityDic, changeIgnoreHideStopPreview, moveablePtzControlId, tileActionsId, tileTipId, landscapeTipId, multiPtzId, ptzMoveableTipId, ptzControlTipId, showFlowLowTipId, zoomLevelChange, setScaleMultipleEvent, trialCountdownEnd, refreshSmartImageQualityEvent } from './constant';
19
+ import { showAllComponent, bottomRightContentResize, bottomLeftContentResize, hideAllComponent, playerTap, startTimeToHideAllComponent, pauseTimeToHideAllComponent, decodeClarityDic, changeIgnoreHideStopPreview, moveablePtzControlId, tileActionsId, tileTipId, landscapeTipId, multiPtzId, ptzMoveableTipId, ptzControlTipId, showFlowLowTipId, zoomLevelChange, setScaleMultipleEvent, trialCountdownEnd, refreshSmartImageQualityEvent } from './constant';
20
20
  import BottomLeftContent from './bottomLeftContent';
21
+ import { getReservedRightWidth } from './bottomControlLayout';
21
22
  import BottomRightContent from './bottomRightContent';
22
23
  import TopLeftContent from './topLeftContent';
23
24
  import TopRightContent from './topRightContent';
@@ -94,12 +95,6 @@ const SET_SCALE_ALIGN_TIMEOUT = 1500;
94
95
 
95
96
  /** 回读值与对齐值 / 目标值的比对容差 */
96
97
  const SCALE_MATCH_EPS = 0.01;
97
-
98
- /** 竖屏左下角内容与右下角按钮之间的安全间距(px) */
99
- // 左下角内容右缘与右下角按钮之间的安全间距。
100
- // 原为 12px:右下角 wrap 当时还带 10px paddingLeft,两段叠起来是 22px 空白,窄屏上太奢侈。
101
- // paddingLeft 已归 0,这里收到 4px —— 右下角按钮自身还有 16px 的右留白撑着,不会显挤。
102
- const BOTTOM_RIGHT_SAFE_GAP = 4;
103
98
  export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
104
99
  const {
105
100
  className,
@@ -674,6 +669,8 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
674
669
 
675
670
  // 折叠屏展开/收起、pad 多窗口拖拽等场景,需要重新计算并同步
676
671
  setIsSmallScreen(computeIsSmallScreen());
672
+ instance.event.emit(bottomRightContentResize);
673
+ instance.event.emit(bottomLeftContentResize);
677
674
  setScreenType(type === 'landscape' ? 'full' : 'vertical');
678
675
  if (type === 'landscape') {
679
676
  // 记录切换横屏前的竖屏全屏状态
@@ -831,43 +828,16 @@ export const IPCPlayerIntegration = /*#__PURE__*/React.memo(props => {
831
828
  const visibleCount = (bottomRightContent || []).filter(item => !item.hidden).length;
832
829
  if (visibleCount <= 0) return 0;
833
830
  if (visibleCount === 1) return 115;
834
- return 132;
831
+ return 132 + Math.max(0, visibleCount - 2) * 56;
835
832
  }, [bottomRightContent, screenType]);
836
833
 
837
- // 右下角实测宽度(竖屏)。按钮数量 / 是否渲染都是动态的,固定常量会白白吃掉左下角可用宽,
838
- // 这里由 BottomRightContent 实测上报,右边挂几个功能左边就自动让多少位。
839
- const [bottomRightMeasuredWidth, setBottomRightMeasuredWidth] = useState(0);
834
+ // Measure the visible buttons in both orientations without moving the right group.
835
+ const [bottomRightMeasuredWidth, setBottomRightMeasuredWidth] = useState(null);
840
836
  const handleBottomRightWidthChange = useMemoizedFn(w => {
841
- setBottomRightMeasuredWidth(prev => Math.abs(prev - w) >= 1 ? w : prev);
837
+ setBottomRightMeasuredWidth(prev => w === null || prev === null || Math.abs(prev - w) >= 1 ? w : prev);
842
838
  });
843
-
844
- // 屏幕宽只用于给实测值封顶,取一次即可
845
- const windowWidthRef = useRef(0);
846
- if (!windowWidthRef.current) {
847
- var _getSystemInfoSync;
848
- windowWidthRef.current = ((_getSystemInfoSync = getSystemInfoSync()) === null || _getSystemInfoSync === void 0 ? void 0 : _getSystemInfoSync.windowWidth) || 0;
849
- }
850
-
851
- /**
852
- * 左下角右侧要预留的宽度:竖屏优先用实测值 + 安全间距,实测不到再退回常量估算;
853
- * 横屏保持原来的 40% 不变。
854
- */
855
- const bottomRightReserved = useMemo(() => {
856
- if (screenType === 'full') {
857
- return bottomRightWidth;
858
- }
859
- // 安卓上 CoverView 的 boundingClientRect 可能一直测不出宽度,轮询跑完仍是 0
860
- if (!(bottomRightMeasuredWidth > 0)) {
861
- return bottomRightWidth;
862
- }
863
- // 封顶保护:个别宿主里不设宽度的 CoverView 可能撑满整行,实测值会异常放大,
864
- // 那样左下角会被挤没。超过屏宽一半就当测量不可信,退回常量估算。
865
- const maxReserved = windowWidthRef.current ? windowWidthRef.current / 2 : 0;
866
- if (maxReserved && bottomRightMeasuredWidth > maxReserved) {
867
- return bottomRightWidth;
868
- }
869
- return Math.ceil(bottomRightMeasuredWidth) + BOTTOM_RIGHT_SAFE_GAP;
870
- }, [screenType, bottomRightWidth, bottomRightMeasuredWidth]);
839
+ useEffect(() => setBottomRightMeasuredWidth(null), [screenType, bottomRightContent]);
840
+ const bottomRightReserved = getReservedRightWidth(bottomRightMeasuredWidth, bottomRightWidth);
871
841
 
872
842
  /**
873
843
  * 传给右下角自身的 width:竖屏不再强制固定宽(否则测出来的永远是那个常量),
package/lib/ui/ui.less CHANGED
@@ -219,37 +219,29 @@
219
219
  opacity: 1;
220
220
  }
221
221
 
222
- // 右边缘淡出:把没完全露出的元素渐隐到透明。写成静态类,避免内联 mask 在原生层反复重绘闪烁
222
+ // Apply alpha to the fixed viewport, leaving the independently rendered arrow unaffected.
223
223
  .ipc-player-bottom-left-scroll-fademask {
224
+ --ipc-left-fade-width: 72px;
225
+ --ipc-left-fade-end: 0px;
224
226
  -webkit-mask-image: linear-gradient(
225
227
  to right,
226
- #000 calc(100% - 72px),
227
- rgba(0, 0, 0, 0.25) calc(100% - 24px),
228
- transparent 100%
228
+ #000 calc(100% - var(--ipc-left-fade-width)),
229
+ transparent calc(100% - var(--ipc-left-fade-end))
229
230
  );
230
231
  mask-image: linear-gradient(
231
232
  to right,
232
- #000 calc(100% - 72px),
233
- rgba(0, 0, 0, 0.25) calc(100% - 24px),
234
- transparent 100%
233
+ #000 calc(100% - var(--ipc-left-fade-width)),
234
+ transparent calc(100% - var(--ipc-left-fade-end))
235
235
  );
236
236
  }
237
237
 
238
- // 竖屏滚动档:可视区被收窄到“前 4 项 + 露一角”,渐变区同步收窄到只覆盖那一角,
239
- // 否则 72px 的渐变会把第 4 项也淡掉一大半
240
238
  .ipc-player-bottom-left-scroll-fademask--narrow {
241
- -webkit-mask-image: linear-gradient(
242
- to right,
243
- #000 calc(100% - 34px),
244
- rgba(0, 0, 0, 0.3) calc(100% - 14px),
245
- transparent 100%
246
- );
247
- mask-image: linear-gradient(
248
- to right,
249
- #000 calc(100% - 34px),
250
- rgba(0, 0, 0, 0.3) calc(100% - 14px),
251
- transparent 100%
252
- );
239
+ --ipc-left-fade-width: 56px;
240
+ }
241
+
242
+ // Finish fading underneath the leading edge of the 26px arrow button.
243
+ .ipc-player-bottom-left-scroll-fademask--arrow {
244
+ --ipc-left-fade-end: 24px;
253
245
  }
254
246
 
255
247
  @keyframes ipc-player-bottom-left-scroll-hint-pulse {
@@ -311,85 +303,58 @@
311
303
  padding: 0 16px 0 0;
312
304
  }
313
305
 
314
- // 左下角子元素容器(竖屏;横屏另叠 .bottom-left-item-full-container 且带 !important)
306
+ // 相邻控件的内容边缘统一间隔 22px;两侧各分配 11px。
307
+ // 首尾保留既有外侧留白,横竖屏只改变外侧留白,不改变内部间距。
315
308
  .bottom-left-item-container {
316
- padding: 0 12px;
309
+ padding: 0 11px;
317
310
  display: flex;
318
311
  justify-content: center;
319
312
  align-items: center;
320
- // 左下角支持横向滚动;不允许子项被压缩,否则在 width:100% 的滚动容器里
321
- // 子项会被挤而不是触发横滑
322
313
  flex-shrink: 0;
323
314
  }
324
315
 
325
316
  .bottom-left-item-container:first-of-type {
326
- padding: 0 12px 0 16px;
317
+ padding: 0 11px 0 16px;
327
318
  }
328
319
 
329
320
  .bottom-left-item-container:last-of-type {
330
- padding: 0 0 0 12px;
321
+ padding: 0 0 0 11px;
331
322
  }
332
323
 
333
324
  .bottom-left-item-container:only-of-type {
334
325
  padding: 0 0 0 16px;
335
326
  }
336
327
 
337
- // 收紧态:左右各 10px(默认 12px)。
338
- //
339
- // 只有窄屏上「前 4 项 + 34 露出区」放不下、且收紧后刚好放得下时才挂这个类
340
- // (判定见 bottomLeftContent.tsx 的 tightened)。宽屏本来就放得下,
341
- // 保持 12px 的宽松间距,不为个别机型让全量机型变紧。
342
- //
343
- // 中间项左右各省 2px = 4px;首项只省右侧 2px —— 左侧 16px 是内容起始留白,
344
- // 要和其余三个角落对齐,不能动。10px 是不显挤的下限。
345
- //
346
- // 横屏叠的 .bottom-left-item-full-container 带 !important,优先级更高,不受影响。
347
- .ipc-player-bottom-left-content-container-tight {
348
- .bottom-left-item-container {
349
- padding: 0 10px;
350
- }
351
-
352
- .bottom-left-item-container:first-of-type {
353
- padding: 0 10px 0 16px;
354
- }
355
-
356
- .bottom-left-item-container:last-of-type {
357
- padding: 0 0 0 10px;
358
- }
359
- }
360
-
361
- // 左下角全屏子元素容器
362
328
  .bottom-left-item-full-container {
363
- padding: 0 16px !important;
329
+ padding: 0 11px !important;
364
330
  flex-shrink: 0;
365
331
  }
366
332
 
367
333
  .bottom-left-item-full-container:first-of-type {
368
- padding: 0 16px 0 12px !important;
334
+ padding: 0 11px 0 12px !important;
369
335
  }
370
336
 
371
337
  .bottom-left-item-full-container:last-of-type {
372
- padding: 0 0 0 16px !important;
338
+ padding: 0 0 0 11px !important;
373
339
  }
374
340
 
375
341
  .bottom-left-item-full-container:only-of-type {
376
342
  padding: 0 0 0 12px !important;
377
343
  }
378
344
 
379
- // 右下角子元素容器
380
345
  .bottom-right-item-container {
381
- padding: 0 8px;
346
+ padding: 0 11px;
382
347
  display: flex;
383
348
  justify-content: center;
384
349
  align-items: center;
385
350
  }
386
351
 
387
352
  .bottom-right-item-container:first-of-type {
388
- padding: 0 12px 0 0;
353
+ padding: 0 11px 0 0;
389
354
  }
390
355
 
391
356
  .bottom-right-item-container:last-of-type {
392
- padding: 0 16px 0 12px;
357
+ padding: 0 16px 0 11px;
393
358
  }
394
359
 
395
360
  .bottom-right-item-container:only-of-type {
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { ComponentConfigProps } from '../../interface';
3
+ import './floatWindow.less';
4
+ /** Business eligibility and native actions belong to the consuming panel. */
5
+ export type FloatWindowOptions = {
6
+ visible: boolean;
7
+ onClick: (deviceId: string) => void | Promise<void>;
8
+ };
9
+ type Props = ComponentConfigProps & Partial<FloatWindowOptions> & {
10
+ className?: string;
11
+ };
12
+ export declare function FloatWindow(props: Props): React.JSX.Element | null;
13
+ export {};
@@ -0,0 +1,93 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.some.js";
3
+ import React, { useContext, useEffect, useRef, useState } from 'react';
4
+ import { View } from '@ray-js/ray';
5
+ import clsx from 'clsx';
6
+ import { useStore } from '../../ctx/store';
7
+ import { UIEventContext } from '../../ui/context';
8
+ import { bottomRightContentResize, fullTravelRouteControlId, ptzControlId, widgetClick } from '../../ui/constant';
9
+ import { floatWindowIcon } from './icon';
10
+ import './floatWindow.less';
11
+
12
+ /** Business eligibility and native actions belong to the consuming panel. */
13
+
14
+ export function FloatWindow(props) {
15
+ const {
16
+ visible = false,
17
+ onClick,
18
+ devId,
19
+ event,
20
+ className
21
+ } = props;
22
+ const {
23
+ screenType
24
+ } = useStore({
25
+ screenType: props.screenType
26
+ });
27
+ const {
28
+ absoluteContent
29
+ } = useStore({
30
+ absoluteContent: props.absoluteContent
31
+ });
32
+ const {
33
+ componentHideState,
34
+ refreshElement
35
+ } = useContext(UIEventContext);
36
+ const [ptzActive, setPtzActive] = useState(false);
37
+ const [busy, setBusy] = useState(false);
38
+ const opening = useRef(false);
39
+ const mounted = useRef(false);
40
+ useEffect(() => {
41
+ mounted.current = true;
42
+ return () => {
43
+ mounted.current = false;
44
+ };
45
+ }, []);
46
+ useEffect(() => {
47
+ setPtzActive(false);
48
+ const show = () => setPtzActive(true);
49
+ const hide = () => setPtzActive(false);
50
+ event.on('ptzControlShow', show);
51
+ event.on('ptzControlHide', hide);
52
+ return () => {
53
+ event.off('ptzControlShow', show);
54
+ event.off('ptzControlHide', hide);
55
+ };
56
+ }, [event, devId]);
57
+ useEffect(() => {
58
+ if (screenType === 'vertical') setPtzActive(false);
59
+ }, [screenType]);
60
+
61
+ // Console containers stay registered after closing; their presence alone is insufficient.
62
+ const consoleVisible = screenType === 'full' && !componentHideState && !refreshElement && absoluteContent.some(item => !item.hidden && (item.id === ptzControlId && ptzActive || item.id === fullTravelRouteControlId && !ptzActive));
63
+ const shown = visible && typeof onClick === 'function' && !consoleVisible;
64
+ useEffect(() => {
65
+ event.emit(bottomRightContentResize);
66
+ }, [event, shown]);
67
+ if (!shown) return null;
68
+ return /*#__PURE__*/React.createElement(View, {
69
+ className: clsx(className, {
70
+ 'ipc-player-float-window-busy': busy
71
+ }),
72
+ onClick: async () => {
73
+ if (opening.current) return;
74
+ opening.current = true;
75
+ setBusy(true);
76
+ event.emit(widgetClick, {
77
+ widgetId: 'FloatWindow'
78
+ });
79
+ try {
80
+ await onClick(devId);
81
+ } finally {
82
+ opening.current = false;
83
+ if (mounted.current) setBusy(false);
84
+ }
85
+ }
86
+ }, /*#__PURE__*/React.createElement(View, {
87
+ className: "ipc-player-float-window-icon",
88
+ style: {
89
+ WebkitMaskImage: `url("${floatWindowIcon}")`,
90
+ maskImage: `url("${floatWindowIcon}")`
91
+ }
92
+ }));
93
+ }
@@ -0,0 +1,14 @@
1
+ .ipc-player-float-window-icon {
2
+ width: calc(var(--iconPlayerSize) * var(--ipc-player-size-scale, 1));
3
+ height: calc(var(--iconPlayerSize) * var(--ipc-player-size-scale, 1));
4
+ background-color: var(--iconColor);
5
+ -webkit-mask-size: contain;
6
+ mask-size: contain;
7
+ -webkit-mask-repeat: no-repeat;
8
+ mask-repeat: no-repeat;
9
+ -webkit-mask-position: center;
10
+ mask-position: center;
11
+ }
12
+ .ipc-player-float-window-busy {
13
+ opacity: 0.5;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,164 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.for-each.js";
3
+ import React from 'react';
4
+ import ReactDOM from 'react-dom';
5
+ import { act, Simulate } from 'react-dom/test-utils';
6
+ import { atom, getDefaultStore } from 'jotai';
7
+ import { FloatWindow } from './floatWindow';
8
+ import { UIEventContext } from '../../ui/context';
9
+ import { bottomRightContentResize, fullTravelRouteControlId, ptzControlId } from '../../ui/constant';
10
+ jest.mock('@ray-js/ray', () => ({
11
+ View: 'div',
12
+ Text: 'span'
13
+ }));
14
+ describe('FloatWindow widget', () => {
15
+ let container;
16
+ let listeners;
17
+ let event;
18
+ let props;
19
+ const store = getDefaultStore();
20
+ beforeEach(() => {
21
+ container = document.createElement('div');
22
+ document.body.appendChild(container);
23
+ listeners = new Map();
24
+ event = {
25
+ on: jest.fn((name, cb) => {
26
+ if (!listeners.has(name)) listeners.set(name, new Set());
27
+ listeners.get(name).add(cb);
28
+ }),
29
+ off: jest.fn((name, cb) => {
30
+ var _listeners$get;
31
+ return (_listeners$get = listeners.get(name)) === null || _listeners$get === void 0 ? void 0 : _listeners$get.delete(cb);
32
+ }),
33
+ emit: jest.fn(name => {
34
+ var _listeners$get2;
35
+ return (_listeners$get2 = listeners.get(name)) === null || _listeners$get2 === void 0 ? void 0 : _listeners$get2.forEach(cb => cb());
36
+ })
37
+ };
38
+ props = {
39
+ devId: 'camera',
40
+ event,
41
+ screenType: atom('vertical'),
42
+ absoluteContent: atom([]),
43
+ visible: true,
44
+ onClick: jest.fn(),
45
+ className: 'bottom-right-item-container'
46
+ };
47
+ });
48
+ afterEach(() => {
49
+ act(() => {
50
+ ReactDOM.unmountComponentAtNode(container);
51
+ });
52
+ container.remove();
53
+ });
54
+ const render = function () {
55
+ let hide = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
56
+ return act(() => {
57
+ ReactDOM.render(/*#__PURE__*/React.createElement(UIEventContext.Provider, {
58
+ value: {
59
+ event,
60
+ componentHideState: hide,
61
+ refreshElement: false
62
+ }
63
+ }, /*#__PURE__*/React.createElement(FloatWindow, props)), container);
64
+ });
65
+ };
66
+ const button = () => container.querySelector('.bottom-right-item-container');
67
+ it('uses the panel visibility flag and callback; omitted flags are hidden', () => {
68
+ props.visible = undefined;
69
+ render();
70
+ expect(button()).toBeNull();
71
+ props.visible = true;
72
+ render();
73
+ expect(button()).not.toBeNull();
74
+ props.visible = false;
75
+ render();
76
+ expect(button()).toBeNull();
77
+ expect(event.emit).toHaveBeenCalledWith(bottomRightContentResize);
78
+ });
79
+ it('hides an entry without a click implementation', () => {
80
+ props.onClick = undefined;
81
+ render();
82
+ expect(button()).toBeNull();
83
+ });
84
+ it('passes the device id and prevents duplicate requests until completion', async () => {
85
+ let resolve;
86
+ props.onClick = jest.fn(() => new Promise(r => {
87
+ resolve = r;
88
+ }));
89
+ render();
90
+ act(() => {
91
+ Simulate.click(button());
92
+ Simulate.click(button());
93
+ });
94
+ expect(props.onClick).toHaveBeenCalledTimes(1);
95
+ expect(props.onClick).toHaveBeenCalledWith('camera');
96
+ await act(async () => {
97
+ resolve();
98
+ });
99
+ act(() => Simulate.click(button()));
100
+ expect(props.onClick).toHaveBeenCalledTimes(2);
101
+ await act(async () => {
102
+ resolve();
103
+ });
104
+ });
105
+ it('hides for expanded landscape PTZ and restores after close', () => {
106
+ act(() => {
107
+ store.set(props.screenType, 'full');
108
+ store.set(props.absoluteContent, [{
109
+ id: ptzControlId
110
+ }]);
111
+ });
112
+ render();
113
+ expect(button()).not.toBeNull();
114
+ act(() => event.emit('ptzControlShow'));
115
+ expect(button()).toBeNull();
116
+ act(() => event.emit('ptzControlHide'));
117
+ expect(button()).not.toBeNull();
118
+ });
119
+ it('hides for a visible landscape cruise console but not in portrait', () => {
120
+ act(() => {
121
+ store.set(props.screenType, 'full');
122
+ store.set(props.absoluteContent, [{
123
+ id: fullTravelRouteControlId
124
+ }]);
125
+ });
126
+ render();
127
+ expect(button()).toBeNull();
128
+ act(() => store.set(props.absoluteContent, [{
129
+ id: fullTravelRouteControlId,
130
+ hidden: true
131
+ }]));
132
+ expect(button()).not.toBeNull();
133
+ act(() => {
134
+ store.set(props.absoluteContent, [{
135
+ id: fullTravelRouteControlId
136
+ }]);
137
+ store.set(props.screenType, 'vertical');
138
+ });
139
+ expect(button()).not.toBeNull();
140
+ });
141
+ it('coexists with the voice intercom and ignores hidden controls', () => {
142
+ act(() => {
143
+ store.set(props.screenType, 'full');
144
+ store.set(props.absoluteContent, [{
145
+ id: 'voiceIntercom'
146
+ }]);
147
+ });
148
+ render();
149
+ expect(button()).not.toBeNull();
150
+ act(() => store.set(props.absoluteContent, [{
151
+ id: fullTravelRouteControlId
152
+ }]));
153
+ render(true);
154
+ expect(button()).not.toBeNull();
155
+ });
156
+ it('unsubscribes from console events', () => {
157
+ render();
158
+ act(() => {
159
+ ReactDOM.unmountComponentAtNode(container);
160
+ });
161
+ expect(listeners.get('ptzControlShow').size).toBe(0);
162
+ expect(listeners.get('ptzControlHide').size).toBe(0);
163
+ });
164
+ });
@@ -0,0 +1 @@
1
+ export declare const floatWindowIcon: string;
@@ -0,0 +1,4 @@
1
+ // Source: 432 panel src/res/svg.js, SvgImage.floatWindow (24 × 24).
2
+ // Preserve the 432 path as an opaque mask; the widget uses the player icon color.
3
+ const path = 'M3.5 4H20.5V10.5C20.5 10.7761 20.7239 11 21 11H22C22.2761 11 22.5 10.7761 22.5 10.5V4C22.5 2.89543 21.6046 2 20.5 2H3.5C2.39543 2 1.5 2.89543 1.5 4V20C1.5 21.1046 2.39543 22 3.5 22H10.5C10.7761 22 11 21.7761 11 21.5V20.5C11 20.2239 10.7761 20 10.5 20H3.5V4ZM20.5 20V15H15L15 20H20.5ZM22.5 15C22.5 13.8954 21.6046 13 20.5 13H15C13.8954 13 13 13.8954 13 15V20C13 21.1046 13.8954 22 15 22H20.5C21.6046 22 22.5 21.1046 22.5 20V15ZM5.64645 7.56066C5.45118 7.3654 5.45118 7.04882 5.64645 6.85355L6.35355 6.14645C6.54882 5.95118 6.8654 5.95118 7.06066 6.14645L10.2929 9.37868V8C10.2929 7.72386 10.5168 7.5 10.7929 7.5H11.7929C12.069 7.5 12.2929 7.72386 12.2929 8V12.2929C12.2929 12.569 12.069 12.7929 11.7929 12.7929H7.49992C7.22378 12.7929 6.99992 12.569 6.99992 12.2929V11.2929C6.99992 11.0167 7.22378 10.7929 7.49992 10.7929H8.87868L5.64645 7.56066Z';
4
+ export const floatWindowIcon = `data:image/svg+xml,${encodeURIComponent(`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill-rule="evenodd" clip-rule="evenodd" d="${path}" fill="#fff"/></svg>`)}`;
@@ -0,0 +1 @@
1
+ export * from './floatWindow';
@@ -0,0 +1 @@
1
+ export * from './floatWindow';
@@ -25,3 +25,4 @@ export * from './flowLowTip';
25
25
  export * from './realTimeMagnification';
26
26
  export * from './zoomTurntable';
27
27
  export * from './captureResult';
28
+ export * from './floatWindow';
@@ -24,4 +24,5 @@ export * from './toggleVerticalFull';
24
24
  export * from './flowLowTip';
25
25
  export * from './realTimeMagnification';
26
26
  export * from './zoomTurntable';
27
- export * from './captureResult';
27
+ export * from './captureResult';
28
+ export * from './floatWindow';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/ipc-player-integration",
3
- "version": "0.0.70",
3
+ "version": "0.0.72-beta.0",
4
4
  "description": "IPC 融合播放器",
5
5
  "main": "lib/index",
6
6
  "files": [