chesai-ui 0.16.2 → 0.16.4

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 (28) hide show
  1. package/dist/chesai-ui.css +1 -1
  2. package/dist/components/charts/bar-chart.d.ts +3 -1
  3. package/dist/components/charts/bar-chart.mjs +87 -74
  4. package/dist/components/charts/chart-utils.d.ts +7 -0
  5. package/dist/components/charts/chart-utils.mjs +24 -7
  6. package/dist/components/charts/heatmap-chart.d.ts +25 -0
  7. package/dist/components/playlist-studio/elements.d.ts +10 -2
  8. package/dist/components/playlist-studio/elements.mjs +289 -120
  9. package/dist/components/playlist-studio/index.d.ts +1 -0
  10. package/dist/components/playlist-studio/item-renderer.d.ts +2 -1
  11. package/dist/components/playlist-studio/item-renderer.mjs +66 -55
  12. package/dist/components/playlist-studio/player.d.ts +3 -1
  13. package/dist/components/playlist-studio/player.mjs +438 -71
  14. package/dist/components/playlist-studio/preload-context.d.ts +8 -0
  15. package/dist/components/playlist-studio/preload-context.mjs +6 -0
  16. package/dist/components/playlist-studio/types.d.ts +3 -0
  17. package/dist/components/textarea/textarea-styles.mjs +4 -4
  18. package/dist/components/textarea/use-textarea.d.ts +2 -2
  19. package/dist/components/textarea/use-textarea.mjs +72 -69
  20. package/dist/context/ChesaiProvider.d.ts +5 -1
  21. package/dist/context/ChesaiProvider.mjs +28 -24
  22. package/dist/context/ThemeProvider.d.ts +5 -1
  23. package/dist/context/ThemeProvider.mjs +130 -112
  24. package/dist/context/heatmap-chart.d.ts +25 -0
  25. package/dist/index.mjs +67 -63
  26. package/dist/utils/theme-generator.d.ts +1 -1
  27. package/dist/utils/theme-generator.mjs +39 -39
  28. package/package.json +1 -1
