liveroom-client-element 0.1.1 → 0.2.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.
@@ -1,4 +1,4 @@
1
- import { c as e, l as t, u as n } from "./constants-Bev8DzXl.js";
1
+ import { c as e, l as t, u as n } from "./constants-zXjdB6PO.js";
2
2
  // ../packages/core/src/protocol.ts
3
3
  var r = {
4
4
  mouseDown: 1,
@@ -249,11 +249,11 @@ var r = {
249
249
  static appendParams(e, t) {
250
250
  return Object.keys(t).length === 0 ? e : `${e}${e.match(/\?/) ? "&" : "?"}${this.serialize(t)}`;
251
251
  }
252
- }, w = (e) => {
252
+ }, ee = (e) => {
253
253
  let t = "", n = new Uint8Array(e), r = n.byteLength;
254
254
  for (let e = 0; e < r; e++) t += String.fromCharCode(n[e]);
255
255
  return btoa(t);
256
- }, T = class {
256
+ }, w = class {
257
257
  constructor(e, t) {
258
258
  t && t.length === 2 && t[1].startsWith(y) && (this.authToken = atob(t[1].slice(y.length))), this.endPoint = null, this.token = null, this.skipHeartbeat = !0, this.reqs = /* @__PURE__ */ new Set(), this.messageTimers = /* @__PURE__ */ new Set(), this.awaitingBatchAck = !1, this.currentBatch = null, this.currentBatchTimer = null, this.batchBuffer = [], this.onopen = function() {}, this.onerror = function() {}, this.onmessage = function() {}, this.onclose = function() {}, this.pollEndpoint = this.normalizeEndpoint(e), this.readyState = d.connecting, setTimeout(() => this.poll(), 0);
259
259
  }
@@ -311,7 +311,7 @@ var r = {
311
311
  });
312
312
  }
