@midsummer-ai/sdk 0.1.0-staging.4477 → 0.1.0-staging.4483

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 (46) hide show
  1. package/auth/contract.d.mts +1 -1
  2. package/auth/contract.mjs +2 -2
  3. package/auth/index.d.mts +1 -1
  4. package/auth/index.mjs +1 -1
  5. package/auth/mail.d.mts +1 -1
  6. package/auth/password.mjs +1 -1
  7. package/auth/react.mjs +1 -1
  8. package/{auth-C7yU9QWZ.mjs → auth-BH2Lfguc.mjs} +49 -3
  9. package/calls/contract.d.mts +23 -0
  10. package/calls/contract.mjs +293 -0
  11. package/calls/index.d.mts +147 -0
  12. package/calls/index.mjs +1131 -0
  13. package/calls/protocol.d.mts +2 -0
  14. package/calls/protocol.mjs +33 -0
  15. package/calls/react.d.mts +56 -0
  16. package/calls/react.mjs +225 -0
  17. package/calls/stand-in.d.mts +22 -0
  18. package/calls/stand-in.mjs +390 -0
  19. package/calls/ui.d.mts +76 -0
  20. package/calls/ui.mjs +783 -0
  21. package/email/client.d.mts +1 -1
  22. package/email/contract.d.mts +1 -1
  23. package/email/inbox.d.mts +1 -1
  24. package/email/index.d.mts +1 -1
  25. package/email/smtp.d.mts +1 -1
  26. package/email/stand-in.d.mts +1 -1
  27. package/{engine-Be7yur9O.mjs → engine-CmTP59GT.mjs} +1 -1
  28. package/flows/contract.d.mts +1 -1
  29. package/flows/index.d.mts +1 -1
  30. package/{guard-Br3K8CVx.mjs → guard-VPI6xq4z.mjs} +1 -1
  31. package/here-C2jhTheQ.mjs +1 -1
  32. package/{index-CkyNDcba.d.mts → index-BmjcZfRb.d.mts} +8 -0
  33. package/{index-DI_L79Hc.d.mts → index-bperY8NN.d.mts} +2 -2
  34. package/index-c616Dbux.d.mts +343 -0
  35. package/kv/contract.d.mts +5 -0
  36. package/kv/contract.mjs +3 -0
  37. package/kv/wire.d.mts +77 -4
  38. package/kv/wire.mjs +492 -201
  39. package/package.json +43 -1
  40. package/protocol-BeBvbfKf.d.mts +185 -0
  41. package/queues/contract.d.mts +1 -1
  42. package/queues/index.d.mts +1 -342
  43. package/queues/stand-in.d.mts +1 -1
  44. package/queues/wire.d.mts +1 -1
  45. package/{style-BJzVvUKV.mjs → style-DXd-0Cxo.mjs} +1 -163
  46. package/tokens-BpV8U5E1.mjs +164 -0
