@lukso/transaction-view-headless 0.2.2-dev.a8c9315

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 (76) hide show
  1. package/.turbo/turbo-build.log +51 -0
  2. package/CHANGELOG.md +88 -0
  3. package/COMPONENT_ARCHITECTURE.md +190 -0
  4. package/COMPONENT_CONVERSION_ANALYSIS.md +371 -0
  5. package/CONTEXT_VARIANT_GUIDE.md +425 -0
  6. package/LAZY_LOADING_GUIDE.md +534 -0
  7. package/LICENSE +201 -0
  8. package/PLAYBACK_EXAMPLES.md +658 -0
  9. package/PLAYBACK_GUIDE.md +402 -0
  10. package/README.md +43 -0
  11. package/REGISTRY_SUMMARY.md +638 -0
  12. package/SUFFERING_ECONOMICS.md +346 -0
  13. package/SUFFERING_ECONOMICS.zip +0 -0
  14. package/VIEW_REGISTRATION_GUIDE.md +795 -0
  15. package/dist/composables/index.cjs +1321 -0
  16. package/dist/composables/index.cjs.map +1 -0
  17. package/dist/composables/index.d.cts +6 -0
  18. package/dist/composables/index.d.ts +6 -0
  19. package/dist/composables/index.js +1276 -0
  20. package/dist/composables/index.js.map +1 -0
  21. package/dist/index-CMLU1hKL.d.ts +374 -0
  22. package/dist/index-CSDjhiKV.d.cts +374 -0
  23. package/dist/index.cjs +1534 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.cts +93 -0
  26. package/dist/index.d.ts +93 -0
  27. package/dist/index.js +1463 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/registry/index.cjs +522 -0
  30. package/dist/registry/index.cjs.map +1 -0
  31. package/dist/registry/index.d.cts +46 -0
  32. package/dist/registry/index.d.ts +46 -0
  33. package/dist/registry/index.js +487 -0
  34. package/dist/registry/index.js.map +1 -0
  35. package/dist/types/index.cjs +19 -0
  36. package/dist/types/index.cjs.map +1 -0
  37. package/dist/types/index.d.cts +203 -0
  38. package/dist/types/index.d.ts +203 -0
  39. package/dist/types/index.js +1 -0
  40. package/dist/types/index.js.map +1 -0
  41. package/dist/utils/index.cjs +217 -0
  42. package/dist/utils/index.cjs.map +1 -0
  43. package/dist/utils/index.d.cts +47 -0
  44. package/dist/utils/index.d.ts +47 -0
  45. package/dist/utils/index.js +188 -0
  46. package/dist/utils/index.js.map +1 -0
  47. package/dist/view-loader-dD86QAlQ.d.cts +121 -0
  48. package/dist/view-loader-ii8AxiQR.d.ts +121 -0
  49. package/package.json +64 -0
  50. package/publish.log +0 -0
  51. package/src/composables/index.ts +59 -0
  52. package/src/composables/use-image-loader.ts +315 -0
  53. package/src/composables/use-transaction-playback.ts +396 -0
  54. package/src/composables/use-transaction-view.ts +309 -0
  55. package/src/config/lukso-config.ts +171 -0
  56. package/src/examples/context-aware-views.ts +300 -0
  57. package/src/examples/example-views.ts +197 -0
  58. package/src/examples/lit-plus-rn-strategy.ts +448 -0
  59. package/src/examples/lsp7-custom-matcher-examples.ts +174 -0
  60. package/src/examples/opt-in-context-examples.ts +372 -0
  61. package/src/examples/optimized-view-definitions.ts +408 -0
  62. package/src/examples/vue-to-lit-compilation.ts +358 -0
  63. package/src/hooks/useAddressQuery.ts +135 -0
  64. package/src/hooks/useAddressResolution.ts +437 -0
  65. package/src/index.ts +36 -0
  66. package/src/registry/index.ts +13 -0
  67. package/src/registry/view-loader.ts +305 -0
  68. package/src/registry/view-registry.ts +135 -0
  69. package/src/types/index.ts +16 -0
  70. package/src/types/view-contexts.ts +72 -0
  71. package/src/types/view-matching.ts +173 -0
  72. package/src/utils/context-matcher.ts +165 -0
  73. package/src/utils/index.ts +5 -0
  74. package/src/utils/view-matcher.ts +338 -0
  75. package/tsconfig.json +20 -0
  76. package/tsup.config.ts +34 -0
