foldkit-primitives 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +454 -0
- package/dist/device/index.d.mts +312 -0
- package/dist/device/index.d.mts.map +1 -0
- package/dist/device/index.mjs +490 -0
- package/dist/device/index.mjs.map +1 -0
- package/dist/dom/index.d.mts +73 -0
- package/dist/dom/index.d.mts.map +1 -0
- package/dist/dom/index.mjs +218 -0
- package/dist/dom/index.mjs.map +1 -0
- package/dist/events/index.d.mts +154 -0
- package/dist/events/index.d.mts.map +1 -0
- package/dist/events/index.mjs +287 -0
- package/dist/events/index.mjs.map +1 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.mjs +10 -0
- package/dist/media/index.d.mts +79 -0
- package/dist/media/index.d.mts.map +1 -0
- package/dist/media/index.mjs +127 -0
- package/dist/media/index.mjs.map +1 -0
- package/dist/motion/index.d.mts +112 -0
- package/dist/motion/index.d.mts.map +1 -0
- package/dist/motion/index.mjs +208 -0
- package/dist/motion/index.mjs.map +1 -0
- package/dist/net/index.d.mts +199 -0
- package/dist/net/index.d.mts.map +1 -0
- package/dist/net/index.mjs +329 -0
- package/dist/net/index.mjs.map +1 -0
- package/dist/observers/index.d.mts +59 -0
- package/dist/observers/index.d.mts.map +1 -0
- package/dist/observers/index.mjs +156 -0
- package/dist/observers/index.mjs.map +1 -0
- package/dist/state/index.d.mts +342 -0
- package/dist/state/index.d.mts.map +1 -0
- package/dist/state/index.mjs +504 -0
- package/dist/state/index.mjs.map +1 -0
- package/dist/time/index.d.mts +129 -0
- package/dist/time/index.d.mts.map +1 -0
- package/dist/time/index.mjs +213 -0
- package/dist/time/index.mjs.map +1 -0
- package/package.json +96 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import { Effect, Option, Queue, Schema, Stream } from "effect";
|
|
2
|
+
import { defineMessageUnion } from "foldkit/message";
|
|
3
|
+
import * as Subscription from "foldkit/subscription";
|
|
4
|
+
import { Bundle } from "foldkit-bundle";
|
|
5
|
+
import * as ManagedResource from "foldkit/managedResource";
|
|
6
|
+
//#region src/device/fullscreen.ts
|
|
7
|
+
/**
|
|
8
|
+
* Fullscreen as Commands plus an entry — not a bundle, because the document
|
|
9
|
+
* owns the state: `document.fullscreenElement` is the fact, and the entry
|
|
10
|
+
* reports it as `Changed`. Commands yield `Entered`/`Exited` on success and
|
|
11
|
+
* `Failed` otherwise (rejected request, missing API), so `update` handles
|
|
12
|
+
* both outcomes as Messages.
|
|
13
|
+
*/
|
|
14
|
+
const FullscreenMessage = defineMessageUnion({
|
|
15
|
+
Changed: { active: Schema.Boolean },
|
|
16
|
+
Entered: {},
|
|
17
|
+
Exited: {},
|
|
18
|
+
Failed: { message: Schema.String }
|
|
19
|
+
});
|
|
20
|
+
const failMessage$3 = (error) => error instanceof Error ? error.message : String(error);
|
|
21
|
+
/**
|
|
22
|
+
* Requests fullscreen for an element. The capability is feature-checked on
|
|
23
|
+
* the element itself (SVG and HTML elements both qualify), falling back to
|
|
24
|
+
* the legacy `webkit` prefix; a platform with neither yields `Failed`
|
|
25
|
+
* instead of throwing.
|
|
26
|
+
*/
|
|
27
|
+
const enterFullscreen = (element) => ({
|
|
28
|
+
name: "Fullscreen.enter",
|
|
29
|
+
args: {},
|
|
30
|
+
effect: Effect.matchEffect(Effect.tryPromise({
|
|
31
|
+
try: () => {
|
|
32
|
+
const requestable = element;
|
|
33
|
+
const request = requestable.requestFullscreen ?? requestable.webkitRequestFullscreen;
|
|
34
|
+
if (typeof request !== "function") throw new Error("fullscreen is unavailable");
|
|
35
|
+
return request.call(element);
|
|
36
|
+
},
|
|
37
|
+
catch: (error) => error
|
|
38
|
+
}), {
|
|
39
|
+
onFailure: (error) => Effect.succeed(FullscreenMessage.Failed({ message: failMessage$3(error) })),
|
|
40
|
+
onSuccess: () => Effect.succeed(FullscreenMessage.Entered())
|
|
41
|
+
})
|
|
42
|
+
});
|
|
43
|
+
/** Leaves fullscreen, with the same legacy fallback. Without a document API it yields `Failed`, not a throw. */
|
|
44
|
+
const exitFullscreen = () => ({
|
|
45
|
+
name: "Fullscreen.exit",
|
|
46
|
+
args: {},
|
|
47
|
+
effect: Effect.matchEffect(Effect.tryPromise({
|
|
48
|
+
try: () => {
|
|
49
|
+
if (typeof document === "undefined") throw new Error("fullscreen is unavailable");
|
|
50
|
+
const api = document;
|
|
51
|
+
const exit = api.exitFullscreen ?? api.webkitExitFullscreen;
|
|
52
|
+
if (typeof exit !== "function") throw new Error("fullscreen is unavailable");
|
|
53
|
+
return exit.call(document);
|
|
54
|
+
},
|
|
55
|
+
catch: (error) => error
|
|
56
|
+
}), {
|
|
57
|
+
onFailure: (error) => Effect.succeed(FullscreenMessage.Failed({ message: failMessage$3(error) })),
|
|
58
|
+
onSuccess: () => Effect.succeed(FullscreenMessage.Exited())
|
|
59
|
+
})
|
|
60
|
+
});
|
|
61
|
+
/**
|
|
62
|
+
* `Changed` whenever fullscreen state flips, starting with the current
|
|
63
|
+
* answer. Without a document the stream is empty instead of throwing.
|
|
64
|
+
*/
|
|
65
|
+
const fullscreenChanges = () => {
|
|
66
|
+
if (typeof document === "undefined" || typeof document.addEventListener !== "function") return Stream.empty;
|
|
67
|
+
const isActive = () => document.fullscreenElement !== null && document.fullscreenElement !== void 0;
|
|
68
|
+
return Stream.concat(Stream.make(FullscreenMessage.Changed({ active: isActive() })), Stream.fromEventListener(document, "fullscreenchange").pipe(Stream.map(() => FullscreenMessage.Changed({ active: isActive() }))));
|
|
69
|
+
};
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/device/geolocation.ts
|
|
72
|
+
/**
|
|
73
|
+
* Geolocation as a bundle: the device position in the Model, watched while
|
|
74
|
+
* placed. Permission denial is its own status (actionable UI); transient
|
|
75
|
+
* failures keep the last fix and note the error. No geolocation API yields
|
|
76
|
+
* an empty stream instead of throwing.
|
|
77
|
+
*/
|
|
78
|
+
const Coordinates = Schema.Struct({
|
|
79
|
+
latitude: Schema.Number,
|
|
80
|
+
longitude: Schema.Number,
|
|
81
|
+
accuracy: Schema.Number
|
|
82
|
+
});
|
|
83
|
+
const GeolocationModel = Schema.Struct({
|
|
84
|
+
status: Schema.Literals([
|
|
85
|
+
"unknown",
|
|
86
|
+
"ready",
|
|
87
|
+
"denied"
|
|
88
|
+
]),
|
|
89
|
+
coords: Schema.NullOr(Coordinates),
|
|
90
|
+
lastError: Schema.NullOr(Schema.String)
|
|
91
|
+
});
|
|
92
|
+
const GeolocationMessage = defineMessageUnion({
|
|
93
|
+
Located: {
|
|
94
|
+
latitude: Schema.Number,
|
|
95
|
+
longitude: Schema.Number,
|
|
96
|
+
accuracy: Schema.Number
|
|
97
|
+
},
|
|
98
|
+
Denied: {},
|
|
99
|
+
Failed: { message: Schema.String }
|
|
100
|
+
});
|
|
101
|
+
const watchStream = () => {
|
|
102
|
+
if (typeof navigator === "undefined" || typeof navigator.geolocation?.watchPosition !== "function") return Stream.empty;
|
|
103
|
+
const geolocation = navigator.geolocation;
|
|
104
|
+
return Stream.unwrap(Effect.gen(function* () {
|
|
105
|
+
const queue = yield* Queue.unbounded();
|
|
106
|
+
const onLocated = (position) => {
|
|
107
|
+
Effect.runFork(Queue.offer(queue, GeolocationMessage.Located({
|
|
108
|
+
latitude: position.coords.latitude,
|
|
109
|
+
longitude: position.coords.longitude,
|
|
110
|
+
accuracy: position.coords.accuracy
|
|
111
|
+
})));
|
|
112
|
+
};
|
|
113
|
+
const onError = (error) => {
|
|
114
|
+
Effect.runFork(Queue.offer(queue, error.code === 1 ? GeolocationMessage.Denied() : GeolocationMessage.Failed({ message: error.message })));
|
|
115
|
+
};
|
|
116
|
+
const watchId = geolocation.watchPosition(onLocated, onError);
|
|
117
|
+
yield* Effect.addFinalizer(() => Effect.sync(() => geolocation.clearWatch(watchId)));
|
|
118
|
+
return Stream.fromQueue(queue);
|
|
119
|
+
}));
|
|
120
|
+
};
|
|
121
|
+
const Geolocation = Bundle.make("Geolocation", {
|
|
122
|
+
Model: GeolocationModel,
|
|
123
|
+
Message: GeolocationMessage,
|
|
124
|
+
init: () => ({ model: {
|
|
125
|
+
status: "unknown",
|
|
126
|
+
coords: null,
|
|
127
|
+
lastError: null
|
|
128
|
+
} }),
|
|
129
|
+
update: (model, message) => GeolocationMessage.match(message, {
|
|
130
|
+
Located: ({ latitude, longitude, accuracy }) => ({ model: {
|
|
131
|
+
...model,
|
|
132
|
+
status: "ready",
|
|
133
|
+
coords: {
|
|
134
|
+
latitude,
|
|
135
|
+
longitude,
|
|
136
|
+
accuracy
|
|
137
|
+
}
|
|
138
|
+
} }),
|
|
139
|
+
Denied: () => ({ model: {
|
|
140
|
+
...model,
|
|
141
|
+
status: "denied"
|
|
142
|
+
} }),
|
|
143
|
+
Failed: ({ message }) => ({ model: {
|
|
144
|
+
...model,
|
|
145
|
+
lastError: message
|
|
146
|
+
} })
|
|
147
|
+
}),
|
|
148
|
+
subscriptions: () => Subscription.make()(() => ({ watch: Subscription.persistent(watchStream()) }))
|
|
149
|
+
});
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/device/media-devices.ts
|
|
152
|
+
/**
|
|
153
|
+
* Media devices as a bundle factory: the enumerated device list in the
|
|
154
|
+
* Model, scanned on placement and re-scanned on every `devicechange`.
|
|
155
|
+
* Denial lands as `denied` with an empty list (actionable UI); any other
|
|
156
|
+
* failure keeps the last list and notes the error. No media-devices API
|
|
157
|
+
* yields an empty stream and a `Failed` scan instead of throwing.
|
|
158
|
+
*/
|
|
159
|
+
const MediaDevice = Schema.Struct({
|
|
160
|
+
deviceId: Schema.String,
|
|
161
|
+
groupId: Schema.String,
|
|
162
|
+
kind: Schema.Literals([
|
|
163
|
+
"audioinput",
|
|
164
|
+
"audiooutput",
|
|
165
|
+
"videoinput"
|
|
166
|
+
]),
|
|
167
|
+
label: Schema.String
|
|
168
|
+
});
|
|
169
|
+
const MediaDevicesModel = Schema.Struct({
|
|
170
|
+
status: Schema.Literals([
|
|
171
|
+
"unknown",
|
|
172
|
+
"ready",
|
|
173
|
+
"denied"
|
|
174
|
+
]),
|
|
175
|
+
devices: Schema.Array(MediaDevice),
|
|
176
|
+
lastError: Schema.NullOr(Schema.String)
|
|
177
|
+
});
|
|
178
|
+
const MediaDevicesMessage = defineMessageUnion({
|
|
179
|
+
Scan: {},
|
|
180
|
+
DevicesChanged: {},
|
|
181
|
+
Refreshed: { devices: Schema.Array(MediaDevice) },
|
|
182
|
+
Denied: {},
|
|
183
|
+
Failed: { message: Schema.String }
|
|
184
|
+
});
|
|
185
|
+
const failMessage$2 = (error) => error instanceof Error ? error.message : String(error);
|
|
186
|
+
const isDenied$1 = (error) => typeof error?.name === "string" && ["NotAllowedError", "SecurityError"].includes(error.name);
|
|
187
|
+
const mediaDevices = (config) => {
|
|
188
|
+
const handle = () => {
|
|
189
|
+
if (typeof navigator === "undefined") return null;
|
|
190
|
+
if (config.create !== void 0) return config.create(navigator);
|
|
191
|
+
return navigator.mediaDevices ?? null;
|
|
192
|
+
};
|
|
193
|
+
const scanEffect = Effect.matchEffect(Effect.tryPromise({
|
|
194
|
+
try: async () => {
|
|
195
|
+
const devices = handle();
|
|
196
|
+
if (devices === null) throw new Error("media devices are unavailable");
|
|
197
|
+
return (await devices.enumerateDevices()).map((item) => {
|
|
198
|
+
if (item.kind !== "audioinput" && item.kind !== "audiooutput" && item.kind !== "videoinput") throw new Error(`unknown device kind: ${item.kind}`);
|
|
199
|
+
return {
|
|
200
|
+
deviceId: item.deviceId,
|
|
201
|
+
groupId: item.groupId,
|
|
202
|
+
kind: item.kind,
|
|
203
|
+
label: item.label
|
|
204
|
+
};
|
|
205
|
+
});
|
|
206
|
+
},
|
|
207
|
+
catch: (error) => error
|
|
208
|
+
}), {
|
|
209
|
+
onFailure: (error) => Effect.succeed(isDenied$1(error) ? MediaDevicesMessage.Denied() : MediaDevicesMessage.Failed({ message: failMessage$2(error) })),
|
|
210
|
+
onSuccess: (devices) => Effect.succeed(MediaDevicesMessage.Refreshed({ devices: [...devices] }))
|
|
211
|
+
});
|
|
212
|
+
const scan = () => ({
|
|
213
|
+
name: `${config.name}.scan`,
|
|
214
|
+
effect: scanEffect
|
|
215
|
+
});
|
|
216
|
+
const changedStream = () => {
|
|
217
|
+
const devices = handle();
|
|
218
|
+
if (devices === null) return Stream.empty;
|
|
219
|
+
return Stream.fromEventListener(devices, "devicechange").pipe(Stream.map(() => MediaDevicesMessage.DevicesChanged()));
|
|
220
|
+
};
|
|
221
|
+
return Bundle.make(config.name, {
|
|
222
|
+
Model: MediaDevicesModel,
|
|
223
|
+
Message: MediaDevicesMessage,
|
|
224
|
+
init: () => ({
|
|
225
|
+
model: {
|
|
226
|
+
status: "unknown",
|
|
227
|
+
devices: [],
|
|
228
|
+
lastError: null
|
|
229
|
+
},
|
|
230
|
+
commands: [scan()]
|
|
231
|
+
}),
|
|
232
|
+
update: (model, message) => MediaDevicesMessage.match(message, {
|
|
233
|
+
Scan: () => ({
|
|
234
|
+
model,
|
|
235
|
+
commands: [scan()]
|
|
236
|
+
}),
|
|
237
|
+
DevicesChanged: () => ({
|
|
238
|
+
model,
|
|
239
|
+
commands: [scan()]
|
|
240
|
+
}),
|
|
241
|
+
Refreshed: ({ devices }) => ({ model: {
|
|
242
|
+
...model,
|
|
243
|
+
status: "ready",
|
|
244
|
+
devices: [...devices]
|
|
245
|
+
} }),
|
|
246
|
+
Denied: () => ({ model: {
|
|
247
|
+
...model,
|
|
248
|
+
status: "denied",
|
|
249
|
+
devices: []
|
|
250
|
+
} }),
|
|
251
|
+
Failed: ({ message }) => ({ model: {
|
|
252
|
+
...model,
|
|
253
|
+
lastError: message
|
|
254
|
+
} })
|
|
255
|
+
}),
|
|
256
|
+
subscriptions: () => Subscription.make()(() => ({ changes: Subscription.persistent(changedStream()) }))
|
|
257
|
+
});
|
|
258
|
+
};
|
|
259
|
+
//#endregion
|
|
260
|
+
//#region src/device/media-stream.ts
|
|
261
|
+
/**
|
|
262
|
+
* A camera/mic stream as a bundle factory: one live MediaStream held in a
|
|
263
|
+
* Managed Resource while the Model asks for it. `Started` requests,
|
|
264
|
+
* `Stopped` releases; denial parks at `denied` (actionable UI), any other
|
|
265
|
+
* acquire failure parks at `idle` with the error noted — both clear
|
|
266
|
+
* requirements, so a failing device never spins an acquire loop. Release
|
|
267
|
+
* stops every track. No media-devices API fails the acquire instead of
|
|
268
|
+
* throwing.
|
|
269
|
+
*/
|
|
270
|
+
const MediaStreamModel = Schema.Struct({
|
|
271
|
+
status: Schema.Literals([
|
|
272
|
+
"idle",
|
|
273
|
+
"requesting",
|
|
274
|
+
"live",
|
|
275
|
+
"denied"
|
|
276
|
+
]),
|
|
277
|
+
lastError: Schema.NullOr(Schema.String)
|
|
278
|
+
});
|
|
279
|
+
const MediaStreamMessage = defineMessageUnion({
|
|
280
|
+
Started: {},
|
|
281
|
+
Stopped: {},
|
|
282
|
+
Live: {},
|
|
283
|
+
Ended: {},
|
|
284
|
+
Denied: {},
|
|
285
|
+
Failed: { message: Schema.String }
|
|
286
|
+
});
|
|
287
|
+
/** The live stream, for commands that attach it to an element. One assembly holds one. */
|
|
288
|
+
const LiveStream = ManagedResource.tag()("media-stream");
|
|
289
|
+
const failMessage$1 = (error) => error instanceof Error ? error.message : String(error);
|
|
290
|
+
const isDenied = (error) => typeof error?.name === "string" && ["NotAllowedError", "SecurityError"].includes(error.name);
|
|
291
|
+
const mediaStream = (config) => {
|
|
292
|
+
const request = (constraints) => {
|
|
293
|
+
if (config.request !== void 0) return config.request(constraints);
|
|
294
|
+
if (typeof navigator === "undefined" || typeof navigator.mediaDevices?.getUserMedia !== "function") return Promise.reject(/* @__PURE__ */ new Error("media devices are unavailable"));
|
|
295
|
+
return navigator.mediaDevices.getUserMedia(constraints);
|
|
296
|
+
};
|
|
297
|
+
return Bundle.make(config.name, {
|
|
298
|
+
Model: MediaStreamModel,
|
|
299
|
+
Message: MediaStreamMessage,
|
|
300
|
+
args: Schema.Struct({
|
|
301
|
+
audio: Schema.Boolean,
|
|
302
|
+
video: Schema.Boolean
|
|
303
|
+
}),
|
|
304
|
+
init: () => ({ model: {
|
|
305
|
+
status: "idle",
|
|
306
|
+
lastError: null
|
|
307
|
+
} }),
|
|
308
|
+
update: (model, message) => MediaStreamMessage.match(message, {
|
|
309
|
+
Started: () => ({ model: {
|
|
310
|
+
...model,
|
|
311
|
+
status: "requesting"
|
|
312
|
+
} }),
|
|
313
|
+
Stopped: () => ({ model: {
|
|
314
|
+
...model,
|
|
315
|
+
status: "idle"
|
|
316
|
+
} }),
|
|
317
|
+
Live: () => ({ model: {
|
|
318
|
+
...model,
|
|
319
|
+
status: "live",
|
|
320
|
+
lastError: null
|
|
321
|
+
} }),
|
|
322
|
+
Ended: () => ({ model: {
|
|
323
|
+
...model,
|
|
324
|
+
status: "idle"
|
|
325
|
+
} }),
|
|
326
|
+
Denied: () => ({ model: {
|
|
327
|
+
...model,
|
|
328
|
+
status: "denied"
|
|
329
|
+
} }),
|
|
330
|
+
Failed: ({ message }) => ({ model: {
|
|
331
|
+
...model,
|
|
332
|
+
status: "idle",
|
|
333
|
+
lastError: message
|
|
334
|
+
} })
|
|
335
|
+
}),
|
|
336
|
+
resources: (args) => ManagedResource.make()((entry) => ({ stream: entry(Schema.Option(Schema.Struct({
|
|
337
|
+
audio: Schema.Boolean,
|
|
338
|
+
video: Schema.Boolean
|
|
339
|
+
})), {
|
|
340
|
+
resource: LiveStream,
|
|
341
|
+
modelToMaybeRequirements: (model) => model.status === "requesting" || model.status === "live" ? Option.some({
|
|
342
|
+
audio: args.audio,
|
|
343
|
+
video: args.video
|
|
344
|
+
}) : Option.none(),
|
|
345
|
+
acquire: (constraints) => Effect.tryPromise({
|
|
346
|
+
try: () => request(constraints),
|
|
347
|
+
catch: (error) => error
|
|
348
|
+
}),
|
|
349
|
+
onAcquired: () => MediaStreamMessage.Live(),
|
|
350
|
+
onReleased: () => MediaStreamMessage.Ended(),
|
|
351
|
+
onAcquireError: (error) => isDenied(error) ? MediaStreamMessage.Denied() : MediaStreamMessage.Failed({ message: failMessage$1(error) }),
|
|
352
|
+
release: (stream) => Effect.sync(() => {
|
|
353
|
+
for (const track of stream.getTracks()) track.stop();
|
|
354
|
+
})
|
|
355
|
+
}) }))
|
|
356
|
+
});
|
|
357
|
+
};
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/device/permissions.ts
|
|
360
|
+
/**
|
|
361
|
+
* Permission states as a bundle factory: queried on placement, kept current
|
|
362
|
+
* by each status object's `onchange`. A resource holds the status objects
|
|
363
|
+
* (they cannot live in the Model); its queue feeds the subscription, and
|
|
364
|
+
* release detaches every handler. An unknown permission name fails the
|
|
365
|
+
* acquire; an unknown state string fails it too — both become `Failed`,
|
|
366
|
+
* never Model facts.
|
|
367
|
+
*/
|
|
368
|
+
const PermissionState = Schema.Literals([
|
|
369
|
+
"granted",
|
|
370
|
+
"denied",
|
|
371
|
+
"prompt"
|
|
372
|
+
]);
|
|
373
|
+
const PermissionsModel = Schema.Struct({
|
|
374
|
+
states: Schema.Record(Schema.String, PermissionState),
|
|
375
|
+
lastError: Schema.NullOr(Schema.String)
|
|
376
|
+
});
|
|
377
|
+
const PermissionsMessage = defineMessageUnion({
|
|
378
|
+
Snapshot: { states: Schema.Record(Schema.String, PermissionState) },
|
|
379
|
+
Changed: {
|
|
380
|
+
name: Schema.String,
|
|
381
|
+
state: PermissionState
|
|
382
|
+
},
|
|
383
|
+
Cleared: {},
|
|
384
|
+
Failed: { message: Schema.String }
|
|
385
|
+
});
|
|
386
|
+
/** The watched statuses, for the changes subscription. One assembly holds one. */
|
|
387
|
+
const Watch = ManagedResource.tag()("permissions");
|
|
388
|
+
const failMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
389
|
+
const readState = (state, name) => {
|
|
390
|
+
if (state !== "granted" && state !== "denied" && state !== "prompt") throw new Error(`unknown permission state for ${name}: ${state}`);
|
|
391
|
+
return state;
|
|
392
|
+
};
|
|
393
|
+
const permissions = (config) => {
|
|
394
|
+
const handle = () => {
|
|
395
|
+
if (typeof navigator === "undefined") return null;
|
|
396
|
+
if (config.create !== void 0) return config.create(navigator);
|
|
397
|
+
return navigator.permissions ?? null;
|
|
398
|
+
};
|
|
399
|
+
return Bundle.make(config.name, {
|
|
400
|
+
Model: PermissionsModel,
|
|
401
|
+
Message: PermissionsMessage,
|
|
402
|
+
args: Schema.Struct({ names: Schema.Array(Schema.String) }),
|
|
403
|
+
init: () => ({ model: {
|
|
404
|
+
states: {},
|
|
405
|
+
lastError: null
|
|
406
|
+
} }),
|
|
407
|
+
update: (model, message) => PermissionsMessage.match(message, {
|
|
408
|
+
Snapshot: ({ states }) => ({ model: {
|
|
409
|
+
...model,
|
|
410
|
+
states: { ...states }
|
|
411
|
+
} }),
|
|
412
|
+
Changed: ({ name, state }) => ({ model: {
|
|
413
|
+
...model,
|
|
414
|
+
states: {
|
|
415
|
+
...model.states,
|
|
416
|
+
[name]: state
|
|
417
|
+
}
|
|
418
|
+
} }),
|
|
419
|
+
Cleared: () => ({ model: {
|
|
420
|
+
...model,
|
|
421
|
+
states: {}
|
|
422
|
+
} }),
|
|
423
|
+
Failed: ({ message }) => ({ model: {
|
|
424
|
+
...model,
|
|
425
|
+
lastError: message
|
|
426
|
+
} })
|
|
427
|
+
}),
|
|
428
|
+
resources: (args) => ManagedResource.make()((entry) => ({ watch: entry(Schema.Option(Schema.Array(Schema.String)), {
|
|
429
|
+
resource: Watch,
|
|
430
|
+
modelToMaybeRequirements: () => Option.some([...new Set(args.names)]),
|
|
431
|
+
acquire: (names) => Effect.gen(function* () {
|
|
432
|
+
const api = handle();
|
|
433
|
+
if (api === null) throw new Error("permissions are unavailable");
|
|
434
|
+
const events = yield* Queue.unbounded();
|
|
435
|
+
const statuses = /* @__PURE__ */ new Map();
|
|
436
|
+
let tail = Promise.resolve();
|
|
437
|
+
const offer = (message) => {
|
|
438
|
+
const run = () => Effect.runPromise(Queue.offer(events, message)).then(() => void 0, () => void 0);
|
|
439
|
+
tail = tail.then(run, run);
|
|
440
|
+
};
|
|
441
|
+
const queried = [];
|
|
442
|
+
for (const name of names) {
|
|
443
|
+
const status = yield* Effect.tryPromise({
|
|
444
|
+
try: () => api.query({ name }),
|
|
445
|
+
catch: (error) => error
|
|
446
|
+
});
|
|
447
|
+
queried.push([
|
|
448
|
+
name,
|
|
449
|
+
status,
|
|
450
|
+
readState(status.state, name)
|
|
451
|
+
]);
|
|
452
|
+
}
|
|
453
|
+
const snapshot = {};
|
|
454
|
+
for (const [name, status, state] of queried) {
|
|
455
|
+
status.onchange = () => {
|
|
456
|
+
try {
|
|
457
|
+
offer(PermissionsMessage.Changed({
|
|
458
|
+
name,
|
|
459
|
+
state: readState(status.state, name)
|
|
460
|
+
}));
|
|
461
|
+
} catch {
|
|
462
|
+
offer(PermissionsMessage.Failed({ message: `unknown permission state for ${name}` }));
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
statuses.set(name, status);
|
|
466
|
+
snapshot[name] = state;
|
|
467
|
+
}
|
|
468
|
+
return {
|
|
469
|
+
statuses,
|
|
470
|
+
snapshot,
|
|
471
|
+
events
|
|
472
|
+
};
|
|
473
|
+
}),
|
|
474
|
+
onAcquired: ({ snapshot }) => PermissionsMessage.Snapshot({ states: { ...snapshot } }),
|
|
475
|
+
onReleased: () => PermissionsMessage.Cleared(),
|
|
476
|
+
onAcquireError: (error) => PermissionsMessage.Failed({ message: failMessage(error) }),
|
|
477
|
+
release: ({ statuses, events }) => Effect.asVoid(Effect.andThen(Effect.sync(() => {
|
|
478
|
+
for (const status of statuses.values()) status.onchange = null;
|
|
479
|
+
}), Queue.shutdown(events)))
|
|
480
|
+
}) })),
|
|
481
|
+
subscriptions: () => Subscription.make()(() => ({ changes: Subscription.persistent(Stream.unwrap(Effect.matchEffect(Watch.get, {
|
|
482
|
+
onFailure: () => Effect.succeed(Stream.empty),
|
|
483
|
+
onSuccess: ({ events }) => Effect.succeed(Stream.fromQueue(events))
|
|
484
|
+
}))) }))
|
|
485
|
+
});
|
|
486
|
+
};
|
|
487
|
+
//#endregion
|
|
488
|
+
export { Coordinates, FullscreenMessage, Geolocation, GeolocationMessage, GeolocationModel, LiveStream, MediaDevice, MediaDevicesMessage, MediaDevicesModel, MediaStreamMessage, MediaStreamModel, PermissionState, PermissionsMessage, PermissionsModel, Watch, enterFullscreen, exitFullscreen, fullscreenChanges, mediaDevices, mediaStream, permissions };
|
|
489
|
+
|
|
490
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +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'\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 Located: ({ latitude, longitude, accuracy }) => ({\n model: { ...model, status: 'ready' as const, coords: { latitude, longitude, accuracy } },\n }),\n Denied: () => ({ model: { ...model, status: 'denied' as const } }),\n Failed: ({ message }) => ({ 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` with an empty list (actionable UI); any other\n * failure keeps the last list and notes the error. No media-devices API\n * yields an empty stream 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'\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\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 Refreshed: ({ devices }) => ({\n model: { ...model, status: 'ready' as const, devices: [...devices] },\n }),\n Denied: () => ({ model: { ...model, status: 'denied' as const, devices: [] } }),\n Failed: ({ message }) => ({ 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'\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 Started: () => ({ model: { ...model, status: 'requesting' as const } }),\n Stopped: () => ({ model: { ...model, status: 'idle' as const } }),\n Live: () => ({ model: { ...model, status: 'live' as const, lastError: null } }),\n Ended: () => ({ model: { ...model, status: 'idle' as const } }),\n Denied: () => ({ model: { ...model, status: 'denied' as const } }),\n Failed: ({ message }) => ({\n model: { ...model, status: 'idle' as const, 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'\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 }) => ({ model: { ...model, states: { ...states } } }),\n Changed: ({ name, state }) => ({\n model: { ...model, states: { ...model.states, [name]: state } },\n }),\n Cleared: () => ({ model: { ...model, states: {} } }),\n Failed: ({ message }) => ({ model: { ...model, lastError: message } }),\n }),\n resources: args =>\n ManagedResource.make<PermissionsModel, PermissionsMessage>()(entry => ({\n watch: entry(Schema.Option(Schema.Array(Schema.String)), {\n resource: Watch,\n modelToMaybeRequirements: () => Option.some([...new Set(args.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 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.fromQueue(events)),\n }),\n ),\n ),\n })),\n })\n}\n"],"mappings":";;;;;;;;;;;;;AAWA,MAAa,oBAAoB,mBAAmB;CAClD,SAAS,EAAE,QAAQ,OAAO,QAAQ;CAClC,SAAS,CAAC;CACV,QAAQ,CAAC;CACT,QAAQ,EAAE,SAAS,OAAO,OAAO;AACnC,CAAC;AAGD,MAAMA,iBAAe,UACnB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;;;;;;;AAQvD,MAAa,mBAAmB,aAAgE;CAC9F,MAAM;CACN,MAAM,CAAC;CACP,QAAQ,OAAO,YACb,OAAO,WAAW;EAChB,WAAW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CAAU;IACrE;IACA,MAAM,WAA4C,CAAC;IACnD,KAAK,MAAM,CAAC,MAAM,QAAQ,UAAU,SAAS;KAC3C,OAAO,iBAAiB;MACtB,IAAI;OACF,MACE,mBAAmB,QAAQ;QAAE;QAAM,OAAO,UAAU,OAAO,OAAO,IAAI;OAAE,CAAC,CAC3E;MACF,QAAQ;OAGN,MACE,mBAAmB,OAAO,EACxB,SAAS,gCAAgC,OAC3C,CAAC,CACH;MACF;KACF;KACA,SAAS,IAAI,MAAM,MAAM;KACzB,SAAS,QAAQ;IACnB;IACA,OAAO;KAAE;KAAU;KAAU;IAAO;GACtC,CAAC;GAGH,aAAa,EAAE,eAAe,mBAAmB,SAAS,EAAE,QAAQ,EAAE,GAAG,SAAS,EAAE,CAAC;GACrF,kBAAkB,mBAAmB,QAAQ;GAC7C,iBAAgB,UAAS,mBAAmB,OAAO,EAAE,SAAS,YAAY,KAAK,EAAE,CAAC;GAClF,UAAU,EAAE,UAAU,aACpB,OAAO,OACL,OAAO,QACL,OAAO,WAAW;IAChB,KAAK,MAAM,UAAU,SAAS,OAAO,GAAG,OAAO,WAAW;GAC5D,CAAC,GACD,MAAM,SAAS,MAAM,CACvB,CACF;EACJ,CAAC,EACH,EAAE;EACJ,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"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import * as Mount from "foldkit/mount";
|
|
3
|
+
import { Command } from "foldkit/command";
|
|
4
|
+
//#region src/dom/autofocus.d.ts
|
|
5
|
+
export declare const Focused: Schema.TaggedStruct<"Focused", {}>;
|
|
6
|
+
export type Focused = typeof Focused.Type;
|
|
7
|
+
export declare const Autofocus: Mount.MountDefinitionNoArgs<"Autofocus", {
|
|
8
|
+
readonly _tag: "Focused";
|
|
9
|
+
}>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/dom/clipboard.d.ts
|
|
12
|
+
export declare const ClipboardMessage: import("foldkit/message").MessageUnion<{
|
|
13
|
+
readonly Copied: {};
|
|
14
|
+
readonly CopyFailed: {
|
|
15
|
+
readonly message: Schema.String;
|
|
16
|
+
};
|
|
17
|
+
}>;
|
|
18
|
+
export type ClipboardMessage = typeof ClipboardMessage.Type;
|
|
19
|
+
/**
|
|
20
|
+
* Copies text to the clipboard. Without a clipboard API (SSR, insecure
|
|
21
|
+
* context, denied permission) the command yields `CopyFailed` instead of
|
|
22
|
+
* throwing, so `update` handles both outcomes as Messages.
|
|
23
|
+
*/
|
|
24
|
+
export declare const copyText: (text: string) => Command<ClipboardMessage, never, never>;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/dom/input-mask.d.ts
|
|
27
|
+
export declare const Input: Schema.TaggedStruct<"Input", {
|
|
28
|
+
readonly value: Schema.String;
|
|
29
|
+
readonly raw: Schema.String;
|
|
30
|
+
}>;
|
|
31
|
+
export type Input = typeof Input.Type;
|
|
32
|
+
export declare const applyMask: (value: string, pattern: string) => {
|
|
33
|
+
readonly masked: string;
|
|
34
|
+
readonly raw: string;
|
|
35
|
+
};
|
|
36
|
+
export declare const InputMask: Mount.MountDefinitionWithArgs<"InputMask", {
|
|
37
|
+
pattern: Schema.String;
|
|
38
|
+
}, {
|
|
39
|
+
readonly _tag: "Input";
|
|
40
|
+
readonly value: string;
|
|
41
|
+
readonly raw: string;
|
|
42
|
+
}>;
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/dom/script-loader.d.ts
|
|
45
|
+
export declare const ScriptMessage: import("foldkit/message").MessageUnion<{
|
|
46
|
+
readonly Loaded: {};
|
|
47
|
+
readonly LoadFailed: {
|
|
48
|
+
readonly message: Schema.String;
|
|
49
|
+
};
|
|
50
|
+
}>;
|
|
51
|
+
export type ScriptMessage = typeof ScriptMessage.Type;
|
|
52
|
+
/** Loads a script by URL, once per URL. */
|
|
53
|
+
export declare const loadScript: (src: string) => Command<ScriptMessage, never, never>;
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/dom/share.d.ts
|
|
56
|
+
export declare const ShareData: Schema.Struct<{
|
|
57
|
+
readonly title: Schema.optional<Schema.String>;
|
|
58
|
+
readonly text: Schema.optional<Schema.String>;
|
|
59
|
+
readonly url: Schema.optional<Schema.String>;
|
|
60
|
+
}>;
|
|
61
|
+
export type ShareData = typeof ShareData.Type;
|
|
62
|
+
export declare const ShareMessage: import("foldkit/message").MessageUnion<{
|
|
63
|
+
readonly Shared: {};
|
|
64
|
+
readonly Dismissed: {};
|
|
65
|
+
readonly ShareFailed: {
|
|
66
|
+
readonly message: Schema.String;
|
|
67
|
+
};
|
|
68
|
+
}>;
|
|
69
|
+
export type ShareMessage = typeof ShareMessage.Type;
|
|
70
|
+
/** Shares data through the platform sheet. */
|
|
71
|
+
export declare const share: (data: ShareData) => Command<ShareMessage, never, never>;
|
|
72
|
+
//#endregion
|
|
73
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/dom/autofocus.ts","../../src/dom/clipboard.ts","../../src/dom/input-mask.ts","../../src/dom/script-loader.ts","../../src/dom/share.ts"],"mappings":";;;;qBAUa,SAAO,OAAA;YACR,iBAAiB,QAAQ;qBAExB,WAAS,MAAA;;;;;qBCJT,4CAAgB;;;sBAAhB,OAAA;;;YAID,0BAA0B,iBAAiB;;;;;;qBAU1C,WAAQ,iBAAmB,QAAQ;;;qBCXnC,OAAK,OAAA;;;;YAIN,eAAe,MAAM;qBA2BpB,YAAS,eACP;WAED;WAAyB;;qBAoC1B,WAAS,MAAA;;;;;;;;;qBCvET,yCAAa;;;sBAAb,OAAA;;;YAID,uBAAuB,cAAc;;qBASpC,aAAU,gBAAkB,QAAQ;;;qBCbpC,WAAS,OAAA;;;;;YAKV,mBAAmB,UAAU;qBAE5B,wCAAY;;;;sBAAZ,OAAA;;;YAKD,sBAAsB,aAAa;;qBAUlC,QAAK,MAAU,cAAY,QAAQ"}
|