package/calls/ui.mjs ADDED
@@ -0,0 +1,783 @@
1
+ "use client";
2
+ import { CallError } from "./index.mjs";
3
+ import { Audio, CallProvider, Video, useCall, useCallError, useCallState, useLocalTracks, useParticipants } from "./react.mjs";
4
+ import { a as TYPE, i as MATERIAL, n as FOUNDATION, r as LIGHT, t as DARK } from "../tokens-BpV8U5E1.mjs";
5
+ import { Fragment, createContext, createElement, useCallback, useContext, useEffect, useId, useMemo, useRef, useState } from "react";
6
+ //#region src/calls/style.ts
7
+ /**
8
+ * The ready call components' stylesheet (`./ui.ts`), scoped to `.msc` and built from Midsummer's tokens, the same ones
9
+ * sign-in's screens use (`../auth/tokens.ts`), light and dark. An app themes a call with a few CSS variables, set on the
10
+ * call or on any parent of it:
11
+ *
12
+ * --msc-accent the speaking ring and focus rings; Midsummer's blue when unset
13
+ * --msc-radius the corner of the call, its tiles and panels (12px); buttons follow it
14
+ * --msc-surface the call's background
15
+ * --msc-tile a tile's background behind someone's initials
16
+ * --msc-text the text colour
17
+ * --msc-danger the Leave button
18
+ * --msc-font the typeface; Geist, else the system's, when unset
19
+ *
20
+ * The theme follows `data-msc-theme` on the call ("light", "dark" or "system", the person's system), else a `dark` or
21
+ * `light` class or `data-theme` on a parent, else the person's system.
22
+ */
23
+ const declarations = (values) => Object.entries(values).map(([name, value]) => `${name}:${value}`).join(";");
24
+ const role = (text) => declarations(text);
25
+ const dark = declarations(DARK);
26
+ /** The stylesheet, the same for every call on the page. */
27
+ function callCss() {
28
+ return `
29
+ .msc{${declarations(LIGHT)};${declarations(MATERIAL)};${declarations(FOUNDATION)};--ms-accent:var(--msc-accent,var(--ms-accent-solid));--_r:var(--msc-radius,var(--radius-card));--_r-button:max(0px,calc(var(--_r) - 2px));--_r-inner:max(0px,calc(var(--_r) - 4px));--_surface:var(--msc-surface,var(--ms-surface-secondary));--_tile:var(--msc-tile,var(--ms-gray-4));--_text:var(--msc-text,var(--ms-text-primary));--_danger:var(--msc-danger,var(--ms-button-danger));color-scheme:light;font-family:var(--msc-font,"Geist Variable","Geist",ui-sans-serif,system-ui,sans-serif);${role(TYPE["body-small"])};color:var(--_text);text-align:start;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;-webkit-text-size-adjust:100%}
30
+ @media (prefers-color-scheme:dark){.msc:not([data-msc-theme="light"]){${dark};color-scheme:dark}}
31
+ :is(.dark,[data-theme="dark"]) .msc:not([data-msc-theme]),.msc[data-msc-theme="dark"]{${dark};color-scheme:dark}
32
+ :is(.light,[data-theme="light"]) .msc:not([data-msc-theme]){${declarations(LIGHT)};color-scheme:light}
33
+ .msc *,.msc *::before,.msc *::after{box-sizing:border-box}
34
+ .msc :where(h2,h3,p,ul,figure,figcaption){margin:0;padding:0}
35
+ .msc :where(button){font:inherit;letter-spacing:inherit;color:inherit;margin:0}
36
+ .msc :where(svg){flex-shrink:0}
37
+ .msc-icon{width:20px;height:20px}
38
+ .msc-sr{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
39
+
40
+ .msc-call{container:msc/inline-size;position:relative;isolation:isolate;display:grid;grid-template-rows:minmax(0,1fr) auto;width:100%;height:100%;min-height:360px;border-radius:var(--_r);background:var(--_surface);color:var(--_text);overflow:hidden}
41
+ .msc-main{position:relative;display:flex;gap:8px;min-width:0;min-height:0;padding:8px 8px 0}
42
+ .msc-stage{container:msc-stage/size;position:relative;display:grid;flex:1;min-width:0;min-height:0;overflow-y:auto;scrollbar-width:thin}
43
+
44
+ .msc-grid{--_cols:1;--_rows:1;display:grid;grid-template-columns:repeat(var(--_cols),minmax(0,1fr));align-content:center;gap:8px;width:100%;max-width:min(100%,calc((100cqh - (var(--_rows) - 1) * 8px) * 16 / 9 * var(--_cols) / var(--_rows) + (var(--_cols) - 1) * 8px));min-width:0;margin:auto}
45
+ .msc-grid[data-cols="2"]{--_cols:2}
46
+ .msc-grid[data-cols="3"]{--_cols:3}
47
+ .msc-grid[data-cols="4"]{--_cols:4}
48
+
49
+ .msc-tile{container:msc-tile/inline-size;position:relative;display:grid;place-items:center;aspect-ratio:16/9;min-width:0;border-radius:var(--_r);background:var(--_tile);overflow:hidden}
50
+ .msc-tile[data-screen]{grid-column:1/-1}
51
+ .msc-more{${role(TYPE["body-medium"])};color:var(--ms-text-primary);font-variant-numeric:tabular-nums}
52
+ .msc-tile::after{content:"";position:absolute;inset:0;border-radius:inherit;pointer-events:none;box-shadow:inset 0 0 0 1px color-mix(in oklab,var(--_text) 8%,transparent);transition:box-shadow var(--motion-duration-quick) var(--motion-ease-out)}
53
+ .msc-tile[data-speaking]::after{box-shadow:inset 0 0 0 2px var(--ms-accent),inset 0 0 0 5px color-mix(in oklab,var(--ms-accent) 28%,transparent)}
54
+ .msc-video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;background:#000}
55
+ .msc-tile[data-screen] .msc-video{object-fit:contain}
56
+ .msc-video[data-mirror]{transform:scaleX(-1)}
57
+ .msc-avatar{position:relative;display:inline-grid;place-items:center;flex-shrink:0;width:clamp(40px,22cqi,112px);aspect-ratio:1;border-radius:999px;overflow:hidden;background:linear-gradient(155deg,var(--ms-surface-primary),var(--ms-surface-secondary));color:var(--ms-text-secondary);font-size:clamp(14px,7cqi,36px);font-weight:var(--font-weight-medium);letter-spacing:-0.01em;line-height:1;user-select:none}
58
+ .msc-avatar::after{content:"";position:absolute;inset:0;border-radius:inherit;pointer-events:none;box-shadow:inset 0 0 0 1px var(--ms-avatar-rim),inset 0 2px 0 var(--ms-avatar-highlight)}
59
+ .msc-tile[data-away] .msc-avatar{opacity:.5}
60
+ .msc-label{position:absolute;inset-inline-start:8px;inset-block-end:8px;z-index:1;display:inline-flex;align-items:center;gap:6px;max-width:calc(100% - 16px);height:24px;padding:0 8px;border-radius:var(--_r-inner);background:oklch(0.2 0 0 / 0.62);color:#fff;${role(TYPE.caption)};font-weight:var(--font-weight-medium);-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px)}
61
+ .msc-label .msc-icon{width:14px;height:14px}
62
+ .msc-label .msc-icon[data-tone="danger"]{color:#ff6875}
63
+ .msc-label .msc-tipped{min-width:0;flex-shrink:1}
64
+ .msc-label .msc-tip{inset-inline-start:0;translate:none;width:max-content;max-width:min(320px,calc(100cqi - 16px));white-space:normal;overflow-wrap:anywhere}
65
+ .msc-name{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
66
+ .msc-away{flex-shrink:0;font-weight:var(--font-weight-normal);opacity:.8}
67
+
68
+ .msc-notice{position:absolute;inset-block-start:12px;inset-inline:0;z-index:2;display:grid;gap:2px;width:max-content;max-width:calc(100% - 24px);margin-inline:auto;padding:10px 16px;border-radius:var(--_r);background:var(--ms-surface-raised);box-shadow:var(--ms-shadow-menu);text-align:center;animation:msc-enter 160ms var(--motion-ease-out) both}
69
+ .msc-notice-title{${role(TYPE["body-medium"])};color:var(--ms-text-primary)}
70
+ .msc-notice-detail{${role(TYPE["body-small"])};color:var(--ms-text-secondary);overflow-wrap:anywhere}
71
+ .msc-overlay{position:absolute;inset:0;z-index:3;display:grid;place-items:center;background:color-mix(in oklab,var(--_surface) 72%,transparent);-webkit-backdrop-filter:blur(3px);backdrop-filter:blur(3px);animation:msc-fade 160ms ease-out both}
72
+ .msc-pill{display:inline-flex;align-items:center;gap:10px;padding:10px 16px;border-radius:var(--_r);background:var(--ms-surface-raised);box-shadow:var(--ms-shadow-menu);${role(TYPE["body-medium"])};color:var(--ms-text-primary)}
73
+ .msc-spinner{width:16px;height:16px;border-radius:999px;border:2px solid color-mix(in oklab,var(--ms-text-primary) 18%,transparent);border-top-color:var(--ms-text-primary);animation:msc-spin 800ms linear infinite}
74
+
75
+ .msc-center{display:grid;justify-items:center;align-content:center;gap:16px;min-height:100%;padding:32px 24px;text-align:center}
76
+ .msc-center-copy{display:grid;gap:4px;max-width:36ch}
77
+ .msc-title{${role(TYPE.heading)};color:var(--ms-text-primary);text-wrap:balance;overflow-wrap:anywhere}
78
+ .msc-detail{${role(TYPE["body-small"])};color:var(--ms-text-secondary);text-wrap:pretty;overflow-wrap:anywhere}
79
+ .msc-subject{font-weight:var(--font-weight-medium);color:var(--ms-text-primary)}
80
+ .msc-status{display:inline-flex;align-items:center;gap:10px;${role(TYPE["body-medium"])};color:var(--ms-text-primary)}
81
+
82
+ .msc-bar{position:relative;display:grid;grid-template-columns:minmax(0,1fr) auto minmax(0,1fr);align-items:center;gap:8px;min-height:68px;padding:12px}
83
+ .msc-room{min-width:0;padding-inline-start:4px;${role(TYPE["body-medium"])};color:var(--ms-text-primary);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
84
+ .msc-controls{display:flex;align-items:center;justify-content:center;gap:8px}
85
+ .msc-bar-end{display:flex;align-items:center;justify-content:flex-end;gap:8px;min-width:0}
86
+ @container msc (max-width:520px){.msc-bar{display:flex;justify-content:center}.msc-room{display:none}.msc-bar-end{flex:none}}
87
+
88
+ .msc-control{position:relative;display:inline-flex;align-items:center;justify-content:center;gap:8px;flex-shrink:0;min-width:44px;height:44px;padding:0 12px;border:1px solid var(--ms-button-secondary-edge);border-radius:var(--_r-button);background-color:var(--ms-button-secondary);background-image:var(--ms-button-secondary-sheen);box-shadow:var(--ms-shadow-button-secondary);color:var(--ms-button-secondary-foreground);${role(TYPE["body-medium"])};white-space:nowrap;cursor:pointer;user-select:none;outline:none;transition:background-color var(--motion-duration-quick) var(--motion-ease-out),color var(--motion-duration-quick) var(--motion-ease-out),box-shadow var(--motion-duration-quick) var(--motion-ease-out)}
89
+ .msc-control[data-icon-only]{width:44px;padding:0}
90
+ .msc-control:hover:not(:disabled){background-color:var(--ms-button-secondary-hover);box-shadow:var(--ms-shadow-button-secondary-hover)}
91
+ .msc-control:active:not(:disabled){background-color:var(--ms-button-secondary-pressed);box-shadow:var(--ms-shadow-button-secondary-pressed)}
92
+ .msc-control:focus-visible{outline:2px solid var(--ms-focus-ring);outline-offset:2px}
93
+ .msc-control[data-off]{color:var(--ms-danger-glyph)}
94
+ .msc-control:disabled{cursor:not-allowed;opacity:.45}
95
+ .msc-control[aria-busy="true"]{cursor:progress}
96
+ .msc-leave{border-color:var(--ms-button-danger-edge);background-color:var(--_danger);background-image:var(--ms-button-danger-sheen);color:var(--ms-button-danger-foreground);box-shadow:var(--ms-shadow-button-danger)}
97
+ .msc-leave:hover:not(:disabled){background-color:var(--ms-button-danger-hover);box-shadow:var(--ms-shadow-button-danger-hover)}
98
+ .msc-leave:active:not(:disabled){background-color:var(--ms-button-danger-pressed);box-shadow:var(--ms-shadow-button-danger-pressed)}
99
+ .msc-tipped{position:relative;display:inline-flex;flex-shrink:0}
100
+ .msc-tip{position:absolute;inset-block-end:calc(100% + 8px);inset-inline-start:50%;translate:-50% 0;z-index:4;padding:4px 8px;border-radius:6px;background:var(--ms-text-primary);color:var(--ms-page);${role(TYPE.caption)};white-space:nowrap;opacity:0;visibility:hidden;pointer-events:none;transition:opacity var(--motion-duration-quick) var(--motion-ease-out),visibility 0s linear var(--motion-duration-quick)}
101
+ .msc-tipped:hover .msc-tip,.msc-tipped:has(:focus-visible) .msc-tip{opacity:1;visibility:visible;transition-delay:300ms,300ms}
102
+ .msc-count{min-width:20px;padding:0 6px;border-radius:999px;background:var(--ms-surface-secondary);${role(TYPE.caption)};font-weight:var(--font-weight-medium);font-variant-numeric:tabular-nums;color:var(--ms-text-primary);text-align:center;line-height:20px}
103
+ @container msc (max-width:520px){.msc-control[data-word] .msc-word{display:none}.msc-control[data-word]{width:auto;min-width:44px;padding:0 8px;gap:4px}.msc-control[data-word] .msc-count{background:var(--ms-surface-raised);box-shadow:var(--ms-shadow-menu)}}
104
+
105
+ .msc-alert{position:absolute;inset-block-end:calc(100% + 4px);inset-inline:0;z-index:4;display:flex;align-items:center;gap:8px;width:max-content;max-width:calc(100% - 24px);margin-inline:auto;padding:6px 6px 6px 12px;border-radius:var(--_r);background:var(--ms-surface-raised);box-shadow:var(--ms-shadow-menu);${role(TYPE["body-small"])};color:var(--ms-text-primary);overflow-wrap:anywhere;animation:msc-enter 160ms var(--motion-ease-out) both}
106
+ .msc-alert>.msc-icon{width:16px;height:16px;color:var(--ms-danger-glyph)}
107
+ .msc-quiet{display:inline-grid;place-items:center;flex-shrink:0;width:28px;height:28px;padding:0;border:0;border-radius:var(--_r-inner);background:none;color:var(--ms-text-secondary);cursor:pointer;outline:none;transition:background-color var(--motion-duration-quick) var(--motion-ease-out),color var(--motion-duration-quick) var(--motion-ease-out)}
108
+ .msc-quiet:hover{background:var(--ms-selection-fill);color:var(--ms-text-primary)}
109
+ .msc-quiet:focus-visible{box-shadow:0 0 0 2px var(--ms-focus-ring)}
110
+ .msc-quiet .msc-icon{width:16px;height:16px}
111
+
112
+ .msc-button{display:inline-flex;align-items:center;justify-content:center;gap:8px;height:36px;padding:0 14px;border:1px solid transparent;border-radius:var(--_r-button);${role(TYPE["body-medium"])};white-space:nowrap;cursor:pointer;user-select:none;outline:none;transition:background-color var(--motion-duration-quick) var(--motion-ease-out),box-shadow var(--motion-duration-quick) var(--motion-ease-out)}
113
+ .msc-button .msc-icon{width:18px;height:18px}
114
+ .msc-button:focus-visible{outline:2px solid var(--ms-focus-ring);outline-offset:2px}
115
+ .msc-primary{border-color:var(--ms-button-primary-edge);background-color:var(--ms-button-primary);background-image:var(--ms-button-primary-sheen);color:var(--ms-button-primary-foreground);box-shadow:var(--ms-shadow-button-primary)}
116
+ .msc-primary:hover{background-color:var(--ms-button-primary-hover);box-shadow:var(--ms-shadow-button-primary-hover)}
117
+ .msc-primary:active{background-color:var(--ms-button-primary-pressed);box-shadow:var(--ms-shadow-button-primary-pressed)}
118
+
119
+ .msc-people{display:flex;flex-direction:column;flex:0 0 272px;min-height:0;border-radius:var(--_r);background:var(--ms-surface-raised);box-shadow:var(--ms-card-lift);animation:msc-enter 160ms var(--motion-ease-out) both}
120
+ .msc-people-head{display:flex;align-items:center;justify-content:space-between;gap:8px;min-height:48px;padding:8px 8px 8px 16px;border-bottom:1px solid var(--ms-border-subtle)}
121
+ .msc-people-title{display:flex;align-items:baseline;gap:6px;${role(TYPE["body-medium"])};color:var(--ms-text-primary)}
122
+ .msc-people-title span{font-weight:var(--font-weight-normal);color:var(--ms-text-secondary);font-variant-numeric:tabular-nums}
123
+ .msc-people-list{display:grid;align-content:start;gap:2px;flex:1;min-height:0;padding:6px;overflow-y:auto;list-style:none}
124
+ .msc-person{display:flex;align-items:center;gap:10px;min-width:0;min-height:44px;padding:6px 10px;border-radius:var(--_r-inner)}
125
+ .msc-person .msc-avatar{width:28px;font-size:11px}
126
+ .msc-person[data-away] .msc-avatar{opacity:.5}
127
+ .msc-person-copy{display:grid;flex:1;min-width:0}
128
+ .msc-person-name{${role(TYPE["body-medium"])};color:var(--ms-text-primary);overflow-wrap:anywhere}
129
+ .msc-person-detail{${role(TYPE.caption)};color:var(--ms-text-secondary)}
130
+ .msc-person>.msc-icon{width:16px;height:16px;color:var(--ms-danger-glyph)}
131
+ @container msc (max-width:640px){.msc-people{position:absolute;inset-block:8px 0;inset-inline-end:8px;z-index:3;width:min(272px,calc(100% - 16px));box-shadow:var(--ms-shadow-menu)}}
132
+
133
+ @keyframes msc-enter{from{opacity:0;transform:translateY(3px)}to{opacity:1;transform:none}}
134
+ @keyframes msc-fade{from{opacity:0}to{opacity:1}}
135
+ @keyframes msc-spin{to{transform:rotate(360deg)}}
136
+ @media (prefers-reduced-motion:reduce){.msc *,.msc *::before,.msc *::after{animation-duration:0s!important;animation-delay:0s!important;animation-iteration-count:1!important;transition-duration:0s!important;transition-delay:0s!important}.msc-spinner{border-top-color:color-mix(in oklab,var(--ms-text-primary) 18%,transparent)}}
137
+ `;
138
+ }
139
+ //#endregion
140
+ //#region src/calls/ui.ts
141
+ /**
142
+ * `@midsummer-ai/sdk/calls/ui`: a whole call in one line, in Midsummer's look, light and dark.
143
+ *
144
+ * import { Call } from "@midsummer-ai/sdk/calls/ui"
145
+ *
146
+ * <Call room="support-42" token={token} />
147
+ *
148
+ * `token` is what `join` takes: a token the app's server made for the room, or a function that asks for one. The call
149
+ * joins as it mounts, turns on the microphone and camera (the browser asks first), and draws every state in words:
150
+ * joining, waiting for others, the call itself, reconnecting, left or ended (with Rejoin), and failed (with Try again).
151
+ * It fills the box it is given, at least 360px tall, so give its parent a height. A call joined elsewhere is drawn
152
+ * with `<Call call={call} />`, and `onRejoin` is what Rejoin and Try again do for it.
153
+ *
154
+ * Its parts are exported too, for a call laid out another way. They go inside `<CallProvider>` from
155
+ * `@midsummer-ai/sdk/calls/react`, best with `autoVideo={false}` so the grid chooses the videos it shows:
156
+ *
157
+ * <CallProvider room="standup" token={token} autoVideo={false}>
158
+ * <CallGrid /> // everyone's tiles, and their sound
159
+ * <ParticipantList /> // who is in the call
160
+ * <CallControls publish /> // microphone, camera, screen and Leave
161
+ * </CallProvider>
162
+ *
163
+ * `CallTile` draws one person's tile. The grid shows at most 9 videos, asks for each at the layer its tile's width
164
+ * needs (`q` under 320px, `h` under 720px, `f` above, at most 2 at `f`), and shows everyone else by their initials.
165
+ *
166
+ * The look comes from Midsummer's tokens and is themed with CSS variables (`--msc-accent`, `--msc-radius`,
167
+ * `--msc-surface`, `--msc-tile`, `--msc-text`, `--msc-danger`, `--msc-font`; `./style.ts` lists them) and `theme`.
168
+ */
169
+ const CSS = callCss();
170
+ const noop = () => {};
171
+ const cx = (...names) => names.filter(Boolean).join(" ");
172
+ const live = (state) => state === "waiting" || state === "in-call";
173
+ /**
174
+ * What the person in the call reads about a failure, in their words; the developer's own sentence stays on
175
+ * `call.error` and the thrown `CallError`.
176
+ */
177
+ const PLAIN = {
178
+ forbidden: "You can't join this call with this link. Ask whoever invited you for a new one.",
179
+ full: "This call is full right now. Try again in a little while.",
180
+ ended: "This call has ended.",
181
+ quota: "This call can't start right now. Try again later.",
182
+ invalid: "That didn't work. Try again.",
183
+ "not-found": "That didn't work. Try again.",
184
+ unavailable: "The call couldn't be reached. Check your connection and try again."
185
+ };
186
+ const messageOf = (error) => {
187
+ if (error instanceof CallError) return PLAIN[error.code];
188
+ if (error instanceof Error && (error.name === "NotAllowedError" || error.name === "NotFoundError")) return "Your browser didn't let the call use your camera, microphone or screen.";
189
+ return PLAIN.unavailable;
190
+ };
191
+ /**
192
+ * A whole call: everyone's tiles, the controls, who is in it, and every state in words. Given `room` and `token` it
193
+ * joins, and Rejoin and Try again join anew; given a `call` it draws that one, and they do what `onRejoin` does.
194
+ */
195
+ function Call(props) {
196
+ const { theme, className } = props;
197
+ const [attempt, setAttempt] = useState(0);
198
+ const [left, setLeft] = useState(false);
199
+ const given = props.call !== void 0 ? props : void 0;
200
+ const joining = given ? void 0 : props;
201
+ const room = given ? given.call.room : joining.room;
202
+ const again = given ? given.onRejoin && (() => {
203
+ setLeft(false);
204
+ given.onRejoin?.();
205
+ }) : () => {
206
+ setLeft(false);
207
+ setAttempt((count) => count + 1);
208
+ };
209
+ const body = createElement(CallBody, {
210
+ room,
211
+ left,
212
+ onLeave: () => setLeft(true),
213
+ ...again ? { onAgain: again } : {}
214
+ });
215
+ return createElement(Root, {
216
+ tag: "section",
217
+ className: cx("msc-call", className),
218
+ ...theme ? { theme } : {},
219
+ attributes: { "aria-label": `Call ${room}` }
220
+ }, given ? createElement(CallProvider, {
221
+ key: attempt,
222
+ call: given.call
223
+ }, body) : createElement(CallProvider, {
224
+ key: attempt,
225
+ room,
226
+ token: joining.token,
227
+ ...joining.url !== void 0 ? { url: joining.url } : {},
228
+ autoVideo: false
229
+ }, body));
230
+ }
231
+ function CallBody({ room, left, onLeave, onAgain }) {
232
+ const state = useCallState();
233
+ const error = useCallError();
234
+ const [people, setPeople] = useState(false);
235
+ const peopleId = useId();
236
+ if (state === "connecting") return createElement("div", {
237
+ className: "msc-center",
238
+ role: "status"
239
+ }, createElement("span", { className: "msc-status" }, createElement("span", {
240
+ className: "msc-spinner",
241
+ "aria-hidden": true
242
+ }), "Joining…"));
243
+ if (state === "failed") return createElement("div", {
244
+ className: "msc-center",
245
+ role: "alert"
246
+ }, createElement("div", { className: "msc-center-copy" }, createElement("h2", { className: "msc-title" }, "The call couldn't connect"), error && createElement("p", { className: "msc-detail" }, messageOf(error))), onAgain && createElement("button", {
247
+ type: "button",
248
+ className: "msc-button msc-primary",
249
+ onClick: onAgain
250
+ }, createElement(Icon, { name: "again" }), "Try again"));
251
+ if (state === "ended") return createElement("div", {
252
+ className: "msc-center",
253
+ role: "status"
254
+ }, createElement("div", { className: "msc-center-copy" }, createElement("h2", { className: "msc-title" }, left ? "You left the call" : "The call has ended"), createElement("p", { className: "msc-detail" }, createElement("span", { className: "msc-subject" }, room))), onAgain && createElement("button", {
255
+ type: "button",
256
+ className: "msc-button msc-primary",
257
+ onClick: onAgain
258
+ }, createElement(Icon, { name: "again" }), "Rejoin"));
259
+ return createElement(Fragment, null, createElement("div", { className: "msc-main" }, createElement("div", { className: "msc-stage" }, createElement(CallGrid), state === "waiting" && createElement("div", {
260
+ className: "msc-notice",
261
+ role: "status"
262
+ }, createElement("p", { className: "msc-notice-title" }, "Waiting for others to join"), createElement("p", { className: "msc-notice-detail" }, room)), state === "reconnecting" && createElement("div", {
263
+ className: "msc-overlay",
264
+ role: "status"
265
+ }, createElement("span", { className: "msc-pill" }, createElement("span", {
266
+ className: "msc-spinner",
267
+ "aria-hidden": true
268
+ }), "Reconnecting…"))), people && createElement(ParticipantList, {
269
+ id: peopleId,
270
+ onClose: () => setPeople(false)
271
+ })), createElement(CallControls, {
272
+ publish: true,
273
+ onLeave,
274
+ people: {
275
+ open: people,
276
+ onToggle: () => setPeople((open) => !open),
277
+ controls: peopleId
278
+ }
279
+ }));
280
+ }
281
+ /** Tiles report their rendered width, so the grid asks for each video at the layer it needs. */
282
+ const Widths = createContext(void 0);
283
+ /** The layer a tile this wide needs. */
284
+ const layerFor = (width) => width < 320 ? "q" : width < 720 ? "h" : "f";
285
+ /**
286
+ * Everyone in the call as tiles, screens first and full width, then you, then the others, those with a camera first;
287
+ * and everyone's sound. At most 16 people have a tile of their own, and a last tile shows how many more are in the call.
288
+ * At most 9 others' videos are received, each at the layer its tile's width needs and at most 2 at `f`; the rest show
289
+ * their initials.
290
+ */
291
+ function CallGrid({ className }) {
292
+ const call = useCall();
293
+ const state = useCallState();
294
+ const participants = useParticipants();
295
+ const local = useLocalTracks();
296
+ const present = participants.filter((participant) => participant.state !== "left");
297
+ const sharing = local.some((track) => track.name === "screen");
298
+ const tiles = call ? [
299
+ ...sharing ? [{
300
+ key: "self/screen",
301
+ participant: call.me,
302
+ video: "screen",
303
+ self: true
304
+ }] : [],
305
+ ...present.filter((participant) => publishes(participant, "screen")).map((participant) => ({
306
+ key: `${participant.id}/screen`,
307
+ participant,
308
+ video: "screen",
309
+ self: false
310
+ })),
311
+ {
312
+ key: "self/camera",
313
+ participant: call.me,
314
+ video: "camera",
315
+ self: true
316
+ },
317
+ ...[...present.filter((participant) => publishes(participant, "camera")), ...present.filter((participant) => !publishes(participant, "camera"))].map((participant) => ({
318
+ key: `${participant.id}/camera`,
319
+ participant,
320
+ video: "camera",
321
+ self: false
322
+ }))
323
+ ] : [];
324
+ const people = tiles.filter((tile) => tile.video === "camera").length;
325
+ const more = people > MAX_TILES ? people - (MAX_TILES - 1) : 0;
326
+ const shown = more ? tiles.filter((tile) => tile.video === "screen" || tiles.filter((one) => one.video === "camera").indexOf(tile) < MAX_TILES - 1) : tiles;
327
+ const [widths, setWidths] = useState(() => /* @__PURE__ */ new Map());
328
+ const grid = useRef(null);
329
+ const [stage, setStage] = useState();
330
+ useEffect(() => {
331
+ const parent = grid.current?.parentElement;
332
+ if (!parent || typeof ResizeObserver === "undefined") return;
333
+ const observer = new ResizeObserver(([entry]) => {
334
+ if (entry) setStage(Math.round(entry.contentRect.width));
335
+ });
336
+ observer.observe(parent);
337
+ return () => observer.disconnect();
338
+ }, []);
339
+ const report = useCallback((key, width) => setWidths((before) => {
340
+ const rounded = width === void 0 ? void 0 : Math.round(width / 16) * 16;
341
+ if (before.get(key) === rounded) return before;
342
+ const next = new Map(before);
343
+ if (rounded === void 0) next.delete(key);
344
+ else next.set(key, rounded);
345
+ return next;
346
+ }), []);
347
+ const wanted = shown.filter((tile) => !tile.self && publishes(tile.participant, tile.video)).slice(0, 9);
348
+ const full = wanted.filter((tile) => layerFor(widths.get(tile.key) ?? 0) === "f").sort((a, b) => (widths.get(b.key) ?? 0) - (widths.get(a.key) ?? 0)).slice(0, 2).map((tile) => tile.key);
349
+ const plan = wanted.map((tile) => {
350
+ const width = widths.get(tile.key);
351
+ const layer = width === void 0 ? "h" : layerFor(width) === "f" && !full.includes(tile.key) ? "h" : layerFor(width);
352
+ return {
353
+ key: tile.key,
354
+ participant: tile.participant.id,
355
+ name: tile.video,
356
+ layer
357
+ };
358
+ });
359
+ const planned = JSON.stringify(plan);
360
+ const layers = useRef(/* @__PURE__ */ new Map());
361
+ const queue = useRef(Promise.resolve());
362
+ useEffect(() => {
363
+ if (!call || !live(state)) {
364
+ layers.current.clear();
365
+ return;
366
+ }
367
+ const asked = new Map(plan.map((entry) => [entry.key, entry]));
368
+ queue.current = queue.current.then(async () => {
369
+ for (const participant of call.participants) for (const name of VIDEOS) {
370
+ const key = `${participant.id}/${name}`;
371
+ if (participant.received[name] && !asked.has(key)) {
372
+ await call.stopReceiving(participant.id, name).catch(noop);
373
+ layers.current.delete(key);
374
+ }
375
+ }
376
+ for (const entry of asked.values()) {
377
+ const participant = call.participants.find((one) => one.id === entry.participant);
378
+ if (!participant || !publishes(participant, entry.name)) continue;
379
+ if (!participant.received[entry.name]) await call.receive(entry.participant, entry.name, { layer: entry.layer }).catch(noop);
380
+ else if ((layers.current.get(entry.key) ?? "h") !== entry.layer) await call.setLayer(entry.participant, entry.name, entry.layer).catch(noop);
381
+ layers.current.set(entry.key, entry.layer);
382
+ }
383
+ });
384
+ }, [
385
+ call,
386
+ state,
387
+ planned
388
+ ]);
389
+ const cameras = shown.filter((tile) => tile.video === "camera").length + (more ? 1 : 0);
390
+ const screens = shown.length - shown.filter((tile) => tile.video === "camera").length;
391
+ const most = cameras <= 1 ? 1 : cameras <= 4 ? 2 : cameras <= 9 ? 3 : 4;
392
+ const columns = stage === void 0 ? most : stage <= 360 ? 1 : stage <= 560 ? Math.min(most, 2) : stage <= 720 ? Math.min(most, 3) : most;
393
+ const rows = Math.ceil(cameras / columns) + screens * columns;
394
+ const sounds = present.flatMap((participant) => ["mic", "screen-audio"].flatMap((name) => {
395
+ const track = participant.received[name];
396
+ return track ? [createElement(Audio, {
397
+ key: `${participant.id}/${name}`,
398
+ track
399
+ })] : [];
400
+ }));
401
+ return createElement(Widths.Provider, { value: report }, createElement(Root, {
402
+ className: cx("msc-grid", className),
403
+ elementRef: grid,
404
+ attributes: {
405
+ "data-cols": String(columns),
406
+ style: { "--_rows": String(rows) }
407
+ }
408
+ }, ...shown.map((tile) => createElement(CallTile, {
409
+ key: tile.key,
410
+ participant: tile.participant,
411
+ video: tile.video,
412
+ self: tile.self
413
+ })), more > 0 && createElement("div", {
414
+ key: "more",
415
+ className: "msc-tile msc-more"
416
+ }, `+${more} more`), ...sounds));
417
+ }
418
+ const VIDEOS = ["camera", "screen"];
419
+ /** The most people the grid gives a tile of their own, the last place being the count of the rest past it. */
420
+ const MAX_TILES = 16;
421
+ const publishes = (participant, name) => participant.tracks.some((track) => track.name === name);
422
+ /** One person's tile: their video once it is received, else their initials; their name, a muted microphone, and a ring while they speak. */
423
+ function CallTile({ participant, video = "camera", self = false, className }) {
424
+ const local = useLocalTracks();
425
+ const mine = (name) => local.find((track) => track.name === name && !track.muted)?.track;
426
+ const track = self ? mine(video) : participant.received[video];
427
+ const mic = self ? mine("mic") : participant.received.mic;
428
+ const silent = useMicOff(participant, self);
429
+ const speaking = useSpeaking(video === "camera" && !silent ? mic : void 0);
430
+ const away = participant.state === "away";
431
+ const name = self ? "You" : participant.name;
432
+ const ref = useRef(null);
433
+ const report = useContext(Widths);
434
+ const key = `${self ? "self" : participant.id}/${video}`;
435
+ useEffect(() => {
436
+ const element = ref.current;
437
+ if (!report || !element || typeof ResizeObserver === "undefined") return;
438
+ const observer = new ResizeObserver(([entry]) => {
439
+ if (entry) report(key, entry.contentRect.width);
440
+ });
441
+ observer.observe(element);
442
+ return () => {
443
+ observer.disconnect();
444
+ report(key, void 0);
445
+ };
446
+ }, [report, key]);
447
+ return createElement(Root, {
448
+ tag: "figure",
449
+ className: cx("msc-tile", className),
450
+ elementRef: ref,
451
+ attributes: {
452
+ ...video === "screen" ? { "data-screen": "" } : {},
453
+ ...speaking ? { "data-speaking": "" } : {},
454
+ ...away ? { "data-away": "" } : {}
455
+ }
456
+ }, track ? createElement(Video, {
457
+ track,
458
+ className: "msc-video",
459
+ ...self && video === "camera" ? { "data-mirror": "" } : {}
460
+ }) : createElement(Initials, { name: participant.name }), createElement("figcaption", { className: "msc-label" }, video === "screen" ? createElement(Icon, {
461
+ name: "screen",
462
+ label: "Screen"
463
+ }) : silent && createElement(Icon, {
464
+ name: "micOff",
465
+ label: "Microphone off",
466
+ danger: true
467
+ }), tipped(name, createElement("span", {
468
+ className: "msc-name",
469
+ "data-truncated-text": ""
470
+ }, name)), away && createElement("span", { className: "msc-away" }, "Away")));
471
+ }
472
+ /** The call's controls: the room's name, microphone, camera, screen sharing and Leave, and the participant list's button. */
473
+ function CallControls({ publish = false, onLeave, people, className }) {
474
+ const call = useCall();
475
+ const state = useCallState();
476
+ const local = useLocalTracks();
477
+ const participants = useParticipants();
478
+ const [pending, setPending] = useState(() => /* @__PURE__ */ new Set());
479
+ const [problem, setProblem] = useState();
480
+ const ready = Boolean(call) && live(state);
481
+ const run = useCallback((what, act) => {
482
+ setProblem(void 0);
483
+ setPending((before) => new Set(before).add(what));
484
+ act().catch((error) => setProblem(messageOf(error))).finally(() => setPending((before) => {
485
+ const next = new Set(before);
486
+ next.delete(what);
487
+ return next;
488
+ }));
489
+ }, []);
490
+ const started = useRef(false);
491
+ useEffect(() => {
492
+ if (!publish || started.current || !call || !live(state)) return;
493
+ started.current = true;
494
+ run("start", () => call.publish({
495
+ mic: true,
496
+ camera: true
497
+ }).catch((both) => call.publish({ mic: true }).catch(() => {
498
+ throw both;
499
+ })));
500
+ }, [
501
+ publish,
502
+ call,
503
+ state,
504
+ run
505
+ ]);
506
+ const track = (name) => local.find((one) => one.name === name);
507
+ const mic = track("mic"), camera = track("camera"), screen = track("screen");
508
+ const micOn = Boolean(mic && !mic.muted), cameraOn = Boolean(camera && !camera.muted);
509
+ const canShare = typeof navigator !== "undefined" && typeof navigator.mediaDevices?.getDisplayMedia === "function";
510
+ const busy = (what) => pending.has(what) || pending.has("start");
511
+ const count = participants.filter((participant) => participant.state !== "left").length + (call ? 1 : 0);
512
+ const toggle = (what, label, on, icons, act) => tipped(label, createElement("button", {
513
+ type: "button",
514
+ className: "msc-control",
515
+ "data-icon-only": "",
516
+ ...on ? {} : { "data-off": "" },
517
+ "aria-label": label,
518
+ "aria-pressed": on,
519
+ "aria-busy": busy(what),
520
+ disabled: !ready || busy(what),
521
+ onClick: () => {
522
+ if (call) run(what, act);
523
+ }
524
+ }, createElement(Icon, { name: on ? icons[0] : icons[1] })));
525
+ return createElement(Root, { className: cx("msc-bar", className) }, problem && createElement("div", {
526
+ className: "msc-alert",
527
+ role: "alert"
528
+ }, createElement(Icon, { name: "warning" }), createElement("span", null, problem), createElement("button", {
529
+ type: "button",
530
+ className: "msc-quiet",
531
+ "aria-label": "Dismiss",
532
+ onClick: () => setProblem(void 0)
533
+ }, createElement(Icon, { name: "close" }))), createElement("span", { className: "msc-room" }, call?.room ?? ""), createElement("div", {
534
+ className: "msc-controls",
535
+ role: "group",
536
+ "aria-label": "Call controls"
537
+ }, call && toggle("mic", "Microphone", micOn, ["mic", "micOff"], () => mic ? mic.muted ? call.unmute("mic") : call.mute("mic") : call.publish({ mic: true })), call && toggle("camera", "Camera", cameraOn, ["camera", "cameraOff"], () => cameraOn ? call.unpublish("camera") : camera ? call.unmute("camera") : call.publish({ camera: true })), call && canShare && tipped(screen ? "Stop sharing" : "Share screen", createElement("button", {
538
+ type: "button",
539
+ className: "msc-control",
540
+ "data-icon-only": "",
541
+ "aria-label": "Share screen",
542
+ "aria-pressed": Boolean(screen),
543
+ "aria-busy": busy("screen"),
544
+ disabled: !ready || busy("screen"),
545
+ onClick: () => run("screen", () => screen ? call.screen.stop() : call.screen.share())
546
+ }, createElement(Icon, { name: "screen" }))), tipped("Leave", createElement("button", {
547
+ type: "button",
548
+ className: "msc-control msc-leave",
549
+ "data-icon-only": "",
550
+ "aria-label": "Leave",
551
+ disabled: !call || state === "ended" || state === "failed",
552
+ onClick: () => {
553
+ onLeave?.();
554
+ call?.leave();
555
+ }
556
+ }, createElement(Icon, { name: "leave" })))), createElement("div", { className: "msc-bar-end" }, people && createElement("button", {
557
+ type: "button",
558
+ className: "msc-control",
559
+ "data-word": "",
560
+ "aria-expanded": people.open,
561
+ ...people.open && people.controls ? { "aria-controls": people.controls } : {},
562
+ "aria-label": `People, ${count}`,
563
+ onClick: people.onToggle
564
+ }, createElement(Icon, { name: "people" }), createElement("span", { className: "msc-word" }, "People"), createElement("span", {
565
+ className: "msc-count",
566
+ "aria-hidden": true
567
+ }, count))));
568
+ }
569
+ /**
570
+ * An icon-only control with its name shown above it on hover and focus. The tip is the button's sibling, so the
571
+ * button keeps its own size; screen readers have the name from the button's label.
572
+ */
573
+ function tipped(tip, button) {
574
+ return createElement("span", { className: "msc-tipped" }, button, createElement("span", {
575
+ className: "msc-tip",
576
+ "aria-hidden": true
577
+ }, tip));
578
+ }
579
+ /** Who is in the call: you first, then the others as they joined, with who is away and whose microphone is off. */
580
+ function ParticipantList({ id, onClose, className }) {
581
+ const call = useCall();
582
+ const participants = useParticipants();
583
+ const titleId = useId();
584
+ const everyone = call ? [call.me, ...participants.filter((participant) => participant.state !== "left")] : [];
585
+ return createElement(Root, {
586
+ tag: "section",
587
+ className: cx("msc-people", className),
588
+ attributes: {
589
+ ...id ? { id } : {},
590
+ "aria-labelledby": titleId
591
+ }
592
+ }, createElement("div", { className: "msc-people-head" }, createElement("h2", {
593
+ id: titleId,
594
+ className: "msc-people-title"
595
+ }, "People", createElement("span", null, everyone.length)), onClose && createElement("button", {
596
+ type: "button",
597
+ className: "msc-quiet",
598
+ "aria-label": "Close",
599
+ onClick: onClose
600
+ }, createElement(Icon, { name: "close" }))), createElement("ul", { className: "msc-people-list" }, ...everyone.map((participant, index) => createElement(Person, {
601
+ key: participant.id,
602
+ participant,
603
+ self: index === 0
604
+ }))));
605
+ }
606
+ function Person({ participant, self }) {
607
+ const off = useMicOff(participant, self);
608
+ const away = participant.state === "away";
609
+ return createElement("li", {
610
+ className: "msc-person",
611
+ ...away ? { "data-away": "" } : {}
612
+ }, createElement(Initials, { name: participant.name }), createElement("span", { className: "msc-person-copy" }, createElement("span", { className: "msc-person-name" }, participant.name), (self || away) && createElement("span", { className: "msc-person-detail" }, self ? "You" : "Away")), off && createElement(Icon, {
613
+ name: "micOff",
614
+ label: "Microphone off",
615
+ danger: true
616
+ }));
617
+ }
618
+ /** Someone's first letters in a circle, for a tile without video and the participant list. */
619
+ function Initials({ name }) {
620
+ const letters = name.trim().split(/\s+/u).slice(0, 2).map((word) => [...word][0] ?? "").join("").toUpperCase();
621
+ return createElement("span", {
622
+ className: "msc-avatar",
623
+ "aria-hidden": true
624
+ }, letters || "?");
625
+ }
626
+ /**
627
+ * Whether someone's microphone sends nothing: yours when it is muted or off; another's when they publish none, or
628
+ * when the one received has gone quiet because they muted it.
629
+ */
630
+ function useMicOff(participant, self) {
631
+ const local = useLocalTracks();
632
+ const quiet = useTrackMuted(self ? void 0 : participant.received.mic);
633
+ if (self) {
634
+ const mic = local.find((track) => track.name === "mic");
635
+ return !mic || mic.muted;
636
+ }
637
+ return !publishes(participant, "mic") || quiet;
638
+ }
639
+ function useTrackMuted(track) {
640
+ const [muted, setMuted] = useState(false);
641
+ useEffect(() => {
642
+ if (!track) {
643
+ setMuted(false);
644
+ return;
645
+ }
646
+ const read = () => setMuted(track.muted);
647
+ read();
648
+ track.addEventListener("mute", read);
649
+ track.addEventListener("unmute", read);
650
+ return () => {
651
+ track.removeEventListener("mute", read);
652
+ track.removeEventListener("unmute", read);
653
+ };
654
+ }, [track]);
655
+ return muted;
656
+ }
657
+ /** One audio context for every tile's level, made as the first tile listens. */
658
+ let listening;
659
+ /** Whether a microphone track is loud enough to be speech now, held for a moment after it goes quiet. */
660
+ function useSpeaking(track) {
661
+ const [speaking, setSpeaking] = useState(false);
662
+ useEffect(() => {
663
+ if (!track || typeof AudioContext === "undefined") {
664
+ setSpeaking(false);
665
+ return;
666
+ }
667
+ const context = listening ??= new AudioContext();
668
+ if (context.state === "suspended") context.resume().catch(noop);
669
+ const source = context.createMediaStreamSource(new MediaStream([track]));
670
+ const analyser = context.createAnalyser();
671
+ analyser.fftSize = 512;
672
+ source.connect(analyser);
673
+ const samples = new Uint8Array(analyser.fftSize);
674
+ let heard = 0;
675
+ const timer = setInterval(() => {
676
+ analyser.getByteTimeDomainData(samples);
677
+ let sum = 0;
678
+ for (const sample of samples) {
679
+ const value = (sample - 128) / 128;
680
+ sum += value * value;
681
+ }
682
+ if (Math.sqrt(sum / samples.length) > .035) heard = Date.now();
683
+ setSpeaking(Date.now() - heard < 400);
684
+ }, 120);
685
+ return () => {
686
+ clearInterval(timer);
687
+ source.disconnect();
688
+ analyser.disconnect();
689
+ setSpeaking(false);
690
+ };
691
+ }, [track]);
692
+ return speaking;
693
+ }
694
+ /** Whether a part is inside another, which brought the stylesheet and the `.msc` scope already. */
695
+ const Scoped = createContext(false);
696
+ /**
697
+ * A part's outer element: the first one on the page brings the stylesheet and the `.msc` scope its tokens are set on,
698
+ * so a part used on its own looks the same as inside `<Call>`.
699
+ */
700
+ function Root({ tag = "div", className, theme, elementRef, attributes, children }) {
701
+ const inside = useContext(Scoped);
702
+ const style = useMemo(() => createElement("style", { "data-msc": "" }, CSS), []);
703
+ const own = {
704
+ ...attributes,
705
+ ...elementRef ? { ref: elementRef } : {}
706
+ };
707
+ const list = Array.isArray(children) ? children : [children];
708
+ if (inside) return createElement(tag, {
709
+ ...own,
710
+ className
711
+ }, ...list);
712
+ return createElement(Scoped.Provider, { value: true }, createElement(tag, {
713
+ ...own,
714
+ className: cx("msc", className),
715
+ ...theme ? { "data-msc-theme": theme } : {}
716
+ }, style, ...list));
717
+ }
718
+ /** The icons the call draws, in Midsummer's line style: 24px, 1.5px strokes, round ends. */
719
+ const ICONS = {
720
+ mic: [
721
+ "M12 15.25a3.25 3.25 0 0 0 3.25-3.25V6a3.25 3.25 0 1 0-6.5 0v6A3.25 3.25 0 0 0 12 15.25Z",
722
+ "M18.25 11.5a6.25 6.25 0 0 1-12.5 0",
723
+ "M12 17.75v3.5"
724
+ ],
725
+ micOff: [
726
+ "M15.25 9.5V6a3.25 3.25 0 0 0-6.37-.92",
727
+ "M8.75 8.75V12a3.25 3.25 0 0 0 5.47 2.38",
728
+ "M18.25 11.5a6.2 6.2 0 0 1-.9 3.23",
729
+ "M5.75 11.5a6.25 6.25 0 0 0 10.26 4.8",
730
+ "M12 17.75v3.5",
731
+ "M3.75 3.75l16.5 16.5"
732
+ ],
733
+ camera: ["M2.75 7.75a2 2 0 0 1 2-2h8.5a2 2 0 0 1 2 2v8.5a2 2 0 0 1-2 2h-8.5a2 2 0 0 1-2-2Z", "M15.25 10.5l5.08-2.9a.6.6 0 0 1 .92.52v7.76a.6.6 0 0 1-.92.52l-5.08-2.9"],
734
+ cameraOff: [
735
+ "M9.25 5.75h4a2 2 0 0 1 2 2v4",
736
+ "M15.25 15.25v1a2 2 0 0 1-2 2h-8.5a2 2 0 0 1-2-2v-8.5a2 2 0 0 1 1.5-1.94",
737
+ "M15.25 10.5l5.08-2.9a.6.6 0 0 1 .92.52v7.76a.6.6 0 0 1-.92.52l-2.08-1.19",
738
+ "M3.75 3.75l16.5 16.5"
739
+ ],
740
+ screen: [
741
+ "M3.75 4.75h16.5a1 1 0 0 1 1 1v10.5a1 1 0 0 1-1 1H3.75a1 1 0 0 1-1-1V5.75a1 1 0 0 1 1-1Z",
742
+ "M8.75 20.25h6.5",
743
+ "M12 14V8",
744
+ "M9.25 10.75L12 8l2.75 2.75"
745
+ ],
746
+ leave: ["M3.4 13.9c-.6-.6-.65-1.6 0-2.2C5.7 9.5 8.8 8.25 12 8.25s6.3 1.25 8.6 3.45c.65.6.6 1.6 0 2.2l-1.45 1.45a1.25 1.25 0 0 1-1.6.14l-1.86-1.3a1.25 1.25 0 0 1-.53-1.02V11.6a9.6 9.6 0 0 0-6.32 0v1.57c0 .41-.2.79-.53 1.02l-1.86 1.3a1.25 1.25 0 0 1-1.6-.14Z"],
747
+ people: [
748
+ "M9 11.25a3.5 3.5 0 1 0 0-7a3.5 3.5 0 0 0 0 7Z",
749
+ "M2.75 19.25c.6-3.1 3-5 6.25-5s5.65 1.9 6.25 5",
750
+ "M15.5 4.4a3.5 3.5 0 0 1 0 6.7",
751
+ "M17.75 14.5c2 .6 3.2 2.3 3.5 4.75"
752
+ ],
753
+ close: ["M6.75 6.75l10.5 10.5", "M17.25 6.75l-10.5 10.5"],
754
+ again: ["M19.25 12a7.25 7.25 0 1 1-2.12-5.13", "M19.25 4.75v4h-4"],
755
+ warning: [
756
+ "M12 9.25v3.5",
757
+ "M12 15.75h.01",
758
+ "M10.27 4.25 2.9 17a2 2 0 0 0 1.73 3h14.74a2 2 0 0 0 1.73-3L13.73 4.25a2 2 0 0 0-3.46 0Z"
759
+ ]
760
+ };
761
+ /** An icon, hidden from screen readers unless it says something its control doesn't (`label`). */
762
+ function Icon({ name, label, danger = false }) {
763
+ return createElement("svg", {
764
+ className: "msc-icon",
765
+ ...danger ? { "data-tone": "danger" } : {},
766
+ viewBox: "0 0 24 24",
767
+ fill: "none",
768
+ stroke: "currentColor",
769
+ strokeWidth: 1.5,
770
+ strokeLinecap: "round",
771
+ strokeLinejoin: "round",
772
+ focusable: "false",
773
+ ...label ? {
774
+ role: "img",
775
+ "aria-label": label
776
+ } : { "aria-hidden": true }
777
+ }, ...ICONS[name].map((d) => createElement("path", {
778
+ key: d,
779
+ d
780
+ })));
781
+ }
782
+ //#endregion
783
+ export { Call, CallControls, CallGrid, CallTile, ParticipantList };