@medialane/ui 0.168.0 → 0.170.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/dist/components/fast-mint/fast-mint.cjs +4 -4
- package/dist/components/fast-mint/fast-mint.cjs.map +1 -1
- package/dist/components/fast-mint/fast-mint.js +4 -4
- package/dist/components/fast-mint/fast-mint.js.map +1 -1
- package/dist/components/remixes-tab.cjs +2 -2
- package/dist/components/remixes-tab.cjs.map +1 -1
- package/dist/components/remixes-tab.d.cts +3 -3
- package/dist/components/remixes-tab.d.ts +3 -3
- package/dist/components/remixes-tab.js +2 -2
- package/dist/components/remixes-tab.js.map +1 -1
- package/dist/index.cjs +68 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +63 -3
- package/dist/index.js.map +1 -1
- package/dist/utils/ipfs-upload.cjs +11 -31
- package/dist/utils/ipfs-upload.cjs.map +1 -1
- package/dist/utils/ipfs-upload.d.cts +5 -5
- package/dist/utils/ipfs-upload.d.ts +5 -5
- package/dist/utils/ipfs-upload.js +11 -31
- package/dist/utils/ipfs-upload.js.map +1 -1
- package/dist/utils/sitemap-data.cjs +55 -0
- package/dist/utils/sitemap-data.cjs.map +1 -0
- package/dist/utils/sitemap-data.d.cts +23 -0
- package/dist/utils/sitemap-data.d.ts +23 -0
- package/dist/utils/sitemap-data.js +31 -0
- package/dist/utils/sitemap-data.js.map +1 -0
- package/dist/utils/use-coin-price.cjs +88 -0
- package/dist/utils/use-coin-price.cjs.map +1 -0
- package/dist/utils/use-coin-price.d.cts +17 -0
- package/dist/utils/use-coin-price.d.ts +17 -0
- package/dist/utils/use-coin-price.js +53 -0
- package/dist/utils/use-coin-price.js.map +1 -0
- package/dist/utils/use-collections.cjs +2 -2
- package/dist/utils/use-collections.cjs.map +1 -1
- package/dist/utils/use-collections.js +2 -2
- package/dist/utils/use-collections.js.map +1 -1
- package/dist/utils/use-drops.cjs +94 -0
- package/dist/utils/use-drops.cjs.map +1 -0
- package/dist/utils/use-drops.d.cts +39 -0
- package/dist/utils/use-drops.d.ts +39 -0
- package/dist/utils/use-drops.js +56 -0
- package/dist/utils/use-drops.js.map +1 -0
- package/dist/utils/use-notifications.cjs +2 -2
- package/dist/utils/use-notifications.cjs.map +1 -1
- package/dist/utils/use-notifications.d.cts +1 -2
- package/dist/utils/use-notifications.d.ts +1 -2
- package/dist/utils/use-notifications.js +2 -2
- package/dist/utils/use-notifications.js.map +1 -1
- package/dist/utils/use-orders.cjs +3 -3
- package/dist/utils/use-orders.cjs.map +1 -1
- package/dist/utils/use-orders.d.cts +1 -2
- package/dist/utils/use-orders.d.ts +1 -2
- package/dist/utils/use-orders.js +3 -3
- package/dist/utils/use-orders.js.map +1 -1
- package/dist/utils/use-platform-stats.cjs +50 -0
- package/dist/utils/use-platform-stats.cjs.map +1 -0
- package/dist/utils/use-platform-stats.d.cts +9 -0
- package/dist/utils/use-platform-stats.d.ts +9 -0
- package/dist/utils/use-platform-stats.js +16 -0
- package/dist/utils/use-platform-stats.js.map +1 -0
- package/dist/utils/use-pop.cjs +72 -0
- package/dist/utils/use-pop.cjs.map +1 -0
- package/dist/utils/use-pop.d.cts +28 -0
- package/dist/utils/use-pop.d.ts +28 -0
- package/dist/utils/use-pop.js +36 -0
- package/dist/utils/use-pop.js.map +1 -0
- package/dist/utils/use-remix-offers.cjs +5 -4
- package/dist/utils/use-remix-offers.cjs.map +1 -1
- package/dist/utils/use-remix-offers.d.cts +4 -9
- package/dist/utils/use-remix-offers.d.ts +4 -9
- package/dist/utils/use-remix-offers.js +5 -4
- package/dist/utils/use-remix-offers.js.map +1 -1
- package/dist/utils/use-sponsorship.cjs +131 -0
- package/dist/utils/use-sponsorship.cjs.map +1 -0
- package/dist/utils/use-sponsorship.d.cts +70 -0
- package/dist/utils/use-sponsorship.d.ts +70 -0
- package/dist/utils/use-sponsorship.js +90 -0
- package/dist/utils/use-sponsorship.js.map +1 -0
- package/dist/utils/use-tiers.cjs +137 -0
- package/dist/utils/use-tiers.cjs.map +1 -0
- package/dist/utils/use-tiers.d.cts +60 -0
- package/dist/utils/use-tiers.d.ts +60 -0
- package/dist/utils/use-tiers.js +95 -0
- package/dist/utils/use-tiers.js.map +1 -0
- package/dist/utils/use-tokens-by-ip-type.cjs +50 -0
- package/dist/utils/use-tokens-by-ip-type.cjs.map +1 -0
- package/dist/utils/use-tokens-by-ip-type.d.cts +14 -0
- package/dist/utils/use-tokens-by-ip-type.d.ts +14 -0
- package/dist/utils/use-tokens-by-ip-type.js +16 -0
- package/dist/utils/use-tokens-by-ip-type.js.map +1 -0
- package/package.json +3 -3
- package/dist/utils/api-fetch.cjs +0 -65
- package/dist/utils/api-fetch.cjs.map +0 -1
- package/dist/utils/api-fetch.d.cts +0 -17
- package/dist/utils/api-fetch.d.ts +0 -17
- package/dist/utils/api-fetch.js +0 -40
- package/dist/utils/api-fetch.js.map +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as swr from 'swr';
|
|
2
|
+
import { ApiClient, ApiCollection } from '@medialane/sdk';
|
|
3
|
+
import { MedialaneClient } from '@medialane/sdk/starknet';
|
|
4
|
+
|
|
5
|
+
/** An IP Ticket type or IP Club membership tier, with amounts as bigint. */
|
|
6
|
+
interface TierOnchain {
|
|
7
|
+
maxSupply: bigint;
|
|
8
|
+
minted: bigint;
|
|
9
|
+
startTime: number | null;
|
|
10
|
+
endTime: number | null;
|
|
11
|
+
royaltyBps: number;
|
|
12
|
+
}
|
|
13
|
+
interface TierListItem extends TierOnchain {
|
|
14
|
+
id: string;
|
|
15
|
+
}
|
|
16
|
+
/** The id the next membership tier will get. Reads a fresh count, so call it right before creating the tier. */
|
|
17
|
+
declare function predictNextMembershipId(api: ApiClient, contract: string): Promise<number>;
|
|
18
|
+
/** The id the next ticket type will get. Reads a fresh count, so call it right before creating the ticket. */
|
|
19
|
+
declare function predictNextTicketId(api: ApiClient, contract: string): Promise<number>;
|
|
20
|
+
declare function useMyClubCollections(getClient: () => MedialaneClient, owner: string | null): {
|
|
21
|
+
collections: ApiCollection[];
|
|
22
|
+
isLoading: boolean;
|
|
23
|
+
error: any;
|
|
24
|
+
mutate: swr.KeyedMutator<ApiCollection[]>;
|
|
25
|
+
};
|
|
26
|
+
declare function useMyTicketCollections(getClient: () => MedialaneClient, owner: string | null): {
|
|
27
|
+
collections: ApiCollection[];
|
|
28
|
+
isLoading: boolean;
|
|
29
|
+
error: any;
|
|
30
|
+
mutate: swr.KeyedMutator<ApiCollection[]>;
|
|
31
|
+
};
|
|
32
|
+
declare function useMembershipList(getClient: () => MedialaneClient, contract: string | null): {
|
|
33
|
+
memberships: TierListItem[];
|
|
34
|
+
isLoading: boolean;
|
|
35
|
+
error: any;
|
|
36
|
+
mutate: swr.KeyedMutator<TierListItem[]>;
|
|
37
|
+
};
|
|
38
|
+
declare function useTicketList(getClient: () => MedialaneClient, contract: string | null): {
|
|
39
|
+
tickets: TierListItem[];
|
|
40
|
+
isLoading: boolean;
|
|
41
|
+
error: any;
|
|
42
|
+
mutate: swr.KeyedMutator<TierListItem[]>;
|
|
43
|
+
};
|
|
44
|
+
declare function useMembershipOnchain(getClient: () => MedialaneClient, contract: string | null, tokenId: string | null): {
|
|
45
|
+
membership: TierOnchain | null;
|
|
46
|
+
isLoading: boolean;
|
|
47
|
+
error: any;
|
|
48
|
+
};
|
|
49
|
+
declare function useTicketOnchain(getClient: () => MedialaneClient, contract: string | null, tokenId: string | null): {
|
|
50
|
+
ticket: TierOnchain | null;
|
|
51
|
+
isLoading: boolean;
|
|
52
|
+
error: any;
|
|
53
|
+
};
|
|
54
|
+
declare function useIsMemberOf(getClient: () => MedialaneClient, contract: string | null, tokenId: string | null, wallet: string | null): {
|
|
55
|
+
isMember: boolean;
|
|
56
|
+
isLoading: boolean;
|
|
57
|
+
error: any;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export { type TierListItem, type TierOnchain, predictNextMembershipId, predictNextTicketId, useIsMemberOf, useMembershipList, useMembershipOnchain, useMyClubCollections, useMyTicketCollections, useTicketList, useTicketOnchain };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import { useMedialaneClient } from "./use-medialane-client.js";
|
|
4
|
+
function toTier(data) {
|
|
5
|
+
return {
|
|
6
|
+
maxSupply: BigInt(data.maxSupply),
|
|
7
|
+
minted: BigInt(data.minted),
|
|
8
|
+
startTime: data.startTime,
|
|
9
|
+
endTime: data.endTime,
|
|
10
|
+
royaltyBps: data.royaltyBps
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
async function readAll(count, read) {
|
|
14
|
+
const ids = Array.from({ length: count }, (_, i) => String(i + 1));
|
|
15
|
+
const tiers = await Promise.all(ids.map(read));
|
|
16
|
+
return tiers.map((tier, i) => ({ id: ids[i], ...toTier(tier) }));
|
|
17
|
+
}
|
|
18
|
+
function useMyCollectionsOf(getClient, service, owner) {
|
|
19
|
+
const client = useMedialaneClient(getClient);
|
|
20
|
+
const { data, error, isLoading, mutate } = useSWR(
|
|
21
|
+
owner ? `my-${service}-collections-${owner}` : null,
|
|
22
|
+
async () => (await client.api.listCollections({ owner, service, limit: 50 })).data ?? [],
|
|
23
|
+
{ revalidateOnFocus: false }
|
|
24
|
+
);
|
|
25
|
+
return { collections: data ?? [], isLoading, error, mutate };
|
|
26
|
+
}
|
|
27
|
+
async function predictNextMembershipId(api, contract) {
|
|
28
|
+
return await api.getClubMembershipCount(contract) + 1;
|
|
29
|
+
}
|
|
30
|
+
async function predictNextTicketId(api, contract) {
|
|
31
|
+
return await api.getTicketCount(contract) + 1;
|
|
32
|
+
}
|
|
33
|
+
function useMyClubCollections(getClient, owner) {
|
|
34
|
+
return useMyCollectionsOf(getClient, "ip-club", owner);
|
|
35
|
+
}
|
|
36
|
+
function useMyTicketCollections(getClient, owner) {
|
|
37
|
+
return useMyCollectionsOf(getClient, "ip-tickets", owner);
|
|
38
|
+
}
|
|
39
|
+
function useMembershipList(getClient, contract) {
|
|
40
|
+
const client = useMedialaneClient(getClient);
|
|
41
|
+
const { data, error, isLoading, mutate } = useSWR(
|
|
42
|
+
contract ? `membership-list-${contract}` : null,
|
|
43
|
+
async () => readAll(await client.api.getClubMembershipCount(contract), (id) => client.api.getClubMembership(contract, id)),
|
|
44
|
+
{ revalidateOnFocus: false, dedupingInterval: 15e3 }
|
|
45
|
+
);
|
|
46
|
+
return { memberships: data ?? [], isLoading, error, mutate };
|
|
47
|
+
}
|
|
48
|
+
function useTicketList(getClient, contract) {
|
|
49
|
+
const client = useMedialaneClient(getClient);
|
|
50
|
+
const { data, error, isLoading, mutate } = useSWR(
|
|
51
|
+
contract ? `ticket-list-${contract}` : null,
|
|
52
|
+
async () => readAll(await client.api.getTicketCount(contract), (id) => client.api.getTicket(contract, id)),
|
|
53
|
+
{ revalidateOnFocus: false, dedupingInterval: 15e3 }
|
|
54
|
+
);
|
|
55
|
+
return { tickets: data ?? [], isLoading, error, mutate };
|
|
56
|
+
}
|
|
57
|
+
function useMembershipOnchain(getClient, contract, tokenId) {
|
|
58
|
+
const client = useMedialaneClient(getClient);
|
|
59
|
+
const { data, error, isLoading } = useSWR(
|
|
60
|
+
contract && tokenId ? `membership-onchain-${contract}-${tokenId}` : null,
|
|
61
|
+
async () => toTier(await client.api.getClubMembership(contract, tokenId)),
|
|
62
|
+
{ revalidateOnFocus: false, shouldRetryOnError: false, dedupingInterval: 3e4 }
|
|
63
|
+
);
|
|
64
|
+
return { membership: data ?? null, isLoading, error };
|
|
65
|
+
}
|
|
66
|
+
function useTicketOnchain(getClient, contract, tokenId) {
|
|
67
|
+
const client = useMedialaneClient(getClient);
|
|
68
|
+
const { data, error, isLoading } = useSWR(
|
|
69
|
+
contract && tokenId ? `ticket-onchain-${contract}-${tokenId}` : null,
|
|
70
|
+
async () => toTier(await client.api.getTicket(contract, tokenId)),
|
|
71
|
+
{ revalidateOnFocus: false, shouldRetryOnError: false, dedupingInterval: 3e4 }
|
|
72
|
+
);
|
|
73
|
+
return { ticket: data ?? null, isLoading, error };
|
|
74
|
+
}
|
|
75
|
+
function useIsMemberOf(getClient, contract, tokenId, wallet) {
|
|
76
|
+
const client = useMedialaneClient(getClient);
|
|
77
|
+
const { data, error, isLoading } = useSWR(
|
|
78
|
+
contract && tokenId && wallet ? `is-member-of-${contract}-${tokenId}-${wallet}` : null,
|
|
79
|
+
() => client.api.isClubMember(contract, tokenId, wallet),
|
|
80
|
+
{ revalidateOnFocus: false, shouldRetryOnError: false }
|
|
81
|
+
);
|
|
82
|
+
return { isMember: data ?? false, isLoading, error };
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
predictNextMembershipId,
|
|
86
|
+
predictNextTicketId,
|
|
87
|
+
useIsMemberOf,
|
|
88
|
+
useMembershipList,
|
|
89
|
+
useMembershipOnchain,
|
|
90
|
+
useMyClubCollections,
|
|
91
|
+
useMyTicketCollections,
|
|
92
|
+
useTicketList,
|
|
93
|
+
useTicketOnchain
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=use-tiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/use-tiers.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport type { ApiClient, ApiCollection, ApiTierOnchain } from \"@medialane/sdk\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\n\n/** An IP Ticket type or IP Club membership tier, with amounts as bigint. */\nexport interface TierOnchain {\n maxSupply: bigint;\n minted: bigint;\n startTime: number | null;\n endTime: number | null;\n royaltyBps: number;\n}\n\nexport interface TierListItem extends TierOnchain {\n id: string;\n}\n\nfunction toTier(data: ApiTierOnchain): TierOnchain {\n return {\n maxSupply: BigInt(data.maxSupply),\n minted: BigInt(data.minted),\n startTime: data.startTime,\n endTime: data.endTime,\n royaltyBps: data.royaltyBps,\n };\n}\n\nasync function readAll(count: number, read: (id: string) => Promise<ApiTierOnchain>): Promise<TierListItem[]> {\n const ids = Array.from({ length: count }, (_, i) => String(i + 1));\n const tiers = await Promise.all(ids.map(read));\n return tiers.map((tier, i) => ({ id: ids[i]!, ...toTier(tier) }));\n}\n\nfunction useMyCollectionsOf(getClient: () => MedialaneClient, service: string, owner: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<ApiCollection[]>(\n owner ? `my-${service}-collections-${owner}` : null,\n async () => (await client.api.listCollections({ owner: owner!, service, limit: 50 })).data ?? [],\n { revalidateOnFocus: false }\n );\n return { collections: data ?? [], isLoading, error, mutate };\n}\n\n/** The id the next membership tier will get. Reads a fresh count, so call it right before creating the tier. */\nexport async function predictNextMembershipId(api: ApiClient, contract: string): Promise<number> {\n return (await api.getClubMembershipCount(contract)) + 1;\n}\n\n/** The id the next ticket type will get. Reads a fresh count, so call it right before creating the ticket. */\nexport async function predictNextTicketId(api: ApiClient, contract: string): Promise<number> {\n return (await api.getTicketCount(contract)) + 1;\n}\n\nexport function useMyClubCollections(getClient: () => MedialaneClient, owner: string | null) {\n return useMyCollectionsOf(getClient, \"ip-club\", owner);\n}\n\nexport function useMyTicketCollections(getClient: () => MedialaneClient, owner: string | null) {\n return useMyCollectionsOf(getClient, \"ip-tickets\", owner);\n}\n\nexport function useMembershipList(getClient: () => MedialaneClient, contract: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<TierListItem[]>(\n contract ? `membership-list-${contract}` : null,\n async () =>\n readAll(await client.api.getClubMembershipCount(contract!), (id) => client.api.getClubMembership(contract!, id)),\n { revalidateOnFocus: false, dedupingInterval: 15_000 }\n );\n return { memberships: data ?? [], isLoading, error, mutate };\n}\n\nexport function useTicketList(getClient: () => MedialaneClient, contract: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<TierListItem[]>(\n contract ? `ticket-list-${contract}` : null,\n async () => readAll(await client.api.getTicketCount(contract!), (id) => client.api.getTicket(contract!, id)),\n { revalidateOnFocus: false, dedupingInterval: 15_000 }\n );\n return { tickets: data ?? [], isLoading, error, mutate };\n}\n\nexport function useMembershipOnchain(getClient: () => MedialaneClient, contract: string | null, tokenId: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading } = useSWR<TierOnchain>(\n contract && tokenId ? `membership-onchain-${contract}-${tokenId}` : null,\n async () => toTier(await client.api.getClubMembership(contract!, tokenId!)),\n { revalidateOnFocus: false, shouldRetryOnError: false, dedupingInterval: 30_000 }\n );\n return { membership: data ?? null, isLoading, error };\n}\n\nexport function useTicketOnchain(getClient: () => MedialaneClient, contract: string | null, tokenId: string | null) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading } = useSWR<TierOnchain>(\n contract && tokenId ? `ticket-onchain-${contract}-${tokenId}` : null,\n async () => toTier(await client.api.getTicket(contract!, tokenId!)),\n { revalidateOnFocus: false, shouldRetryOnError: false, dedupingInterval: 30_000 }\n );\n return { ticket: data ?? null, isLoading, error };\n}\n\nexport function useIsMemberOf(\n getClient: () => MedialaneClient,\n contract: string | null,\n tokenId: string | null,\n wallet: string | null\n) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading } = useSWR<boolean>(\n contract && tokenId && wallet ? `is-member-of-${contract}-${tokenId}-${wallet}` : null,\n () => client.api.isClubMember(contract!, tokenId!, wallet!),\n { revalidateOnFocus: false, shouldRetryOnError: false }\n );\n return { isMember: data ?? false, isLoading, error };\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var use_tokens_by_ip_type_exports = {};
|
|
31
|
+
__export(use_tokens_by_ip_type_exports, {
|
|
32
|
+
useTokensByIpType: () => useTokensByIpType
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(use_tokens_by_ip_type_exports);
|
|
35
|
+
var import_swr = __toESM(require("swr"), 1);
|
|
36
|
+
var import_use_medialane_client = require("./use-medialane-client.js");
|
|
37
|
+
function useTokensByIpType(getClient, ipTypeSlug, page = 1, limit = 24) {
|
|
38
|
+
const client = (0, import_use_medialane_client.useMedialaneClient)(getClient);
|
|
39
|
+
const { data, error, isLoading, mutate } = (0, import_swr.default)(
|
|
40
|
+
`tokens-by-type-${ipTypeSlug ?? "all"}-${page}-${limit}`,
|
|
41
|
+
() => client.api.getTokens({ page, limit, sort: "recent", ipType: ipTypeSlug ?? void 0 }),
|
|
42
|
+
{ revalidateOnFocus: false, refreshInterval: 3e4 }
|
|
43
|
+
);
|
|
44
|
+
return { tokens: data?.data ?? [], meta: data?.meta, isLoading, error, mutate };
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
useTokensByIpType
|
|
49
|
+
});
|
|
50
|
+
//# sourceMappingURL=use-tokens-by-ip-type.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/use-tokens-by-ip-type.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport type { ApiResponse, ApiToken } from \"@medialane/sdk\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\n\nexport function useTokensByIpType(getClient: () => MedialaneClient, ipTypeSlug: string | null, page = 1, limit = 24) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiToken[]>>(\n `tokens-by-type-${ipTypeSlug ?? \"all\"}-${page}-${limit}`,\n () => client.api.getTokens({ page, limit, sort: \"recent\", ipType: ipTypeSlug ?? undefined }),\n { revalidateOnFocus: false, refreshInterval: 30000 }\n );\n return { tokens: data?.data ?? [], meta: data?.meta, isLoading, error, mutate };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAmB;AAGnB,kCAAmC;AAE5B,SAAS,kBAAkB,WAAkC,YAA2B,OAAO,GAAG,QAAQ,IAAI;AACnH,QAAM,aAAS,gDAAmB,SAAS;AAC3C,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,QAAI,WAAAA;AAAA,IACzC,kBAAkB,cAAc,KAAK,IAAI,IAAI,IAAI,KAAK;AAAA,IACtD,MAAM,OAAO,IAAI,UAAU,EAAE,MAAM,OAAO,MAAM,UAAU,QAAQ,cAAc,OAAU,CAAC;AAAA,IAC3F,EAAE,mBAAmB,OAAO,iBAAiB,IAAM;AAAA,EACrD;AACA,SAAO,EAAE,QAAQ,MAAM,QAAQ,CAAC,GAAG,MAAM,MAAM,MAAM,WAAW,OAAO,OAAO;AAChF;","names":["useSWR"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as swr from 'swr';
|
|
2
|
+
import * as _medialane_sdk from '@medialane/sdk';
|
|
3
|
+
import { ApiToken, ApiResponse } from '@medialane/sdk';
|
|
4
|
+
import { MedialaneClient } from '@medialane/sdk/starknet';
|
|
5
|
+
|
|
6
|
+
declare function useTokensByIpType(getClient: () => MedialaneClient, ipTypeSlug: string | null, page?: number, limit?: number): {
|
|
7
|
+
tokens: ApiToken[];
|
|
8
|
+
meta: _medialane_sdk.ApiMeta | undefined;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
error: any;
|
|
11
|
+
mutate: swr.KeyedMutator<ApiResponse<ApiToken[]>>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useTokensByIpType };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as swr from 'swr';
|
|
2
|
+
import * as _medialane_sdk from '@medialane/sdk';
|
|
3
|
+
import { ApiToken, ApiResponse } from '@medialane/sdk';
|
|
4
|
+
import { MedialaneClient } from '@medialane/sdk/starknet';
|
|
5
|
+
|
|
6
|
+
declare function useTokensByIpType(getClient: () => MedialaneClient, ipTypeSlug: string | null, page?: number, limit?: number): {
|
|
7
|
+
tokens: ApiToken[];
|
|
8
|
+
meta: _medialane_sdk.ApiMeta | undefined;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
error: any;
|
|
11
|
+
mutate: swr.KeyedMutator<ApiResponse<ApiToken[]>>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { useTokensByIpType };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import { useMedialaneClient } from "./use-medialane-client.js";
|
|
4
|
+
function useTokensByIpType(getClient, ipTypeSlug, page = 1, limit = 24) {
|
|
5
|
+
const client = useMedialaneClient(getClient);
|
|
6
|
+
const { data, error, isLoading, mutate } = useSWR(
|
|
7
|
+
`tokens-by-type-${ipTypeSlug ?? "all"}-${page}-${limit}`,
|
|
8
|
+
() => client.api.getTokens({ page, limit, sort: "recent", ipType: ipTypeSlug ?? void 0 }),
|
|
9
|
+
{ revalidateOnFocus: false, refreshInterval: 3e4 }
|
|
10
|
+
);
|
|
11
|
+
return { tokens: data?.data ?? [], meta: data?.meta, isLoading, error, mutate };
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
useTokensByIpType
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=use-tokens-by-ip-type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/use-tokens-by-ip-type.ts"],"sourcesContent":["\"use client\";\n\nimport useSWR from \"swr\";\nimport type { ApiResponse, ApiToken } from \"@medialane/sdk\";\nimport type { MedialaneClient } from \"@medialane/sdk/starknet\";\nimport { useMedialaneClient } from \"./use-medialane-client.js\";\n\nexport function useTokensByIpType(getClient: () => MedialaneClient, ipTypeSlug: string | null, page = 1, limit = 24) {\n const client = useMedialaneClient(getClient);\n const { data, error, isLoading, mutate } = useSWR<ApiResponse<ApiToken[]>>(\n `tokens-by-type-${ipTypeSlug ?? \"all\"}-${page}-${limit}`,\n () => client.api.getTokens({ page, limit, sort: \"recent\", ipType: ipTypeSlug ?? undefined }),\n { revalidateOnFocus: false, refreshInterval: 30000 }\n );\n return { tokens: data?.data ?? [], meta: data?.meta, isLoading, error, mutate };\n}\n"],"mappings":";AAEA,OAAO,YAAY;AAGnB,SAAS,0BAA0B;AAE5B,SAAS,kBAAkB,WAAkC,YAA2B,OAAO,GAAG,QAAQ,IAAI;AACnH,QAAM,SAAS,mBAAmB,SAAS;AAC3C,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,IAAI;AAAA,IACzC,kBAAkB,cAAc,KAAK,IAAI,IAAI,IAAI,KAAK;AAAA,IACtD,MAAM,OAAO,IAAI,UAAU,EAAE,MAAM,OAAO,MAAM,UAAU,QAAQ,cAAc,OAAU,CAAC;AAAA,IAC3F,EAAE,mBAAmB,OAAO,iBAAiB,IAAM;AAAA,EACrD;AACA,SAAO,EAAE,QAAQ,MAAM,QAAQ,CAAC,GAAG,MAAM,MAAM,MAAM,WAAW,OAAO,OAAO;AAChF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@medialane/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.170.0",
|
|
4
4
|
"description": "Shared UI components for Medialane apps",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"preview": "vite --config preview/vite.config.ts"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@medialane/sdk": ">=0.
|
|
54
|
+
"@medialane/sdk": ">=0.138.0",
|
|
55
55
|
"@radix-ui/react-checkbox": ">=1.1.0",
|
|
56
56
|
"@radix-ui/react-collapsible": ">=1.1.0",
|
|
57
57
|
"@radix-ui/react-dialog": ">=1.1.0",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"zod": "^3.25.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
|
-
"@medialane/sdk": "0.
|
|
82
|
+
"@medialane/sdk": "0.138.0",
|
|
83
83
|
"@radix-ui/react-checkbox": "^1.3.8",
|
|
84
84
|
"@radix-ui/react-collapsible": "^1.1.17",
|
|
85
85
|
"@radix-ui/react-dialog": "^1.1.20",
|
package/dist/utils/api-fetch.cjs
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var api_fetch_exports = {};
|
|
20
|
-
__export(api_fetch_exports, {
|
|
21
|
-
ApiError: () => ApiError,
|
|
22
|
-
apiFetch: () => apiFetch
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(api_fetch_exports);
|
|
25
|
-
class ApiError extends Error {
|
|
26
|
-
constructor(status, message) {
|
|
27
|
-
super(message);
|
|
28
|
-
this.status = status;
|
|
29
|
-
this.name = "ApiError";
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async function apiFetch(config, path, options = {}) {
|
|
33
|
-
const { method = "GET", body, bearer, signal } = options;
|
|
34
|
-
const url = `${config.baseUrl.replace(/\/$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
|
|
35
|
-
const headers = {};
|
|
36
|
-
if (body !== void 0) headers["Content-Type"] = "application/json";
|
|
37
|
-
if (config.apiKey) headers["x-api-key"] = config.apiKey;
|
|
38
|
-
if (bearer) headers["Authorization"] = `Bearer ${bearer}`;
|
|
39
|
-
const res = await fetch(url, {
|
|
40
|
-
method,
|
|
41
|
-
headers,
|
|
42
|
-
body: body !== void 0 ? JSON.stringify(body) : void 0,
|
|
43
|
-
signal
|
|
44
|
-
});
|
|
45
|
-
if (!res.ok) {
|
|
46
|
-
const text = await res.text().catch(() => res.statusText);
|
|
47
|
-
let message = text || `Request failed with HTTP ${res.status}`;
|
|
48
|
-
try {
|
|
49
|
-
const parsed = JSON.parse(text);
|
|
50
|
-
if (parsed && typeof parsed === "object" && "error" in parsed && typeof parsed.error === "string") {
|
|
51
|
-
message = parsed.error;
|
|
52
|
-
}
|
|
53
|
-
} catch {
|
|
54
|
-
}
|
|
55
|
-
throw new ApiError(res.status, message);
|
|
56
|
-
}
|
|
57
|
-
if (res.status === 204) return void 0;
|
|
58
|
-
return res.json();
|
|
59
|
-
}
|
|
60
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
-
0 && (module.exports = {
|
|
62
|
-
ApiError,
|
|
63
|
-
apiFetch
|
|
64
|
-
});
|
|
65
|
-
//# sourceMappingURL=api-fetch.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/api-fetch.ts"],"sourcesContent":["\nexport class ApiError extends Error {\n constructor(public readonly status: number, message: string) {\n super(message);\n this.name = \"ApiError\";\n }\n}\n\nexport interface ApiFetchConfig {\n baseUrl: string;\n apiKey?: string;\n}\n\nexport interface ApiFetchOptions {\n method?: \"GET\" | \"POST\" | \"PATCH\" | \"PUT\" | \"DELETE\";\n body?: unknown;\n\n bearer?: string | null;\n signal?: AbortSignal;\n}\n\nexport async function apiFetch<T = unknown>(\n config: ApiFetchConfig,\n path: string,\n options: ApiFetchOptions = {}\n): Promise<T> {\n const { method = \"GET\", body, bearer, signal } = options;\n const url = `${config.baseUrl.replace(/\\/$/, \"\")}${path.startsWith(\"/\") ? path : `/${path}`}`;\n\n const headers: Record<string, string> = {};\n if (body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n if (config.apiKey) headers[\"x-api-key\"] = config.apiKey;\n if (bearer) headers[\"Authorization\"] = `Bearer ${bearer}`;\n\n const res = await fetch(url, {\n method,\n headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal,\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => res.statusText);\n let message = text || `Request failed with HTTP ${res.status}`;\n try {\n const parsed = JSON.parse(text);\n if (parsed && typeof parsed === \"object\" && \"error\" in parsed && typeof parsed.error === \"string\") {\n message = parsed.error;\n }\n } catch {\n\n }\n throw new ApiError(res.status, message);\n }\n\n if (res.status === 204) return undefined as T;\n return res.json() as Promise<T>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACO,MAAM,iBAAiB,MAAM;AAAA,EAClC,YAA4B,QAAgB,SAAiB;AAC3D,UAAM,OAAO;AADa;AAE1B,SAAK,OAAO;AAAA,EACd;AACF;AAeA,eAAsB,SACpB,QACA,MACA,UAA2B,CAAC,GAChB;AACZ,QAAM,EAAE,SAAS,OAAO,MAAM,QAAQ,OAAO,IAAI;AACjD,QAAM,MAAM,GAAG,OAAO,QAAQ,QAAQ,OAAO,EAAE,CAAC,GAAG,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI,EAAE;AAE3F,QAAM,UAAkC,CAAC;AACzC,MAAI,SAAS,OAAW,SAAQ,cAAc,IAAI;AAClD,MAAI,OAAO,OAAQ,SAAQ,WAAW,IAAI,OAAO;AACjD,MAAI,OAAQ,SAAQ,eAAe,IAAI,UAAU,MAAM;AAEvD,QAAM,MAAM,MAAM,MAAM,KAAK;AAAA,IAC3B;AAAA,IACA;AAAA,IACA,MAAM,SAAS,SAAY,KAAK,UAAU,IAAI,IAAI;AAAA,IAClD;AAAA,EACF,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,OAAO,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI,UAAU;AACxD,QAAI,UAAU,QAAQ,4BAA4B,IAAI,MAAM;AAC5D,QAAI;AACF,YAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,UAAI,UAAU,OAAO,WAAW,YAAY,WAAW,UAAU,OAAO,OAAO,UAAU,UAAU;AACjG,kBAAU,OAAO;AAAA,MACnB;AAAA,IACF,QAAQ;AAAA,IAER;AACA,UAAM,IAAI,SAAS,IAAI,QAAQ,OAAO;AAAA,EACxC;AAEA,MAAI,IAAI,WAAW,IAAK,QAAO;AAC/B,SAAO,IAAI,KAAK;AAClB;","names":[]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare class ApiError extends Error {
|
|
2
|
-
readonly status: number;
|
|
3
|
-
constructor(status: number, message: string);
|
|
4
|
-
}
|
|
5
|
-
interface ApiFetchConfig {
|
|
6
|
-
baseUrl: string;
|
|
7
|
-
apiKey?: string;
|
|
8
|
-
}
|
|
9
|
-
interface ApiFetchOptions {
|
|
10
|
-
method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
|
|
11
|
-
body?: unknown;
|
|
12
|
-
bearer?: string | null;
|
|
13
|
-
signal?: AbortSignal;
|
|
14
|
-
}
|
|
15
|
-
declare function apiFetch<T = unknown>(config: ApiFetchConfig, path: string, options?: ApiFetchOptions): Promise<T>;
|
|
16
|
-
|
|
17
|
-
export { ApiError, type ApiFetchConfig, type ApiFetchOptions, apiFetch };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare class ApiError extends Error {
|
|
2
|
-
readonly status: number;
|
|
3
|
-
constructor(status: number, message: string);
|
|
4
|
-
}
|
|
5
|
-
interface ApiFetchConfig {
|
|
6
|
-
baseUrl: string;
|
|
7
|
-
apiKey?: string;
|
|
8
|
-
}
|
|
9
|
-
interface ApiFetchOptions {
|
|
10
|
-
method?: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
|
|
11
|
-
body?: unknown;
|
|
12
|
-
bearer?: string | null;
|
|
13
|
-
signal?: AbortSignal;
|
|
14
|
-
}
|
|
15
|
-
declare function apiFetch<T = unknown>(config: ApiFetchConfig, path: string, options?: ApiFetchOptions): Promise<T>;
|
|
16
|
-
|
|
17
|
-
export { ApiError, type ApiFetchConfig, type ApiFetchOptions, apiFetch };
|
package/dist/utils/api-fetch.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
class ApiError extends Error {
|
|
2
|
-
constructor(status, message) {
|
|
3
|
-
super(message);
|
|
4
|
-
this.status = status;
|
|
5
|
-
this.name = "ApiError";
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
async function apiFetch(config, path, options = {}) {
|
|
9
|
-
const { method = "GET", body, bearer, signal } = options;
|
|
10
|
-
const url = `${config.baseUrl.replace(/\/$/, "")}${path.startsWith("/") ? path : `/${path}`}`;
|
|
11
|
-
const headers = {};
|
|
12
|
-
if (body !== void 0) headers["Content-Type"] = "application/json";
|
|
13
|
-
if (config.apiKey) headers["x-api-key"] = config.apiKey;
|
|
14
|
-
if (bearer) headers["Authorization"] = `Bearer ${bearer}`;
|
|
15
|
-
const res = await fetch(url, {
|
|
16
|
-
method,
|
|
17
|
-
headers,
|
|
18
|
-
body: body !== void 0 ? JSON.stringify(body) : void 0,
|
|
19
|
-
signal
|
|
20
|
-
});
|
|
21
|
-
if (!res.ok) {
|
|
22
|
-
const text = await res.text().catch(() => res.statusText);
|
|
23
|
-
let message = text || `Request failed with HTTP ${res.status}`;
|
|
24
|
-
try {
|
|
25
|
-
const parsed = JSON.parse(text);
|
|
26
|
-
if (parsed && typeof parsed === "object" && "error" in parsed && typeof parsed.error === "string") {
|
|
27
|
-
message = parsed.error;
|
|
28
|
-
}
|
|
29
|
-
} catch {
|
|
30
|
-
}
|
|
31
|
-
throw new ApiError(res.status, message);
|
|
32
|
-
}
|
|
33
|
-
if (res.status === 204) return void 0;
|
|
34
|
-
return res.json();
|
|
35
|
-
}
|
|
36
|
-
export {
|
|
37
|
-
ApiError,
|
|
38
|
-
apiFetch
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=api-fetch.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/api-fetch.ts"],"sourcesContent":["\nexport class ApiError extends Error {\n constructor(public readonly status: number, message: string) {\n super(message);\n this.name = \"ApiError\";\n }\n}\n\nexport interface ApiFetchConfig {\n baseUrl: string;\n apiKey?: string;\n}\n\nexport interface ApiFetchOptions {\n method?: \"GET\" | \"POST\" | \"PATCH\" | \"PUT\" | \"DELETE\";\n body?: unknown;\n\n bearer?: string | null;\n signal?: AbortSignal;\n}\n\nexport async function apiFetch<T = unknown>(\n config: ApiFetchConfig,\n path: string,\n options: ApiFetchOptions = {}\n): Promise<T> {\n const { method = \"GET\", body, bearer, signal } = options;\n const url = `${config.baseUrl.replace(/\\/$/, \"\")}${path.startsWith(\"/\") ? path : `/${path}`}`;\n\n const headers: Record<string, string> = {};\n if (body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n if (config.apiKey) headers[\"x-api-key\"] = config.apiKey;\n if (bearer) headers[\"Authorization\"] = `Bearer ${bearer}`;\n\n const res = await fetch(url, {\n method,\n headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n signal,\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => res.statusText);\n let message = text || `Request failed with HTTP ${res.status}`;\n try {\n const parsed = JSON.parse(text);\n if (parsed && typeof parsed === \"object\" && \"error\" in parsed && typeof parsed.error === \"string\") {\n message = parsed.error;\n }\n } catch {\n\n }\n throw new ApiError(res.status, message);\n }\n\n if (res.status === 204) return undefined as T;\n return res.json() as Promise<T>;\n}\n"],"mappings":"AACO,MAAM,iBAAiB,MAAM;AAAA,EAClC,YAA4B,QAAgB,SAAiB;AAC3D,UAAM,OAAO;AADa;AAE1B,SAAK,OAAO;AAAA,EACd;AACF;AAeA,eAAsB,SACpB,QACA,MACA,UAA2B,CAAC,GAChB;AACZ,QAAM,EAAE,SAAS,OAAO,MAAM,QAAQ,OAAO,IAAI;AACjD,QAAM,MAAM,GAAG,OAAO,QAAQ,QAAQ,OAAO,EAAE,CAAC,GAAG,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI,EAAE;AAE3F,QAAM,UAAkC,CAAC;AACzC,MAAI,SAAS,OAAW,SAAQ,cAAc,IAAI;AAClD,MAAI,OAAO,OAAQ,SAAQ,WAAW,IAAI,OAAO;AACjD,MAAI,OAAQ,SAAQ,eAAe,IAAI,UAAU,MAAM;AAEvD,QAAM,MAAM,MAAM,MAAM,KAAK;AAAA,IAC3B;AAAA,IACA;AAAA,IACA,MAAM,SAAS,SAAY,KAAK,UAAU,IAAI,IAAI;AAAA,IAClD;AAAA,EACF,CAAC;AAED,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,OAAO,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI,UAAU;AACxD,QAAI,UAAU,QAAQ,4BAA4B,IAAI,MAAM;AAC5D,QAAI;AACF,YAAM,SAAS,KAAK,MAAM,IAAI;AAC9B,UAAI,UAAU,OAAO,WAAW,YAAY,WAAW,UAAU,OAAO,OAAO,UAAU,UAAU;AACjG,kBAAU,OAAO;AAAA,MACnB;AAAA,IACF,QAAQ;AAAA,IAER;AACA,UAAM,IAAI,SAAS,IAAI,QAAQ,OAAO;AAAA,EACxC;AAEA,MAAI,IAAI,WAAW,IAAK,QAAO;AAC/B,SAAO,IAAI,KAAK;AAClB;","names":[]}
|