jazz-vue 0.9.23 → 0.10.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/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +20 -0
- package/dist/auth/useDemoAuth.d.ts +5 -55
- package/dist/auth/useIsAuthenticated.d.ts +1 -0
- package/dist/auth/usePasskeyAuth.d.ts +18 -0
- package/dist/auth/usePassphraseAuth.d.ts +18 -0
- package/dist/composables.d.ts +8 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.js +367 -243
- package/dist/index.js.map +1 -0
- package/dist/provider-CkA-a4Og.js +86 -0
- package/dist/provider-CkA-a4Og.js.map +1 -0
- package/dist/provider.d.ts +39 -13
- package/dist/testing.d.ts +13 -3
- package/dist/testing.js +29 -17
- package/dist/testing.js.map +1 -0
- package/dist/tests/fixtures.d.ts +1 -0
- package/dist/tests/testUtils.d.ts +3 -2
- package/dist/tests/usePassphraseAuth.test.d.ts +1 -0
- package/package.json +7 -6
- package/src/auth/DemoAuthBasicUI.vue +115 -113
- package/src/auth/useDemoAuth.ts +31 -71
- package/src/auth/useIsAuthenticated.ts +18 -0
- package/src/auth/usePasskeyAuth.ts +46 -0
- package/src/auth/usePassphraseAuth.ts +56 -0
- package/src/composables.ts +36 -22
- package/src/index.ts +2 -0
- package/src/provider.ts +55 -56
- package/src/testing.ts +16 -5
- package/src/tests/fixtures.ts +2050 -0
- package/src/tests/testUtils.ts +8 -1
- package/src/tests/useCoState.test.ts +33 -4
- package/src/tests/usePassphraseAuth.test.ts +95 -0
- package/vite.config.ts +2 -0
- package/dist/provider-BZnz6FpX.js +0 -69
package/dist/index.js
CHANGED
@@ -1,316 +1,440 @@
|
|
1
|
-
import { consumeInviteLinkFromWindowLocation
|
2
|
-
import { createInviteLink
|
3
|
-
import { subscribeToCoValue
|
4
|
-
import { ref
|
5
|
-
import { J as
|
6
|
-
import {
|
7
|
-
const
|
8
|
-
function
|
9
|
-
const
|
10
|
-
|
11
|
-
);
|
12
|
-
if (!u)
|
1
|
+
import { consumeInviteLinkFromWindowLocation, BrowserPasskeyAuth } from "jazz-browser";
|
2
|
+
import { createInviteLink, parseInviteLink } from "jazz-browser";
|
3
|
+
import { subscribeToCoValue, DemoAuth, PassphraseAuth } from "jazz-tools";
|
4
|
+
import { ref, inject, shallowRef, watch, unref, toRaw, onUnmounted, computed, onMounted, watchEffect, defineComponent, renderSlot, openBlock, createElementBlock, createElementVNode, normalizeStyle, toDisplayString, withDirectives, vModelText, Fragment, renderList, createCommentVNode, toRef } from "vue";
|
5
|
+
import { J as JazzContextSymbol, a as JazzAuthContextSymbol } from "./provider-CkA-a4Og.js";
|
6
|
+
import { b } from "./provider-CkA-a4Og.js";
|
7
|
+
const logoutHandler = ref();
|
8
|
+
function useJazzContext() {
|
9
|
+
const context = inject(JazzContextSymbol);
|
10
|
+
if (!(context == null ? void 0 : context.value)) {
|
13
11
|
throw new Error("useJazzContext must be used within a JazzProvider");
|
14
|
-
|
12
|
+
}
|
13
|
+
return context;
|
14
|
+
}
|
15
|
+
function useAuthSecretStorage() {
|
16
|
+
const context = inject(JazzAuthContextSymbol);
|
17
|
+
if (!context) {
|
18
|
+
throw new Error("useAuthSecretStorage must be used within a JazzProvider");
|
19
|
+
}
|
20
|
+
return context;
|
15
21
|
}
|
16
|
-
function
|
17
|
-
function
|
18
|
-
const
|
19
|
-
if (!
|
22
|
+
function createUseAccountComposables() {
|
23
|
+
function useAccount2(depth) {
|
24
|
+
const context = useJazzContext();
|
25
|
+
if (!context.value) {
|
20
26
|
throw new Error("useAccount must be used within a JazzProvider");
|
21
|
-
|
27
|
+
}
|
28
|
+
if (!("me" in context.value)) {
|
22
29
|
throw new Error(
|
23
30
|
"useAccount can't be used in a JazzProvider with auth === 'guest' - consider using useAccountOrGuest()"
|
24
31
|
);
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
32
|
+
}
|
33
|
+
const contextMe = context.value.me;
|
34
|
+
const me = useCoState(
|
35
|
+
contextMe.constructor,
|
36
|
+
contextMe.id,
|
37
|
+
depth
|
29
38
|
);
|
30
39
|
return {
|
31
|
-
me:
|
32
|
-
const
|
33
|
-
return
|
40
|
+
me: computed(() => {
|
41
|
+
const value = depth === void 0 ? me.value || toRaw(context.value.me) : me.value;
|
42
|
+
return value ? toRaw(value) : value;
|
34
43
|
}),
|
35
|
-
logOut:
|
44
|
+
logOut: context.value.logOut
|
36
45
|
};
|
37
46
|
}
|
38
|
-
function
|
39
|
-
var
|
40
|
-
const
|
41
|
-
if (!
|
47
|
+
function useAccountOrGuest2(depth) {
|
48
|
+
var _a, _b;
|
49
|
+
const context = useJazzContext();
|
50
|
+
if (!context.value) {
|
42
51
|
throw new Error("useAccountOrGuest must be used within a JazzProvider");
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
(s = o.value) == null ? void 0 : s.constructor,
|
47
|
-
(a = o.value) == null ? void 0 : a.id,
|
48
|
-
r
|
52
|
+
}
|
53
|
+
const contextMe = computed(
|
54
|
+
() => "me" in context.value ? context.value.me : void 0
|
49
55
|
);
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
const me = useCoState(
|
57
|
+
(_a = contextMe.value) == null ? void 0 : _a.constructor,
|
58
|
+
(_b = contextMe.value) == null ? void 0 : _b.id,
|
59
|
+
depth
|
60
|
+
);
|
61
|
+
if ("me" in context.value) {
|
62
|
+
return {
|
63
|
+
me: computed(
|
64
|
+
() => depth === void 0 ? me.value || toRaw(context.value.me) : me.value
|
65
|
+
)
|
66
|
+
};
|
67
|
+
} else {
|
68
|
+
return {
|
69
|
+
me: computed(() => toRaw(context.value.guest))
|
70
|
+
};
|
71
|
+
}
|
57
72
|
}
|
58
73
|
return {
|
59
|
-
useAccount:
|
60
|
-
useAccountOrGuest:
|
74
|
+
useAccount: useAccount2,
|
75
|
+
useAccountOrGuest: useAccountOrGuest2
|
61
76
|
};
|
62
77
|
}
|
63
|
-
const { useAccount
|
64
|
-
function
|
65
|
-
const
|
66
|
-
|
78
|
+
const { useAccount, useAccountOrGuest } = createUseAccountComposables();
|
79
|
+
function useCoState(Schema, id, depth = []) {
|
80
|
+
const state = shallowRef(void 0);
|
81
|
+
const context = useJazzContext();
|
82
|
+
if (!context.value) {
|
67
83
|
throw new Error("useCoState must be used within a JazzProvider");
|
68
|
-
|
69
|
-
|
70
|
-
|
84
|
+
}
|
85
|
+
let unsubscribe;
|
86
|
+
watch(
|
87
|
+
[() => unref(id), () => context, () => Schema, () => depth],
|
71
88
|
() => {
|
72
|
-
|
73
|
-
const
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
89
|
+
if (unsubscribe) unsubscribe();
|
90
|
+
const idValue = unref(id);
|
91
|
+
if (!idValue) return;
|
92
|
+
unsubscribe = subscribeToCoValue(
|
93
|
+
Schema,
|
94
|
+
idValue,
|
95
|
+
"me" in context.value ? toRaw(context.value.me) : toRaw(context.value.guest),
|
96
|
+
depth,
|
97
|
+
(value) => {
|
98
|
+
state.value = value;
|
99
|
+
},
|
100
|
+
() => {
|
101
|
+
state.value = null;
|
81
102
|
},
|
82
|
-
|
83
|
-
|
84
|
-
));
|
103
|
+
true
|
104
|
+
);
|
85
105
|
},
|
86
|
-
{ deep:
|
87
|
-
)
|
88
|
-
|
89
|
-
|
106
|
+
{ deep: true, immediate: true }
|
107
|
+
);
|
108
|
+
onUnmounted(() => {
|
109
|
+
if (unsubscribe) unsubscribe();
|
110
|
+
});
|
111
|
+
const computedState = computed(() => state.value);
|
112
|
+
return computedState;
|
90
113
|
}
|
91
|
-
function
|
92
|
-
invitedObjectSchema
|
93
|
-
onAccept
|
94
|
-
forValueHint
|
114
|
+
function useAcceptInvite({
|
115
|
+
invitedObjectSchema,
|
116
|
+
onAccept,
|
117
|
+
forValueHint
|
95
118
|
}) {
|
96
|
-
const
|
97
|
-
if (!
|
119
|
+
const context = useJazzContext();
|
120
|
+
if (!context.value) {
|
98
121
|
throw new Error("useAcceptInvite must be used within a JazzProvider");
|
99
|
-
|
122
|
+
}
|
123
|
+
if (!("me" in context.value)) {
|
100
124
|
throw new Error(
|
101
125
|
"useAcceptInvite can't be used in a JazzProvider with auth === 'guest'."
|
102
126
|
);
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
127
|
+
}
|
128
|
+
const runInviteAcceptance = () => {
|
129
|
+
const result = consumeInviteLinkFromWindowLocation({
|
130
|
+
as: toRaw(context.value.me),
|
131
|
+
invitedObjectSchema,
|
132
|
+
forValueHint
|
133
|
+
});
|
134
|
+
result.then((res) => res && onAccept(res.valueID)).catch((e) => {
|
135
|
+
console.error("Failed to accept invite", e);
|
110
136
|
});
|
111
137
|
};
|
112
|
-
|
113
|
-
|
114
|
-
})
|
115
|
-
|
116
|
-
(
|
117
|
-
|
138
|
+
onMounted(() => {
|
139
|
+
runInviteAcceptance();
|
140
|
+
});
|
141
|
+
watch(
|
142
|
+
() => onAccept,
|
143
|
+
(newOnAccept, oldOnAccept) => {
|
144
|
+
if (newOnAccept !== oldOnAccept) {
|
145
|
+
runInviteAcceptance();
|
146
|
+
}
|
118
147
|
}
|
119
148
|
);
|
120
149
|
}
|
121
|
-
function
|
122
|
-
|
123
|
-
|
124
|
-
const
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
},
|
142
|
-
u
|
143
|
-
)
|
150
|
+
function useIsAuthenticated() {
|
151
|
+
const authSecretStorage = useAuthSecretStorage();
|
152
|
+
const isAuthenticated = ref(authSecretStorage.isAuthenticated);
|
153
|
+
const handleUpdate = () => {
|
154
|
+
isAuthenticated.value = authSecretStorage.isAuthenticated;
|
155
|
+
};
|
156
|
+
onMounted(() => {
|
157
|
+
const cleanup = authSecretStorage.onUpdate(handleUpdate);
|
158
|
+
onUnmounted(cleanup);
|
159
|
+
});
|
160
|
+
return isAuthenticated;
|
161
|
+
}
|
162
|
+
function useDemoAuth() {
|
163
|
+
const context = useJazzContext();
|
164
|
+
const authSecretStorage = useAuthSecretStorage();
|
165
|
+
if ("guest" in context.value) {
|
166
|
+
throw new Error("Demo auth is not supported in guest mode");
|
167
|
+
}
|
168
|
+
const authMethod = computed(
|
169
|
+
() => new DemoAuth(context.value.authenticate, authSecretStorage)
|
144
170
|
);
|
145
|
-
|
146
|
-
|
147
|
-
|
171
|
+
const existingUsers = ref([]);
|
172
|
+
const isAuthenticated = useIsAuthenticated();
|
173
|
+
watch(authMethod, () => {
|
174
|
+
authMethod.value.getExistingUsers().then((users) => {
|
175
|
+
existingUsers.value = users;
|
176
|
+
});
|
177
|
+
});
|
178
|
+
return computed(() => ({
|
179
|
+
state: isAuthenticated.value ? "signedIn" : "anonymous",
|
180
|
+
logIn(username) {
|
181
|
+
authMethod.value.logIn(username);
|
182
|
+
},
|
183
|
+
signUp(username) {
|
184
|
+
authMethod.value.signUp(username);
|
185
|
+
},
|
186
|
+
existingUsers: existingUsers.value
|
187
|
+
}));
|
188
|
+
}
|
189
|
+
function usePassphraseAuth({
|
190
|
+
wordlist
|
191
|
+
}) {
|
192
|
+
const context = useJazzContext();
|
193
|
+
const authSecretStorage = useAuthSecretStorage();
|
194
|
+
const isAuthenticated = useIsAuthenticated();
|
195
|
+
if ("guest" in context.value) {
|
196
|
+
throw new Error("Passphrase auth is not supported in guest mode");
|
197
|
+
}
|
198
|
+
const authMethod = computed(() => {
|
199
|
+
return new PassphraseAuth(
|
200
|
+
context.value.node.crypto,
|
201
|
+
context.value.authenticate,
|
202
|
+
authSecretStorage,
|
203
|
+
wordlist
|
204
|
+
);
|
205
|
+
});
|
206
|
+
const passphrase = ref(authMethod.value.passphrase);
|
207
|
+
watchEffect((onCleanup) => {
|
208
|
+
authMethod.value.loadCurrentAccountPassphrase();
|
209
|
+
const unsubscribe = authMethod.value.subscribe(() => {
|
210
|
+
passphrase.value = authMethod.value.passphrase;
|
211
|
+
});
|
212
|
+
onCleanup(unsubscribe);
|
213
|
+
});
|
214
|
+
return computed(() => ({
|
215
|
+
state: isAuthenticated.value ? "signedIn" : "anonymous",
|
216
|
+
logIn: authMethod.value.logIn,
|
217
|
+
signUp: authMethod.value.signUp,
|
218
|
+
passphrase: passphrase.value
|
219
|
+
}));
|
220
|
+
}
|
221
|
+
function usePasskeyAuth({
|
222
|
+
appName,
|
223
|
+
appHostname
|
224
|
+
}) {
|
225
|
+
const context = useJazzContext();
|
226
|
+
const authSecretStorage = useAuthSecretStorage();
|
227
|
+
const isAuthenticated = useIsAuthenticated();
|
228
|
+
if ("guest" in context.value) {
|
229
|
+
throw new Error("Passkey auth is not supported in guest mode");
|
230
|
+
}
|
231
|
+
const authMethod = computed(() => {
|
232
|
+
return new BrowserPasskeyAuth(
|
233
|
+
context.value.node.crypto,
|
234
|
+
context.value.authenticate,
|
235
|
+
authSecretStorage,
|
236
|
+
appName,
|
237
|
+
appHostname
|
238
|
+
);
|
239
|
+
});
|
240
|
+
return computed(() => ({
|
241
|
+
state: isAuthenticated.value ? "signedIn" : "anonymous",
|
242
|
+
logIn: authMethod.value.logIn,
|
243
|
+
signUp: authMethod.value.signUp
|
244
|
+
}));
|
148
245
|
}
|
149
|
-
const
|
246
|
+
const _hoisted_1 = {
|
247
|
+
key: 1,
|
248
|
+
style: {
|
249
|
+
minHeight: "100%",
|
250
|
+
display: "flex",
|
251
|
+
flexDirection: "column",
|
252
|
+
justifyContent: "center",
|
253
|
+
width: "18rem",
|
254
|
+
maxWidth: "calc(100vw - 2rem)",
|
255
|
+
gap: "2rem",
|
256
|
+
margin: "0 auto"
|
257
|
+
}
|
258
|
+
};
|
259
|
+
const _hoisted_2 = {
|
150
260
|
key: 0,
|
151
|
-
style: {
|
152
|
-
|
261
|
+
style: {
|
262
|
+
display: "flex",
|
263
|
+
flexDirection: "column",
|
264
|
+
gap: "0.5rem"
|
265
|
+
}
|
266
|
+
};
|
267
|
+
const _hoisted_3 = ["onClick", "aria-label"];
|
268
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
153
269
|
__name: "DemoAuthBasicUI",
|
154
270
|
props: {
|
155
|
-
appName: {}
|
156
|
-
state: {}
|
271
|
+
appName: {}
|
157
272
|
},
|
158
|
-
setup(
|
159
|
-
const
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
justifyContent: "center",
|
166
|
-
alignItems: "center",
|
167
|
-
width: "100%",
|
168
|
-
padding: "1rem",
|
169
|
-
maxWidth: "100vw",
|
170
|
-
gap: "2rem",
|
171
|
-
margin: "0",
|
172
|
-
...e.value ? { background: "#000" } : {}
|
173
|
-
})), n = l(() => ({
|
174
|
-
border: e.value ? "2px solid #444" : "2px solid #ddd",
|
175
|
-
padding: "11px 8px",
|
176
|
-
borderRadius: "6px",
|
177
|
-
background: e.value ? "#000" : "#fff",
|
178
|
-
color: e.value ? "#fff" : "#000"
|
179
|
-
})), s = l(() => ({
|
180
|
-
padding: "13px 5px",
|
181
|
-
border: "none",
|
182
|
-
borderRadius: "6px",
|
183
|
-
cursor: "pointer",
|
184
|
-
background: e.value ? "#444" : "#ddd",
|
185
|
-
color: e.value ? "#fff" : "#000"
|
186
|
-
})), a = l(() => ({
|
187
|
-
background: e.value ? "#0d0d0d" : "#eee",
|
188
|
-
color: e.value ? "#fff" : "#000",
|
189
|
-
padding: "0.5rem",
|
190
|
-
border: "none",
|
191
|
-
borderRadius: "6px"
|
192
|
-
})), h = () => {
|
193
|
-
t.state.signUp(r.value), r.value = "";
|
194
|
-
}, f = (c) => {
|
195
|
-
t.state.logInAs(c);
|
273
|
+
setup(__props) {
|
274
|
+
const auth = useDemoAuth();
|
275
|
+
const username = ref("");
|
276
|
+
const darkMode = typeof window !== "undefined" ? window.matchMedia("(prefers-color-scheme: dark)").matches : false;
|
277
|
+
const handleSubmit = (e) => {
|
278
|
+
e.preventDefault();
|
279
|
+
auth.value.signUp(username.value);
|
196
280
|
};
|
197
|
-
return (
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
281
|
+
return (_ctx, _cache) => {
|
282
|
+
return unref(auth).state === "signedIn" ? renderSlot(_ctx.$slots, "default", { key: 0 }) : (openBlock(), createElementBlock("div", _hoisted_1, [
|
283
|
+
createElementVNode("h1", {
|
284
|
+
style: normalizeStyle({
|
285
|
+
color: unref(darkMode) ? "#fff" : "#000",
|
286
|
+
textAlign: "center",
|
287
|
+
fontSize: "1.5rem",
|
288
|
+
fontWeight: "bold"
|
289
|
+
})
|
290
|
+
}, toDisplayString(_ctx.appName), 5),
|
291
|
+
createElementVNode("form", {
|
292
|
+
style: {
|
293
|
+
display: "flex",
|
294
|
+
flexDirection: "column",
|
295
|
+
gap: "0.5rem"
|
296
|
+
},
|
297
|
+
onSubmit: handleSubmit
|
211
298
|
}, [
|
212
|
-
|
213
|
-
"onUpdate:modelValue":
|
299
|
+
withDirectives(createElementVNode("input", {
|
300
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => username.value = $event),
|
214
301
|
placeholder: "Display name",
|
215
|
-
|
216
|
-
style:
|
302
|
+
autocomplete: "webauthn",
|
303
|
+
style: normalizeStyle({
|
304
|
+
border: unref(darkMode) ? "1px solid #444" : "1px solid #ddd",
|
305
|
+
padding: "11px 8px",
|
306
|
+
borderRadius: "6px",
|
307
|
+
background: unref(darkMode) ? "#000" : "#fff",
|
308
|
+
color: unref(darkMode) ? "#fff" : "#000"
|
309
|
+
})
|
217
310
|
}, null, 4), [
|
218
|
-
[
|
311
|
+
[vModelText, username.value]
|
219
312
|
]),
|
220
|
-
|
313
|
+
createElementVNode("input", {
|
221
314
|
type: "submit",
|
222
315
|
value: "Sign up",
|
223
|
-
style:
|
316
|
+
style: normalizeStyle({
|
317
|
+
padding: "13px 5px",
|
318
|
+
border: "none",
|
319
|
+
borderRadius: "6px",
|
320
|
+
cursor: "pointer",
|
321
|
+
background: unref(darkMode) ? "#444" : "#ddd",
|
322
|
+
color: unref(darkMode) ? "#fff" : "#000"
|
323
|
+
})
|
224
324
|
}, null, 4)
|
225
325
|
], 32),
|
226
|
-
|
227
|
-
|
228
|
-
style:
|
229
|
-
color:
|
326
|
+
unref(auth).existingUsers.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_2, [
|
327
|
+
createElementVNode("p", {
|
328
|
+
style: normalizeStyle({
|
329
|
+
color: unref(darkMode) ? "#e2e2e2" : "#000",
|
230
330
|
textAlign: "center",
|
231
331
|
paddingTop: "0.5rem",
|
232
332
|
borderTop: "1px solid",
|
233
|
-
borderColor:
|
333
|
+
borderColor: unref(darkMode) ? "#111" : "#e2e2e2"
|
234
334
|
})
|
235
335
|
}, " Log in as ", 4),
|
236
|
-
(
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
336
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(unref(auth).existingUsers, (user) => {
|
337
|
+
return openBlock(), createElementBlock("button", {
|
338
|
+
key: user,
|
339
|
+
onClick: ($event) => unref(auth).logIn(user),
|
340
|
+
type: "button",
|
341
|
+
"aria-label": `Log in as ${user}`,
|
342
|
+
style: normalizeStyle({
|
343
|
+
background: unref(darkMode) ? "#0d0d0d" : "#eee",
|
344
|
+
color: unref(darkMode) ? "#fff" : "#000",
|
345
|
+
padding: "0.5rem",
|
346
|
+
border: "none",
|
347
|
+
borderRadius: "6px"
|
348
|
+
})
|
349
|
+
}, toDisplayString(user), 13, _hoisted_3);
|
350
|
+
}), 128))
|
351
|
+
])) : createCommentVNode("", true)
|
352
|
+
]));
|
353
|
+
};
|
246
354
|
}
|
247
|
-
})
|
355
|
+
});
|
356
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
248
357
|
__name: "ProgressiveImg",
|
249
358
|
props: {
|
250
359
|
image: {},
|
251
360
|
maxWidth: {}
|
252
361
|
},
|
253
|
-
setup(
|
254
|
-
function
|
255
|
-
const
|
256
|
-
let
|
257
|
-
const
|
362
|
+
setup(__props) {
|
363
|
+
function useProgressiveImg(image, maxWidth) {
|
364
|
+
const current2 = ref({});
|
365
|
+
let cleanup;
|
366
|
+
const unsubscribe = watch(
|
258
367
|
() => {
|
259
|
-
var
|
260
|
-
return [(
|
368
|
+
var _a;
|
369
|
+
return [(_a = image.value) == null ? void 0 : _a.id, maxWidth];
|
261
370
|
},
|
262
371
|
() => {
|
263
|
-
let
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
372
|
+
let lastHighestRes;
|
373
|
+
if (!image.value) return;
|
374
|
+
const unsub = image.value.subscribe({}, (update) => {
|
375
|
+
var _a, _b;
|
376
|
+
const highestRes = update == null ? void 0 : update.highestResAvailable({ maxWidth });
|
377
|
+
if (highestRes) {
|
378
|
+
if (highestRes.res !== lastHighestRes) {
|
379
|
+
lastHighestRes = highestRes.res;
|
380
|
+
const blob = highestRes.stream.toBlob();
|
381
|
+
if (blob) {
|
382
|
+
const blobURI = URL.createObjectURL(blob);
|
383
|
+
current2.value = {
|
384
|
+
src: blobURI,
|
385
|
+
res: highestRes.res,
|
386
|
+
originalSize: (_a = image.value) == null ? void 0 : _a.originalSize
|
387
|
+
};
|
388
|
+
if (cleanup) cleanup();
|
389
|
+
cleanup = () => {
|
390
|
+
setTimeout(() => URL.revokeObjectURL(blobURI), 200);
|
279
391
|
};
|
280
392
|
}
|
281
393
|
}
|
282
|
-
} else
|
283
|
-
|
284
|
-
src:
|
394
|
+
} else {
|
395
|
+
current2.value = {
|
396
|
+
src: update == null ? void 0 : update.placeholderDataURL,
|
285
397
|
res: "placeholder",
|
286
|
-
originalSize: (
|
398
|
+
originalSize: (_b = image.value) == null ? void 0 : _b.originalSize
|
287
399
|
};
|
288
|
-
|
400
|
+
}
|
401
|
+
});
|
402
|
+
return unsub;
|
289
403
|
}
|
290
404
|
);
|
291
|
-
|
292
|
-
|
293
|
-
|
405
|
+
onUnmounted(() => {
|
406
|
+
unsubscribe();
|
407
|
+
if (cleanup) cleanup();
|
408
|
+
});
|
409
|
+
return current2;
|
294
410
|
}
|
295
|
-
const
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
411
|
+
const props = __props;
|
412
|
+
const current = useProgressiveImg(toRef(props, "image"), props.maxWidth);
|
413
|
+
return (_ctx, _cache) => {
|
414
|
+
return renderSlot(_ctx.$slots, "default", {
|
415
|
+
src: unref(current).src,
|
416
|
+
res: unref(current).res,
|
417
|
+
originalSize: unref(current).originalSize
|
418
|
+
});
|
419
|
+
};
|
301
420
|
}
|
302
421
|
});
|
303
422
|
export {
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
423
|
+
_sfc_main$1 as DemoAuthBasicUI,
|
424
|
+
b as JazzProvider,
|
425
|
+
_sfc_main as ProgressiveImg,
|
426
|
+
createInviteLink,
|
427
|
+
createUseAccountComposables,
|
428
|
+
logoutHandler,
|
429
|
+
parseInviteLink,
|
430
|
+
useAcceptInvite,
|
431
|
+
useAccount,
|
432
|
+
useAccountOrGuest,
|
433
|
+
useAuthSecretStorage,
|
434
|
+
useCoState,
|
435
|
+
useDemoAuth,
|
436
|
+
useJazzContext,
|
437
|
+
usePasskeyAuth,
|
438
|
+
usePassphraseAuth
|
316
439
|
};
|
440
|
+
//# sourceMappingURL=index.js.map
|