react-native-ai-animations 0.0.0-stage → 0.8.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.
- package/LICENSE +21 -0
- package/README.md +226 -2
- package/lib/module/brand/index.js +4 -0
- package/lib/module/brand/index.js.map +1 -0
- package/lib/module/brand/spinning-mark.js +96 -0
- package/lib/module/brand/spinning-mark.js.map +1 -0
- package/lib/module/chat/effort-bar.js +853 -0
- package/lib/module/chat/effort-bar.js.map +1 -0
- package/lib/module/chat/index.js +8 -0
- package/lib/module/chat/index.js.map +1 -0
- package/lib/module/chat/question-card.js +720 -0
- package/lib/module/chat/question-card.js.map +1 -0
- package/lib/module/chat/reasoning.js +38 -0
- package/lib/module/chat/reasoning.js.map +1 -0
- package/lib/module/chat/status-row.js +140 -0
- package/lib/module/chat/status-row.js.map +1 -0
- package/lib/module/chat/thinking-block.js +255 -0
- package/lib/module/chat/thinking-block.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/internal/color.js +15 -0
- package/lib/module/internal/color.js.map +1 -0
- package/lib/module/internal/use-elapsed.js +20 -0
- package/lib/module/internal/use-elapsed.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/skia/dot-orb.js +256 -0
- package/lib/module/skia/dot-orb.js.map +1 -0
- package/lib/module/skia/index.js +8 -0
- package/lib/module/skia/index.js.map +1 -0
- package/lib/module/skia/liquid-orb.js +303 -0
- package/lib/module/skia/liquid-orb.js.map +1 -0
- package/lib/module/skia/matrix-orb.js +272 -0
- package/lib/module/skia/matrix-orb.js.map +1 -0
- package/lib/module/skia/media-generating.js +524 -0
- package/lib/module/skia/media-generating.js.map +1 -0
- package/lib/module/skia/voice-wave.js +278 -0
- package/lib/module/skia/voice-wave.js.map +1 -0
- package/lib/module/text/index.js +6 -0
- package/lib/module/text/index.js.map +1 -0
- package/lib/module/text/shimmer-text.js +122 -0
- package/lib/module/text/shimmer-text.js.map +1 -0
- package/lib/module/text/spoken-text.js +85 -0
- package/lib/module/text/spoken-text.js.map +1 -0
- package/lib/module/text/streaming-text.js +135 -0
- package/lib/module/text/streaming-text.js.map +1 -0
- package/lib/module/theme/index.js +5 -0
- package/lib/module/theme/index.js.map +1 -0
- package/lib/module/theme/palette.js +45 -0
- package/lib/module/theme/palette.js.map +1 -0
- package/lib/module/theme/provider.js +65 -0
- package/lib/module/theme/provider.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/brand/index.d.ts +2 -0
- package/lib/typescript/src/brand/index.d.ts.map +1 -0
- package/lib/typescript/src/brand/spinning-mark.d.ts +21 -0
- package/lib/typescript/src/brand/spinning-mark.d.ts.map +1 -0
- package/lib/typescript/src/chat/effort-bar.d.ts +42 -0
- package/lib/typescript/src/chat/effort-bar.d.ts.map +1 -0
- package/lib/typescript/src/chat/index.d.ts +6 -0
- package/lib/typescript/src/chat/index.d.ts.map +1 -0
- package/lib/typescript/src/chat/question-card.d.ts +73 -0
- package/lib/typescript/src/chat/question-card.d.ts.map +1 -0
- package/lib/typescript/src/chat/reasoning.d.ts +20 -0
- package/lib/typescript/src/chat/reasoning.d.ts.map +1 -0
- package/lib/typescript/src/chat/status-row.d.ts +20 -0
- package/lib/typescript/src/chat/status-row.d.ts.map +1 -0
- package/lib/typescript/src/chat/thinking-block.d.ts +35 -0
- package/lib/typescript/src/chat/thinking-block.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +3 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/internal/color.d.ts +2 -0
- package/lib/typescript/src/internal/color.d.ts.map +1 -0
- package/lib/typescript/src/internal/use-elapsed.d.ts +3 -0
- package/lib/typescript/src/internal/use-elapsed.d.ts.map +1 -0
- package/lib/typescript/src/skia/dot-orb.d.ts +16 -0
- package/lib/typescript/src/skia/dot-orb.d.ts.map +1 -0
- package/lib/typescript/src/skia/index.d.ts +6 -0
- package/lib/typescript/src/skia/index.d.ts.map +1 -0
- package/lib/typescript/src/skia/liquid-orb.d.ts +20 -0
- package/lib/typescript/src/skia/liquid-orb.d.ts.map +1 -0
- package/lib/typescript/src/skia/matrix-orb.d.ts +12 -0
- package/lib/typescript/src/skia/matrix-orb.d.ts.map +1 -0
- package/lib/typescript/src/skia/media-generating.d.ts +59 -0
- package/lib/typescript/src/skia/media-generating.d.ts.map +1 -0
- package/lib/typescript/src/skia/voice-wave.d.ts +17 -0
- package/lib/typescript/src/skia/voice-wave.d.ts.map +1 -0
- package/lib/typescript/src/text/index.d.ts +4 -0
- package/lib/typescript/src/text/index.d.ts.map +1 -0
- package/lib/typescript/src/text/shimmer-text.d.ts +13 -0
- package/lib/typescript/src/text/shimmer-text.d.ts.map +1 -0
- package/lib/typescript/src/text/spoken-text.d.ts +15 -0
- package/lib/typescript/src/text/spoken-text.d.ts.map +1 -0
- package/lib/typescript/src/text/streaming-text.d.ts +16 -0
- package/lib/typescript/src/text/streaming-text.d.ts.map +1 -0
- package/lib/typescript/src/theme/index.d.ts +3 -0
- package/lib/typescript/src/theme/index.d.ts.map +1 -0
- package/lib/typescript/src/theme/palette.d.ts +33 -0
- package/lib/typescript/src/theme/palette.d.ts.map +1 -0
- package/lib/typescript/src/theme/provider.d.ts +13 -0
- package/lib/typescript/src/theme/provider.d.ts.map +1 -0
- package/package.json +133 -4
- package/src/brand/index.ts +5 -0
- package/src/brand/spinning-mark.tsx +118 -0
- package/src/chat/effort-bar.tsx +748 -0
- package/src/chat/index.ts +45 -0
- package/src/chat/question-card.tsx +649 -0
- package/src/chat/reasoning.ts +30 -0
- package/src/chat/status-row.tsx +127 -0
- package/src/chat/thinking-block.tsx +250 -0
- package/src/index.ts +2 -0
- package/src/internal/color.ts +18 -0
- package/src/internal/use-elapsed.ts +21 -0
- package/src/skia/dot-orb.tsx +248 -0
- package/src/skia/index.ts +34 -0
- package/src/skia/liquid-orb.tsx +274 -0
- package/src/skia/matrix-orb.tsx +337 -0
- package/src/skia/media-generating.tsx +389 -0
- package/src/skia/voice-wave.tsx +215 -0
- package/src/text/index.ts +3 -0
- package/src/text/shimmer-text.tsx +140 -0
- package/src/text/spoken-text.tsx +82 -0
- package/src/text/streaming-text.tsx +144 -0
- package/src/theme/index.ts +11 -0
- package/src/theme/palette.ts +62 -0
- package/src/theme/provider.tsx +54 -0
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { Canvas, LinearGradient, Path, Skia, useClock, vec } from "@shopify/react-native-skia";
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { View } from "react-native";
|
|
6
|
+
import { useDerivedValue, useFrameCallback, useReducedMotion, useSharedValue } from "react-native-reanimated";
|
|
7
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
const DEFAULT_HEIGHT = 32;
|
|
9
|
+
const SAMPLE_STEP = 2;
|
|
10
|
+
const MIN_AMPLITUDE = 1.5;
|
|
11
|
+
const EDGE_PADDING = 2;
|
|
12
|
+
const HISTORY = 96;
|
|
13
|
+
const PUSH_MS = 70;
|
|
14
|
+
const LAYERS = [{
|
|
15
|
+
frequency: 1.1,
|
|
16
|
+
speed: 0.0024,
|
|
17
|
+
phase: 2.6,
|
|
18
|
+
amplitude: 0.55,
|
|
19
|
+
strokeWidth: 1.5,
|
|
20
|
+
opacity: 0.45
|
|
21
|
+
}, {
|
|
22
|
+
frequency: 2.3,
|
|
23
|
+
speed: -0.0031,
|
|
24
|
+
phase: 1.4,
|
|
25
|
+
amplitude: 0.75,
|
|
26
|
+
strokeWidth: 1.5,
|
|
27
|
+
opacity: 0.6
|
|
28
|
+
}, {
|
|
29
|
+
frequency: 1.6,
|
|
30
|
+
speed: 0.0042,
|
|
31
|
+
phase: 0,
|
|
32
|
+
amplitude: 1,
|
|
33
|
+
strokeWidth: 2,
|
|
34
|
+
opacity: 1
|
|
35
|
+
}];
|
|
36
|
+
function WaveLayerPath({
|
|
37
|
+
layer,
|
|
38
|
+
width,
|
|
39
|
+
height,
|
|
40
|
+
level,
|
|
41
|
+
clock,
|
|
42
|
+
color
|
|
43
|
+
}) {
|
|
44
|
+
const path = useDerivedValue(() => {
|
|
45
|
+
const middle = height / 2;
|
|
46
|
+
const reach = middle - EDGE_PADDING;
|
|
47
|
+
const amplitude = (MIN_AMPLITUDE + level.value * (reach - MIN_AMPLITUDE)) * layer.amplitude;
|
|
48
|
+
const offset = clock.value * layer.speed + layer.phase;
|
|
49
|
+
const next = Skia.Path.Make();
|
|
50
|
+
for (let x = 0; x <= width; x += SAMPLE_STEP) {
|
|
51
|
+
const progress = x / width;
|
|
52
|
+
const envelope = Math.sin(Math.PI * progress);
|
|
53
|
+
const y = middle + amplitude * envelope * Math.sin(2 * Math.PI * layer.frequency * progress + offset);
|
|
54
|
+
if (x === 0) next.moveTo(x, y);else next.lineTo(x, y);
|
|
55
|
+
}
|
|
56
|
+
return next;
|
|
57
|
+
});
|
|
58
|
+
return /*#__PURE__*/_jsx(Path, {
|
|
59
|
+
path: path,
|
|
60
|
+
style: "stroke",
|
|
61
|
+
strokeWidth: layer.strokeWidth,
|
|
62
|
+
strokeCap: "round",
|
|
63
|
+
strokeJoin: "round",
|
|
64
|
+
color: color,
|
|
65
|
+
opacity: layer.opacity
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function Lines({
|
|
69
|
+
width,
|
|
70
|
+
height,
|
|
71
|
+
level,
|
|
72
|
+
clock,
|
|
73
|
+
colors
|
|
74
|
+
}) {
|
|
75
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
76
|
+
children: LAYERS.map((layer, index) => /*#__PURE__*/_jsx(WaveLayerPath, {
|
|
77
|
+
layer: layer,
|
|
78
|
+
width: width,
|
|
79
|
+
height: height,
|
|
80
|
+
level: level,
|
|
81
|
+
clock: clock,
|
|
82
|
+
color: colors[index]
|
|
83
|
+
}, index))
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function Bars({
|
|
87
|
+
width,
|
|
88
|
+
height,
|
|
89
|
+
level,
|
|
90
|
+
colors,
|
|
91
|
+
still
|
|
92
|
+
}) {
|
|
93
|
+
const history = useSharedValue(new Array(HISTORY).fill(0));
|
|
94
|
+
const last = useSharedValue(0);
|
|
95
|
+
const smooth = useSharedValue(0);
|
|
96
|
+
useFrameCallback(info => {
|
|
97
|
+
smooth.value += (level.value - smooth.value) * 0.35;
|
|
98
|
+
if (info.timestamp - last.value < PUSH_MS) return;
|
|
99
|
+
last.value = info.timestamp;
|
|
100
|
+
const next = history.value.slice(1);
|
|
101
|
+
next.push(smooth.value);
|
|
102
|
+
history.value = next;
|
|
103
|
+
}, !still);
|
|
104
|
+
const path = useDerivedValue(() => {
|
|
105
|
+
const bar = 3;
|
|
106
|
+
const gap = 3;
|
|
107
|
+
const count = Math.min(HISTORY, Math.floor((width + gap) / (bar + gap)));
|
|
108
|
+
const middle = height / 2;
|
|
109
|
+
const samples = still ? new Array(HISTORY).fill(level.value) : history.value;
|
|
110
|
+
const next = Skia.Path.Make();
|
|
111
|
+
for (let index = 0; index < count; index += 1) {
|
|
112
|
+
const sample = samples[HISTORY - count + index] ?? 0;
|
|
113
|
+
const h = Math.max(bar, sample * (height - 4));
|
|
114
|
+
const x = width - (count - index) * (bar + gap) + gap;
|
|
115
|
+
next.addRRect(Skia.RRectXY(Skia.XYWHRect(x, middle - h / 2, bar, h), bar / 2, bar / 2));
|
|
116
|
+
}
|
|
117
|
+
return next;
|
|
118
|
+
});
|
|
119
|
+
return /*#__PURE__*/_jsx(Path, {
|
|
120
|
+
path: path,
|
|
121
|
+
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
122
|
+
start: vec(0, 0),
|
|
123
|
+
end: vec(width, 0),
|
|
124
|
+
colors: [colors[0], colors[1], colors[2]]
|
|
125
|
+
})
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function Dots({
|
|
129
|
+
width,
|
|
130
|
+
height,
|
|
131
|
+
level,
|
|
132
|
+
clock,
|
|
133
|
+
colors
|
|
134
|
+
}) {
|
|
135
|
+
const path = useDerivedValue(() => {
|
|
136
|
+
const spacing = 11;
|
|
137
|
+
const count = Math.max(3, Math.floor(width / spacing));
|
|
138
|
+
const start = (width - (count - 1) * spacing) / 2;
|
|
139
|
+
const middle = height / 2;
|
|
140
|
+
const reach = middle - 4;
|
|
141
|
+
const t = clock.value * 0.006;
|
|
142
|
+
const next = Skia.Path.Make();
|
|
143
|
+
for (let index = 0; index < count; index += 1) {
|
|
144
|
+
const progress = index / (count - 1);
|
|
145
|
+
const envelope = Math.sin(Math.PI * progress);
|
|
146
|
+
const wave = Math.sin(t + index * 0.55) * Math.sin(t * 0.43 + index * 0.21);
|
|
147
|
+
const y = middle + wave * reach * envelope * (0.15 + level.value * 0.85);
|
|
148
|
+
const r = 1.6 + Math.abs(wave) * level.value * 1.8 * envelope;
|
|
149
|
+
next.addCircle(start + index * spacing, y, r);
|
|
150
|
+
}
|
|
151
|
+
return next;
|
|
152
|
+
});
|
|
153
|
+
return /*#__PURE__*/_jsx(Path, {
|
|
154
|
+
path: path,
|
|
155
|
+
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
156
|
+
start: vec(0, 0),
|
|
157
|
+
end: vec(width, 0),
|
|
158
|
+
colors: [colors[0], colors[1], colors[2]]
|
|
159
|
+
})
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function Pulse({
|
|
163
|
+
width,
|
|
164
|
+
height,
|
|
165
|
+
level,
|
|
166
|
+
clock,
|
|
167
|
+
colors
|
|
168
|
+
}) {
|
|
169
|
+
const path = useDerivedValue(() => {
|
|
170
|
+
const middle = height / 2;
|
|
171
|
+
const reach = middle - 3;
|
|
172
|
+
const t = clock.value * 0.004;
|
|
173
|
+
const next = Skia.Path.Make();
|
|
174
|
+
for (let x = 0; x <= width; x += 2) {
|
|
175
|
+
const progress = x / width;
|
|
176
|
+
const envelope = Math.pow(Math.sin(Math.PI * progress), 1.5);
|
|
177
|
+
const carrier = Math.sin(x * 0.21 - t * 5.2);
|
|
178
|
+
const burst = Math.pow(Math.abs(Math.sin(x * 0.027 + t * 1.7)), 3);
|
|
179
|
+
const y = middle + carrier * burst * envelope * reach * (0.08 + level.value * 0.92);
|
|
180
|
+
if (x === 0) next.moveTo(x, y);else next.lineTo(x, y);
|
|
181
|
+
}
|
|
182
|
+
return next;
|
|
183
|
+
});
|
|
184
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
185
|
+
children: [/*#__PURE__*/_jsx(Path, {
|
|
186
|
+
path: path,
|
|
187
|
+
style: "stroke",
|
|
188
|
+
strokeWidth: 5,
|
|
189
|
+
strokeCap: "round",
|
|
190
|
+
strokeJoin: "round",
|
|
191
|
+
color: colors[1],
|
|
192
|
+
opacity: 0.18
|
|
193
|
+
}), /*#__PURE__*/_jsx(Path, {
|
|
194
|
+
path: path,
|
|
195
|
+
style: "stroke",
|
|
196
|
+
strokeWidth: 1.8,
|
|
197
|
+
strokeCap: "round",
|
|
198
|
+
strokeJoin: "round",
|
|
199
|
+
children: /*#__PURE__*/_jsx(LinearGradient, {
|
|
200
|
+
start: vec(0, 0),
|
|
201
|
+
end: vec(width, 0),
|
|
202
|
+
colors: [colors[0], colors[2], colors[0]]
|
|
203
|
+
})
|
|
204
|
+
})]
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
export function VoiceWave({
|
|
208
|
+
level,
|
|
209
|
+
colors,
|
|
210
|
+
variant = "lines",
|
|
211
|
+
height = DEFAULT_HEIGHT,
|
|
212
|
+
style
|
|
213
|
+
}) {
|
|
214
|
+
const [width, setWidth] = useState(0);
|
|
215
|
+
const reduceMotion = useReducedMotion();
|
|
216
|
+
const ticking = useClock();
|
|
217
|
+
const clock = useDerivedValue(() => reduceMotion ? 1200 : ticking.value, [reduceMotion]);
|
|
218
|
+
const handleLayout = event => setWidth(event.nativeEvent.layout.width);
|
|
219
|
+
const props = {
|
|
220
|
+
width,
|
|
221
|
+
height,
|
|
222
|
+
level,
|
|
223
|
+
clock,
|
|
224
|
+
colors,
|
|
225
|
+
still: reduceMotion
|
|
226
|
+
};
|
|
227
|
+
return /*#__PURE__*/_jsx(View, {
|
|
228
|
+
style: [{
|
|
229
|
+
flex: 1,
|
|
230
|
+
height
|
|
231
|
+
}, style],
|
|
232
|
+
onLayout: handleLayout,
|
|
233
|
+
children: width > 0 ? /*#__PURE__*/_jsx(Canvas, {
|
|
234
|
+
style: {
|
|
235
|
+
width,
|
|
236
|
+
height
|
|
237
|
+
},
|
|
238
|
+
children: variant === "bars" ? /*#__PURE__*/_jsx(Bars, {
|
|
239
|
+
...props
|
|
240
|
+
}) : variant === "dots" ? /*#__PURE__*/_jsx(Dots, {
|
|
241
|
+
...props
|
|
242
|
+
}) : variant === "pulse" ? /*#__PURE__*/_jsx(Pulse, {
|
|
243
|
+
...props
|
|
244
|
+
}) : /*#__PURE__*/_jsx(Lines, {
|
|
245
|
+
width: width,
|
|
246
|
+
height: height,
|
|
247
|
+
level: level,
|
|
248
|
+
clock: clock,
|
|
249
|
+
colors: colors
|
|
250
|
+
})
|
|
251
|
+
}) : null
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
export function VoiceWaveLines(props) {
|
|
255
|
+
return /*#__PURE__*/_jsx(VoiceWave, {
|
|
256
|
+
...props,
|
|
257
|
+
variant: "lines"
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
export function VoiceWaveBars(props) {
|
|
261
|
+
return /*#__PURE__*/_jsx(VoiceWave, {
|
|
262
|
+
...props,
|
|
263
|
+
variant: "bars"
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
export function VoiceWaveDots(props) {
|
|
267
|
+
return /*#__PURE__*/_jsx(VoiceWave, {
|
|
268
|
+
...props,
|
|
269
|
+
variant: "dots"
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
export function VoiceWavePulse(props) {
|
|
273
|
+
return /*#__PURE__*/_jsx(VoiceWave, {
|
|
274
|
+
...props,
|
|
275
|
+
variant: "pulse"
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
//# sourceMappingURL=voice-wave.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Canvas","LinearGradient","Path","Skia","useClock","vec","useState","View","useDerivedValue","useFrameCallback","useReducedMotion","useSharedValue","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","DEFAULT_HEIGHT","SAMPLE_STEP","MIN_AMPLITUDE","EDGE_PADDING","HISTORY","PUSH_MS","LAYERS","frequency","speed","phase","amplitude","strokeWidth","opacity","WaveLayerPath","layer","width","height","level","clock","color","path","middle","reach","value","offset","next","Make","x","progress","envelope","Math","sin","PI","y","moveTo","lineTo","style","strokeCap","strokeJoin","Lines","colors","children","map","index","Bars","still","history","Array","fill","last","smooth","info","timestamp","slice","push","bar","gap","count","min","floor","samples","sample","h","max","addRRect","RRectXY","XYWHRect","start","end","Dots","spacing","t","wave","r","abs","addCircle","Pulse","pow","carrier","burst","VoiceWave","variant","setWidth","reduceMotion","ticking","handleLayout","event","nativeEvent","layout","props","flex","onLayout","VoiceWaveLines","VoiceWaveBars","VoiceWaveDots","VoiceWavePulse"],"sourceRoot":"../../../src","sources":["skia/voice-wave.tsx"],"mappings":";;AAAA,SAASA,MAAM,EAAEC,cAAc,EAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,GAAG,QAAQ,4BAA4B;AAC9F,SAASC,QAAQ,QAAQ,OAAO;AAChC,SAASC,IAAI,QAAgE,cAAc;AAC3F,SAA2BC,eAAe,EAAEC,gBAAgB,EAAEC,gBAAgB,EAAEC,cAAc,QAAQ,yBAAyB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA,EAAAC,IAAA,IAAAC,KAAA;AAEhI,MAAMC,cAAc,GAAG,EAAE;AACzB,MAAMC,WAAW,GAAG,CAAC;AACrB,MAAMC,aAAa,GAAG,GAAG;AACzB,MAAMC,YAAY,GAAG,CA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IAAI;QAAA,GAAK6C;MAAK,CAAG,CAAC,GACjBR,OAAO,KAAK,MAAM,gBACpBtF,IAAA,CAAC0E,IAAI;QAAA,GAAKoB;MAAK,CAAG,CAAC,GACjBR,OAAO,KAAK,OAAO,gBACrBtF,IAAA,CAACiF,KAAK;QAAA,GAAKa;MAAK,CAAG,CAAC,gBAEpB9F,IAAA,CAAC4C,KAAK;QAACxB,KAAK,EAAEA,KAAM;QAACC,MAAM,EAAEA,MAAO;QAACC,KAAK,EAAEA,KAAM;QAACC,KAAK,EAAEA,KAAM;QAACsB,MAAM,EAAEA;MAAO,CAAE;IACnF,CACK,CAAC,GACP;EAAI,CACJ,CAAC;AAEX;AAIA,OAAO,SAASoD,cAAcA,CAACH,KAA0B,EAAE;EACzD,oBAAO9F,IAAA,CAACqF,SAAS;IAAA,GAAKS,KAAK;IAAER,OAAO,EAAC;EAAO,CAAE,CAAC;AACjD;AAEA,OAAO,SAASY,aAAaA,CAACJ,KAA0B,EAAE;EACxD,oBAAO9F,IAAA,CAACqF,SAAS;IAAA,GAAKS,KAAK;IAAER,OAAO,EAAC;EAAM,CAAE,CAAC;AAChD;AAEA,OAAO,SAASa,aAAaA,CAACL,KAA0B,EAAE;EACxD,oBAAO9F,IAAA,CAACqF,SAAS;IAAA,GAAKS,KAAK;IAAER,OAAO,EAAC;EAAM,CAAE,CAAC;AAChD;AAEA,OAAO,SAASc,cAAcA,CAACN,KAA0B,EAAE;EACzD,oBAAO9F,IAAA,CAACqF,SAAS;IAAA,GAAKS,KAAK;IAAER,OAAO,EAAC;EAAO,CAAE,CAAC;AACjD","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["ShimmerText","StreamingText","SpokenText"],"sourceRoot":"../../../src","sources":["text/index.ts"],"mappings":";;AAAA,SAASA,WAAW,QAA+B,mBAAgB;AACnE,SAASC,aAAa,QAAiC,qBAAkB;AACzE,SAASC,UAAU,QAA8B,kBAAe","ignoreList":[]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo } from "react";
|
|
4
|
+
import { Text, View } from "react-native";
|
|
5
|
+
import Animated, { Easing, Extrapolation, interpolate, interpolateColor, useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withRepeat, withSequence, withTiming } from "react-native-reanimated";
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const DEFAULT_DURATION = 1400;
|
|
8
|
+
const DEFAULT_HIGHLIGHT_WIDTH = 0.22;
|
|
9
|
+
const GLYPH_BLEED = {
|
|
10
|
+
paddingHorizontal: 2,
|
|
11
|
+
marginHorizontal: -2
|
|
12
|
+
};
|
|
13
|
+
const DEFAULT_TEXT_STYLE = {
|
|
14
|
+
fontSize: 14,
|
|
15
|
+
fontWeight: "500",
|
|
16
|
+
lineHeight: 20
|
|
17
|
+
};
|
|
18
|
+
export function ShimmerText({
|
|
19
|
+
text,
|
|
20
|
+
activeColor,
|
|
21
|
+
mutedColor,
|
|
22
|
+
textStyle = DEFAULT_TEXT_STYLE,
|
|
23
|
+
duration = DEFAULT_DURATION,
|
|
24
|
+
highlightWidth = DEFAULT_HIGHLIGHT_WIDTH,
|
|
25
|
+
pause = 0,
|
|
26
|
+
direction = "ltr"
|
|
27
|
+
}) {
|
|
28
|
+
const reduceMotion = useReducedMotion();
|
|
29
|
+
const progress = useSharedValue(0);
|
|
30
|
+
const {
|
|
31
|
+
words,
|
|
32
|
+
total
|
|
33
|
+
} = useMemo(() => {
|
|
34
|
+
const characters = Array.from(text);
|
|
35
|
+
const groups = [];
|
|
36
|
+
let current = [];
|
|
37
|
+
characters.forEach((char, index) => {
|
|
38
|
+
current.push({
|
|
39
|
+
char,
|
|
40
|
+
index
|
|
41
|
+
});
|
|
42
|
+
if (char === " ") {
|
|
43
|
+
groups.push(current);
|
|
44
|
+
current = [];
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
if (current.length) groups.push(current);
|
|
48
|
+
return {
|
|
49
|
+
words: groups,
|
|
50
|
+
total: characters.length
|
|
51
|
+
};
|
|
52
|
+
}, [text]);
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (reduceMotion) return;
|
|
55
|
+
progress.value = 0;
|
|
56
|
+
const sweep = withTiming(1, {
|
|
57
|
+
duration,
|
|
58
|
+
easing: Easing.linear
|
|
59
|
+
});
|
|
60
|
+
progress.value = withRepeat(pause > 0 ? withSequence(sweep, withDelay(pause, withTiming(0, {
|
|
61
|
+
duration: 0
|
|
62
|
+
}))) : sweep, -1, false);
|
|
63
|
+
}, [duration, pause, progress, reduceMotion]);
|
|
64
|
+
if (reduceMotion) {
|
|
65
|
+
return /*#__PURE__*/_jsx(Text, {
|
|
66
|
+
style: [textStyle, {
|
|
67
|
+
color: activeColor
|
|
68
|
+
}],
|
|
69
|
+
children: text
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return /*#__PURE__*/_jsx(View, {
|
|
73
|
+
accessible: true,
|
|
74
|
+
accessibilityRole: "text",
|
|
75
|
+
accessibilityLabel: text,
|
|
76
|
+
style: {
|
|
77
|
+
flexDirection: "row",
|
|
78
|
+
flexWrap: "wrap"
|
|
79
|
+
},
|
|
80
|
+
children: words.map((word, wordIndex) => /*#__PURE__*/_jsx(View, {
|
|
81
|
+
style: {
|
|
82
|
+
flexDirection: "row"
|
|
83
|
+
},
|
|
84
|
+
children: word.map(glyph => /*#__PURE__*/_jsx(ShimmerChar, {
|
|
85
|
+
char: glyph.char,
|
|
86
|
+
index: direction === "rtl" ? total - 1 - glyph.index : glyph.index,
|
|
87
|
+
total: total,
|
|
88
|
+
progress: progress,
|
|
89
|
+
activeColor: activeColor,
|
|
90
|
+
mutedColor: mutedColor,
|
|
91
|
+
textStyle: textStyle,
|
|
92
|
+
highlightWidth: highlightWidth
|
|
93
|
+
}, glyph.index))
|
|
94
|
+
}, wordIndex))
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function ShimmerChar({
|
|
98
|
+
char,
|
|
99
|
+
index,
|
|
100
|
+
total,
|
|
101
|
+
progress,
|
|
102
|
+
activeColor,
|
|
103
|
+
mutedColor,
|
|
104
|
+
textStyle,
|
|
105
|
+
highlightWidth
|
|
106
|
+
}) {
|
|
107
|
+
const style = useAnimatedStyle(() => {
|
|
108
|
+
const phase = total > 1 ? index / (total - 1) : 0;
|
|
109
|
+
const position = -highlightWidth + progress.value * (1 + highlightWidth * 2);
|
|
110
|
+
const distance = Math.abs(position - phase);
|
|
111
|
+
const linear = interpolate(distance, [0, highlightWidth], [0, 1], Extrapolation.CLAMP);
|
|
112
|
+
const t = linear * linear * (3 - 2 * linear);
|
|
113
|
+
return {
|
|
114
|
+
color: interpolateColor(t, [0, 1], [activeColor, mutedColor])
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
return /*#__PURE__*/_jsx(Animated.Text, {
|
|
118
|
+
style: [textStyle, GLYPH_BLEED, style],
|
|
119
|
+
children: char
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=shimmer-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useMemo","Text","View","Animated","Easing","Extrapolation","interpolate","interpolateColor","useAnimatedStyle","useReducedMotion","useSharedValue","withDelay","withRepeat","withSequence","withTiming","jsx","_jsx","DEFAULT_DURATION","DEFAULT_HIGHLIGHT_WIDTH","GLYPH_BLEED","paddingHorizontal","marginHorizontal","DEFAULT_TEXT_STYLE","fontSize","fontWeight","lineHeight","ShimmerText","text","activeColor","mutedColor","textStyle","duration","highlightWidth","pause","direction","reduceMotion","progress","words","total","characters","Array","from","groups","current","forEach","char","index","push","length","value","sweep","easing","linear","style","color","children","accessible","accessibilityRole","accessibilityLabel","flexDirection","flexWrap","map","word","wordIndex","glyph","ShimmerChar","phase","position","distance","Math","abs","CLAMP","t"],"sourceRoot":"../../../src","sources":["text/shimmer-text.tsx"],"mappings":";;AAAA,SAAS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AAE,CAAC,CAAC,EAAE3B,aAAa,CAACkE,KAAK,CAAC;IACtF,MAAMC,CAAC,GAAGpB,MAAM,GAAGA,MAAM,IAAI,CAAC,GAAG,CAAC,GAAGA,MAAM,CAAC;IAC5C,OAAO;MAAEE,KAAK,EAAE/C,gBAAgB,CAACiE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC5C,WAAW,EAAEC,UAAU,CAAC;IAAE,CAAC;EAC1E,CAAC,CAAC;EAEF,oBAAOb,IAAA,CAACb,QAAQ,CAACF,IAAI;IAACoD,KAAK,EAAE,CAACvB,SAAS,EAAEX,WAAW,EAAEkC,KAAK,CAAE;IAAAE,QAAA,EAAEV;EAAI,CAAgB,CAAC;AACtF","ignoreList":[]}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { memo, useEffect, useMemo } from "react";
|
|
4
|
+
import { Text, View } from "react-native";
|
|
5
|
+
import Animated, { interpolateColor, useAnimatedStyle, useReducedMotion, useSharedValue, withTiming } from "react-native-reanimated";
|
|
6
|
+
import { useMotionPalette } from "../theme/provider.js";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const DEFAULT_TEXT_STYLE = {
|
|
9
|
+
fontSize: 22,
|
|
10
|
+
lineHeight: 30,
|
|
11
|
+
fontWeight: "600"
|
|
12
|
+
};
|
|
13
|
+
export function SpokenText({
|
|
14
|
+
text,
|
|
15
|
+
spoken,
|
|
16
|
+
textStyle = DEFAULT_TEXT_STYLE,
|
|
17
|
+
activeColor,
|
|
18
|
+
spokenColor,
|
|
19
|
+
upcomingColor,
|
|
20
|
+
align = "center",
|
|
21
|
+
colors,
|
|
22
|
+
style
|
|
23
|
+
}) {
|
|
24
|
+
const palette = useMotionPalette(colors);
|
|
25
|
+
const reduceMotion = useReducedMotion();
|
|
26
|
+
const words = useMemo(() => text.match(/\S+\s*/g) ?? [], [text]);
|
|
27
|
+
const active = activeColor ?? palette.text;
|
|
28
|
+
const done = spokenColor ?? palette.textSecondary;
|
|
29
|
+
const upcoming = upcomingColor ?? palette.textTertiary;
|
|
30
|
+
const current = Math.min(words.length, Math.max(0, Math.floor(spoken)));
|
|
31
|
+
if (reduceMotion) {
|
|
32
|
+
return /*#__PURE__*/_jsx(Text, {
|
|
33
|
+
accessibilityLabel: text,
|
|
34
|
+
style: [textStyle, {
|
|
35
|
+
color: active,
|
|
36
|
+
textAlign: align
|
|
37
|
+
}, style],
|
|
38
|
+
children: text
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return /*#__PURE__*/_jsx(View, {
|
|
42
|
+
accessible: true,
|
|
43
|
+
accessibilityRole: "text",
|
|
44
|
+
accessibilityLabel: text,
|
|
45
|
+
style: [{
|
|
46
|
+
flexDirection: "row",
|
|
47
|
+
flexWrap: "wrap",
|
|
48
|
+
justifyContent: align === "center" ? "center" : "flex-start"
|
|
49
|
+
}, style],
|
|
50
|
+
children: words.map((word, index) => /*#__PURE__*/_jsx(SpokenWord, {
|
|
51
|
+
word: word,
|
|
52
|
+
phase: index < current ? 2 : index === current ? 1 : 0,
|
|
53
|
+
textStyle: textStyle,
|
|
54
|
+
active: active,
|
|
55
|
+
done: done,
|
|
56
|
+
upcoming: upcoming
|
|
57
|
+
}, index))
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const SpokenWord = /*#__PURE__*/memo(function SpokenWord({
|
|
61
|
+
word,
|
|
62
|
+
phase,
|
|
63
|
+
textStyle,
|
|
64
|
+
active,
|
|
65
|
+
done,
|
|
66
|
+
upcoming
|
|
67
|
+
}) {
|
|
68
|
+
const value = useSharedValue(phase);
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
value.value = withTiming(phase, {
|
|
71
|
+
duration: 180
|
|
72
|
+
});
|
|
73
|
+
}, [phase, value]);
|
|
74
|
+
const style = useAnimatedStyle(() => ({
|
|
75
|
+
color: interpolateColor(value.value, [0, 1, 2], [upcoming, active, done]),
|
|
76
|
+
transform: [{
|
|
77
|
+
translateY: -2 * Math.max(0, 1 - Math.abs(value.value - 1))
|
|
78
|
+
}]
|
|
79
|
+
}));
|
|
80
|
+
return /*#__PURE__*/_jsx(Animated.Text, {
|
|
81
|
+
style: [textStyle, style],
|
|
82
|
+
children: word
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
//# sourceMappingURL=spoken-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["memo","useEffect","useMemo","Text","View","Animated","interpolateColor","useAnimatedStyle","useReducedMotion","useSharedValue","withTiming","useMotionPalette","jsx","_jsx","DEFAULT_TEXT_STYLE","fontSize","lineHeight","fontWeight","SpokenText","text","spoken","textStyle","activeColor","spokenColor","upcomingColor","align","colors","style","palette","reduceMotion","words","match","active","done","textSecondary","upcoming","textTertiary","current","Math","min","length","max","floor","accessibilityLabel","color","textAlign","children","accessible","accessibilityRole","flexDirection","flexWrap","justifyContent","map","word","index","SpokenWord","phase","value","duration","transform","translateY","abs"],"sourceRoot":"../../../src","sources":["text/spoken-text.tsx"],"mappings":";;AAAA,SAASA,IAAI,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AAChD,SAASC,IAAI,EAAEC,IAAI,QAAwD,cAAc;AACzF,OAAOC,QAAQ,IAAIC,gBAAgB,EAAEC,gBAAgB,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,UAAU,QAAQ,yBAAyB;AAEpI,SAASC,gBAAgB,QAAQ,sBAAmB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAErD,MAAMC,kBAA6B,GAAG;EAAEC,QAAQ,EAAE,EAAE;EAAEC,UAAU,EAAE,EAAE;EAAEC,UAAU,EAAE;AAAM,CAAC;AAczF,OAAO,SAASC,UAAUA,CAAC;EACzBC,IAAI;EACJC,MAAM;EACNC,SAAS,GAAGP,kBAAkB;EAC9BQ,WAAW;EACXC,WAAW;EACXC,aAAa;EACbC,KAAK,GAAG,QAAQ;EA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AACzE,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { isValidElement, memo, useEffect, useMemo } from "react";
|
|
4
|
+
import { StyleSheet, Text, View } from "react-native";
|
|
5
|
+
import Animated, { cancelAnimation, Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withRepeat, withSequence, withTiming } from "react-native-reanimated";
|
|
6
|
+
import { useMotionPalette } from "../theme/provider.js";
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
const DEFAULT_TEXT_STYLE = {
|
|
9
|
+
fontSize: 16,
|
|
10
|
+
lineHeight: 24
|
|
11
|
+
};
|
|
12
|
+
const DEFAULT_FADE = 360;
|
|
13
|
+
const DEFAULT_RISE = 6;
|
|
14
|
+
const CARET_BLINK = 530;
|
|
15
|
+
function tokenize(paragraph) {
|
|
16
|
+
const parts = paragraph.match(/\S+\s*/g) ?? [];
|
|
17
|
+
return parts.map((value, key) => ({
|
|
18
|
+
value,
|
|
19
|
+
key
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
export function StreamingText({
|
|
23
|
+
text,
|
|
24
|
+
streaming,
|
|
25
|
+
textStyle = DEFAULT_TEXT_STYLE,
|
|
26
|
+
paragraphGap = 12,
|
|
27
|
+
fadeDuration = DEFAULT_FADE,
|
|
28
|
+
rise = DEFAULT_RISE,
|
|
29
|
+
caret = true,
|
|
30
|
+
colors,
|
|
31
|
+
style
|
|
32
|
+
}) {
|
|
33
|
+
const palette = useMotionPalette(colors);
|
|
34
|
+
const reduceMotion = useReducedMotion();
|
|
35
|
+
const paragraphs = useMemo(() => text.split(/\n{2,}/), [text]);
|
|
36
|
+
const animate = streaming && !reduceMotion;
|
|
37
|
+
const color = palette.text;
|
|
38
|
+
const caretNode = caret === false ? null : /*#__PURE__*/isValidElement(caret) ? caret : /*#__PURE__*/_jsx(Caret, {
|
|
39
|
+
color: color,
|
|
40
|
+
blink: !reduceMotion,
|
|
41
|
+
textStyle: textStyle
|
|
42
|
+
});
|
|
43
|
+
return /*#__PURE__*/_jsx(View, {
|
|
44
|
+
style: [{
|
|
45
|
+
gap: paragraphGap
|
|
46
|
+
}, style],
|
|
47
|
+
children: paragraphs.map((paragraph, index) => {
|
|
48
|
+
const last = index === paragraphs.length - 1;
|
|
49
|
+
if (!animate || !last) {
|
|
50
|
+
return /*#__PURE__*/_jsxs(Text, {
|
|
51
|
+
style: [textStyle, {
|
|
52
|
+
color
|
|
53
|
+
}],
|
|
54
|
+
children: [paragraph, last && streaming && caretNode]
|
|
55
|
+
}, index);
|
|
56
|
+
}
|
|
57
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
58
|
+
accessible: true,
|
|
59
|
+
accessibilityRole: "text",
|
|
60
|
+
accessibilityLabel: paragraph,
|
|
61
|
+
style: {
|
|
62
|
+
flexDirection: "row",
|
|
63
|
+
flexWrap: "wrap",
|
|
64
|
+
alignItems: "flex-end"
|
|
65
|
+
},
|
|
66
|
+
children: [tokenize(paragraph).map(token => /*#__PURE__*/_jsx(StreamingWord, {
|
|
67
|
+
value: token.value,
|
|
68
|
+
textStyle: textStyle,
|
|
69
|
+
color: color,
|
|
70
|
+
fadeDuration: fadeDuration,
|
|
71
|
+
rise: rise
|
|
72
|
+
}, token.key)), caretNode]
|
|
73
|
+
}, index);
|
|
74
|
+
})
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
const StreamingWord = /*#__PURE__*/memo(function StreamingWord({
|
|
78
|
+
value,
|
|
79
|
+
textStyle,
|
|
80
|
+
color,
|
|
81
|
+
fadeDuration,
|
|
82
|
+
rise
|
|
83
|
+
}) {
|
|
84
|
+
const progress = useSharedValue(0);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
progress.value = withTiming(1, {
|
|
87
|
+
duration: fadeDuration,
|
|
88
|
+
easing: Easing.out(Easing.cubic)
|
|
89
|
+
});
|
|
90
|
+
}, [fadeDuration, progress]);
|
|
91
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
92
|
+
opacity: progress.value,
|
|
93
|
+
transform: [{
|
|
94
|
+
translateY: rise * (1 - progress.value)
|
|
95
|
+
}]
|
|
96
|
+
}));
|
|
97
|
+
return /*#__PURE__*/_jsx(Animated.Text, {
|
|
98
|
+
style: [textStyle, {
|
|
99
|
+
color
|
|
100
|
+
}, animatedStyle],
|
|
101
|
+
children: value
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
function Caret({
|
|
105
|
+
color,
|
|
106
|
+
blink,
|
|
107
|
+
textStyle
|
|
108
|
+
}) {
|
|
109
|
+
const opacity = useSharedValue(1);
|
|
110
|
+
const flat = StyleSheet.flatten(textStyle);
|
|
111
|
+
const height = Math.round((flat?.fontSize ?? 16) * 1.05);
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
if (!blink) return;
|
|
114
|
+
opacity.value = withRepeat(withSequence(withTiming(0, {
|
|
115
|
+
duration: CARET_BLINK
|
|
116
|
+
}), withTiming(1, {
|
|
117
|
+
duration: CARET_BLINK
|
|
118
|
+
})), -1, false);
|
|
119
|
+
return () => cancelAnimation(opacity);
|
|
120
|
+
}, [blink, opacity]);
|
|
121
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
122
|
+
opacity: opacity.value
|
|
123
|
+
}));
|
|
124
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
125
|
+
style: [{
|
|
126
|
+
width: 2,
|
|
127
|
+
height,
|
|
128
|
+
borderRadius: 1,
|
|
129
|
+
backgroundColor: color,
|
|
130
|
+
marginLeft: 2,
|
|
131
|
+
marginBottom: 3
|
|
132
|
+
}, animatedStyle]
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
//# sourceMappingURL=streaming-text.js.map
|