@adsterra-ad/vue 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/dist/index.cjs +179 -0
- package/dist/index.d.cts +147 -0
- package/dist/index.d.ts +147 -0
- package/dist/index.js +157 -0
- package/package.json +37 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
AdBanner: () => AdBanner,
|
|
24
|
+
AdContainer: () => AdContainer,
|
|
25
|
+
configureAds: () => import_core.configureAds,
|
|
26
|
+
default: () => index_default
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
var import_vue = require("vue");
|
|
30
|
+
var import_core = require("@adsterra-ad/core");
|
|
31
|
+
var AdBanner = (0, import_vue.defineComponent)({
|
|
32
|
+
name: "AdBanner",
|
|
33
|
+
props: {
|
|
34
|
+
format: { type: String, required: true },
|
|
35
|
+
provider: { type: String, default: "adsterra" },
|
|
36
|
+
adKey: { type: String, default: "" },
|
|
37
|
+
adLabel: { type: String, default: "Advertisement" },
|
|
38
|
+
showAdLabel: { type: Boolean, default: true },
|
|
39
|
+
adLabelPosition: { type: String, default: "top-left" },
|
|
40
|
+
className: { type: String, default: "" }
|
|
41
|
+
},
|
|
42
|
+
emits: ["load", "error"],
|
|
43
|
+
setup(props, { emit }) {
|
|
44
|
+
const bannerId = (0, import_core.createBannerId)();
|
|
45
|
+
const adLoaded = (0, import_vue.ref)(false);
|
|
46
|
+
const adFailed = (0, import_vue.ref)(false);
|
|
47
|
+
const activeProvider = (0, import_vue.ref)(props.provider);
|
|
48
|
+
(0, import_vue.watch)(() => props.provider, (next) => {
|
|
49
|
+
activeProvider.value = next;
|
|
50
|
+
});
|
|
51
|
+
const config = (0, import_vue.computed)(() => (0, import_core.resolveAdConfig)(props.format, props.adKey || void 0));
|
|
52
|
+
const srcDoc = (0, import_vue.computed)(
|
|
53
|
+
() => (0, import_core.buildSrcDoc)({ format: props.format, provider: activeProvider.value, config: config.value, bannerId })
|
|
54
|
+
);
|
|
55
|
+
const style = (0, import_vue.computed)(() => ({
|
|
56
|
+
width: typeof config.value.width === "number" ? `${config.value.width}px` : config.value.width,
|
|
57
|
+
height: typeof config.value.height === "number" ? `${config.value.height}px` : config.value.height,
|
|
58
|
+
overflow: "hidden",
|
|
59
|
+
borderRadius: "6px",
|
|
60
|
+
border: "1px solid #e5e7eb",
|
|
61
|
+
background: "#f3f4f6",
|
|
62
|
+
display: "flex",
|
|
63
|
+
alignItems: "center",
|
|
64
|
+
justifyContent: "center"
|
|
65
|
+
}));
|
|
66
|
+
const wrapperStyle = (0, import_vue.computed)(() => ({
|
|
67
|
+
display: "inline-flex",
|
|
68
|
+
flexDirection: "column",
|
|
69
|
+
alignItems: props.adLabelPosition.endsWith("left") ? "flex-start" : props.adLabelPosition.endsWith("right") ? "flex-end" : "center"
|
|
70
|
+
}));
|
|
71
|
+
const labelStyle = (0, import_vue.computed)(() => ({
|
|
72
|
+
fontSize: "10px",
|
|
73
|
+
fontWeight: "600",
|
|
74
|
+
letterSpacing: "0.1em",
|
|
75
|
+
textTransform: "uppercase",
|
|
76
|
+
color: "#9ca3af",
|
|
77
|
+
marginBottom: props.adLabelPosition.startsWith("top") ? "4px" : "0",
|
|
78
|
+
marginTop: props.adLabelPosition.startsWith("bottom") ? "4px" : "0",
|
|
79
|
+
textAlign: props.adLabelPosition.endsWith("left") ? "left" : props.adLabelPosition.endsWith("right") ? "right" : "center",
|
|
80
|
+
width: "100%"
|
|
81
|
+
}));
|
|
82
|
+
const visibilityStyle = (0, import_vue.computed)(
|
|
83
|
+
() => adLoaded.value ? { opacity: "1", transform: "scale(1)" } : {
|
|
84
|
+
opacity: "0",
|
|
85
|
+
transform: "scale(0.95)",
|
|
86
|
+
pointerEvents: "none",
|
|
87
|
+
position: "absolute",
|
|
88
|
+
width: "0",
|
|
89
|
+
height: "0",
|
|
90
|
+
overflow: "hidden"
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
const onMessage = (event) => {
|
|
94
|
+
const data = event.data;
|
|
95
|
+
if (!data || data.bannerId !== bannerId) return;
|
|
96
|
+
if (data.type === "ad-load-success") {
|
|
97
|
+
adLoaded.value = true;
|
|
98
|
+
emit("load");
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (data.type === "ad-load-error") {
|
|
102
|
+
adFailed.value = true;
|
|
103
|
+
emit("error");
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
(0, import_vue.onMounted)(() => window.addEventListener("message", onMessage));
|
|
107
|
+
(0, import_vue.onUnmounted)(() => window.removeEventListener("message", onMessage));
|
|
108
|
+
return () => {
|
|
109
|
+
if (adFailed.value) return null;
|
|
110
|
+
const topLabel = props.showAdLabel && props.adLabelPosition.startsWith("top");
|
|
111
|
+
const bottomLabel = props.showAdLabel && props.adLabelPosition.startsWith("bottom");
|
|
112
|
+
return (0, import_vue.h)("div", { class: props.className, style: { ...wrapperStyle.value, ...visibilityStyle.value } }, [
|
|
113
|
+
topLabel ? (0, import_vue.h)("span", { style: labelStyle.value }, props.adLabel) : null,
|
|
114
|
+
(0, import_vue.h)("div", { "data-testid": "ad-banner", style: style.value }, [
|
|
115
|
+
(0, import_vue.h)("iframe", {
|
|
116
|
+
title: "Advertisement",
|
|
117
|
+
srcdoc: srcDoc.value,
|
|
118
|
+
frameborder: "0",
|
|
119
|
+
scrolling: "no",
|
|
120
|
+
sandbox: "allow-scripts allow-forms allow-same-origin allow-popups allow-modals"
|
|
121
|
+
})
|
|
122
|
+
]),
|
|
123
|
+
bottomLabel ? (0, import_vue.h)("span", { style: labelStyle.value }, props.adLabel) : null
|
|
124
|
+
]);
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
var AdContainer = (0, import_vue.defineComponent)({
|
|
129
|
+
name: "AdContainer",
|
|
130
|
+
props: {
|
|
131
|
+
format: { type: String, required: true },
|
|
132
|
+
provider: { type: String, default: "adsterra" },
|
|
133
|
+
adKey: { type: String, default: "" },
|
|
134
|
+
className: { type: String, default: "" },
|
|
135
|
+
adLabel: { type: String, default: "Advertisement" },
|
|
136
|
+
showAdLabel: { type: Boolean, default: true },
|
|
137
|
+
adLabelPosition: { type: String, default: "top-left" }
|
|
138
|
+
},
|
|
139
|
+
setup(props) {
|
|
140
|
+
const adLoaded = (0, import_vue.ref)(false);
|
|
141
|
+
const adFailed = (0, import_vue.ref)(false);
|
|
142
|
+
return () => {
|
|
143
|
+
if (adFailed.value) return null;
|
|
144
|
+
const containerVisibilityStyle = adLoaded.value ? { opacity: "1", transform: "scale(1)" } : {
|
|
145
|
+
opacity: "0",
|
|
146
|
+
transform: "scale(0.95)",
|
|
147
|
+
pointerEvents: "none",
|
|
148
|
+
position: "absolute",
|
|
149
|
+
width: "0",
|
|
150
|
+
height: "0",
|
|
151
|
+
overflow: "hidden"
|
|
152
|
+
};
|
|
153
|
+
return (0, import_vue.h)("div", { style: containerVisibilityStyle }, [
|
|
154
|
+
(0, import_vue.h)(AdBanner, {
|
|
155
|
+
format: props.format,
|
|
156
|
+
provider: props.provider,
|
|
157
|
+
adKey: props.adKey,
|
|
158
|
+
className: props.className,
|
|
159
|
+
adLabel: props.adLabel,
|
|
160
|
+
showAdLabel: props.showAdLabel,
|
|
161
|
+
adLabelPosition: props.adLabelPosition,
|
|
162
|
+
onLoad: () => {
|
|
163
|
+
adLoaded.value = true;
|
|
164
|
+
},
|
|
165
|
+
onError: () => {
|
|
166
|
+
adFailed.value = true;
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
]);
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
var index_default = AdBanner;
|
|
174
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
+
0 && (module.exports = {
|
|
176
|
+
AdBanner,
|
|
177
|
+
AdContainer,
|
|
178
|
+
configureAds
|
|
179
|
+
});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { PropType } from 'vue';
|
|
3
|
+
import { AdFormat, AdProvider } from '@adsterra-ad/core';
|
|
4
|
+
export { configureAds } from '@adsterra-ad/core';
|
|
5
|
+
|
|
6
|
+
type AdLabelPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
7
|
+
declare const AdBanner: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
8
|
+
format: {
|
|
9
|
+
type: PropType<AdFormat>;
|
|
10
|
+
required: true;
|
|
11
|
+
};
|
|
12
|
+
provider: {
|
|
13
|
+
type: PropType<AdProvider>;
|
|
14
|
+
default: string;
|
|
15
|
+
};
|
|
16
|
+
adKey: {
|
|
17
|
+
type: StringConstructor;
|
|
18
|
+
default: string;
|
|
19
|
+
};
|
|
20
|
+
adLabel: {
|
|
21
|
+
type: StringConstructor;
|
|
22
|
+
default: string;
|
|
23
|
+
};
|
|
24
|
+
showAdLabel: {
|
|
25
|
+
type: BooleanConstructor;
|
|
26
|
+
default: boolean;
|
|
27
|
+
};
|
|
28
|
+
adLabelPosition: {
|
|
29
|
+
type: PropType<AdLabelPosition>;
|
|
30
|
+
default: string;
|
|
31
|
+
};
|
|
32
|
+
className: {
|
|
33
|
+
type: StringConstructor;
|
|
34
|
+
default: string;
|
|
35
|
+
};
|
|
36
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}> | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("load" | "error")[], "load" | "error", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
39
|
+
format: {
|
|
40
|
+
type: PropType<AdFormat>;
|
|
41
|
+
required: true;
|
|
42
|
+
};
|
|
43
|
+
provider: {
|
|
44
|
+
type: PropType<AdProvider>;
|
|
45
|
+
default: string;
|
|
46
|
+
};
|
|
47
|
+
adKey: {
|
|
48
|
+
type: StringConstructor;
|
|
49
|
+
default: string;
|
|
50
|
+
};
|
|
51
|
+
adLabel: {
|
|
52
|
+
type: StringConstructor;
|
|
53
|
+
default: string;
|
|
54
|
+
};
|
|
55
|
+
showAdLabel: {
|
|
56
|
+
type: BooleanConstructor;
|
|
57
|
+
default: boolean;
|
|
58
|
+
};
|
|
59
|
+
adLabelPosition: {
|
|
60
|
+
type: PropType<AdLabelPosition>;
|
|
61
|
+
default: string;
|
|
62
|
+
};
|
|
63
|
+
className: {
|
|
64
|
+
type: StringConstructor;
|
|
65
|
+
default: string;
|
|
66
|
+
};
|
|
67
|
+
}>> & Readonly<{
|
|
68
|
+
onLoad?: ((...args: any[]) => any) | undefined;
|
|
69
|
+
onError?: ((...args: any[]) => any) | undefined;
|
|
70
|
+
}>, {
|
|
71
|
+
provider: AdProvider;
|
|
72
|
+
adKey: string;
|
|
73
|
+
adLabel: string;
|
|
74
|
+
showAdLabel: boolean;
|
|
75
|
+
adLabelPosition: AdLabelPosition;
|
|
76
|
+
className: string;
|
|
77
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
78
|
+
declare const AdContainer: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
79
|
+
format: {
|
|
80
|
+
type: PropType<AdFormat>;
|
|
81
|
+
required: true;
|
|
82
|
+
};
|
|
83
|
+
provider: {
|
|
84
|
+
type: PropType<AdProvider>;
|
|
85
|
+
default: string;
|
|
86
|
+
};
|
|
87
|
+
adKey: {
|
|
88
|
+
type: StringConstructor;
|
|
89
|
+
default: string;
|
|
90
|
+
};
|
|
91
|
+
className: {
|
|
92
|
+
type: StringConstructor;
|
|
93
|
+
default: string;
|
|
94
|
+
};
|
|
95
|
+
adLabel: {
|
|
96
|
+
type: StringConstructor;
|
|
97
|
+
default: string;
|
|
98
|
+
};
|
|
99
|
+
showAdLabel: {
|
|
100
|
+
type: BooleanConstructor;
|
|
101
|
+
default: boolean;
|
|
102
|
+
};
|
|
103
|
+
adLabelPosition: {
|
|
104
|
+
type: PropType<AdLabelPosition>;
|
|
105
|
+
default: string;
|
|
106
|
+
};
|
|
107
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
108
|
+
[key: string]: any;
|
|
109
|
+
}> | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
110
|
+
format: {
|
|
111
|
+
type: PropType<AdFormat>;
|
|
112
|
+
required: true;
|
|
113
|
+
};
|
|
114
|
+
provider: {
|
|
115
|
+
type: PropType<AdProvider>;
|
|
116
|
+
default: string;
|
|
117
|
+
};
|
|
118
|
+
adKey: {
|
|
119
|
+
type: StringConstructor;
|
|
120
|
+
default: string;
|
|
121
|
+
};
|
|
122
|
+
className: {
|
|
123
|
+
type: StringConstructor;
|
|
124
|
+
default: string;
|
|
125
|
+
};
|
|
126
|
+
adLabel: {
|
|
127
|
+
type: StringConstructor;
|
|
128
|
+
default: string;
|
|
129
|
+
};
|
|
130
|
+
showAdLabel: {
|
|
131
|
+
type: BooleanConstructor;
|
|
132
|
+
default: boolean;
|
|
133
|
+
};
|
|
134
|
+
adLabelPosition: {
|
|
135
|
+
type: PropType<AdLabelPosition>;
|
|
136
|
+
default: string;
|
|
137
|
+
};
|
|
138
|
+
}>> & Readonly<{}>, {
|
|
139
|
+
provider: AdProvider;
|
|
140
|
+
adKey: string;
|
|
141
|
+
adLabel: string;
|
|
142
|
+
showAdLabel: boolean;
|
|
143
|
+
adLabelPosition: AdLabelPosition;
|
|
144
|
+
className: string;
|
|
145
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
146
|
+
|
|
147
|
+
export { AdBanner, AdContainer, AdBanner as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import * as vue from 'vue';
|
|
2
|
+
import { PropType } from 'vue';
|
|
3
|
+
import { AdFormat, AdProvider } from '@adsterra-ad/core';
|
|
4
|
+
export { configureAds } from '@adsterra-ad/core';
|
|
5
|
+
|
|
6
|
+
type AdLabelPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
7
|
+
declare const AdBanner: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
8
|
+
format: {
|
|
9
|
+
type: PropType<AdFormat>;
|
|
10
|
+
required: true;
|
|
11
|
+
};
|
|
12
|
+
provider: {
|
|
13
|
+
type: PropType<AdProvider>;
|
|
14
|
+
default: string;
|
|
15
|
+
};
|
|
16
|
+
adKey: {
|
|
17
|
+
type: StringConstructor;
|
|
18
|
+
default: string;
|
|
19
|
+
};
|
|
20
|
+
adLabel: {
|
|
21
|
+
type: StringConstructor;
|
|
22
|
+
default: string;
|
|
23
|
+
};
|
|
24
|
+
showAdLabel: {
|
|
25
|
+
type: BooleanConstructor;
|
|
26
|
+
default: boolean;
|
|
27
|
+
};
|
|
28
|
+
adLabelPosition: {
|
|
29
|
+
type: PropType<AdLabelPosition>;
|
|
30
|
+
default: string;
|
|
31
|
+
};
|
|
32
|
+
className: {
|
|
33
|
+
type: StringConstructor;
|
|
34
|
+
default: string;
|
|
35
|
+
};
|
|
36
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
37
|
+
[key: string]: any;
|
|
38
|
+
}> | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, ("load" | "error")[], "load" | "error", vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
39
|
+
format: {
|
|
40
|
+
type: PropType<AdFormat>;
|
|
41
|
+
required: true;
|
|
42
|
+
};
|
|
43
|
+
provider: {
|
|
44
|
+
type: PropType<AdProvider>;
|
|
45
|
+
default: string;
|
|
46
|
+
};
|
|
47
|
+
adKey: {
|
|
48
|
+
type: StringConstructor;
|
|
49
|
+
default: string;
|
|
50
|
+
};
|
|
51
|
+
adLabel: {
|
|
52
|
+
type: StringConstructor;
|
|
53
|
+
default: string;
|
|
54
|
+
};
|
|
55
|
+
showAdLabel: {
|
|
56
|
+
type: BooleanConstructor;
|
|
57
|
+
default: boolean;
|
|
58
|
+
};
|
|
59
|
+
adLabelPosition: {
|
|
60
|
+
type: PropType<AdLabelPosition>;
|
|
61
|
+
default: string;
|
|
62
|
+
};
|
|
63
|
+
className: {
|
|
64
|
+
type: StringConstructor;
|
|
65
|
+
default: string;
|
|
66
|
+
};
|
|
67
|
+
}>> & Readonly<{
|
|
68
|
+
onLoad?: ((...args: any[]) => any) | undefined;
|
|
69
|
+
onError?: ((...args: any[]) => any) | undefined;
|
|
70
|
+
}>, {
|
|
71
|
+
provider: AdProvider;
|
|
72
|
+
adKey: string;
|
|
73
|
+
adLabel: string;
|
|
74
|
+
showAdLabel: boolean;
|
|
75
|
+
adLabelPosition: AdLabelPosition;
|
|
76
|
+
className: string;
|
|
77
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
78
|
+
declare const AdContainer: vue.DefineComponent<vue.ExtractPropTypes<{
|
|
79
|
+
format: {
|
|
80
|
+
type: PropType<AdFormat>;
|
|
81
|
+
required: true;
|
|
82
|
+
};
|
|
83
|
+
provider: {
|
|
84
|
+
type: PropType<AdProvider>;
|
|
85
|
+
default: string;
|
|
86
|
+
};
|
|
87
|
+
adKey: {
|
|
88
|
+
type: StringConstructor;
|
|
89
|
+
default: string;
|
|
90
|
+
};
|
|
91
|
+
className: {
|
|
92
|
+
type: StringConstructor;
|
|
93
|
+
default: string;
|
|
94
|
+
};
|
|
95
|
+
adLabel: {
|
|
96
|
+
type: StringConstructor;
|
|
97
|
+
default: string;
|
|
98
|
+
};
|
|
99
|
+
showAdLabel: {
|
|
100
|
+
type: BooleanConstructor;
|
|
101
|
+
default: boolean;
|
|
102
|
+
};
|
|
103
|
+
adLabelPosition: {
|
|
104
|
+
type: PropType<AdLabelPosition>;
|
|
105
|
+
default: string;
|
|
106
|
+
};
|
|
107
|
+
}>, () => vue.VNode<vue.RendererNode, vue.RendererElement, {
|
|
108
|
+
[key: string]: any;
|
|
109
|
+
}> | null, {}, {}, {}, vue.ComponentOptionsMixin, vue.ComponentOptionsMixin, {}, string, vue.PublicProps, Readonly<vue.ExtractPropTypes<{
|
|
110
|
+
format: {
|
|
111
|
+
type: PropType<AdFormat>;
|
|
112
|
+
required: true;
|
|
113
|
+
};
|
|
114
|
+
provider: {
|
|
115
|
+
type: PropType<AdProvider>;
|
|
116
|
+
default: string;
|
|
117
|
+
};
|
|
118
|
+
adKey: {
|
|
119
|
+
type: StringConstructor;
|
|
120
|
+
default: string;
|
|
121
|
+
};
|
|
122
|
+
className: {
|
|
123
|
+
type: StringConstructor;
|
|
124
|
+
default: string;
|
|
125
|
+
};
|
|
126
|
+
adLabel: {
|
|
127
|
+
type: StringConstructor;
|
|
128
|
+
default: string;
|
|
129
|
+
};
|
|
130
|
+
showAdLabel: {
|
|
131
|
+
type: BooleanConstructor;
|
|
132
|
+
default: boolean;
|
|
133
|
+
};
|
|
134
|
+
adLabelPosition: {
|
|
135
|
+
type: PropType<AdLabelPosition>;
|
|
136
|
+
default: string;
|
|
137
|
+
};
|
|
138
|
+
}>> & Readonly<{}>, {
|
|
139
|
+
provider: AdProvider;
|
|
140
|
+
adKey: string;
|
|
141
|
+
adLabel: string;
|
|
142
|
+
showAdLabel: boolean;
|
|
143
|
+
adLabelPosition: AdLabelPosition;
|
|
144
|
+
className: string;
|
|
145
|
+
}, {}, {}, {}, string, vue.ComponentProvideOptions, true, {}, any>;
|
|
146
|
+
|
|
147
|
+
export { AdBanner, AdContainer, AdBanner as default };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { defineComponent, h, onMounted, onUnmounted, ref, watch, computed } from "vue";
|
|
3
|
+
import {
|
|
4
|
+
buildSrcDoc,
|
|
5
|
+
configureAds,
|
|
6
|
+
createBannerId,
|
|
7
|
+
resolveAdConfig
|
|
8
|
+
} from "@adsterra-ad/core";
|
|
9
|
+
var AdBanner = defineComponent({
|
|
10
|
+
name: "AdBanner",
|
|
11
|
+
props: {
|
|
12
|
+
format: { type: String, required: true },
|
|
13
|
+
provider: { type: String, default: "adsterra" },
|
|
14
|
+
adKey: { type: String, default: "" },
|
|
15
|
+
adLabel: { type: String, default: "Advertisement" },
|
|
16
|
+
showAdLabel: { type: Boolean, default: true },
|
|
17
|
+
adLabelPosition: { type: String, default: "top-left" },
|
|
18
|
+
className: { type: String, default: "" }
|
|
19
|
+
},
|
|
20
|
+
emits: ["load", "error"],
|
|
21
|
+
setup(props, { emit }) {
|
|
22
|
+
const bannerId = createBannerId();
|
|
23
|
+
const adLoaded = ref(false);
|
|
24
|
+
const adFailed = ref(false);
|
|
25
|
+
const activeProvider = ref(props.provider);
|
|
26
|
+
watch(() => props.provider, (next) => {
|
|
27
|
+
activeProvider.value = next;
|
|
28
|
+
});
|
|
29
|
+
const config = computed(() => resolveAdConfig(props.format, props.adKey || void 0));
|
|
30
|
+
const srcDoc = computed(
|
|
31
|
+
() => buildSrcDoc({ format: props.format, provider: activeProvider.value, config: config.value, bannerId })
|
|
32
|
+
);
|
|
33
|
+
const style = computed(() => ({
|
|
34
|
+
width: typeof config.value.width === "number" ? `${config.value.width}px` : config.value.width,
|
|
35
|
+
height: typeof config.value.height === "number" ? `${config.value.height}px` : config.value.height,
|
|
36
|
+
overflow: "hidden",
|
|
37
|
+
borderRadius: "6px",
|
|
38
|
+
border: "1px solid #e5e7eb",
|
|
39
|
+
background: "#f3f4f6",
|
|
40
|
+
display: "flex",
|
|
41
|
+
alignItems: "center",
|
|
42
|
+
justifyContent: "center"
|
|
43
|
+
}));
|
|
44
|
+
const wrapperStyle = computed(() => ({
|
|
45
|
+
display: "inline-flex",
|
|
46
|
+
flexDirection: "column",
|
|
47
|
+
alignItems: props.adLabelPosition.endsWith("left") ? "flex-start" : props.adLabelPosition.endsWith("right") ? "flex-end" : "center"
|
|
48
|
+
}));
|
|
49
|
+
const labelStyle = computed(() => ({
|
|
50
|
+
fontSize: "10px",
|
|
51
|
+
fontWeight: "600",
|
|
52
|
+
letterSpacing: "0.1em",
|
|
53
|
+
textTransform: "uppercase",
|
|
54
|
+
color: "#9ca3af",
|
|
55
|
+
marginBottom: props.adLabelPosition.startsWith("top") ? "4px" : "0",
|
|
56
|
+
marginTop: props.adLabelPosition.startsWith("bottom") ? "4px" : "0",
|
|
57
|
+
textAlign: props.adLabelPosition.endsWith("left") ? "left" : props.adLabelPosition.endsWith("right") ? "right" : "center",
|
|
58
|
+
width: "100%"
|
|
59
|
+
}));
|
|
60
|
+
const visibilityStyle = computed(
|
|
61
|
+
() => adLoaded.value ? { opacity: "1", transform: "scale(1)" } : {
|
|
62
|
+
opacity: "0",
|
|
63
|
+
transform: "scale(0.95)",
|
|
64
|
+
pointerEvents: "none",
|
|
65
|
+
position: "absolute",
|
|
66
|
+
width: "0",
|
|
67
|
+
height: "0",
|
|
68
|
+
overflow: "hidden"
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
const onMessage = (event) => {
|
|
72
|
+
const data = event.data;
|
|
73
|
+
if (!data || data.bannerId !== bannerId) return;
|
|
74
|
+
if (data.type === "ad-load-success") {
|
|
75
|
+
adLoaded.value = true;
|
|
76
|
+
emit("load");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (data.type === "ad-load-error") {
|
|
80
|
+
adFailed.value = true;
|
|
81
|
+
emit("error");
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
onMounted(() => window.addEventListener("message", onMessage));
|
|
85
|
+
onUnmounted(() => window.removeEventListener("message", onMessage));
|
|
86
|
+
return () => {
|
|
87
|
+
if (adFailed.value) return null;
|
|
88
|
+
const topLabel = props.showAdLabel && props.adLabelPosition.startsWith("top");
|
|
89
|
+
const bottomLabel = props.showAdLabel && props.adLabelPosition.startsWith("bottom");
|
|
90
|
+
return h("div", { class: props.className, style: { ...wrapperStyle.value, ...visibilityStyle.value } }, [
|
|
91
|
+
topLabel ? h("span", { style: labelStyle.value }, props.adLabel) : null,
|
|
92
|
+
h("div", { "data-testid": "ad-banner", style: style.value }, [
|
|
93
|
+
h("iframe", {
|
|
94
|
+
title: "Advertisement",
|
|
95
|
+
srcdoc: srcDoc.value,
|
|
96
|
+
frameborder: "0",
|
|
97
|
+
scrolling: "no",
|
|
98
|
+
sandbox: "allow-scripts allow-forms allow-same-origin allow-popups allow-modals"
|
|
99
|
+
})
|
|
100
|
+
]),
|
|
101
|
+
bottomLabel ? h("span", { style: labelStyle.value }, props.adLabel) : null
|
|
102
|
+
]);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
var AdContainer = defineComponent({
|
|
107
|
+
name: "AdContainer",
|
|
108
|
+
props: {
|
|
109
|
+
format: { type: String, required: true },
|
|
110
|
+
provider: { type: String, default: "adsterra" },
|
|
111
|
+
adKey: { type: String, default: "" },
|
|
112
|
+
className: { type: String, default: "" },
|
|
113
|
+
adLabel: { type: String, default: "Advertisement" },
|
|
114
|
+
showAdLabel: { type: Boolean, default: true },
|
|
115
|
+
adLabelPosition: { type: String, default: "top-left" }
|
|
116
|
+
},
|
|
117
|
+
setup(props) {
|
|
118
|
+
const adLoaded = ref(false);
|
|
119
|
+
const adFailed = ref(false);
|
|
120
|
+
return () => {
|
|
121
|
+
if (adFailed.value) return null;
|
|
122
|
+
const containerVisibilityStyle = adLoaded.value ? { opacity: "1", transform: "scale(1)" } : {
|
|
123
|
+
opacity: "0",
|
|
124
|
+
transform: "scale(0.95)",
|
|
125
|
+
pointerEvents: "none",
|
|
126
|
+
position: "absolute",
|
|
127
|
+
width: "0",
|
|
128
|
+
height: "0",
|
|
129
|
+
overflow: "hidden"
|
|
130
|
+
};
|
|
131
|
+
return h("div", { style: containerVisibilityStyle }, [
|
|
132
|
+
h(AdBanner, {
|
|
133
|
+
format: props.format,
|
|
134
|
+
provider: props.provider,
|
|
135
|
+
adKey: props.adKey,
|
|
136
|
+
className: props.className,
|
|
137
|
+
adLabel: props.adLabel,
|
|
138
|
+
showAdLabel: props.showAdLabel,
|
|
139
|
+
adLabelPosition: props.adLabelPosition,
|
|
140
|
+
onLoad: () => {
|
|
141
|
+
adLoaded.value = true;
|
|
142
|
+
},
|
|
143
|
+
onError: () => {
|
|
144
|
+
adFailed.value = true;
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
]);
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
var index_default = AdBanner;
|
|
152
|
+
export {
|
|
153
|
+
AdBanner,
|
|
154
|
+
AdContainer,
|
|
155
|
+
configureAds,
|
|
156
|
+
index_default as default
|
|
157
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adsterra-ad/vue",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"require": "./dist/index.cjs"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"vue": "^3.4.0"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@adsterra-ad/core": "0.1.0"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"prepublishOnly": "npm run build && npm run typecheck"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.2.4",
|
|
34
|
+
"typescript": "^5.5.4",
|
|
35
|
+
"vue": "^3.4.38"
|
|
36
|
+
}
|
|
37
|
+
}
|