foldkit-primitives 0.9.0 → 0.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -1
- package/dist/device/index.d.mts +69 -36
- package/dist/device/index.d.mts.map +1 -1
- package/dist/device/index.mjs +34 -34
- package/dist/device/index.mjs.map +1 -1
- package/dist/dom/index.d.mts +68 -19
- package/dist/dom/index.d.mts.map +1 -1
- package/dist/dom/index.mjs +32 -25
- package/dist/dom/index.mjs.map +1 -1
- package/dist/{editable-text-BbsPOATY.d.mts → editable-text-Dvm-Fuqs.d.mts} +65 -3
- package/dist/editable-text-Dvm-Fuqs.d.mts.map +1 -0
- package/dist/events/index.d.mts +52 -31
- package/dist/events/index.d.mts.map +1 -1
- package/dist/events/index.mjs +40 -28
- package/dist/events/index.mjs.map +1 -1
- package/dist/{follow-tab-stop-BDxyoUPQ.mjs → follow-tab-stop-Ci1tqAIW.mjs} +63 -61
- package/dist/follow-tab-stop-Ci1tqAIW.mjs.map +1 -0
- package/dist/{index-Cppf-lBx.d.mts → index-CmmxqSEi.d.mts} +34 -15
- package/dist/index-CmmxqSEi.d.mts.map +1 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +3 -3
- package/dist/{input-modality-m6v7__Xs.mjs → input-modality-BXD383jg.mjs} +9 -9
- package/dist/input-modality-BXD383jg.mjs.map +1 -0
- package/dist/{input-modality-DGOhAknO.d.mts → input-modality-BY-bSrEc.d.mts} +9 -2
- package/dist/input-modality-BY-bSrEc.d.mts.map +1 -0
- package/dist/interaction/index.d.mts +118 -118
- package/dist/interaction/index.d.mts.map +1 -1
- package/dist/interaction/index.mjs +3 -3
- package/dist/interaction/index.mjs.map +1 -1
- package/dist/media/index.d.mts +24 -3
- package/dist/media/index.d.mts.map +1 -1
- package/dist/media/index.mjs +23 -13
- package/dist/media/index.mjs.map +1 -1
- package/dist/motion/index.d.mts +1 -1
- package/dist/motion/index.mjs +1 -2
- package/dist/{motion-DGGBZ0wt.mjs → motion-DmFDppRn.mjs} +20 -20
- package/dist/{motion-DGGBZ0wt.mjs.map → motion-DmFDppRn.mjs.map} +1 -1
- package/dist/net/index.d.mts +63 -25
- package/dist/net/index.d.mts.map +1 -1
- package/dist/net/index.mjs +31 -31
- package/dist/net/index.mjs.map +1 -1
- package/dist/observers/index.d.mts +25 -0
- package/dist/observers/index.d.mts.map +1 -1
- package/dist/observers/index.mjs +22 -22
- package/dist/observers/index.mjs.map +1 -1
- package/dist/state/index.d.mts +98 -44
- package/dist/state/index.d.mts.map +1 -1
- package/dist/state/index.mjs +39 -39
- package/dist/state/index.mjs.map +1 -1
- package/dist/time/index.d.mts +35 -5
- package/dist/time/index.d.mts.map +1 -1
- package/dist/time/index.mjs +20 -20
- package/dist/time/index.mjs.map +1 -1
- package/package.json +14 -14
- package/dist/editable-text-BbsPOATY.d.mts.map +0 -1
- package/dist/follow-tab-stop-BDxyoUPQ.mjs.map +0 -1
- package/dist/index-Cppf-lBx.d.mts.map +0 -1
- package/dist/input-modality-DGOhAknO.d.mts.map +0 -1
- package/dist/input-modality-m6v7__Xs.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -106,7 +106,7 @@ import * as Subscription from 'foldkit/subscription'
|
|
|
106
106
|
import { keyboardEvents } from 'foldkit-primitives/events'
|
|
107
107
|
|
|
108
108
|
const subscriptions = Subscription.make<GameModel, GameMessage>()(() => ({
|
|
109
|
-
keys: Subscription.
|
|
109
|
+
keys: Subscription.persistentEntry(
|
|
110
110
|
keyboardEvents({ preventDefault: press => press.key.startsWith('Arrow') }).pipe(
|
|
111
111
|
Stream.filter(event => event._tag === 'Pressed'),
|
|
112
112
|
Stream.map(({ key }) => GameMessage.PressedKey({ key })),
|
|
@@ -138,6 +138,36 @@ const copy = (model: NoteModel): Update.Return<NoteModel, NoteMessage> => ({
|
|
|
138
138
|
})
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
+
## Find one by the job
|
|
142
|
+
|
|
143
|
+
| You want to | Reach for | In |
|
|
144
|
+
| --- | --- | --- |
|
|
145
|
+
| Follow the color scheme, reduced motion or any media query | `MediaQuery`, `PrefersDark`, `PrefersReducedMotion` | [media](./media/README.md) |
|
|
146
|
+
| Change the layout at named widths | `Breakpoints` | [media](./media/README.md) |
|
|
147
|
+
| Know whether the tab is visible, the window's size, or the user idle | `Visibility`, `WindowSize`, `Idle` | [events](./events/README.md) |
|
|
148
|
+
| Answer keyboard shortcuts | `keyboardEvents` with `matchHotkey` | [events](./events/README.md) |
|
|
149
|
+
| Count ticks, or run something on an interval | `Timer`, `Interval`, `ticks` | [time](./time/README.md) |
|
|
150
|
+
| Wait until typing stops, or limit how often something runs | `debounce`, `Throttle` | [time](./time/README.md) |
|
|
151
|
+
| Say "3 minutes ago" | `formatRelativeTime` | [time](./time/README.md) |
|
|
152
|
+
| Page through a list | `Pagination`, `range` | [state](./state/README.md) |
|
|
153
|
+
| Undo and redo | `history` | [state](./state/README.md) |
|
|
154
|
+
| Draw only the visible rows of a long list | `Virtual` | [state](./state/README.md) |
|
|
155
|
+
| Animate a value, or let an element leave before it is removed | `Tween`, `Spring`, `Presence` | [motion](./motion/README.md) |
|
|
156
|
+
| Move with arrow keys through a toolbar, list, grid or tree | `RovingTabindex`, `ListNavigation`, `GridNavigation`, `TreeNavigation` | [interaction](./interaction/README.md) |
|
|
157
|
+
| Close a popup on Escape or an outside press | `DismissLayer`, `Overlay` | [interaction](./interaction/README.md) |
|
|
158
|
+
| Press, long-press or drag | `Press`, `LongPress`, `Move`, `PointerDrag` | [interaction](./interaction/README.md) |
|
|
159
|
+
| Edit text in place | `EditableText` | [interaction](./interaction/README.md) |
|
|
160
|
+
| Tell a screen reader what changed | `LiveAnnounce` | [interaction](./interaction/README.md) |
|
|
161
|
+
| Know whether the browser is online, or talk over a socket | `Online`, `websocket`, `sse` | [net](./net/README.md) |
|
|
162
|
+
| Talk between tabs | `broadcastMessages`, `SharedHost` | [net](./net/README.md) |
|
|
163
|
+
| Use the camera, the location or a permission | `mediaStream`, `Geolocation`, `permissions` | [device](./device/README.md) |
|
|
164
|
+
| Track one element's size or visibility | `Resize`, `Intersection`, `Bounds` | [observers](./observers/README.md) |
|
|
165
|
+
| Focus, mask or keep an element in view | `Autofocus`, `InputMask`, `KeepInView` | [dom](./dom/README.md) |
|
|
166
|
+
| Copy, share, load a script or restore scroll | `copyText`, `share`, `loadScript`, `keepScroll` | [dom](./dom/README.md) |
|
|
167
|
+
|
|
168
|
+
Working widgets built from the interaction primitives are listed under
|
|
169
|
+
[In the examples](./interaction/README.md#in-the-examples).
|
|
170
|
+
|
|
141
171
|
## The map
|
|
142
172
|
|
|
143
173
|
Each subpath is one concern and one import. Its README has the full
|
package/dist/device/index.d.mts
CHANGED
|
@@ -5,12 +5,12 @@ import { Command } from "foldkit/command";
|
|
|
5
5
|
//#region src/device/fullscreen.d.ts
|
|
6
6
|
export declare const FullscreenMessage: import("foldkit/message").MessageUnion<{
|
|
7
7
|
readonly Changed: {
|
|
8
|
-
|
|
8
|
+
active: Schema.Boolean;
|
|
9
9
|
};
|
|
10
10
|
readonly Entered: {};
|
|
11
11
|
readonly Exited: {};
|
|
12
12
|
readonly Failed: {
|
|
13
|
-
|
|
13
|
+
message: Schema.String;
|
|
14
14
|
};
|
|
15
15
|
}>;
|
|
16
16
|
export type FullscreenMessage = typeof FullscreenMessage.Type;
|
|
@@ -48,18 +48,24 @@ export declare const GeolocationModel: Schema.Struct<{
|
|
|
48
48
|
export type GeolocationModel = typeof GeolocationModel.Type;
|
|
49
49
|
export declare const GeolocationMessage: import("foldkit/message").MessageUnion<{
|
|
50
50
|
readonly Located: {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
latitude: Schema.Number;
|
|
52
|
+
longitude: Schema.Number;
|
|
53
|
+
accuracy: Schema.Number;
|
|
54
54
|
};
|
|
55
55
|
readonly Denied: {};
|
|
56
56
|
readonly Failed: {
|
|
57
|
-
|
|
57
|
+
message: Schema.String;
|
|
58
58
|
};
|
|
59
59
|
}>;
|
|
60
60
|
export type GeolocationMessage = typeof GeolocationMessage.Type;
|
|
61
|
+
/**
|
|
62
|
+
* Geolocation as a bundle: the device position in the Model, watched while
|
|
63
|
+
* placed. Permission denial is its own status (actionable UI); transient
|
|
64
|
+
* failures keep the last fix and note the error. No geolocation API yields
|
|
65
|
+
* an empty stream instead of throwing.
|
|
66
|
+
*/
|
|
61
67
|
export declare const Geolocation: Bundle.Bundle<"Geolocation", void, {
|
|
62
|
-
readonly status: "
|
|
68
|
+
readonly status: "denied" | "ready" | "unknown";
|
|
63
69
|
readonly coords: {
|
|
64
70
|
readonly latitude: number;
|
|
65
71
|
readonly longitude: number;
|
|
@@ -101,7 +107,7 @@ export declare const MediaDevicesMessage: import("foldkit/message").MessageUnion
|
|
|
101
107
|
readonly Scan: {};
|
|
102
108
|
readonly DevicesChanged: {};
|
|
103
109
|
readonly Refreshed: {
|
|
104
|
-
|
|
110
|
+
devices: Schema.$Array<Schema.Struct<{
|
|
105
111
|
readonly deviceId: Schema.String;
|
|
106
112
|
readonly groupId: Schema.String;
|
|
107
113
|
readonly kind: Schema.Literals<readonly ["audioinput", "audiooutput", "videoinput"]>;
|
|
@@ -110,7 +116,7 @@ export declare const MediaDevicesMessage: import("foldkit/message").MessageUnion
|
|
|
110
116
|
};
|
|
111
117
|
readonly Denied: {};
|
|
112
118
|
readonly Failed: {
|
|
113
|
-
|
|
119
|
+
message: Schema.String;
|
|
114
120
|
};
|
|
115
121
|
}>;
|
|
116
122
|
export type MediaDevicesMessage = typeof MediaDevicesMessage.Type;
|
|
@@ -125,12 +131,20 @@ export interface MediaDevicesHandle {
|
|
|
125
131
|
addEventListener(type: string, listener: () => void): void;
|
|
126
132
|
removeEventListener(type: string, listener: () => void): void;
|
|
127
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Media devices as a bundle factory: the enumerated device list in the
|
|
136
|
+
* Model, scanned on placement and re-scanned on every `devicechange`.
|
|
137
|
+
* Denial lands as `denied` while keeping the last list (actionable UI over
|
|
138
|
+
* stale data, like Geolocation's last fix); any other failure keeps the
|
|
139
|
+
* list and notes the error. No media-devices API yields an empty stream
|
|
140
|
+
* and a `Failed` scan instead of throwing.
|
|
141
|
+
*/
|
|
128
142
|
export declare const mediaDevices: <const Name extends string>(config: {
|
|
129
143
|
readonly name: Name;
|
|
130
144
|
/** Read lazily so tests can substitute a double, like the SSE bundle. */
|
|
131
145
|
readonly create?: ((navigator: Navigator) => MediaDevicesHandle | null) | undefined;
|
|
132
146
|
}) => Bundle.Bundle<Name, void, {
|
|
133
|
-
readonly status: "
|
|
147
|
+
readonly status: "denied" | "ready" | "unknown";
|
|
134
148
|
readonly devices: readonly {
|
|
135
149
|
readonly deviceId: string;
|
|
136
150
|
readonly groupId: string;
|
|
@@ -139,12 +153,12 @@ export declare const mediaDevices: <const Name extends string>(config: {
|
|
|
139
153
|
}[];
|
|
140
154
|
readonly lastError: string | null;
|
|
141
155
|
}, {
|
|
142
|
-
readonly _tag: "
|
|
143
|
-
readonly message: string;
|
|
144
|
-
} | {
|
|
145
|
-
readonly _tag: "Scan";
|
|
156
|
+
readonly _tag: "Denied";
|
|
146
157
|
} | {
|
|
147
158
|
readonly _tag: "DevicesChanged";
|
|
159
|
+
} | {
|
|
160
|
+
readonly _tag: "Failed";
|
|
161
|
+
readonly message: string;
|
|
148
162
|
} | {
|
|
149
163
|
readonly _tag: "Refreshed";
|
|
150
164
|
readonly devices: readonly {
|
|
@@ -154,7 +168,7 @@ export declare const mediaDevices: <const Name extends string>(config: {
|
|
|
154
168
|
readonly label: string;
|
|
155
169
|
}[];
|
|
156
170
|
} | {
|
|
157
|
-
readonly _tag: "
|
|
171
|
+
readonly _tag: "Scan";
|
|
158
172
|
}, never, never, never, void, {}, {}>;
|
|
159
173
|
//#endregion
|
|
160
174
|
//#region src/device/media-stream.d.ts
|
|
@@ -170,7 +184,7 @@ export declare const MediaStreamMessage: import("foldkit/message").MessageUnion<
|
|
|
170
184
|
readonly Ended: {};
|
|
171
185
|
readonly Denied: {};
|
|
172
186
|
readonly Failed: {
|
|
173
|
-
|
|
187
|
+
message: Schema.String;
|
|
174
188
|
};
|
|
175
189
|
}>;
|
|
176
190
|
export type MediaStreamMessage = typeof MediaStreamMessage.Type;
|
|
@@ -182,6 +196,7 @@ export interface MediaTrackHandle {
|
|
|
182
196
|
export interface MediaStreamHandle {
|
|
183
197
|
getTracks(): ReadonlyArray<MediaTrackHandle>;
|
|
184
198
|
}
|
|
199
|
+
/** Which tracks `mediaStream` asks `getUserMedia` for. */
|
|
185
200
|
export interface MediaStreamConstraints {
|
|
186
201
|
readonly audio: boolean;
|
|
187
202
|
readonly video: boolean;
|
|
@@ -190,6 +205,15 @@ export interface MediaStreamConstraints {
|
|
|
190
205
|
export declare const LiveStream: ManagedResource.ManagedResource<MediaStreamHandle, ManagedResource.ManagedResourceService<"media-stream">>;
|
|
191
206
|
/** The stream service a placed camera requires. */
|
|
192
207
|
export type LiveStreamService = ManagedResource.ServiceOf<typeof LiveStream>;
|
|
208
|
+
/**
|
|
209
|
+
* A camera/mic stream as a bundle factory: one live MediaStream held in a
|
|
210
|
+
* Managed Resource while the Model asks for it. `Started` requests,
|
|
211
|
+
* `Stopped` releases; denial parks at `denied` (actionable UI), any other
|
|
212
|
+
* acquire failure parks at `idle` with the error noted — both clear
|
|
213
|
+
* requirements, so a failing device never spins an acquire loop. Release
|
|
214
|
+
* stops every track. No media-devices API fails the acquire instead of
|
|
215
|
+
* throwing.
|
|
216
|
+
*/
|
|
193
217
|
export declare const mediaStream: <const Name extends string>(config: {
|
|
194
218
|
readonly name: Name;
|
|
195
219
|
/** Read lazily so tests can substitute a double, like the SSE bundle. */
|
|
@@ -198,38 +222,38 @@ export declare const mediaStream: <const Name extends string>(config: {
|
|
|
198
222
|
readonly audio: boolean;
|
|
199
223
|
readonly video: boolean;
|
|
200
224
|
}, {
|
|
201
|
-
readonly status: "denied" | "idle" | "
|
|
225
|
+
readonly status: "denied" | "idle" | "live" | "requesting";
|
|
202
226
|
readonly lastError: string | null;
|
|
203
227
|
}, {
|
|
204
|
-
readonly _tag: "Started";
|
|
205
|
-
} | {
|
|
206
|
-
readonly _tag: "Stopped";
|
|
207
|
-
} | {
|
|
208
228
|
readonly _tag: "Denied";
|
|
209
229
|
} | {
|
|
210
|
-
readonly _tag: "
|
|
230
|
+
readonly _tag: "Ended";
|
|
211
231
|
} | {
|
|
212
232
|
readonly _tag: "Failed";
|
|
213
233
|
readonly message: string;
|
|
214
234
|
} | {
|
|
215
|
-
readonly _tag: "
|
|
235
|
+
readonly _tag: "Live";
|
|
236
|
+
} | {
|
|
237
|
+
readonly _tag: "Started";
|
|
238
|
+
} | {
|
|
239
|
+
readonly _tag: "Stopped";
|
|
216
240
|
}, never, never, never, void, {
|
|
217
241
|
stream: ManagedResource.Entry<{
|
|
218
|
-
readonly status: "denied" | "idle" | "
|
|
242
|
+
readonly status: "denied" | "idle" | "live" | "requesting";
|
|
219
243
|
readonly lastError: string | null;
|
|
220
244
|
}, {
|
|
221
|
-
readonly _tag: "Started";
|
|
222
|
-
} | {
|
|
223
|
-
readonly _tag: "Stopped";
|
|
224
|
-
} | {
|
|
225
245
|
readonly _tag: "Denied";
|
|
226
246
|
} | {
|
|
227
|
-
readonly _tag: "
|
|
247
|
+
readonly _tag: "Ended";
|
|
228
248
|
} | {
|
|
229
249
|
readonly _tag: "Failed";
|
|
230
250
|
readonly message: string;
|
|
231
251
|
} | {
|
|
232
|
-
readonly _tag: "
|
|
252
|
+
readonly _tag: "Live";
|
|
253
|
+
} | {
|
|
254
|
+
readonly _tag: "Started";
|
|
255
|
+
} | {
|
|
256
|
+
readonly _tag: "Stopped";
|
|
233
257
|
}, Option.Option<{
|
|
234
258
|
readonly audio: boolean;
|
|
235
259
|
readonly video: boolean;
|
|
@@ -248,15 +272,15 @@ export declare const PermissionsModel: Schema.Struct<{
|
|
|
248
272
|
export type PermissionsModel = typeof PermissionsModel.Type;
|
|
249
273
|
export declare const PermissionsMessage: import("foldkit/message").MessageUnion<{
|
|
250
274
|
readonly Snapshot: {
|
|
251
|
-
|
|
275
|
+
states: Schema.$Record<Schema.String, Schema.Literals<readonly ["granted", "denied", "prompt"]>>;
|
|
252
276
|
};
|
|
253
277
|
readonly Changed: {
|
|
254
|
-
|
|
255
|
-
|
|
278
|
+
name: Schema.String;
|
|
279
|
+
state: Schema.Literals<readonly ["granted", "denied", "prompt"]>;
|
|
256
280
|
};
|
|
257
281
|
readonly Cleared: {};
|
|
258
282
|
readonly Failed: {
|
|
259
|
-
|
|
283
|
+
message: Schema.String;
|
|
260
284
|
};
|
|
261
285
|
}>;
|
|
262
286
|
export type PermissionsMessage = typeof PermissionsMessage.Type;
|
|
@@ -280,6 +304,14 @@ interface Acquired {
|
|
|
280
304
|
export declare const Watch: ManagedResource.ManagedResource<Acquired, ManagedResource.ManagedResourceService<"permissions">>;
|
|
281
305
|
/** The watch service a placed Permissions bundle requires. */
|
|
282
306
|
export type WatchService = ManagedResource.ServiceOf<typeof Watch>;
|
|
307
|
+
/**
|
|
308
|
+
* Permission states as a bundle factory: queried on placement, kept current
|
|
309
|
+
* by each status object's `onchange`. A resource holds the status objects
|
|
310
|
+
* (they cannot live in the Model); its queue feeds the subscription, and
|
|
311
|
+
* release detaches every handler. An unknown permission name fails the
|
|
312
|
+
* acquire; an unknown state string fails it too — both become `Failed`,
|
|
313
|
+
* never Model facts.
|
|
314
|
+
*/
|
|
283
315
|
export declare const permissions: <const Name extends string>(config: {
|
|
284
316
|
readonly name: Name;
|
|
285
317
|
/** Read lazily so tests can substitute a double, like the SSE bundle. */
|
|
@@ -292,11 +324,11 @@ export declare const permissions: <const Name extends string>(config: {
|
|
|
292
324
|
};
|
|
293
325
|
readonly lastError: string | null;
|
|
294
326
|
}, {
|
|
295
|
-
readonly _tag: "Cleared";
|
|
296
|
-
} | {
|
|
297
327
|
readonly _tag: "Changed";
|
|
298
328
|
readonly name: string;
|
|
299
329
|
readonly state: "denied" | "granted" | "prompt";
|
|
330
|
+
} | {
|
|
331
|
+
readonly _tag: "Cleared";
|
|
300
332
|
} | {
|
|
301
333
|
readonly _tag: "Failed";
|
|
302
334
|
readonly message: string;
|
|
@@ -309,4 +341,5 @@ export declare const permissions: <const Name extends string>(config: {
|
|
|
309
341
|
watch: ManagedResource.Entry<PermissionsModel, PermissionsMessage, Option.Option<ReadonlyArray<string>>, Acquired, WatchService, (acquired: Acquired) => PermissionsMessage>;
|
|
310
342
|
}>, {}>;
|
|
311
343
|
//#endregion
|
|
344
|
+
export {};
|
|
312
345
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/device/fullscreen.ts","../../src/device/geolocation.ts","../../src/device/media-devices.ts","../../src/device/media-stream.ts","../../src/device/permissions.ts"],"mappings":";;;;;qBAWa,6CAAiB
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/device/fullscreen.ts","../../src/device/geolocation.ts","../../src/device/media-devices.ts","../../src/device/media-stream.ts","../../src/device/permissions.ts"],"mappings":";;;;;qBAWa,6CAAiB;;IACjB,QAAM,OAAA;;;;;IAGP,SAAO,OAAA;;;YAEP,2BAA2B,kBAAkB;;;;;;;qBAW5C,kBAAe,SAAa,YAAU,QAAQ;;qBA0B9C,sBAAqB,QAAQ;;;;;qBAgC7B,yBAAwB,OAAO,OAAO;;;qBC/EtC,aAAW,OAAA;;;;;YAKZ,qBAAqB,YAAY;qBAEhC,kBAAgB,OAAA;;;;;;;;;YAKjB,0BAA0B,iBAAiB;qBAE1C,8CAAkB;;IAE3B,UAAQ,OAAA;IACR,WAAS,OAAA;IACT,UAAQ,OAAA;;;;IAGA,SAAO,OAAA;;;YAEP,4BAA4B,mBAAmB;;;;;;;qBAyD9C,aAAW,OAAA;;;;;;;;;;;;;;;;;;;;;qBChFX,aAAW,OAAA;;;;;;YAMZ,qBAAqB,YAAY;qBAEhC,mBAAiB,OAAA;;;;;;;;;;Y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C,oBAAqB,qBAAmB;WAC1C,MAAM;;WAEN,WAAW,WAAW,cAAc;MAC9C,OAAA,OAAA;WAYqB,OAAA;;;;;;;;;;;;;;;;;;;;;EA5Cb,OAAA,gBAAgB,MACrB,kBACA,oBACA,OAAO,OAAO,wBACd,UACA,eACC,UAAU,aAAa"}
|
package/dist/device/index.mjs
CHANGED
|
@@ -70,12 +70,6 @@ const fullscreenChanges = () => {
|
|
|
70
70
|
};
|
|
71
71
|
//#endregion
|
|
72
72
|
//#region src/device/geolocation.ts
|
|
73
|
-
/**
|
|
74
|
-
* Geolocation as a bundle: the device position in the Model, watched while
|
|
75
|
-
* placed. Permission denial is its own status (actionable UI); transient
|
|
76
|
-
* failures keep the last fix and note the error. No geolocation API yields
|
|
77
|
-
* an empty stream instead of throwing.
|
|
78
|
-
*/
|
|
79
73
|
const Coordinates = Schema.Struct({
|
|
80
74
|
latitude: Schema.Number,
|
|
81
75
|
longitude: Schema.Number,
|
|
@@ -119,6 +113,12 @@ const watchStream = () => {
|
|
|
119
113
|
return Stream.fromQueue(queue);
|
|
120
114
|
}));
|
|
121
115
|
};
|
|
116
|
+
/**
|
|
117
|
+
* Geolocation as a bundle: the device position in the Model, watched while
|
|
118
|
+
* placed. Permission denial is its own status (actionable UI); transient
|
|
119
|
+
* failures keep the last fix and note the error. No geolocation API yields
|
|
120
|
+
* an empty stream instead of throwing.
|
|
121
|
+
*/
|
|
122
122
|
const Geolocation = Bundle.make("Geolocation", {
|
|
123
123
|
Model: GeolocationModel,
|
|
124
124
|
Message: GeolocationMessage,
|
|
@@ -146,18 +146,10 @@ const Geolocation = Bundle.make("Geolocation", {
|
|
|
146
146
|
lastError: message
|
|
147
147
|
}) })
|
|
148
148
|
}),
|
|
149
|
-
subscriptions: () => Subscription.make()(() => ({ watch: Subscription.
|
|
149
|
+
subscriptions: () => Subscription.make()(() => ({ watch: Subscription.persistentEntry(watchStream()) }))
|
|
150
150
|
});
|
|
151
151
|
//#endregion
|
|
152
152
|
//#region src/device/media-devices.ts
|
|
153
|
-
/**
|
|
154
|
-
* Media devices as a bundle factory: the enumerated device list in the
|
|
155
|
-
* Model, scanned on placement and re-scanned on every `devicechange`.
|
|
156
|
-
* Denial lands as `denied` while keeping the last list (actionable UI over
|
|
157
|
-
* stale data, like Geolocation's last fix); any other failure keeps the
|
|
158
|
-
* list and notes the error. No media-devices API yields an empty stream
|
|
159
|
-
* and a `Failed` scan instead of throwing.
|
|
160
|
-
*/
|
|
161
153
|
const MediaDevice = Schema.Struct({
|
|
162
154
|
deviceId: Schema.String,
|
|
163
155
|
groupId: Schema.String,
|
|
@@ -187,6 +179,14 @@ const MediaDevicesMessage = defineMessageUnion({
|
|
|
187
179
|
const sameDevices = (a, b) => a.length === b.length && a.every((device, index) => device.deviceId === b[index].deviceId && device.groupId === b[index].groupId && device.kind === b[index].kind && device.label === b[index].label);
|
|
188
180
|
const failMessage$2 = (error) => error instanceof Error ? error.message : String(error);
|
|
189
181
|
const isDenied$1 = (error) => typeof error?.name === "string" && ["NotAllowedError", "SecurityError"].includes(error.name);
|
|
182
|
+
/**
|
|
183
|
+
* Media devices as a bundle factory: the enumerated device list in the
|
|
184
|
+
* Model, scanned on placement and re-scanned on every `devicechange`.
|
|
185
|
+
* Denial lands as `denied` while keeping the last list (actionable UI over
|
|
186
|
+
* stale data, like Geolocation's last fix); any other failure keeps the
|
|
187
|
+
* list and notes the error. No media-devices API yields an empty stream
|
|
188
|
+
* and a `Failed` scan instead of throwing.
|
|
189
|
+
*/
|
|
190
190
|
const mediaDevices = (config) => {
|
|
191
191
|
const handle = () => {
|
|
192
192
|
if (typeof navigator === "undefined") return null;
|
|
@@ -255,20 +255,11 @@ const mediaDevices = (config) => {
|
|
|
255
255
|
lastError: message
|
|
256
256
|
}) })
|
|
257
257
|
}),
|
|
258
|
-
subscriptions: () => Subscription.make()(() => ({ changes: Subscription.
|
|
258
|
+
subscriptions: () => Subscription.make()(() => ({ changes: Subscription.persistentEntry(changedStream()) }))
|
|
259
259
|
});
|
|
260
260
|
};
|
|
261
261
|
//#endregion
|
|
262
262
|
//#region src/device/media-stream.ts
|
|
263
|
-
/**
|
|
264
|
-
* A camera/mic stream as a bundle factory: one live MediaStream held in a
|
|
265
|
-
* Managed Resource while the Model asks for it. `Started` requests,
|
|
266
|
-
* `Stopped` releases; denial parks at `denied` (actionable UI), any other
|
|
267
|
-
* acquire failure parks at `idle` with the error noted — both clear
|
|
268
|
-
* requirements, so a failing device never spins an acquire loop. Release
|
|
269
|
-
* stops every track. No media-devices API fails the acquire instead of
|
|
270
|
-
* throwing.
|
|
271
|
-
*/
|
|
272
263
|
const MediaStreamModel = Schema.Struct({
|
|
273
264
|
status: Schema.Literals([
|
|
274
265
|
"idle",
|
|
@@ -290,6 +281,15 @@ const MediaStreamMessage = defineMessageUnion({
|
|
|
290
281
|
const LiveStream = ManagedResource.tag()("media-stream");
|
|
291
282
|
const failMessage$1 = (error) => error instanceof Error ? error.message : String(error);
|
|
292
283
|
const isDenied = (error) => typeof error?.name === "string" && ["NotAllowedError", "SecurityError"].includes(error.name);
|
|
284
|
+
/**
|
|
285
|
+
* A camera/mic stream as a bundle factory: one live MediaStream held in a
|
|
286
|
+
* Managed Resource while the Model asks for it. `Started` requests,
|
|
287
|
+
* `Stopped` releases; denial parks at `denied` (actionable UI), any other
|
|
288
|
+
* acquire failure parks at `idle` with the error noted — both clear
|
|
289
|
+
* requirements, so a failing device never spins an acquire loop. Release
|
|
290
|
+
* stops every track. No media-devices API fails the acquire instead of
|
|
291
|
+
* throwing.
|
|
292
|
+
*/
|
|
293
293
|
const mediaStream = (config) => {
|
|
294
294
|
const request = (constraints) => {
|
|
295
295
|
if (config.request !== void 0) return config.request(constraints);
|
|
@@ -359,14 +359,6 @@ const mediaStream = (config) => {
|
|
|
359
359
|
};
|
|
360
360
|
//#endregion
|
|
361
361
|
//#region src/device/permissions.ts
|
|
362
|
-
/**
|
|
363
|
-
* Permission states as a bundle factory: queried on placement, kept current
|
|
364
|
-
* by each status object's `onchange`. A resource holds the status objects
|
|
365
|
-
* (they cannot live in the Model); its queue feeds the subscription, and
|
|
366
|
-
* release detaches every handler. An unknown permission name fails the
|
|
367
|
-
* acquire; an unknown state string fails it too — both become `Failed`,
|
|
368
|
-
* never Model facts.
|
|
369
|
-
*/
|
|
370
362
|
const PermissionState = Schema.Literals([
|
|
371
363
|
"granted",
|
|
372
364
|
"denied",
|
|
@@ -392,6 +384,14 @@ const readState = (state, name) => {
|
|
|
392
384
|
if (state !== "granted" && state !== "denied" && state !== "prompt") throw new Error(`unknown permission state for ${name}: ${state}`);
|
|
393
385
|
return state;
|
|
394
386
|
};
|
|
387
|
+
/**
|
|
388
|
+
* Permission states as a bundle factory: queried on placement, kept current
|
|
389
|
+
* by each status object's `onchange`. A resource holds the status objects
|
|
390
|
+
* (they cannot live in the Model); its queue feeds the subscription, and
|
|
391
|
+
* release detaches every handler. An unknown permission name fails the
|
|
392
|
+
* acquire; an unknown state string fails it too — both become `Failed`,
|
|
393
|
+
* never Model facts.
|
|
394
|
+
*/
|
|
395
395
|
const permissions = (config) => {
|
|
396
396
|
const handle = () => {
|
|
397
397
|
if (typeof navigator === "undefined") return null;
|
|
@@ -486,7 +486,7 @@ const permissions = (config) => {
|
|
|
486
486
|
}), Queue.shutdown(events)))
|
|
487
487
|
}) }));
|
|
488
488
|
},
|
|
489
|
-
subscriptions: () => Subscription.make()(() => ({ changes: Subscription.
|
|
489
|
+
subscriptions: () => Subscription.make()(() => ({ changes: Subscription.persistentEntry(Stream.unwrap(Effect.matchEffect(Watch.get, {
|
|
490
490
|
onFailure: () => Effect.succeed(Stream.empty),
|
|
491
491
|
onSuccess: ({ events }) => Effect.succeed(Stream.fromQueue(events))
|
|
492
492
|
}))) }))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["failMessage","failMessage","isDenied","failMessage"],"sources":["../../src/device/fullscreen.ts","../../src/device/geolocation.ts","../../src/device/media-devices.ts","../../src/device/media-stream.ts","../../src/device/permissions.ts"],"sourcesContent":["/**\n * Fullscreen as Commands plus an entry — not a bundle, because the document\n * owns the state: `document.fullscreenElement` is the fact, and the entry\n * reports it as `Changed`. Commands yield `Entered`/`Exited` on success and\n * `Failed` otherwise (rejected request, missing API), so `update` handles\n * both outcomes as Messages.\n */\nimport { Effect, Schema, Stream } from 'effect'\nimport type { Command } from 'foldkit/command'\nimport { defineMessageUnion } from 'foldkit/message'\n\nexport const FullscreenMessage = defineMessageUnion({\n Changed: { active: Schema.Boolean },\n Entered: {},\n Exited: {},\n Failed: { message: Schema.String },\n})\nexport type FullscreenMessage = typeof FullscreenMessage.Type\n\nconst failMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error)\n\n/**\n * Requests fullscreen for an element. The capability is feature-checked on\n * the element itself (SVG and HTML elements both qualify), falling back to\n * the legacy `webkit` prefix; a platform with neither yields `Failed`\n * instead of throwing.\n */\nexport const enterFullscreen = (element: Element): Command<FullscreenMessage, never, never> => ({\n name: 'Fullscreen.enter',\n args: {},\n effect: Effect.matchEffect(\n Effect.tryPromise({\n try: () => {\n const requestable = element as unknown as {\n readonly requestFullscreen?: unknown\n readonly webkitRequestFullscreen?: unknown\n }\n const request = requestable.requestFullscreen ?? requestable.webkitRequestFullscreen\n if (typeof request !== 'function') {\n throw new Error('fullscreen is unavailable')\n }\n return (request as () => Promise<void>).call(element)\n },\n catch: (error: unknown) => error,\n }),\n {\n onFailure: error => Effect.succeed(FullscreenMessage.Failed({ message: failMessage(error) })),\n onSuccess: () => Effect.succeed(FullscreenMessage.Entered()),\n },\n ),\n})\n\n/** Leaves fullscreen, with the same legacy fallback. Without a document API it yields `Failed`, not a throw. */\nexport const exitFullscreen = (): Command<FullscreenMessage, never, never> => ({\n name: 'Fullscreen.exit',\n args: {},\n effect: Effect.matchEffect(\n Effect.tryPromise({\n try: () => {\n if (typeof document === 'undefined') {\n throw new Error('fullscreen is unavailable')\n }\n const api = document as unknown as {\n readonly exitFullscreen?: unknown\n readonly webkitExitFullscreen?: unknown\n }\n const exit = api.exitFullscreen ?? api.webkitExitFullscreen\n if (typeof exit !== 'function') {\n throw new Error('fullscreen is unavailable')\n }\n return (exit as () => Promise<void>).call(document)\n },\n catch: (error: unknown) => error,\n }),\n {\n onFailure: error => Effect.succeed(FullscreenMessage.Failed({ message: failMessage(error) })),\n onSuccess: () => Effect.succeed(FullscreenMessage.Exited()),\n },\n ),\n})\n\n/**\n * `Changed` whenever fullscreen state flips, starting with the current\n * answer. Without a document the stream is empty instead of throwing.\n */\nexport const fullscreenChanges = (): Stream.Stream<FullscreenMessage> => {\n if (typeof document === 'undefined' || typeof document.addEventListener !== 'function') {\n return Stream.empty\n }\n // Incomplete DOMs leave fullscreenElement undefined instead of null.\n const isActive = (): boolean =>\n document.fullscreenElement !== null && document.fullscreenElement !== undefined\n return Stream.concat(\n Stream.make(FullscreenMessage.Changed({ active: isActive() })),\n Stream.fromEventListener(document, 'fullscreenchange').pipe(\n Stream.map(() => FullscreenMessage.Changed({ active: isActive() })),\n ),\n )\n}\n","/**\n * Geolocation as a bundle: the device position in the Model, watched while\n * placed. Permission denial is its own status (actionable UI); transient\n * failures keep the last fix and note the error. No geolocation API yields\n * an empty stream instead of throwing.\n */\nimport { Effect, Queue, Schema, Stream } from 'effect'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as Subscription from 'foldkit/subscription'\nimport type * as Update from 'foldkit/update'\nimport { Bundle } from 'foldkit-bundle'\nimport { unlessSame } from '../internal.js'\n\nexport const Coordinates = Schema.Struct({\n latitude: Schema.Number,\n longitude: Schema.Number,\n accuracy: Schema.Number,\n})\nexport type Coordinates = typeof Coordinates.Type\n\nexport const GeolocationModel = Schema.Struct({\n status: Schema.Literals(['unknown', 'ready', 'denied']),\n coords: Schema.NullOr(Coordinates),\n lastError: Schema.NullOr(Schema.String),\n})\nexport type GeolocationModel = typeof GeolocationModel.Type\n\nexport const GeolocationMessage = defineMessageUnion({\n Located: {\n latitude: Schema.Number,\n longitude: Schema.Number,\n accuracy: Schema.Number,\n },\n Denied: {},\n Failed: { message: Schema.String },\n})\nexport type GeolocationMessage = typeof GeolocationMessage.Type\n\ntype PositionCallback = (position: {\n readonly coords: {\n readonly latitude: number\n readonly longitude: number\n readonly accuracy: number\n }\n}) => void\ntype ErrorCallback = (error: { readonly code: number; readonly message: string }) => void\n\nconst watchStream = (): Stream.Stream<GeolocationMessage> => {\n if (\n typeof navigator === 'undefined' ||\n typeof navigator.geolocation?.watchPosition !== 'function'\n ) {\n return Stream.empty\n }\n const geolocation = navigator.geolocation\n return Stream.unwrap(\n Effect.gen(function* () {\n const queue = yield* Queue.unbounded<GeolocationMessage>()\n const onLocated: PositionCallback = position => {\n Effect.runFork(\n Queue.offer(\n queue,\n GeolocationMessage.Located({\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n }),\n ),\n )\n }\n const onError: ErrorCallback = error => {\n Effect.runFork(\n Queue.offer(\n queue,\n error.code === 1\n ? GeolocationMessage.Denied()\n : GeolocationMessage.Failed({ message: error.message }),\n ),\n )\n }\n const watchId = geolocation.watchPosition(onLocated, onError)\n yield* Effect.addFinalizer(() => Effect.sync(() => geolocation.clearWatch(watchId)))\n return Stream.fromQueue(queue)\n }),\n )\n}\n\nexport const Geolocation = Bundle.make<\n 'Geolocation',\n GeolocationModel,\n GeolocationMessage,\n void,\n never,\n never,\n never,\n void,\n {},\n {}\n>('Geolocation', {\n Model: GeolocationModel,\n Message: GeolocationMessage,\n init: () => ({ model: { status: 'unknown', coords: null, lastError: null } }),\n update: (model, message) =>\n GeolocationMessage.match<\n Update.ReturnWithOutMessage<GeolocationModel, GeolocationMessage, never>\n >(message, {\n // A watch repeats a fix that has not moved.\n Located: ({ latitude, longitude, accuracy }) =>\n model.status === 'ready' &&\n model.coords !== null &&\n model.coords.latitude === latitude &&\n model.coords.longitude === longitude &&\n model.coords.accuracy === accuracy\n ? { model }\n : {\n model: {\n ...model,\n status: 'ready' as const,\n coords: { latitude, longitude, accuracy },\n },\n },\n Denied: () => ({ model: unlessSame(model, { ...model, status: 'denied' }) }),\n Failed: ({ message }) => ({ model: unlessSame(model, { ...model, lastError: message }) }),\n }),\n subscriptions: (): Subscription.Subscriptions<GeolocationModel, GeolocationMessage> =>\n Subscription.make<GeolocationModel, GeolocationMessage>()(() => ({\n watch: Subscription.persistent(watchStream()),\n })),\n})\n","/**\n * Media devices as a bundle factory: the enumerated device list in the\n * Model, scanned on placement and re-scanned on every `devicechange`.\n * Denial lands as `denied` while keeping the last list (actionable UI over\n * stale data, like Geolocation's last fix); any other failure keeps the\n * list and notes the error. No media-devices API yields an empty stream\n * and a `Failed` scan instead of throwing.\n */\nimport { Effect, Schema, Stream } from 'effect'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as Subscription from 'foldkit/subscription'\nimport type * as Update from 'foldkit/update'\nimport { Bundle } from 'foldkit-bundle'\nimport { unlessSame } from '../internal.js'\n\nexport const MediaDevice = Schema.Struct({\n deviceId: Schema.String,\n groupId: Schema.String,\n kind: Schema.Literals(['audioinput', 'audiooutput', 'videoinput']),\n label: Schema.String,\n})\nexport type MediaDevice = typeof MediaDevice.Type\n\nexport const MediaDevicesModel = Schema.Struct({\n status: Schema.Literals(['unknown', 'ready', 'denied']),\n devices: Schema.Array(MediaDevice),\n lastError: Schema.NullOr(Schema.String),\n})\nexport type MediaDevicesModel = typeof MediaDevicesModel.Type\n\nexport const MediaDevicesMessage = defineMessageUnion({\n Scan: {},\n DevicesChanged: {},\n Refreshed: { devices: Schema.Array(MediaDevice) },\n Denied: {},\n Failed: { message: Schema.String },\n})\nexport type MediaDevicesMessage = typeof MediaDevicesMessage.Type\n\nconst sameDevices = (a: ReadonlyArray<MediaDevice>, b: ReadonlyArray<MediaDevice>): boolean =>\n a.length === b.length &&\n a.every(\n (device, index) =>\n device.deviceId === b[index]!.deviceId &&\n device.groupId === b[index]!.groupId &&\n device.kind === b[index]!.kind &&\n device.label === b[index]!.label,\n )\n\n/** The slice of MediaDevices the bundle needs; satisfied by the platform object. */\nexport interface MediaDevicesHandle {\n enumerateDevices(): Promise<\n ReadonlyArray<{\n readonly deviceId: string\n readonly groupId: string\n readonly kind: string\n readonly label: string\n }>\n >\n addEventListener(type: string, listener: () => void): void\n removeEventListener(type: string, listener: () => void): void\n}\n\nconst failMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error)\n\nconst isDenied = (error: unknown): boolean =>\n typeof (error as { readonly name?: unknown } | null)?.name === 'string' &&\n ['NotAllowedError', 'SecurityError'].includes((error as { readonly name: string }).name)\n\nexport const mediaDevices = <const Name extends string>(config: {\n readonly name: Name\n /** Read lazily so tests can substitute a double, like the SSE bundle. */\n readonly create?: ((navigator: Navigator) => MediaDevicesHandle | null) | undefined\n}) => {\n const handle = (): MediaDevicesHandle | null => {\n if (typeof navigator === 'undefined') return null\n if (config.create !== undefined) return config.create(navigator)\n const devices = navigator.mediaDevices as unknown as MediaDevicesHandle | undefined\n return devices ?? null\n }\n\n const scanEffect = Effect.matchEffect(\n Effect.tryPromise({\n try: async () => {\n const devices = handle()\n if (devices === null) throw new Error('media devices are unavailable')\n const listed = await devices.enumerateDevices()\n // The platform constrains kind to three values; anything else is a\n // boundary violation, so it fails the scan instead of entering the Model.\n return listed.map(item => {\n if (\n item.kind !== 'audioinput' &&\n item.kind !== 'audiooutput' &&\n item.kind !== 'videoinput'\n ) {\n throw new Error(`unknown device kind: ${item.kind}`)\n }\n // Guarded by the check above: only the three platform kinds reach here.\n return {\n deviceId: item.deviceId,\n groupId: item.groupId,\n kind: item.kind as MediaDevice['kind'],\n label: item.label,\n }\n })\n },\n catch: (error: unknown) => error,\n }),\n {\n onFailure: error =>\n Effect.succeed(\n isDenied(error)\n ? MediaDevicesMessage.Denied()\n : MediaDevicesMessage.Failed({ message: failMessage(error) }),\n ),\n onSuccess: devices =>\n Effect.succeed(MediaDevicesMessage.Refreshed({ devices: [...devices] })),\n },\n )\n\n const scan = () => ({ name: `${config.name}.scan`, effect: scanEffect })\n\n const changedStream = (): Stream.Stream<MediaDevicesMessage> => {\n const devices = handle()\n if (devices === null) return Stream.empty\n // The handle carries only the slice the bundle needs, not the full\n // EventTarget surface, so the listener attaches through a cast.\n return Stream.fromEventListener(devices as unknown as EventTarget, 'devicechange').pipe(\n Stream.map(() => MediaDevicesMessage.DevicesChanged()),\n )\n }\n\n return Bundle.make<Name, MediaDevicesModel, MediaDevicesMessage>(config.name, {\n Model: MediaDevicesModel,\n Message: MediaDevicesMessage,\n init: () => ({\n model: { status: 'unknown', devices: [], lastError: null },\n commands: [scan()],\n }),\n update: (model, message) =>\n MediaDevicesMessage.match<\n Update.ReturnWithOutMessage<MediaDevicesModel, MediaDevicesMessage, never>\n >(message, {\n Scan: () => ({ model, commands: [scan()] }),\n DevicesChanged: () => ({ model, commands: [scan()] }),\n // One plug-in fires several `devicechange`s, and each rescan finds the same list.\n Refreshed: ({ devices }) =>\n model.status === 'ready' && sameDevices(model.devices, devices)\n ? { model }\n : { model: { ...model, status: 'ready' as const, devices } },\n Denied: () => ({ model: unlessSame(model, { ...model, status: 'denied' }) }),\n Failed: ({ message }) => ({ model: unlessSame(model, { ...model, lastError: message }) }),\n }),\n subscriptions: (): Subscription.Subscriptions<MediaDevicesModel, MediaDevicesMessage> =>\n Subscription.make<MediaDevicesModel, MediaDevicesMessage>()(() => ({\n changes: Subscription.persistent(changedStream()),\n })),\n })\n}\n","/**\n * A camera/mic stream as a bundle factory: one live MediaStream held in a\n * Managed Resource while the Model asks for it. `Started` requests,\n * `Stopped` releases; denial parks at `denied` (actionable UI), any other\n * acquire failure parks at `idle` with the error noted — both clear\n * requirements, so a failing device never spins an acquire loop. Release\n * stops every track. No media-devices API fails the acquire instead of\n * throwing.\n */\nimport { Effect, Option, Schema } from 'effect'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as ManagedResource from 'foldkit/managedResource'\nimport type * as Update from 'foldkit/update'\nimport { Bundle } from 'foldkit-bundle'\nimport { unlessSame } from '../internal.js'\n\nexport const MediaStreamModel = Schema.Struct({\n status: Schema.Literals(['idle', 'requesting', 'live', 'denied']),\n lastError: Schema.NullOr(Schema.String),\n})\nexport type MediaStreamModel = typeof MediaStreamModel.Type\n\nexport const MediaStreamMessage = defineMessageUnion({\n Started: {},\n Stopped: {},\n Live: {},\n Ended: {},\n Denied: {},\n Failed: { message: Schema.String },\n})\nexport type MediaStreamMessage = typeof MediaStreamMessage.Type\n\n/** A single media track: stopped on release. */\nexport interface MediaTrackHandle {\n stop(): void\n}\n\n/** The live stream: its tracks stop on release. */\nexport interface MediaStreamHandle {\n getTracks(): ReadonlyArray<MediaTrackHandle>\n}\n\nexport interface MediaStreamConstraints {\n readonly audio: boolean\n readonly video: boolean\n}\n\n/** The live stream, for commands that attach it to an element. One assembly holds one. */\nexport const LiveStream = ManagedResource.tag<MediaStreamHandle>()('media-stream')\n\n/** The stream service a placed camera requires. */\nexport type LiveStreamService = ManagedResource.ServiceOf<typeof LiveStream>\n\ntype StreamResources = Readonly<{\n stream: ManagedResource.Entry<\n MediaStreamModel,\n MediaStreamMessage,\n Option.Option<MediaStreamConstraints>,\n MediaStreamHandle,\n LiveStreamService,\n () => MediaStreamMessage\n >\n}>\n\nconst failMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error)\n\nconst isDenied = (error: unknown): boolean =>\n typeof (error as { readonly name?: unknown } | null)?.name === 'string' &&\n ['NotAllowedError', 'SecurityError'].includes((error as { readonly name: string }).name)\n\nexport const mediaStream = <const Name extends string>(config: {\n readonly name: Name\n /** Read lazily so tests can substitute a double, like the SSE bundle. */\n readonly request?:\n ((constraints: MediaStreamConstraints) => Promise<MediaStreamHandle>) | undefined\n}) => {\n const request = (constraints: MediaStreamConstraints): Promise<MediaStreamHandle> => {\n if (config.request !== undefined) return config.request(constraints)\n if (\n typeof navigator === 'undefined' ||\n typeof navigator.mediaDevices?.getUserMedia !== 'function'\n ) {\n return Promise.reject(new Error('media devices are unavailable'))\n }\n return navigator.mediaDevices.getUserMedia(constraints)\n }\n\n return Bundle.make(config.name, {\n Model: MediaStreamModel,\n Message: MediaStreamMessage,\n args: Schema.Struct({ audio: Schema.Boolean, video: Schema.Boolean }),\n init: () => ({ model: { status: 'idle' as const, lastError: null } }),\n update: (model, message) =>\n MediaStreamMessage.match<\n Update.ReturnWithOutMessage<MediaStreamModel, MediaStreamMessage, never>\n >(message, {\n // Starting a live stream would wait at `requesting` for an acquire\n // that never comes: the requirements are the same.\n Started: () =>\n model.status === 'requesting' || model.status === 'live'\n ? { model }\n : { model: { ...model, status: 'requesting' as const } },\n Stopped: () => ({ model: unlessSame(model, { ...model, status: 'idle' }) }),\n Live: () => ({ model: unlessSame(model, { ...model, status: 'live', lastError: null }) }),\n // Stopping releases the stream, whose release reports it ended.\n Ended: () => ({ model: unlessSame(model, { ...model, status: 'idle' }) }),\n Denied: () => ({ model: unlessSame(model, { ...model, status: 'denied' }) }),\n Failed: ({ message }) => ({\n model: unlessSame(model, { ...model, status: 'idle', lastError: message }),\n }),\n }),\n resources: args =>\n ManagedResource.make<MediaStreamModel, MediaStreamMessage>()(entry => ({\n stream: entry(\n Schema.Option(Schema.Struct({ audio: Schema.Boolean, video: Schema.Boolean })),\n {\n resource: LiveStream,\n modelToMaybeRequirements: model =>\n model.status === 'requesting' || model.status === 'live'\n ? Option.some({ audio: args.audio, video: args.video })\n : Option.none(),\n acquire: (constraints: MediaStreamConstraints) =>\n Effect.tryPromise({\n try: () => request(constraints),\n catch: (error: unknown) => error,\n }),\n onAcquired: () => MediaStreamMessage.Live(),\n onReleased: () => MediaStreamMessage.Ended(),\n onAcquireError: error =>\n isDenied(error)\n ? MediaStreamMessage.Denied()\n : MediaStreamMessage.Failed({ message: failMessage(error) }),\n release: stream =>\n Effect.sync(() => {\n for (const track of stream.getTracks()) track.stop()\n }),\n },\n ),\n })),\n })\n}\n","/**\n * Permission states as a bundle factory: queried on placement, kept current\n * by each status object's `onchange`. A resource holds the status objects\n * (they cannot live in the Model); its queue feeds the subscription, and\n * release detaches every handler. An unknown permission name fails the\n * acquire; an unknown state string fails it too — both become `Failed`,\n * never Model facts.\n */\nimport { Effect, Option, Queue, Schema, Stream } from 'effect'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as ManagedResource from 'foldkit/managedResource'\nimport * as Subscription from 'foldkit/subscription'\nimport type * as Update from 'foldkit/update'\nimport { Bundle } from 'foldkit-bundle'\nimport { unlessSame } from '../internal.js'\n\nexport const PermissionState = Schema.Literals(['granted', 'denied', 'prompt'])\nexport type PermissionState = typeof PermissionState.Type\n\nexport const PermissionsModel = Schema.Struct({\n states: Schema.Record(Schema.String, PermissionState),\n lastError: Schema.NullOr(Schema.String),\n})\nexport type PermissionsModel = typeof PermissionsModel.Type\n\nexport const PermissionsMessage = defineMessageUnion({\n Snapshot: { states: Schema.Record(Schema.String, PermissionState) },\n Changed: { name: Schema.String, state: PermissionState },\n Cleared: {},\n Failed: { message: Schema.String },\n})\nexport type PermissionsMessage = typeof PermissionsMessage.Type\n\n/** A queried permission status; `onchange` fires while watched. */\nexport interface PermissionStatusHandle {\n readonly state: string\n onchange: (() => void) | null\n}\n\n/** The slice of the Permissions API the bundle needs. */\nexport interface PermissionsHandle {\n query(descriptor: { readonly name: string }): Promise<PermissionStatusHandle>\n}\n\ninterface Acquired {\n readonly statuses: ReadonlyMap<string, PermissionStatusHandle>\n readonly snapshot: Readonly<Record<string, PermissionState>>\n readonly events: Queue.Queue<PermissionsMessage>\n}\n\n/** The watched statuses, for the changes subscription. One assembly holds one. */\nexport const Watch = ManagedResource.tag<Acquired>()('permissions')\n\n/** The watch service a placed Permissions bundle requires. */\nexport type WatchService = ManagedResource.ServiceOf<typeof Watch>\n\ntype WatchResources = Readonly<{\n watch: ManagedResource.Entry<\n PermissionsModel,\n PermissionsMessage,\n Option.Option<ReadonlyArray<string>>,\n Acquired,\n WatchService,\n (acquired: Acquired) => PermissionsMessage\n >\n}>\n\nconst failMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error)\n\nconst readState = (state: string, name: string): PermissionState => {\n if (state !== 'granted' && state !== 'denied' && state !== 'prompt') {\n throw new Error(`unknown permission state for ${name}: ${state}`)\n }\n return state\n}\n\nexport const permissions = <const Name extends string>(config: {\n readonly name: Name\n /** Read lazily so tests can substitute a double, like the SSE bundle. */\n readonly create?: ((navigator: Navigator) => PermissionsHandle | null) | undefined\n}) => {\n const handle = (): PermissionsHandle | null => {\n if (typeof navigator === 'undefined') return null\n if (config.create !== undefined) return config.create(navigator)\n const api = navigator.permissions as unknown as PermissionsHandle | undefined\n return api ?? null\n }\n\n return Bundle.make<\n Name,\n PermissionsModel,\n PermissionsMessage,\n { readonly names: ReadonlyArray<string> },\n never,\n never,\n WatchService,\n void,\n WatchResources,\n {}\n >(config.name, {\n Model: PermissionsModel,\n Message: PermissionsMessage,\n args: Schema.Struct({ names: Schema.Array(Schema.String) }),\n init: () => ({ model: { states: {}, lastError: null } }),\n update: (model, message) =>\n PermissionsMessage.match<\n Update.ReturnWithOutMessage<PermissionsModel, PermissionsMessage, never>\n >(message, {\n Snapshot: ({ states }) => {\n const next = unlessSame(model.states, { ...states })\n return next === model.states ? { model } : { model: { ...model, states: next } }\n },\n Changed: ({ name, state }) =>\n Object.hasOwn(model.states, name) && model.states[name] === state\n ? { model }\n : { model: { ...model, states: { ...model.states, [name]: state } } },\n Cleared: () =>\n Object.keys(model.states).length === 0 ? { model } : { model: { ...model, states: {} } },\n Failed: ({ message }) => ({ model: unlessSame(model, { ...model, lastError: message }) }),\n }),\n resources: args => {\n const names = Option.some([...new Set(args.names)])\n return ManagedResource.make<PermissionsModel, PermissionsMessage>()(entry => ({\n watch: entry(Schema.Option(Schema.Array(Schema.String)), {\n resource: Watch,\n modelToMaybeRequirements: () => names,\n acquire: (names: ReadonlyArray<string>) =>\n Effect.gen(function* () {\n const api = handle()\n if (api === null) throw new Error('permissions are unavailable')\n const events = yield* Queue.unbounded<PermissionsMessage>()\n const statuses = new Map<string, PermissionStatusHandle>()\n // Offers run in arrival order; see the WebSocket bundle.\n let tail: Promise<void> = Promise.resolve()\n const offer = (message: PermissionsMessage) => {\n const run = () =>\n Effect.runPromise(Queue.offer(events, message)).then(\n () => undefined,\n () => undefined,\n )\n tail = tail.then(run, run)\n }\n // Two phases: query and validate everything first, so a later\n // name failing cannot abandon handlers attached to earlier ones.\n const queried: Array<readonly [string, PermissionStatusHandle, PermissionState]> = []\n for (const name of names) {\n const status = yield* Effect.tryPromise({\n try: () => api.query({ name }),\n catch: (error: unknown) => error,\n })\n queried.push([name, status, readState(status.state, name)] as const)\n }\n const snapshot: Record<string, PermissionState> = {}\n for (const [name, status, state] of queried) {\n status.onchange = () => {\n try {\n offer(\n PermissionsMessage.Changed({ name, state: readState(status.state, name) }),\n )\n } catch {\n // readState evaluates before offer runs, so a state the\n // schema rejects lands here instead of crashing the handler.\n offer(\n PermissionsMessage.Failed({\n message: `unknown permission state for ${name}`,\n }),\n )\n }\n }\n statuses.set(name, status)\n snapshot[name] = state\n }\n return { statuses, snapshot, events }\n }),\n // The snapshot is captured during acquire, so onAcquired cannot\n // throw re-reading a state that changed mid-acquire.\n onAcquired: ({ snapshot }) => PermissionsMessage.Snapshot({ states: { ...snapshot } }),\n onReleased: () => PermissionsMessage.Cleared(),\n onAcquireError: error => PermissionsMessage.Failed({ message: failMessage(error) }),\n release: ({ statuses, events }) =>\n Effect.asVoid(\n Effect.andThen(\n Effect.sync(() => {\n for (const status of statuses.values()) status.onchange = null\n }),\n Queue.shutdown(events),\n ),\n ),\n }),\n }))\n },\n subscriptions: (): Subscription.Subscriptions<\n PermissionsModel,\n PermissionsMessage,\n WatchService\n > =>\n Subscription.make<PermissionsModel, PermissionsMessage, WatchService>()(() => ({\n // No model gate: the queue outlives every state change, and release\n // ends the stream through teardown, not through dependencies.\n changes: Subscription.persistent(\n Stream.unwrap(\n Effect.matchEffect(Watch.get, {\n // Released between placement and attach: end quietly.\n onFailure: () => Effect.succeed(Stream.empty),\n onSuccess: ({ events }) => Effect.succeed(Stream.fromQue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AAQ,UAAU,OAAO,OAAO,IAAI;MAAC,CAAU;KACrE;KACA,MAAM,WAA4C,CAAC;KACnD,KAAK,MAAM,CAAC,MAAM,QAAQ,UAAU,SAAS;MAC3C,OAAO,iBAAiB;OACtB,IAAI;QACF,MACE,mBAAmB,QAAQ;SAAE;SAAM,OAAO,UAAU,OAAO,OAAO,IAAI;QAAE,CAAC,CAC3E;OACF,QAAQ;QAGN,MACE,mBAAmB,OAAO,EACxB,SAAS,gCAAgC,OAC3C,CAAC,CACH;OACF;MACF;MACA,SAAS,IAAI,MAAM,MAAM;MACzB,SAAS,QAAQ;KACnB;KACA,OAAO;MAAE;MAAU;MAAU;KAAO;IACtC,CAAC;IAGH,aAAa,EAAE,eAAe,mBAAmB,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,CAAC;IACrF,kBAAkB,mBAAmB,QAAQ;IAC7C,iBAAgB,UAAS,mBAAmB,OAAO,EAAE,SAAS,YAAY,KAAK,EAAE,CAAC;IAClF,UAAU,EAAE,UAAU,aACpB,OAAO,OACL,OAAO,QACL,OAAO,WAAW;KAChB,KAAK,MAAM,UAAU,SAAS,OAAO,GAAG,OAAO,WAAW;IAC5D,CAAC,GACD,MAAM,SAAS,MAAM,CACvB,CACF;GACJ,CAAC,EACH,EAAE;EACJ;EACA,qBAKE,aAAa,KAAyD,CAAC,QAAQ,EAG7E,SAAS,aAAa,WACpB,OAAO,OACL,OAAO,YAAY,MAAM,KAAK;GAE5B,iBAAiB,OAAO,QAAQ,OAAO,KAAK;GAC5C,YAAY,EAAE,aAAa,OAAO,QAAQ,OAAO,UAAU,MAAM,CAAC;EACpE,CAAC,CACH,CACF,EACF,EAAE;CACN,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["failMessage","failMessage","isDenied","failMessage"],"sources":["../../src/device/fullscreen.ts","../../src/device/geolocation.ts","../../src/device/media-devices.ts","../../src/device/media-stream.ts","../../src/device/permissions.ts"],"sourcesContent":["/**\n * Fullscreen as Commands plus an entry — not a bundle, because the document\n * owns the state: `document.fullscreenElement` is the fact, and the entry\n * reports it as `Changed`. Commands yield `Entered`/`Exited` on success and\n * `Failed` otherwise (rejected request, missing API), so `update` handles\n * both outcomes as Messages.\n */\nimport { Effect, Schema, Stream } from 'effect'\nimport type { Command } from 'foldkit/command'\nimport { defineMessageUnion } from 'foldkit/message'\n\nexport const FullscreenMessage = defineMessageUnion({\n Changed: { active: Schema.Boolean },\n Entered: {},\n Exited: {},\n Failed: { message: Schema.String },\n})\nexport type FullscreenMessage = typeof FullscreenMessage.Type\n\nconst failMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error)\n\n/**\n * Requests fullscreen for an element. The capability is feature-checked on\n * the element itself (SVG and HTML elements both qualify), falling back to\n * the legacy `webkit` prefix; a platform with neither yields `Failed`\n * instead of throwing.\n */\nexport const enterFullscreen = (element: Element): Command<FullscreenMessage, never, never> => ({\n name: 'Fullscreen.enter',\n args: {},\n effect: Effect.matchEffect(\n Effect.tryPromise({\n try: () => {\n const requestable = element as unknown as {\n readonly requestFullscreen?: unknown\n readonly webkitRequestFullscreen?: unknown\n }\n const request = requestable.requestFullscreen ?? requestable.webkitRequestFullscreen\n if (typeof request !== 'function') {\n throw new Error('fullscreen is unavailable')\n }\n return (request as () => Promise<void>).call(element)\n },\n catch: (error: unknown) => error,\n }),\n {\n onFailure: error => Effect.succeed(FullscreenMessage.Failed({ message: failMessage(error) })),\n onSuccess: () => Effect.succeed(FullscreenMessage.Entered()),\n },\n ),\n})\n\n/** Leaves fullscreen, with the same legacy fallback. Without a document API it yields `Failed`, not a throw. */\nexport const exitFullscreen = (): Command<FullscreenMessage, never, never> => ({\n name: 'Fullscreen.exit',\n args: {},\n effect: Effect.matchEffect(\n Effect.tryPromise({\n try: () => {\n if (typeof document === 'undefined') {\n throw new Error('fullscreen is unavailable')\n }\n const api = document as unknown as {\n readonly exitFullscreen?: unknown\n readonly webkitExitFullscreen?: unknown\n }\n const exit = api.exitFullscreen ?? api.webkitExitFullscreen\n if (typeof exit !== 'function') {\n throw new Error('fullscreen is unavailable')\n }\n return (exit as () => Promise<void>).call(document)\n },\n catch: (error: unknown) => error,\n }),\n {\n onFailure: error => Effect.succeed(FullscreenMessage.Failed({ message: failMessage(error) })),\n onSuccess: () => Effect.succeed(FullscreenMessage.Exited()),\n },\n ),\n})\n\n/**\n * `Changed` whenever fullscreen state flips, starting with the current\n * answer. Without a document the stream is empty instead of throwing.\n */\nexport const fullscreenChanges = (): Stream.Stream<FullscreenMessage> => {\n if (typeof document === 'undefined' || typeof document.addEventListener !== 'function') {\n return Stream.empty\n }\n // Incomplete DOMs leave fullscreenElement undefined instead of null.\n const isActive = (): boolean =>\n document.fullscreenElement !== null && document.fullscreenElement !== undefined\n return Stream.concat(\n Stream.make(FullscreenMessage.Changed({ active: isActive() })),\n Stream.fromEventListener(document, 'fullscreenchange').pipe(\n Stream.map(() => FullscreenMessage.Changed({ active: isActive() })),\n ),\n )\n}\n","import { Effect, Queue, Schema, Stream } from 'effect'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as Subscription from 'foldkit/subscription'\nimport type * as Update from 'foldkit/update'\nimport { Bundle } from 'foldkit-bundle'\nimport { unlessSame } from '../internal.js'\n\nexport const Coordinates = Schema.Struct({\n latitude: Schema.Number,\n longitude: Schema.Number,\n accuracy: Schema.Number,\n})\nexport type Coordinates = typeof Coordinates.Type\n\nexport const GeolocationModel = Schema.Struct({\n status: Schema.Literals(['unknown', 'ready', 'denied']),\n coords: Schema.NullOr(Coordinates),\n lastError: Schema.NullOr(Schema.String),\n})\nexport type GeolocationModel = typeof GeolocationModel.Type\n\nexport const GeolocationMessage = defineMessageUnion({\n Located: {\n latitude: Schema.Number,\n longitude: Schema.Number,\n accuracy: Schema.Number,\n },\n Denied: {},\n Failed: { message: Schema.String },\n})\nexport type GeolocationMessage = typeof GeolocationMessage.Type\n\ntype PositionCallback = (position: {\n readonly coords: {\n readonly latitude: number\n readonly longitude: number\n readonly accuracy: number\n }\n}) => void\ntype ErrorCallback = (error: { readonly code: number; readonly message: string }) => void\n\nconst watchStream = (): Stream.Stream<GeolocationMessage> => {\n if (\n typeof navigator === 'undefined' ||\n typeof navigator.geolocation?.watchPosition !== 'function'\n ) {\n return Stream.empty\n }\n const geolocation = navigator.geolocation\n return Stream.unwrap(\n Effect.gen(function* () {\n const queue = yield* Queue.unbounded<GeolocationMessage>()\n const onLocated: PositionCallback = position => {\n Effect.runFork(\n Queue.offer(\n queue,\n GeolocationMessage.Located({\n latitude: position.coords.latitude,\n longitude: position.coords.longitude,\n accuracy: position.coords.accuracy,\n }),\n ),\n )\n }\n const onError: ErrorCallback = error => {\n Effect.runFork(\n Queue.offer(\n queue,\n error.code === 1\n ? GeolocationMessage.Denied()\n : GeolocationMessage.Failed({ message: error.message }),\n ),\n )\n }\n const watchId = geolocation.watchPosition(onLocated, onError)\n yield* Effect.addFinalizer(() => Effect.sync(() => geolocation.clearWatch(watchId)))\n return Stream.fromQueue(queue)\n }),\n )\n}\n\n/**\n * Geolocation as a bundle: the device position in the Model, watched while\n * placed. Permission denial is its own status (actionable UI); transient\n * failures keep the last fix and note the error. No geolocation API yields\n * an empty stream instead of throwing.\n */\nexport const Geolocation = Bundle.make<\n 'Geolocation',\n GeolocationModel,\n GeolocationMessage,\n void,\n never,\n never,\n never,\n void,\n {},\n {}\n>('Geolocation', {\n Model: GeolocationModel,\n Message: GeolocationMessage,\n init: () => ({ model: { status: 'unknown', coords: null, lastError: null } }),\n update: (model, message) =>\n GeolocationMessage.match<\n Update.ReturnWithOutMessage<GeolocationModel, GeolocationMessage, never>\n >(message, {\n // A watch repeats a fix that has not moved.\n Located: ({ latitude, longitude, accuracy }) =>\n model.status === 'ready' &&\n model.coords !== null &&\n model.coords.latitude === latitude &&\n model.coords.longitude === longitude &&\n model.coords.accuracy === accuracy\n ? { model }\n : {\n model: {\n ...model,\n status: 'ready' as const,\n coords: { latitude, longitude, accuracy },\n },\n },\n Denied: () => ({ model: unlessSame(model, { ...model, status: 'denied' }) }),\n Failed: ({ message }) => ({ model: unlessSame(model, { ...model, lastError: message }) }),\n }),\n subscriptions: (): Subscription.Subscriptions<GeolocationModel, GeolocationMessage> =>\n Subscription.make<GeolocationModel, GeolocationMessage>()(() => ({\n watch: Subscription.persistentEntry(watchStream()),\n })),\n})\n","import { Effect, Schema, Stream } from 'effect'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as Subscription from 'foldkit/subscription'\nimport type * as Update from 'foldkit/update'\nimport { Bundle } from 'foldkit-bundle'\nimport { unlessSame } from '../internal.js'\n\nexport const MediaDevice = Schema.Struct({\n deviceId: Schema.String,\n groupId: Schema.String,\n kind: Schema.Literals(['audioinput', 'audiooutput', 'videoinput']),\n label: Schema.String,\n})\nexport type MediaDevice = typeof MediaDevice.Type\n\nexport const MediaDevicesModel = Schema.Struct({\n status: Schema.Literals(['unknown', 'ready', 'denied']),\n devices: Schema.Array(MediaDevice),\n lastError: Schema.NullOr(Schema.String),\n})\nexport type MediaDevicesModel = typeof MediaDevicesModel.Type\n\nexport const MediaDevicesMessage = defineMessageUnion({\n Scan: {},\n DevicesChanged: {},\n Refreshed: { devices: Schema.Array(MediaDevice) },\n Denied: {},\n Failed: { message: Schema.String },\n})\nexport type MediaDevicesMessage = typeof MediaDevicesMessage.Type\n\nconst sameDevices = (a: ReadonlyArray<MediaDevice>, b: ReadonlyArray<MediaDevice>): boolean =>\n a.length === b.length &&\n a.every(\n (device, index) =>\n device.deviceId === b[index]!.deviceId &&\n device.groupId === b[index]!.groupId &&\n device.kind === b[index]!.kind &&\n device.label === b[index]!.label,\n )\n\n/** The slice of MediaDevices the bundle needs; satisfied by the platform object. */\nexport interface MediaDevicesHandle {\n enumerateDevices(): Promise<\n ReadonlyArray<{\n readonly deviceId: string\n readonly groupId: string\n readonly kind: string\n readonly label: string\n }>\n >\n addEventListener(type: string, listener: () => void): void\n removeEventListener(type: string, listener: () => void): void\n}\n\nconst failMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error)\n\nconst isDenied = (error: unknown): boolean =>\n typeof (error as { readonly name?: unknown } | null)?.name === 'string' &&\n ['NotAllowedError', 'SecurityError'].includes((error as { readonly name: string }).name)\n\n/**\n * Media devices as a bundle factory: the enumerated device list in the\n * Model, scanned on placement and re-scanned on every `devicechange`.\n * Denial lands as `denied` while keeping the last list (actionable UI over\n * stale data, like Geolocation's last fix); any other failure keeps the\n * list and notes the error. No media-devices API yields an empty stream\n * and a `Failed` scan instead of throwing.\n */\nexport const mediaDevices = <const Name extends string>(config: {\n readonly name: Name\n /** Read lazily so tests can substitute a double, like the SSE bundle. */\n readonly create?: ((navigator: Navigator) => MediaDevicesHandle | null) | undefined\n}) => {\n const handle = (): MediaDevicesHandle | null => {\n if (typeof navigator === 'undefined') return null\n if (config.create !== undefined) return config.create(navigator)\n const devices = navigator.mediaDevices as unknown as MediaDevicesHandle | undefined\n return devices ?? null\n }\n\n const scanEffect = Effect.matchEffect(\n Effect.tryPromise({\n try: async () => {\n const devices = handle()\n if (devices === null) throw new Error('media devices are unavailable')\n const listed = await devices.enumerateDevices()\n // The platform constrains kind to three values; anything else is a\n // boundary violation, so it fails the scan instead of entering the Model.\n return listed.map(item => {\n if (\n item.kind !== 'audioinput' &&\n item.kind !== 'audiooutput' &&\n item.kind !== 'videoinput'\n ) {\n throw new Error(`unknown device kind: ${item.kind}`)\n }\n // Guarded by the check above: only the three platform kinds reach here.\n return {\n deviceId: item.deviceId,\n groupId: item.groupId,\n kind: item.kind as MediaDevice['kind'],\n label: item.label,\n }\n })\n },\n catch: (error: unknown) => error,\n }),\n {\n onFailure: error =>\n Effect.succeed(\n isDenied(error)\n ? MediaDevicesMessage.Denied()\n : MediaDevicesMessage.Failed({ message: failMessage(error) }),\n ),\n onSuccess: devices =>\n Effect.succeed(MediaDevicesMessage.Refreshed({ devices: [...devices] })),\n },\n )\n\n const scan = () => ({ name: `${config.name}.scan`, effect: scanEffect })\n\n const changedStream = (): Stream.Stream<MediaDevicesMessage> => {\n const devices = handle()\n if (devices === null) return Stream.empty\n // The handle carries only the slice the bundle needs, not the full\n // EventTarget surface, so the listener attaches through a cast.\n return Stream.fromEventListener(devices as unknown as EventTarget, 'devicechange').pipe(\n Stream.map(() => MediaDevicesMessage.DevicesChanged()),\n )\n }\n\n return Bundle.make<Name, MediaDevicesModel, MediaDevicesMessage>(config.name, {\n Model: MediaDevicesModel,\n Message: MediaDevicesMessage,\n init: () => ({\n model: { status: 'unknown', devices: [], lastError: null },\n commands: [scan()],\n }),\n update: (model, message) =>\n MediaDevicesMessage.match<\n Update.ReturnWithOutMessage<MediaDevicesModel, MediaDevicesMessage, never>\n >(message, {\n Scan: () => ({ model, commands: [scan()] }),\n DevicesChanged: () => ({ model, commands: [scan()] }),\n // One plug-in fires several `devicechange`s, and each rescan finds the same list.\n Refreshed: ({ devices }) =>\n model.status === 'ready' && sameDevices(model.devices, devices)\n ? { model }\n : { model: { ...model, status: 'ready' as const, devices } },\n Denied: () => ({ model: unlessSame(model, { ...model, status: 'denied' }) }),\n Failed: ({ message }) => ({ model: unlessSame(model, { ...model, lastError: message }) }),\n }),\n subscriptions: (): Subscription.Subscriptions<MediaDevicesModel, MediaDevicesMessage> =>\n Subscription.make<MediaDevicesModel, MediaDevicesMessage>()(() => ({\n changes: Subscription.persistentEntry(changedStream()),\n })),\n })\n}\n","import { Effect, Option, Schema } from 'effect'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as ManagedResource from 'foldkit/managedResource'\nimport type * as Update from 'foldkit/update'\nimport { Bundle } from 'foldkit-bundle'\nimport { unlessSame } from '../internal.js'\n\nexport const MediaStreamModel = Schema.Struct({\n status: Schema.Literals(['idle', 'requesting', 'live', 'denied']),\n lastError: Schema.NullOr(Schema.String),\n})\nexport type MediaStreamModel = typeof MediaStreamModel.Type\n\nexport const MediaStreamMessage = defineMessageUnion({\n Started: {},\n Stopped: {},\n Live: {},\n Ended: {},\n Denied: {},\n Failed: { message: Schema.String },\n})\nexport type MediaStreamMessage = typeof MediaStreamMessage.Type\n\n/** A single media track: stopped on release. */\nexport interface MediaTrackHandle {\n stop(): void\n}\n\n/** The live stream: its tracks stop on release. */\nexport interface MediaStreamHandle {\n getTracks(): ReadonlyArray<MediaTrackHandle>\n}\n\n/** Which tracks `mediaStream` asks `getUserMedia` for. */\nexport interface MediaStreamConstraints {\n readonly audio: boolean\n readonly video: boolean\n}\n\n/** The live stream, for commands that attach it to an element. One assembly holds one. */\nexport const LiveStream = ManagedResource.tag<MediaStreamHandle>()('media-stream')\n\n/** The stream service a placed camera requires. */\nexport type LiveStreamService = ManagedResource.ServiceOf<typeof LiveStream>\n\ntype StreamResources = Readonly<{\n stream: ManagedResource.Entry<\n MediaStreamModel,\n MediaStreamMessage,\n Option.Option<MediaStreamConstraints>,\n MediaStreamHandle,\n LiveStreamService,\n () => MediaStreamMessage\n >\n}>\n\nconst failMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error)\n\nconst isDenied = (error: unknown): boolean =>\n typeof (error as { readonly name?: unknown } | null)?.name === 'string' &&\n ['NotAllowedError', 'SecurityError'].includes((error as { readonly name: string }).name)\n\n/**\n * A camera/mic stream as a bundle factory: one live MediaStream held in a\n * Managed Resource while the Model asks for it. `Started` requests,\n * `Stopped` releases; denial parks at `denied` (actionable UI), any other\n * acquire failure parks at `idle` with the error noted — both clear\n * requirements, so a failing device never spins an acquire loop. Release\n * stops every track. No media-devices API fails the acquire instead of\n * throwing.\n */\nexport const mediaStream = <const Name extends string>(config: {\n readonly name: Name\n /** Read lazily so tests can substitute a double, like the SSE bundle. */\n readonly request?:\n ((constraints: MediaStreamConstraints) => Promise<MediaStreamHandle>) | undefined\n}) => {\n const request = (constraints: MediaStreamConstraints): Promise<MediaStreamHandle> => {\n if (config.request !== undefined) return config.request(constraints)\n if (\n typeof navigator === 'undefined' ||\n typeof navigator.mediaDevices?.getUserMedia !== 'function'\n ) {\n return Promise.reject(new Error('media devices are unavailable'))\n }\n return navigator.mediaDevices.getUserMedia(constraints)\n }\n\n return Bundle.make(config.name, {\n Model: MediaStreamModel,\n Message: MediaStreamMessage,\n args: Schema.Struct({ audio: Schema.Boolean, video: Schema.Boolean }),\n init: () => ({ model: { status: 'idle' as const, lastError: null } }),\n update: (model, message) =>\n MediaStreamMessage.match<\n Update.ReturnWithOutMessage<MediaStreamModel, MediaStreamMessage, never>\n >(message, {\n // Starting a live stream would wait at `requesting` for an acquire\n // that never comes: the requirements are the same.\n Started: () =>\n model.status === 'requesting' || model.status === 'live'\n ? { model }\n : { model: { ...model, status: 'requesting' as const } },\n Stopped: () => ({ model: unlessSame(model, { ...model, status: 'idle' }) }),\n Live: () => ({ model: unlessSame(model, { ...model, status: 'live', lastError: null }) }),\n // Stopping releases the stream, whose release reports it ended.\n Ended: () => ({ model: unlessSame(model, { ...model, status: 'idle' }) }),\n Denied: () => ({ model: unlessSame(model, { ...model, status: 'denied' }) }),\n Failed: ({ message }) => ({\n model: unlessSame(model, { ...model, status: 'idle', lastError: message }),\n }),\n }),\n resources: args =>\n ManagedResource.make<MediaStreamModel, MediaStreamMessage>()(entry => ({\n stream: entry(\n Schema.Option(Schema.Struct({ audio: Schema.Boolean, video: Schema.Boolean })),\n {\n resource: LiveStream,\n modelToMaybeRequirements: model =>\n model.status === 'requesting' || model.status === 'live'\n ? Option.some({ audio: args.audio, video: args.video })\n : Option.none(),\n acquire: (constraints: MediaStreamConstraints) =>\n Effect.tryPromise({\n try: () => request(constraints),\n catch: (error: unknown) => error,\n }),\n onAcquired: () => MediaStreamMessage.Live(),\n onReleased: () => MediaStreamMessage.Ended(),\n onAcquireError: error =>\n isDenied(error)\n ? MediaStreamMessage.Denied()\n : MediaStreamMessage.Failed({ message: failMessage(error) }),\n release: stream =>\n Effect.sync(() => {\n for (const track of stream.getTracks()) track.stop()\n }),\n },\n ),\n })),\n })\n}\n","import { Effect, Option, Queue, Schema, Stream } from 'effect'\nimport { defineMessageUnion } from 'foldkit/message'\nimport * as ManagedResource from 'foldkit/managedResource'\nimport * as Subscription from 'foldkit/subscription'\nimport type * as Update from 'foldkit/update'\nimport { Bundle } from 'foldkit-bundle'\nimport { unlessSame } from '../internal.js'\n\nexport const PermissionState = Schema.Literals(['granted', 'denied', 'prompt'])\nexport type PermissionState = typeof PermissionState.Type\n\nexport const PermissionsModel = Schema.Struct({\n states: Schema.Record(Schema.String, PermissionState),\n lastError: Schema.NullOr(Schema.String),\n})\nexport type PermissionsModel = typeof PermissionsModel.Type\n\nexport const PermissionsMessage = defineMessageUnion({\n Snapshot: { states: Schema.Record(Schema.String, PermissionState) },\n Changed: { name: Schema.String, state: PermissionState },\n Cleared: {},\n Failed: { message: Schema.String },\n})\nexport type PermissionsMessage = typeof PermissionsMessage.Type\n\n/** A queried permission status; `onchange` fires while watched. */\nexport interface PermissionStatusHandle {\n readonly state: string\n onchange: (() => void) | null\n}\n\n/** The slice of the Permissions API the bundle needs. */\nexport interface PermissionsHandle {\n query(descriptor: { readonly name: string }): Promise<PermissionStatusHandle>\n}\n\ninterface Acquired {\n readonly statuses: ReadonlyMap<string, PermissionStatusHandle>\n readonly snapshot: Readonly<Record<string, PermissionState>>\n readonly events: Queue.Queue<PermissionsMessage>\n}\n\n/** The watched statuses, for the changes subscription. One assembly holds one. */\nexport const Watch = ManagedResource.tag<Acquired>()('permissions')\n\n/** The watch service a placed Permissions bundle requires. */\nexport type WatchService = ManagedResource.ServiceOf<typeof Watch>\n\ntype WatchResources = Readonly<{\n watch: ManagedResource.Entry<\n PermissionsModel,\n PermissionsMessage,\n Option.Option<ReadonlyArray<string>>,\n Acquired,\n WatchService,\n (acquired: Acquired) => PermissionsMessage\n >\n}>\n\nconst failMessage = (error: unknown): string =>\n error instanceof Error ? error.message : String(error)\n\nconst readState = (state: string, name: string): PermissionState => {\n if (state !== 'granted' && state !== 'denied' && state !== 'prompt') {\n throw new Error(`unknown permission state for ${name}: ${state}`)\n }\n return state\n}\n\n/**\n * Permission states as a bundle factory: queried on placement, kept current\n * by each status object's `onchange`. A resource holds the status objects\n * (they cannot live in the Model); its queue feeds the subscription, and\n * release detaches every handler. An unknown permission name fails the\n * acquire; an unknown state string fails it too — both become `Failed`,\n * never Model facts.\n */\nexport const permissions = <const Name extends string>(config: {\n readonly name: Name\n /** Read lazily so tests can substitute a double, like the SSE bundle. */\n readonly create?: ((navigator: Navigator) => PermissionsHandle | null) | undefined\n}) => {\n const handle = (): PermissionsHandle | null => {\n if (typeof navigator === 'undefined') return null\n if (config.create !== undefined) return config.create(navigator)\n const api = navigator.permissions as unknown as PermissionsHandle | undefined\n return api ?? null\n }\n\n return Bundle.make<\n Name,\n PermissionsModel,\n PermissionsMessage,\n { readonly names: ReadonlyArray<string> },\n never,\n never,\n WatchService,\n void,\n WatchResources,\n {}\n >(config.name, {\n Model: PermissionsModel,\n Message: PermissionsMessage,\n args: Schema.Struct({ names: Schema.Array(Schema.String) }),\n init: () => ({ model: { states: {}, lastError: null } }),\n update: (model, message) =>\n PermissionsMessage.match<\n Update.ReturnWithOutMessage<PermissionsModel, PermissionsMessage, never>\n >(message, {\n Snapshot: ({ states }) => {\n const next = unlessSame(model.states, { ...states })\n return next === model.states ? { model } : { model: { ...model, states: next } }\n },\n Changed: ({ name, state }) =>\n Object.hasOwn(model.states, name) && model.states[name] === state\n ? { model }\n : { model: { ...model, states: { ...model.states, [name]: state } } },\n Cleared: () =>\n Object.keys(model.states).length === 0 ? { model } : { model: { ...model, states: {} } },\n Failed: ({ message }) => ({ model: unlessSame(model, { ...model, lastError: message }) }),\n }),\n resources: args => {\n const names = Option.some([...new Set(args.names)])\n return ManagedResource.make<PermissionsModel, PermissionsMessage>()(entry => ({\n watch: entry(Schema.Option(Schema.Array(Schema.String)), {\n resource: Watch,\n modelToMaybeRequirements: () => names,\n acquire: (names: ReadonlyArray<string>) =>\n Effect.gen(function* () {\n const api = handle()\n if (api === null) throw new Error('permissions are unavailable')\n const events = yield* Queue.unbounded<PermissionsMessage>()\n const statuses = new Map<string, PermissionStatusHandle>()\n // Offers run in arrival order; see the WebSocket bundle.\n let tail: Promise<void> = Promise.resolve()\n const offer = (message: PermissionsMessage) => {\n const run = () =>\n Effect.runPromise(Queue.offer(events, message)).then(\n () => undefined,\n () => undefined,\n )\n tail = tail.then(run, run)\n }\n // Two phases: query and validate everything first, so a later\n // name failing cannot abandon handlers attached to earlier ones.\n const queried: Array<readonly [string, PermissionStatusHandle, PermissionState]> = []\n for (const name of names) {\n const status = yield* Effect.tryPromise({\n try: () => api.query({ name }),\n catch: (error: unknown) => error,\n })\n queried.push([name, status, readState(status.state, name)] as const)\n }\n const snapshot: Record<string, PermissionState> = {}\n for (const [name, status, state] of queried) {\n status.onchange = () => {\n try {\n offer(\n PermissionsMessage.Changed({ name, state: readState(status.state, name) }),\n )\n } catch {\n // readState evaluates before offer runs, so a state the\n // schema rejects lands here instead of crashing the handler.\n offer(\n PermissionsMessage.Failed({\n message: `unknown permission state for ${name}`,\n }),\n )\n }\n }\n statuses.set(name, status)\n snapshot[name] = state\n }\n return { statuses, snapshot, events }\n }),\n // The snapshot is captured during acquire, so onAcquired cannot\n // throw re-reading a state that changed mid-acquire.\n onAcquired: ({ snapshot }) => PermissionsMessage.Snapshot({ states: { ...snapshot } }),\n onReleased: () => PermissionsMessage.Cleared(),\n onAcquireError: error => PermissionsMessage.Failed({ message: failMessage(error) }),\n release: ({ statuses, events }) =>\n Effect.asVoid(\n Effect.andThen(\n Effect.sync(() => {\n for (const status of statuses.values()) status.onchange = null\n }),\n Queue.shutdown(events),\n ),\n ),\n }),\n }))\n },\n subscriptions: (): Subscription.Subscriptions<\n PermissionsModel,\n PermissionsMessage,\n WatchService\n > =>\n Subscription.make<PermissionsModel, PermissionsMessage, WatchService>()(() => ({\n // No model gate: the queue outlives every state change, and release\n // ends the stream through teardown, not through dependencies.\n changes: Subscription.persistentEntry(\n Stream.unwrap(\n Effect.matchEffect(Watch.get, {\n // Released between placement and attach: end quietly.\n onFailure: () => Effect.succeed(Stream.empty),\n onSuccess: ({ events }) => Effect.succeed(Stream.f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