@bendyline/squisq-editor-react 2.2.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,132 @@
1
+ // src/recorder/formats.ts
2
+ var AUDIO_CANDIDATES = [
3
+ "audio/webm;codecs=opus",
4
+ "audio/webm",
5
+ "audio/mp4;codecs=mp4a.40.2",
6
+ "audio/mp4",
7
+ "audio/ogg;codecs=opus"
8
+ ];
9
+ var VIDEO_CANDIDATES = [
10
+ "video/webm;codecs=vp9,opus",
11
+ "video/webm;codecs=vp8,opus",
12
+ "video/webm",
13
+ "video/mp4;codecs=avc1.42E01E,mp4a.40.2",
14
+ "video/mp4"
15
+ ];
16
+ function extensionForMime(mimeType) {
17
+ const m = mimeType.toLowerCase();
18
+ if (m.startsWith("audio/webm")) return ".webm";
19
+ if (m.startsWith("audio/ogg")) return ".ogg";
20
+ if (m.startsWith("audio/mp4")) return ".m4a";
21
+ if (m.startsWith("audio/mpeg")) return ".mp3";
22
+ if (m.startsWith("audio/wav")) return ".wav";
23
+ if (m.startsWith("video/webm")) return ".webm";
24
+ if (m.startsWith("video/mp4")) return ".mp4";
25
+ return ".bin";
26
+ }
27
+ function probeMimeType(candidates) {
28
+ if (typeof MediaRecorder === "undefined") return null;
29
+ for (const candidate of candidates) {
30
+ try {
31
+ if (MediaRecorder.isTypeSupported(candidate)) return candidate;
32
+ } catch {
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+ function resolveFormat(kind, preferred) {
38
+ const candidates = kind === "audio" ? AUDIO_CANDIDATES : VIDEO_CANDIDATES;
39
+ const probed = (preferred && probeMimeType([preferred])) ?? probeMimeType(candidates) ?? "";
40
+ const directory = kind === "audio" ? "audio" : "video";
41
+ const extension = probed ? extensionForMime(probed) : ".webm";
42
+ return { mimeType: probed, extension, directory };
43
+ }
44
+ function supportsMediaRecorder() {
45
+ return typeof MediaRecorder !== "undefined";
46
+ }
47
+ function supportsUserMedia() {
48
+ return typeof navigator !== "undefined" && typeof navigator.mediaDevices !== "undefined" && typeof navigator.mediaDevices.getUserMedia === "function";
49
+ }
50
+ function supportsDisplayMedia() {
51
+ return typeof navigator !== "undefined" && typeof navigator.mediaDevices !== "undefined" && typeof navigator.mediaDevices.getDisplayMedia === "function";
52
+ }
53
+ function buildFilename(kind, extension, basename) {
54
+ const safe = basename ? basename.trim().replace(/[\\/:*?"<>|]+/g, "-").replace(/\s+/g, "-") : "";
55
+ if (safe) return `${safe}${extension}`;
56
+ const now = /* @__PURE__ */ new Date();
57
+ const stamp = now.getFullYear().toString().padStart(4, "0") + (now.getMonth() + 1).toString().padStart(2, "0") + now.getDate().toString().padStart(2, "0") + "-" + now.getHours().toString().padStart(2, "0") + now.getMinutes().toString().padStart(2, "0") + now.getSeconds().toString().padStart(2, "0");
58
+ const prefix = kind === "audio" ? "narration" : "recording";
59
+ return `${prefix}-${stamp}${extension}`;
60
+ }
61
+
62
+ // src/recorder/sources/micStream.ts
63
+ async function requestMicStream(constraints) {
64
+ if (!supportsUserMedia()) {
65
+ throw new Error("navigator.mediaDevices.getUserMedia is not available in this environment.");
66
+ }
67
+ return navigator.mediaDevices.getUserMedia({
68
+ audio: constraints ?? true,
69
+ video: false
70
+ });
71
+ }
72
+
73
+ // src/recorder/sources/cameraStream.ts
74
+ async function requestCameraStream(options) {
75
+ if (!supportsUserMedia()) {
76
+ throw new Error("navigator.mediaDevices.getUserMedia is not available in this environment.");
77
+ }
78
+ const video = options?.video ?? true;
79
+ const audio = options?.audio ?? true;
80
+ return navigator.mediaDevices.getUserMedia({ video, audio });
81
+ }
82
+
83
+ // src/recorder/hooks/useStreamPreview.ts
84
+ import { useEffect } from "react";
85
+ function useStreamPreview(ref, stream) {
86
+ useEffect(() => {
87
+ const el = ref.current;
88
+ if (!el) return;
89
+ el.muted = true;
90
+ el.playsInline = true;
91
+ el.srcObject = stream;
92
+ if (stream) {
93
+ void el.play().catch(() => {
94
+ });
95
+ }
96
+ return () => {
97
+ if (el.srcObject === stream) {
98
+ el.srcObject = null;
99
+ }
100
+ };
101
+ }, [ref, stream]);
102
+ }
103
+
104
+ // src/recorder/timingJson.ts
105
+ function buildTimingJson(sourceText, durationSec) {
106
+ return {
107
+ sourceText: sourceText ?? "",
108
+ duration: Number.isFinite(durationSec) && durationSec >= 0 ? durationSec : 0,
109
+ bookmarks: []
110
+ };
111
+ }
112
+ function encodeTimingJson(timing) {
113
+ const text = JSON.stringify(timing, null, 2);
114
+ return new TextEncoder().encode(text);
115
+ }
116
+ function timingPathFor(audioRelativePath) {
117
+ return `${audioRelativePath}.timing.json`;
118
+ }
119
+
120
+ export {
121
+ resolveFormat,
122
+ supportsMediaRecorder,
123
+ supportsUserMedia,
124
+ supportsDisplayMedia,
125
+ buildFilename,
126
+ requestMicStream,
127
+ requestCameraStream,
128
+ useStreamPreview,
129
+ buildTimingJson,
130
+ encodeTimingJson,
131
+ timingPathFor
132
+ };
@@ -0,0 +1,49 @@
1
+ import {
2
+ RecorderModal
3
+ } from "./chunk-MJJK7YQB.js";
4
+
5
+ // src/recorder/RecorderButton.tsx
6
+ import { useCallback, useState } from "react";
7
+ import { createPortal } from "react-dom";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ function RecorderButton({
10
+ mediaProvider,
11
+ container = null,
12
+ initialMode = "mic",
13
+ colorScheme = "light",
14
+ onSave,
15
+ label = "Record",
16
+ style,
17
+ disabled
18
+ }) {
19
+ const [open, setOpen] = useState(false);
20
+ const handleOpen = useCallback(() => setOpen(true), []);
21
+ const handleClose = useCallback(() => setOpen(false), []);
22
+ const handleSave = useCallback(
23
+ (result) => {
24
+ onSave?.(result);
25
+ },
26
+ [onSave]
27
+ );
28
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
29
+ /* @__PURE__ */ jsx("button", { type: "button", onClick: handleOpen, style, disabled, children: label }),
30
+ open && typeof document !== "undefined" && createPortal(
31
+ /* @__PURE__ */ jsx(
32
+ RecorderModal,
33
+ {
34
+ mediaProvider,
35
+ container,
36
+ initialMode,
37
+ colorScheme,
38
+ onClose: handleClose,
39
+ onSave: handleSave
40
+ }
41
+ ),
42
+ document.body
43
+ )
44
+ ] });
45
+ }
46
+
47
+ export {
48
+ RecorderButton
49
+ };
@@ -0,0 +1,9 @@
1
+ // src/Icon.tsx
2
+ import { jsx } from "react/jsx-runtime";
3
+ function Icon({ icon, className, style }) {
4
+ return /* @__PURE__ */ jsx("i", { className: className ? `${icon} ${className}` : icon, style, "aria-hidden": "true" });
5
+ }
6
+
7
+ export {
8
+ Icon
9
+ };