deepsea-components 5.17.35 → 5.18.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,4 +1,4 @@
1
- import { ReadSheetProps } from "./ReadSheet";
1
+ import { ReadSheet, ReadSheetProps } from "./ReadSheet";
2
2
  /**
3
3
  * @deprecated 请使用 ReadSheetProps 代替
4
4
  */
@@ -6,4 +6,4 @@ export type ReadExcelProps = ReadSheetProps;
6
6
  /**
7
7
  * @deprecated 请使用 ReadSheet 代替
8
8
  */
9
- export declare const ReadExcel: import("react").FC<ReadSheetProps>;
9
+ export declare const ReadExcel: typeof ReadSheet;
@@ -30,15 +30,14 @@ __webpack_require__.d(__webpack_exports__, {
30
30
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
31
31
  const external_deepsea_tools_namespaceObject = require("deepsea-tools");
32
32
  const external_InputFile_cjs_namespaceObject = require("./InputFile.cjs");
33
- const ReadSheet = (props)=>{
34
- const { onValueChange, ...rest } = props;
33
+ function ReadSheet({ onValueChange, ...rest }) {
35
34
  return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_InputFile_cjs_namespaceObject.InputFile, {
36
35
  accept: ".xlsx",
37
36
  type: "arrayBuffer",
38
37
  onValueChange: (data)=>null == onValueChange ? void 0 : onValueChange((0, external_deepsea_tools_namespaceObject.readSheet)(data)),
39
38
  ...rest
40
39
  });
41
- };
40
+ }
42
41
  exports.ReadSheet = __webpack_exports__.ReadSheet;
43
42
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
44
43
  "ReadSheet"
@@ -1,8 +1,7 @@
1
- import { FC } from "react";
2
1
  import { WorkBookData, WorkSheetData } from "deepsea-tools";
3
2
  import { InputFileProps } from "./InputFile";
4
- export interface ReadSheetProps extends Omit<InputFileProps<false, "arrayBuffer">, "multiple" | "accept" | "type" | "onValueChange"> {
5
- onValueChange?: <Sheet = WorkSheetData>(data: WorkBookData<Sheet>) => void;
3
+ export interface ReadSheetProps<Sheet = WorkSheetData> extends Omit<InputFileProps<false, "arrayBuffer">, "multiple" | "accept" | "type" | "onValueChange"> {
4
+ onValueChange?: (data: WorkBookData<Sheet>) => void;
6
5
  }
7
6
  /** 专门用于读取 excel 的组件 */
8
- export declare const ReadSheet: FC<ReadSheetProps>;
7
+ export declare function ReadSheet<Sheet = WorkSheetData>({ onValueChange, ...rest }: ReadSheetProps<Sheet>): import("react/jsx-runtime").JSX.Element;
@@ -2,13 +2,12 @@
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { readSheet } from "deepsea-tools";
4
4
  import { InputFile } from "./InputFile.js";
5
- const ReadSheet = (props)=>{
6
- const { onValueChange, ...rest } = props;
5
+ function ReadSheet({ onValueChange, ...rest }) {
7
6
  return /*#__PURE__*/ jsx(InputFile, {
8
7
  accept: ".xlsx",
9
8
  type: "arrayBuffer",
10
9
  onValueChange: (data)=>null == onValueChange ? void 0 : onValueChange(readSheet(data)),
11
10
  ...rest
12
11
  });
13
- };
12
+ }
14
13
  export { ReadSheet };
@@ -0,0 +1,113 @@
1
+ "use client"
2
+ "use strict";
3
+ var __webpack_require__ = {};
4
+ (()=>{
5
+ __webpack_require__.d = (exports1, definition)=>{
6
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ get: definition[key]
9
+ });
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.r = (exports1)=>{
17
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
18
+ value: 'Module'
19
+ });
20
+ Object.defineProperty(exports1, '__esModule', {
21
+ value: true
22
+ });
23
+ };
24
+ })();
25
+ var __webpack_exports__ = {};
26
+ __webpack_require__.r(__webpack_exports__);
27
+ __webpack_require__.d(__webpack_exports__, {
28
+ RtspPlayer: ()=>RtspPlayer
29
+ });
30
+ const jsx_runtime_namespaceObject = require("react/jsx-runtime");
31
+ const external_react_namespaceObject = require("react");
32
+ const reader_cjs_namespaceObject = require("./rtspPlayer/reader.cjs");
33
+ function getWhepUrl(src) {
34
+ const url = new URL(src, window.location.href);
35
+ if ("http:" !== url.protocol && "https:" !== url.protocol) throw new Error("RtspPlayer expects a MediaMTX HTTP(S) playback URL, not an RTSP URL");
36
+ const pathname = url.pathname.replace(/\/+$/, "");
37
+ url.pathname = pathname.endsWith("/whep") ? pathname : `${pathname}/whep`;
38
+ url.hash = "";
39
+ return url.toString();
40
+ }
41
+ function stopStream(stream) {
42
+ stream.getTracks().forEach((track)=>track.stop());
43
+ }
44
+ const RtspPlayer = ({ ref, src, user, pass, token, onReaderError, ...rest })=>{
45
+ const video = (0, external_react_namespaceObject.useRef)(null);
46
+ const onReaderErrorRef = (0, external_react_namespaceObject.useRef)(onReaderError);
47
+ (0, external_react_namespaceObject.useImperativeHandle)(ref, ()=>video.current, []);
48
+ (0, external_react_namespaceObject.useEffect)(()=>{
49
+ onReaderErrorRef.current = onReaderError;
50
+ }, [
51
+ onReaderError
52
+ ]);
53
+ (0, external_react_namespaceObject.useEffect)(()=>{
54
+ const { current: player } = video;
55
+ if (!player || !src) return;
56
+ if ("undefined" == typeof RTCPeerConnection || "undefined" == typeof MediaStream) {
57
+ var _onReaderErrorRef_current;
58
+ null == (_onReaderErrorRef_current = onReaderErrorRef.current) || _onReaderErrorRef_current.call(onReaderErrorRef, "RtspPlayer requires WebRTC support in the current browser");
59
+ return;
60
+ }
61
+ let whepUrl;
62
+ try {
63
+ whepUrl = getWhepUrl(src);
64
+ } catch (error) {
65
+ var _onReaderErrorRef_current1;
66
+ null == (_onReaderErrorRef_current1 = onReaderErrorRef.current) || _onReaderErrorRef_current1.call(onReaderErrorRef, error instanceof Error ? error.message : String(error));
67
+ return;
68
+ }
69
+ let closed = false;
70
+ const fallbackStream = new MediaStream();
71
+ const reader = new reader_cjs_namespaceObject.MediaMTXWebRTCReader({
72
+ url: whepUrl,
73
+ user,
74
+ pass,
75
+ token,
76
+ onError: (error)=>{
77
+ var _onReaderErrorRef_current;
78
+ return null == (_onReaderErrorRef_current = onReaderErrorRef.current) ? void 0 : _onReaderErrorRef_current.call(onReaderErrorRef, error);
79
+ },
80
+ onTrack: (evt)=>{
81
+ if (closed) return;
82
+ const stream = evt.streams[0] ?? fallbackStream;
83
+ if (0 === evt.streams.length && !fallbackStream.getTracks().includes(evt.track)) fallbackStream.addTrack(evt.track);
84
+ if (player.srcObject !== stream) player.srcObject = stream;
85
+ }
86
+ });
87
+ return ()=>{
88
+ closed = true;
89
+ reader.close();
90
+ const { srcObject } = player;
91
+ if (srcObject instanceof MediaStream) stopStream(srcObject);
92
+ if (srcObject !== fallbackStream) stopStream(fallbackStream);
93
+ player.srcObject = null;
94
+ player.load();
95
+ };
96
+ }, [
97
+ src,
98
+ user,
99
+ pass,
100
+ token
101
+ ]);
102
+ return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("video", {
103
+ ref: video,
104
+ ...rest
105
+ });
106
+ };
107
+ exports.RtspPlayer = __webpack_exports__.RtspPlayer;
108
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
109
+ "RtspPlayer"
110
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
111
+ Object.defineProperty(exports, '__esModule', {
112
+ value: true
113
+ });
@@ -0,0 +1,9 @@
1
+ import { ComponentProps, FC } from "react";
2
+ export interface RtspPlayerProps extends Omit<ComponentProps<"video">, "src" | "children"> {
3
+ src: string;
4
+ user?: string;
5
+ pass?: string;
6
+ token?: string;
7
+ onReaderError?: (error: string) => void;
8
+ }
9
+ export declare const RtspPlayer: FC<RtspPlayerProps>;
@@ -0,0 +1,79 @@
1
+ "use client"
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { useEffect, useImperativeHandle, useRef } from "react";
4
+ import { MediaMTXWebRTCReader } from "./rtspPlayer/reader.js";
5
+ function getWhepUrl(src) {
6
+ const url = new URL(src, window.location.href);
7
+ if ("http:" !== url.protocol && "https:" !== url.protocol) throw new Error("RtspPlayer expects a MediaMTX HTTP(S) playback URL, not an RTSP URL");
8
+ const pathname = url.pathname.replace(/\/+$/, "");
9
+ url.pathname = pathname.endsWith("/whep") ? pathname : `${pathname}/whep`;
10
+ url.hash = "";
11
+ return url.toString();
12
+ }
13
+ function stopStream(stream) {
14
+ stream.getTracks().forEach((track)=>track.stop());
15
+ }
16
+ const RtspPlayer = ({ ref, src, user, pass, token, onReaderError, ...rest })=>{
17
+ const video = useRef(null);
18
+ const onReaderErrorRef = useRef(onReaderError);
19
+ useImperativeHandle(ref, ()=>video.current, []);
20
+ useEffect(()=>{
21
+ onReaderErrorRef.current = onReaderError;
22
+ }, [
23
+ onReaderError
24
+ ]);
25
+ useEffect(()=>{
26
+ const { current: player } = video;
27
+ if (!player || !src) return;
28
+ if ("undefined" == typeof RTCPeerConnection || "undefined" == typeof MediaStream) {
29
+ var _onReaderErrorRef_current;
30
+ null == (_onReaderErrorRef_current = onReaderErrorRef.current) || _onReaderErrorRef_current.call(onReaderErrorRef, "RtspPlayer requires WebRTC support in the current browser");
31
+ return;
32
+ }
33
+ let whepUrl;
34
+ try {
35
+ whepUrl = getWhepUrl(src);
36
+ } catch (error) {
37
+ var _onReaderErrorRef_current1;
38
+ null == (_onReaderErrorRef_current1 = onReaderErrorRef.current) || _onReaderErrorRef_current1.call(onReaderErrorRef, error instanceof Error ? error.message : String(error));
39
+ return;
40
+ }
41
+ let closed = false;
42
+ const fallbackStream = new MediaStream();
43
+ const reader = new MediaMTXWebRTCReader({
44
+ url: whepUrl,
45
+ user,
46
+ pass,
47
+ token,
48
+ onError: (error)=>{
49
+ var _onReaderErrorRef_current;
50
+ return null == (_onReaderErrorRef_current = onReaderErrorRef.current) ? void 0 : _onReaderErrorRef_current.call(onReaderErrorRef, error);
51
+ },
52
+ onTrack: (evt)=>{
53
+ if (closed) return;
54
+ const stream = evt.streams[0] ?? fallbackStream;
55
+ if (0 === evt.streams.length && !fallbackStream.getTracks().includes(evt.track)) fallbackStream.addTrack(evt.track);
56
+ if (player.srcObject !== stream) player.srcObject = stream;
57
+ }
58
+ });
59
+ return ()=>{
60
+ closed = true;
61
+ reader.close();
62
+ const { srcObject } = player;
63
+ if (srcObject instanceof MediaStream) stopStream(srcObject);
64
+ if (srcObject !== fallbackStream) stopStream(fallbackStream);
65
+ player.srcObject = null;
66
+ player.load();
67
+ };
68
+ }, [
69
+ src,
70
+ user,
71
+ pass,
72
+ token
73
+ ]);
74
+ return /*#__PURE__*/ jsx("video", {
75
+ ref: video,
76
+ ...rest
77
+ });
78
+ };
79
+ export { RtspPlayer };