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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +454 -0
  3. package/dist/device/index.d.mts +312 -0
  4. package/dist/device/index.d.mts.map +1 -0
  5. package/dist/device/index.mjs +490 -0
  6. package/dist/device/index.mjs.map +1 -0
  7. package/dist/dom/index.d.mts +73 -0
  8. package/dist/dom/index.d.mts.map +1 -0
  9. package/dist/dom/index.mjs +218 -0
  10. package/dist/dom/index.mjs.map +1 -0
  11. package/dist/events/index.d.mts +154 -0
  12. package/dist/events/index.d.mts.map +1 -0
  13. package/dist/events/index.mjs +287 -0
  14. package/dist/events/index.mjs.map +1 -0
  15. package/dist/index.d.mts +10 -0
  16. package/dist/index.mjs +10 -0
  17. package/dist/media/index.d.mts +79 -0
  18. package/dist/media/index.d.mts.map +1 -0
  19. package/dist/media/index.mjs +127 -0
  20. package/dist/media/index.mjs.map +1 -0
  21. package/dist/motion/index.d.mts +112 -0
  22. package/dist/motion/index.d.mts.map +1 -0
  23. package/dist/motion/index.mjs +208 -0
  24. package/dist/motion/index.mjs.map +1 -0
  25. package/dist/net/index.d.mts +199 -0
  26. package/dist/net/index.d.mts.map +1 -0
  27. package/dist/net/index.mjs +329 -0
  28. package/dist/net/index.mjs.map +1 -0
  29. package/dist/observers/index.d.mts +59 -0
  30. package/dist/observers/index.d.mts.map +1 -0
  31. package/dist/observers/index.mjs +156 -0
  32. package/dist/observers/index.mjs.map +1 -0
  33. package/dist/state/index.d.mts +342 -0
  34. package/dist/state/index.d.mts.map +1 -0
  35. package/dist/state/index.mjs +504 -0
  36. package/dist/state/index.mjs.map +1 -0
  37. package/dist/time/index.d.mts +129 -0
  38. package/dist/time/index.d.mts.map +1 -0
  39. package/dist/time/index.mjs +213 -0
  40. package/dist/time/index.mjs.map +1 -0
  41. package/package.json +96 -0
