@poolse/react-ui 2.13.0 → 2.14.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.
package/dist/index.js CHANGED
@@ -282,7 +282,12 @@ function userColor(userId) {
282
282
  }
283
283
  return PALETTE[Math.abs(h) % PALETTE.length];
284
284
  }
285
- function CallVideoGrid({ participants, labelFor, className }) {
285
+ function CallVideoGrid({
286
+ participants,
287
+ labelFor,
288
+ className,
289
+ onLocalClick
290
+ }) {
286
291
  const label = labelFor ?? ((id) => `User ${id.slice(0, 6)}`);
287
292
  const self = participants.find((p) => p.isSelf) ?? null;
288
293
  const others = useMemo(() => participants.filter((p) => !p.isSelf), [participants]);
@@ -292,7 +297,7 @@ function CallVideoGrid({ participants, labelFor, className }) {
292
297
  if (!spotlight) return null;
293
298
  return /* @__PURE__ */ jsxs("div", { className: className ?? "callstage callstage--solo", children: [
294
299
  /* @__PURE__ */ jsx(CallVideoTile, { participant: spotlight, label, bleed: true }),
295
- self && others.length === 1 && /* @__PURE__ */ jsx("div", { className: "callstage__pip", children: /* @__PURE__ */ jsx(CallVideoTile, { participant: self, label, hideName: true }) })
300
+ self && others.length === 1 && /* @__PURE__ */ jsx(FloatingSelf, { onClick: onLocalClick, children: /* @__PURE__ */ jsx(CallVideoTile, { participant: self, label, hideName: true }) })
296
301
  ] });
297
302
  }
298
303
  const tiles = [...others, ...self ? [self] : []];
@@ -336,7 +341,24 @@ function CallVideoTile({
336
341
  autoPlay: true,
337
342
  playsInline: true,
338
343
  muted: participant.isSelf,
339
- style: participant.isSelf ? { transform: "scaleX(-1)" } : void 0
344
+ style: {
345
+ // `contain` for the spotlight, `cover` for everything else,
346
+ // and set here rather than left to host CSS because it is
347
+ // behaviour rather than theme.
348
+ //
349
+ // A phone publishes portrait video. Cropping that to fill a
350
+ // landscape browser window — which is what `cover` does —
351
+ // throws away most of the frame and lands somewhere around
352
+ // the caller's nose. Letterboxing shows the picture they
353
+ // are actually sending. Fixed-ratio tiles keep `cover`,
354
+ // where the crop is slight and the alternative is a grid
355
+ // full of pillarboxed slivers.
356
+ objectFit: bleed ? "contain" : "cover",
357
+ // Mirrored only for yourself — mirroring a remote feed would
358
+ // flip their text and reverse which hand they are waving
359
+ // with.
360
+ ...participant.isSelf ? { transform: "scaleX(-1)" } : {}
361
+ }
340
362
  }
341
363
  ) : /* @__PURE__ */ jsx("div", { className: "callgrid__placeholder", children: /* @__PURE__ */ jsx(
342
364
  "span",
@@ -353,12 +375,171 @@ function CallVideoTile({
353
375
  ] })
354
376
  ] });
355
377
  }
378
+ function FloatingSelf({
379
+ children,
380
+ onClick
381
+ }) {
382
+ const ref = useRef(null);
383
+ const [corner, setCorner] = useState(1);
384
+ const [drag, setDrag] = useState(null);
385
+ const origin = useRef(null);
386
+ const moved = useRef(false);
387
+ const onPointerDown = useCallback((event) => {
388
+ origin.current = { x: event.clientX, y: event.clientY };
389
+ moved.current = false;
390
+ event.currentTarget.setPointerCapture(event.pointerId);
391
+ }, []);
392
+ const onPointerMove = useCallback((event) => {
393
+ const from = origin.current;
394
+ if (!from) return;
395
+ const dx = event.clientX - from.x;
396
+ const dy = event.clientY - from.y;
397
+ if (!moved.current && Math.abs(dx) < 4 && Math.abs(dy) < 4) return;
398
+ moved.current = true;
399
+ setDrag({ x: dx, y: dy });
400
+ }, []);
401
+ const onPointerUp = useCallback(
402
+ (event) => {
403
+ const from = origin.current;
404
+ origin.current = null;
405
+ setDrag(null);
406
+ if (!moved.current) {
407
+ onClick?.();
408
+ return;
409
+ }
410
+ if (!from) return;
411
+ const stage = ref.current?.parentElement?.getBoundingClientRect();
412
+ if (!stage) return;
413
+ const right = event.clientX > stage.left + stage.width / 2;
414
+ const bottom = event.clientY > stage.top + stage.height / 2;
415
+ setCorner((bottom ? 2 : 0) + (right ? 1 : 0));
416
+ },
417
+ [onClick]
418
+ );
419
+ return /* @__PURE__ */ jsx(
420
+ "div",
421
+ {
422
+ ref,
423
+ className: `callstage__pip callstage__pip--c${corner}${drag ? " callstage__pip--dragging" : ""}`,
424
+ style: drag ? { transform: `translate(${drag.x}px, ${drag.y}px)` } : void 0,
425
+ onPointerDown,
426
+ onPointerMove,
427
+ onPointerUp,
428
+ onPointerCancel: onPointerUp,
429
+ role: onClick ? "button" : void 0,
430
+ "aria-label": onClick ? "Your camera. Drag to move, click to switch camera." : void 0,
431
+ children
432
+ }
433
+ );
434
+ }
356
435
  function initialsOf(name) {
357
436
  const parts = name.trim().split(/\s+/).filter(Boolean);
358
437
  if (parts.length === 0) return "?";
359
438
  if (parts.length === 1) return parts[0].slice(0, 2).toUpperCase();
360
439
  return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase();
361
440
  }