313
313
  send(e) {
314
- typeof e != "string" && (e = w(e)), this.currentBatch ? this.currentBatch.push(e) : this.awaitingBatchAck ? this.batchBuffer.push(e) : (this.currentBatch = [e], this.currentBatchTimer = setTimeout(() => {
314
+ typeof e != "string" && (e = ee(e)), this.currentBatch ? this.currentBatch.push(e) : this.awaitingBatchAck ? this.batchBuffer.push(e) : (this.currentBatch = [e], this.currentBatchTimer = setTimeout(() => {
315
315
  this.batchSend(this.currentBatch), this.currentBatch = null;
316
316
  }, 0));
317
317
  }
@@ -349,7 +349,7 @@ var r = {
349
349
  this.reqs.delete(a) && i(e);
350
350
  });
351
351
  }
352
- }, E = {
352
+ }, T = {
353
353
  HEADER_LENGTH: 1,
354
354
  META_LENGTH: 4,
355
355
  KINDS: {
@@ -449,7 +449,7 @@ var r = {
449
449
  payload: e.slice(a, e.byteLength)
450
450
  };
451
451
  }
452
- }, D = class {
452
+ }, E = class {
453
453
  constructor(e, t) {
454
454
  this.socket = e, this.transport = t, this.joins = /* @__PURE__ */ new WeakMap(), this.pings = /* @__PURE__ */ new Map(), this.closing = !1, this.ended = !1, this.channelsErrored = !1, this.closeHandled = !1, t.onopen = () => {
455
455
  this.isCurrent() && e.onConnOpen();
@@ -476,14 +476,14 @@ var r = {
476
476
  close(e, t) {
477
477
  this.closing = !0, this.transport.onerror = function() {}, e ? this.transport.close(e, t || "") : this.transport.close();
478
478
  }
479
- }, O = class {
479
+ }, D = class {
480
480
  constructor(e, t = {}) {
481
481
  this.stateChangeCallbacks = {
482
482
  open: [],
483
483
  close: [],
484
484
  error: [],
485
485
  message: []
486
- }, this.channels = [], this.sendBuffer = [], this.ref = 0, this.fallbackRef = null, this.fallbackErrorRef = null, this.timeout = t.timeout || p, this.transport = t.transport || l.WebSocket || T, this.primaryPassedHealthCheck = !1, this.longPollFallbackMs = t.longPollFallbackMs, this.fallbackTimer = null, this.sessionStore = t.sessionStorage || l && l.sessionStorage, this.establishedConnections = 0, this.defaultEncoder = E.encode.bind(E), this.defaultDecoder = E.decode.bind(E), this.closeWasClean = !0, this.binaryType = t.binaryType || "arraybuffer", this.connection = null, this.connectClock = 1, this.visibilityConnection = null, this.transport === T ? (this.encode = this.defaultEncoder, this.decode = this.defaultDecoder) : (this.encode = t.encode || this.defaultEncoder, this.decode = t.decode || this.defaultDecoder);
486
+ }, this.channels = [], this.sendBuffer = [], this.ref = 0, this.fallbackRef = null, this.fallbackErrorRef = null, this.timeout = t.timeout || p, this.transport = t.transport || l.WebSocket || w, this.primaryPassedHealthCheck = !1, this.longPollFallbackMs = t.longPollFallbackMs, this.fallbackTimer = null, this.sessionStore = t.sessionStorage || l && l.sessionStorage, this.establishedConnections = 0, this.defaultEncoder = T.encode.bind(T), this.defaultDecoder = T.decode.bind(T), this.closeWasClean = !0, this.binaryType = t.binaryType || "arraybuffer", this.connection = null, this.connectClock = 1, this.visibilityConnection = null, this.transport === w ? (this.encode = this.defaultEncoder, this.decode = this.defaultDecoder) : (this.encode = t.encode || this.defaultEncoder, this.decode = t.decode || this.defaultDecoder);
487
487
  let n = null;
488
488
  c && c.addEventListener && (c.addEventListener("pagehide", (e) => {
489
489
  this.connection && !this.connection.ended && (this.disconnect(), n = this.connectClock);
@@ -530,7 +530,7 @@ var r = {
530
530
  }));
531
531
  }
532
532
  getLongPollTransport() {
533
- return T;
533
+ return w;
534
534
  }
535
535
  replaceTransport(e) {
536
536
  let t = ++this.connectClock;
@@ -553,7 +553,7 @@ var r = {
553
553
  this.connectClock++, this.closeWasClean = !0, clearTimeout(this.fallbackTimer), this.reconnectTimer.reset(), this.connection && (this.connection.ended = !0), this.teardown(e, t, n);
554
554
  }
555
555
  connect(e) {
556
- e && (console && console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor"), this.params = o(e)), (!this.connection || this.connection.ended) && (this.longPollFallbackMs && this.transport !== T ? this.connectWithFallback(T, this.longPollFallbackMs) : this.transportConnect());
556
+ e && (console && console.log("passing params to connect is deprecated. Instead pass :params to the Socket constructor"), this.params = o(e)), (!this.connection || this.connection.ended) && (this.longPollFallbackMs && this.transport !== w ? this.connectWithFallback(w, this.longPollFallbackMs) : this.transportConnect());
557
557
  }
558
558
  log(e, t, n) {
559
559
  this.logger && this.logger(e, t, n);
@@ -589,7 +589,7 @@ var r = {
589
589
  }
590
590
  transportName(e) {
591
591
  switch (e) {
592
- case T: return "LongPoll";
592
+ case w: return "LongPoll";
593
593
  default: return e.name;
594
594
  }
595
595
  }
@@ -599,7 +599,7 @@ var r = {
599
599
  let t;
600
600
  this.authToken && (t = ["phoenix", `${y}${btoa(this.authToken()).replace(/=/g, "")}`]);
601
601
  let n = new this.transport(this.endPointURL(), t);
602
- n.binaryType = this.binaryType, n.timeout = this.longpollerTimeout, this.connection = new D(this, n), e && e.isOpen() && this.triggerChanError("connection_closed", e);
602
+ n.binaryType = this.binaryType, n.timeout = this.longpollerTimeout, this.connection = new E(this, n), e && e.isOpen() && this.triggerChanError("connection_closed", e);
603
603
  }
604
604
  getSession(e) {
605
605
  return this.sessionStore && this.sessionStore.getItem(e);
@@ -778,7 +778,7 @@ var r = {
778
778
  let t = this.channels.find((t) => t.topic === e && (t.isJoined() || t.isJoining()));
779
779
  t && (this.hasLogger() && this.log("transport", `leaving duplicate topic "${e}"`), t.leave());
780
780
  }
781
- }, k = 1e3, A = 1e3, j = 150, ee = 2, te = 3e4, ne = 1e4, M = 60, N = class {
781
+ }, O = 1e3, k = 1e3, A = 150, te = 2, ne = 3e4, re = 1e4, ie = 60, ae = class {
782
782
  probe;
783
783
  onChange;
784
784
  now;
@@ -814,8 +814,8 @@ var r = {
814
814
  let e = this.now(), t = e - this.lastTick;
815
815
  this.lastTick = e, this.quality === "unstable" && (this.unstableMs += t), this.quality === "offline" && (this.offlineMs += t);
816
816
  let n = this.probe.online();
817
- n && !this.wasOnline && (this.everOnline && this.reconnects++, this.everOnline = !0), !n && this.wasOnline && this.endStall(e), this.wasOnline = n, n ? (this.pingSentAt !== null && this.stallSince === null && e - this.pingSentAt >= A && (this.stallSince = this.pingSentAt), this.pingSentAt === null && e - this.lastPingAt >= k && this.sendPing(e)) : this.pingSentAt = null;
818
- let r = n ? this.stallSince !== null || e - this.lastIssueAt < ne || this.recentSlow(e) >= ee ? "unstable" : "good" : this.everOnline ? "offline" : "good";
817
+ n && !this.wasOnline && (this.everOnline && this.reconnects++, this.everOnline = !0), !n && this.wasOnline && this.endStall(e), this.wasOnline = n, n ? (this.pingSentAt !== null && this.stallSince === null && e - this.pingSentAt >= k && (this.stallSince = this.pingSentAt), this.pingSentAt === null && e - this.lastPingAt >= O && this.sendPing(e)) : this.pingSentAt = null;
818
+ let r = n ? this.stallSince !== null || e - this.lastIssueAt < re || this.recentSlow(e) >= te ? "unstable" : "good" : this.everOnline ? "offline" : "good";
819
819
  r !== this.quality && (this.quality = r, this.onChange(r));
820
820
  }
821
821
  report() {
@@ -840,13 +840,13 @@ var r = {
840
840
  this.lastPingAt = e, this.probe.ping((t) => {
841
841
  if (this.pingSentAt !== e) return;
842
842
  let n = this.now();
843
- this.pingSentAt = null, this.pings++, this.rtt = t, this.rtts.push(t), this.rtts.length > M && this.rtts.shift();
843
+ this.pingSentAt = null, this.pings++, this.rtt = t, this.rtts.push(t), this.rtts.length > ie && this.rtts.shift();
844
844
  let [r, i, a] = this.rtts.slice(-3);
845
- a !== void 0 && i >= r + j && i >= a + j && this.slowAt.push(n), this.endStall(n), this.tick();
845
+ a !== void 0 && i >= r + A && i >= a + A && this.slowAt.push(n), this.endStall(n), this.tick();
846
846
  }) && (this.pingSentAt = e);
847
847
  }
848
848
  recentSlow(e) {
849
- for (; this.slowAt.length && e - this.slowAt[0] >= te;) this.slowAt.shift();
849
+ for (; this.slowAt.length && e - this.slowAt[0] >= ne;) this.slowAt.shift();
850
850
  return this.slowAt.length;
851
851
  }
852
852
  endStall(e) {
@@ -854,19 +854,19 @@ var r = {
854
854
  let t = e - this.stallSince;
855
855
  this.stalls++, this.stallMs += t, this.maxStallMs = Math.max(this.maxStallMs, t), this.stallSince = null, this.lastIssueAt = e;
856
856
  }
857
- }, P = [
857
+ }, j = [
858
858
  80,
859
859
  160,
860
860
  320,
861
861
  640,
862
862
  1e3
863
863
  ];
864
- function F(e, t = Math.random) {
865
- let n = P[Math.min(Math.max(e, 1), P.length) - 1], r = Math.round(n * .2), i = Math.min(Math.max(t(), 0), .999999);
864
+ function M(e, t = Math.random) {
865
+ let n = j[Math.min(Math.max(e, 1), j.length) - 1], r = Math.round(n * .2), i = Math.min(Math.max(t(), 0), .999999);
866
866
  return n - r + Math.floor(i * (r * 2 + 1));
867
867
  }
868
868
  // ../packages/core/src/room-client.ts
869
- var I = class {
869
+ var N = class {
870
870
  options;
871
871
  participants = /* @__PURE__ */ new Map();
872
872
  status = "connecting";
@@ -889,6 +889,8 @@ var I = class {
889
889
  reportTimer = null;
890
890
  offPageHide = null;
891
891
  tabs = null;
892
+ control = null;
893
+ serverStop = !1;
892
894
  constructor(e) {
893
895
  this.options = e;
894
896
  }
@@ -907,10 +909,10 @@ var I = class {
907
909
  }
908
910
  connect() {
909
911
  let e = this.options, t = () => this.reportNet();
910
- window.addEventListener("pagehide", t), this.offPageHide = () => window.removeEventListener("pagehide", t), this.socket = new O(e.url, {
912
+ window.addEventListener("pagehide", t), this.offPageHide = () => window.removeEventListener("pagehide", t), this.socket = new D(e.url, {
911
913
  params: e.apiToken ? { api_token: e.apiToken } : {},
912
914
  heartbeatIntervalMs: e.heartbeatMs ?? 5e3,
913
- reconnectAfterMs: (e) => F(e),
915
+ reconnectAfterMs: (e) => M(e),
914
916
  rejoinAfterMs: (e) => [
915
917
  100,
916
918
  500,
@@ -920,7 +922,7 @@ var I = class {
920
922
  logger: e.logger
921
923
  }), this.socket.onClose(() => this.setStatus("disconnected")), this.socket.connect();
922
924
  let n = this.socket;
923
- this.monitor = new N({
925
+ this.monitor = new ae({
924
926
  ping: (e) => n.ping(e),
925
927
  online: () => n.isConnected() && this.status === "joined"
926
928
  }, (e) => {
@@ -932,8 +934,8 @@ var I = class {
932
934
  this.whenResumeIsFree(() => this.join(r)), r.onError(() => this.setStatus("disconnected"));
933
935
  }
934
936
  join(e) {
935
- e === this.channel && e.join().receive("ok", ({ you: e, resume: t }) => {
936
- this.you = e, t && this.storage?.setItem(this.resumeKey, t);
937
+ e === this.channel && e.join().receive("ok", ({ you: e, resume: t, stopped: n }) => {
938
+ this.you = e, t && this.storage?.setItem(this.resumeKey, t), this.serverStop = typeof n == "boolean";
937
939
  }).receive("error", ({ reason: e, code: t }) => {
938
940
  if (t !== "refused") return this.setStatus("disconnected");
939
941
  this.setStatus("refused"), this.emit("refused", e), this.disconnect();
@@ -985,7 +987,7 @@ var I = class {
985
987
  }
986
988
  joinParams() {
987
989
  let e = this.options;
988
- return z({
990
+ return I({
989
991
  v: 2,
990
992
  room_token: e.roomToken,
991
993
  type: e.type,
@@ -1001,7 +1003,7 @@ var I = class {
1001
1003
  onSnapshot(e) {
1002
1004
  this.you = e.you, this.livekit = e.livekit, this.account = e.account, this.participants.clear(), this.bySlot.clear();
1003
1005
  for (let t of Object.values(e.users)) this.put(t);
1004
- this.setStatus("joined"), this.sentCursor = null, this.push("f", this.flags), Object.keys(this.localState).length && this.push("s", this.localState), this.follow !== "all" && this.push("follow", this.follow), this.reportNet(), this.flushMove(), this.emit("snapshot", void 0), this.emit("account", this.account);
1006
+ this.setStatus("joined"), this.sentCursor = null, this.push("f", this.flags), Object.keys(this.localState).length && this.push("s", this.localState), this.follow !== "all" && this.push("follow", this.follow), this.reportNet(), this.flushMove(), this.flushControl(), this.emit("snapshot", void 0), this.emit("account", this.account);
1005
1007
  }
1006
1008
  onPresence(e) {
1007
1009
  let t = Object.values(e.joins).map((e) => (this.put(e), e.id));
@@ -1077,9 +1079,18 @@ var I = class {
1077
1079
  setState(e) {
1078
1080
  e.url && (e = {
1079
1081
  ...e,
1080
- url: R(e.url)
1082
+ url: F(e.url)
1081
1083
  }), Object.assign(this.localState, e), this.push("s", e);
1082
1084
  }
1085
+ stop() {
1086
+ this.control = "stop", this.flushControl();
1087
+ }
1088
+ resume() {
1089
+ this.control = "resume", this.flushControl();
1090
+ }
1091
+ flushControl() {
1092
+ this.control && this.status === "joined" && this.serverStop && (this.push(this.control, {}), this.control = null);
1093
+ }
1083
1094
  click(e) {
1084
1095
  this.flushMove(), this.push("click", {
1085
1096
  to: e,
@@ -1125,19 +1136,19 @@ var I = class {
1125
1136
  setFollow(e) {
1126
1137
  e === this.follow || Array.isArray(e) && Array.isArray(this.follow) && e.length === this.follow.length && e.every((e, t) => e === this.follow[t]) || (this.follow = e, this.push("follow", e));
1127
1138
  }
1128
- }, L = 2048;
1129
- function R(e) {
1130
- return e.length > 2048 ? e.slice(0, L) : e;
1139
+ }, P = 2048;
1140
+ function F(e) {
1141
+ return e.length > 2048 ? e.slice(0, P) : e;
1131
1142
  }
1132
- function z(e) {
1133
- return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, typeof t == "string" ? R(t) : t]));
1143
+ function I(e) {
1144
+ return Object.fromEntries(Object.entries(e).map(([e, t]) => [e, typeof t == "string" ? F(t) : t]));
1134
1145
  }
1135
1146
  // ../packages/core/src/cursor-layer.ts
1136
- var B = "\n.lr-cursors { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 2147483646; }\n.lr-user { position: absolute; top: 0; left: 0; user-select: none; will-change: transform; transform-origin: 0 0; }\n.lr-user[data-hidden=\"true\"] { display: none; }\n.lr-cursor { position: absolute; top: 0; left: 0; color: var(--color); transform-origin: top left; transform: rotate(6deg);\n filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.2)); overflow: visible; }\n/* Cursor colors are light pastels: the contour keeps the arrow visible on white pages.\n The path touches the viewBox's top edge, hence the svg's visible overflow. */\n.lr-cursor path { stroke: rgb(0 0 0 / 0.6); stroke-width: 3; stroke-linejoin: round; paint-order: stroke fill; }\n.lr-label { position: absolute; top: 18px; left: 14px; font: 600 12px/1.6 system-ui, sans-serif; color: black;\n background: var(--color); border-radius: 9999px; padding: 0 8px; white-space: nowrap;\n box-shadow: 0 0 0 1px rgb(0 0 0 / 0.12), 0 1px 2px rgb(0 0 0 / 0.08);\n display: flex; flex-direction: column; align-items: center; overflow: hidden; max-width: 200px; text-overflow: ellipsis; }\n.lr-label video { display: none; width: 170.6667px; height: 96px; object-fit: cover; margin: 0; }\n/* Keep the same 16:9 video surface. The small bubble is a circular crop. */\n.lr-user[data-live=\"true\"] .lr-label, .lr-user[data-focus-motion=\"true\"] .lr-label {\n padding: 0; border-radius: 0; top: 10px; left: -31.3333px; width: 170.6667px; height: 96px;\n background: transparent; box-shadow: none; overflow: visible;\n}\n.lr-user[data-live=\"true\"] .lr-label video, .lr-user[data-focus-motion=\"true\"] .lr-label video {\n display: block; clip-path: inset(0 37.3333px round 48px);\n transition: clip-path 250ms cubic-bezier(0.77, 0, 0.175, 1);\n}\n.lr-user[data-live=\"true\"] .lr-label > span, .lr-user[data-focus-motion=\"true\"] .lr-label > span {\n position: absolute; top: calc(100% + 2px); left: 50%; padding: 2px 8px; border-radius: 9999px;\n background: var(--color); opacity: 0; visibility: hidden;\n transform: translateX(-50%) scale(calc(1 / var(--focus-scale, 1))); transform-origin: top center;\n transition: opacity 200ms ease, visibility 200ms ease;\n}\n.lr-halo { position: absolute; top: -60px; left: -60px; width: 120px; height: 120px; border-radius: 9999px; z-index: -1;\n border: 1px solid color-mix(in srgb, var(--color) 75%, transparent); background: color-mix(in srgb, var(--color) 25%, transparent);\n transform: scale(0); transition: transform 200ms ease-in-out; }\n.lr-user[data-halo=\"true\"] .lr-halo { transform: scale(1); }\n.lr-user[data-self=\"true\"] .lr-cursor, .lr-user[data-self=\"true\"] .lr-label { display: none; }\n.lr-cursors::before { content: \"\"; position: absolute; inset: 0; background: rgb(39 39 42 / 25%); backdrop-filter: blur(6px); opacity: 0; transition: opacity 200ms ease; }\n.lr-cursors[data-focus=\"true\"]::before { opacity: 1; }\n.lr-user[data-focus-motion=\"true\"] { transition: transform 250ms cubic-bezier(0.77, 0, 0.175, 1); }\n.lr-user[data-focus=\"true\"] { transform: translate3d(calc(50vw - 54px * var(--focus-scale)), calc(50vh - 58px * var(--focus-scale)), 0) scale(var(--focus-scale)) !important; z-index: 1; }\n.lr-user[data-focus=\"true\"] .lr-label video { clip-path: inset(0 round 4px); }\n.lr-user[data-focus=\"true\"] .lr-label > span { opacity: 1; visibility: visible; }\n.lr-user[data-focus=\"true\"]:not([data-live=\"true\"]) .lr-label { background: #18181b; border-radius: 4px; }\n.lr-user[data-focus=\"true\"] .lr-cursor, .lr-user[data-focus=\"true\"] .lr-halo { opacity: 0; }\n@media (prefers-reduced-motion: reduce) {\n .lr-user[data-focus-motion=\"true\"], .lr-label video { transition: none !important; }\n .lr-cursors::before, .lr-label > span { transition-duration: 100ms; }\n}\n.lr-user[data-blocked=\"true\"] { opacity: 0.4; }\n/* On a bad network: a pulsing dot before the name (its cursor may freeze). */\n.lr-user[data-net=\"unstable\"] .lr-label span::before { content: \"\"; display: inline-block; width: 6px; height: 6px; margin: 0 5px 1px 0;\n border-radius: 50%; background: #d97706; box-shadow: 0 0 0 1px rgb(255 255 255 / 70%); animation: lr-pulse 1.2s ease-in-out infinite; }\n@keyframes lr-pulse { 50% { opacity: 0.3; } }\n", V = "<svg width=\"23\" viewBox=\"0 0 27 24\" fill=\"currentColor\" aria-hidden=\"true\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M2.27 0.06L25.43 8.06C25.66 8.13 25.83 8.26 25.95 8.43C26.07 8.59 26.14 8.79 26.14 8.99C26.14 9.2 26.07 9.4 25.95 9.56C25.83 9.73 25.66 9.86 25.46 9.93L15.35 13.77L11.31 23.37C11.23 23.56 11.1 23.72 10.92 23.83C10.75 23.94 10.54 24 10.33 24C10.12 24 9.91 23.94 9.73 23.82C9.55 23.7 9.42 23.53 9.34 23.34L0.92 1.34C0.86 1.16 0.84 0.97 0.89 0.78C0.93 0.6 1.03 0.43 1.17 0.29C1.31 0.16 1.49 0.07 1.68 0.02C1.88 -0.02 2.08 -0.01 2.27 0.06Z\"/></svg>", H = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i, U = (e) => H.test(e) ? e : "#a3a3a3";
1137
- function W(e, t, n) {
1147
+ var L = "\n.lr-cursors { position: absolute; inset: 0; overflow: hidden; pointer-events: none; z-index: 2147483646; }\n.lr-user { position: absolute; top: 0; left: 0; user-select: none; will-change: transform; transform-origin: 0 0; }\n.lr-user[data-hidden=\"true\"] { display: none; }\n.lr-cursor { position: absolute; top: 0; left: 0; color: var(--color); transform-origin: top left; transform: rotate(6deg);\n filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.2)); overflow: visible; }\n/* Cursor colors are light pastels: the contour keeps the arrow visible on white pages.\n The path touches the viewBox's top edge, hence the svg's visible overflow. */\n.lr-cursor path { stroke: rgb(0 0 0 / 0.6); stroke-width: 3; stroke-linejoin: round; paint-order: stroke fill; }\n.lr-label { position: absolute; top: 18px; left: 14px; font: 600 12px/1.6 system-ui, sans-serif; color: black;\n background: var(--color); border-radius: 9999px; padding: 0 8px; white-space: nowrap;\n box-shadow: 0 0 0 1px rgb(0 0 0 / 0.12), 0 1px 2px rgb(0 0 0 / 0.08);\n display: flex; flex-direction: column; align-items: center; overflow: hidden; max-width: 200px; text-overflow: ellipsis; }\n.lr-label video { display: none; width: 170.6667px; height: 96px; object-fit: cover; margin: 0; }\n/* Keep the same 16:9 video surface. The small bubble is a circular crop. */\n.lr-user[data-live=\"true\"] .lr-label, .lr-user[data-focus-motion=\"true\"] .lr-label {\n padding: 0; border-radius: 0; top: 10px; left: -31.3333px; width: 170.6667px; height: 96px;\n background: transparent; box-shadow: none; overflow: visible;\n}\n.lr-user[data-live=\"true\"] .lr-label video, .lr-user[data-focus-motion=\"true\"] .lr-label video {\n display: block; clip-path: inset(0 37.3333px round 48px);\n transition: clip-path 250ms cubic-bezier(0.77, 0, 0.175, 1);\n}\n.lr-user[data-live=\"true\"] .lr-label > span, .lr-user[data-focus-motion=\"true\"] .lr-label > span {\n position: absolute; top: calc(100% + 2px); left: 50%; padding: 2px 8px; border-radius: 9999px;\n background: var(--color); opacity: 0; visibility: hidden;\n transform: translateX(-50%) scale(calc(1 / var(--focus-scale, 1))); transform-origin: top center;\n transition: opacity 200ms ease, visibility 200ms ease;\n}\n.lr-halo { position: absolute; top: -60px; left: -60px; width: 120px; height: 120px; border-radius: 9999px; z-index: -1;\n border: 1px solid color-mix(in srgb, var(--color) 75%, transparent); background: color-mix(in srgb, var(--color) 25%, transparent);\n transform: scale(0); transition: transform 200ms ease-in-out; }\n.lr-user[data-halo=\"true\"] .lr-halo { transform: scale(1); }\n.lr-user[data-self=\"true\"] .lr-cursor, .lr-user[data-self=\"true\"] .lr-label { display: none; }\n.lr-cursors::before { content: \"\"; position: absolute; inset: 0; background: rgb(39 39 42 / 25%); backdrop-filter: blur(6px); opacity: 0; transition: opacity 200ms ease; }\n.lr-cursors[data-focus=\"true\"]::before { opacity: 1; }\n.lr-user[data-focus-motion=\"true\"] { transition: transform 250ms cubic-bezier(0.77, 0, 0.175, 1); }\n.lr-user[data-focus=\"true\"] { transform: translate3d(calc(50vw - 54px * var(--focus-scale)), calc(50vh - 58px * var(--focus-scale)), 0) scale(var(--focus-scale)) !important; z-index: 1; }\n.lr-user[data-focus=\"true\"] .lr-label video { clip-path: inset(0 round 4px); }\n.lr-user[data-focus=\"true\"] .lr-label > span { opacity: 1; visibility: visible; }\n.lr-user[data-focus=\"true\"]:not([data-live=\"true\"]) .lr-label { background: #18181b; border-radius: 4px; }\n.lr-user[data-focus=\"true\"] .lr-cursor, .lr-user[data-focus=\"true\"] .lr-halo { opacity: 0; }\n@media (prefers-reduced-motion: reduce) {\n .lr-user[data-focus-motion=\"true\"], .lr-label video { transition: none !important; }\n .lr-cursors::before, .lr-label > span { transition-duration: 100ms; }\n}\n.lr-user[data-blocked=\"true\"] { opacity: 0.4; }\n/* On a bad network: a pulsing dot before the name (its cursor may freeze). */\n.lr-user[data-net=\"unstable\"] .lr-label span::before { content: \"\"; display: inline-block; width: 6px; height: 6px; margin: 0 5px 1px 0;\n border-radius: 50%; background: #d97706; box-shadow: 0 0 0 1px rgb(255 255 255 / 70%); animation: lr-pulse 1.2s ease-in-out infinite; }\n@keyframes lr-pulse { 50% { opacity: 0.3; } }\n", R = "<svg width=\"23\" viewBox=\"0 0 27 24\" fill=\"currentColor\" aria-hidden=\"true\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M2.27 0.06L25.43 8.06C25.66 8.13 25.83 8.26 25.95 8.43C26.07 8.59 26.14 8.79 26.14 8.99C26.14 9.2 26.07 9.4 25.95 9.56C25.83 9.73 25.66 9.86 25.46 9.93L15.35 13.77L11.31 23.37C11.23 23.56 11.1 23.72 10.92 23.83C10.75 23.94 10.54 24 10.33 24C10.12 24 9.91 23.94 9.73 23.82C9.55 23.7 9.42 23.53 9.34 23.34L0.92 1.34C0.86 1.16 0.84 0.97 0.89 0.78C0.93 0.6 1.03 0.43 1.17 0.29C1.31 0.16 1.49 0.07 1.68 0.02C1.88 -0.02 2.08 -0.01 2.27 0.06Z\"/></svg>", z = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i, B = (e) => z.test(e) ? e : "#a3a3a3";
1148
+ function V(e, t, n) {
1138
1149
  e.dataset[t] !== n && (e.dataset[t] = n);
1139
1150
  }
1140
- var G = class {
1151
+ var H = class {
1141
1152
  root;
1142
1153
  options;
1143
1154
  nodes = /* @__PURE__ */ new Map();
@@ -1152,7 +1163,7 @@ var G = class {
1152
1163
  ...e
1153
1164
  };
1154
1165
  let t = e.container.ownerDocument;
1155
- this.style = t.createElement("style"), this.style.textContent = B, (e.styleRoot.nodeType === 9 ? e.styleRoot.head : e.styleRoot).appendChild(this.style), this.trace = t.documentElement.hasAttribute("data-liveroom-trace"), this.root = t.createElement("div"), this.root.className = "lr-cursors", e.container.appendChild(this.root);
1166
+ this.style = t.createElement("style"), this.style.textContent = L, (e.styleRoot.nodeType === 9 ? e.styleRoot.head : e.styleRoot).appendChild(this.style), this.trace = t.documentElement.hasAttribute("data-liveroom-trace"), this.root = t.createElement("div"), this.root.className = "lr-cursors", e.container.appendChild(this.root);
1156
1167
  }
1157
1168
  destroy() {
1158
1169
  cancelAnimationFrame(this.frame), this.root.remove(), this.style.remove();
@@ -1173,15 +1184,15 @@ var G = class {
1173
1184
  e.style.setProperty("--focus-scale", String(n));
1174
1185
  }
1175
1186
  updateFocus() {
1176
- W(this.root, "focus", String(!!this.root.querySelector("[data-focus=\"true\"]")));
1187
+ V(this.root, "focus", String(!!this.root.querySelector("[data-focus=\"true\"]")));
1177
1188
  }
1178
1189
  update(e) {
1179
- let t = this.nodes.get(e.id) ?? this.create(e), n = t.el, i = U(e.color);
1180
- n.style.getPropertyValue("--color") !== i && n.style.setProperty("--color", i), t.label.firstChild.textContent !== e.name && (t.label.firstChild.textContent = e.name), t.video.getAttribute("aria-label") !== e.name && t.video.setAttribute("aria-label", e.name), W(n, "self", String(!!e.self)), W(n, "camera", String((e.camera || e.type === "admin" && (e.flags & r.focus) !== 0) && !e.self));
1190
+ let t = this.nodes.get(e.id) ?? this.create(e), n = t.el, i = B(e.color);
1191
+ n.style.getPropertyValue("--color") !== i && n.style.setProperty("--color", i), t.label.firstChild.textContent !== e.name && (t.label.firstChild.textContent = e.name), t.video.getAttribute("aria-label") !== e.name && t.video.setAttribute("aria-label", e.name), V(n, "self", String(!!e.self)), V(n, "camera", String((e.camera || e.type === "admin" && (e.flags & r.focus) !== 0) && !e.self));
1181
1192
  let a = String(e.type === "admin" && !e.self && (e.flags & r.focus) !== 0);
1182
- n.dataset.focus !== a && (clearTimeout(t.focusExitTimer), (n.dataset.focus !== void 0 || a === "true") && W(n, "focusMotion", "true"), this.setFocusScale(n), W(n, "focus", a), a === "false" && n.dataset.focusMotion === "true" && (t.focusExitTimer = setTimeout(() => {
1183
- W(n, "focusMotion", "false");
1184
- }, 300)), this.updateFocus()), W(n, "blocked", String(!!e.blocked)), W(n, "net", e.net ?? "good"), W(n, "halo", String((e.flags & r.shift) !== 0 || !e.self && (e.flags & r.mouseDown) !== 0)), this.setTarget(e.id, e.x, e.y);
1193
+ n.dataset.focus !== a && (clearTimeout(t.focusExitTimer), (n.dataset.focus !== void 0 || a === "true") && V(n, "focusMotion", "true"), this.setFocusScale(n), V(n, "focus", a), a === "false" && n.dataset.focusMotion === "true" && (t.focusExitTimer = setTimeout(() => {
1194
+ V(n, "focusMotion", "false");
1195
+ }, 300)), this.updateFocus()), V(n, "blocked", String(!!e.blocked)), V(n, "net", e.net ?? "good"), V(n, "halo", String((e.flags & r.shift) !== 0 || !e.self && (e.flags & r.mouseDown) !== 0)), this.setTarget(e.id, e.x, e.y);
1185
1196
  }
1186
1197
  setTarget(e, t, n, r = !1) {
1187
1198
  let i = this.nodes.get(e);
@@ -1201,7 +1212,7 @@ var G = class {
1201
1212
  }
1202
1213
  create(e) {
1203
1214
  let t = this.root.ownerDocument.createElement("div");
1204
- t.className = "lr-user", t.id = `user-${e.id}`, t.innerHTML = `${V.replace("<svg", "<svg class=\"lr-cursor\"")}<div class="lr-label"><span></span><video autoplay muted playsinline></video></div><div class="lr-halo"></div>`;
1215
+ t.className = "lr-user", t.id = `user-${e.id}`, t.innerHTML = `${R.replace("<svg", "<svg class=\"lr-cursor\"")}<div class="lr-label"><span></span><video autoplay muted playsinline></video></div><div class="lr-halo"></div>`;
1205
1216
  let n = t.querySelector(".lr-label");
1206
1217
  n.firstElementChild.textContent = e.name, this.root.appendChild(t);
1207
1218
  let r = {
@@ -1237,11 +1248,11 @@ var G = class {
1237
1248
  }
1238
1249
  };
1239
1250
  // ../packages/core/src/cameras.ts
1240
- function K(e, t) {
1251
+ function U(e, t) {
1241
1252
  let n = e?.closest(".lr-user");
1242
1253
  n && (n.dataset.live = String(t));
1243
1254
  }
1244
- var q = (e, t) => e.type === "admin" && ((e.id === t.you ? t.ownFlags : e.flags) & r.focus) !== 0, J = (e, t) => e.camera || q(e, t), Y = class {
1255
+ var W = (e, t) => e.type === "admin" && ((e.id === t.you ? t.ownFlags : e.flags) & r.focus) !== 0, G = (e, t) => e.camera || W(e, t), K = class {
1245
1256
  options;
1246
1257
  room = null;
1247
1258
  connecting = null;
@@ -1256,7 +1267,7 @@ var q = (e, t) => e.type === "admin" && ((e.id === t.you ? t.ownFlags : e.flags)
1256
1267
  this.options = e;
1257
1268
  let { client: t } = e, n = () => {
1258
1269
  if (this.stopped) return;
1259
- let e = [...t.participants.values()], n = e.some((e) => q(e, t)), r = `${e.some((e) => J(e, t))}/${t.me ? J(t.me, t) : !1}/${n}/${this.warm()}`;
1270
+ let e = [...t.participants.values()], n = e.some((e) => W(e, t)), r = `${e.some((e) => G(e, t))}/${t.me ? G(t.me, t) : !1}/${n}/${this.warm()}`;
1260
1271
  r !== this.requested && (this.requested = r, this.focusExitTimer && clearTimeout(this.focusExitTimer), this.wasFocused && !n ? this.focusExitTimer = setTimeout(() => {
1261
1272
  this.focusExitTimer = null, this.update();
1262
1273
  }, 300) : this.update(), this.wasFocused = n);
@@ -1268,7 +1279,7 @@ var q = (e, t) => e.type === "admin" && ((e.id === t.you ? t.ownFlags : e.flags)
1268
1279
  let n = this.options.videoFor(e);
1269
1280
  n && !t.attachedElements.includes(n) && t.attach(n);
1270
1281
  let r = this.options.client.participants.get(e);
1271
- K(n, !!r && (J(r, this.options.client) || !!this.focusExitTimer));
1282
+ U(n, !!r && (G(r, this.options.client) || !!this.focusExitTimer));
1272
1283
  }
1273
1284
  }
1274
1285
  async stop() {
@@ -1285,19 +1296,19 @@ var q = (e, t) => e.type === "admin" && ((e.id === t.you ? t.ownFlags : e.flags)
1285
1296
  }, e);
1286
1297
  }
1287
1298
  clearTracks() {
1288
- for (let e of this.tracks.keys()) K(this.options.videoFor(e), !1);
1299
+ for (let e of this.tracks.keys()) U(this.options.videoFor(e), !1);
1289
1300
  this.tracks.clear();
1290
1301
  }
1291
1302
  async update() {
1292
1303
  if (this.stopped) return;
1293
1304
  let { client: e } = this.options;
1294
- if ((this.warm() || [...e.participants.values()].some((t) => J(t, e))) && !this.room && !this.connecting && e.livekit && (this.connecting = this.connect().finally(() => this.connecting = null)), this.connecting && await this.connecting, !this.stopped) {
1295
- if (!this.warm() && ![...e.participants.values()].some((t) => J(t, e)) && this.room) {
1305
+ if ((this.warm() || [...e.participants.values()].some((t) => G(t, e))) && !this.room && !this.connecting && e.livekit && (this.connecting = this.connect().finally(() => this.connecting = null)), this.connecting && await this.connecting, !this.stopped) {
1306
+ if (!this.warm() && ![...e.participants.values()].some((t) => G(t, e)) && this.room) {
1296
1307
  let e = this.room;
1297
1308
  this.room = null, this.clearTracks(), await e.disconnect();
1298
1309
  } else {
1299
1310
  if (this.room && this.options.publish) {
1300
- let t = e.me ? J(e.me, e) : !1;
1311
+ let t = e.me ? G(e.me, e) : !1;
1301
1312
  this.room.localParticipant.isCameraEnabled !== t && await this.room.localParticipant.setCameraEnabled(t).catch((e) => this.options.log?.("camera", e));
1302
1313
  }
1303
1314
  this.reattach();
@@ -1312,7 +1323,7 @@ var q = (e, t) => e.type === "admin" && ((e.id === t.you ? t.ownFlags : e.flags)
1312
1323
  i.on(n.TrackSubscribed, (e, t, n) => {
1313
1324
  t.source === r.Source.Camera && (this.tracks.set(n.identity, e), this.reattach());
1314
1325
  }), i.on(n.TrackUnsubscribed, (e, t, n) => {
1315
- this.tracks.delete(n.identity), K(this.options.videoFor(n.identity), !1);
1326
+ this.tracks.delete(n.identity), U(this.options.videoFor(n.identity), !1);
1316
1327
  }), i.on(n.Disconnected, () => {
1317
1328
  this.room === i && (this.room = null, this.clearTracks(), this.scheduleRetry());
1318
1329
  });
@@ -1323,46 +1334,265 @@ var q = (e, t) => e.type === "admin" && ((e.id === t.you ? t.ownFlags : e.flags)
1323
1334
  this.options.log?.("livekit connect failed", e), this.scheduleRetry();
1324
1335
  }
1325
1336
  }
1326
- }, X = "16px/1.5 system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif";
1327
- function re(e) {
1328
- return `:host { all: initial !important; display: block !important; font: ${X} !important; color: #0f172a !important; text-align: left !important; direction: ltr !important; ${e.split(";").map((e) => e.trim()).filter(Boolean).map((e) => `${e.replace(/\s*!important$/, "")} !important;`).join(" ")} }`;
1337
+ }, q = "16px/1.5 system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif";
1338
+ function J(e) {
1339
+ return `:host { all: initial !important; display: block !important; font: ${q} !important; color: #0f172a !important; text-align: left !important; direction: ltr !important; ${e.split(";").map((e) => e.trim()).filter(Boolean).map((e) => `${e.replace(/\s*!important$/, "")} !important;`).join(" ")} }`;
1340
+ }
1341
+ // src/pill.ts
1342
+ var oe = "#94A3B8", se = "#F59E0B", ce = "#EF4444", le = 3e3, ue = 600;
1343
+ function Y(e) {
1344
+ let t = de(e.people), n = t.filter((e) => e.pointed), r = n.some((e) => e.clicks), i = e.stopped && t.length > 0, a = n.length > 0 && !e.stopped, o = e.quality !== "good";
1345
+ if (!i && !a && !o) return {
1346
+ visible: !1,
1347
+ label: "",
1348
+ button: null,
1349
+ dots: [],
1350
+ quality: null
1351
+ };
1352
+ let s = i && e.sinceStopMs !== null && e.sinceStopMs < le, c = i ? he(t, e.sinceStopMs !== null && e.sinceStopMs < ue) : a ? me(n, r) : null;
1353
+ return {
1354
+ visible: !0,
1355
+ label: o ? e.quality === "offline" ? "Reconnecting…" : "Unstable connection" : i ? pe(t, s) : fe(n, r),
1356
+ button: c,
1357
+ dots: o ? [e.quality === "offline" ? ce : se] : i ? [oe] : n.slice(0, 3).map((e) => e.color),
1358
+ quality: e.quality === "good" ? null : e.quality
1359
+ };
1360
+ }
1361
+ function de(e) {
1362
+ return [...e].sort((e, t) => e.name.localeCompare(t.name) || e.id.localeCompare(t.id));
1363
+ }
1364
+ function fe(e, t) {
1365
+ if (e.length === 1) return t ? `${e[0].name} can point and click` : `${e[0].name} is pointing`;
1366
+ if (e.length === 2) {
1367
+ let n = `${e[0].name} and ${e[1].name}`;
1368
+ return t ? `${n} can point and click` : `${n} are pointing`;
1369
+ }
1370
+ return t ? `${e.length} people can point and click` : `${e.length} people are pointing`;
1371
+ }
1372
+ function pe(e, t) {
1373
+ return t ? e.length === 1 ? `You stopped ${e[0].name}'s cursor` : `You stopped ${e.length} cursors` : e.length === 1 ? `${e[0].name}'s cursor is off` : `${e.length} cursors are off`;
1374
+ }
1375
+ function me(e, t) {
1376
+ return {
1377
+ text: "Stop",
1378
+ ariaLabel: e.length === 1 ? t ? `Stop ${e[0].name}'s cursor and clicks` : `Stop ${e[0].name}'s cursor` : e.length === 2 ? `Stop ${e[0].name}'s and ${e[1].name}'s cursors` : `Stop all ${e.length} cursors`,
1379
+ disabled: !1,
1380
+ action: "stop"
1381
+ };
1382
+ }
1383
+ function he(e, t) {
1384
+ if (e.length === 1) {
1385
+ let n = `Let ${e[0].name} point again`;
1386
+ return {
1387
+ text: n,
1388
+ ariaLabel: n,
1389
+ disabled: t,
1390
+ action: "resume"
1391
+ };
1392
+ }
1393
+ return {
1394
+ text: "Let them point again",
1395
+ ariaLabel: e.length === 2 ? `Let ${e[0].name} and ${e[1].name} point again` : `Let all ${e.length} point again`,
1396
+ disabled: t,
1397
+ action: "resume"
1398
+ };
1329
1399
  }
1400
+ var ge = "\n.lr-pill { position: fixed; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 6px;\n padding: 4px 4px 4px 6px; border-radius: 9999px; background: rgb(15 23 42 / 85%);\n box-shadow: inset 0 0 0 1px rgb(255 255 255 / 12%), 0 1px 3px rgb(0 0 0 / 20%);\n color: #fff; font: 500 12px/1.5 system-ui, sans-serif; pointer-events: auto; user-select: none;\n cursor: grab; opacity: 0; transition: opacity 200ms ease-out, transform 200ms ease-out; z-index: 2; }\n.lr-pill[data-shown=\"true\"] { opacity: 1; }\n.lr-pill[hidden] { display: none !important; }\n.lr-pill[data-button=\"false\"] { padding: 4px 10px 4px 6px; }\n.lr-grip { width: 6px; height: 10px; flex: none; background: radial-gradient(circle, rgb(255 255 255 / 55%) 1px, transparent 1.2px) 0 0 / 4px 4px; }\n.lr-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--dot, #94A3B8); box-shadow: 0 0 0 1px rgb(255 255 255 / 25%); }\n.lr-dots { display: flex; flex: none; }\n.lr-dots .lr-dot { box-shadow: 0 0 0 1.5px rgb(15 23 42); }\n.lr-dots .lr-dot + .lr-dot { margin-left: -3px; }\n.lr-label { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.lr-btn { height: 24px; min-width: 44px; max-width: 200px; padding: 0 10px; margin-left: 2px; border: 0; border-radius: 9999px;\n background: rgb(255 255 255 / 14%); color: #fff; font: 600 12px/24px system-ui, sans-serif; cursor: pointer;\n overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.lr-btn:hover { background: rgb(255 255 255 / 22%); }\n.lr-btn:active { background: rgb(255 255 255 / 28%); }\n.lr-btn[aria-disabled=\"true\"] { color: rgb(255 255 255 / 55%); cursor: default; }\n.lr-btn:focus-visible { outline: 2px solid #818CF8; outline-offset: 2px; }\n.lr-pill.dragging { cursor: grabbing; box-shadow: inset 0 0 0 1px rgb(255 255 255 / 12%), 0 6px 16px -4px rgb(0 0 0 / 35%); }\n.lr-pill.snapping { transition: left 160ms cubic-bezier(.2,.8,.2,1), top 160ms cubic-bezier(.2,.8,.2,1), opacity 200ms ease-out; }\n.lr-target { position: fixed; border: 1.5px dashed rgb(129 140 248 / 70%); border-radius: 12px; pointer-events: none; box-sizing: border-box; }\n.lr-target[data-near=\"true\"] { background: rgb(129 140 248 / 15%); }\n@media (prefers-reduced-motion: reduce) {\n .lr-pill, .lr-pill.snapping { transition: opacity 200ms linear; transform: none !important; }\n}\n", X = class {
1401
+ root;
1402
+ label;
1403
+ dots;
1404
+ button;
1405
+ targets = [];
1406
+ style;
1407
+ shown = !1;
1408
+ hideTimer;
1409
+ qualityTimer;
1410
+ quality = "good";
1411
+ model = {
1412
+ stopped: !1,
1413
+ sinceStopMs: null,
1414
+ people: []
1415
+ };
1416
+ view = Y({
1417
+ ...this.model,
1418
+ quality: "good"
1419
+ });
1420
+ drag = null;
1421
+ handlers;
1422
+ constructor(e, t) {
1423
+ this.handlers = t, this.style = document.createElement("style"), this.style.textContent = ge, this.root = document.createElement("div"), this.root.className = "lr-pill", this.root.role = "group", this.root.setAttribute("aria-label", "Liveroom"), this.root.hidden = !0, this.root.dataset.shown = "false";
1424
+ let n = document.createElement("span");
1425
+ n.className = "lr-grip", n.ariaHidden = "true", this.dots = document.createElement("span"), this.dots.className = "lr-dots", this.dots.ariaHidden = "true", this.label = document.createElement("span"), this.label.className = "lr-label", this.label.role = "status", this.label.ariaLive = "polite", this.button = document.createElement("button"), this.button.type = "button", this.button.className = "lr-btn", this.button.addEventListener("click", (e) => {
1426
+ this.button.getAttribute("aria-disabled") === "true" ? (e.preventDefault(), e.stopPropagation()) : this.view.button?.action === "resume" ? this.handlers.onResume() : this.view.button?.action === "stop" && this.handlers.onStop();
1427
+ }), this.root.append(n, this.dots, this.label, this.button), this.root.addEventListener("pointerdown", (e) => this.onPointerDown(e)), e.append(this.style, this.root);
1428
+ }
1429
+ update(e) {
1430
+ this.model = e, this.paint();
1431
+ }
1432
+ setQuality(e) {
1433
+ window.clearTimeout(this.qualityTimer), e === "good" ? (this.quality = "good", this.paint()) : this.qualityTimer = window.setTimeout(() => {
1434
+ this.quality = e, this.paint();
1435
+ }, 500);
1436
+ }
1437
+ destroy() {
1438
+ window.clearTimeout(this.hideTimer), window.clearTimeout(this.qualityTimer), this.style.remove(), this.root.remove();
1439
+ for (let e of this.targets) e.remove();
1440
+ }
1441
+ paint() {
1442
+ let e = Y({
1443
+ ...this.model,
1444
+ quality: this.quality
1445
+ });
1446
+ this.view = e, e.visible ? (this.label.textContent !== e.label && (this.label.textContent = e.label), this.dots.replaceChildren(...e.dots.map((e) => {
1447
+ let t = document.createElement("span");
1448
+ return t.className = "lr-dot", t.style.setProperty("--dot", e), t;
1449
+ })), e.quality ? this.root.dataset.quality = e.quality : delete this.root.dataset.quality, e.button ? (this.button.hidden = !1, this.button.textContent !== e.button.text && (this.button.textContent = e.button.text), this.button.getAttribute("aria-label") !== e.button.ariaLabel && this.button.setAttribute("aria-label", e.button.ariaLabel), e.button.disabled ? this.button.setAttribute("aria-disabled", "true") : this.button.removeAttribute("aria-disabled"), this.root.dataset.button = "true") : (this.button.hidden = !0, this.button.removeAttribute("aria-disabled"), this.root.dataset.button = "false"), this.fadeIn()) : this.fadeOut();
1450
+ }
1451
+ fadeIn() {
1452
+ window.clearTimeout(this.hideTimer), this.shown || (this.shown = !0, this.resetCorner(), this.root.hidden = !1, this.root.dataset.shown = "false", requestAnimationFrame(() => {
1453
+ requestAnimationFrame(() => {
1454
+ this.shown && (this.root.dataset.shown = "true");
1455
+ });
1456
+ }));
1457
+ }
1458
+ fadeOut() {
1459
+ this.shown && (this.shown = !1, this.root.dataset.shown = "false", window.clearTimeout(this.hideTimer), this.hideTimer = window.setTimeout(() => {
1460
+ this.shown || (this.root.hidden = !0, this.resetCorner());
1461
+ }, 200));
1462
+ }
1463
+ resetCorner() {
1464
+ this.root.classList.remove("dragging", "snapping"), this.root.style.left = "", this.root.style.top = "", this.root.style.right = "", this.root.style.bottom = "";
1465
+ }
1466
+ onPointerDown(e) {
1467
+ if (e.button !== 0 || e.target?.closest?.(".lr-btn")) return;
1468
+ let t = this.root.getBoundingClientRect();
1469
+ this.drag = {
1470
+ pointer: e.pointerId,
1471
+ x: e.clientX,
1472
+ y: e.clientY,
1473
+ left: t.left,
1474
+ top: t.top,
1475
+ moved: !1
1476
+ }, this.root.setPointerCapture(e.pointerId);
1477
+ let n = (e) => {
1478
+ if (!this.drag || e.pointerId !== this.drag.pointer) return;
1479
+ let t = e.clientX - this.drag.x, n = e.clientY - this.drag.y;
1480
+ !this.drag.moved && Math.hypot(t, n) < 4 || (this.drag.moved || (this.drag.moved = !0, this.root.classList.add("dragging"), this.showTargets()), this.place(this.drag.left + t, this.drag.top + n), this.markNearest());
1481
+ }, r = (e) => {
1482
+ if (!this.drag || e.pointerId !== this.drag.pointer) return;
1483
+ this.root.removeEventListener("pointermove", n), this.root.removeEventListener("pointerup", r), this.root.removeEventListener("pointercancel", r);
1484
+ let t = this.drag.moved;
1485
+ this.drag = null, this.root.classList.remove("dragging"), t ? this.snap() : this.clearTargets();
1486
+ };
1487
+ this.root.addEventListener("pointermove", n), this.root.addEventListener("pointerup", r), this.root.addEventListener("pointercancel", r);
1488
+ }
1489
+ place(e, t) {
1490
+ this.root.style.left = `${e}px`, this.root.style.top = `${t}px`, this.root.style.right = "auto", this.root.style.bottom = "auto";
1491
+ }
1492
+ corners() {
1493
+ let e = this.root.getBoundingClientRect();
1494
+ return [
1495
+ {
1496
+ left: 12,
1497
+ top: 12
1498
+ },
1499
+ {
1500
+ left: window.innerWidth - e.width - 12,
1501
+ top: 12
1502
+ },
1503
+ {
1504
+ left: 12,
1505
+ top: window.innerHeight - e.height - 12
1506
+ },
1507
+ {
1508
+ left: window.innerWidth - e.width - 12,
1509
+ top: window.innerHeight - e.height - 12
1510
+ }
1511
+ ];
1512
+ }
1513
+ showTargets() {
1514
+ this.clearTargets();
1515
+ for (let e of this.corners()) {
1516
+ let t = document.createElement("div");
1517
+ t.className = "lr-target";
1518
+ let n = this.root.getBoundingClientRect();
1519
+ t.style.left = `${e.left}px`, t.style.top = `${e.top}px`, t.style.width = `${n.width}px`, t.style.height = `${n.height}px`, this.root.parentElement?.append(t), this.targets.push(t);
1520
+ }
1521
+ this.markNearest();
1522
+ }
1523
+ markNearest() {
1524
+ let e = this.root.getBoundingClientRect(), t = e.left + e.width / 2, n = e.top + e.height / 2, r = 0, i = Infinity;
1525
+ this.corners().forEach((a, o) => {
1526
+ let s = Math.hypot(a.left + e.width / 2 - t, a.top + e.height / 2 - n);
1527
+ s < i && (i = s, r = o);
1528
+ }), this.targets.forEach((e, t) => {
1529
+ e.dataset.near = String(t === r);
1530
+ });
1531
+ }
1532
+ clearTargets() {
1533
+ for (let e of this.targets) e.remove();
1534
+ this.targets.length = 0;
1535
+ }
1536
+ snap() {
1537
+ let e = this.root.getBoundingClientRect(), t = e.left + e.width / 2, n = e.top + e.height / 2, r = this.corners().reduce((r, i) => {
1538
+ let a = Math.hypot(i.left + e.width / 2 - t, i.top + e.height / 2 - n);
1539
+ return a < r.dist ? {
1540
+ corner: i,
1541
+ dist: a
1542
+ } : r;
1543
+ }, {
1544
+ corner: this.corners()[0],
1545
+ dist: Infinity
1546
+ }).corner, i = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
1547
+ this.clearTargets(), i ? this.place(r.left, r.top) : (this.root.classList.add("snapping"), requestAnimationFrame(() => this.place(r.left, r.top)), window.setTimeout(() => this.root.classList.remove("snapping"), 180));
1548
+ }
1549
+ };
1330
1550
  // src/stylesheets.ts
1331
- function ie() {
1551
+ function _e() {
1332
1552
  let e = document.createElement("style");
1333
1553
  return e.textContent = "\n * {\n cursor: crosshair !important;\n }\n ", e;
1334
1554
  }
1335
- function ae() {
1555
+ function ve() {
1336
1556
  let e = document.createElement("style");
1337
1557
  return e.textContent = "\n * {\n pointer-events: none !important;\n user-select: none !important;\n }\n ", e;
1338
1558
  }
1339
- function oe() {
1559
+ function ye() {
1340
1560
  let e = document.createElement("style");
1341
1561
  return e.textContent = "\n html { overflow: hidden !important; scrollbar-gutter: stable !important; }\n * { touch-action: none !important; overscroll-behavior: none !important; }\n ", e;
1342
1562
  }
1343
1563
  // src/element.ts
1344
- var se = re("position: fixed; inset: 0; pointer-events: none; z-index: 2147483646; width: auto; height: auto"), Z = class extends HTMLElement {
1564
+ var be = J("position: fixed; inset: 0; pointer-events: none; z-index: 2147483646; width: auto; height: auto"), Z = class extends HTMLElement {
1345
1565
  client;
1346
1566
  layer;
1347
1567
  cameras;
1348
1568
  cleanup = [];
1349
- blockMouseStyle = ie();
1350
- blockPointerStyle = ae();
1569
+ blockMouseStyle = _e();
1570
+ blockPointerStyle = ve();
1351
1571
  blocked = !1;
1352
- blockScrollStyle = oe();
1572
+ blockScrollStyle = ye();
1353
1573
  pointer = [50, 50];
1354
1574
  shift = !1;
1575
+ pill;
1576
+ wantStop = !1;
1577
+ holdUntilCursor = !1;
1578
+ stopClickedAt = null;
1579
+ stopAcked = !1;
1580
+ pillTimers = [];
1355
1581
  connectedCallback() {
1582
+ if (this.parentElement !== document.body || this.nextSibling !== null) {
1583
+ document.body.appendChild(this);
1584
+ return;
1585
+ }
1356
1586
  let r = this.getAttribute("room_id"), i = this.getAttribute("room_token"), a = this.getAttribute("url") || "wss://liveroom.app/room";
1357
1587
  if (!r || !i || this.client) return;
1358
1588
  console.log(`[Liveroom] Starting in room '${r}'... (v${n})`);
1359
1589
  let o = this.shadowRoot ?? this.attachShadow({ mode: "open" });
1360
1590
  o.replaceChildren();
1361
1591
  let s = document.createElement("style");
1362
- s.textContent = se, o.appendChild(s);
1592
+ s.textContent = be, o.appendChild(s);
1363
1593
  let c = document.createElement("div");
1364
1594
  c.id = "liveroom-client-element", c.style.cssText = "position: fixed; inset: 0; pointer-events: none;", o.appendChild(c);
1365
- let l = this.client = new I({
1595
+ let l = this.client = new N({
1366
1596
  url: a,
1367
1597
  roomId: r,
1368
1598
  roomToken: i,
@@ -1377,45 +1607,53 @@ var se = re("position: fixed; inset: 0; pointer-events: none; z-index: 214748364
1377
1607
  user_agent: navigator.userAgent
1378
1608
  }
1379
1609
  });
1380
- this.layer = new G({
1610
+ this.layer = new H({
1381
1611
  container: c,
1382
1612
  styleRoot: o,
1383
1613
  map: (e, t) => ({
1384
1614
  left: e / 100 * innerWidth,
1385
1615
  top: t / 100 * innerHeight
1386
1616
  })
1387
- }), this.cameras = new Y({
1617
+ }), this.cameras = new K({
1388
1618
  preconnect: !0,
1389
1619
  client: l,
1390
1620
  publish: !1,
1391
1621
  videoFor: (e) => this.layer?.videoFor(e)
1392
1622
  });
1393
- let u = () => this.render();
1394
- l.on("snapshot", () => {
1623
+ let u = () => this.render(), d = () => {
1395
1624
  let n = l.me;
1396
- n?.name && sessionStorage?.setItem(t, n.name), n?.color && sessionStorage?.setItem(e, n.color), u();
1397
- }), l.on("presence", () => {
1398
- let e = l.me;
1399
- e?.name && sessionStorage?.setItem(t, e.name), u(), this.cameras?.reattach();
1625
+ n?.name && sessionStorage?.setItem(t, n.name), n?.color && sessionStorage?.setItem(e, n.color), this.noteServerStop(!!n?.stopped), u(), this.syncPill();
1626
+ };
1627
+ l.on("snapshot", d), l.on("presence", () => {
1628
+ d(), this.cameras?.reattach();
1400
1629
  }), l.on("cursors", ({ ids: e }) => {
1401
- let t = !1;
1402
- for (let n of e) {
1403
- let e = l.participants.get(n);
1404
- e && (this.layer.update(e), e.type === "admin" && (t = !0));
1630
+ let t = e.some((e) => l.participants.get(e)?.type === "admin");
1631
+ t && this.holdUntilCursor && !l.me?.stopped && !this.wantStop && (this.holdUntilCursor = !1);
1632
+ let n = !1;
1633
+ for (let t of e) {
1634
+ let e = l.participants.get(t);
1635
+ e && !this.hostHidden(e) && (this.layer.update(e), e.type === "admin" && (n = !0));
1405
1636
  }
1406
- t && this.updateBlocked();
1407
- }), l.on("click", ({ x: e, y: t }) => this.replayClick(e / 100, t / 100)), l.on("wheel", ({ x: e, y: t, dx: n, dy: r }) => this.replayWheel(e / 100, t / 100, n, r)), l.on("refused", (e) => console.error(`[Liveroom] Refused: ${e}`)), this.netPill(o, l), l.connect();
1408
- let d = (e) => {
1637
+ t && this.syncPill(), n && this.updateBlocked();
1638
+ }), l.on("click", ({ x: e, y: t }) => {
1639
+ this.stopped() || this.replayClick(e / 100, t / 100);
1640
+ }), l.on("wheel", ({ x: e, y: t, dx: n, dy: r }) => {
1641
+ this.stopped() || this.replayWheel(e / 100, t / 100, n, r);
1642
+ }), l.on("refused", (e) => console.error(`[Liveroom] Refused: ${e}`)), this.pill = new X(o, {
1643
+ onStop: () => this.stopHosts(),
1644
+ onResume: () => this.resumeHosts()
1645
+ }), this.cleanup.push(l.on("quality", (e) => this.pill?.setQuality(e)), () => this.pill?.destroy()), l.connect();
1646
+ let f = (e) => {
1409
1647
  this.blocked && (e.preventDefault(), e.stopImmediatePropagation());
1410
1648
  };
1411
- this.listen(window, "wheel", d, {
1649
+ this.listen(window, "wheel", f, {
1412
1650
  capture: !0,
1413
1651
  passive: !1
1414
- }), this.listen(window, "touchmove", d, {
1652
+ }), this.listen(window, "touchmove", f, {
1415
1653
  capture: !0,
1416
1654
  passive: !1
1417
1655
  }), this.listen(window, "keydown", (e) => {
1418
- [
1656
+ this.pill && e.composedPath().includes(this.pill.root) || [
1419
1657
  "ArrowUp",
1420
1658
  "ArrowDown",
1421
1659
  "ArrowLeft",
@@ -1425,7 +1663,7 @@ var se = re("position: fixed; inset: 0; pointer-events: none; z-index: 214748364
1425
1663
  "Home",
1426
1664
  "End",
1427
1665
  " "
1428
- ].includes(e.key) && d(e);
1666
+ ].includes(e.key) && f(e);
1429
1667
  }, { capture: !0 }), this.listen(window, "mousemove", (e) => {
1430
1668
  this.pointer = [e.clientX / innerWidth * 100, e.clientY / innerHeight * 100], l.move(this.pointer[0], this.pointer[1]), this.shift && this.renderSelf();
1431
1669
  }), this.listen(window, "mousedown", () => l.setFlag("mouseDown", !0)), this.listen(window, "mouseup", () => l.setFlag("mouseDown", !1)), this.listen(window, "keydown", (e) => {
@@ -1433,37 +1671,67 @@ var se = re("position: fixed; inset: 0; pointer-events: none; z-index: 214748364
1433
1671
  }), this.listen(window, "keyup", (e) => {
1434
1672
  e.key === "Shift" && (this.shift = !1, l.setFlag("shift", !1), u());
1435
1673
  });
1436
- let f;
1674
+ let p;
1437
1675
  this.listen(window, "resize", () => {
1438
- clearTimeout(f), f = window.setTimeout(() => {
1676
+ clearTimeout(p), p = window.setTimeout(() => {
1439
1677
  l.setState({ viewport: Q() }), this.layer?.relayout();
1440
1678
  }, 100);
1441
1679
  });
1442
- let p = location.href, m = window.setInterval(() => {
1443
- location.href !== p && l.setState({ url: p = location.href });
1680
+ let m = location.href, h = window.setInterval(() => {
1681
+ location.href !== m && l.setState({ url: m = location.href });
1444
1682
  }, 500);
1445
- this.cleanup.push(() => clearInterval(m));
1683
+ this.cleanup.push(() => clearInterval(h));
1446
1684
  }
1447
1685
  disconnectedCallback() {
1448
1686
  for (let e of this.cleanup.splice(0)) e();
1449
- this.cameras?.stop(), this.client?.disconnect(), this.layer?.destroy(), this.setBlocked(!1), this.client = this.layer = this.cameras = void 0;
1450
- }
1451
- netPill(e, t) {
1452
- let n = document.createElement("style");
1453
- n.textContent = "\n.lr-net { position: fixed; left: 12px; bottom: 12px; display: flex; align-items: center; gap: 6px; padding: 4px 10px;\n border-radius: 9999px; background: rgb(15 23 42 / 85%); color: white; font: 500 12px/1.5 system-ui, sans-serif;\n pointer-events: none; opacity: 0; transform: translateY(4px); transition: opacity 200ms, transform 200ms; }\n.lr-net[data-shown=\"true\"] { opacity: 1; transform: none; }\n.lr-net::before { content: \"\"; width: 7px; height: 7px; border-radius: 50%; background: #f59e0b; }\n.lr-net[data-quality=\"offline\"]::before { background: #ef4444; }";
1454
- let r = document.createElement("div");
1455
- r.className = "lr-net", r.setAttribute("role", "status"), e.append(n, r);
1456
- let i, a = t.on("quality", (e) => {
1457
- clearTimeout(i), e === "good" ? r.dataset.shown = "false" : i = window.setTimeout(() => {
1458
- r.dataset.quality = e, r.textContent = e === "offline" ? "Reconnecting…" : "Unstable connection", r.dataset.shown = "true";
1459
- }, 500);
1687
+ this.cameras?.stop(), this.client?.disconnect(), this.layer?.destroy(), this.setBlocked(!1), this.clearPillTimers(), this.client = this.layer = this.cameras = this.pill = void 0;
1688
+ }
1689
+ stopped() {
1690
+ return this.wantStop || this.holdUntilCursor || !!this.client?.me?.stopped;
1691
+ }
1692
+ hostHidden(e) {
1693
+ return e.type === "admin" && this.stopped();
1694
+ }
1695
+ noteServerStop(e) {
1696
+ this.holdUntilCursor ? e || (this.wantStop = !1) : e ? (this.wantStop = !0, this.stopAcked = !0) : (this.stopAcked || this.stopClickedAt === null) && (this.wantStop = !1, this.stopAcked = !1, this.stopClickedAt = null);
1697
+ }
1698
+ people() {
1699
+ let e = [];
1700
+ for (let t of this.client?.participants.values() ?? []) t.type === "admin" && t.id !== this.client?.you && e.push({
1701
+ id: t.id,
1702
+ name: t.name,
1703
+ color: t.color,
1704
+ clicks: (t.flags & r.alt) !== 0,
1705
+ pointed: t.cursorAt > 0
1460
1706
  });
1461
- this.cleanup.push(a, () => clearTimeout(i), () => (n.remove(), r.remove()));
1707
+ return e;
1708
+ }
1709
+ syncPill() {
1710
+ let e = this.stopClickedAt === null ? null : performance.now() - this.stopClickedAt;
1711
+ this.pill?.update({
1712
+ stopped: this.stopped(),
1713
+ sinceStopMs: this.wantStop ? e : null,
1714
+ people: this.people()
1715
+ });
1716
+ }
1717
+ stopHosts() {
1718
+ this.wantStop = !0, this.holdUntilCursor = !1, this.stopClickedAt = performance.now(), this.clearPillTimers(), this.pillTimers.push(window.setTimeout(() => this.syncPill(), 620), window.setTimeout(() => this.syncPill(), 3020)), this.setBlocked(!1), this.render(), this.syncPill(), this.client?.stop();
1719
+ }
1720
+ clearPillTimers() {
1721
+ for (let e of this.pillTimers) window.clearTimeout(e);
1722
+ this.pillTimers = [];
1723
+ }
1724
+ resumeHosts() {
1725
+ this.stopClickedAt !== null && performance.now() - this.stopClickedAt < 600 || (this.wantStop = !1, this.holdUntilCursor = !0, this.syncPill(), this.client?.resume());
1462
1726
  }
1463
1727
  listen(e, t, n, r) {
1464
1728
  e.addEventListener(t, n, r), this.cleanup.push(() => e.removeEventListener(t, n, r));
1465
1729
  }
1466
1730
  updateBlocked() {
1731
+ if (this.stopped()) {
1732
+ this.setBlocked(!1);
1733
+ return;
1734
+ }
1467
1735
  let e = [...this.client.participants.values()].filter((e) => e.type === "admin");
1468
1736
  this.setBlocked(e.some((e) => (e.flags & (r.block | r.focus)) !== 0));
1469
1737
  }
@@ -1477,7 +1745,7 @@ var se = re("position: fixed; inset: 0; pointer-events: none; z-index: 214748364
1477
1745
  x: this.pointer[0],
1478
1746
  y: this.pointer[1],
1479
1747
  flags: this.shift ? r.shift : 0
1480
- }) : t.push(n);
1748
+ }) : this.hostHidden(n) || t.push(n);
1481
1749
  this.layer.sync(t);
1482
1750
  }
1483
1751
  renderSelf() {
@@ -1519,7 +1787,7 @@ var se = re("position: fixed; inset: 0; pointer-events: none; z-index: 214748364
1519
1787
  replayWheel(e, t, n, r) {
1520
1788
  let i = this.elementAt(innerWidth * e / 100, innerHeight * t / 100);
1521
1789
  if (!(i instanceof HTMLElement || i instanceof SVGElement)) return;
1522
- let a = Math.abs(r) >= Math.abs(n), o = ce(i, a ? "vertical" : "horizontal");
1790
+ let a = Math.abs(r) >= Math.abs(n), o = xe(i, a ? "vertical" : "horizontal");
1523
1791
  $(o) ? o.scrollByPoint(a ? 0 : n, a ? r : 0, 0) : o.scrollBy({
1524
1792
  top: a ? r : 0,
1525
1793
  left: a ? 0 : n,
@@ -1538,7 +1806,7 @@ function Q() {
1538
1806
  function $(e) {
1539
1807
  return e instanceof HTMLElement && e.tagName === "ION-CONTENT" && "scrollByPoint" in e;
1540
1808
  }
1541
- function ce(e, t) {
1809
+ function xe(e, t) {
1542
1810
  for (let n = e; n && n !== document.body; n = n.parentElement) {
1543
1811
  if ($(n)) return n;
1544
1812
  let { overflowY: e, overflowX: r } = getComputedStyle(n);