@brett_lamy/ui 3.1.0 → 5.0.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 (241) hide show
  1. package/README.md +4 -4
  2. package/dist/components/animated-height.d.ts +3 -1
  3. package/dist/components/animated-height.d.ts.map +1 -1
  4. package/dist/components/animated-height.js +11 -11
  5. package/dist/components/artifact-chat-container.d.ts.map +1 -1
  6. package/dist/components/artifact-chat-container.js +81 -82
  7. package/dist/components/button.d.ts +4 -3
  8. package/dist/components/button.d.ts.map +1 -1
  9. package/dist/components/button.js +22 -9
  10. package/dist/components/canvas.d.ts +91 -0
  11. package/dist/components/canvas.d.ts.map +1 -0
  12. package/dist/components/canvas.js +296 -0
  13. package/dist/components/composer/composer-cards.d.ts +55 -0
  14. package/dist/components/composer/composer-cards.d.ts.map +1 -0
  15. package/dist/components/composer/composer-cards.js +351 -0
  16. package/dist/components/composer/composer.d.ts +9 -1
  17. package/dist/components/composer/composer.d.ts.map +1 -1
  18. package/dist/components/composer/composer.js +179 -154
  19. package/dist/components/context-menu.d.ts +25 -0
  20. package/dist/components/context-menu.d.ts.map +1 -0
  21. package/dist/components/context-menu.js +127 -0
  22. package/dist/components/credenza.d.ts.map +1 -1
  23. package/dist/components/credenza.js +52 -92
  24. package/dist/components/cron-editor.d.ts +47 -0
  25. package/dist/components/cron-editor.d.ts.map +1 -0
  26. package/dist/components/cron-editor.js +297 -0
  27. package/dist/components/dropdown-menu.d.ts +3 -1
  28. package/dist/components/dropdown-menu.d.ts.map +1 -1
  29. package/dist/components/dropdown-menu.js +5 -5
  30. package/dist/components/edge-drawer.d.ts.map +1 -1
  31. package/dist/components/edge-drawer.js +1 -0
  32. package/dist/components/file-upload.d.ts +121 -0
  33. package/dist/components/file-upload.d.ts.map +1 -0
  34. package/dist/components/file-upload.js +405 -0
  35. package/dist/components/filter-input.d.ts +22 -0
  36. package/dist/components/filter-input.d.ts.map +1 -0
  37. package/dist/components/filter-input.js +126 -0
  38. package/dist/components/filter.d.ts +154 -0
  39. package/dist/components/filter.d.ts.map +1 -0
  40. package/dist/components/filter.js +815 -0
  41. package/dist/components/floating-chat.d.ts.map +1 -1
  42. package/dist/components/floating-chat.js +71 -88
  43. package/dist/components/floating-sheet.d.ts +21 -5
  44. package/dist/components/floating-sheet.d.ts.map +1 -1
  45. package/dist/components/floating-sheet.js +113 -116
  46. package/dist/components/markdown-editor.d.ts +2 -0
  47. package/dist/components/markdown-editor.d.ts.map +1 -1
  48. package/dist/components/markdown-editor.js +46 -45
  49. package/dist/components/markdown-view.d.ts +6 -1
  50. package/dist/components/markdown-view.d.ts.map +1 -1
  51. package/dist/components/markdown-view.js +13 -11
  52. package/dist/components/navigation-stack.d.ts +3 -5
  53. package/dist/components/navigation-stack.d.ts.map +1 -1
  54. package/dist/components/navigation-stack.js +212 -382
  55. package/dist/components/passkey-enroll-dialog.d.ts +36 -0
  56. package/dist/components/passkey-enroll-dialog.d.ts.map +1 -0
  57. package/dist/components/passkey-enroll-dialog.js +234 -0
  58. package/dist/components/result-table.d.ts +38 -0
  59. package/dist/components/result-table.d.ts.map +1 -0
  60. package/dist/components/result-table.js +161 -0
  61. package/dist/components/schema-tree.d.ts +19 -0
  62. package/dist/components/schema-tree.d.ts.map +1 -0
  63. package/dist/components/schema-tree.js +172 -0
  64. package/dist/components/side-drawer.d.ts.map +1 -1
  65. package/dist/components/side-drawer.js +117 -143
  66. package/dist/components/slider.d.ts.map +1 -1
  67. package/dist/components/slider.js +4 -1
  68. package/dist/components/spinner-shapes.d.ts +263 -0
  69. package/dist/components/spinner-shapes.d.ts.map +1 -0
  70. package/dist/components/spinner-shapes.js +771 -0
  71. package/dist/components/spinner.d.ts +133 -3
  72. package/dist/components/spinner.d.ts.map +1 -1
  73. package/dist/components/spinner.js +445 -29
  74. package/dist/components/sql-console.d.ts +28 -0
  75. package/dist/components/sql-console.d.ts.map +1 -0
  76. package/dist/components/sql-console.js +348 -0
  77. package/dist/components/sql-editor.d.ts +47 -0
  78. package/dist/components/sql-editor.d.ts.map +1 -0
  79. package/dist/components/sql-editor.js +170 -0
  80. package/dist/components/tab-view.d.ts +2 -2
  81. package/dist/components/tab-view.d.ts.map +1 -1
  82. package/dist/components/tab-view.js +63 -49
  83. package/dist/components/tailscale-login-button.d.ts +53 -0
  84. package/dist/components/tailscale-login-button.d.ts.map +1 -0
  85. package/dist/components/tailscale-login-button.js +197 -0
  86. package/dist/components/time-input.d.ts +46 -0
  87. package/dist/components/time-input.d.ts.map +1 -0
  88. package/dist/components/time-input.js +258 -0
  89. package/dist/components/toast.d.ts +5 -2
  90. package/dist/components/toast.d.ts.map +1 -1
  91. package/dist/components/toast.js +249 -125
  92. package/dist/components/vault-gate.d.ts +60 -0
  93. package/dist/components/vault-gate.d.ts.map +1 -0
  94. package/dist/components/vault-gate.js +382 -0
  95. package/dist/index.css +1 -1
  96. package/dist/index.d.ts +86 -7
  97. package/dist/index.d.ts.map +1 -1
  98. package/dist/index.js +129 -85
  99. package/dist/lib/back-history.d.ts +5 -0
  100. package/dist/lib/back-history.d.ts.map +1 -0
  101. package/dist/lib/back-history.js +44 -0
  102. package/dist/lib/canvas-math.d.ts +82 -0
  103. package/dist/lib/canvas-math.d.ts.map +1 -0
  104. package/dist/lib/canvas-math.js +226 -0
  105. package/dist/lib/controllable-state.d.ts +4 -0
  106. package/dist/lib/controllable-state.d.ts.map +1 -0
  107. package/dist/lib/controllable-state.js +11 -0
  108. package/dist/lib/cron.d.ts +55 -0
  109. package/dist/lib/cron.d.ts.map +1 -0
  110. package/dist/lib/cron.js +269 -0
  111. package/dist/lib/edge-swipe.d.ts +36 -0
  112. package/dist/lib/edge-swipe.d.ts.map +1 -0
  113. package/dist/lib/edge-swipe.js +73 -0
  114. package/dist/lib/file-upload.d.ts +187 -0
  115. package/dist/lib/file-upload.d.ts.map +1 -0
  116. package/dist/lib/file-upload.js +349 -0
  117. package/dist/lib/filter-query.d.ts +90 -0
  118. package/dist/lib/filter-query.d.ts.map +1 -0
  119. package/dist/lib/filter-query.js +459 -0
  120. package/dist/lib/filter.d.ts +120 -0
  121. package/dist/lib/filter.d.ts.map +1 -0
  122. package/dist/lib/filter.js +399 -0
  123. package/dist/lib/format-bytes.d.ts +3 -0
  124. package/dist/lib/format-bytes.d.ts.map +1 -0
  125. package/dist/lib/format-bytes.js +16 -0
  126. package/dist/lib/gpu-cron.d.ts +51 -0
  127. package/dist/lib/gpu-cron.d.ts.map +1 -0
  128. package/dist/lib/gpu-cron.js +81 -0
  129. package/dist/lib/gpu-query/featurize.d.ts +19 -0
  130. package/dist/lib/gpu-query/featurize.d.ts.map +1 -0
  131. package/dist/lib/gpu-query/featurize.js +88 -0
  132. package/dist/lib/gpu-query/index.d.ts +73 -0
  133. package/dist/lib/gpu-query/index.d.ts.map +1 -0
  134. package/dist/lib/gpu-query/index.js +117 -0
  135. package/dist/lib/gpu-query/kernel.wgsl.d.ts +30 -0
  136. package/dist/lib/gpu-query/kernel.wgsl.d.ts.map +1 -0
  137. package/dist/lib/gpu-query/model.d.ts +8 -0
  138. package/dist/lib/gpu-query/model.d.ts.map +1 -0
  139. package/dist/lib/gpu-query/model.js +91 -0
  140. package/dist/lib/gpu-query/schema.d.ts +40 -0
  141. package/dist/lib/gpu-query/schema.d.ts.map +1 -0
  142. package/dist/lib/gpu-query/schema.js +0 -0
  143. package/dist/lib/gpu-query/webgpu.d.ts +12 -0
  144. package/dist/lib/gpu-query/webgpu.d.ts.map +1 -0
  145. package/dist/lib/gpu-query/weights.d.ts +17 -0
  146. package/dist/lib/gpu-query/weights.d.ts.map +1 -0
  147. package/dist/lib/gpu-query/weights.js +40 -0
  148. package/dist/lib/gpu-query/weights.json.d.ts +3 -0
  149. package/dist/lib/gpu-query/weights2.js +25 -0
  150. package/dist/lib/gpu-time.d.ts +77 -0
  151. package/dist/lib/gpu-time.d.ts.map +1 -0
  152. package/dist/lib/gpu-time.js +260 -0
  153. package/dist/lib/morph-path.d.ts +22 -0
  154. package/dist/lib/morph-path.d.ts.map +1 -0
  155. package/dist/lib/morph-path.js +42 -0
  156. package/dist/lib/passkey.d.ts +120 -0
  157. package/dist/lib/passkey.d.ts.map +1 -0
  158. package/dist/lib/passkey.js +186 -0
  159. package/dist/lib/persistent-state.d.ts +9 -0
  160. package/dist/lib/persistent-state.d.ts.map +1 -0
  161. package/dist/lib/persistent-state.js +37 -0
  162. package/dist/lib/pglite-core.d.ts +219 -0
  163. package/dist/lib/pglite-core.d.ts.map +1 -0
  164. package/dist/lib/pglite-core.js +273 -0
  165. package/dist/lib/pglite-files.d.ts +7 -0
  166. package/dist/lib/pglite-files.d.ts.map +1 -0
  167. package/dist/lib/pglite-files.js +17 -0
  168. package/dist/lib/pglite-schema.d.ts +58 -0
  169. package/dist/lib/pglite-schema.d.ts.map +1 -0
  170. package/dist/lib/pglite-schema.js +105 -0
  171. package/dist/lib/pglite-storage.d.ts +33 -0
  172. package/dist/lib/pglite-storage.d.ts.map +1 -0
  173. package/dist/lib/pglite-storage.js +55 -0
  174. package/dist/lib/pglite-transfer.d.ts +53 -0
  175. package/dist/lib/pglite-transfer.d.ts.map +1 -0
  176. package/dist/lib/pglite-transfer.js +126 -0
  177. package/dist/lib/pglite.d.ts +106 -0
  178. package/dist/lib/pglite.d.ts.map +1 -0
  179. package/dist/lib/pglite.js +298 -0
  180. package/dist/lib/pull-to-refresh.d.ts +24 -0
  181. package/dist/lib/pull-to-refresh.d.ts.map +1 -0
  182. package/dist/lib/pull-to-refresh.js +74 -0
  183. package/dist/lib/scroll-hidden.d.ts +6 -0
  184. package/dist/lib/scroll-hidden.d.ts.map +1 -0
  185. package/dist/lib/scroll-hidden.js +21 -0
  186. package/dist/lib/sheet-drag.d.ts +10 -2
  187. package/dist/lib/sheet-drag.d.ts.map +1 -1
  188. package/dist/lib/sheet-drag.js +72 -69
  189. package/dist/lib/sql-format.d.ts +62 -0
  190. package/dist/lib/sql-format.d.ts.map +1 -0
  191. package/dist/lib/sql-format.js +175 -0
  192. package/dist/lib/sql-lex.d.ts +25 -0
  193. package/dist/lib/sql-lex.d.ts.map +1 -0
  194. package/dist/lib/sql-lex.js +135 -0
  195. package/dist/lib/tab-lock.d.ts +28 -0
  196. package/dist/lib/tab-lock.d.ts.map +1 -0
  197. package/dist/lib/tab-lock.js +80 -0
  198. package/dist/lib/tailscale-connect.d.ts +56 -0
  199. package/dist/lib/tailscale-connect.d.ts.map +1 -0
  200. package/dist/lib/tailscale-connect.js +99 -0
  201. package/dist/lib/tailscale-fake.d.ts +33 -0
  202. package/dist/lib/tailscale-fake.d.ts.map +1 -0
  203. package/dist/lib/tailscale-fake.js +80 -0
  204. package/dist/lib/tailscale-policy.d.ts +71 -0
  205. package/dist/lib/tailscale-policy.d.ts.map +1 -0
  206. package/dist/lib/tailscale-policy.js +244 -0
  207. package/dist/lib/tailscale-react.d.ts +20 -0
  208. package/dist/lib/tailscale-react.d.ts.map +1 -0
  209. package/dist/lib/tailscale-react.js +37 -0
  210. package/dist/lib/tailscale-router/bridge.d.ts +60 -0
  211. package/dist/lib/tailscale-router/bridge.d.ts.map +1 -0
  212. package/dist/lib/tailscale-router/bridge.js +198 -0
  213. package/dist/lib/tailscale-router/react.d.ts +19 -0
  214. package/dist/lib/tailscale-router/react.d.ts.map +1 -0
  215. package/dist/lib/tailscale-router/react.js +52 -0
  216. package/dist/lib/tailscale.d.ts +204 -0
  217. package/dist/lib/tailscale.d.ts.map +1 -0
  218. package/dist/lib/tailscale.js +443 -0
  219. package/dist/lib/title-flight.d.ts +34 -0
  220. package/dist/lib/title-flight.d.ts.map +1 -0
  221. package/dist/lib/title-flight.js +123 -0
  222. package/dist/lib/vault-react.d.ts +49 -0
  223. package/dist/lib/vault-react.d.ts.map +1 -0
  224. package/dist/lib/vault-react.js +196 -0
  225. package/dist/lib/vault-storage.d.ts +30 -0
  226. package/dist/lib/vault-storage.d.ts.map +1 -0
  227. package/dist/lib/vault-storage.js +105 -0
  228. package/dist/lib/vault.d.ts +200 -0
  229. package/dist/lib/vault.d.ts.map +1 -0
  230. package/dist/lib/vault.js +641 -0
  231. package/dist/tailscale-sw.js +332 -0
  232. package/package.json +35 -5
  233. package/dist/components/icon-button.d.ts +0 -19
  234. package/dist/components/icon-button.d.ts.map +0 -1
  235. package/dist/components/icon-button.js +0 -31
  236. package/dist/components/measure-h.d.ts +0 -7
  237. package/dist/components/measure-h.d.ts.map +0 -1
  238. package/dist/components/measure-h.js +0 -20
  239. package/dist/components/snap-sheet.d.ts +0 -13
  240. package/dist/components/snap-sheet.d.ts.map +0 -1
  241. package/dist/components/snap-sheet.js +0 -100