441
+ function CallControlButton({
442
+ icon,
443
+ label,
444
+ onClick,
445
+ active = false,
446
+ tone = "neutral",
447
+ large = false,
448
+ disabled = false,
449
+ hasMenu = false,
450
+ onMenuClick
451
+ }) {
452
+ const classes = [
453
+ "callbtn",
454
+ tone !== "neutral" ? `callbtn--${tone}` : "",
455
+ active ? "callbtn--active" : "",
456
+ large ? "callbtn--large" : ""
457
+ ].filter(Boolean).join(" ");
458
+ return /* @__PURE__ */ jsxs("span", { className: "callbtn__slot", children: [
459
+ /* @__PURE__ */ jsxs("span", { className: "callbtn__wrap", children: [
460
+ /* @__PURE__ */ jsx(
461
+ "button",
462
+ {
463
+ type: "button",
464
+ className: classes,
465
+ onClick,
466
+ disabled,
467
+ "aria-pressed": tone === "neutral" ? active : void 0,
468
+ "aria-label": label,
469
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: icon, size: large ? 26 : 22, label: null })
470
+ }
471
+ ),
472
+ hasMenu && // A separate hit target, not a long-press: the toggle and the
473
+ // device list are different actions, and hiding one inside a
474
+ // timed gesture on the other is how people end up muting
475
+ // themselves while trying to change microphone.
476
+ /* @__PURE__ */ jsx(
477
+ "button",
478
+ {
479
+ type: "button",
480
+ className: "callbtn__caret",
481
+ onClick: onMenuClick,
482
+ "aria-label": `${label} options`,
483
+ children: /* @__PURE__ */ jsx(PoolseIcon, { name: "chevron-up", size: 13, label: null })
484
+ }
485
+ )
486
+ ] }),
487
+ /* @__PURE__ */ jsx("span", { className: "callbtn__label", children: label })
488
+ ] });
489
+ }
490
+ function CallDeviceMenu({
491
+ title,
492
+ devices,
493
+ activeId,
494
+ onSelect,
495
+ onClose
496
+ }) {
497
+ const ref = useRef(null);
498
+ useEffect(() => {
499
+ const onDown = (event) => {
500
+ if (!ref.current?.contains(event.target)) onClose();
501
+ };
502
+ const onKey = (event) => {
503
+ if (event.key === "Escape") onClose();
504
+ };
505
+ document.addEventListener("mousedown", onDown);
506
+ document.addEventListener("keydown", onKey);
507
+ return () => {
508
+ document.removeEventListener("mousedown", onDown);
509
+ document.removeEventListener("keydown", onKey);
510
+ };
511
+ }, [onClose]);
512
+ if (devices.length === 0) return null;
513
+ return /* @__PURE__ */ jsxs("div", { className: "calldevices", ref, role: "menu", "aria-label": title, children: [
514
+ /* @__PURE__ */ jsx("p", { className: "calldevices__title", children: title }),
515
+ devices.map((device, index) => {
516
+ const selected = device.deviceId === activeId;
517
+ return /* @__PURE__ */ jsxs(
518
+ "button",
519
+ {
520
+ type: "button",
521
+ role: "menuitemradio",
522
+ "aria-checked": selected,
523
+ className: `calldevices__row${selected ? " calldevices__row--on" : ""}`,
524
+ onClick: () => {
525
+ onSelect(device.kind, device.deviceId);
526
+ onClose();
527
+ },
528
+ children: [
529
+ /* @__PURE__ */ jsx("span", { className: "calldevices__name", children: device.label || `${kindLabel(device.kind)} ${index + 1}` }),
530
+ selected && /* @__PURE__ */ jsx(PoolseIcon, { name: "check", size: 16, label: "selected" })
531
+ ]
532
+ },
533
+ device.deviceId || `${device.kind}-${index}`
534
+ );
535
+ })
536
+ ] });
537
+ }
538
+ function kindLabel(kind) {
539
+ if (kind === "videoinput") return "Camera";
540
+ if (kind === "audioinput") return "Microphone";
541
+ return "Output";
542
+ }
362
543
  var FONT_HREF = "https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,400;12..96,600;12..96,800&family=Hanken+Grotesk:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap";
363
544
  var FONT_HREF_PRECONNECT_GOOGLE = "https://fonts.googleapis.com";
364
545
  var FONT_HREF_PRECONNECT_STATIC = "https://fonts.gstatic.com";
@@ -3124,6 +3305,6 @@ function PoolseLogo({
3124
3305
  );
3125
3306
  }
3126
3307
 
3127
- export { AttachmentPreview, Avatar, CallVideoGrid, ChatHeader, ConversationList, ConversationView, EditableMessageBubble, GroupDetailsSheet, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseInbox, PoolseLogo, ReactionPicker, ReactionStrip, ThreadView, TypingIndicator, UploadQueueStrip, UserName, UserPickerSheet, useDisplayName, usePoolseFonts };
3308
+ export { AttachmentPreview, Avatar, CallControlButton, CallDeviceMenu, CallVideoGrid, ChatHeader, ConversationList, ConversationView, EditableMessageBubble, GroupDetailsSheet, MemberList, MentionInput, MessageActions, MessageBubble, MessageComposer, PoolseFonts, PoolseIcon, PoolseInbox, PoolseLogo, ReactionPicker, ReactionStrip, ThreadView, TypingIndicator, UploadQueueStrip, UserName, UserPickerSheet, useDisplayName, usePoolseFonts };
3128
3309
  //# sourceMappingURL=index.js.map
3129
3310
  //# sourceMappingURL=index.js.map