@adspacedotfun/sdk 0.1.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/README.md +52 -0
- package/dist/campaign-8I-L9KNW.js +319 -0
- package/dist/campaign-8I-L9KNW.js.map +1 -0
- package/dist/campaign-D-02mKGw.cjs +2 -0
- package/dist/campaign-D-02mKGw.cjs.map +1 -0
- package/dist/core/client.d.ts +63 -0
- package/dist/core/client.d.ts.map +1 -0
- package/dist/core/config.d.ts +57 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/contracts.d.ts +167 -0
- package/dist/core/contracts.d.ts.map +1 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/types.d.ts +89 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/utils/campaign.d.ts +22 -0
- package/dist/core/utils/campaign.d.ts.map +1 -0
- package/dist/core/utils/index.d.ts +3 -0
- package/dist/core/utils/index.d.ts.map +1 -0
- package/dist/core/utils/ipfs.d.ts +13 -0
- package/dist/core/utils/ipfs.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/react/components/AdWidget.d.ts +49 -0
- package/dist/react/components/AdWidget.d.ts.map +1 -0
- package/dist/react/components/index.d.ts +3 -0
- package/dist/react/components/index.d.ts.map +1 -0
- package/dist/react/context.d.ts +39 -0
- package/dist/react/context.d.ts.map +1 -0
- package/dist/react/hooks/index.d.ts +3 -0
- package/dist/react/hooks/index.d.ts.map +1 -0
- package/dist/react/hooks/useActiveAd.d.ts +41 -0
- package/dist/react/hooks/useActiveAd.d.ts.map +1 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react.cjs +2 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.ts +8 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +167 -0
- package/dist/react.js.map +1 -0
- package/dist/vue/components/AdWidget.vue.d.ts +41 -0
- package/dist/vue/components/AdWidget.vue.d.ts.map +1 -0
- package/dist/vue/components/index.d.ts +2 -0
- package/dist/vue/components/index.d.ts.map +1 -0
- package/dist/vue/composables/index.d.ts +3 -0
- package/dist/vue/composables/index.d.ts.map +1 -0
- package/dist/vue/composables/useActiveAd.d.ts +38 -0
- package/dist/vue/composables/useActiveAd.d.ts.map +1 -0
- package/dist/vue/index.d.ts +6 -0
- package/dist/vue/index.d.ts.map +1 -0
- package/dist/vue/plugin.d.ts +32 -0
- package/dist/vue/plugin.d.ts.map +1 -0
- package/dist/vue.cjs +2 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.ts +7 -0
- package/dist/vue.d.ts.map +1 -0
- package/dist/vue.js +140 -0
- package/dist/vue.js.map +1 -0
- package/package.json +102 -0
package/dist/react.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { a as x } from "./campaign-8I-L9KNW.js";
|
|
2
|
+
import { A as O, C as T, D as W, c as B, b as H, e as J, f as N, g as q, d as z, h as K, i as Q, j as V, r as X } from "./campaign-8I-L9KNW.js";
|
|
3
|
+
import { jsx as r } from "react/jsx-runtime";
|
|
4
|
+
import { useMemo as C, useContext as I, createContext as E, useState as y, useRef as b, useCallback as w, useEffect as L } from "react";
|
|
5
|
+
const m = E(null);
|
|
6
|
+
function _({
|
|
7
|
+
children: t,
|
|
8
|
+
config: c = {},
|
|
9
|
+
client: i
|
|
10
|
+
}) {
|
|
11
|
+
const o = C(
|
|
12
|
+
() => i || new x(c),
|
|
13
|
+
[i, JSON.stringify(c)]
|
|
14
|
+
), a = C(
|
|
15
|
+
() => ({ client: o, config: o.getConfig() }),
|
|
16
|
+
[o]
|
|
17
|
+
);
|
|
18
|
+
return /* @__PURE__ */ r(m.Provider, { value: a, children: t });
|
|
19
|
+
}
|
|
20
|
+
function k() {
|
|
21
|
+
const t = I(m);
|
|
22
|
+
if (!t)
|
|
23
|
+
throw new Error("useAdSpaceContext must be used within AdSpaceProvider");
|
|
24
|
+
return t;
|
|
25
|
+
}
|
|
26
|
+
function D() {
|
|
27
|
+
const { client: t } = k();
|
|
28
|
+
return t;
|
|
29
|
+
}
|
|
30
|
+
function P(t, c = {}) {
|
|
31
|
+
const i = D(), [o, a] = y(null), [p, h] = y(!0), [f, v] = y(null), u = b(), { refreshInterval: g = 0, onLoad: l, onError: n, enabled: d = !0 } = c, s = w(async () => {
|
|
32
|
+
if (d)
|
|
33
|
+
try {
|
|
34
|
+
h(!0), v(null);
|
|
35
|
+
const e = await i.getActiveAd(t);
|
|
36
|
+
a(e), e && l && l(e);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
const A = e instanceof Error ? e : new Error(String(e));
|
|
39
|
+
v(A), n && n(A);
|
|
40
|
+
} finally {
|
|
41
|
+
h(!1);
|
|
42
|
+
}
|
|
43
|
+
}, [i, t, l, n, d]);
|
|
44
|
+
return L(() => (s(), g > 0 && d && (u.current = setInterval(s, g * 1e3)), () => {
|
|
45
|
+
u.current && clearInterval(u.current);
|
|
46
|
+
}), [s, g, d]), {
|
|
47
|
+
ad: o,
|
|
48
|
+
isLoading: p,
|
|
49
|
+
error: f,
|
|
50
|
+
refresh: s
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function U({
|
|
54
|
+
spaceId: t,
|
|
55
|
+
width: c = "100%",
|
|
56
|
+
height: i = "auto",
|
|
57
|
+
refreshInterval: o = 30,
|
|
58
|
+
className: a,
|
|
59
|
+
style: p,
|
|
60
|
+
loadingComponent: h,
|
|
61
|
+
errorComponent: f,
|
|
62
|
+
emptyComponent: v,
|
|
63
|
+
onLoad: u,
|
|
64
|
+
onError: g,
|
|
65
|
+
onClick: l
|
|
66
|
+
}) {
|
|
67
|
+
const { ad: n, isLoading: d, error: s } = P(t, {
|
|
68
|
+
refreshInterval: o,
|
|
69
|
+
onLoad: u,
|
|
70
|
+
onError: g
|
|
71
|
+
}), e = {
|
|
72
|
+
width: c,
|
|
73
|
+
height: i,
|
|
74
|
+
minHeight: i === "auto" ? "100px" : i,
|
|
75
|
+
overflow: "hidden",
|
|
76
|
+
position: "relative",
|
|
77
|
+
...p
|
|
78
|
+
}, A = (S) => {
|
|
79
|
+
n && l && l(n, S);
|
|
80
|
+
};
|
|
81
|
+
return d && !n ? /* @__PURE__ */ r("div", { className: a, style: e, children: h || /* @__PURE__ */ r(
|
|
82
|
+
"div",
|
|
83
|
+
{
|
|
84
|
+
style: {
|
|
85
|
+
display: "flex",
|
|
86
|
+
alignItems: "center",
|
|
87
|
+
justifyContent: "center",
|
|
88
|
+
height: "100%",
|
|
89
|
+
color: "#666"
|
|
90
|
+
},
|
|
91
|
+
children: "Loading..."
|
|
92
|
+
}
|
|
93
|
+
) }) : s ? /* @__PURE__ */ r("div", { className: a, style: e, children: typeof f == "function" ? f(s) : f || /* @__PURE__ */ r(
|
|
94
|
+
"div",
|
|
95
|
+
{
|
|
96
|
+
style: {
|
|
97
|
+
display: "flex",
|
|
98
|
+
alignItems: "center",
|
|
99
|
+
justifyContent: "center",
|
|
100
|
+
height: "100%",
|
|
101
|
+
color: "#f00"
|
|
102
|
+
},
|
|
103
|
+
children: "Failed to load ad"
|
|
104
|
+
}
|
|
105
|
+
) }) : n ? /* @__PURE__ */ r("div", { className: a, style: e, children: /* @__PURE__ */ r(
|
|
106
|
+
"a",
|
|
107
|
+
{
|
|
108
|
+
href: n.advertiserSiteLink || "#",
|
|
109
|
+
target: "_blank",
|
|
110
|
+
rel: "noopener noreferrer",
|
|
111
|
+
onClick: A,
|
|
112
|
+
style: {
|
|
113
|
+
display: "block",
|
|
114
|
+
width: "100%",
|
|
115
|
+
height: "100%",
|
|
116
|
+
textDecoration: "none"
|
|
117
|
+
},
|
|
118
|
+
children: /* @__PURE__ */ r(
|
|
119
|
+
"img",
|
|
120
|
+
{
|
|
121
|
+
src: n.imageUrl,
|
|
122
|
+
alt: "Advertisement",
|
|
123
|
+
style: {
|
|
124
|
+
width: "100%",
|
|
125
|
+
height: "auto",
|
|
126
|
+
display: "block",
|
|
127
|
+
maxWidth: "100%"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
) }) : /* @__PURE__ */ r("div", { className: a, style: e, children: v || /* @__PURE__ */ r(
|
|
133
|
+
"div",
|
|
134
|
+
{
|
|
135
|
+
style: {
|
|
136
|
+
display: "flex",
|
|
137
|
+
alignItems: "center",
|
|
138
|
+
justifyContent: "center",
|
|
139
|
+
height: "100%",
|
|
140
|
+
color: "#999"
|
|
141
|
+
},
|
|
142
|
+
children: "No ad available"
|
|
143
|
+
}
|
|
144
|
+
) });
|
|
145
|
+
}
|
|
146
|
+
export {
|
|
147
|
+
O as AD_SPACE_MANAGER_ABI,
|
|
148
|
+
x as AdSpaceClient,
|
|
149
|
+
_ as AdSpaceProvider,
|
|
150
|
+
U as AdWidget,
|
|
151
|
+
T as CampaignStatus,
|
|
152
|
+
W as DEFAULT_CONFIG,
|
|
153
|
+
B as createAdSpaceClient,
|
|
154
|
+
H as createConfig,
|
|
155
|
+
J as extractCID,
|
|
156
|
+
N as formatDuration,
|
|
157
|
+
q as getCampaignStatusLabel,
|
|
158
|
+
z as getCampaignTimeRemaining,
|
|
159
|
+
K as getEffectiveCampaignStatus,
|
|
160
|
+
Q as isCampaignActive,
|
|
161
|
+
V as isIPFSReference,
|
|
162
|
+
X as resolveIPFSUrl,
|
|
163
|
+
P as useActiveAd,
|
|
164
|
+
D as useAdSpaceClient,
|
|
165
|
+
k as useAdSpaceContext
|
|
166
|
+
};
|
|
167
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sources":["../src/react/context.tsx","../src/react/hooks/useActiveAd.ts","../src/react/components/AdWidget.tsx"],"sourcesContent":["import { createContext, useContext, useMemo, ReactNode } from 'react';\nimport { AdSpaceClient } from '../core/client';\nimport { AdSpaceConfig } from '../core/config';\n\ninterface AdSpaceContextValue {\n client: AdSpaceClient;\n config: AdSpaceConfig;\n}\n\nconst AdSpaceContext = createContext<AdSpaceContextValue | null>(null);\n\nexport interface AdSpaceProviderProps {\n children: ReactNode;\n config?: Partial<AdSpaceConfig>;\n client?: AdSpaceClient;\n}\n\n/**\n * AdSpace Provider for React applications\n *\n * @example\n * ```tsx\n * import { AdSpaceProvider } from '@adspace/sdk/react';\n *\n * function App() {\n * return (\n * <AdSpaceProvider config={{ network: { rpcUrl: '...' } }}>\n * <MyComponent />\n * </AdSpaceProvider>\n * );\n * }\n * ```\n */\nexport function AdSpaceProvider({\n children,\n config = {},\n client: providedClient,\n}: AdSpaceProviderProps) {\n const client = useMemo(\n () => providedClient || new AdSpaceClient(config),\n [providedClient, JSON.stringify(config)]\n );\n\n const value = useMemo(\n () => ({ client, config: client.getConfig() }),\n [client]\n );\n\n return (\n <AdSpaceContext.Provider value={value}>\n {children}\n </AdSpaceContext.Provider>\n );\n}\n\n/**\n * Hook to access AdSpace context\n */\nexport function useAdSpaceContext(): AdSpaceContextValue {\n const context = useContext(AdSpaceContext);\n if (!context) {\n throw new Error('useAdSpaceContext must be used within AdSpaceProvider');\n }\n return context;\n}\n\n/**\n * Hook to access the AdSpace client directly\n */\nexport function useAdSpaceClient(): AdSpaceClient {\n const { client } = useAdSpaceContext();\n return client;\n}\n","import { useState, useEffect, useCallback, useRef } from 'react';\nimport { useAdSpaceClient } from '../context';\nimport { ActiveAd } from '../../core/types';\n\nexport interface UseActiveAdOptions {\n /** Polling interval in seconds (0 to disable) */\n refreshInterval?: number;\n /** Callback when ad loads successfully */\n onLoad?: (ad: ActiveAd) => void;\n /** Callback on error */\n onError?: (error: Error) => void;\n /** Whether to fetch immediately on mount */\n enabled?: boolean;\n}\n\nexport interface UseActiveAdResult {\n ad: ActiveAd | null;\n isLoading: boolean;\n error: Error | null;\n refresh: () => Promise<void>;\n}\n\n/**\n * Hook to fetch and display the active ad for a space\n *\n * @example\n * ```tsx\n * function AdDisplay({ spaceId }: { spaceId: number }) {\n * const { ad, isLoading, error } = useActiveAd(spaceId, {\n * refreshInterval: 30\n * });\n *\n * if (isLoading) return <div>Loading...</div>;\n * if (error) return <div>Error: {error.message}</div>;\n * if (!ad) return <div>No ad available</div>;\n *\n * return (\n * <a href={ad.advertiserSiteLink} target=\"_blank\">\n * <img src={ad.imageUrl} alt=\"Advertisement\" />\n * </a>\n * );\n * }\n * ```\n */\nexport function useActiveAd(\n spaceId: number,\n options: UseActiveAdOptions = {}\n): UseActiveAdResult {\n const client = useAdSpaceClient();\n const [ad, setAd] = useState<ActiveAd | null>(null);\n const [isLoading, setIsLoading] = useState(true);\n const [error, setError] = useState<Error | null>(null);\n const intervalRef = useRef<ReturnType<typeof setInterval>>();\n\n const { refreshInterval = 0, onLoad, onError, enabled = true } = options;\n\n const fetchAd = useCallback(async () => {\n if (!enabled) return;\n\n try {\n setIsLoading(true);\n setError(null);\n\n const activeAd = await client.getActiveAd(spaceId);\n setAd(activeAd);\n\n if (activeAd && onLoad) {\n onLoad(activeAd);\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n if (onError) {\n onError(error);\n }\n } finally {\n setIsLoading(false);\n }\n }, [client, spaceId, onLoad, onError, enabled]);\n\n // Initial fetch and polling setup\n useEffect(() => {\n fetchAd();\n\n if (refreshInterval > 0 && enabled) {\n intervalRef.current = setInterval(fetchAd, refreshInterval * 1000);\n }\n\n return () => {\n if (intervalRef.current) {\n clearInterval(intervalRef.current);\n }\n };\n }, [fetchAd, refreshInterval, enabled]);\n\n return {\n ad,\n isLoading,\n error,\n refresh: fetchAd,\n };\n}\n","import React, { CSSProperties } from 'react';\nimport { useActiveAd } from '../hooks/useActiveAd';\nimport { ActiveAd } from '../../core/types';\n\nexport interface AdWidgetProps {\n /** Space ID to display ads for */\n spaceId: number;\n /** Container width (CSS value) */\n width?: string;\n /** Container height (CSS value) */\n height?: string;\n /** Refresh interval in seconds (0 to disable) */\n refreshInterval?: number;\n /** Custom CSS class name */\n className?: string;\n /** Custom inline styles */\n style?: CSSProperties;\n /** Loading component */\n loadingComponent?: React.ReactNode;\n /** Error component */\n errorComponent?: React.ReactNode | ((error: Error) => React.ReactNode);\n /** Empty state component */\n emptyComponent?: React.ReactNode;\n /** Callback when ad loads */\n onLoad?: (ad: ActiveAd) => void;\n /** Callback on error */\n onError?: (error: Error) => void;\n /** Callback on ad click */\n onClick?: (ad: ActiveAd, event: React.MouseEvent) => void;\n}\n\n/**\n * Pre-built Ad Widget component\n *\n * @example\n * ```tsx\n * import { AdWidget } from '@adspace/sdk/react';\n *\n * function MyPage() {\n * return (\n * <AdWidget\n * spaceId={1}\n * width=\"300px\"\n * height=\"250px\"\n * refreshInterval={30}\n * />\n * );\n * }\n * ```\n */\nexport function AdWidget({\n spaceId,\n width = '100%',\n height = 'auto',\n refreshInterval = 30,\n className,\n style,\n loadingComponent,\n errorComponent,\n emptyComponent,\n onLoad,\n onError,\n onClick,\n}: AdWidgetProps) {\n const { ad, isLoading, error } = useActiveAd(spaceId, {\n refreshInterval,\n onLoad,\n onError,\n });\n\n const containerStyle: CSSProperties = {\n width,\n height,\n minHeight: height === 'auto' ? '100px' : height,\n overflow: 'hidden',\n position: 'relative',\n ...style,\n };\n\n const handleClick = (event: React.MouseEvent) => {\n if (ad && onClick) {\n onClick(ad, event);\n }\n };\n\n // Loading state\n if (isLoading && !ad) {\n return (\n <div className={className} style={containerStyle}>\n {loadingComponent || (\n <div\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n height: '100%',\n color: '#666',\n }}\n >\n Loading...\n </div>\n )}\n </div>\n );\n }\n\n // Error state\n if (error) {\n return (\n <div className={className} style={containerStyle}>\n {typeof errorComponent === 'function'\n ? errorComponent(error)\n : errorComponent || (\n <div\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n height: '100%',\n color: '#f00',\n }}\n >\n Failed to load ad\n </div>\n )}\n </div>\n );\n }\n\n // Empty state\n if (!ad) {\n return (\n <div className={className} style={containerStyle}>\n {emptyComponent || (\n <div\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n height: '100%',\n color: '#999',\n }}\n >\n No ad available\n </div>\n )}\n </div>\n );\n }\n\n // Ad display\n return (\n <div className={className} style={containerStyle}>\n <a\n href={ad.advertiserSiteLink || '#'}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n onClick={handleClick}\n style={{\n display: 'block',\n width: '100%',\n height: '100%',\n textDecoration: 'none',\n }}\n >\n <img\n src={ad.imageUrl}\n alt=\"Advertisement\"\n style={{\n width: '100%',\n height: 'auto',\n display: 'block',\n maxWidth: '100%',\n }}\n />\n </a>\n </div>\n );\n}\n"],"names":["AdSpaceContext","createContext","AdSpaceProvider","children","config","providedClient","client","useMemo","AdSpaceClient","value","jsx","useAdSpaceContext","context","useContext","useAdSpaceClient","useActiveAd","spaceId","options","ad","setAd","useState","isLoading","setIsLoading","error","setError","intervalRef","useRef","refreshInterval","onLoad","onError","enabled","fetchAd","useCallback","activeAd","err","useEffect","AdWidget","width","height","className","style","loadingComponent","errorComponent","emptyComponent","onClick","containerStyle","handleClick","event"],"mappings":";;;;AASA,MAAMA,IAAiBC,EAA0C,IAAI;AAwB9D,SAASC,EAAgB;AAAA,EAC9B,UAAAC;AAAA,EACA,QAAAC,IAAS,CAAA;AAAA,EACT,QAAQC;AACV,GAAyB;AACvB,QAAMC,IAASC;AAAA,IACb,MAAMF,KAAkB,IAAIG,EAAcJ,CAAM;AAAA,IAChD,CAACC,GAAgB,KAAK,UAAUD,CAAM,CAAC;AAAA,EAAA,GAGnCK,IAAQF;AAAA,IACZ,OAAO,EAAE,QAAAD,GAAQ,QAAQA,EAAO,YAAU;AAAA,IAC1C,CAACA,CAAM;AAAA,EAAA;AAGT,SACE,gBAAAI,EAACV,EAAe,UAAf,EAAwB,OAAAS,GACtB,UAAAN,EAA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QACL,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,QAAQ;AAAA,QACR,OAAO;AAAA,MAAA;AAAA,MAEV,UAAA;AAAA,IAAA;AAAA,EAAA,GAIT,IAKCQ,IAsBH,gBAAAR,EAAC,OAAA,EAAI,WAAA6B,GAAsB,OAAOM,GAChC,UAAA,gBAAAnC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAMQ,EAAG,sBAAsB;AAAA,MAC/B,QAAO;AAAA,MACP,KAAI;AAAA,MACJ,SAAS4B;AAAA,MACT,OAAO;AAAA,QACL,SAAS;AAAA,QACT,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,gBAAgB;AAAA,MAAA;AAAA,MAGlB,UAAA,gBAAApC;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,KAAKQ,EAAG;AAAA,UACR,KAAI;AAAA,UACJ,OAAO;AAAA,YACL,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,SAAS;AAAA,YACT,UAAU;AAAA,UAAA;AAAA,QACZ;AAAA,MAAA;AAAA,IACF;AAAA,EAAA,GAEJ,IA5CE,gBAAAR,EAAC,OAAA,EAAI,WAAA6B,GAAsB,OAAOM,GAC/B,UAAAF,KACC,gBAAAjC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,SAAS;AAAA,QACT,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,QAAQ;AAAA,QACR,OAAO;AAAA,MAAA;AAAA,MAEV,UAAA;AAAA,IAAA;AAAA,EAAA,GAIL;AAgCN;"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ActiveAd } from '../../core/types';
|
|
2
|
+
interface Props {
|
|
3
|
+
spaceId: number;
|
|
4
|
+
width?: string;
|
|
5
|
+
height?: string;
|
|
6
|
+
refreshInterval?: number;
|
|
7
|
+
}
|
|
8
|
+
declare function __VLS_template(): {
|
|
9
|
+
attrs: Partial<{}>;
|
|
10
|
+
slots: {
|
|
11
|
+
loading?(_: {}): any;
|
|
12
|
+
error?(_: {
|
|
13
|
+
error: Error;
|
|
14
|
+
}): any;
|
|
15
|
+
empty?(_: {}): any;
|
|
16
|
+
};
|
|
17
|
+
refs: {};
|
|
18
|
+
rootEl: HTMLDivElement;
|
|
19
|
+
};
|
|
20
|
+
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
21
|
+
declare const __VLS_component: import('vue').DefineComponent<Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {} & {
|
|
22
|
+
error: (error: Error) => any;
|
|
23
|
+
load: (ad: ActiveAd) => any;
|
|
24
|
+
click: (ad: ActiveAd, event: MouseEvent) => any;
|
|
25
|
+
}, string, import('vue').PublicProps, Readonly<Props> & Readonly<{
|
|
26
|
+
onError?: ((error: Error) => any) | undefined;
|
|
27
|
+
onLoad?: ((ad: ActiveAd) => any) | undefined;
|
|
28
|
+
onClick?: ((ad: ActiveAd, event: MouseEvent) => any) | undefined;
|
|
29
|
+
}>, {
|
|
30
|
+
refreshInterval: number;
|
|
31
|
+
width: string;
|
|
32
|
+
height: string;
|
|
33
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, HTMLDivElement>;
|
|
34
|
+
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
35
|
+
export default _default;
|
|
36
|
+
type __VLS_WithTemplateSlots<T, S> = T & {
|
|
37
|
+
new (): {
|
|
38
|
+
$slots: S;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=AdWidget.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AdWidget.vue.d.ts","sourceRoot":"","sources":["../../../src/vue/components/AdWidget.vue"],"names":[],"mappings":"AA8FA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,UAAU,KAAK;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AA6CD,iBAAS,cAAc;WA2DT,OAAO,IAA6B;;yBAZrB,GAAG;;;YACL,GAAG;uBACH,GAAG;;;;EAe7B;AAeD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC9D,QAAA,MAAM,eAAe;;;;;;;;;qBA9HD,MAAM;WAFhB,MAAM;YACL,MAAM;wFAwIf,CAAC;wBACkB,uBAAuB,CAAC,OAAO,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAAnG,wBAAoG;AAapG,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IACxC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vue/components/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vue/composables/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { ActiveAd } from '../../core/types';
|
|
3
|
+
export interface UseActiveAdOptions {
|
|
4
|
+
refreshInterval?: number;
|
|
5
|
+
onLoad?: (ad: ActiveAd) => void;
|
|
6
|
+
onError?: (error: Error) => void;
|
|
7
|
+
}
|
|
8
|
+
export interface UseActiveAdReturn {
|
|
9
|
+
ad: Ref<ActiveAd | null>;
|
|
10
|
+
isLoading: Ref<boolean>;
|
|
11
|
+
error: Ref<Error | null>;
|
|
12
|
+
refresh: () => Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Vue composable for fetching active ads
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```vue
|
|
19
|
+
* <script setup>
|
|
20
|
+
* import { useActiveAd } from '@adspace/sdk/vue';
|
|
21
|
+
*
|
|
22
|
+
* const { ad, isLoading, error } = useActiveAd(1, {
|
|
23
|
+
* refreshInterval: 30
|
|
24
|
+
* });
|
|
25
|
+
* </script>
|
|
26
|
+
*
|
|
27
|
+
* <template>
|
|
28
|
+
* <div v-if="isLoading">Loading...</div>
|
|
29
|
+
* <div v-else-if="error">Error: {{ error.message }}</div>
|
|
30
|
+
* <a v-else-if="ad" :href="ad.advertiserSiteLink" target="_blank">
|
|
31
|
+
* <img :src="ad.imageUrl" alt="Advertisement" />
|
|
32
|
+
* </a>
|
|
33
|
+
* <div v-else>No ad available</div>
|
|
34
|
+
* </template>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function useActiveAd(spaceId: number | Ref<number>, options?: UseActiveAdOptions): UseActiveAdReturn;
|
|
38
|
+
//# sourceMappingURL=useActiveAd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useActiveAd.d.ts","sourceRoot":"","sources":["../../../src/vue/composables/useActiveAd.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,GAAG,EAAoB,MAAM,KAAK,CAAC;AAEhF,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,IAAI,CAAC;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;IACzB,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACxB,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC;IACzB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,EAC7B,OAAO,GAAE,kBAAuB,GAC/B,iBAAiB,CA4EnB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { AdSpacePlugin, AdSpaceClientKey, useAdSpaceClient } from './plugin';
|
|
2
|
+
export type { AdSpacePluginOptions } from './plugin';
|
|
3
|
+
export { useActiveAd } from './composables';
|
|
4
|
+
export type { UseActiveAdOptions, UseActiveAdReturn } from './composables';
|
|
5
|
+
export { AdWidget } from './components';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vue/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC7E,YAAY,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { App, InjectionKey, Ref } from 'vue';
|
|
2
|
+
import { AdSpaceClient } from '../core/client';
|
|
3
|
+
import { AdSpaceConfig } from '../core/config';
|
|
4
|
+
export declare const AdSpaceClientKey: InjectionKey<Ref<AdSpaceClient>>;
|
|
5
|
+
export interface AdSpacePluginOptions {
|
|
6
|
+
config?: Partial<AdSpaceConfig>;
|
|
7
|
+
client?: AdSpaceClient;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Vue plugin for AdSpace SDK
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createApp } from 'vue';
|
|
15
|
+
* import { AdSpacePlugin } from '@adspace/sdk/vue';
|
|
16
|
+
*
|
|
17
|
+
* const app = createApp(App);
|
|
18
|
+
* app.use(AdSpacePlugin, {
|
|
19
|
+
* config: {
|
|
20
|
+
* network: { rpcUrl: '...' }
|
|
21
|
+
* }
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare const AdSpacePlugin: {
|
|
26
|
+
install(app: App, options?: AdSpacePluginOptions): void;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Composable to get the AdSpace client
|
|
30
|
+
*/
|
|
31
|
+
export declare function useAdSpaceClient(): AdSpaceClient;
|
|
32
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vue/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,GAAG,EAAsB,MAAM,KAAK,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,eAAO,MAAM,gBAAgB,EAAE,YAAY,CAAC,GAAG,CAAC,aAAa,CAAC,CAA2B,CAAC;AAE1F,MAAM,WAAW,oBAAoB;IACnC,MAAM,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAChC,MAAM,CAAC,EAAE,aAAa,CAAC;CACxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa;iBACX,GAAG,YAAW,oBAAoB;CAUhD,CAAC;AAEF;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,aAAa,CAMhD"}
|
package/dist/vue.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./campaign-D-02mKGw.cjs"),e=require("vue"),m=Symbol("AdSpaceClient"),y={install(r,c={}){const n=e.shallowRef(c.client||new t.AdSpaceClient(c.config));r.provide(m,n),r.config.globalProperties.$adspace=n.value}};function k(){const r=e.inject(m);if(!r)throw new Error("AdSpacePlugin must be installed before using useAdSpaceClient");return r.value}function C(r,c={}){const n=e.inject(m);if(!n)throw new Error("AdSpacePlugin must be installed before using useActiveAd");const u=n.value,o=e.ref(null),f=e.ref(!0),s=e.ref(null);let d=null;const{refreshInterval:g=0,onLoad:i,onError:l}=c,v=e.computed(()=>typeof r=="number"?r:r.value),p=async()=>{try{f.value=!0,s.value=null;const a=await u.getActiveAd(v.value);o.value=a,a&&i&&i(a)}catch(a){const S=a instanceof Error?a:new Error(String(a));s.value=S,l&&l(S)}finally{f.value=!1}},h=()=>{g>0&&(d=setInterval(p,g*1e3))},A=()=>{d&&(clearInterval(d),d=null)};return e.watch(v,()=>{A(),p(),h()}),e.onMounted(()=>{p(),h()}),e.onUnmounted(()=>{A()}),{ad:o,isLoading:f,error:s,refresh:p}}const E={key:0,style:{display:"flex","align-items":"center","justify-content":"center",height:"100%",color:"#666"}},I={key:1,style:{display:"flex","align-items":"center","justify-content":"center",height:"100%",color:"#f00"}},w={key:2,style:{display:"flex","align-items":"center","justify-content":"center",height:"100%",color:"#999"}},_=["href"],b=["src"],P=e.defineComponent({__name:"AdWidget",props:{spaceId:{},width:{default:"100%"},height:{default:"auto"},refreshInterval:{default:30}},emits:["load","error","click"],setup(r,{emit:c}){const n=r,u=c,{ad:o,isLoading:f,error:s}=C(n.spaceId,{refreshInterval:n.refreshInterval,onLoad:i=>u("load",i),onError:i=>u("error",i)}),d=e.computed(()=>({width:n.width,height:n.height,minHeight:n.height==="auto"?"100px":n.height,overflow:"hidden",position:"relative"})),g=i=>{o.value&&u("click",o.value,i)};return(i,l)=>(e.openBlock(),e.createElementBlock("div",{style:e.normalizeStyle(d.value)},[e.unref(f)&&!e.unref(o)?(e.openBlock(),e.createElementBlock("div",E,[e.renderSlot(i.$slots,"loading",{},()=>[l[0]||(l[0]=e.createTextVNode("Loading...",-1))])])):e.unref(s)?(e.openBlock(),e.createElementBlock("div",I,[e.renderSlot(i.$slots,"error",{error:e.unref(s)},()=>[l[1]||(l[1]=e.createTextVNode("Failed to load ad",-1))])])):e.unref(o)?(e.openBlock(),e.createElementBlock("a",{key:3,href:e.unref(o).advertiserSiteLink||"#",target:"_blank",rel:"noopener noreferrer",style:{display:"block",width:"100%",height:"100%","text-decoration":"none"},onClick:g},[e.createElementVNode("img",{src:e.unref(o).imageUrl,alt:"Advertisement",style:{width:"100%",height:"auto",display:"block","max-width":"100%"}},null,8,b)],8,_)):(e.openBlock(),e.createElementBlock("div",w,[e.renderSlot(i.$slots,"empty",{},()=>[l[2]||(l[2]=e.createTextVNode("No ad available",-1))])]))],4))}});exports.AD_SPACE_MANAGER_ABI=t.AD_SPACE_MANAGER_ABI;exports.AdSpaceClient=t.AdSpaceClient;exports.CampaignStatus=t.CampaignStatus;exports.DEFAULT_CONFIG=t.DEFAULT_CONFIG;exports.createAdSpaceClient=t.createAdSpaceClient;exports.createConfig=t.createConfig;exports.extractCID=t.extractCID;exports.formatDuration=t.formatDuration;exports.getCampaignStatusLabel=t.getCampaignStatusLabel;exports.getCampaignTimeRemaining=t.getCampaignTimeRemaining;exports.getEffectiveCampaignStatus=t.getEffectiveCampaignStatus;exports.isCampaignActive=t.isCampaignActive;exports.isIPFSReference=t.isIPFSReference;exports.resolveIPFSUrl=t.resolveIPFSUrl;exports.AdSpaceClientKey=m;exports.AdSpacePlugin=y;exports.AdWidget=P;exports.useActiveAd=C;exports.useAdSpaceClient=k;
|
|
2
|
+
//# sourceMappingURL=vue.cjs.map
|
package/dist/vue.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.cjs","sources":["../src/vue/plugin.ts","../src/vue/composables/useActiveAd.ts","../src/vue/components/AdWidget.vue"],"sourcesContent":["import { App, InjectionKey, Ref, shallowRef, inject } from 'vue';\nimport { AdSpaceClient } from '../core/client';\nimport { AdSpaceConfig } from '../core/config';\n\nexport const AdSpaceClientKey: InjectionKey<Ref<AdSpaceClient>> = Symbol('AdSpaceClient');\n\nexport interface AdSpacePluginOptions {\n config?: Partial<AdSpaceConfig>;\n client?: AdSpaceClient;\n}\n\n/**\n * Vue plugin for AdSpace SDK\n *\n * @example\n * ```typescript\n * import { createApp } from 'vue';\n * import { AdSpacePlugin } from '@adspace/sdk/vue';\n *\n * const app = createApp(App);\n * app.use(AdSpacePlugin, {\n * config: {\n * network: { rpcUrl: '...' }\n * }\n * });\n * ```\n */\nexport const AdSpacePlugin = {\n install(app: App, options: AdSpacePluginOptions = {}) {\n const client = shallowRef(\n options.client || new AdSpaceClient(options.config)\n );\n\n app.provide(AdSpaceClientKey, client);\n\n // Also make available globally\n app.config.globalProperties.$adspace = client.value;\n },\n};\n\n/**\n * Composable to get the AdSpace client\n */\nexport function useAdSpaceClient(): AdSpaceClient {\n const client = inject(AdSpaceClientKey);\n if (!client) {\n throw new Error('AdSpacePlugin must be installed before using useAdSpaceClient');\n }\n return client.value;\n}\n","import { ref, watch, onMounted, onUnmounted, Ref, computed, inject } from 'vue';\nimport { AdSpaceClientKey } from '../plugin';\nimport { ActiveAd } from '../../core/types';\n\nexport interface UseActiveAdOptions {\n refreshInterval?: number;\n onLoad?: (ad: ActiveAd) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseActiveAdReturn {\n ad: Ref<ActiveAd | null>;\n isLoading: Ref<boolean>;\n error: Ref<Error | null>;\n refresh: () => Promise<void>;\n}\n\n/**\n * Vue composable for fetching active ads\n *\n * @example\n * ```vue\n * <script setup>\n * import { useActiveAd } from '@adspace/sdk/vue';\n *\n * const { ad, isLoading, error } = useActiveAd(1, {\n * refreshInterval: 30\n * });\n * </script>\n *\n * <template>\n * <div v-if=\"isLoading\">Loading...</div>\n * <div v-else-if=\"error\">Error: {{ error.message }}</div>\n * <a v-else-if=\"ad\" :href=\"ad.advertiserSiteLink\" target=\"_blank\">\n * <img :src=\"ad.imageUrl\" alt=\"Advertisement\" />\n * </a>\n * <div v-else>No ad available</div>\n * </template>\n * ```\n */\nexport function useActiveAd(\n spaceId: number | Ref<number>,\n options: UseActiveAdOptions = {}\n): UseActiveAdReturn {\n const clientRef = inject(AdSpaceClientKey);\n if (!clientRef) {\n throw new Error('AdSpacePlugin must be installed before using useActiveAd');\n }\n const client = clientRef.value;\n\n const ad = ref<ActiveAd | null>(null);\n const isLoading = ref(true);\n const error = ref<Error | null>(null);\n\n let intervalId: ReturnType<typeof setInterval> | null = null;\n\n const { refreshInterval = 0, onLoad, onError } = options;\n\n const resolvedSpaceId = computed(() =>\n typeof spaceId === 'number' ? spaceId : spaceId.value\n );\n\n const fetchAd = async () => {\n try {\n isLoading.value = true;\n error.value = null;\n\n const activeAd = await client.getActiveAd(resolvedSpaceId.value);\n ad.value = activeAd;\n\n if (activeAd && onLoad) {\n onLoad(activeAd);\n }\n } catch (err) {\n const e = err instanceof Error ? err : new Error(String(err));\n error.value = e;\n if (onError) {\n onError(e);\n }\n } finally {\n isLoading.value = false;\n }\n };\n\n const startPolling = () => {\n if (refreshInterval > 0) {\n intervalId = setInterval(fetchAd, refreshInterval * 1000);\n }\n };\n\n const stopPolling = () => {\n if (intervalId) {\n clearInterval(intervalId);\n intervalId = null;\n }\n };\n\n // Watch for spaceId changes\n watch(resolvedSpaceId, () => {\n stopPolling();\n fetchAd();\n startPolling();\n });\n\n onMounted(() => {\n fetchAd();\n startPolling();\n });\n\n onUnmounted(() => {\n stopPolling();\n });\n\n return {\n ad,\n isLoading,\n error,\n refresh: fetchAd,\n };\n}\n","<script setup lang=\"ts\">\nimport { computed, CSSProperties } from 'vue';\nimport { useActiveAd } from '../composables/useActiveAd';\nimport { ActiveAd } from '../../core/types';\n\ninterface Props {\n spaceId: number;\n width?: string;\n height?: string;\n refreshInterval?: number;\n}\n\ninterface Emits {\n (e: 'load', ad: ActiveAd): void;\n (e: 'error', error: Error): void;\n (e: 'click', ad: ActiveAd, event: MouseEvent): void;\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n width: '100%',\n height: 'auto',\n refreshInterval: 30,\n});\n\nconst emit = defineEmits<Emits>();\n\nconst { ad, isLoading, error } = useActiveAd(props.spaceId, {\n refreshInterval: props.refreshInterval,\n onLoad: (ad) => emit('load', ad),\n onError: (err) => emit('error', err),\n});\n\nconst containerStyle = computed<CSSProperties>(() => ({\n width: props.width,\n height: props.height,\n minHeight: props.height === 'auto' ? '100px' : props.height,\n overflow: 'hidden',\n position: 'relative',\n}));\n\nconst handleClick = (event: MouseEvent) => {\n if (ad.value) {\n emit('click', ad.value, event);\n }\n};\n</script>\n\n<template>\n <div :style=\"containerStyle\">\n <!-- Loading state -->\n <div\n v-if=\"isLoading && !ad\"\n style=\"display: flex; align-items: center; justify-content: center; height: 100%; color: #666\"\n >\n <slot name=\"loading\">Loading...</slot>\n </div>\n\n <!-- Error state -->\n <div\n v-else-if=\"error\"\n style=\"display: flex; align-items: center; justify-content: center; height: 100%; color: #f00\"\n >\n <slot name=\"error\" :error=\"error\">Failed to load ad</slot>\n </div>\n\n <!-- Empty state -->\n <div\n v-else-if=\"!ad\"\n style=\"display: flex; align-items: center; justify-content: center; height: 100%; color: #999\"\n >\n <slot name=\"empty\">No ad available</slot>\n </div>\n\n <!-- Ad display -->\n <a\n v-else\n :href=\"ad.advertiserSiteLink || '#'\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n style=\"display: block; width: 100%; height: 100%; text-decoration: none\"\n @click=\"handleClick\"\n >\n <img\n :src=\"ad.imageUrl\"\n alt=\"Advertisement\"\n style=\"width: 100%; height: auto; display: block; max-width: 100%\"\n />\n </a>\n </div>\n</template>\n"],"names":["AdSpaceClientKey","AdSpacePlugin","app","options","client","shallowRef","AdSpaceClient","useAdSpaceClient","inject","useActiveAd","spaceId","clientRef","ad","ref","isLoading","error","intervalId","refreshInterval","onLoad","onError","resolvedSpaceId","computed","fetchAd","activeAd","err","e","startPolling","stopPolling","watch","onMounted","onUnmounted","props","__props","emit","__emit","containerStyle","handleClick","event","_createElementBlock","_unref","_openBlock","_hoisted_1","_renderSlot","_ctx","_hoisted_2","_createElementVNode","_hoisted_3"],"mappings":"4IAIaA,EAAqD,OAAO,eAAe,EAuB3EC,EAAgB,CAC3B,QAAQC,EAAUC,EAAgC,GAAI,CACpD,MAAMC,EAASC,EAAAA,WACbF,EAAQ,QAAU,IAAIG,EAAAA,cAAcH,EAAQ,MAAM,CAAA,EAGpDD,EAAI,QAAQF,EAAkBI,CAAM,EAGpCF,EAAI,OAAO,iBAAiB,SAAWE,EAAO,KAChD,CACF,EAKO,SAASG,GAAkC,CAChD,MAAMH,EAASI,EAAAA,OAAOR,CAAgB,EACtC,GAAI,CAACI,EACH,MAAM,IAAI,MAAM,+DAA+D,EAEjF,OAAOA,EAAO,KAChB,CCTO,SAASK,EACdC,EACAP,EAA8B,GACX,CACnB,MAAMQ,EAAYH,EAAAA,OAAOR,CAAgB,EACzC,GAAI,CAACW,EACH,MAAM,IAAI,MAAM,0DAA0D,EAE5E,MAAMP,EAASO,EAAU,MAEnBC,EAAKC,EAAAA,IAAqB,IAAI,EAC9BC,EAAYD,EAAAA,IAAI,EAAI,EACpBE,EAAQF,EAAAA,IAAkB,IAAI,EAEpC,IAAIG,EAAoD,KAExD,KAAM,CAAE,gBAAAC,EAAkB,EAAG,OAAAC,EAAQ,QAAAC,GAAYhB,EAE3CiB,EAAkBC,EAAAA,SAAS,IAC/B,OAAOX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ACLqB,EAAK,QAASrB,EAAG,MAAOyB,CAAK,CAEjC,8BAIEC,EAAAA,mBAwCM,MAAA,CAxCA,uBAAOH,EAAA,KAAc,CAAA,GAGjBI,QAAAzB,CAAA,IAAcyB,QAAA3B,CAAA,GADtB4B,EAAAA,YAAAF,EAAAA,mBAKM,MALNG,EAKM,CADJC,EAAAA,WAAsCC,sBAAtC,IAAsC,+BAAjB,aAAU,EAAA,EAAA,MAKpBJ,EAAAA,MAAAxB,CAAA,GADbyB,EAAAA,UAAA,EAAAF,EAAAA,mBAKM,MALNM,EAKM,CADJF,aAA0DC,EAAA,OAAA,QAAA,CAAtC,MAAOJ,EAAAA,MAAAxB,CAAA,CAAA,EAA3B,IAA0D,+BAAxB,oBAAiB,EAAA,EAAA,MAKvCwB,EAAAA,MAAA3B,CAAA,iBAOd0B,EAAAA,mBAaI,IAAA,OAXD,KAAMC,EAAAA,MAAA3B,CAAA,EAAG,oBAAkB,IAC5B,OAAO,SACP,IAAI,sBACJ,MAAA,CAAA,QAAA,QAAA,MAAA,OAAA,OAAA,OAAA,kBAAA,MAAA,EACC,QAAOwB,CAAA,GAERS,EAAAA,mBAIE,MAAA,CAHC,IAAKN,EAAAA,MAAA3B,CAAA,EAAG,SACT,IAAI,gBACJ,MAAA,CAAA,MAAA,OAAA,OAAA,OAAA,QAAA,QAAA,YAAA,MAAA,CAAA,oBAnBJ4B,EAAAA,UAAA,EAAAF,EAAAA,mBAKM,MALNQ,EAKM,CADJJ,EAAAA,WAAyCC,oBAAzC,IAAyC,+BAAtB,kBAAe,EAAA,EAAA"}
|
package/dist/vue.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * from './index';
|
|
2
|
+
export { AdSpacePlugin, AdSpaceClientKey, useAdSpaceClient, } from './vue/plugin';
|
|
3
|
+
export type { AdSpacePluginOptions } from './vue/plugin';
|
|
4
|
+
export { useActiveAd } from './vue/composables';
|
|
5
|
+
export type { UseActiveAdOptions, UseActiveAdReturn } from './vue/composables';
|
|
6
|
+
export { AdWidget } from './vue/components';
|
|
7
|
+
//# sourceMappingURL=vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.d.ts","sourceRoot":"","sources":["../src/vue.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE/E,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/vue.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { a as E } from "./campaign-8I-L9KNW.js";
|
|
2
|
+
import { A as O, C as q, D as J, c as Q, b as X, e as Y, f as Z, g as ee, d as te, h as ne, i as ie, j as oe, r as re } from "./campaign-8I-L9KNW.js";
|
|
3
|
+
import { shallowRef as _, inject as b, ref as v, computed as I, watch as P, onMounted as x, onUnmounted as L, defineComponent as j, openBlock as f, createElementBlock as g, normalizeStyle as D, unref as a, renderSlot as m, createTextVNode as A, createElementVNode as F } from "vue";
|
|
4
|
+
const y = Symbol("AdSpaceClient"), V = {
|
|
5
|
+
install(n, l = {}) {
|
|
6
|
+
const e = _(
|
|
7
|
+
l.client || new E(l.config)
|
|
8
|
+
);
|
|
9
|
+
n.provide(y, e), n.config.globalProperties.$adspace = e.value;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
function W() {
|
|
13
|
+
const n = b(y);
|
|
14
|
+
if (!n)
|
|
15
|
+
throw new Error("AdSpacePlugin must be installed before using useAdSpaceClient");
|
|
16
|
+
return n.value;
|
|
17
|
+
}
|
|
18
|
+
function N(n, l = {}) {
|
|
19
|
+
const e = b(y);
|
|
20
|
+
if (!e)
|
|
21
|
+
throw new Error("AdSpacePlugin must be installed before using useActiveAd");
|
|
22
|
+
const d = e.value, i = v(null), u = v(!0), s = v(null);
|
|
23
|
+
let c = null;
|
|
24
|
+
const { refreshInterval: h = 0, onLoad: t, onError: o } = l, S = I(
|
|
25
|
+
() => typeof n == "number" ? n : n.value
|
|
26
|
+
), p = async () => {
|
|
27
|
+
try {
|
|
28
|
+
u.value = !0, s.value = null;
|
|
29
|
+
const r = await d.getActiveAd(S.value);
|
|
30
|
+
i.value = r, r && t && t(r);
|
|
31
|
+
} catch (r) {
|
|
32
|
+
const k = r instanceof Error ? r : new Error(String(r));
|
|
33
|
+
s.value = k, o && o(k);
|
|
34
|
+
} finally {
|
|
35
|
+
u.value = !1;
|
|
36
|
+
}
|
|
37
|
+
}, C = () => {
|
|
38
|
+
h > 0 && (c = setInterval(p, h * 1e3));
|
|
39
|
+
}, w = () => {
|
|
40
|
+
c && (clearInterval(c), c = null);
|
|
41
|
+
};
|
|
42
|
+
return P(S, () => {
|
|
43
|
+
w(), p(), C();
|
|
44
|
+
}), x(() => {
|
|
45
|
+
p(), C();
|
|
46
|
+
}), L(() => {
|
|
47
|
+
w();
|
|
48
|
+
}), {
|
|
49
|
+
ad: i,
|
|
50
|
+
isLoading: u,
|
|
51
|
+
error: s,
|
|
52
|
+
refresh: p
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const R = {
|
|
56
|
+
key: 0,
|
|
57
|
+
style: { display: "flex", "align-items": "center", "justify-content": "center", height: "100%", color: "#666" }
|
|
58
|
+
}, U = {
|
|
59
|
+
key: 1,
|
|
60
|
+
style: { display: "flex", "align-items": "center", "justify-content": "center", height: "100%", color: "#f00" }
|
|
61
|
+
}, $ = {
|
|
62
|
+
key: 2,
|
|
63
|
+
style: { display: "flex", "align-items": "center", "justify-content": "center", height: "100%", color: "#999" }
|
|
64
|
+
}, B = ["href"], T = ["src"], z = /* @__PURE__ */ j({
|
|
65
|
+
__name: "AdWidget",
|
|
66
|
+
props: {
|
|
67
|
+
spaceId: {},
|
|
68
|
+
width: { default: "100%" },
|
|
69
|
+
height: { default: "auto" },
|
|
70
|
+
refreshInterval: { default: 30 }
|
|
71
|
+
},
|
|
72
|
+
emits: ["load", "error", "click"],
|
|
73
|
+
setup(n, { emit: l }) {
|
|
74
|
+
const e = n, d = l, { ad: i, isLoading: u, error: s } = N(e.spaceId, {
|
|
75
|
+
refreshInterval: e.refreshInterval,
|
|
76
|
+
onLoad: (t) => d("load", t),
|
|
77
|
+
onError: (t) => d("error", t)
|
|
78
|
+
}), c = I(() => ({
|
|
79
|
+
width: e.width,
|
|
80
|
+
height: e.height,
|
|
81
|
+
minHeight: e.height === "auto" ? "100px" : e.height,
|
|
82
|
+
overflow: "hidden",
|
|
83
|
+
position: "relative"
|
|
84
|
+
})), h = (t) => {
|
|
85
|
+
i.value && d("click", i.value, t);
|
|
86
|
+
};
|
|
87
|
+
return (t, o) => (f(), g("div", {
|
|
88
|
+
style: D(c.value)
|
|
89
|
+
}, [
|
|
90
|
+
a(u) && !a(i) ? (f(), g("div", R, [
|
|
91
|
+
m(t.$slots, "loading", {}, () => [
|
|
92
|
+
o[0] || (o[0] = A("Loading...", -1))
|
|
93
|
+
])
|
|
94
|
+
])) : a(s) ? (f(), g("div", U, [
|
|
95
|
+
m(t.$slots, "error", { error: a(s) }, () => [
|
|
96
|
+
o[1] || (o[1] = A("Failed to load ad", -1))
|
|
97
|
+
])
|
|
98
|
+
])) : a(i) ? (f(), g("a", {
|
|
99
|
+
key: 3,
|
|
100
|
+
href: a(i).advertiserSiteLink || "#",
|
|
101
|
+
target: "_blank",
|
|
102
|
+
rel: "noopener noreferrer",
|
|
103
|
+
style: { display: "block", width: "100%", height: "100%", "text-decoration": "none" },
|
|
104
|
+
onClick: h
|
|
105
|
+
}, [
|
|
106
|
+
F("img", {
|
|
107
|
+
src: a(i).imageUrl,
|
|
108
|
+
alt: "Advertisement",
|
|
109
|
+
style: { width: "100%", height: "auto", display: "block", "max-width": "100%" }
|
|
110
|
+
}, null, 8, T)
|
|
111
|
+
], 8, B)) : (f(), g("div", $, [
|
|
112
|
+
m(t.$slots, "empty", {}, () => [
|
|
113
|
+
o[2] || (o[2] = A("No ad available", -1))
|
|
114
|
+
])
|
|
115
|
+
]))
|
|
116
|
+
], 4));
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
export {
|
|
120
|
+
O as AD_SPACE_MANAGER_ABI,
|
|
121
|
+
E as AdSpaceClient,
|
|
122
|
+
y as AdSpaceClientKey,
|
|
123
|
+
V as AdSpacePlugin,
|
|
124
|
+
z as AdWidget,
|
|
125
|
+
q as CampaignStatus,
|
|
126
|
+
J as DEFAULT_CONFIG,
|
|
127
|
+
Q as createAdSpaceClient,
|
|
128
|
+
X as createConfig,
|
|
129
|
+
Y as extractCID,
|
|
130
|
+
Z as formatDuration,
|
|
131
|
+
ee as getCampaignStatusLabel,
|
|
132
|
+
te as getCampaignTimeRemaining,
|
|
133
|
+
ne as getEffectiveCampaignStatus,
|
|
134
|
+
ie as isCampaignActive,
|
|
135
|
+
oe as isIPFSReference,
|
|
136
|
+
re as resolveIPFSUrl,
|
|
137
|
+
N as useActiveAd,
|
|
138
|
+
W as useAdSpaceClient
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=vue.js.map
|
package/dist/vue.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue.js","sources":["../src/vue/plugin.ts","../src/vue/composables/useActiveAd.ts","../src/vue/components/AdWidget.vue"],"sourcesContent":["import { App, InjectionKey, Ref, shallowRef, inject } from 'vue';\nimport { AdSpaceClient } from '../core/client';\nimport { AdSpaceConfig } from '../core/config';\n\nexport const AdSpaceClientKey: InjectionKey<Ref<AdSpaceClient>> = Symbol('AdSpaceClient');\n\nexport interface AdSpacePluginOptions {\n config?: Partial<AdSpaceConfig>;\n client?: AdSpaceClient;\n}\n\n/**\n * Vue plugin for AdSpace SDK\n *\n * @example\n * ```typescript\n * import { createApp } from 'vue';\n * import { AdSpacePlugin } from '@adspace/sdk/vue';\n *\n * const app = createApp(App);\n * app.use(AdSpacePlugin, {\n * config: {\n * network: { rpcUrl: '...' }\n * }\n * });\n * ```\n */\nexport const AdSpacePlugin = {\n install(app: App, options: AdSpacePluginOptions = {}) {\n const client = shallowRef(\n options.client || new AdSpaceClient(options.config)\n );\n\n app.provide(AdSpaceClientKey, client);\n\n // Also make available globally\n app.config.globalProperties.$adspace = client.value;\n },\n};\n\n/**\n * Composable to get the AdSpace client\n */\nexport function useAdSpaceClient(): AdSpaceClient {\n const client = inject(AdSpaceClientKey);\n if (!client) {\n throw new Error('AdSpacePlugin must be installed before using useAdSpaceClient');\n }\n return client.value;\n}\n","import { ref, watch, onMounted, onUnmounted, Ref, computed, inject } from 'vue';\nimport { AdSpaceClientKey } from '../plugin';\nimport { ActiveAd } from '../../core/types';\n\nexport interface UseActiveAdOptions {\n refreshInterval?: number;\n onLoad?: (ad: ActiveAd) => void;\n onError?: (error: Error) => void;\n}\n\nexport interface UseActiveAdReturn {\n ad: Ref<ActiveAd | null>;\n isLoading: Ref<boolean>;\n error: Ref<Error | null>;\n refresh: () => Promise<void>;\n}\n\n/**\n * Vue composable for fetching active ads\n *\n * @example\n * ```vue\n * <script setup>\n * import { useActiveAd } from '@adspace/sdk/vue';\n *\n * const { ad, isLoading, error } = useActiveAd(1, {\n * refreshInterval: 30\n * });\n * </script>\n *\n * <template>\n * <div v-if=\"isLoading\">Loading...</div>\n * <div v-else-if=\"error\">Error: {{ error.message }}</div>\n * <a v-else-if=\"ad\" :href=\"ad.advertiserSiteLink\" target=\"_blank\">\n * <img :src=\"ad.imageUrl\" alt=\"Advertisement\" />\n * </a>\n * <div v-else>No ad available</div>\n * </template>\n * ```\n */\nexport function useActiveAd(\n spaceId: number | Ref<number>,\n options: UseActiveAdOptions = {}\n): UseActiveAdReturn {\n const clientRef = inject(AdSpaceClientKey);\n if (!clientRef) {\n throw new Error('AdSpacePlugin must be installed before using useActiveAd');\n }\n const client = clientRef.value;\n\n const ad = ref<ActiveAd | null>(null);\n const isLoading = ref(true);\n const error = ref<Error | null>(null);\n\n let intervalId: ReturnType<typeof setInterval> | null = null;\n\n const { refreshInterval = 0, onLoad, onError } = options;\n\n const resolvedSpaceId = computed(() =>\n typeof spaceId === 'number' ? spaceId : spaceId.value\n );\n\n const fetchAd = async () => {\n try {\n isLoading.value = true;\n error.value = null;\n\n const activeAd = await client.getActiveAd(resolvedSpaceId.value);\n ad.value = activeAd;\n\n if (activeAd && onLoad) {\n onLoad(activeAd);\n }\n } catch (err) {\n const e = err instanceof Error ? err : new Error(String(err));\n error.value = e;\n if (onError) {\n onError(e);\n }\n } finally {\n isLoading.value = false;\n }\n };\n\n const startPolling = () => {\n if (refreshInterval > 0) {\n intervalId = setInterval(fetchAd, refreshInterval * 1000);\n }\n };\n\n const stopPolling = () => {\n if (intervalId) {\n clearInterval(intervalId);\n intervalId = null;\n }\n };\n\n // Watch for spaceId changes\n watch(resolvedSpaceId, () => {\n stopPolling();\n fetchAd();\n startPolling();\n });\n\n onMounted(() => {\n fetchAd();\n startPolling();\n });\n\n onUnmounted(() => {\n stopPolling();\n });\n\n return {\n ad,\n isLoading,\n error,\n refresh: fetchAd,\n };\n}\n","<script setup lang=\"ts\">\nimport { computed, CSSProperties } from 'vue';\nimport { useActiveAd } from '../composables/useActiveAd';\nimport { ActiveAd } from '../../core/types';\n\ninterface Props {\n spaceId: number;\n width?: string;\n height?: string;\n refreshInterval?: number;\n}\n\ninterface Emits {\n (e: 'load', ad: ActiveAd): void;\n (e: 'error', error: Error): void;\n (e: 'click', ad: ActiveAd, event: MouseEvent): void;\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n width: '100%',\n height: 'auto',\n refreshInterval: 30,\n});\n\nconst emit = defineEmits<Emits>();\n\nconst { ad, isLoading, error } = useActiveAd(props.spaceId, {\n refreshInterval: props.refreshInterval,\n onLoad: (ad) => emit('load', ad),\n onError: (err) => emit('error', err),\n});\n\nconst containerStyle = computed<CSSProperties>(() => ({\n width: props.width,\n height: props.height,\n minHeight: props.height === 'auto' ? '100px' : props.height,\n overflow: 'hidden',\n position: 'relative',\n}));\n\nconst handleClick = (event: MouseEvent) => {\n if (ad.value) {\n emit('click', ad.value, event);\n }\n};\n</script>\n\n<template>\n <div :style=\"containerStyle\">\n <!-- Loading state -->\n <div\n v-if=\"isLoading && !ad\"\n style=\"display: flex; align-items: center; justify-content: center; height: 100%; color: #666\"\n >\n <slot name=\"loading\">Loading...</slot>\n </div>\n\n <!-- Error state -->\n <div\n v-else-if=\"error\"\n style=\"display: flex; align-items: center; justify-content: center; height: 100%; color: #f00\"\n >\n <slot name=\"error\" :error=\"error\">Failed to load ad</slot>\n </div>\n\n <!-- Empty state -->\n <div\n v-else-if=\"!ad\"\n style=\"display: flex; align-items: center; justify-content: center; height: 100%; color: #999\"\n >\n <slot name=\"empty\">No ad available</slot>\n </div>\n\n <!-- Ad display -->\n <a\n v-else\n :href=\"ad.advertiserSiteLink || '#'\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n style=\"display: block; width: 100%; height: 100%; text-decoration: none\"\n @click=\"handleClick\"\n >\n <img\n :src=\"ad.imageUrl\"\n alt=\"Advertisement\"\n style=\"width: 100%; height: auto; display: block; max-width: 100%\"\n />\n </a>\n </div>\n</template>\n"],"names":["AdSpaceClientKey","AdSpacePlugin","app","options","client","shallowRef","AdSpaceClient","useAdSpaceClient","inject","useActiveAd","spaceId","clientRef","ad","ref","isLoading","error","intervalId","refreshInterval","onLoad","onError","resolvedSpaceId","computed","fetchAd","activeAd","err","e","startPolling","stopPolling","watch","onMounted","onUnmounted","props","__props","emit","__emit","containerStyle","handleClick","event","_createElementBlock","_unref","_openBlock","_hoisted_1","_renderSlot","_ctx","_hoisted_2","_createElementVNode","_hoisted_3"],"mappings":";;;AAIO,MAAMA,IAAqD,OAAO,eAAe,GAuB3EC,IAAgB;AAAA,EAC3B,QAAQC,G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