@dxos/plugin-transcription 0.8.4-main.69d29f4 → 0.8.4-main.6fa680abb7

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 (161) hide show
  1. package/dist/lib/browser/TranscriptionContainer-5MFETUHZ.mjs +40 -0
  2. package/dist/lib/browser/TranscriptionContainer-5MFETUHZ.mjs.map +7 -0
  3. package/dist/lib/browser/blueprint-definition-ICUHRZXS.mjs +18 -0
  4. package/dist/lib/browser/blueprint-definition-ICUHRZXS.mjs.map +7 -0
  5. package/dist/lib/browser/blueprints/index.mjs +3 -3
  6. package/dist/lib/browser/{chunk-Q5OC3WVG.mjs → chunk-7D57BEI2.mjs} +8 -26
  7. package/dist/lib/browser/chunk-7D57BEI2.mjs.map +7 -0
  8. package/dist/lib/browser/{chunk-ZZF7ICVM.mjs → chunk-DCPLHPHH.mjs} +24 -26
  9. package/dist/lib/browser/chunk-DCPLHPHH.mjs.map +7 -0
  10. package/dist/lib/browser/chunk-KYI5GIQM.mjs +22 -0
  11. package/dist/lib/browser/chunk-KYI5GIQM.mjs.map +7 -0
  12. package/dist/lib/browser/{chunk-TKFU53OZ.mjs → chunk-QWIUIEWX.mjs} +2 -2
  13. package/dist/lib/browser/{chunk-ICM7JRCO.mjs → chunk-SLZXQVQU.mjs} +361 -391
  14. package/dist/lib/browser/chunk-SLZXQVQU.mjs.map +7 -0
  15. package/dist/lib/browser/index.mjs +24 -27
  16. package/dist/lib/browser/index.mjs.map +3 -3
  17. package/dist/lib/browser/meta.json +1 -1
  18. package/dist/lib/browser/{operation-resolver-ZUWTU7C5.mjs → operation-resolver-PFR5PQTK.mjs} +5 -4
  19. package/dist/lib/browser/operation-resolver-PFR5PQTK.mjs.map +7 -0
  20. package/dist/lib/browser/react-surface-MISGR3BD.mjs +37 -0
  21. package/dist/lib/browser/react-surface-MISGR3BD.mjs.map +7 -0
  22. package/dist/lib/browser/{transcriber-EZZTUCPE.mjs → transcriber-GKFU347S.mjs} +7 -6
  23. package/dist/lib/browser/transcriber-GKFU347S.mjs.map +7 -0
  24. package/dist/lib/browser/types/index.mjs +2 -1
  25. package/dist/lib/node-esm/TranscriptionContainer-3ZP67PX6.mjs +41 -0
  26. package/dist/lib/node-esm/TranscriptionContainer-3ZP67PX6.mjs.map +7 -0
  27. package/dist/lib/node-esm/{blueprint-definition-IOX35YUX.mjs → blueprint-definition-KYLTO7UH.mjs} +6 -6
  28. package/dist/lib/node-esm/blueprint-definition-KYLTO7UH.mjs.map +7 -0
  29. package/dist/lib/node-esm/blueprints/index.mjs +3 -3
  30. package/dist/lib/node-esm/chunk-5XJY5QP5.mjs +24 -0
  31. package/dist/lib/node-esm/chunk-5XJY5QP5.mjs.map +7 -0
  32. package/dist/lib/node-esm/{chunk-4BFY6P2D.mjs → chunk-6BWAFL5Z.mjs} +8 -26
  33. package/dist/lib/node-esm/chunk-6BWAFL5Z.mjs.map +7 -0
  34. package/dist/lib/node-esm/{chunk-EPC27WWV.mjs → chunk-LSWGXNVP.mjs} +2 -2
  35. package/dist/lib/node-esm/{chunk-CWP22IHV.mjs → chunk-TRS6GDYW.mjs} +24 -26
  36. package/dist/lib/node-esm/chunk-TRS6GDYW.mjs.map +7 -0
  37. package/dist/lib/node-esm/{chunk-BX2AB7S7.mjs → chunk-WVSA6JHE.mjs} +361 -391
  38. package/dist/lib/node-esm/chunk-WVSA6JHE.mjs.map +7 -0
  39. package/dist/lib/node-esm/index.mjs +24 -27
  40. package/dist/lib/node-esm/index.mjs.map +3 -3
  41. package/dist/lib/node-esm/meta.json +1 -1
  42. package/dist/lib/node-esm/{operation-resolver-Z72B4H2Q.mjs → operation-resolver-IZ7BRISJ.mjs} +5 -4
  43. package/dist/lib/node-esm/operation-resolver-IZ7BRISJ.mjs.map +7 -0
  44. package/dist/lib/node-esm/react-surface-BCAKAGCT.mjs +38 -0
  45. package/dist/lib/node-esm/react-surface-BCAKAGCT.mjs.map +7 -0
  46. package/dist/lib/node-esm/{transcriber-RGW3YYT4.mjs → transcriber-7BSCYWMV.mjs} +7 -6
  47. package/dist/lib/node-esm/transcriber-7BSCYWMV.mjs.map +7 -0
  48. package/dist/lib/node-esm/types/index.mjs +2 -1
  49. package/dist/types/src/TranscriptionPlugin.d.ts.map +1 -1
  50. package/dist/types/src/blueprints/index.d.ts +1 -1
  51. package/dist/types/src/blueprints/index.d.ts.map +1 -1
  52. package/dist/types/src/blueprints/transcription-blueprint.d.ts +3 -20
  53. package/dist/types/src/blueprints/transcription-blueprint.d.ts.map +1 -1
  54. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts +3 -6
  55. package/dist/types/src/capabilities/blueprint-definition/blueprint-definition.d.ts.map +1 -1
  56. package/dist/types/src/capabilities/blueprint-definition/index.d.ts +1 -1
  57. package/dist/types/src/capabilities/blueprint-definition/index.d.ts.map +1 -1
  58. package/dist/types/src/capabilities/operation-handler/index.d.ts +1 -1
  59. package/dist/types/src/capabilities/operation-handler/index.d.ts.map +1 -1
  60. package/dist/types/src/capabilities/operation-handler/operation-handler.d.ts +2 -2
  61. package/dist/types/src/capabilities/operation-handler/operation-handler.d.ts.map +1 -1
  62. package/dist/types/src/capabilities/operation-resolver/index.d.ts +1 -1
  63. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -1
  64. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +2 -2
  65. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -1
  66. package/dist/types/src/capabilities/react-surface/index.d.ts +1 -1
  67. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -1
  68. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +2 -2
  69. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -1
  70. package/dist/types/src/capabilities/transcriber/transcriber.d.ts +1 -1
  71. package/dist/types/src/capabilities/transcriber/transcriber.d.ts.map +1 -1
  72. package/dist/types/src/components/{Transcript/Transcript.d.ts → Transcription/Transcription.d.ts} +3 -3
  73. package/dist/types/src/components/Transcription/Transcription.d.ts.map +1 -0
  74. package/dist/types/src/components/{Transcript/Transcript.stories.d.ts → Transcription/Transcription.stories.d.ts} +3 -3
  75. package/dist/types/src/components/Transcription/Transcription.stories.d.ts.map +1 -0
  76. package/dist/types/src/components/Transcription/index.d.ts +2 -0
  77. package/dist/types/src/components/Transcription/index.d.ts.map +1 -0
  78. package/dist/types/src/components/{Transcript/transcript-extension.d.ts → Transcription/transcription-extension.d.ts} +3 -3
  79. package/dist/types/src/components/Transcription/transcription-extension.d.ts.map +1 -0
  80. package/dist/types/src/components/index.d.ts +1 -3
  81. package/dist/types/src/components/index.d.ts.map +1 -1
  82. package/dist/types/src/{components/TranscriptContainer.d.ts → containers/TranscriptionContainer/TranscriptionContainer.d.ts} +3 -4
  83. package/dist/types/src/containers/TranscriptionContainer/TranscriptionContainer.d.ts.map +1 -0
  84. package/dist/types/src/containers/TranscriptionContainer/index.d.ts +3 -0
  85. package/dist/types/src/containers/TranscriptionContainer/index.d.ts.map +1 -0
  86. package/dist/types/src/containers/index.d.ts +3 -0
  87. package/dist/types/src/containers/index.d.ts.map +1 -0
  88. package/dist/types/src/functions/index.d.ts +17 -2
  89. package/dist/types/src/functions/index.d.ts.map +1 -1
  90. package/dist/types/src/functions/open.d.ts +5 -1
  91. package/dist/types/src/functions/open.d.ts.map +1 -1
  92. package/dist/types/src/segments-normalization/normalization.d.ts +19 -6
  93. package/dist/types/src/segments-normalization/normalization.d.ts.map +1 -1
  94. package/dist/types/src/types/TranscriptAction.d.ts +1 -1
  95. package/dist/types/tsconfig.tsbuildinfo +1 -1
  96. package/package.json +65 -64
  97. package/src/TranscriptionPlugin.tsx +9 -8
  98. package/src/blueprints/index.ts +1 -1
  99. package/src/blueprints/transcription-blueprint.ts +14 -6
  100. package/src/capabilities/blueprint-definition/blueprint-definition.ts +6 -12
  101. package/src/capabilities/operation-handler/operation-handler.ts +2 -2
  102. package/src/capabilities/operation-resolver/operation-resolver.ts +2 -2
  103. package/src/capabilities/react-surface/react-surface.tsx +11 -8
  104. package/src/capabilities/transcriber/transcriber.ts +3 -3
  105. package/src/components/{Transcript/Transcript.stories.tsx → Transcription/Transcription.stories.tsx} +8 -8
  106. package/src/components/{Transcript/Transcript.tsx → Transcription/Transcription.tsx} +5 -8
  107. package/src/components/{Transcript → Transcription}/index.ts +1 -1
  108. package/src/components/{Transcript/transcript-extension.ts → Transcription/transcription-extension.ts} +4 -4
  109. package/src/components/index.ts +1 -6
  110. package/src/components/stories/FileTranscription.stories.tsx +4 -4
  111. package/src/components/stories/KeyWordRecognition.stories.tsx +4 -4
  112. package/src/components/stories/MicrophoneTranscription.stories.tsx +4 -4
  113. package/src/components/stories/TranscriptionStory.tsx +3 -3
  114. package/src/{components/TranscriptContainer.tsx → containers/TranscriptionContainer/TranscriptionContainer.tsx} +11 -13
  115. package/src/containers/TranscriptionContainer/index.ts +7 -0
  116. package/src/containers/index.ts +7 -0
  117. package/src/functions/index.ts +7 -2
  118. package/src/functions/open.ts +6 -8
  119. package/src/functions/summarize.ts +1 -1
  120. package/src/hooks/useTranscriber.ts +1 -1
  121. package/src/meta.ts +1 -1
  122. package/src/segments-normalization/normalization.test.ts +1 -1
  123. package/src/testing/testing.ts +1 -1
  124. package/src/types/TranscriptAction.ts +2 -2
  125. package/src/types/capabilities.ts +2 -2
  126. package/dist/lib/browser/TranscriptContainer-6EHKWVS4.mjs +0 -12
  127. package/dist/lib/browser/TranscriptContainer-6EHKWVS4.mjs.map +0 -7
  128. package/dist/lib/browser/blueprint-definition-FTRNMLJZ.mjs +0 -18
  129. package/dist/lib/browser/blueprint-definition-FTRNMLJZ.mjs.map +0 -7
  130. package/dist/lib/browser/chunk-ICM7JRCO.mjs.map +0 -7
  131. package/dist/lib/browser/chunk-Q5OC3WVG.mjs.map +0 -7
  132. package/dist/lib/browser/chunk-SYGEFDWO.mjs +0 -8
  133. package/dist/lib/browser/chunk-SYGEFDWO.mjs.map +0 -7
  134. package/dist/lib/browser/chunk-ZZF7ICVM.mjs.map +0 -7
  135. package/dist/lib/browser/operation-resolver-ZUWTU7C5.mjs.map +0 -7
  136. package/dist/lib/browser/react-surface-ZXH5267I.mjs +0 -34
  137. package/dist/lib/browser/react-surface-ZXH5267I.mjs.map +0 -7
  138. package/dist/lib/browser/transcriber-EZZTUCPE.mjs.map +0 -7
  139. package/dist/lib/node-esm/TranscriptContainer-5YT5W73I.mjs +0 -13
  140. package/dist/lib/node-esm/TranscriptContainer-5YT5W73I.mjs.map +0 -7
  141. package/dist/lib/node-esm/blueprint-definition-IOX35YUX.mjs.map +0 -7
  142. package/dist/lib/node-esm/chunk-4BFY6P2D.mjs.map +0 -7
  143. package/dist/lib/node-esm/chunk-BX2AB7S7.mjs.map +0 -7
  144. package/dist/lib/node-esm/chunk-CWP22IHV.mjs.map +0 -7
  145. package/dist/lib/node-esm/chunk-GVAVEVZ6.mjs +0 -10
  146. package/dist/lib/node-esm/chunk-GVAVEVZ6.mjs.map +0 -7
  147. package/dist/lib/node-esm/operation-resolver-Z72B4H2Q.mjs.map +0 -7
  148. package/dist/lib/node-esm/react-surface-6GUBZX2V.mjs +0 -35
  149. package/dist/lib/node-esm/react-surface-6GUBZX2V.mjs.map +0 -7
  150. package/dist/lib/node-esm/transcriber-RGW3YYT4.mjs.map +0 -7
  151. package/dist/types/src/components/Transcript/Transcript.d.ts.map +0 -1
  152. package/dist/types/src/components/Transcript/Transcript.stories.d.ts.map +0 -1
  153. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts +0 -28
  154. package/dist/types/src/components/Transcript/deprecated/OldTranscript.d.ts.map +0 -1
  155. package/dist/types/src/components/Transcript/index.d.ts +0 -2
  156. package/dist/types/src/components/Transcript/index.d.ts.map +0 -1
  157. package/dist/types/src/components/Transcript/transcript-extension.d.ts.map +0 -1
  158. package/dist/types/src/components/TranscriptContainer.d.ts.map +0 -1
  159. package/src/components/Transcript/deprecated/OldTranscript.tsx +0 -260
  160. /package/dist/lib/browser/{chunk-TKFU53OZ.mjs.map → chunk-QWIUIEWX.mjs.map} +0 -0
  161. /package/dist/lib/node-esm/{chunk-EPC27WWV.mjs.map → chunk-LSWGXNVP.mjs.map} +0 -0
