@ghchinoy/lit-audio-ui 0.5.1 → 0.6.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.
Files changed (40) hide show
  1. package/custom-elements.json +134 -60
  2. package/dist/components/atoms/ui-audio-next-button.js +9 -13
  3. package/dist/components/atoms/ui-audio-play-button.js +10 -14
  4. package/dist/components/atoms/ui-audio-player-error.js +10 -14
  5. package/dist/components/atoms/ui-audio-prev-button.js +9 -13
  6. package/dist/components/atoms/ui-audio-progress-slider.js +16 -20
  7. package/dist/components/atoms/ui-audio-time-display.js +15 -19
  8. package/dist/components/atoms/ui-audio-volume-slider.js +17 -21
  9. package/dist/components/atoms/ui-speech-cancel-button.js +5 -5
  10. package/dist/components/atoms/ui-speech-record-button.js +5 -5
  11. package/dist/components/atoms/ui-timed-text.js +14 -18
  12. package/dist/components/atoms/ui-voice-waveform.js +15 -19
  13. package/dist/components/molecules/ui-live-waveform.js +33 -32
  14. package/dist/components/molecules/ui-mic-selector.js +14 -18
  15. package/dist/components/molecules/ui-playlist.js +15 -19
  16. package/dist/components/molecules/ui-scrolling-waveform.js +30 -29
  17. package/dist/components/molecules/ui-spectrum-visualizer.js +23 -25
  18. package/dist/components/molecules/ui-speech-preview.js +16 -20
  19. package/dist/components/molecules/ui-voice-button.js +25 -29
  20. package/dist/components/molecules/ui-voice-picker.js +21 -25
  21. package/dist/components/molecules/ui-voice-pill.js +5 -5
  22. package/dist/components/molecules/ui-waveform.js +46 -36
  23. package/dist/components/organisms/ui-audio-player.js +7 -11
  24. package/dist/components/providers/ui-audio-provider.js +17 -22
  25. package/dist/components/providers/ui-speech-provider.js +13 -17
  26. package/dist/index.js +36 -36
  27. package/dist/node_modules/@chenglou/pretext/dist/analysis.js +456 -0
  28. package/dist/node_modules/@chenglou/pretext/dist/bidi.js +62 -0
  29. package/dist/node_modules/@chenglou/pretext/dist/layout.js +190 -0
  30. package/dist/node_modules/@chenglou/pretext/dist/line-break.js +234 -0
  31. package/dist/node_modules/@chenglou/pretext/dist/measurement.js +106 -0
  32. package/dist/scream-audio-ui.umd.js +45 -42
  33. package/dist/src/components/molecules/ui-waveform.d.ts +7 -1
  34. package/dist/src/components/providers/ui-audio-provider.d.ts +2 -1
  35. package/dist/src/utils/audio-context.d.ts +0 -1
  36. package/dist/src/utils/audio-utils.d.ts +8 -0
  37. package/dist/standalone/scream-audio-ui.standalone.js +2626 -1655
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/dist/utils/audio-utils.js +27 -16
  40. package/package.json +7 -4