@@ -0,0 +1,312 @@
1
+ import { Option, Queue, Schema, Stream } from "effect";
2
+ import { Bundle } from "foldkit-bundle";
3
+ import * as ManagedResource from "foldkit/managedResource";
4
+ import { Command } from "foldkit/command";
5
+ //#region src/device/fullscreen.d.ts
6
+ export declare const FullscreenMessage: import("foldkit/message").MessageUnion<{
7
+ readonly Changed: {
8
+ readonly active: Schema.Boolean;
9
+ };
10
+ readonly Entered: {};
11
+ readonly Exited: {};
12
+ readonly Failed: {
13
+ readonly message: Schema.String;
14
+ };
15
+ }>;
16
+ export type FullscreenMessage = typeof FullscreenMessage.Type;
17
+ /**
18
+ * Requests fullscreen for an element. The capability is feature-checked on
19
+ * the element itself (SVG and HTML elements both qualify), falling back to
20
+ * the legacy `webkit` prefix; a platform with neither yields `Failed`
21
+ * instead of throwing.
22
+ */
23
+ export declare const enterFullscreen: (element: Element) => Command<FullscreenMessage, never, never>;
24
+ /** Leaves fullscreen, with the same legacy fallback. Without a document API it yields `Failed`, not a throw. */
25
+ export declare const exitFullscreen: () => Command<FullscreenMessage, never, never>;
26
+ /**
27
+ * `Changed` whenever fullscreen state flips, starting with the current
28
+ * answer. Without a document the stream is empty instead of throwing.
29
+ */
30
+ export declare const fullscreenChanges: () => Stream.Stream<FullscreenMessage>;
31
+ //#endregion
32
+ //#region src/device/geolocation.d.ts
33
+ export declare const Coordinates: Schema.Struct<{
34
+ readonly latitude: Schema.Number;
35
+ readonly longitude: Schema.Number;
36
+ readonly accuracy: Schema.Number;
37
+ }>;
38
+ export type Coordinates = typeof Coordinates.Type;
39
+ export declare const GeolocationModel: Schema.Struct<{
40
+ readonly status: Schema.Literals<readonly ["unknown", "ready", "denied"]>;
41
+ readonly coords: Schema.NullOr<Schema.Struct<{
42
+ readonly latitude: Schema.Number;
43
+ readonly longitude: Schema.Number;
44
+ readonly accuracy: Schema.Number;
45
+ }>>;
46
+ readonly lastError: Schema.NullOr<Schema.String>;
47
+ }>;
48
+ export type GeolocationModel = typeof GeolocationModel.Type;
49
+ export declare const GeolocationMessage: import("foldkit/message").MessageUnion<{
50
+ readonly Located: {
51
+ readonly latitude: Schema.Number;
52
+ readonly longitude: Schema.Number;
53
+ readonly accuracy: Schema.Number;
54
+ };
55
+ readonly Denied: {};
56
+ readonly Failed: {
57
+ readonly message: Schema.String;
58
+ };
59
+ }>;
60
+ export type GeolocationMessage = typeof GeolocationMessage.Type;
61
+ export declare const Geolocation: Bundle.Bundle<"Geolocation", void, {
62
+ readonly status: "unknown" | "denied" | "ready";
63
+ readonly coords: {
64
+ readonly latitude: number;
65
+ readonly longitude: number;
66
+ readonly accuracy: number;
67
+ } | null;
68
+ readonly lastError: string | null;
69
+ }, {
70
+ readonly _tag: "Failed";
71
+ readonly message: string;
72
+ } | {
73
+ readonly _tag: "Located";
74
+ readonly latitude: number;
75
+ readonly longitude: number;
76
+ readonly accuracy: number;
77
+ } | {
78
+ readonly _tag: "Denied";
79
+ }, never, never, never, void, {}, {}>;
80
+ //#endregion
81
+ //#region src/device/media-devices.d.ts
82
+ export declare const MediaDevice: Schema.Struct<{
83
+ readonly deviceId: Schema.String;
84
+ readonly groupId: Schema.String;
85
+ readonly kind: Schema.Literals<readonly ["audioinput", "audiooutput", "videoinput"]>;
86
+ readonly label: Schema.String;
87
+ }>;
88
+ export type MediaDevice = typeof MediaDevice.Type;
89
+ export declare const MediaDevicesModel: Schema.Struct<{
90
+ readonly status: Schema.Literals<readonly ["unknown", "ready", "denied"]>;
91
+ readonly devices: Schema.$Array<Schema.Struct<{
92
+ readonly deviceId: Schema.String;
93
+ readonly groupId: Schema.String;
94
+ readonly kind: Schema.Literals<readonly ["audioinput", "audiooutput", "videoinput"]>;
95
+ readonly label: Schema.String;
96
+ }>>;
97
+ readonly lastError: Schema.NullOr<Schema.String>;
98
+ }>;
99
+ export type MediaDevicesModel = typeof MediaDevicesModel.Type;
100
+ export declare const MediaDevicesMessage: import("foldkit/message").MessageUnion<{
101
+ readonly Scan: {};
102
+ readonly DevicesChanged: {};
103
+ readonly Refreshed: {
104
+ readonly devices: Schema.$Array<Schema.Struct<{
105
+ readonly deviceId: Schema.String;
106
+ readonly groupId: Schema.String;
107
+ readonly kind: Schema.Literals<readonly ["audioinput", "audiooutput", "videoinput"]>;
108
+ readonly label: Schema.String;
109
+ }>>;
110
+ };
111
+ readonly Denied: {};
112
+ readonly Failed: {
113
+ readonly message: Schema.String;
114
+ };
115
+ }>;
116
+ export type MediaDevicesMessage = typeof MediaDevicesMessage.Type;
117
+ /** The slice of MediaDevices the bundle needs; satisfied by the platform object. */
118
+ export interface MediaDevicesHandle {
119
+ enumerateDevices(): Promise<ReadonlyArray<{
120
+ readonly deviceId: string;
121
+ readonly groupId: string;
122
+ readonly kind: string;
123
+ readonly label: string;
124
+ }>>;
125
+ addEventListener(type: string, listener: () => void): void;
126
+ removeEventListener(type: string, listener: () => void): void;
127
+ }
128
+ export declare const mediaDevices: <const Name extends string>(config: {
129
+ readonly name: Name;
130
+ /** Read lazily so tests can substitute a double, like the SSE bundle. */
131
+ readonly create?: ((navigator: Navigator) => MediaDevicesHandle | null) | undefined;
132
+ }) => Bundle.Bundle<Name, void, {
133
+ readonly status: "unknown" | "denied" | "ready";
134
+ readonly devices: readonly {
135
+ readonly deviceId: string;
136
+ readonly groupId: string;
137
+ readonly kind: "audioinput" | "audiooutput" | "videoinput";
138
+ readonly label: string;
139
+ }[];
140
+ readonly lastError: string | null;
141
+ }, {
142
+ readonly _tag: "Denied";
143
+ } | {
144
+ readonly _tag: "Failed";
145
+ readonly message: string;
146
+ } | {
147
+ readonly _tag: "Scan";
148
+ } | {
149
+ readonly _tag: "DevicesChanged";
150
+ } | {
151
+ readonly _tag: "Refreshed";
152
+ readonly devices: readonly {
153
+ readonly deviceId: string;
154
+ readonly groupId: string;
155
+ readonly kind: "audioinput" | "audiooutput" | "videoinput";
156
+ readonly label: string;
157
+ }[];
158
+ }, never, never, never, void, {}, {}>;
159
+ //#endregion
160
+ //#region src/device/media-stream.d.ts
161
+ export declare const MediaStreamModel: Schema.Struct<{
162
+ readonly status: Schema.Literals<readonly ["idle", "requesting", "live", "denied"]>;
163
+ readonly lastError: Schema.NullOr<Schema.String>;
164
+ }>;
165
+ export type MediaStreamModel = typeof MediaStreamModel.Type;
166
+ export declare const MediaStreamMessage: import("foldkit/message").MessageUnion<{
167
+ readonly Started: {};
168
+ readonly Stopped: {};
169
+ readonly Live: {};
170
+ readonly Ended: {};
171
+ readonly Denied: {};
172
+ readonly Failed: {
173
+ readonly message: Schema.String;
174
+ };
175
+ }>;
176
+ export type MediaStreamMessage = typeof MediaStreamMessage.Type;
177
+ /** A single media track: stopped on release. */
178
+ export interface MediaTrackHandle {
179
+ stop(): void;
180
+ }
181
+ /** The live stream: its tracks stop on release. */
182
+ export interface MediaStreamHandle {
183
+ getTracks(): ReadonlyArray<MediaTrackHandle>;
184
+ }
185
+ export interface MediaStreamConstraints {
186
+ readonly audio: boolean;
187
+ readonly video: boolean;
188
+ }
189
+ /** The live stream, for commands that attach it to an element. One assembly holds one. */
190
+ export declare const LiveStream: ManagedResource.ManagedResource<MediaStreamHandle, ManagedResource.ManagedResourceService<"media-stream">>;
191
+ /** The stream service a placed camera requires. */
192
+ export type LiveStreamService = ManagedResource.ServiceOf<typeof LiveStream>;
193
+ export declare const mediaStream: <const Name extends string>(config: {
194
+ readonly name: Name;
195
+ /** Read lazily so tests can substitute a double, like the SSE bundle. */
196
+ readonly request?: ((constraints: MediaStreamConstraints) => Promise<MediaStreamHandle>) | undefined;
197
+ }) => Bundle.Bundle<Name, {
198
+ readonly audio: boolean;
199
+ readonly video: boolean;
200
+ }, {
201
+ readonly status: "denied" | "idle" | "requesting" | "live";
202
+ readonly lastError: string | null;
203
+ }, {
204
+ readonly _tag: "Started";
205
+ } | {
206
+ readonly _tag: "Stopped";
207
+ } | {
208
+ readonly _tag: "Denied";
209
+ } | {
210
+ readonly _tag: "Live";
211
+ } | {
212
+ readonly _tag: "Failed";
213
+ readonly message: string;
214
+ } | {
215
+ readonly _tag: "Ended";
216
+ }, never, never, never, void, {
217
+ stream: ManagedResource.Entry<{
218
+ readonly status: "denied" | "idle" | "requesting" | "live";
219
+ readonly lastError: string | null;
220
+ }, {
221
+ readonly _tag: "Started";
222
+ } | {
223
+ readonly _tag: "Stopped";
224
+ } | {
225
+ readonly _tag: "Denied";
226
+ } | {
227
+ readonly _tag: "Live";
228
+ } | {
229
+ readonly _tag: "Failed";
230
+ readonly message: string;
231
+ } | {
232
+ readonly _tag: "Ended";
233
+ }, Option.Option<{
234
+ readonly audio: boolean;
235
+ readonly video: boolean;
236
+ }>, MediaStreamHandle, ManagedResource.ManagedResourceService<"media-stream">, () => {
237
+ readonly _tag: "Live";
238
+ }>;
239
+ }, {}>;
240
+ //#endregion
241
+ //#region src/device/permissions.d.ts
242
+ export declare const PermissionState: Schema.Literals<readonly ["granted", "denied", "prompt"]>;
243
+ export type PermissionState = typeof PermissionState.Type;
244
+ export declare const PermissionsModel: Schema.Struct<{
245
+ readonly states: Schema.$Record<Schema.String, Schema.Literals<readonly ["granted", "denied", "prompt"]>>;
246
+ readonly lastError: Schema.NullOr<Schema.String>;
247
+ }>;
248
+ export type PermissionsModel = typeof PermissionsModel.Type;
249
+ export declare const PermissionsMessage: import("foldkit/message").MessageUnion<{
250
+ readonly Snapshot: {
251
+ readonly states: Schema.$Record<Schema.String, Schema.Literals<readonly ["granted", "denied", "prompt"]>>;
252
+ };
253
+ readonly Changed: {
254
+ readonly name: Schema.String;
255
+ readonly state: Schema.Literals<readonly ["granted", "denied", "prompt"]>;
256
+ };
257
+ readonly Cleared: {};
258
+ readonly Failed: {
259
+ readonly message: Schema.String;
260
+ };
261
+ }>;
262
+ export type PermissionsMessage = typeof PermissionsMessage.Type;
263
+ /** A queried permission status; `onchange` fires while watched. */
264
+ export interface PermissionStatusHandle {
265
+ readonly state: string;
266
+ onchange: (() => void) | null;
267
+ }
268
+ /** The slice of the Permissions API the bundle needs. */
269
+ export interface PermissionsHandle {
270
+ query(descriptor: {
271
+ readonly name: string;
272
+ }): Promise<PermissionStatusHandle>;
273
+ }
274
+ interface Acquired {
275
+ readonly statuses: ReadonlyMap<string, PermissionStatusHandle>;
276
+ readonly snapshot: Readonly<Record<string, PermissionState>>;
277
+ readonly events: Queue.Queue<PermissionsMessage>;
278
+ }
279
+ /** The watched statuses, for the changes subscription. One assembly holds one. */
280
+ export declare const Watch: ManagedResource.ManagedResource<Acquired, ManagedResource.ManagedResourceService<"permissions">>;
281
+ /** The watch service a placed Permissions bundle requires. */
282
+ export type WatchService = ManagedResource.ServiceOf<typeof Watch>;
283
+ export declare const permissions: <const Name extends string>(config: {
284
+ readonly name: Name;
285
+ /** Read lazily so tests can substitute a double, like the SSE bundle. */
286
+ readonly create?: ((navigator: Navigator) => PermissionsHandle | null) | undefined;
287
+ }) => Bundle.Bundle<Name, {
288
+ readonly names: ReadonlyArray<string>;
289
+ }, {
290
+ readonly states: {
291
+ readonly [x: string]: "granted" | "denied" | "prompt";
292
+ };
293
+ readonly lastError: string | null;
294
+ }, {
295
+ readonly _tag: "Changed";
296
+ readonly name: string;
297
+ readonly state: "granted" | "denied" | "prompt";
298
+ } | {
299
+ readonly _tag: "Failed";
300
+ readonly message: string;
301
+ } | {
302
+ readonly _tag: "Snapshot";
303
+ readonly states: {
304
+ readonly [x: string]: "granted" | "denied" | "prompt";
305
+ };
306
+ } | {
307
+ readonly _tag: "Cleared";
308
+ }, never, never, ManagedResource.ManagedResourceService<"permissions">, void, Readonly<{
309
+ watch: ManagedResource.Entry<PermissionsModel, PermissionsMessage, Option.Option<ReadonlyArray<string>>, Acquired, WatchService, (acquired: Acquired) => PermissionsMessage>;
310
+ }>, {}>;
311
+ //#endregion
312
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +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;;;;;;;;;;YAMlB,2BAA2B,kBAAkB;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