@@ -1,163 +1,332 @@
1
- import { jsxs as v, jsx as y } from "react/jsx-runtime";
2
- import { useRef as h, useState as k, useEffect as E } from "react";
3
- import { clsx as D } from "clsx";
4
- import P from "hls.js";
5
- import { useMotionValueEvent as w } from "framer-motion";
6
- const S = ({
7
- data: m,
8
- isActive: a,
9
- isTimelinePlaying: d,
10
- playhead: p,
11
- startTime: R
1
+ import { jsxs as V, jsx as k } from "react/jsx-runtime";
2
+ import { useRef as E, useState as D, useEffect as f } from "react";
3
+ import { clsx as A } from "clsx";
4
+ import _ from "hls.js";
5
+ import { useMotionValueEvent as O } from "framer-motion";
6
+ import { LoadingIndicator as J } from "../loadingIndicator/index.mjs";
7
+ import { usePreload as M } from "./preload-context.mjs";
8
+ const q = /* @__PURE__ */ new Set([
9
+ "div",
10
+ "span",
11
+ "p",
12
+ "h1",
13
+ "h2",
14
+ "h3",
15
+ "h4",
16
+ "h5",
17
+ "h6",
18
+ "section",
19
+ "article",
20
+ "aside",
21
+ "header",
22
+ "footer",
23
+ "main",
24
+ "ul",
25
+ "ol",
26
+ "li",
27
+ "a",
28
+ "table",
29
+ "thead",
30
+ "tbody",
31
+ "tr",
32
+ "th",
33
+ "td",
34
+ "pre",
35
+ "code",
36
+ "blockquote",
37
+ "mark",
38
+ "strong",
39
+ "em",
40
+ "i",
41
+ "b"
42
+ ]), B = ({
43
+ id: r,
44
+ data: N,
45
+ isActive: s,
46
+ isTimelinePlaying: u,
47
+ playhead: L,
48
+ startTime: g
12
49
  }) => {
13
- const c = h(null), n = h(null), u = h(null), [s, f] = k(null), { src: e, muted: i = !0, objectFit: l = "cover", volume: x = 1 } = m;
14
- return E(() => {
15
- const t = c.current;
16
- if (!t || !e) return;
17
- if (f(null), n.current && (n.current.destroy(), n.current = null), e.includes(".m3u8") || e.includes("application/x-mpegURL"))
18
- if (t.canPlayType("application/vnd.apple.mpegurl"))
19
- t.src = e;
20
- else if (P.isSupported()) {
21
- const r = new P({
50
+ const l = E(null), a = E(null), d = E(null), [c, v] = D(null), { src: m, muted: R = !0, objectFit: S = "cover", volume: t = 1 } = N, i = E(!1), [h, b] = D(!1), p = E(null), P = E(null), y = M();
51
+ f(() => (y && r && y.registerAsset(r, "Video"), () => {
52
+ y && r && y.unregisterAsset(r);
53
+ }), [r, y]), f(() => {
54
+ y && r && y.setAssetReady(r, h, s);
55
+ }, [r, y, h, s]), f(() => {
56
+ c && y && r && y.setAssetReady(r, !0, s);
57
+ }, [c, y, r, s]), f(() => {
58
+ const e = l.current;
59
+ if (!e || !m) return;
60
+ if (v(null), i.current = !1, b(!1), a.current && (a.current.destroy(), a.current = null), m.includes(".m3u8") || m.includes("application/x-mpegURL"))
61
+ if (e.canPlayType("application/vnd.apple.mpegurl"))
62
+ e.src = m;
63
+ else if (_.isSupported()) {
64
+ const o = new _({
22
65
  enableWorker: !0,
23
66
  lowLatencyMode: !0
24
67
  });
25
- r.loadSource(e), r.attachMedia(t), n.current = r, r.on(P.Events.ERROR, (M, b) => {
26
- b.fatal && (console.warn(
68
+ o.loadSource(m), o.attachMedia(e), a.current = o, o.on(_.Events.ERROR, (T, w) => {
69
+ w.fatal && (console.warn(
27
70
  "[PlaylistVideo] Fatal HLS error encountered:",
28
- b.type
29
- ), f(`HLS stream error: ${b.details}`));
71
+ w.type
72
+ ), v(`HLS stream error: ${w.details}`));
30
73
  });
31
74
  } else
32
- f("HLS playback is not supported in this environment");
75
+ v("HLS playback is not supported in this environment");
33
76
  else
34
- t.src = e;
77
+ e.src = m;
35
78
  return () => {
36
- n.current && (n.current.destroy(), n.current = null);
79
+ e && (e.pause(), e.src = "", e.load()), a.current && (a.current.destroy(), a.current = null);
37
80
  };
38
- }, [e]), E(() => {
39
- const t = c.current;
40
- if (!t || s) return;
41
- if (a && d)
42
- t.muted = i, t.volume = x, u.current = t.play(), u.current.catch((r) => {
43
- console.warn("[PlaylistVideo] Play request prevented:", r);
81
+ }, [m]), f(() => {
82
+ const e = l.current;
83
+ if (!e) return;
84
+ const n = () => {
85
+ if (p.current && (clearTimeout(p.current), p.current = null), P.current !== null) {
86
+ const T = P.current;
87
+ P.current = null;
88
+ try {
89
+ e.currentTime = T;
90
+ } catch {
91
+ }
92
+ return;
93
+ }
94
+ e.readyState >= 3 && b(!0);
95
+ }, o = () => {
96
+ p.current || (p.current = setTimeout(() => {
97
+ b(!1), p.current = null;
98
+ }, 300));
99
+ };
100
+ return e.addEventListener("canplay", n), e.addEventListener("canplaythrough", n), e.addEventListener("playing", n), e.addEventListener("progress", n), e.addEventListener("seeked", n), e.addEventListener("waiting", o), e.addEventListener("stalled", o), e.addEventListener("seeking", o), e.addEventListener("loadstart", o), e.addEventListener("emptied", o), n(), () => {
101
+ p.current && clearTimeout(p.current), e.removeEventListener("canplay", n), e.removeEventListener("canplaythrough", n), e.removeEventListener("playing", n), e.removeEventListener("progress", n), e.removeEventListener("seeked", n), e.removeEventListener("waiting", o), e.removeEventListener("stalled", o), e.removeEventListener("seeking", o), e.removeEventListener("loadstart", o), e.removeEventListener("emptied", o);
102
+ };
103
+ }, [m]), f(() => {
104
+ const e = l.current;
105
+ if (!e || c) return;
106
+ if (s && u && h)
107
+ e.muted = R, e.volume = t, d.current = e.play(), d.current.catch((o) => {
108
+ console.warn("[PlaylistVideo] Play request prevented:", o);
44
109
  });
45
110
  else {
46
- const r = () => {
47
- t.pause(), a || (t.currentTime = 0);
111
+ const o = () => {
112
+ e.pause(), s || (e.currentTime = 0);
48
113
  };
49
- u.current ? u.current.then(r).catch(r) : r();
114
+ d.current ? d.current.then(o).catch(o) : o();
50
115
  }
51
- }, [a, d, i, x, s]), w(p, "change", (t) => {
52
- const o = c.current;
53
- if (!o || !a || o.readyState < 1) return;
54
- const r = Math.max(0, (t - R) / 1e3);
55
- if (Math.abs(o.currentTime - r) > 0.3)
56
- try {
57
- o.currentTime = r;
58
- } catch {
116
+ }, [s, u, h, R, t, c]);
117
+ const x = E(0);
118
+ return O(L, "change", (e) => {
119
+ const n = l.current;
120
+ if (!n || !s || n.readyState < 1) {
121
+ x.current = e;
122
+ return;
123
+ }
124
+ const o = Math.max(0, (e - g) / 1e3), T = Math.abs(e - x.current);
125
+ let w = o;
126
+ n.duration && !isNaN(n.duration) && n.duration > 0 && (w = o % n.duration);
127
+ const H = Math.abs(n.currentTime - w), j = (I) => {
128
+ if (n.seeking)
129
+ P.current = I;
130
+ else {
131
+ P.current = null;
132
+ try {
133
+ n.currentTime = I;
134
+ } catch {
135
+ }
59
136
  }
60
- }), /* @__PURE__ */ v("div", { className: "relative w-full h-full bg-surface-container-low flex items-center justify-center overflow-hidden", children: [
61
- s && /* @__PURE__ */ v("div", { className: "absolute inset-0 z-20 flex flex-col items-center justify-center p-4 bg-error-container/20 text-center", children: [
62
- /* @__PURE__ */ y("span", { className: "text-xs font-semibold text-error mb-1", children: "Playback Error" }),
63
- /* @__PURE__ */ y("span", { className: "text-[10px] text-on-error-container opacity-80 max-w-[80%] leading-normal", children: s })
137
+ };
138
+ u ? (T > 1e3 || e < x.current || H > 0.25) && j(w) : H > 0.1 && j(w), x.current = e;
139
+ }), /* @__PURE__ */ V("div", { className: "relative w-full h-full bg-surface-container-low flex items-center justify-center overflow-hidden", children: [
140
+ c && /* @__PURE__ */ V("div", { className: "absolute inset-0 z-20 flex flex-col items-center justify-center p-4 bg-error-container/20 text-center", children: [
141
+ /* @__PURE__ */ k("span", { className: "text-xs font-semibold text-error mb-1", children: "Playback Error" }),
142
+ /* @__PURE__ */ k("span", { className: "text-[10px] text-on-error-container opacity-80 max-w-[80%] leading-normal", children: c })
64
143
  ] }),
65
- /* @__PURE__ */ y(
144
+ s && u && !h && !c && /* @__PURE__ */ k("div", { className: "absolute inset-0 z-10 flex items-center justify-center bg-black/15", children: /* @__PURE__ */ k(
145
+ J,
146
+ {
147
+ variant: "material-morph",
148
+ className: "!w-20vw !h-20vh text-primary"
149
+ }
150
+ ) }),
151
+ /* @__PURE__ */ k(
66
152
  "video",
67
153
  {
68
- ref: c,
69
- onError: (t) => {
70
- const o = t.target.error;
71
- let r = "An unknown media error occurred.";
72
- if (o)
73
- switch (o.code) {
74
- case o.MEDIA_ERR_ABORTED:
75
- r = "Video loading aborted.";
154
+ ref: l,
155
+ onError: (e) => {
156
+ const n = e.target.error;
157
+ let o = "An unknown media error occurred.";
158
+ if (n)
159
+ switch (n.code) {
160
+ case n.MEDIA_ERR_ABORTED:
161
+ o = "Video loading aborted.";
76
162
  break;
77
- case o.MEDIA_ERR_NETWORK:
78
- r = "Network error prevented video download.";
163
+ case n.MEDIA_ERR_NETWORK:
164
+ o = "Network error prevented video download.";
79
165
  break;
80
- case o.MEDIA_ERR_DECODE:
81
- r = "Video corrupted or decoding failed.";
166
+ case n.MEDIA_ERR_DECODE:
167
+ o = "Video corrupted or decoding failed.";
82
168
  break;
83
- case o.MEDIA_ERR_SRC_NOT_SUPPORTED:
84
- r = "Failed to load: Video format or source url is not supported.";
169
+ case n.MEDIA_ERR_SRC_NOT_SUPPORTED:
170
+ o = "Failed to load: Video format or source url is not supported.";
85
171
  break;
86
172
  }
87
- f(r);
173
+ v(o);
88
174
  },
89
- className: D(
175
+ className: A(
90
176
  "w-full h-full border-0 outline-none transition-opacity duration-300",
91
- s ? "opacity-0" : "opacity-100",
92
- l === "contain" ? "object-contain" : "object-cover"
177
+ c ? "opacity-0" : "opacity-100",
178
+ S === "contain" ? "object-contain" : "object-cover"
93
179
  ),
94
180
  preload: "auto",
95
- muted: i,
181
+ muted: R,
96
182
  playsInline: !0
97
183
  }
98
184
  )
99
185
  ] });
100
- }, T = ({
101
- data: m,
102
- isActive: a,
103
- isTimelinePlaying: d,
104
- playhead: p,
105
- startTime: R
186
+ }, C = ({
187
+ id: r,
188
+ data: N,
189
+ isActive: s,
190
+ isTimelinePlaying: u,
191
+ playhead: L,
192
+ startTime: g,
193
+ isSeeking: l = !1
106
194
  }) => {
107
- const c = h(null), n = h(null), { src: u, muted: s = !1, volume: f = 1 } = m;
108
- return E(() => {
109
- const e = c.current;
110
- !e || !u || (e.src = u);
111
- }, [u]), E(() => {
112
- const e = c.current;
113
- if (!e) return;
114
- if (a && d)
115
- e.muted = s, e.volume = f, n.current = e.play(), n.current.catch((l) => {
116
- console.warn("[PlaylistAudio] Play request prevented:", l);
117
- });
118
- else {
119
- const l = () => {
120
- e.pause(), a || (e.currentTime = 0);
121
- };
122
- n.current ? n.current.then(l).catch(l) : l();
195
+ const a = E(null), d = E(null), { src: c, muted: v = !1, volume: m = 1 } = N, R = M();
196
+ f(() => {
197
+ const t = new Audio();
198
+ return t.preload = "auto", a.current = t, () => {
199
+ a.current && (a.current.pause(), a.current.src = ""), a.current = null;
200
+ };
201
+ }, []), f(() => (R && r && (R.registerAsset(r, "Audio"), R.setAssetReady(r, !0, s)), () => {
202
+ R && r && R.unregisterAsset(r);
203
+ }), [r, R, s]), f(() => {
204
+ const t = a.current;
205
+ !t || !c || (t.src = c, t.load());
206
+ }, [c]), f(() => {
207
+ const t = a.current;
208
+ if (!t) return;
209
+ s && u && !l ? (t.muted = v, t.volume = m, t.play().then(() => {
210
+ console.log("[PlaylistAudio] Playback started successfully!");
211
+ }).catch((h) => {
212
+ console.warn("[PlaylistAudio] Playback blocked:", h);
213
+ })) : (t.pause(), s || (t.currentTime = 0));
214
+ }, [s, u, v, m, l]), f(() => {
215
+ const t = a.current;
216
+ if (!t) return;
217
+ const i = () => {
218
+ if (d.current !== null) {
219
+ const h = d.current;
220
+ d.current = null;
221
+ try {
222
+ t.currentTime = h;
223
+ } catch (b) {
224
+ console.log(b);
225
+ }
226
+ }
227
+ };
228
+ return t.addEventListener("seeked", i), () => {
229
+ t.removeEventListener("seeked", i);
230
+ };
231
+ }, [c]), f(() => {
232
+ const t = a.current;
233
+ if (!t || l) return;
234
+ const i = L.get(), h = Math.max(0, (i - g) / 1e3);
235
+ let b = h;
236
+ t.duration && !isNaN(t.duration) && t.duration > 0 && (b = h % t.duration);
237
+ try {
238
+ t.currentTime = b;
239
+ } catch {
240
+ }
241
+ }, [l, s, g, L]);
242
+ const S = E(0);
243
+ return O(L, "change", (t) => {
244
+ const i = a.current;
245
+ if (!i || !s || i.readyState < 1 || l) {
246
+ S.current = t;
247
+ return;
123
248
  }
124
- }, [a, d, s, f]), w(p, "change", (e) => {
125
- const i = c.current;
126
- if (!i || !a || i.readyState < 1) return;
127
- const l = Math.max(0, (e - R) / 1e3);
128
- if (Math.abs(i.currentTime - l) > 0.3)
129
- try {
130
- i.currentTime = l;
131
- } catch {
249
+ const h = Math.max(0, (t - g) / 1e3), b = Math.abs(t - S.current);
250
+ let p = h;
251
+ i.duration && !isNaN(i.duration) && i.duration > 0 && (p = h % i.duration);
252
+ const P = Math.abs(i.currentTime - p), y = (x) => {
253
+ if (i.seeking)
254
+ d.current = x;
255
+ else {
256
+ d.current = null;
257
+ try {
258
+ i.currentTime = x;
259
+ } catch {
260
+ }
132
261
  }
133
- }), /* @__PURE__ */ y(
134
- "audio",
262
+ };
263
+ u ? (b > 1e3 || t < S.current || P > 0.25) && y(p) : P > 0.1 && y(p), S.current = t;
264
+ }), null;
265
+ }, W = ({
266
+ id: r,
267
+ data: N,
268
+ isActive: s
269
+ }) => {
270
+ const { src: u, alt: L, objectFit: g = "cover" } = N, l = M(), a = E(null), [d, c] = D(!1);
271
+ return f(() => (l && r && l.registerAsset(r, "Image"), () => {
272
+ l && r && l.unregisterAsset(r);
273
+ }), [r, l]), f(() => {
274
+ l && r && l.setAssetReady(r, d, s);
275
+ }, [r, l, d, s]), f(() => {
276
+ a.current?.complete ? c(!0) : c(!1);
277
+ }, [u]), /* @__PURE__ */ k(
278
+ "img",
135
279
  {
136
- ref: c,
137
- preload: "auto",
138
- muted: s,
139
- style: { display: "none" }
280
+ ref: a,
281
+ src: u,
282
+ alt: L || "Playlist Image",
283
+ onLoad: () => {
284
+ c(!0);
285
+ },
286
+ onError: () => {
287
+ c(!0);
288
+ },
289
+ className: "w-full h-full border-0 block select-none pointer-events-none",
290
+ style: { objectFit: g }
140
291
  }
141
292
  );
142
- }, _ = ({ data: m }) => {
143
- const { src: a, alt: d, objectFit: p = "cover" } = m;
144
- return /* @__PURE__ */ y(
145
- "img",
293
+ }, z = ({
294
+ id: r,
295
+ data: N,
296
+ isActive: s
297
+ }) => {
298
+ const u = M(), { tag: L = "div", html: g, children: l, className: a, style: d, ...c } = N;
299
+ f(() => (u && r && (u.registerAsset(r, "Html"), u.setAssetReady(r, !0, s)), () => {
300
+ u && r && u.unregisterAsset(r);
301
+ }), [r, u, s]);
302
+ const v = typeof L == "string" ? L.toLowerCase() : "div", m = q.has(v) ? v : "div";
303
+ return g && typeof g == "string" ? /* @__PURE__ */ k(
304
+ m,
146
305
  {
147
- src: a,
148
- alt: d || "Playlist Image",
149
- className: "w-full h-full border-0 block select-none pointer-events-none",
150
- style: { objectFit: p }
306
+ className: A("w-full h-full overflow-hidden", a),
307
+ style: d,
308
+ dangerouslySetInnerHTML: { __html: g },
309
+ ...c
310
+ }
311
+ ) : /* @__PURE__ */ k(
312
+ m,
313
+ {
314
+ className: A("w-full h-full overflow-hidden", a),
315
+ style: d,
316
+ ...c,
317
+ children: l
151
318
  }
152
319
  );
153
- }, L = {
154
- Video: S,
155
- Audio: T,
156
- Image: _
320
+ }, re = {
321
+ Video: B,
322
+ Audio: C,
323
+ Image: W,
324
+ Html: z
157
325
  };
158
326
  export {
159
- T as PlaylistAudio,
160
- _ as PlaylistImage,
161
- S as PlaylistVideo,
162
- L as defaultPlaylistRegistry
327
+ C as PlaylistAudio,
328
+ z as PlaylistHtml,
329
+ W as PlaylistImage,
330
+ B as PlaylistVideo,
331
+ re as defaultPlaylistRegistry
163
332
  };
@@ -1,5 +1,6 @@
1
1
  export { usePlayhead } from './use-playhead';
2
2
  export { PlaylistPlayer } from './player';
3
+ export { PreloadContext, usePreload } from './preload-context';
3
4
  export * from './elements';
4
5
  export * from './types';
5
6
  export declare const PlaylistStudio: {
@@ -5,6 +5,7 @@ interface ItemRendererProps {
5
5
  playhead: any;
6
6
  components: PlaylistComponentRegistry;
7
7
  isTimelinePlaying: boolean;
8
+ isSeeking?: boolean;
8
9
  }
9
- export declare const ItemRenderer: React.MemoExoticComponent<({ item, playhead, components, isTimelinePlaying }: ItemRendererProps) => import("react/jsx-runtime").JSX.Element | null>;
10
+ export declare const ItemRenderer: React.MemoExoticComponent<({ item, playhead, components, isTimelinePlaying, isSeeking, }: ItemRendererProps) => import("react/jsx-runtime").JSX.Element | null>;
10
11
  export {};