@@ -1,143 +1,29 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- import {
3
- renderByline
4
- } from "./chunk-NVM2QUMX.mjs";
5
2
  import {
6
3
  TranscriptionCapabilities
7
- } from "./chunk-4BFY6P2D.mjs";
8
-
9
- // src/components/TranscriptContainer.tsx
10
- import React2 from "react";
11
- import { Obj } from "@dxos/echo";
12
- import { useMembers, useQueue } from "@dxos/react-client/echo";
13
- import { Layout } from "@dxos/react-ui-mosaic";
14
-
15
- // src/hooks/useAudioFile.ts
16
- import { useEffect, useState } from "react";
17
- import { scheduleTask } from "@dxos/async";
18
- import { Context } from "@dxos/context";
19
- import { log } from "@dxos/log";
20
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useAudioFile.ts";
21
- var useAudioFile = (audioUrl, constraints) => {
22
- const [{ audio, stream, track }, setStream] = useState({});
23
- useEffect(() => {
24
- const ctx = new Context(void 0, {
25
- F: __dxlog_file,
26
- L: 20
27
- });
28
- scheduleTask(ctx, async () => {
29
- try {
30
- const response = await fetch(audioUrl);
31
- const blob = await response.blob();
32
- const objectUrl = URL.createObjectURL(blob);
33
- ctx.onDispose(() => {
34
- URL.revokeObjectURL(objectUrl);
35
- });
36
- const audio2 = new Audio();
37
- audio2.src = objectUrl;
38
- await new Promise((resolve, reject) => {
39
- audio2.addEventListener("error", (err) => {
40
- log.error("error", {
41
- err
42
- }, {
43
- F: __dxlog_file,
44
- L: 39,
45
- S: void 0,
46
- C: (f, a) => f(...a)
47
- });
48
- reject(err);
49
- }, {
50
- once: true
51
- });
52
- audio2.addEventListener("canplay", async () => {
53
- resolve();
54
- }, {
55
- once: true
56
- });
57
- audio2.load();
58
- });
59
- const audioCtx = new AudioContext();
60
- if (audioCtx.state === "suspended") {
61
- await audioCtx.resume();
62
- }
63
- const destination = audioCtx.createMediaStreamDestination();
64
- destination.channelCount = 1;
65
- const source = audioCtx.createMediaElementSource(audio2);
66
- source.connect(destination);
67
- const track2 = destination.stream.getAudioTracks()[0];
68
- if (constraints) {
69
- await track2.applyConstraints(constraints).catch((err) => log.catch(err, void 0, {
70
- F: __dxlog_file,
71
- L: 68,
72
- S: void 0,
73
- C: (f, a) => f(...a)
74
- }));
75
- }
76
- setStream({
77
- audio: audio2,
78
- stream: destination.stream,
79
- track: destination.stream.getAudioTracks()[0]
80
- });
81
- } catch (err) {
82
- log.catch(err, void 0, {
83
- F: __dxlog_file,
84
- L: 78,
85
- S: void 0,
86
- C: (f, a) => f(...a)
87
- });
88
- }
89
- });
90
- return () => {
91
- void ctx.dispose();
92
- };
93
- }, [
94
- audioUrl
95
- ]);
96
- return {
97
- audio,
98
- stream,
99
- track
100
- };
101
- };
4
+ } from "./chunk-6BWAFL5Z.mjs";
102
5
 