@@ -0,0 +1,204 @@
1
+ import { ResolvedTailscalePolicy, TailscalePolicy } from './tailscale-policy';
2
+ /** The backend states Tailscale's client reports (ipn/backend.go). */
3
+ export type TailscaleClientState = 'NoState' | 'InUseOtherUser' | 'NeedsLogin' | 'NeedsMachineAuth' | 'Stopped' | 'Starting' | 'Running';
4
+ export interface TailscaleNode {
5
+ name: string;
6
+ addresses: string[];
7
+ online?: boolean;
8
+ }
9
+ export interface TailscaleNetMap {
10
+ self: TailscaleNode;
11
+ peers: TailscaleNode[];
12
+ /** Tailnet lock is on and this node is not signed. */
13
+ lockedOut?: boolean;
14
+ }
15
+ export interface TailscaleClientEvent {
16
+ state?: TailscaleClientState;
17
+ /** The control server wants the person to visit this URL (notifyBrowseToURL). */
18
+ loginUrl?: string | null;
19
+ netMap?: TailscaleNetMap | null;
20
+ /** The client crashed or panicked; it is unusable until restarted. */
21
+ error?: string;
22
+ }
23
+ export interface TailscaleClientStartOptions {
24
+ hostname: string;
25
+ /** A Headscale or other control server. Default: Tailscale's. */
26
+ controlUrl?: string;
27
+ /** A pre-auth key: sign in without a person. */
28
+ authKey?: string;
29
+ /** The saved state map (node keys, profile), or null for a new node. */
30
+ state: Record<string, string> | null;
31
+ /** Called with the whole map after the client writes to it. */
32
+ onState: (state: Record<string, string>) => void;
33
+ onEvent: (event: TailscaleClientEvent) => void;
34
+ }
35
+ /** A request as the tailnet client takes it. Header names are lower case; `body` is absent for GET and HEAD. */
36
+ export interface TailscaleRequest {
37
+ url: string;
38
+ method?: string;
39
+ headers?: Array<[string, string]>;
40
+ body?: Uint8Array | null;
41
+ redirect?: RequestRedirect;
42
+ signal?: AbortSignal;
43
+ }
44
+ export interface TailscaleResponse {
45
+ url?: string;
46
+ status: number;
47
+ statusText?: string;
48
+ headers: Array<[string, string]>;
49
+ /** Bytes, or a stream for a client that can stream (the WebAssembly client cannot: it returns the whole body). */
50
+ body: Uint8Array | ReadableStream<Uint8Array> | null;
51
+ }
52
+ /** What BL UI needs from a tailnet client. `createTailscaleConnectClient` and `createFakeTailscaleClient` make one. */
53
+ export interface TailscaleClient {
54
+ start(options: TailscaleClientStartOptions): Promise<void>;
55
+ /** Ask for an interactive sign-in; the client answers with a `loginUrl` event. */
56
+ login(): Promise<void> | void;
57
+ logout(): Promise<void> | void;
58
+ fetch(request: TailscaleRequest): Promise<TailscaleResponse>;
59
+ dispose(): Promise<void> | void;
60
+ }
61
+ /** What is kept between visits. `state` holds the node's private keys: whoever has it can act as this device. */
62
+ export interface TailscaleSession {
63
+ v: 1;
64
+ hostname: string;
65
+ state: Record<string, string>;
66
+ }
67
+ export interface TailscalePersistence {
68
+ load(): Promise<TailscaleSession | null>;
69
+ save(session: TailscaleSession): Promise<void>;
70
+ clear(): Promise<void>;
71
+ }
72
+ /** Nothing outlives the page (the default when no persistence is given). Every visit is a new device. */
73
+ export declare function memoryTailscalePersistence(): TailscalePersistence;
74
+ /** A `Storage` (sessionStorage, localStorage). **Plain text**: any script on the origin, and anyone with the profile's files, can read the node keys. */
75
+ export declare function webStorageTailscalePersistence(storage: Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>, key?: string): TailscalePersistence;
76
+ /** The part of a passkey vault (`createVault` in lib/vault) this needs. */
77
+ export interface TailscaleVaultLike {
78
+ get<T = unknown>(name: string): Promise<T | undefined>;
79
+ put(name: string, value: unknown): Promise<void>;
80
+ delete(name: string): Promise<void>;
81
+ }
82
+ /** Encrypted at rest in a passkey vault. The vault must be unlocked: load and save fail while it is locked. */
83
+ export declare function vaultTailscalePersistence(vault: TailscaleVaultLike, name?: string): TailscalePersistence;
84
+ export type TailscaleErrorReason = 'no-client' | 'client' | 'auth-key' | 'login-url' | 'not-connected' | 'other-tab' | 'storage' | 'locked-out' | 'in-use';
85
+ export declare class TailscaleError extends Error {
86
+ readonly reason: TailscaleErrorReason;
87
+ constructor(reason: TailscaleErrorReason, message: string, options?: {
88
+ cause?: unknown;
89
+ });
90
+ }
91
+ /** A sentence for the person using the app. Replace it to localise. */
92
+ export declare function tailscaleErrorMessage(error: unknown): string;
93
+ export type TailscaleStatus = 'idle' | 'loading' | 'needs-login' | 'signing-in' | 'starting' | 'needs-approval' | 'connected' | 'error';
94
+ export interface TailscalePeer {
95
+ name: string;
96
+ addresses: string[];
97
+ online: boolean;
98
+ }
99
+ export interface TailscaleSnapshot {
100
+ status: TailscaleStatus;
101
+ /** While signing in: the page to open (https, or http on loopback for a local control server). */
102
+ loginUrl: string | null;
103
+ error: TailscaleError | null;
104
+ /** A problem that did not stop the connection (saving the session failed). */
105
+ warning: string | null;
106
+ /** This device's MagicDNS name, its tailnet (`tail1234.ts.net`) and addresses. */
107
+ selfName: string | null;
108
+ tailnet: string | null;
109
+ addresses: string[];
110
+ peers: TailscalePeer[];
111
+ /** A saved session exists: `connect()` restores it without a sign-in. */
112
+ hasSession: boolean;
113
+ }
114
+ export type TailscaleAuth = {
115
+ mode: 'interactive';
116
+ }
117
+ /** A pre-auth key, or a function that fetches one (from your server, for the signed-in user). It is passed to the client and never stored. */
118
+ | {
119
+ mode: 'auth-key';
120
+ authKey: string | ((signal: AbortSignal) => Promise<string>);
121
+ };
122
+ /** Just enough of a window for the sign-in popup. */
123
+ export interface TailscalePopup {
124
+ closed?: boolean;
125
+ opener?: unknown;
126
+ close(): void;
127
+ location: {
128
+ replace(url: string): void;
129
+ } | Location;
130
+ document?: {
131
+ title: string;
132
+ body: {
133
+ textContent: string | null;
134
+ } | null;
135
+ } | Document;
136
+ }
137
+ export interface TailscaleEnv {
138
+ /** `window.open`; return null where popups are blocked. */
139
+ open?: ((url: string, target: string, features: string) => TailscalePopup | null) | null;
140
+ /** `navigator.locks`, to keep one tailnet node per origin. */
141
+ locks?: Pick<LockManager, 'request'> | null;
142
+ }
143
+ export interface TailscaleOptions {
144
+ /** The tailnet client, or a function that makes it (called on first use, so its code loads lazily). */
145
+ client?: TailscaleClient | (() => TailscaleClient | Promise<TailscaleClient>);
146
+ /** Default interactive. */
147
+ auth?: TailscaleAuth;
148
+ /** Where the node's keys are kept. Default: memory (every visit is a new device). */
149
+ persistence?: TailscalePersistence;
150
+ /** This device's name on the tailnet. Default `bl-` and six random letters, kept with the session. */
151
+ hostname?: string;
152
+ /** A Headscale (or other) control server URL. */
153
+ controlUrl?: string;
154
+ /** Restore a saved session on activation. Default true. */
155
+ autoConnect?: boolean;
156
+ /** Called with the sign-in URL when no popup could be opened (the snapshot's `loginUrl` has it too). */
157
+ onLoginUrl?: (url: string) => void;
158
+ /** Open the sign-in page in a popup on `signIn()` (opened at once, so the press counts as the user gesture). Default true. */
159
+ popup?: boolean;
160
+ /** Hold a Web Lock named `bl-tailscale:<lockName>` while connected, so two tabs never run the same node. `false` to skip. Default `default`. */
161
+ lockName?: string | false;
162
+ /** How long an auth-key sign-in may take before it is reported as failed (ms). Default 30 000. */
163
+ authKeyTimeoutMs?: number;
164
+ /** The default policy for `fetch` and `matches` (the service-worker router takes its own). */
165
+ policy?: TailscalePolicy;
166
+ env?: TailscaleEnv;
167
+ }
168
+ export interface Tailscale {
169
+ getSnapshot(): TailscaleSnapshot;
170
+ getServerSnapshot(): TailscaleSnapshot;
171
+ subscribe(listener: () => void): () => void;
172
+ /** Starts using it (reads whether a session is saved; restores it when `autoConnect`). Returns the matching release. Providers call this. */
173
+ activate(): () => void;
174
+ /** Restore the saved session, if any. */
175
+ connect(): Promise<void>;
176
+ /** Sign in (interactive or with the auth key). Call it from a press handler so the popup is allowed. */
177
+ signIn(): Promise<void>;
178
+ /** Give up a sign-in in progress. */
179
+ cancel(): void;
180
+ /** Stop the client but keep the session (`connect()` resumes it). */
181
+ disconnect(): Promise<void>;
182
+ /** Log the node out and forget the session. */
183
+ signOut(): Promise<void>;
184
+ /** A request through the tailnet. Rejects with `TailscaleError('not-connected')` unless connected. */
185
+ fetch(request: TailscaleRequest): Promise<TailscaleResponse>;
186
+ /** Whether `url` matches this controller's policy. */
187
+ matches(url: string | URL, method?: string): boolean;
188
+ readonly policy: ResolvedTailscalePolicy;
189
+ /** Stops everything; the controller can be activated again. */
190
+ dispose(): Promise<void>;
191
+ }
192
+ /** https anywhere; http only on loopback (a local Headscale). Anything else (javascript:, data:) is refused. */
193
+ export declare function isSafeLoginUrl(url: string): boolean;
194
+ export declare function createTailscale(options?: TailscaleOptions): Tailscale;
195
+ /** A `Request` (or fetch's arguments) as a `TailscaleRequest`: the body is read into memory. */
196
+ export declare function toTailscaleRequest(input: RequestInfo | URL, init?: RequestInit): Promise<TailscaleRequest>;
197
+ /** A `TailscaleResponse` as a `Response`. Statuses a `Response` cannot carry become 502. */
198
+ export declare function toResponse(res: TailscaleResponse): Response;
199
+ /**
200
+ * A `fetch` that sends what matches the policy through the tailnet and the rest to `fallback` (default: the global
201
+ * fetch). While disconnected, matching requests go to the fallback too, unless the policy says `whenUnavailable: 'error'`.
202
+ */
203
+ export declare function createTailscaleFetch(tailscale: Tailscale, fallback?: typeof fetch): typeof fetch;
204
+ //# sourceMappingURL=tailscale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tailscale.d.ts","sourceRoot":"","sources":["../../src/lib/tailscale.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAgD,KAAK,uBAAuB,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI1I,sEAAsE;AACtE,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,gBAAgB,GAAG,YAAY,GAAG,kBAAkB,GAAG,SAAS,GA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,IAAI,CAAC;IACf,qEAAqE;IACrE,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,+CAA+C;IAC/C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,sGAAsG;IACtG,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC7D,sDAAsD;IACtD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACrD,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,+DAA+D;IAC/D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B;AAMD,gHAAgH;AAChH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAQnD;AAcD,wBAAgB,eAAe,CAAC,OAAO,GAAE,gBAAqB,GAAG,SAAS,CAgYzE;AAID,gGAAgG;AAChG,wBAAsB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAOhH;AAID,4FAA4F;AAC5F,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,GAAG,QAAQ,CAQ3D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,GAAE,OAAO,KAAwC,GAAG,OAAO,KAAK,CAUlI"}
@@ -0,0 +1,443 @@
1
+ import { matchTailscalePolicy as e, resolveTailscalePolicy as t } from "./tailscale-policy.js";
2
+ //#region src/lib/tailscale.ts
3
+ function n(e) {
4
+ if (!e || typeof e != "object") return null;
5
+ let t = e;
6
+ if (t.v !== 1 || typeof t.hostname != "string" || !t.state || typeof t.state != "object") return null;
7
+ let n = {};
8
+ for (let [e, r] of Object.entries(t.state)) {
9
+ if (typeof r != "string") return null;
10
+ n[e] = r;
11
+ }
12
+ return {
13
+ v: 1,
14
+ hostname: t.hostname,
15
+ state: n
16
+ };
17
+ }
18
+ function r() {
19
+ let e = null;
20
+ return {
21
+ load: async () => e,
22
+ save: async (t) => {
23
+ e = {
24
+ ...t,
25
+ state: { ...t.state }
26
+ };
27
+ },
28
+ clear: async () => {
29
+ e = null;
30
+ }
31
+ };
32
+ }
33
+ function i(e, t = "bl-tailscale-session") {
34
+ return {
35
+ load: async () => {
36
+ try {
37
+ return n(JSON.parse(e.getItem(t) ?? "null"));
38
+ } catch {
39
+ return null;
40
+ }
41
+ },
42
+ save: async (n) => e.setItem(t, JSON.stringify(n)),
43
+ clear: async () => e.removeItem(t)
44
+ };
45
+ }
46
+ function a(e, t = "tailscale-session") {
47
+ return {
48
+ load: async () => n(await e.get(t)),
49
+ save: (n) => e.put(t, n),
50
+ clear: () => e.delete(t)
51
+ };
52
+ }
53
+ var o = class extends Error {
54
+ reason;
55
+ constructor(e, t, n) {
56
+ super(t, n), this.name = "TailscaleError", this.reason = e;
57
+ }
58
+ };
59
+ function s(e) {
60
+ if (e instanceof o) switch (e.reason) {
61
+ case "no-client": return "Tailscale is not set up on this page.";
62
+ case "auth-key": return "Couldn't sign in with the auth key. It may have expired or been used already.";
63
+ case "login-url": return "The sign-in page address was not safe to open.";
64
+ case "not-connected": return "Not connected to Tailscale.";
65
+ case "other-tab": return "Tailscale is already running in another tab of this app.";
66
+ case "storage": return "Couldn't read or save the Tailscale session.";
67
+ case "locked-out": return "Tailnet lock: an administrator has to sign this device.";
68
+ case "in-use": return "This Tailscale session belongs to a different user.";
69
+ default: return e.message || "Tailscale stopped unexpectedly.";
70
+ }
71
+ return "Something went wrong with Tailscale. Try again.";
72
+ }
73
+ var c = Object.freeze({
74
+ status: "idle",
75
+ loginUrl: null,
76
+ error: null,
77
+ warning: null,
78
+ selfName: null,
79
+ tailnet: null,
80
+ addresses: [],
81
+ peers: [],
82
+ hasSession: !1
83
+ });
84
+ function l(e) {
85
+ try {
86
+ let t = new URL(e);
87
+ return t.protocol === "https:" || t.protocol === "http:" && (t.hostname === "localhost" || t.hostname === "127.0.0.1" || t.hostname === "[::1]");
88
+ } catch {
89
+ return !1;
90
+ }
91
+ }
92
+ function u() {
93
+ let e = /* @__PURE__ */ new Uint8Array(6);
94
+ return globalThis.crypto.getRandomValues(e), `bl-${Array.from(e, (e) => "abcdefghijklmnopqrstuvwxyz0123456789"[e % 36]).join("")}`;
95
+ }
96
+ function d(e) {
97
+ if (!e) return null;
98
+ let t = e.replace(/\.$/, "").split(".");
99
+ return t.length > 2 ? t.slice(1).join(".") : null;
100
+ }
101
+ function f(n = {}) {
102
+ let i = t(n.policy), a = n.auth ?? { mode: "interactive" }, s = n.persistence ?? r(), f = n.lockName === !1 ? null : `bl-tailscale:${n.lockName ?? "default"}`, p = /* @__PURE__ */ new Set(), m = c, h = null, g = null, _ = 0, v = "NoState", y = !1, b = null, x = null, S = null, C = null, w = null, T = null, E = null, D = null, O = 0, k = null, A = () => ({
103
+ open: n.env?.open === void 0 ? typeof window < "u" ? (e, t, n) => window.open(e, t, n) : null : n.env.open,
104
+ locks: n.env?.locks === void 0 ? typeof navigator < "u" && navigator.locks ? navigator.locks : null : n.env.locks
105
+ });
106
+ function j(e) {
107
+ let t = {
108
+ ...m,
109
+ ...e
110
+ };
111
+ Object.keys(e).every((e) => Object.is(t[e], m[e])) || (m = t, p.forEach((e) => e()));
112
+ }
113
+ function M(e) {
114
+ L(), V(), y = !1, j({
115
+ status: "error",
116
+ error: e,
117
+ loginUrl: null
118
+ });
119
+ }
120
+ function N() {
121
+ return S ||= s.load().then((e) => {
122
+ x = e, j({ hasSession: e !== null });
123
+ }, (e) => {
124
+ throw S = null, new o("storage", "Could not read the saved Tailscale session.", { cause: e });
125
+ }), S;
126
+ }
127
+ function P(e, t) {
128
+ w = e, !C && (C = setTimeout(() => void F(t), 250));
129
+ }
130
+ async function F(e) {
131
+ C && clearTimeout(C), C = null;
132
+ let t = w;
133
+ if (w = null, t) {
134
+ x = {
135
+ v: 1,
136
+ hostname: e,
137
+ state: t
138
+ };
139
+ try {
140
+ await s.save(x), j({
141
+ hasSession: !0,
142
+ warning: null
143
+ });
144
+ } catch {
145
+ j({ warning: "The Tailscale session couldn't be saved; you will be asked to sign in again next time." });
146
+ }
147
+ }
148
+ }
149
+ function I() {
150
+ if (n.popup === !1) return;
151
+ let e = A().open;
152
+ if (!(!e || b && !b.closed)) {
153
+ try {
154
+ b = e("", "bl-tailscale-login", "popup,width=520,height=720");
155
+ } catch {
156
+ b = null;
157
+ }
158
+ if (b) try {
159
+ let e = b.document;
160
+ e && (e.title = "Tailscale", e.body && (e.body.textContent = "Waiting for Tailscale…"));
161
+ } catch {}
162
+ }
163
+ }
164
+ function L() {
165
+ let e = b;
166
+ b = null;
167
+ try {
168
+ e && !e.closed && e.close();
169
+ } catch {}
170
+ }
171
+ function R(e) {
172
+ if (e === null) return j({ loginUrl: null });
173
+ if (!l(e)) return M(new o("login-url", `Refused to open the sign-in URL ${JSON.stringify(e.slice(0, 80))}.`));
174
+ j({ loginUrl: e });
175
+ let t = b;
176
+ if (t && !t.closed) try {
177
+ t.opener = null, t.location.replace(e);
178
+ return;
179
+ } catch {
180
+ b = null;
181
+ }
182
+ n.onLoginUrl?.(e);
183
+ }
184
+ function z() {
185
+ switch (v) {
186
+ case "Running": return "connected";
187
+ case "Starting": return y ? "signing-in" : "starting";
188
+ case "NeedsMachineAuth": return "needs-approval";
189
+ case "NeedsLogin":
190
+ case "Stopped":
191
+ case "NoState": return y ? "signing-in" : g || h ? "needs-login" : "idle";
192
+ default: return "error";
193
+ }
194
+ }
195
+ function B(e, t) {
196
+ if (e === _) {
197
+ if (t.error) {
198
+ W(!1), M(new o("client", t.error));
199
+ return;
200
+ }
201
+ if (t.netMap !== void 0) {
202
+ let e = t.netMap;
203
+ if (e?.lockedOut) {
204
+ M(new o("locked-out", "Tailnet lock: this device is not signed."));
205
+ return;
206
+ }
207
+ let n = e?.self.name.replace(/\.$/, "") || null;
208
+ j({
209
+ selfName: n,
210
+ tailnet: d(n),
211
+ addresses: e?.self.addresses ?? [],
212
+ peers: (e?.peers ?? []).map((e) => ({
213
+ name: e.name.replace(/\.$/, ""),
214
+ addresses: e.addresses,
215
+ online: e.online === !0
216
+ }))
217
+ });
218
+ }
219
+ if (t.loginUrl !== void 0 && R(t.loginUrl), t.state) {
220
+ if (v = t.state, v === "InUseOtherUser") return M(new o("in-use", "The session belongs to a different user."));
221
+ v === "Running" && (y = !1, V(), L(), j({ loginUrl: null }));
222
+ }
223
+ (m.status !== "error" || t.state === "Running") && j({
224
+ status: z(),
225
+ ...t.state === "Running" ? { error: null } : {}
226
+ });
227
+ }
228
+ }
229
+ function V() {
230
+ D && clearTimeout(D), D = null;
231
+ }
232
+ async function H() {
233
+ if (!f || T) return !0;
234
+ let e = A().locks;
235
+ return !e || new Promise((t) => {
236
+ e.request(f, { ifAvailable: !0 }, (e) => {
237
+ if (!e) {
238
+ t(!1);
239
+ return;
240
+ }
241
+ return t(!0), new Promise((e) => {
242
+ T = e;
243
+ });
244
+ }).catch(() => t(!0));
245
+ });
246
+ }
247
+ async function U(e) {
248
+ if (h) return h;
249
+ if (g) return g;
250
+ let t = ++_;
251
+ g = (async () => {
252
+ if (j({
253
+ status: "loading",
254
+ error: null
255
+ }), !await H()) throw new o("other-tab", "Tailscale is running in another tab.");
256
+ await N();
257
+ let r = n.client;
258
+ if (!r) throw new o("no-client", "No Tailscale client: pass `client` to createTailscale (for example createTailscaleConnectClient).");
259
+ let i;
260
+ try {
261
+ i = typeof r == "function" ? await r() : r;
262
+ } catch (e) {
263
+ throw new o("client", `The Tailscale client failed to load: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
264
+ }
265
+ if (t !== _) throw i.dispose(), new o("client", "Stopped while starting.");
266
+ let a = x?.hostname ?? n.hostname ?? u();
267
+ v = "NoState";
268
+ try {
269
+ await i.start({
270
+ hostname: a,
271
+ controlUrl: n.controlUrl,
272
+ authKey: e,
273
+ state: x?.state ?? null,
274
+ onState: (e) => {
275
+ t === _ && P(e, a);
276
+ },
277
+ onEvent: (e) => B(t, e)
278
+ });
279
+ } catch (e) {
280
+ throw i.dispose(), new o("client", `The Tailscale client failed to start: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
281
+ }
282
+ if (t !== _) throw i.dispose(), new o("client", "Stopped while starting.");
283
+ return h = i, j({ status: z() }), i;
284
+ })();
285
+ try {
286
+ return await g;
287
+ } catch (e) {
288
+ throw t === _ && (T?.(), T = null), e;
289
+ } finally {
290
+ t === _ && (g = null);
291
+ }
292
+ }
293
+ async function W(e) {
294
+ _++, V(), E?.abort(), E = null;
295
+ let t = h;
296
+ h = null, g = null, v = "NoState", y = !1, w && x && await F(x.hostname), e || (T?.(), T = null), t && await t.dispose();
297
+ }
298
+ let G = () => j({
299
+ status: "idle",
300
+ loginUrl: null,
301
+ selfName: null,
302
+ tailnet: null,
303
+ addresses: [],
304
+ peers: []
305
+ }), K = {
306
+ policy: i,
307
+ getSnapshot: () => m,
308
+ getServerSnapshot: () => c,
309
+ subscribe(e) {
310
+ return p.add(e), () => p.delete(e);
311
+ },
312
+ activate() {
313
+ O++, k && clearTimeout(k), k = null, N().then(() => {
314
+ O > 0 && x && n.autoConnect !== !1 && m.status === "idle" && K.connect();
315
+ }, (e) => j({ warning: e instanceof Error ? e.message : String(e) }));
316
+ let e = !1;
317
+ return () => {
318
+ e || (e = !0, O--, O === 0 && (k = setTimeout(() => {
319
+ k = null, O === 0 && K.dispose();
320
+ }, 0)));
321
+ };
322
+ },
323
+ async connect() {
324
+ if (!(h || g)) try {
325
+ if (await N(), !x) return;
326
+ await U();
327
+ } catch (e) {
328
+ M(e instanceof o ? e : new o("client", String(e)));
329
+ }
330
+ },
331
+ async signIn() {
332
+ if (m.status === "connected") return;
333
+ let e = a.mode === "interactive";
334
+ e && I(), y = !0, j({
335
+ status: "signing-in",
336
+ error: null,
337
+ loginUrl: null
338
+ });
339
+ try {
340
+ let t;
341
+ if (a.mode === "auth-key") {
342
+ h && await W(!0), E = new AbortController();
343
+ try {
344
+ t = typeof a.authKey == "function" ? await a.authKey(E.signal) : a.authKey;
345
+ } catch (e) {
346
+ throw new o("auth-key", `Could not get an auth key: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
347
+ }
348
+ if (!t) throw new o("auth-key", "The auth key is empty.");
349
+ let e = _;
350
+ V(), D = setTimeout(() => {
351
+ e <= _ && m.status !== "connected" && y && (W(!1), M(new o("auth-key", "Signing in with the auth key did not finish in time.")));
352
+ }, n.authKeyTimeoutMs ?? 3e4);
353
+ }
354
+ y = !0;
355
+ let r = await U(t);
356
+ j({ status: z() }), e && v !== "Running" && await r.login();
357
+ } catch (e) {
358
+ if (!y && !(e instanceof o)) return;
359
+ M(e instanceof o ? e : new o("client", e instanceof Error ? e.message : String(e), { cause: e }));
360
+ }
361
+ },
362
+ cancel() {
363
+ (m.status === "signing-in" || m.status === "loading") && (y = !1, V(), E?.abort(), L(), j({
364
+ loginUrl: null,
365
+ status: h ? z() : "idle"
366
+ }));
367
+ },
368
+ async disconnect() {
369
+ L(), await W(!1), G(), j({ error: null });
370
+ },
371
+ async signOut() {
372
+ L();
373
+ let e = h;
374
+ try {
375
+ e && await e.logout();
376
+ } catch {}
377
+ w = null, await W(!1), x = null;
378
+ try {
379
+ await s.clear();
380
+ } catch {
381
+ j({ warning: "The saved session couldn't be deleted." });
382
+ }
383
+ G(), j({
384
+ hasSession: !1,
385
+ error: null
386
+ });
387
+ },
388
+ async fetch(e) {
389
+ if (!h || v !== "Running") throw new o("not-connected", "Not connected to Tailscale.");
390
+ return h.fetch(e);
391
+ },
392
+ matches(t, n = "GET") {
393
+ return e(t, n, i, typeof location < "u" ? location.origin : void 0).route;
394
+ },
395
+ async dispose() {
396
+ L(), await W(!1), G();
397
+ }
398
+ };
399
+ return K;
400
+ }
401
+ async function p(e, t) {
402
+ let n = new Request(e, t), r = [];
403
+ n.headers.forEach((e, t) => r.push([t, e]));
404
+ let i = n.method.toUpperCase(), a = i === "GET" || i === "HEAD" ? null : new Uint8Array(await n.arrayBuffer());
405
+ return {
406
+ url: n.url,
407
+ method: i,
408
+ headers: r,
409
+ body: a && a.byteLength ? a : null,
410
+ redirect: n.redirect,
411
+ signal: t?.signal ?? void 0
412
+ };
413
+ }
414
+ var m = /* @__PURE__ */ new Set([
415
+ 101,
416
+ 103,
417
+ 204,
418
+ 205,
419
+ 304
420
+ ]);
421
+ function h(e) {
422
+ let t = e.status >= 200 && e.status <= 599 ? e.status : 502, n = new Headers();
423
+ for (let [t, r] of e.headers) try {
424
+ n.append(t, r);
425
+ } catch {}
426
+ let r = m.has(t) ? null : e.body;
427
+ return new Response(r, {
428
+ status: t,
429
+ statusText: e.statusText ?? "",
430
+ headers: n
431
+ });
432
+ }
433
+ function g(e, t = (...e) => globalThis.fetch(...e)) {
434
+ return async (n, r) => {
435
+ let i = new Request(n, r);
436
+ return e.matches(i.url, i.method) ? e.getSnapshot().status === "connected" ? h(await e.fetch(await p(i))) : e.policy.whenUnavailable === "error" ? new Response("Tailscale is not connected.", {
437
+ status: 503,
438
+ headers: { "content-type": "text/plain" }
439
+ }) : t(n, r) : t(n, r);
440
+ };
441
+ }
442
+ //#endregion
443
+ export { o as TailscaleError, f as createTailscale, g as createTailscaleFetch, l as isSafeLoginUrl, r as memoryTailscalePersistence, s as tailscaleErrorMessage, h as toResponse, p as toTailscaleRequest, a as vaultTailscalePersistence, i as webStorageTailscalePersistence };
@@ -0,0 +1,34 @@
1
+ import { RefObject } from 'react';
2
+ import { AnimationPlaybackControls } from 'framer-motion';
3
+ /** The elements of a screen's header the morph reads. */
4
+ export interface TitleParts {
5
+ /** The screen's root; `data-scrolled` says its large title has gone under the bar. */
6
+ el?: HTMLElement | null;
7
+ large?: HTMLElement | null;
8
+ inline?: HTMLElement | null;
9
+ back?: HTMLElement | null;
10
+ }
11
+ interface Flight {
12
+ set: (t: number) => void;
13
+ done: () => void;
14
+ }
15
+ /** A flight in progress: `run` is its spring once released. */
16
+ export interface ActiveFlight {
17
+ f: Flight;
18
+ run?: AnimationPlaybackControls;
19
+ }
20
+ /** The title a screen is showing right now: its large title until it scrolls under the bar, else the inline one. */
21
+ export declare function shownTitle(r: TitleParts | undefined): HTMLElement | null;
22
+ /** A screen's back label, when it shows the previous title (not "Back", not nothing). */
23
+ export declare function backLabel(r: TitleParts | undefined): HTMLElement | null;
24
+ /** Owns the stack's one flight at a time: starting another (or unmounting) ends the one in progress, so a push or
25
+ * pop that lands mid-flight simply takes over. `cont` is the element the flight layer is drawn in. */
26
+ export declare function useTitleFlight(cont: RefObject<HTMLElement | null>): {
27
+ fly: (pick: () => [HTMLElement | null, HTMLElement | null, HTMLElement | null | undefined]) => void;
28
+ scrub: (from: HTMLElement | null, to: HTMLElement | null, toScreen: HTMLElement | null | undefined) => ActiveFlight | null;
29
+ release: (c: ActiveFlight | null | undefined, p: number, to: 0 | 1) => void;
30
+ end: () => void;
31
+ isCurrent: (c: ActiveFlight | null | undefined) => c is ActiveFlight;
32
+ };
33
+ export {};
34
+ //# sourceMappingURL=title-flight.d.ts.map