@spooky-sync/client-solid2 0.0.1-canary.200 → 0.0.1-canary.201

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.
@@ -0,0 +1,108 @@
1
+ import { createSignal, createEffect, type Accessor } from 'solid-js';
2
+ import type { SchemaStructure, BucketNames } from '@spooky-sync/query-builder';
3
+ import type { SyncedDb } from '../index';
4
+ import { useDb } from './context';
5
+ import {
6
+ useDownloadFile,
7
+ type UseDownloadFileOptions,
8
+ type UseDownloadFileResult,
9
+ } from './use-download-file';
10
+ import { useBlurhash } from './use-blurhash';
11
+
12
+ export interface UseBucketImageOptions extends UseDownloadFileOptions {
13
+ /**
14
+ * Also resolve the image's blurhash sidecar (see `Sp00kyConfig.blurhash`).
15
+ * Default `true`; the read is registered before the image bytes so the tiny
16
+ * sidecar tends to land first on the serialized remote chain.
17
+ */
18
+ blurhash?: boolean;
19
+ }
20
+
21
+ export interface UseBucketImageResult extends UseDownloadFileResult {
22
+ /** Blurhash for the same path, or null (off, missing, still loading). */
23
+ blurhash: Accessor<string | null>;
24
+ /** True once the current `url()` has been decoded and is safe to paint. */
25
+ ready: Accessor<boolean>;
26
+ /**
27
+ * Ref callback for the `<img>` rendering `url()`: flips `ready` when the
28
+ * bitmap is decoded (resolves on failure too, so a broken blob degrades to
29
+ * paint-on-load instead of hiding the image forever). Re-arms itself when
30
+ * the url changes.
31
+ */
32
+ gate: (img: HTMLImageElement) => void;
33
+ }
34
+
35
+ /**
36
+ * Everything needed to render a bucket image without a pop-in: the refcounted
37
+ * object URL, the blurhash placeholder, and a decode gate so the real bitmap
38
+ * is only revealed once it can paint in full. `BucketImage` wraps this into a
39
+ * drop-in component; use the hook for custom markup.
40
+ */
41
+ export function useBucketImage<S extends SchemaStructure>(
42
+ bucketName: BucketNames<S>,
43
+ path: Accessor<string | null | undefined>,
44
+ options?: UseBucketImageOptions
45
+ ): UseBucketImageResult;
46
+ export function useBucketImage<S extends SchemaStructure>(
47
+ db: SyncedDb<S>,
48
+ bucketName: BucketNames<S>,
49
+ path: Accessor<string | null | undefined>,
50
+ options?: UseBucketImageOptions
51
+ ): UseBucketImageResult;
52
+ export function useBucketImage<S extends SchemaStructure>(
53
+ dbOrBucketName: SyncedDb<S> | BucketNames<S>,
54
+ bucketNameOrPath?: BucketNames<S> | Accessor<string | null | undefined>,
55
+ pathOrOptions?: Accessor<string | null | undefined> | UseBucketImageOptions,
56
+ maybeOptions?: UseBucketImageOptions
57
+ ): UseBucketImageResult {
58
+ let db: SyncedDb<S>;
59
+ let bucketName: BucketNames<S>;
60
+ let path: Accessor<string | null | undefined>;
61
+ let options: UseBucketImageOptions;
62
+
63
+ if (typeof dbOrBucketName === 'string') {
64
+ db = useDb<S>();
65
+ bucketName = dbOrBucketName as BucketNames<S>;
66
+ path = bucketNameOrPath as Accessor<string | null | undefined>;
67
+ options = (pathOrOptions as UseBucketImageOptions) ?? {};
68
+ } else {
69
+ db = dbOrBucketName as SyncedDb<S>;
70
+ bucketName = bucketNameOrPath as BucketNames<S>;
71
+ path = pathOrOptions as Accessor<string | null | undefined>;
72
+ options = maybeOptions ?? {};
73
+ }
74
+
75
+ // Registered BEFORE the download so the sidecar read enters the serialized
76
+ // remote queue first: the placeholder should never wait behind the bytes it
77
+ // is standing in for.
78
+ const wantHash = options.blurhash !== false;
79
+ const { hash } = useBlurhash(db, bucketName, () => (wantHash ? path() : null));
80
+
81
+ const file = useDownloadFile(db, bucketName, path, options);
82
+
83
+ // Written from the decode continuation (and from the url effect's apply
84
+ // phase), outside any tracking scope.
85
+ const [ready, setReady] = createSignal(false, { ownedWrite: true });
86
+ // A new url (path change, refetch) means a new undecoded bitmap.
87
+ createEffect(
88
+ file.url,
89
+ () => {
90
+ setReady(false);
91
+ },
92
+ { defer: true }
93
+ );
94
+
95
+ const gate = (img: HTMLImageElement) => {
96
+ const done = () => setReady(true);
97
+ if (typeof img.decode === 'function') {
98
+ img.decode().then(done, done);
99
+ } else if (img.complete) {
100
+ done();
101
+ } else {
102
+ img.onload = done;
103
+ img.onerror = done;
104
+ }
105
+ };
106
+
107
+ return { ...file, blurhash: hash, ready, gate };
108
+ }
package/tsdown.config.ts CHANGED
@@ -8,6 +8,8 @@ export default defineConfig({
8
8
  'surrealdb',
9
9
  '@surrealdb/wasm',
10
10
  'solid-js',
11
+ '@solidjs/signals',
12
+ '@solidjs/web',
11
13
  '@spooky-sync/core',
12
14
  '@spooky-sync/query-builder',
13
15
  ],
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 Khadim Fall
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.