@@ -0,0 +1,234 @@
1
+ import { getEngineProfile as e } from "./measurement.js";
2
+ function t(e) {
3
+ return e === "space" || e === "preserved-space" || e === "tab" || e === "zero-width-break" || e === "soft-hyphen";
4
+ }
5
+ function n(e, t) {
6
+ for (; t < e.widths.length;) {
7
+ let n = e.kinds[t];
8
+ if (n !== "space" && n !== "zero-width-break" && n !== "soft-hyphen") break;
9
+ t++;
10
+ }
11
+ return t;
12
+ }
13
+ function r(e, t) {
14
+ if (t <= 0) return 0;
15
+ let n = e % t;
16
+ return Math.abs(n) <= 1e-6 ? t : t - n;
17
+ }
18
+ function i(e, t, n, r) {
19
+ return !r || t === null ? e[n] : t[n] - (n > 0 ? t[n - 1] : 0);
20
+ }
21
+ function a(e, t, n, r, i, a) {
22
+ let o = 0, s = t;
23
+ for (; o < e.length;) {
24
+ let c = a ? t + e[o] : s + e[o];
25
+ if ((o + 1 < e.length ? c + i : c) > n + r) break;
26
+ s = c, o++;
27
+ }
28
+ return {
29
+ fitCount: o,
30
+ fittedWidth: s
31
+ };
32
+ }
33
+ function o(r, a, o) {
34
+ let { widths: s, kinds: c, breakableWidths: l, breakablePrefixWidths: u } = r;
35
+ if (s.length === 0) return 0;
36
+ let d = e(), f = d.lineFitEpsilon, p = 0, m = 0, h = !1, g = 0, _ = 0, v = 0, y = 0, b = -1, x = 0;
37
+ function S() {
38
+ b = -1, x = 0;
39
+ }
40
+ function C(e = v, t = y, n = m) {
41
+ p++, o?.({
42
+ startSegmentIndex: g,
43
+ startGraphemeIndex: _,
44
+ endSegmentIndex: e,
45
+ endGraphemeIndex: t,
46
+ width: n
47
+ }), m = 0, h = !1, S();
48
+ }
49
+ function w(e, t) {
50
+ h = !0, g = e, _ = 0, v = e + 1, y = 0, m = t;
51
+ }
52
+ function T(e, t, n) {
53
+ h = !0, g = e, _ = t, v = e, y = t + 1, m = n;
54
+ }
55
+ function E(e, t) {
56
+ if (!h) {
57
+ w(e, t);
58
+ return;
59
+ }
60
+ m += t, v = e + 1, y = 0;
61
+ }
62
+ function D(e, n) {
63
+ t(c[e]) && (b = e + 1, x = m - n);
64
+ }
65
+ function O(e) {
66
+ k(e, 0);
67
+ }
68
+ function k(e, t) {
69
+ let n = l[e], r = u[e] ?? null;
70
+ for (let o = t; o < n.length; o++) {
71
+ let t = i(n, r, o, d.preferPrefixWidthsForBreakableRuns);
72
+ if (!h) {
73
+ T(e, o, t);
74
+ continue;
75
+ }
76
+ m + t > a + f ? (C(), T(e, o, t)) : (m += t, v = e, y = o + 1);
77
+ }
78
+ h && v === e && y === n.length && (v = e + 1, y = 0);
79
+ }
80
+ let A = 0;
81
+ for (; A < s.length && !(!h && (A = n(r, A), A >= s.length));) {
82
+ let e = s[A], n = c[A];
83
+ if (!h) {
84
+ e > a && l[A] !== null ? O(A) : w(A, e), D(A, e), A++;
85
+ continue;
86
+ }
87
+ if (m + e > a + f) {
88
+ if (t(n)) {
89
+ E(A, e), C(A + 1, 0, m - e), A++;
90
+ continue;
91
+ }
92
+ if (b >= 0) {
93
+ if (v > b || v === b && y > 0) {
94
+ C();
95
+ continue;
96
+ }
97
+ C(b, 0, x);
98
+ continue;
99
+ }
100
+ if (e > a && l[A] !== null) {
101
+ C(), O(A), A++;
102
+ continue;
103
+ }
104
+ C();
105
+ continue;
106
+ }
107
+ E(A, e), D(A, e), A++;
108
+ }
109
+ return h && C(), p;
110
+ }
111
+ function s(n, s, c) {
112
+ if (n.simpleLineWalkFastPath) return o(n, s, c);
113
+ let { widths: l, lineEndFitAdvances: u, lineEndPaintAdvances: d, kinds: f, breakableWidths: p, breakablePrefixWidths: m, discretionaryHyphenWidth: h, tabStopAdvance: g, chunks: _ } = n;
114
+ if (l.length === 0 || _.length === 0) return 0;
115
+ let v = e(), y = v.lineFitEpsilon, b = 0, x = 0, S = !1, C = 0, w = 0, T = 0, E = 0, D = -1, O = 0, k = 0, A = null;
116
+ function j() {
117
+ D = -1, O = 0, k = 0, A = null;
118
+ }
119
+ function M(e = T, t = E, n = x) {
120
+ b++, c?.({
121
+ startSegmentIndex: C,
122
+ startGraphemeIndex: w,
123
+ endSegmentIndex: e,
124
+ endGraphemeIndex: t,
125
+ width: n
126
+ }), x = 0, S = !1, j();
127
+ }
128
+ function N(e, t) {
129
+ S = !0, C = e, w = 0, T = e + 1, E = 0, x = t;
130
+ }
131
+ function P(e, t, n) {
132
+ S = !0, C = e, w = t, T = e, E = t + 1, x = n;
133
+ }
134
+ function F(e, t) {
135
+ if (!S) {
136
+ N(e, t);
137
+ return;
138
+ }
139
+ x += t, T = e + 1, E = 0;
140
+ }
141
+ function I(e, n) {
142
+ if (!t(f[e])) return;
143
+ let r = f[e] === "tab" ? 0 : u[e], i = f[e] === "tab" ? n : d[e];
144
+ D = e + 1, O = x - n + r, k = x - n + i, A = f[e];
145
+ }
146
+ function L(e) {
147
+ R(e, 0);
148
+ }
149
+ function R(e, t) {
150
+ let n = p[e], r = m[e] ?? null;
151
+ for (let a = t; a < n.length; a++) {
152
+ let t = i(n, r, a, v.preferPrefixWidthsForBreakableRuns);
153
+ if (!S) {
154
+ P(e, a, t);
155
+ continue;
156
+ }
157
+ x + t > s + y ? (M(), P(e, a, t)) : (x += t, T = e, E = a + 1);
158
+ }
159
+ S && T === e && E === n.length && (T = e + 1, E = 0);
160
+ }
161
+ function z(e) {
162
+ if (A !== "soft-hyphen") return !1;
163
+ let t = p[e];
164
+ if (t === null) return !1;
165
+ let n = v.preferPrefixWidthsForBreakableRuns ? m[e] ?? t : t, { fitCount: r, fittedWidth: i } = a(n, x, s, y, h, n !== t);
166
+ return r === 0 ? !1 : (x = i, T = e, E = r, j(), r === t.length ? (T = e + 1, E = 0, !0) : (M(e, r, i + h), R(e, r), !0));
167
+ }
168
+ function B(e) {
169
+ b++, c?.({
170
+ startSegmentIndex: e.startSegmentIndex,
171
+ startGraphemeIndex: 0,
172
+ endSegmentIndex: e.consumedEndSegmentIndex,
173
+ endGraphemeIndex: 0,
174
+ width: 0
175
+ }), j();
176
+ }
177
+ for (let e = 0; e < _.length; e++) {
178
+ let n = _[e];
179
+ if (n.startSegmentIndex === n.endSegmentIndex) {
180
+ B(n);
181
+ continue;
182
+ }
183
+ S = !1, x = 0, C = n.startSegmentIndex, w = 0, T = n.startSegmentIndex, E = 0, j();
184
+ let i = n.startSegmentIndex;
185
+ for (; i < n.endSegmentIndex;) {
186
+ let e = f[i], n = e === "tab" ? r(x, g) : l[i];
187
+ if (e === "soft-hyphen") {
188
+ S && (T = i + 1, E = 0, D = i + 1, O = x + h, k = x + h, A = e), i++;
189
+ continue;
190
+ }
191
+ if (!S) {
192
+ n > s && p[i] !== null ? L(i) : N(i, n), I(i, n), i++;
193
+ continue;
194
+ }
195
+ if (x + n > s + y) {
196
+ let r = x + (e === "tab" ? 0 : u[i]), a = x + (e === "tab" ? n : d[i]);
197
+ if (A === "soft-hyphen" && v.preferEarlySoftHyphenBreak && O <= s + y) {
198
+ M(D, 0, k);
199
+ continue;
200
+ }
201
+ if (A === "soft-hyphen" && z(i)) {
202
+ i++;
203
+ continue;
204
+ }
205
+ if (t(e) && r <= s + y) {
206
+ F(i, n), M(i + 1, 0, a), i++;
207
+ continue;
208
+ }
209
+ if (D >= 0 && O <= s + y) {
210
+ if (T > D || T === D && E > 0) {
211
+ M();
212
+ continue;
213
+ }
214
+ let e = D;
215
+ M(e, 0, k), i = e;
216
+ continue;
217
+ }
218
+ if (n > s && p[i] !== null) {
219
+ M(), L(i), i++;
220
+ continue;
221
+ }
222
+ M();
223
+ continue;
224
+ }
225
+ F(i, n), I(i, n), i++;
226
+ }
227
+ if (S) {
228
+ let e = D === n.consumedEndSegmentIndex ? k : x;
229
+ M(n.consumedEndSegmentIndex, 0, e);
230
+ }
231
+ }
232
+ return b;
233
+ }
234
+ export { s as walkPreparedLines };
@@ -0,0 +1,106 @@
1
+ import { isCJK as e } from "./analysis.js";
2
+ var t = null, n = /* @__PURE__ */ new Map(), r = null, i = /\p{Emoji_Presentation}/u, a = /[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u, o = null, s = /* @__PURE__ */ new Map();
3
+ function c() {
4
+ if (t !== null) return t;
5
+ if (typeof OffscreenCanvas < "u") return t = new OffscreenCanvas(1, 1).getContext("2d"), t;
6
+ if (typeof document < "u") return t = document.createElement("canvas").getContext("2d"), t;
7
+ throw Error("Text measurement requires OffscreenCanvas or a DOM canvas context.");
8
+ }
9
+ function l(e) {
10
+ let t = n.get(e);
11
+ return t || (t = /* @__PURE__ */ new Map(), n.set(e, t)), t;
12
+ }
13
+ function u(t, n) {
14
+ let r = n.get(t);
15
+ return r === void 0 && (r = {
16
+ width: c().measureText(t).width,
17
+ containsCJK: e(t)
18
+ }, n.set(t, r)), r;
19
+ }
20
+ function d() {
21
+ if (r !== null) return r;
22
+ if (typeof navigator > "u") return r = {
23
+ lineFitEpsilon: .005,
24
+ carryCJKAfterClosingQuote: !1,
25
+ preferPrefixWidthsForBreakableRuns: !1,
26
+ preferEarlySoftHyphenBreak: !1
27
+ }, r;
28
+ let e = navigator.userAgent, t = navigator.vendor === "Apple Computer, Inc." && e.includes("Safari/") && !e.includes("Chrome/") && !e.includes("Chromium/") && !e.includes("CriOS/") && !e.includes("FxiOS/") && !e.includes("EdgiOS/"), n = e.includes("Chrome/") || e.includes("Chromium/") || e.includes("CriOS/") || e.includes("Edg/");
29
+ return r = {
30
+ lineFitEpsilon: t ? 1 / 64 : .005,
31
+ carryCJKAfterClosingQuote: n,
32
+ preferPrefixWidthsForBreakableRuns: t,
33
+ preferEarlySoftHyphenBreak: t
34
+ }, r;
35
+ }
36
+ function f(e) {
37
+ let t = e.match(/(\d+(?:\.\d+)?)\s*px/);
38
+ return t ? parseFloat(t[1]) : 16;
39
+ }
40
+ function p() {
41
+ return o === null && (o = new Intl.Segmenter(void 0, { granularity: "grapheme" })), o;
42
+ }
43
+ function m(e) {
44
+ return i.test(e) || e.includes("️");
45
+ }
46
+ function h(e) {
47
+ return a.test(e);
48
+ }
49
+ function g(e, t) {
50
+ let n = s.get(e);
51
+ if (n !== void 0) return n;
52
+ let r = c();
53
+ r.font = e;
54
+ let i = r.measureText("😀").width;
55
+ if (n = 0, i > t + .5 && typeof document < "u" && document.body !== null) {
56
+ let t = document.createElement("span");
57
+ t.style.font = e, t.style.display = "inline-block", t.style.visibility = "hidden", t.style.position = "absolute", t.textContent = "😀", document.body.appendChild(t);
58
+ let r = t.getBoundingClientRect().width;
59
+ document.body.removeChild(t), i - r > .5 && (n = i - r);
60
+ }
61
+ return s.set(e, n), n;
62
+ }
63
+ function _(e) {
64
+ let t = 0, n = p();
65
+ for (let r of n.segment(e)) m(r.segment) && t++;
66
+ return t;
67
+ }
68
+ function v(e, t) {
69
+ return t.emojiCount === void 0 && (t.emojiCount = _(e)), t.emojiCount;
70
+ }
71
+ function y(e, t, n) {
72
+ return n === 0 ? t.width : t.width - v(e, t) * n;
73
+ }
74
+ function b(e, t, n, r) {
75
+ if (t.graphemeWidths !== void 0) return t.graphemeWidths;
76
+ let i = [], a = p();
77
+ for (let t of a.segment(e)) {
78
+ let e = u(t.segment, n);
79
+ i.push(y(t.segment, e, r));
80
+ }
81
+ return t.graphemeWidths = i.length > 1 ? i : null, t.graphemeWidths;
82
+ }
83
+ function x(e, t, n, r) {
84
+ if (t.graphemePrefixWidths !== void 0) return t.graphemePrefixWidths;
85
+ let i = [], a = p(), o = "";
86
+ for (let t of a.segment(e)) {
87
+ o += t.segment;
88
+ let e = u(o, n);
89
+ i.push(y(o, e, r));
90
+ }
91
+ return t.graphemePrefixWidths = i.length > 1 ? i : null, t.graphemePrefixWidths;
92
+ }
93
+ function S(e, t) {
94
+ let n = c();
95
+ n.font = e;
96
+ let r = l(e), i = f(e);
97
+ return {
98
+ cache: r,
99
+ fontSize: i,
100
+ emojiCorrection: t ? g(e, i) : 0
101
+ };
102
+ }
103
+ function C() {
104
+ n.clear(), s.clear(), o = null;
105
+ }
106
+ export { C as clearMeasurementCaches, y as getCorrectedSegmentWidth, d as getEngineProfile, S as getFontMeasurementState, x as getSegmentGraphemePrefixWidths, b as getSegmentGraphemeWidths, u as getSegmentMetrics, h as textMayContainEmoji };