package/dist/index.js ADDED
@@ -0,0 +1,1463 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropNames = Object.getOwnPropertyNames;
3
+ var __esm = (fn, res) => function __init() {
4
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
+ };
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+
11
+ // src/config/lukso-config.ts
12
+ import { signal } from "@preact/signals-core";
13
+ function setLuksoConfig(config) {
14
+ globalConfig = { ...globalConfig, ...config };
15
+ clearAddressCache();
16
+ if (typeof window !== "undefined" && window.console) {
17
+ console.log("\u{1F310} LUKSO Config Updated:", {
18
+ chainId: globalConfig.chainId,
19
+ network: globalConfig.chainId === 42 ? "mainnet" : globalConfig.chainId === 4201 ? "testnet" : "custom",
20
+ addressResolution: globalConfig.enableAddressResolution
21
+ });
22
+ }
23
+ }
24
+ function getLuksoConfig() {
25
+ return { ...globalConfig };
26
+ }
27
+ function useLuksoMainnet() {
28
+ setLuksoConfig({
29
+ chainId: 42,
30
+ rpcUrl: "https://rpc.lukso.network"
31
+ });
32
+ }
33
+ function useLuksoTestnet() {
34
+ setLuksoConfig({
35
+ chainId: 4201,
36
+ rpcUrl: "https://rpc.testnet.lukso.network"
37
+ });
38
+ }
39
+ function cacheAddress(address, data) {
40
+ if (!globalConfig.enableAddressResolution) return;
41
+ const key = address.toLowerCase();
42
+ addressCache.set(key, data);
43
+ cacheTimestamps.set(key, Date.now());
44
+ }
45
+ function getCachedAddress(address) {
46
+ if (!globalConfig.enableAddressResolution) return null;
47
+ const key = address.toLowerCase();
48
+ const data = addressCache.get(key);
49
+ const timestamp = cacheTimestamps.get(key);
50
+ if (!data || !timestamp) return null;
51
+ if (Date.now() - timestamp > globalConfig.cacheDuration) {
52
+ addressCache.delete(key);
53
+ cacheTimestamps.delete(key);
54
+ return null;
55
+ }
56
+ return data;
57
+ }
58
+ function clearAddressCache() {
59
+ addressCache.clear();
60
+ cacheTimestamps.clear();
61
+ }
62
+ function isAddressResolutionEnabled() {
63
+ return globalConfig.enableAddressResolution ?? true;
64
+ }
65
+ function setCurrentChain(chain) {
66
+ currentChainSignal.value = chain;
67
+ setLuksoConfig({
68
+ chainId: chain.id,
69
+ rpcUrl: chain.rpcUrls.default.http[0]
70
+ });
71
+ }
72
+ function getCurrentChain() {
73
+ return currentChainSignal.value;
74
+ }
75
+ async function initializeChainSignal() {
76
+ if (currentChainSignal.value) return;
77
+ try {
78
+ const { lukso, luksoTestnet } = await import("viem/chains");
79
+ const config = getLuksoConfig();
80
+ const chain = config.chainId === 42 ? lukso : luksoTestnet;
81
+ currentChainSignal.value = chain;
82
+ } catch (error) {
83
+ console.warn("Failed to initialize chain signal:", error);
84
+ }
85
+ }
86
+ var DEFAULT_CONFIG, globalConfig, addressCache, cacheTimestamps, currentChainSignal;
87
+ var init_lukso_config = __esm({
88
+ "src/config/lukso-config.ts"() {
89
+ "use strict";
90
+ DEFAULT_CONFIG = {
91
+ chainId: 42,
92
+ // LUKSO mainnet
93
+ rpcUrl: "https://rpc.lukso.network",
94
+ graphqlEndpoint: "/api/graphql",
95
+ // Use local API proxy
96
+ ipfsGateway: "https://api.universalprofile.cloud/ipfs",
97
+ enableAddressResolution: true,
98
+ cacheDuration: 5 * 60 * 1e3
99
+ // 5 minutes
100
+ };
101
+ globalConfig = { ...DEFAULT_CONFIG };
102
+ addressCache = /* @__PURE__ */ new Map();
103
+ cacheTimestamps = /* @__PURE__ */ new Map();
104
+ currentChainSignal = signal(null);
105
+ }
106
+ });
107
+
108
+ // src/hooks/useAddressResolution.ts
109
+ var useAddressResolution_exports = {};
110
+ __export(useAddressResolution_exports, {
111
+ createAddressResolutionState: () => createAddressResolutionState,
112
+ resolveAddress: () => resolveAddress,
113
+ resolveAddressWithState: () => resolveAddressWithState,
114
+ resolveAddresses: () => resolveAddresses
115
+ });
116
+ function truncateAddress(address, prefixLength = 5, suffixLength = 4) {
117
+ if (!address || address.length <= prefixLength + suffixLength + 2) {
118
+ return address;
119
+ }
120
+ const prefix = address.slice(0, 2 + prefixLength);
121
+ const suffix = address.slice(-suffixLength);
122
+ return `${prefix}...${suffix}`;
123
+ }
124
+ function getBatchState(chainId) {
125
+ let state = chainBatchStates.get(chainId);
126
+ if (!state) {
127
+ state = {
128
+ batchTimeout: null,
129
+ batchQueue: /* @__PURE__ */ new Set(),
130
+ batchResolvers: /* @__PURE__ */ new Map(),
131
+ pendingResolutions: /* @__PURE__ */ new Map(),
132
+ isProcessing: false
133
+ };
134
+ chainBatchStates.set(chainId, state);
135
+ }
136
+ return state;
137
+ }
138
+ async function processBatch(chainId) {
139
+ const state = getBatchState(chainId);
140
+ if (state.batchQueue.size === 0 || state.isProcessing) return;
141
+ state.isProcessing = true;
142
+ const addresses = Array.from(state.batchQueue);
143
+ state.batchQueue.clear();
144
+ try {
145
+ const { fetchMultipleAddresses: fetchMultipleAddresses2, getGraphQLEndpoint: getGraphQLEndpoint2 } = await import("@lukso/transaction-decoder");
146
+ const { lukso, luksoTestnet } = await import("viem/chains");
147
+ const chain = chainId === 42 ? lukso : luksoTestnet;
148
+ const graphqlEndpoint = getGraphQLEndpoint2(chain);
149
+ const dataKeys = addresses;
150
+ const results = await fetchMultipleAddresses2(dataKeys, graphqlEndpoint);
151
+ for (const address of addresses) {
152
+ const normalizedAddress = address.toLowerCase();
153
+ const enhanced = results.get(normalizedAddress);
154
+ let result;
155
+ if (enhanced) {
156
+ const profileImages = enhanced.profileImages;
157
+ const resolvedData = {
158
+ ...enhanced,
159
+ hasProfile: !!(enhanced.name || profileImages?.length)
160
+ };
161
+ cacheAddressForChain(address, resolvedData, chainId);
162
+ result = {
163
+ ...resolvedData,
164
+ address,
165
+ truncatedAddress: truncateAddress(address)
166
+ };
167
+ } else {
168
+ result = {
169
+ address,
170
+ truncatedAddress: truncateAddress(address),
171
+ hasProfile: false
172
+ };
173
+ cacheAddressForChain(address, { hasProfile: false }, chainId);
174
+ }
175
+ const resolver = state.batchResolvers.get(normalizedAddress);
176
+ if (resolver) {
177
+ resolver(result);
178
+ state.batchResolvers.delete(normalizedAddress);
179
+ }
180
+ }
181
+ } catch (error) {
182
+ console.warn(
183
+ "Batch address resolution failed (falling back to API):",
184
+ error
185
+ );
186
+ try {
187
+ const response = await fetch("/api/resolveAddresses", {
188
+ method: "POST",
189
+ headers: { "Content-Type": "application/json" },
190
+ body: JSON.stringify({
191
+ addresses,
192
+ chainId
193
+ })
194
+ });
195
+ if (!response.ok) {
196
+ throw new Error(`API fallback failed: ${response.status}`);
197
+ }
198
+ const data = await response.json();
199
+ for (const address of addresses) {
200
+ const normalizedAddress = address.toLowerCase();
201
+ const resolved = data.resolved?.[normalizedAddress];
202
+ let result;
203
+ if (resolved) {
204
+ const resolvedData = {
205
+ name: resolved.name,
206
+ profileImage: resolved.profileImage,
207
+ hasProfile: !!(resolved.name || resolved.profileImage)
208
+ };
209
+ cacheAddressForChain(address, resolvedData, chainId);
210
+ result = {
211
+ address,
212
+ truncatedAddress: truncateAddress(address),
213
+ ...resolvedData
214
+ };
215
+ } else {
216
+ result = {
217
+ address,
218
+ truncatedAddress: truncateAddress(address),
219
+ hasProfile: false
220
+ };
221
+ cacheAddressForChain(address, { hasProfile: false }, chainId);
222
+ }
223
+ const resolver = state.batchResolvers.get(normalizedAddress);
224
+ if (resolver) {
225
+ resolver(result);
226
+ state.batchResolvers.delete(normalizedAddress);
227
+ }
228
+ }
229
+ } catch (fallbackError) {
230
+ console.warn("Both GraphQL and API resolution failed:", fallbackError);
231
+ for (const address of addresses) {
232
+ const fallback = {
233
+ address,
234
+ truncatedAddress: truncateAddress(address),
235
+ hasProfile: false
236
+ };
237
+ cacheAddressForChain(address, { hasProfile: false }, chainId);
238
+ const resolver = state.batchResolvers.get(address.toLowerCase());
239
+ if (resolver) {
240
+ resolver(fallback);
241
+ state.batchResolvers.delete(address.toLowerCase());
242
+ }
243
+ }
244
+ }
245
+ } finally {
246
+ state.isProcessing = false;
247
+ }
248
+ }
249
+ function cacheAddressForChain(address, data, chainId) {
250
+ const key = `${address.toLowerCase()}:${chainId}`;
251
+ cacheAddress(key, data);
252
+ }
253
+ function getCachedAddressForChain(address, chainId) {
254
+ const key = `${address.toLowerCase()}:${chainId}`;
255
+ return getCachedAddress(key);
256
+ }
257
+ async function getEffectiveChainId(chainId) {
258
+ if (chainId !== void 0) return chainId;
259
+ await initializeChainSignal();
260
+ const currentChain = currentChainSignal.value;
261
+ if (currentChain) {
262
+ return currentChain.id;
263
+ }
264
+ const config = getLuksoConfig();
265
+ return config.chainId;
266
+ }
267
+ async function resolveAddress(address, chainId) {
268
+ const effectiveChainId = await getEffectiveChainId(chainId);
269
+ const normalizedAddress = address.toLowerCase();
270
+ const fallback = {
271
+ address,
272
+ truncatedAddress: truncateAddress(address),
273
+ hasProfile: false
274
+ };
275
+ if (!isAddressResolutionEnabled()) {
276
+ return fallback;
277
+ }
278
+ const cached = getCachedAddressForChain(address, effectiveChainId);
279
+ if (cached) {
280
+ return {
281
+ ...fallback,
282
+ ...cached,
283
+ hasProfile: !!(cached.name || cached.profileImage)
284
+ };
285
+ }
286
+ const state = getBatchState(effectiveChainId);
287
+ const existingPromise = state.pendingResolutions.get(normalizedAddress);
288
+ if (existingPromise) {
289
+ return existingPromise;
290
+ }
291
+ if (state.batchQueue.has(normalizedAddress)) {
292
+ return Promise.resolve(fallback);
293
+ }
294
+ const resolutionPromise = new Promise((resolve) => {
295
+ state.batchQueue.add(normalizedAddress);
296
+ state.batchResolvers.set(normalizedAddress, resolve);
297
+ if (state.batchTimeout) {
298
+ clearTimeout(state.batchTimeout);
299
+ }
300
+ if (!state.isProcessing) {
301
+ state.batchTimeout = setTimeout(() => {
302
+ state.batchTimeout = null;
303
+ processBatch(effectiveChainId);
304
+ }, BATCH_DELAY);
305
+ if (state.batchQueue.size >= BATCH_SIZE) {
306
+ if (state.batchTimeout) {
307
+ clearTimeout(state.batchTimeout);
308
+ state.batchTimeout = null;
309
+ }
310
+ processBatch(effectiveChainId);
311
+ }
312
+ }
313
+ });
314
+ state.pendingResolutions.set(normalizedAddress, resolutionPromise);
315
+ resolutionPromise.finally(() => {
316
+ state.pendingResolutions.delete(normalizedAddress);
317
+ });
318
+ return resolutionPromise;
319
+ }
320
+ async function resolveAddresses(addresses, chainId) {
321
+ const results = /* @__PURE__ */ new Map();
322
+ const resolutionPromises = addresses.map(async (address) => {
323
+ const resolved = await resolveAddress(address, chainId);
324
+ results.set(address.toLowerCase(), resolved);
325
+ });
326
+ await Promise.all(resolutionPromises);
327
+ return results;
328
+ }
329
+ function createAddressResolutionState() {
330
+ return {
331
+ resolved: null,
332
+ loading: false,
333
+ error: null
334
+ };
335
+ }
336
+ async function resolveAddressWithState(address, _state, updateCallback, chainId) {
337
+ updateCallback({ loading: true, error: null });
338
+ try {
339
+ const resolved = await resolveAddress(address, chainId);
340
+ updateCallback({
341
+ resolved,
342
+ loading: false,
343
+ error: null
344
+ });
345
+ } catch (error) {
346
+ updateCallback({
347
+ loading: false,
348
+ error: error instanceof Error ? error.message : "Resolution failed"
349
+ });
350
+ }
351
+ }
352
+ var chainBatchStates, BATCH_DELAY, BATCH_SIZE;
353
+ var init_useAddressResolution = __esm({
354
+ "src/hooks/useAddressResolution.ts"() {
355
+ "use strict";
356
+ init_lukso_config();
357
+ chainBatchStates = /* @__PURE__ */ new Map();
358
+ BATCH_DELAY = 0;
359
+ BATCH_SIZE = 50;
360
+ }
361
+ });
362
+
363
+ // src/composables/index.ts
364
+ init_lukso_config();
365
+ init_useAddressResolution();
366
+
367
+ // src/composables/use-image-loader.ts
368
+ console.log(
369
+ "\u{1F525} LOADING NEW useAddressResolver CODE - should see GraphQL integration"
370
+ );
371
+ var imageLoadCache = /* @__PURE__ */ new Map();
372
+ function getImageCacheKey(imageData, options) {
373
+ const imageUrls = imageData.filter((img) => img?.url || img?.src).map((img) => img.url || img.src).sort().join(",");
374
+ const sizeKey = `${options.width || 32}x${options.height || options.width || 32}@${options.dpr || 1}`;
375
+ return `${imageUrls}-${sizeKey}`;
376
+ }
377
+ function useImageLoader() {
378
+ async function loadImage(imageData, options = {}) {
379
+ try {
380
+ if (!imageData || imageData.length === 0) {
381
+ return null;
382
+ }
383
+ const loadOptions = {
384
+ width: options.width || 32,
385
+ height: options.height || options.width || 32,
386
+ dpr: options.dpr || (typeof window !== "undefined" ? window.devicePixelRatio : 1),
387
+ ignoreHead: true
388
+ // Skip HEAD requests in component context
389
+ };
390
+ const cacheKey = getImageCacheKey(imageData, loadOptions);
391
+ const cachedPromise = imageLoadCache.get(cacheKey);
392
+ if (cachedPromise) {
393
+ console.log("\u{1F4F8} loadImage: Using cached promise for", cacheKey);
394
+ return cachedPromise;
395
+ }
396
+ console.log(
397
+ "\u{1F4F8} loadImage: Creating new request for",
398
+ imageData.length,
399
+ "options:",
400
+ loadOptions
401
+ );
402
+ const loadingPromise = (async () => {
403
+ const { getImage } = await import("@lukso/transaction-decoder");
404
+ const result = await getImage(imageData, loadOptions);
405
+ if (result?.src) {
406
+ console.log("\u{1F4F8} loadImage: Selected image:", result.src);
407
+ return {
408
+ src: result.src,
409
+ width: result.width,
410
+ height: result.height
411
+ };
412
+ }
413
+ return null;
414
+ })();
415
+ imageLoadCache.set(cacheKey, loadingPromise);
416
+ loadingPromise.finally(() => {
417
+ loadingPromise.then((result) => {
418
+ if (!result) {
419
+ imageLoadCache.delete(cacheKey);
420
+ }
421
+ }).catch(() => {
422
+ imageLoadCache.delete(cacheKey);
423
+ });
424
+ });
425
+ return loadingPromise;
426
+ } catch (error) {
427
+ console.warn("Failed to load image:", error);
428
+ return null;
429
+ }
430
+ }
431
+ async function loadProfileImage(addressData, options = {}) {
432
+ if (addressData.__gqltype === "Profile") {
433
+ if (addressData.profileImages?.length) {
434
+ const result = await loadImage(addressData.profileImages, options);
435
+ if (result) return result;
436
+ }
437
+ if (addressData.icons?.length) {
438
+ const result = await loadImage(addressData.icons, options);
439
+ if (result) return result;
440
+ }
441
+ if (addressData.images?.length) {
442
+ return loadImage(addressData.images, options);
443
+ }
444
+ return null;
445
+ }
446
+ if (addressData.icons?.length) {
447
+ const result = await loadImage(addressData.icons, options);
448
+ if (result) return result;
449
+ }
450
+ if (addressData.images?.length) {
451
+ return loadImage(addressData.images, options);
452
+ }
453
+ return null;
454
+ }
455
+ async function loadBackgroundImage(addressData, options = {}) {
456
+ const imageGroup = addressData.backgroundImages || [];
457
+ return loadImage(imageGroup, options);
458
+ }
459
+ function getFallbackImage(addressData) {
460
+ const isProfile = addressData.__gqltype === "Profile";
461
+ return {
462
+ src: isProfile ? "/assets/images/profile-default.svg" : "/assets/images/token-default.svg"
463
+ };
464
+ }
465
+ function isContractAddress(addressData) {
466
+ return addressData.__gqltype !== "Profile";
467
+ }
468
+ return {
469
+ loadImage,
470
+ loadProfileImage,
471
+ loadBackgroundImage,
472
+ getFallbackImage,
473
+ isContractAddress
474
+ };
475
+ }
476
+ function useAddressResolver() {
477
+ async function resolveAddress2(address) {
478
+ console.log("\u{1F525} useAddressResolver.resolveAddress called with:", address);
479
+ try {
480
+ const { resolveAddress: batchedResolve } = await Promise.resolve().then(() => (init_useAddressResolution(), useAddressResolution_exports));
481
+ console.log("\u{1F525} useAddressResolver: calling batchedResolve...");
482
+ const resolved = await batchedResolve(address);
483
+ console.log("\u{1F525} useAddressResolver: batchedResolve returned:", resolved);
484
+ const result = {
485
+ // Preserve all image arrays from GraphQL
486
+ ...resolved,
487
+ // Override with computed values only if not already set by GraphQL
488
+ address: resolved.address,
489
+ name: resolved.name || "",
490
+ __gqltype: resolved.__gqltype || (resolved.hasProfile ? "Profile" : "Contract")
491
+ };
492
+ console.log("\u{1F525} useAddressResolver: returning result:", result);
493
+ return result;
494
+ } catch (error) {
495
+ console.error("\u{1F525} useAddressResolver: Failed to resolve address:", error);
496
+ return {
497
+ address,
498
+ name: "",
499
+ __gqltype: "Contract",
500
+ profileImages: [],
501
+ avatar: [],
502
+ icon: []
503
+ };
504
+ }
505
+ }
506
+ function formatDisplayName(addressData) {
507
+ const baseName = addressData.name?.toLowerCase?.() || addressData.lsp4TokenName || addressData.baseAsset?.lsp4TokenName || "";
508
+ const symbol = addressData.lsp4TokenSymbol || addressData.baseAsset?.lsp4TokenSymbol || "";
509
+ return symbol ? `${baseName} (${symbol})` : baseName;
510
+ }
511
+ function getAddressPrefix(addressData) {
512
+ return addressData.__gqltype !== "Profile" ? "\u{1FA99} " : "@";
513
+ }
514
+ function shouldShowNameColor(addressData) {
515
+ return addressData.__gqltype === "Profile";
516
+ }
517
+ return {
518
+ resolveAddress: resolveAddress2,
519
+ formatDisplayName,
520
+ getAddressPrefix,
521
+ shouldShowNameColor
522
+ };
523
+ }
524
+
525
+ // src/utils/view-matcher.ts
526
+ var CRITERIA_WEIGHTS = {
527
+ recordType: 0.25,
528
+ // Most specific to transaction type
529
+ functionName: 0.2,
530
+ // Function-level specificity
531
+ context: 0.2,
532
+ // Context specificity (when opt-in)
533
+ standard: 0.15,
534
+ // LSP standard specificity
535
+ contractAddress: 0.1,
536
+ // Contract-specific logic
537
+ contextRequirements: 0.05,
538
+ // Context requirement matching
539
+ chainId: 0.03,
540
+ // Network-specific behavior
541
+ customMatcher: 0.02
542
+ // Custom logic (lowest weight due to unpredictability)
543
+ };
544
+ function calculateMatchScore(transaction, view, options) {
545
+ const { criteria } = view;
546
+ const matchedCriteria = [];
547
+ let totalWeight = 0;
548
+ let matchedWeight = 0;
549
+ for (const [criterion, weight] of Object.entries(CRITERIA_WEIGHTS)) {
550
+ const criterionKey = criterion;
551
+ const criterionValue = criteria[criterionKey];
552
+ if (criterionValue === void 0) continue;
553
+ totalWeight += weight;
554
+ if (criterionKey === "customMatcher" && typeof criterionValue === "function") {
555
+ try {
556
+ const matchCount = criterionValue(transaction);
557
+ if (matchCount > 0) {
558
+ matchedCriteria.push(criterionKey);
559
+ const normalizedScore = Math.min(matchCount / 10, 1);
560
+ matchedWeight += weight * normalizedScore;
561
+ }
562
+ } catch (error) {
563
+ console.warn("Custom matcher threw error:", error);
564
+ }
565
+ continue;
566
+ }
567
+ if (doesCriterionMatch(transaction, criterionKey, criterionValue, options)) {
568
+ matchedCriteria.push(criterionKey);
569
+ matchedWeight += weight;
570
+ }
571
+ }
572
+ const viewHasContext = criteria.context !== void 0;
573
+ const requestHasContext = options?.context !== void 0;
574
+ if (viewHasContext && !requestHasContext) {
575
+ matchedWeight *= 0.1;
576
+ } else if (!viewHasContext && requestHasContext) {
577
+ matchedWeight *= 0.9;
578
+ }
579
+ if (totalWeight === 0) return { score: 0, matchedCriteria: [] };
580
+ const score = matchedWeight / totalWeight;
581
+ return { score, matchedCriteria };
582
+ }
583
+ function doesCriterionMatch(transaction, criterion, criterionValue, options) {
584
+ switch (criterion) {
585
+ case "recordType":
586
+ return matchesStringOrArray(
587
+ transaction.recordType,
588
+ criterionValue
589
+ );
590
+ case "functionName":
591
+ return matchesStringOrArray(
592
+ transaction.functionName,
593
+ criterionValue
594
+ );
595
+ case "standard":
596
+ return matchesStringOrArray(
597
+ transaction.standard,
598
+ criterionValue
599
+ );
600
+ case "contractAddress":
601
+ return matchesStringOrArray(
602
+ transaction.contractAddress,
603
+ criterionValue
604
+ );
605
+ case "chainId":
606
+ return matchesNumberOrArray(transaction.chainId, criterionValue);
607
+ case "context":
608
+ if (!options?.context) return false;
609
+ return matchesStringOrArray(options.context, criterionValue);
610
+ case "contextRequirements":
611
+ if (!options?.contextRequirements || !criterionValue) return false;
612
+ return areContextRequirementsCompatible(
613
+ options.contextRequirements,
614
+ criterionValue
615
+ );
616
+ case "customMatcher":
617
+ if (typeof criterionValue === "function") {
618
+ try {
619
+ const matchCount = criterionValue(transaction);
620
+ return matchCount > 0;
621
+ } catch (error) {
622
+ console.warn("Custom matcher threw error:", error);
623
+ return false;
624
+ }
625
+ }
626
+ return false;
627
+ default:
628
+ return false;
629
+ }
630
+ }
631
+ function matchesStringOrArray(value, criteria) {
632
+ if (!value || !criteria) return false;
633
+ if (Array.isArray(criteria)) {
634
+ return criteria.includes(value);
635
+ }
636
+ return value === criteria;
637
+ }
638
+ function matchesNumberOrArray(value, criteria) {
639
+ if (value === void 0 || criteria === void 0) return false;
640
+ if (Array.isArray(criteria)) {
641
+ return criteria.includes(value);
642
+ }
643
+ return value === criteria;
644
+ }
645
+ function areContextRequirementsCompatible(requested, viewRequirements) {
646
+ if (requested.detailLevel && viewRequirements.detailLevel) {
647
+ const detailOrder = ["minimal", "summary", "full", "debug"];
648
+ const requestedLevel = detailOrder.indexOf(requested.detailLevel);
649
+ const viewLevel = detailOrder.indexOf(viewRequirements.detailLevel);
650
+ if (viewLevel < requestedLevel) return false;
651
+ }
652
+ if (requested.maxHeight && viewRequirements.maxHeight) {
653
+ if (viewRequirements.maxHeight > requested.maxHeight) return false;
654
+ }
655
+ return true;
656
+ }
657
+ function calculateNativeFrameworkBonus(view, requestedFramework) {
658
+ if (requestedFramework === "lit") {
659
+ return 0;
660
+ }
661
+ if (requestedFramework === "vue" && view.frameworks.vue) {
662
+ return 0.15;
663
+ }
664
+ if (requestedFramework === "rn" && view.frameworks.rn) {
665
+ return 0.15;
666
+ }
667
+ return 0;
668
+ }
669
+ function findMatchingViews(transaction, views, options) {
670
+ const matches = [];
671
+ const minScore = options.minScore ?? 0;
672
+ for (const view of views) {
673
+ if (!view.frameworks[options.framework]) {
674
+ continue;
675
+ }
676
+ const { score, matchedCriteria } = calculateMatchScore(transaction, view, {
677
+ context: options.context,
678
+ contextRequirements: options.contextRequirements
679
+ });
680
+ if (score < minScore) {
681
+ continue;
682
+ }
683
+ const frameworkBonus = calculateNativeFrameworkBonus(
684
+ view,
685
+ options.framework
686
+ );
687
+ const finalScore = Math.min(1, score + frameworkBonus);
688
+ const match = {
689
+ view,
690
+ score: finalScore,
691
+ matchedCriteria,
692
+ frameworkConfig: options.includeFrameworkConfig ? view.frameworks[options.framework] : void 0
693
+ };
694
+ matches.push(match);
695
+ }
696
+ matches.sort((a, b) => {
697
+ if (a.score !== b.score) {
698
+ return b.score - a.score;
699
+ }
700
+ return b.view.priority - a.view.priority;
701
+ });
702
+ if (options.maxMatches) {
703
+ return matches.slice(0, options.maxMatches);
704
+ }
705
+ return matches;
706
+ }
707
+
708
+ // src/registry/view-registry.ts
709
+ var DefaultViewRegistry = class {
710
+ views = /* @__PURE__ */ new Map();
711
+ register(view) {
712
+ if (this.views.has(view.id)) {
713
+ console.warn(
714
+ `View with id "${view.id}" is already registered. Overwriting.`
715
+ );
716
+ }
717
+ this.views.set(view.id, view);
718
+ }
719
+ unregister(viewId) {
720
+ this.views.delete(viewId);
721
+ }
722
+ getAllViews() {
723
+ return Array.from(this.views.values());
724
+ }
725
+ findMatches(transaction, options) {
726
+ const allViews = this.getAllViews();
727
+ return findMatchingViews(transaction, allViews, options);
728
+ }
729
+ getView(viewId) {
730
+ return this.views.get(viewId);
731
+ }
732
+ clear() {
733
+ this.views.clear();
734
+ }
735
+ /**
736
+ * Get the best matching view (highest score) for a transaction
737
+ */
738
+ getBestMatch(transaction, options) {
739
+ const matches = this.findMatches(transaction, { ...options, maxMatches: 1 });
740
+ return matches[0] || null;
741
+ }
742
+ /**
743
+ * Bulk register multiple views
744
+ */
745
+ registerMany(views) {
746
+ for (const view of views) {
747
+ this.register(view);
748
+ }
749
+ }
750
+ /**
751
+ * Get stats about registered views
752
+ */
753
+ getStats() {
754
+ const allViews = this.getAllViews();
755
+ const totalViews = allViews.length;
756
+ const viewsByFramework = {};
757
+ const viewsByRecordType = {};
758
+ for (const view of allViews) {
759
+ for (const framework of Object.keys(view.frameworks)) {
760
+ viewsByFramework[framework] = (viewsByFramework[framework] || 0) + 1;
761
+ }
762
+ const recordType = view.criteria.recordType;
763
+ if (recordType) {
764
+ const types = Array.isArray(recordType) ? recordType : [recordType];
765
+ for (const type of types) {
766
+ viewsByRecordType[type] = (viewsByRecordType[type] || 0) + 1;
767
+ }
768
+ }
769
+ }
770
+ return {
771
+ totalViews,
772
+ viewsByFramework,
773
+ viewsByRecordType
774
+ };
775
+ }
776
+ };
777
+ var globalRegistry = null;
778
+ function getGlobalRegistry() {
779
+ if (!globalRegistry) {
780
+ globalRegistry = new DefaultViewRegistry();
781
+ }
782
+ return globalRegistry;
783
+ }
784
+ function setGlobalRegistry(registry) {
785
+ globalRegistry = registry;
786
+ }
787
+ function resetGlobalRegistry() {
788
+ globalRegistry = null;
789
+ }
790
+
791
+ // src/composables/use-transaction-playback.ts
792
+ function isBatchTransaction(transaction) {
793
+ return transaction.resultType === "executeBatch" || transaction.resultType === "setDataBatch" || !!transaction.children?.length;
794
+ }
795
+ function getBatchChildren(transaction) {
796
+ if (!isBatchTransaction(transaction)) {
797
+ return [];
798
+ }
799
+ return transaction.children || [];
800
+ }
801
+ function selectViewAtIndex(rootTransaction, index, options) {
802
+ const {
803
+ registry = getGlobalRegistry(),
804
+ framework = "lit",
805
+ fallbackViewId,
806
+ minScore = 0,
807
+ includeFrameworkConfig = true
808
+ } = options;
809
+ const isBatch = isBatchTransaction(rootTransaction);
810
+ const children = getBatchChildren(rootTransaction);
811
+ const childCount = children.length;
812
+ const result = {
813
+ match: null,
814
+ transaction: null,
815
+ indexInfo: {
816
+ requested: index,
817
+ childIndex: null,
818
+ isBatchSummary: false,
819
+ isValid: false
820
+ },
821
+ batchInfo: {
822
+ isBatch,
823
+ childCount,
824
+ availableIndices: []
825
+ }
826
+ };
827
+ if (isBatch) {
828
+ result.batchInfo.availableIndices = Array.from(
829
+ { length: childCount + 1 },
830
+ (_, i) => i
831
+ );
832
+ } else {
833
+ result.batchInfo.availableIndices = [0, 1];
834
+ }
835
+ if (index < 0) {
836
+ return result;
837
+ }
838
+ if (!isBatch) {
839
+ if (index === 0 || index === 1) {
840
+ result.indexInfo.isValid = true;
841
+ result.transaction = rootTransaction;
842
+ const matchOptions = {
843
+ framework,
844
+ minScore,
845
+ maxMatches: 1,
846
+ includeFrameworkConfig
847
+ };
848
+ const matches = registry.findMatches(rootTransaction, matchOptions);
849
+ result.match = matches[0] || null;
850
+ if (!result.match && fallbackViewId) {
851
+ const fallbackView = registry.getView(fallbackViewId);
852
+ if (fallbackView && fallbackView.frameworks[framework]) {
853
+ result.match = {
854
+ view: fallbackView,
855
+ score: 0,
856
+ matchedCriteria: [],
857
+ frameworkConfig: includeFrameworkConfig ? fallbackView.frameworks[framework] : void 0
858
+ };
859
+ }
860
+ }
861
+ return result;
862
+ }
863
+ return result;
864
+ }
865
+ if (index === 0) {
866
+ result.indexInfo.isValid = true;
867
+ result.indexInfo.isBatchSummary = true;
868
+ result.transaction = rootTransaction;
869
+ const matchOptions = {
870
+ framework,
871
+ minScore,
872
+ maxMatches: 1,
873
+ includeFrameworkConfig
874
+ };
875
+ const matches = registry.findMatches(rootTransaction, matchOptions);
876
+ result.match = matches[0] || null;
877
+ if (!result.match && fallbackViewId) {
878
+ const fallbackView = registry.getView(fallbackViewId);
879
+ if (fallbackView && fallbackView.frameworks[framework]) {
880
+ result.match = {
881
+ view: fallbackView,
882
+ score: 0,
883
+ matchedCriteria: [],
884
+ frameworkConfig: includeFrameworkConfig ? fallbackView.frameworks[framework] : void 0
885
+ };
886
+ }
887
+ }
888
+ return result;
889
+ }
890
+ const childIndex = index - 1;
891
+ if (childIndex >= 0 && childIndex < childCount) {
892
+ result.indexInfo.isValid = true;
893
+ result.indexInfo.childIndex = childIndex;
894
+ result.transaction = children[childIndex];
895
+ const matchOptions = {
896
+ framework,
897
+ minScore,
898
+ maxMatches: 1,
899
+ includeFrameworkConfig
900
+ };
901
+ const matches = registry.findMatches(result.transaction, matchOptions);
902
+ result.match = matches[0] || null;
903
+ if (!result.match && fallbackViewId) {
904
+ const fallbackView = registry.getView(fallbackViewId);
905
+ if (fallbackView && fallbackView.frameworks[framework]) {
906
+ result.match = {
907
+ view: fallbackView,
908
+ score: 0,
909
+ matchedCriteria: [],
910
+ frameworkConfig: includeFrameworkConfig ? fallbackView.frameworks[framework] : void 0
911
+ };
912
+ }
913
+ }
914
+ return result;
915
+ }
916
+ return result;
917
+ }
918
+ function createTransactionPlayback(rootTransaction, options = {}) {
919
+ const isBatch = isBatchTransaction(rootTransaction);
920
+ const children = getBatchChildren(rootTransaction);
921
+ const childCount = children.length;
922
+ const indexCount = isBatch ? childCount + 1 : 2;
923
+ const availableIndices = isBatch ? Array.from({ length: childCount + 1 }, (_, i) => i) : [0, 1];
924
+ return {
925
+ rootTransaction,
926
+ isBatch,
927
+ children,
928
+ indexCount,
929
+ batchInfo: {
930
+ isBatch,
931
+ childCount,
932
+ availableIndices
933
+ },
934
+ getViewAtIndex: (index) => selectViewAtIndex(rootTransaction, index, options),
935
+ getAllViews: () => {
936
+ const views = [];
937
+ for (let i = 0; i < indexCount; i++) {
938
+ views.push(selectViewAtIndex(rootTransaction, i, options));
939
+ }
940
+ return views;
941
+ }
942
+ };
943
+ }
944
+ function useTransactionPlayback(rootTransaction, index, options = {}) {
945
+ return selectViewAtIndex(rootTransaction, index, options);
946
+ }
947
+ function isValidPlaybackIndex(transaction, index) {
948
+ const isBatch = isBatchTransaction(transaction);
949
+ if (!isBatch) {
950
+ return index === 0 || index === 1;
951
+ }
952
+ const childCount = getBatchChildren(transaction).length;
953
+ return index >= 0 && index <= childCount;
954
+ }
955
+ function getValidPlaybackIndices(transaction) {
956
+ const isBatch = isBatchTransaction(transaction);
957
+ if (!isBatch) {
958
+ return [0, 1];
959
+ }
960
+ const childCount = getBatchChildren(transaction).length;
961
+ return Array.from({ length: childCount + 1 }, (_, i) => i);
962
+ }
963
+
964
+ // src/composables/use-transaction-view.ts
965
+ import {
966
+ fetchMultipleAddresses,
967
+ getGraphQLEndpoint
968
+ } from "@lukso/transaction-decoder";
969
+
970
+ // src/registry/view-loader.ts
971
+ var ViewLoadingError = class extends Error {
972
+ loader;
973
+ config;
974
+ cause;
975
+ constructor(message, loader, config, cause) {
976
+ super(message);
977
+ this.name = "ViewLoadingError";
978
+ this.loader = loader;
979
+ this.config = config;
980
+ this.cause = cause;
981
+ }
982
+ };
983
+ var UniversalViewLoader = class {
984
+ cache = /* @__PURE__ */ new Map();
985
+ /**
986
+ * Load a component based on the framework configuration
987
+ */
988
+ async loadComponent(config) {
989
+ const cacheKey = this.getCacheKey(config);
990
+ if (this.cache.has(cacheKey)) {
991
+ return this.cache.get(cacheKey);
992
+ }
993
+ try {
994
+ const component = await this.loadByStrategy(config.loader);
995
+ this.cache.set(cacheKey, component);
996
+ return component;
997
+ } catch (error) {
998
+ throw new ViewLoadingError(
999
+ `Failed to load component "${config.component}"`,
1000
+ config.loader,
1001
+ config,
1002
+ error instanceof Error ? error : new Error(String(error))
1003
+ );
1004
+ }
1005
+ }
1006
+ /**
1007
+ * Load a component from a view match
1008
+ */
1009
+ async loadFromMatch(match) {
1010
+ if (!match.frameworkConfig) {
1011
+ throw new ViewLoadingError(
1012
+ `No framework config available for view "${match.view.id}"`,
1013
+ { type: "dynamic-import", path: "" },
1014
+ {}
1015
+ );
1016
+ }
1017
+ return this.loadComponent(match.frameworkConfig);
1018
+ }
1019
+ /**
1020
+ * Load component using the specific strategy
1021
+ */
1022
+ async loadByStrategy(loader) {
1023
+ switch (loader.type) {
1024
+ case "dynamic-import":
1025
+ return this.loadDynamicImport(loader.path);
1026
+ case "static-import":
1027
+ return this.loadStaticImport(loader.path);
1028
+ case "custom-element":
1029
+ return this.loadCustomElement(loader.tagName);
1030
+ case "registry-lookup":
1031
+ return this.loadFromRegistry(loader.registryKey);
1032
+ case "custom":
1033
+ return loader.loader({});
1034
+ // Will be passed proper config in real usage
1035
+ default:
1036
+ throw new Error(`Unknown loader type: ${loader.type}`);
1037
+ }
1038
+ }
1039
+ /**
1040
+ * Dynamic import strategy (most common)
1041
+ * Supports both static strings and lazy-loaded callbacks
1042
+ */
1043
+ async loadDynamicImport(path) {
1044
+ if (typeof path === "function") {
1045
+ const module2 = await path();
1046
+ if (module2.default) {
1047
+ return module2.default;
1048
+ }
1049
+ return module2;
1050
+ }
1051
+ const module = await import(path);
1052
+ if (module.default) {
1053
+ return module.default;
1054
+ }
1055
+ return module;
1056
+ }
1057
+ /**
1058
+ * Static import strategy (requires bundler support)
1059
+ * Supports both static strings and lazy-loaded callbacks
1060
+ */
1061
+ async loadStaticImport(path) {
1062
+ if (typeof path === "function") {
1063
+ const module = await path();
1064
+ if (module.default) {
1065
+ return module.default;
1066
+ }
1067
+ return module;
1068
+ }
1069
+ console.warn(
1070
+ "Static import not implemented, falling back to dynamic import"
1071
+ );
1072
+ return this.loadDynamicImport(path);
1073
+ }
1074
+ /**
1075
+ * Custom element strategy (for Lit components)
1076
+ */
1077
+ async loadCustomElement(tagName) {
1078
+ if (typeof window !== "undefined" && window.customElements) {
1079
+ await window.customElements.whenDefined(tagName);
1080
+ return { tagName, type: "custom-element" };
1081
+ }
1082
+ throw new Error("Custom elements not available in this environment");
1083
+ }
1084
+ /**
1085
+ * Registry lookup strategy (for pre-registered components)
1086
+ */
1087
+ async loadFromRegistry(registryKey) {
1088
+ throw new Error(`Registry lookup not implemented for key: ${registryKey}`);
1089
+ }
1090
+ /**
1091
+ * Generate cache key for component config
1092
+ */
1093
+ getCacheKey(config) {
1094
+ const { loader, component, package: pkg } = config;
1095
+ return JSON.stringify({ loader, component, package: pkg });
1096
+ }
1097
+ /**
1098
+ * Clear the component cache
1099
+ */
1100
+ clearCache() {
1101
+ this.cache.clear();
1102
+ }
1103
+ /**
1104
+ * Get cache statistics
1105
+ */
1106
+ getCacheStats() {
1107
+ return {
1108
+ size: this.cache.size,
1109
+ keys: Array.from(this.cache.keys())
1110
+ };
1111
+ }
1112
+ };
1113
+ var globalLoader = null;
1114
+ function getGlobalLoader() {
1115
+ if (!globalLoader) {
1116
+ globalLoader = new UniversalViewLoader();
1117
+ }
1118
+ return globalLoader;
1119
+ }
1120
+ function setGlobalLoader(loader) {
1121
+ globalLoader = loader;
1122
+ }
1123
+ var LoaderHelpers = {
1124
+ /**
1125
+ * Create a Lit custom element loader (universal web compatibility)
1126
+ */
1127
+ litComponent(tagName) {
1128
+ return { type: "custom-element", tagName };
1129
+ },
1130
+ /**
1131
+ * Create a Vue component loader (native Vue, optional)
1132
+ * Supports both static paths and lazy-loaded callbacks
1133
+ */
1134
+ vueComponent(path) {
1135
+ return { type: "dynamic-import", path };
1136
+ },
1137
+ /**
1138
+ * Create a React Native JSX dynamic import loader (mobile-native, optional)
1139
+ * Supports both static paths and lazy-loaded callbacks
1140
+ */
1141
+ rnComponent(path) {
1142
+ return { type: "dynamic-import", path };
1143
+ },
1144
+ /**
1145
+ * Create a custom loader function for advanced use cases
1146
+ */
1147
+ custom(loader) {
1148
+ return { type: "custom", loader };
1149
+ },
1150
+ // Legacy helpers for compilation pipelines (Vue/React → Lit)
1151
+ /**
1152
+ * @deprecated Use litComponent() instead. This exists for compilation pipeline compatibility.
1153
+ */
1154
+ vueToLitCompiled(tagName) {
1155
+ console.warn(
1156
+ "vueToLitCompiled is deprecated. Use litComponent() - the output is the same."
1157
+ );
1158
+ return { type: "custom-element", tagName };
1159
+ },
1160
+ /**
1161
+ * @deprecated Use litComponent() instead. This exists for compilation pipeline compatibility.
1162
+ */
1163
+ reactToLitCompiled(tagName) {
1164
+ console.warn(
1165
+ "reactToLitCompiled is deprecated. Use litComponent() - the output is the same."
1166
+ );
1167
+ return { type: "custom-element", tagName };
1168
+ },
1169
+ /**
1170
+ * @deprecated Use rnComponent() instead. Updated for better TypeScript support.
1171
+ */
1172
+ reactNativeComponent(path) {
1173
+ console.warn(
1174
+ "reactNativeComponent is deprecated. Use rnComponent() instead."
1175
+ );
1176
+ return { type: "dynamic-import", path };
1177
+ }
1178
+ };
1179
+
1180
+ // src/composables/use-transaction-view.ts
1181
+ function useTransactionView(transaction, options) {
1182
+ const {
1183
+ registry = getGlobalRegistry(),
1184
+ autoLoad = false,
1185
+ fallbackViewId,
1186
+ framework = "lit",
1187
+ minScore = 0,
1188
+ maxMatches,
1189
+ includeFrameworkConfig = true,
1190
+ resolve = false,
1191
+ chain,
1192
+ addressCache: addressCache2
1193
+ } = options;
1194
+ const loader = getGlobalLoader();
1195
+ let matches = [];
1196
+ let bestMatch = null;
1197
+ let component = null;
1198
+ let isLoading = false;
1199
+ let error = null;
1200
+ let isResolvingAddresses = false;
1201
+ let resolvedAddresses = {};
1202
+ const refreshMatches = () => {
1203
+ const matchOptions = {
1204
+ framework,
1205
+ minScore,
1206
+ maxMatches,
1207
+ includeFrameworkConfig
1208
+ };
1209
+ matches = registry.findMatches(transaction, matchOptions);
1210
+ bestMatch = matches[0] || null;
1211
+ if (!bestMatch && fallbackViewId) {
1212
+ const fallbackView = registry.getView(fallbackViewId);
1213
+ if (fallbackView && fallbackView.frameworks[framework]) {
1214
+ bestMatch = {
1215
+ view: fallbackView,
1216
+ score: 0,
1217
+ matchedCriteria: [],
1218
+ frameworkConfig: includeFrameworkConfig ? fallbackView.frameworks[framework] : void 0
1219
+ };
1220
+ }
1221
+ }
1222
+ };
1223
+ const loadMatch = async (match) => {
1224
+ if (!match.frameworkConfig) {
1225
+ throw new ViewLoadingError(
1226
+ `No framework config for view "${match.view.id}" and framework "${framework}"`,
1227
+ { type: "dynamic-import", path: "" },
1228
+ {}
1229
+ );
1230
+ }
1231
+ isLoading = true;
1232
+ error = null;
1233
+ try {
1234
+ const loadedComponent = await loader.loadFromMatch(match);
1235
+ component = loadedComponent;
1236
+ return loadedComponent;
1237
+ } catch (err) {
1238
+ error = err instanceof ViewLoadingError ? err : new ViewLoadingError(
1239
+ "Unknown loading error",
1240
+ match.frameworkConfig.loader,
1241
+ match.frameworkConfig,
1242
+ err instanceof Error ? err : new Error(String(err))
1243
+ );
1244
+ throw error;
1245
+ } finally {
1246
+ isLoading = false;
1247
+ }
1248
+ };
1249
+ const loadBestMatch = async () => {
1250
+ if (!bestMatch) {
1251
+ throw new Error("No matching view found for transaction");
1252
+ }
1253
+ return loadMatch(bestMatch);
1254
+ };
1255
+ const resolveAddressesFunc = async () => {
1256
+ if (!resolve || !transaction.addresses || transaction.addresses.length === 0) {
1257
+ return;
1258
+ }
1259
+ if (!chain) {
1260
+ console.warn(
1261
+ "Address resolution requested but no chain provided. Pass chain option to resolve addresses."
1262
+ );
1263
+ return;
1264
+ }
1265
+ isResolvingAddresses = true;
1266
+ try {
1267
+ const dataKeys = transaction.addresses.filter((addr) => addr && typeof addr === "string").map((addr) => addr.toLowerCase());
1268
+ if (dataKeys.length === 0) {
1269
+ return;
1270
+ }
1271
+ const endpoint = getGraphQLEndpoint(chain);
1272
+ const resolvedMap = await fetchMultipleAddresses(
1273
+ dataKeys,
1274
+ endpoint,
1275
+ addressCache2
1276
+ );
1277
+ const resolved = {};
1278
+ resolvedMap.forEach((enhancedInfo, dataKey) => {
1279
+ resolved[dataKey] = enhancedInfo;
1280
+ });
1281
+ resolvedAddresses = resolved;
1282
+ } catch (err) {
1283
+ console.error("Address resolution failed:", err);
1284
+ } finally {
1285
+ isResolvingAddresses = false;
1286
+ }
1287
+ };
1288
+ refreshMatches();
1289
+ if (resolve) {
1290
+ resolveAddressesFunc().catch((err) => {
1291
+ console.error("Auto address resolution failed:", err);
1292
+ });
1293
+ }
1294
+ if (autoLoad && bestMatch) {
1295
+ loadBestMatch().catch((err) => {
1296
+ console.error("Auto-load failed:", err);
1297
+ });
1298
+ }
1299
+ return {
1300
+ matches,
1301
+ bestMatch,
1302
+ component,
1303
+ isLoading,
1304
+ error,
1305
+ isResolvingAddresses,
1306
+ resolvedAddresses,
1307
+ loadMatch,
1308
+ loadBestMatch,
1309
+ refreshMatches,
1310
+ resolveAddresses: resolveAddressesFunc
1311
+ };
1312
+ }
1313
+ function findBestTransactionView(transaction, framework, registry) {
1314
+ const reg = registry || getGlobalRegistry();
1315
+ const matches = reg.findMatches(transaction, {
1316
+ framework,
1317
+ includeFrameworkConfig: true
1318
+ });
1319
+ return matches.length > 0 ? matches[0] : null;
1320
+ }
1321
+ function findAllTransactionViews(transaction, framework, registry) {
1322
+ const reg = registry || getGlobalRegistry();
1323
+ return reg.findMatches(transaction, {
1324
+ framework,
1325
+ includeFrameworkConfig: true
1326
+ });
1327
+ }
1328
+
1329
+ // src/index.ts
1330
+ init_lukso_config();
1331
+
1332
+ // src/hooks/useAddressQuery.ts
1333
+ init_useAddressResolution();
1334
+ function getAddressQueryKey(address, chainId) {
1335
+ return ["address", address.toLowerCase(), chainId || "current"];
1336
+ }
1337
+ function getAddressesQueryKey(addresses, chainId) {
1338
+ const sortedAddresses = [...addresses].map((addr) => addr.toLowerCase()).sort();
1339
+ return ["addresses", sortedAddresses.join(","), chainId || "current"];
1340
+ }
1341
+ async function queryAddress({
1342
+ queryKey
1343
+ }) {
1344
+ const [, address, chainIdOrCurrent] = queryKey;
1345
+ const chainId = chainIdOrCurrent === "current" ? void 0 : chainIdOrCurrent;
1346
+ return resolveAddress(address, chainId);
1347
+ }
1348
+ async function queryAddresses({
1349
+ queryKey
1350
+ }) {
1351
+ const [, addressesStr, chainIdOrCurrent] = queryKey;
1352
+ const chainId = chainIdOrCurrent === "current" ? void 0 : chainIdOrCurrent;
1353
+ const addresses = addressesStr.split(",");
1354
+ return resolveAddresses(addresses, chainId);
1355
+ }
1356
+ var addressQueryOptions = {
1357
+ /**
1358
+ * Single address query options
1359
+ */
1360
+ single: (address, chainId) => ({
1361
+ queryKey: getAddressQueryKey(address, chainId),
1362
+ queryFn: queryAddress,
1363
+ staleTime: 5 * 60 * 1e3,
1364
+ // 5 minutes
1365
+ gcTime: 10 * 60 * 1e3
1366
+ // 10 minutes (formerly cacheTime)
1367
+ }),
1368
+ /**
1369
+ * Batch addresses query options
1370
+ */
1371
+ batch: (addresses, chainId) => ({
1372
+ queryKey: getAddressesQueryKey(addresses, chainId),
1373
+ queryFn: queryAddresses,
1374
+ staleTime: 5 * 60 * 1e3,
1375
+ // 5 minutes
1376
+ gcTime: 10 * 60 * 1e3
1377
+ // 10 minutes
1378
+ })
1379
+ };
1380
+ var addressQueryOptionsVue = {
1381
+ /**
1382
+ * Single address query options for Vue Query
1383
+ */
1384
+ single: (address, chainId) => ({
1385
+ queryKey: getAddressQueryKey(address, chainId),
1386
+ queryFn: queryAddress,
1387
+ staleTime: 5 * 60 * 1e3,
1388
+ cacheTime: 10 * 60 * 1e3
1389
+ // Vue Query still uses cacheTime
1390
+ }),
1391
+ /**
1392
+ * Batch addresses query options for Vue Query
1393
+ */
1394
+ batch: (addresses, chainId) => ({
1395
+ queryKey: getAddressesQueryKey(addresses, chainId),
1396
+ queryFn: queryAddresses,
1397
+ staleTime: 5 * 60 * 1e3,
1398
+ cacheTime: 10 * 60 * 1e3
1399
+ })
1400
+ };
1401
+ function getInvalidateAddressesPattern(chainId) {
1402
+ return ["address", chainId || "current"];
1403
+ }
1404
+ function getAllAddressQueryKeys(address) {
1405
+ return [
1406
+ ["address", address.toLowerCase(), "current"],
1407
+ ["address", address.toLowerCase(), 42],
1408
+ // mainnet
1409
+ ["address", address.toLowerCase(), 4201]
1410
+ // testnet
1411
+ ];
1412
+ }
1413
+
1414
+ // src/index.ts
1415
+ init_useAddressResolution();
1416
+ export {
1417
+ CRITERIA_WEIGHTS,
1418
+ DefaultViewRegistry,
1419
+ LoaderHelpers,
1420
+ UniversalViewLoader,
1421
+ ViewLoadingError,
1422
+ addressQueryOptions,
1423
+ addressQueryOptionsVue,
1424
+ cacheAddress,
1425
+ calculateMatchScore,
1426
+ clearAddressCache,
1427
+ createAddressResolutionState,
1428
+ createTransactionPlayback,
1429
+ currentChainSignal,
1430
+ findAllTransactionViews,
1431
+ findBestTransactionView,
1432
+ findMatchingViews,
1433
+ getAddressQueryKey,
1434
+ getAddressesQueryKey,
1435
+ getAllAddressQueryKeys,
1436
+ getCachedAddress,
1437
+ getCurrentChain,
1438
+ getGlobalLoader,
1439
+ getGlobalRegistry,
1440
+ getInvalidateAddressesPattern,
1441
+ getLuksoConfig,
1442
+ getValidPlaybackIndices,
1443
+ initializeChainSignal,
1444
+ isAddressResolutionEnabled,
1445
+ isValidPlaybackIndex,
1446
+ queryAddress,
1447
+ queryAddresses,
1448
+ resetGlobalRegistry,
1449
+ resolveAddress,
1450
+ resolveAddressWithState,
1451
+ resolveAddresses,
1452
+ setCurrentChain,
1453
+ setGlobalLoader,
1454
+ setGlobalRegistry,
1455
+ setLuksoConfig,
1456
+ useAddressResolver,
1457
+ useImageLoader,
1458
+ useLuksoMainnet,
1459
+ useLuksoTestnet,
1460
+ useTransactionPlayback,
1461
+ useTransactionView
1462
+ };
1463
+ //# sourceMappingURL=index.js.map