103
- // src/hooks/useAudioTrack.ts
104
- import { useEffect as useEffect2, useState as useState2 } from "react";
105
- var useAudioTrack = (active, constraints) => {
106
- const [track, setTrack] = useState2();
107
- useEffect2(() => {
108
- if (!active) {
109
- track?.stop();
110
- setTrack(void 0);
111
- return;
112
- }
113
- const initAudio = async () => {
114
- const audio = new Audio();
115
- audio.srcObject = await navigator.mediaDevices.getUserMedia({
116
- audio: constraints ?? true
117
- });
118
- const [track2] = audio.srcObject.getAudioTracks();
119
- if (track2) {
120
- setTrack(track2);
121
- }
122
- };
123
- if (active) {
124
- void initAudio();
125
- }
126
- }, [
127
- active
128
- ]);
129
- return track;
130
- };
6
+ // src/components/Transcription/Transcription.tsx
7
+ import React from "react";
8
+ import { useThemeContext } from "@dxos/react-ui";
9
+ import { useTextEditor } from "@dxos/react-ui-editor";
10
+ import { autoScroll, createBasicExtensions, createMarkdownExtensions, createThemeExtensions, decorateMarkdown, editorSlots, preview } from "@dxos/ui-editor";
11
+ import { mx } from "@dxos/ui-theme";
12
+ import { isTruthy } from "@dxos/util";
131
13
 
132
- // src/hooks/useQueueModelAdapter.ts
133
- import { useEffect as useEffect3, useMemo, useState as useState3 } from "react";
14
+ // src/components/Transcription/transcription-extension.ts
15
+ import { RangeSetBuilder } from "@codemirror/state";
16
+ import { EditorView, GutterMarker, ViewPlugin, gutter } from "@codemirror/view";
17
+ import { format } from "date-fns/format";
18
+ import { intervalToDuration } from "date-fns/intervalToDuration";
19
+ import { addEventListener, combine } from "@dxos/async";
134
20
 
135
21
  // src/model/model.ts
136
22
  import { Text } from "@codemirror/state";
137
23
  import { Event } from "@dxos/async";
138
24
  import { invariant } from "@dxos/invariant";
139
- import { log as log2 } from "@dxos/log";
140
- var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/model/model.ts";
25
+ import { log } from "@dxos/log";
26
+ var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/model/model.ts";
141
27
  var DocumentAdapter = class {
142
28
  _view;
143
29
  constructor(_view) {
@@ -148,13 +34,13 @@ var DocumentAdapter = class {
148
34
  return this._view.state.doc.lines - 1;
149
35
  }
150
36
  replaceLines(from, remove, insert) {
151
- log2("replaceLines", {
37
+ log("replaceLines", {
152
38
  count: this._view.state.doc.lines,
153
39
  from,
154
40
  remove,
155
41
  insert
156
42
  }, {
157
- F: __dxlog_file2,
43
+ F: __dxlog_file,
158
44
  L: 39,
159
45
  S: this,
160
46
  C: (f, a) => f(...a)
@@ -235,7 +121,7 @@ var SerializationModel = class {
235
121
  updateChunk(chunk) {
236
122
  const index = this._chunks.findIndex((c) => c.id === chunk.id);
237
123
  invariant(index !== -1, void 0, {
238
- F: __dxlog_file2,
124
+ F: __dxlog_file,
239
125
  L: 147,
240
126
  S: this,
241
127
  A: [
@@ -255,7 +141,7 @@ var SerializationModel = class {
255
141
  deleteBlock(id) {
256
142
  const index = this._chunks.findIndex((c) => c.id === id);
257
143
  invariant(index !== -1, void 0, {
258
- F: __dxlog_file2,
144
+ F: __dxlog_file,
259
145
  L: 156,
260
146
  S: this,
261
147
  A: [
@@ -276,10 +162,10 @@ var SerializationModel = class {
276
162
  * Syncs the tracked changes with the ChunkDocument.
277
163
  */
278
164
  sync(document2) {
279
- log2("sync", {
165
+ log("sync", {
280
166
  changes: this._changes
281
167
  }, {
282
- F: __dxlog_file2,
168
+ F: __dxlog_file,
283
169
  L: 167,
284
170
  S: this,
285
171
  C: (f, a) => f(...a)
@@ -332,235 +218,80 @@ var SerializationModel = class {
332
218
  }
333
219
  };
334
220
 
335
- // src/hooks/useQueueModelAdapter.ts
336
- var useQueueModelAdapter = (renderer, queue, initialChunks = []) => {
337
- const model = useMemo(() => new SerializationModel(renderer, initialChunks), [
338
- queue
339
- ]);
340
- const [loaded, setLoaded] = useState3(false);
341
- useEffect3(() => {
342
- if (!queue) {
343
- return;
344
- }
345
- const update = () => {
346
- for (const block of queue?.objects ?? []) {
347
- model.appendChunk(block);
221
+ // src/components/Transcription/transcription-extension.ts
222
+ var transcription = ({ model, started }) => {
223
+ return [
224
+ // Show timestamps in the gutter.
225
+ gutter({
226
+ class: "cm-timestamp-gutter",
227
+ lineMarkerChange: (update) => update.docChanged || update.viewportChanged,
228
+ markers: (view) => {
229
+ const start = getStartTime(started, model.chunks[0]);
230
+ const builder = new RangeSetBuilder();
231
+ for (const { from, to } of view.visibleRanges) {
232
+ let line = view.state.doc.lineAt(from);
233
+ while (line.from <= to) {
234
+ const block = model.getChunkAtLine(line.number)?.blocks[0];
235
+ const timestamp = block?._tag === "transcript" && block.started;
236
+ if (timestamp) {
237
+ builder.add(line.from, line.from, new TimestampMarker(line.number, new Date(timestamp), start));
238
+ }
239
+ if (line.to + 1 > view.state.doc.length) {
240
+ break;
241
+ }
242
+ line = view.state.doc.lineAt(line.to + 1);
243
+ }
244
+ }
245
+ return builder.finish();
348
246
  }
349
- setLoaded(true);
350
- };
351
- let i;
352
- if (queue.isLoading) {
353
- i = setInterval(() => {
354
- if (!queue?.isLoading) {
355
- clearInterval(i);
356
- update();
357
- }
358
- }, 1e3);
359
- } else {
360
- update();
361
- }
362
- return () => clearTimeout(i);
363
- }, [
364
- model,
365
- queue
366
- ]);
367
- useEffect3(() => {
368
- if (!loaded || !queue || model.chunks.length === queue.objects.length) {
369
- return;
370
- }
371
- const chunk = queue.objects.at(-1);
372
- if (chunk) {
373
- model.appendChunk(chunk);
374
- }
375
- }, [
376
- model,
377
- loaded,
378
- queue?.objects.length
379
- ]);
380
- return model;
381
- };
382
-
383
- // src/hooks/useTranscriber.ts
384
- import { useEffect as useEffect4, useMemo as useMemo2 } from "react";
385
- import { useCapabilities } from "@dxos/app-framework/react";
386
- var useTranscriber = ({ audioStreamTrack, recorderConfig, transcriberConfig, onSegments }) => {
387
- const [getTranscriber] = useCapabilities(TranscriptionCapabilities.Transcriber);
388
- const transcriber = useMemo2(() => {
389
- if (!getTranscriber || !audioStreamTrack || !onSegments) {
390
- return void 0;
391
- }
392
- return getTranscriber({
393
- audioStreamTrack,
394
- recorderConfig,
395
- transcriberConfig,
396
- onSegments
397
- });
398
- }, [
399
- getTranscriber,
400
- audioStreamTrack,
401
- recorderConfig,
402
- transcriberConfig,
403
- onSegments
404
- ]);
405
- useEffect4(() => {
406
- return () => {
407
- void transcriber?.close();
408
- };
409
- }, [
410
- transcriber
411
- ]);
412
- return transcriber;
413
- };
414
-
415
- // src/hooks/useVoiceInput.ts
416
- import { useCallback, useEffect as useEffect5, useState as useState4 } from "react";
417
- import { scheduleMicroTask } from "@dxos/async";
418
- import { Context as Context2 } from "@dxos/context";
419
- import { log as log3 } from "@dxos/log";
420
- import { useSoundEffect } from "@dxos/react-ui-sfx";
421
- var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useVoiceInput.ts";
422
- var useVoiceInput = ({ active, onUpdate }) => {
423
- const soundStart = useSoundEffect("StartRecording");
424
- const soundStop = useSoundEffect("StopRecording");
425
- const handleSegments = useCallback(async (segments) => {
426
- const text = segments.map((str) => str.text.trim().replace(/[^\w\s]/g, "")).join(" ");
427
- onUpdate(text);
428
- }, []);
429
- const [recording, setRecording] = useState4(false);
430
- const track = useAudioTrack(active);
431
- const transcriber = useTranscriber({
432
- audioStreamTrack: track,
433
- onSegments: handleSegments
434
- });
435
- useEffect5(() => {
436
- const ctx = new Context2(void 0, {
437
- F: __dxlog_file3,
438
- L: 44
439
- });
440
- scheduleMicroTask(ctx, async () => {
441
- if (active && transcriber) {
442
- await transcriber.open();
443
- log3.info("starting...", void 0, {
444
- F: __dxlog_file3,
445
- L: 48,
446
- S: void 0,
447
- C: (f, a) => f(...a)
448
- });
449
- setRecording(true);
450
- void soundStart.play();
451
- transcriber.startChunksRecording();
452
- } else if (!active && transcriber?.isOpen) {
453
- transcriber?.stopChunksRecording();
454
- await transcriber?.close();
455
- log3.info("stopped", void 0, {
456
- F: __dxlog_file3,
457
- L: 55,
458
- S: void 0,
459
- C: (f, a) => f(...a)
460
- });
461
- setRecording(false);
462
- void soundStop.play();
463
- }
464
- });
465
- return () => {
466
- void ctx.dispose();
467
- };
468
- }, [
469
- active,
470
- transcriber
471
- ]);
472
- return {
473
- recording
474
- };
475
- };
476
-
477
- // src/components/Transcript/Transcript.tsx
478
- import React from "react";
479
- import { useThemeContext } from "@dxos/react-ui";
480
- import { useTextEditor } from "@dxos/react-ui-editor";
481
- import { autoScroll, createBasicExtensions, createMarkdownExtensions, createThemeExtensions, decorateMarkdown, editorSlots, preview } from "@dxos/ui-editor";
482
- import { mx } from "@dxos/ui-theme";
483
- import { isTruthy } from "@dxos/util";
484
-
485
- // src/components/Transcript/transcript-extension.ts
486
- import { RangeSetBuilder } from "@codemirror/state";
487
- import { EditorView, GutterMarker, ViewPlugin, gutter } from "@codemirror/view";
488
- import { format } from "date-fns/format";
489
- import { intervalToDuration } from "date-fns/intervalToDuration";
490
- import { addEventListener, combine } from "@dxos/async";
491
- var transcript = ({ model, started }) => {
492
- return [
493
- // Show timestamps in the gutter.
494
- gutter({
495
- class: "cm-timestamp-gutter",
496
- lineMarkerChange: (update) => update.docChanged || update.viewportChanged,
497
- markers: (view) => {
498
- const start = getStartTime(started, model.chunks[0]);
499
- const builder = new RangeSetBuilder();
500
- for (const { from, to } of view.visibleRanges) {
501
- let line = view.state.doc.lineAt(from);
502
- while (line.from <= to) {
503
- const block = model.getChunkAtLine(line.number)?.blocks[0];
504
- const timestamp = block?._tag === "transcript" && block.started;
505
- if (timestamp) {
506
- builder.add(line.from, line.from, new TimestampMarker(line.number, new Date(timestamp), start));
507
- }
508
- if (line.to + 1 > view.state.doc.length) {
509
- break;
510
- }
511
- line = view.state.doc.lineAt(line.to + 1);
512
- }
513
- }
514
- return builder.finish();
515
- }
516
- }),
517
- // Listen for model updates.
518
- ViewPlugin.fromClass(class {
519
- _controls;
520
- _cleanup;
521
- _adapter;
522
- _initialized = false;
523
- constructor(view) {
524
- this._adapter = new DocumentAdapter(view);
525
- const scroller = view.scrollDOM;
526
- let isAutoScrolling = false;
527
- let hasScrolled = false;
528
- let timeout;
529
- const scrollToBottom = (smooth = false) => {
530
- scroller.style.scrollBehavior = smooth ? "smooth" : "";
531
- scroller.classList.add("cm-hide-scrollbar");
532
- isAutoScrolling = true;
533
- clearTimeout(timeout);
534
- timeout = setTimeout(() => {
535
- this._controls?.classList.add("opacity-0");
536
- scroller.classList.remove("cm-hide-scrollbar");
537
- isAutoScrolling = false;
538
- }, 500);
539
- view.dispatch({
540
- effects: EditorView.scrollIntoView(view.state.doc.length, {
541
- y: "end"
542
- })
543
- });
544
- };
545
- this._cleanup = combine(addEventListener(view.scrollDOM, "scroll", () => {
546
- if (!isAutoScrolling) {
547
- hasScrolled = true;
548
- this._controls?.classList.remove("opacity-0");
549
- }
550
- }), model.update.on(() => {
551
- const autoScroll2 = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight === 0 || !hasScrolled;
552
- model.sync(this._adapter);
553
- if (autoScroll2) {
554
- scrollToBottom(true);
555
- }
556
- }));
557
- }
558
- update(_update) {
559
- if (!this._initialized) {
560
- this._initialized = true;
561
- setTimeout(() => {
562
- model.sync(this._adapter);
563
- });
247
+ }),
248
+ // Listen for model updates.
249
+ ViewPlugin.fromClass(class {
250
+ _controls;
251
+ _cleanup;
252
+ _adapter;
253
+ _initialized = false;
254
+ constructor(view) {
255
+ this._adapter = new DocumentAdapter(view);
256
+ const scroller = view.scrollDOM;
257
+ let isAutoScrolling = false;
258
+ let hasScrolled = false;
259
+ let timeout;
260
+ const scrollToBottom = (smooth = false) => {
261
+ scroller.style.scrollBehavior = smooth ? "smooth" : "";
262
+ scroller.classList.add("cm-hide-scrollbar");
263
+ isAutoScrolling = true;
264
+ clearTimeout(timeout);
265
+ timeout = setTimeout(() => {
266
+ this._controls?.classList.add("opacity-0");
267
+ scroller.classList.remove("cm-hide-scrollbar");
268
+ isAutoScrolling = false;
269
+ }, 500);
270
+ view.dispatch({
271
+ effects: EditorView.scrollIntoView(view.state.doc.length, {
272
+ y: "end"
273
+ })
274
+ });
275
+ };
276
+ this._cleanup = combine(addEventListener(view.scrollDOM, "scroll", () => {
277
+ if (!isAutoScrolling) {
278
+ hasScrolled = true;
279
+ this._controls?.classList.remove("opacity-0");
280
+ }
281
+ }), model.update.on(() => {
282
+ const autoScroll2 = scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight === 0 || !hasScrolled;
283
+ model.sync(this._adapter);
284
+ if (autoScroll2) {
285
+ scrollToBottom(true);
286
+ }
287
+ }));
288
+ }
289
+ update(_update) {
290
+ if (!this._initialized) {
291
+ this._initialized = true;
292
+ setTimeout(() => {
293
+ model.sync(this._adapter);
294
+ });
564
295
  }
565
296
  }
566
297
  destroy() {
@@ -570,7 +301,7 @@ var transcript = ({ model, started }) => {
570
301
  }),
571
302
  EditorView.theme({
572
303
  ".cm-gutters": {
573
- backgroundColor: "var(--dx-baseSurface)"
304
+ backgroundColor: "var(--color-base-surface)"
574
305
  },
575
306
  ".cm-timestamp-gutter": {
576
307
  width: "6rem",
@@ -597,7 +328,7 @@ var TimestampMarker = class extends GutterMarker {
597
328
  }
598
329
  toDOM(view) {
599
330
  const el = document.createElement("div");
600
- el.className = "text-sm text-subdued hover:bg-hoverSurface cursor-pointer";
331
+ el.className = "text-sm text-subdued hover:bg-hover-surface cursor-pointer";
601
332
  el.textContent = formatTimestamp(this._timestamp, this._started);
602
333
  el.onclick = () => {
603
334
  const pos = view.state.doc.line(this._line).from;
@@ -632,8 +363,8 @@ var formatTimestamp = (timestamp, relative) => {
632
363
  }
633
364
  };
634
365
 
635
- // src/components/Transcript/Transcript.tsx
636
- var TranscriptView = ({ classNames, transcript: object, model }) => {
366
+ // src/components/Transcription/Transcription.tsx
367
+ var Transcription = ({ classNames, transcript: object, model }) => {
637
368
  const { themeMode } = useThemeContext();
638
369
  const { parentRef } = useTextEditor(() => {
639
370
  return {
@@ -650,7 +381,7 @@ var TranscriptView = ({ classNames, transcript: object, model }) => {
650
381
  }),
651
382
  decorateMarkdown(),
652
383
  preview(),
653
- transcript({
384
+ transcription({
654
385
  model,
655
386
  started: object?.started ? new Date(object.started) : void 0
656
387
  }),
@@ -662,38 +393,277 @@ var TranscriptView = ({ classNames, transcript: object, model }) => {
662
393
  ]);
663
394
  return /* @__PURE__ */ React.createElement("div", {
664
395
  ref: parentRef,
665
- className: mx("flex grow overflow-hidden container-max-width", classNames),
396
+ className: mx("dx-container", classNames),
666
397
  "data-popover-collision-boundary": true
667
398
  });
668
399
  };
669
400
 
670
- // src/components/TranscriptContainer.tsx
671
- var TranscriptionContainer = ({ role, subject: transcript2 }) => {
672
- const attendableId = Obj.getDXN(transcript2).toString();
673
- const db = Obj.getDatabase(transcript2);
674
- const members = useMembers(db?.spaceId).map((member) => member.identity);
675
- const queue = useQueue(transcript2.queue.dxn, {
676
- pollInterval: 1e3
677
- });
678
- const model = useQueueModelAdapter(renderByline(members), queue);
679
- return /* @__PURE__ */ React2.createElement(Layout.Main, {
680
- role
681
- }, /* @__PURE__ */ React2.createElement(TranscriptView, {
682
- attendableId,
401
+ // src/hooks/useAudioFile.ts
402
+ import { useEffect, useState } from "react";
403
+ import { scheduleTask } from "@dxos/async";
404
+ import { Context } from "@dxos/context";
405
+ import { log as log2 } from "@dxos/log";
406
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useAudioFile.ts";
407
+ var useAudioFile = (audioUrl, constraints) => {
408
+ const [{ audio, stream, track }, setStream] = useState({});
409
+ useEffect(() => {
410
+ const ctx = new Context(void 0, {
411
+ F: __dxlog_file2,
412
+ L: 20
413
+ });
414
+ scheduleTask(ctx, async () => {
415
+ try {
416
+ const response = await fetch(audioUrl);
417
+ const blob = await response.blob();
418
+ const objectUrl = URL.createObjectURL(blob);
419
+ ctx.onDispose(() => {
420
+ URL.revokeObjectURL(objectUrl);
421
+ });
422
+ const audio2 = new Audio();
423
+ audio2.src = objectUrl;
424
+ await new Promise((resolve, reject) => {
425
+ audio2.addEventListener("error", (err) => {
426
+ log2.error("error", {
427
+ err
428
+ }, {
429
+ F: __dxlog_file2,
430
+ L: 39,
431
+ S: void 0,
432
+ C: (f, a) => f(...a)
433
+ });
434
+ reject(err);
435
+ }, {
436
+ once: true
437
+ });
438
+ audio2.addEventListener("canplay", async () => {
439
+ resolve();
440
+ }, {
441
+ once: true
442
+ });
443
+ audio2.load();
444
+ });
445
+ const audioCtx = new AudioContext();
446
+ if (audioCtx.state === "suspended") {
447
+ await audioCtx.resume();
448
+ }
449
+ const destination = audioCtx.createMediaStreamDestination();
450
+ destination.channelCount = 1;
451
+ const source = audioCtx.createMediaElementSource(audio2);
452
+ source.connect(destination);
453
+ const track2 = destination.stream.getAudioTracks()[0];
454
+ if (constraints) {
455
+ await track2.applyConstraints(constraints).catch((err) => log2.catch(err, void 0, {
456
+ F: __dxlog_file2,
457
+ L: 68,
458
+ S: void 0,
459
+ C: (f, a) => f(...a)
460
+ }));
461
+ }
462
+ setStream({
463
+ audio: audio2,
464
+ stream: destination.stream,
465
+ track: destination.stream.getAudioTracks()[0]
466
+ });
467
+ } catch (err) {
468
+ log2.catch(err, void 0, {
469
+ F: __dxlog_file2,
470
+ L: 78,
471
+ S: void 0,
472
+ C: (f, a) => f(...a)
473
+ });
474
+ }
475
+ });
476
+ return () => {
477
+ void ctx.dispose();
478
+ };
479
+ }, [
480
+ audioUrl
481
+ ]);
482
+ return {
483
+ audio,
484
+ stream,
485
+ track
486
+ };
487
+ };
488
+
489
+ // src/hooks/useAudioTrack.ts
490
+ import { useEffect as useEffect2, useState as useState2 } from "react";
491
+ var useAudioTrack = (active, constraints) => {
492
+ const [track, setTrack] = useState2();
493
+ useEffect2(() => {
494
+ if (!active) {
495
+ track?.stop();
496
+ setTrack(void 0);
497
+ return;
498
+ }
499
+ const initAudio = async () => {
500
+ const audio = new Audio();
501
+ audio.srcObject = await navigator.mediaDevices.getUserMedia({
502
+ audio: constraints ?? true
503
+ });
504
+ const [track2] = audio.srcObject.getAudioTracks();
505
+ if (track2) {
506
+ setTrack(track2);
507
+ }
508
+ };
509
+ if (active) {
510
+ void initAudio();
511
+ }
512
+ }, [
513
+ active
514
+ ]);
515
+ return track;
516
+ };
517
+
518
+ // src/hooks/useQueueModelAdapter.ts
519
+ import { useEffect as useEffect3, useMemo, useState as useState3 } from "react";
520
+ var useQueueModelAdapter = (renderer, queue, initialChunks = []) => {
521
+ const model = useMemo(() => new SerializationModel(renderer, initialChunks), [
522
+ queue
523
+ ]);
524
+ const [loaded, setLoaded] = useState3(false);
525
+ useEffect3(() => {
526
+ if (!queue) {
527
+ return;
528
+ }
529
+ const update = () => {
530
+ for (const block of queue?.objects ?? []) {
531
+ model.appendChunk(block);
532
+ }
533
+ setLoaded(true);
534
+ };
535
+ let i;
536
+ if (queue.isLoading) {
537
+ i = setInterval(() => {
538
+ if (!queue?.isLoading) {
539
+ clearInterval(i);
540
+ update();
541
+ }
542
+ }, 1e3);
543
+ } else {
544
+ update();
545
+ }
546
+ return () => clearTimeout(i);
547
+ }, [
683
548
  model,
684
- transcript: transcript2
685
- }));
549
+ queue
550
+ ]);
551
+ useEffect3(() => {
552
+ if (!loaded || !queue || model.chunks.length === queue.objects.length) {
553
+ return;
554
+ }
555
+ const chunk = queue.objects.at(-1);
556
+ if (chunk) {
557
+ model.appendChunk(chunk);
558
+ }
559
+ }, [
560
+ model,
561
+ loaded,
562
+ queue?.objects.length
563
+ ]);
564
+ return model;
565
+ };
566
+
567
+ // src/hooks/useTranscriber.ts
568
+ import { useEffect as useEffect4, useMemo as useMemo2 } from "react";
569
+ import { useCapabilities } from "@dxos/app-framework/ui";
570
+ var useTranscriber = ({ audioStreamTrack, recorderConfig, transcriberConfig, onSegments }) => {
571
+ const [getTranscriber] = useCapabilities(TranscriptionCapabilities.Transcriber);
572
+ const transcriber = useMemo2(() => {
573
+ if (!getTranscriber || !audioStreamTrack || !onSegments) {
574
+ return void 0;
575
+ }
576
+ return getTranscriber({
577
+ audioStreamTrack,
578
+ recorderConfig,
579
+ transcriberConfig,
580
+ onSegments
581
+ });
582
+ }, [
583
+ getTranscriber,
584
+ audioStreamTrack,
585
+ recorderConfig,
586
+ transcriberConfig,
587
+ onSegments
588
+ ]);
589
+ useEffect4(() => {
590
+ return () => {
591
+ void transcriber?.close();
592
+ };
593
+ }, [
594
+ transcriber
595
+ ]);
596
+ return transcriber;
597
+ };
598
+
599
+ // src/hooks/useVoiceInput.ts
600
+ import { useCallback, useEffect as useEffect5, useState as useState4 } from "react";
601
+ import { scheduleMicroTask } from "@dxos/async";
602
+ import { Context as Context2 } from "@dxos/context";
603
+ import { log as log3 } from "@dxos/log";
604
+ import { useSoundEffect } from "@dxos/react-ui-sfx";
605
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/plugins/plugin-transcription/src/hooks/useVoiceInput.ts";
606
+ var useVoiceInput = ({ active, onUpdate }) => {
607
+ const soundStart = useSoundEffect("StartRecording");
608
+ const soundStop = useSoundEffect("StopRecording");
609
+ const handleSegments = useCallback(async (segments) => {
610
+ const text = segments.map((str) => str.text.trim().replace(/[^\w\s]/g, "")).join(" ");
611
+ onUpdate(text);
612
+ }, []);
613
+ const [recording, setRecording] = useState4(false);
614
+ const track = useAudioTrack(active);
615
+ const transcriber = useTranscriber({
616
+ audioStreamTrack: track,
617
+ onSegments: handleSegments
618
+ });
619
+ useEffect5(() => {
620
+ const ctx = new Context2(void 0, {
621
+ F: __dxlog_file3,
622
+ L: 44
623
+ });
624
+ scheduleMicroTask(ctx, async () => {
625
+ if (active && transcriber) {
626
+ await transcriber.open();
627
+ log3.info("starting...", void 0, {
628
+ F: __dxlog_file3,
629
+ L: 48,
630
+ S: void 0,
631
+ C: (f, a) => f(...a)
632
+ });
633
+ setRecording(true);
634
+ void soundStart.play();
635
+ transcriber.startChunksRecording();
636
+ } else if (!active && transcriber?.isOpen) {
637
+ transcriber?.stopChunksRecording();
638
+ await transcriber?.close();
639
+ log3.info("stopped", void 0, {
640
+ F: __dxlog_file3,
641
+ L: 55,
642
+ S: void 0,
643
+ C: (f, a) => f(...a)
644
+ });
645
+ setRecording(false);
646
+ void soundStop.play();
647
+ }
648
+ });
649
+ return () => {
650
+ void ctx.dispose();
651
+ };
652
+ }, [
653
+ active,
654
+ transcriber
655
+ ]);
656
+ return {
657
+ recording
658
+ };
686
659
  };
687
- var TranscriptContainer_default = TranscriptionContainer;
688
660
 
689
661
  export {
690
- TranscriptView,
662
+ Transcription,
691
663
  useAudioFile,
692
664
  useAudioTrack,
693
665
  useQueueModelAdapter,
694
666
  useTranscriber,
695
- useVoiceInput,
696
- TranscriptionContainer,
697
- TranscriptContainer_default
667
+ useVoiceInput
698
668
  };
699
- //# sourceMappingURL=chunk-BX2AB7S7.mjs.map
669
+ //# sourceMappingURL=chunk-WVSA6JHE.mjs.map