@adhese/sdk 0.20.0 → 0.21.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/CHANGELOG.md +20 -0
- package/dist/cjs/consent/consent.cjs +37 -0
- package/dist/cjs/consent/consent.cjs.map +1 -0
- package/dist/cjs/findDomSlots/findDomSlots.cjs +28 -0
- package/dist/cjs/findDomSlots/findDomSlots.cjs.map +1 -0
- package/dist/cjs/hooks.cjs +55 -0
- package/dist/cjs/hooks.cjs.map +1 -0
- package/dist/cjs/index.cjs +5 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/logger/logger.cjs +9 -0
- package/dist/cjs/logger/logger.cjs.map +1 -0
- package/dist/cjs/main.cjs +120 -0
- package/dist/cjs/main.cjs.map +1 -0
- package/dist/cjs/main.composables.cjs +61 -0
- package/dist/cjs/main.composables.cjs.map +1 -0
- package/dist/cjs/main.utils.cjs +25 -0
- package/dist/cjs/main.utils.cjs.map +1 -0
- package/dist/cjs/package.json.cjs +7 -0
- package/dist/cjs/package.json.cjs.map +1 -0
- package/dist/cjs/queryDetector/queryDetector.cjs +37 -0
- package/dist/cjs/queryDetector/queryDetector.cjs.map +1 -0
- package/dist/cjs/requestAds/requestAds.cjs +81 -0
- package/dist/cjs/requestAds/requestAds.cjs.map +1 -0
- package/dist/cjs/requestAds/requestAds.preview.cjs +52 -0
- package/dist/cjs/requestAds/requestAds.preview.cjs.map +1 -0
- package/dist/{requestAds.schema-Cr3vDRnz.cjs → cjs/requestAds/requestAds.schema.cjs} +2 -2
- package/dist/cjs/requestAds/requestAds.schema.cjs.map +1 -0
- package/dist/cjs/requestAds/requestAds.utils.cjs +54 -0
- package/dist/cjs/requestAds/requestAds.utils.cjs.map +1 -0
- package/dist/cjs/slot/slot.cjs +229 -0
- package/dist/cjs/slot/slot.cjs.map +1 -0
- package/dist/cjs/slot/slot.composables.cjs +125 -0
- package/dist/cjs/slot/slot.composables.cjs.map +1 -0
- package/dist/cjs/slot/slot.utils.cjs +31 -0
- package/dist/cjs/slot/slot.utils.cjs.map +1 -0
- package/dist/cjs/slotManager/slotManager.cjs +75 -0
- package/dist/cjs/slotManager/slotManager.cjs.map +1 -0
- package/dist/consent/consent.js +37 -0
- package/dist/consent/consent.js.map +1 -0
- package/dist/findDomSlots/findDomSlots.js +28 -0
- package/dist/findDomSlots/findDomSlots.js.map +1 -0
- package/dist/hooks.js +55 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.js +1 -910
- package/dist/index.js.map +1 -1
- package/dist/logger/logger.js +9 -0
- package/dist/logger/logger.js.map +1 -0
- package/dist/main.composables.js +61 -0
- package/dist/main.composables.js.map +1 -0
- package/dist/main.js +120 -0
- package/dist/main.js.map +1 -0
- package/dist/main.utils.js +25 -0
- package/dist/main.utils.js.map +1 -0
- package/dist/package.json.js +7 -0
- package/dist/package.json.js.map +1 -0
- package/dist/queryDetector/queryDetector.js +37 -0
- package/dist/queryDetector/queryDetector.js.map +1 -0
- package/dist/requestAds/requestAds.js +81 -0
- package/dist/requestAds/requestAds.js.map +1 -0
- package/dist/requestAds/requestAds.preview.js +52 -0
- package/dist/requestAds/requestAds.preview.js.map +1 -0
- package/dist/{requestAds.schema-BsJYUvgz.js → requestAds/requestAds.schema.js} +2 -2
- package/dist/requestAds/requestAds.schema.js.map +1 -0
- package/dist/requestAds/requestAds.utils.js +54 -0
- package/dist/requestAds/requestAds.utils.js.map +1 -0
- package/dist/slot/slot.composables.js +125 -0
- package/dist/slot/slot.composables.js.map +1 -0
- package/dist/slot/slot.js +229 -0
- package/dist/slot/slot.js.map +1 -0
- package/dist/slot/slot.utils.js +31 -0
- package/dist/slot/slot.utils.js.map +1 -0
- package/dist/slotManager/slotManager.js +75 -0
- package/dist/slotManager/slotManager.js.map +1 -0
- package/package.json +3 -3
- package/dist/index.cjs +0 -914
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -654
- package/dist/requestAds.schema-BsJYUvgz.js.map +0 -1
- package/dist/requestAds.schema-Cr3vDRnz.cjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,913 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
const name = "@adhese/sdk";
|
|
3
|
-
const version = "0.20.0";
|
|
4
|
-
const logger = createLogger({
|
|
5
|
-
scope: `${name}@${version}`
|
|
6
|
-
});
|
|
7
|
-
async function requestPreviews(account) {
|
|
8
|
-
const previewObjects = getPreviewObjects();
|
|
9
|
-
const [list, adSchema] = await Promise.all([
|
|
10
|
-
Promise.allSettled(previewObjects.filter((previewObject) => "adhesePreviewCreativeId" in previewObject).map(async (previewObject) => {
|
|
11
|
-
const endpoint = new URL(`https://${account}-preview.adhese.org/creatives/preview/json/tag.do`);
|
|
12
|
-
endpoint.searchParams.set(
|
|
13
|
-
"id",
|
|
14
|
-
previewObject.adhesePreviewCreativeId
|
|
15
|
-
);
|
|
16
|
-
const response = await fetch(endpoint.href, {
|
|
17
|
-
method: "GET",
|
|
18
|
-
headers: {
|
|
19
|
-
accept: "application/json"
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
if (!response.ok)
|
|
23
|
-
return Promise.reject(new Error(`Failed to request preview ad with ID: ${previewObject.adhesePreviewCreativeId}`));
|
|
24
|
-
return await response.json();
|
|
25
|
-
})),
|
|
26
|
-
import("./requestAds.schema-BsJYUvgz.js").then((module) => module.adSchema)
|
|
27
|
-
]);
|
|
28
|
-
return adSchema.array().parse(list.filter((response) => {
|
|
29
|
-
if (response.status === "rejected") {
|
|
30
|
-
logger.error(response.reason);
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
return response.status === "fulfilled";
|
|
34
|
-
}).flatMap((response) => response.value.map((item) => ({
|
|
35
|
-
...item,
|
|
36
|
-
preview: true
|
|
37
|
-
}))));
|
|
38
|
-
}
|
|
39
|
-
function getPreviewObjects() {
|
|
40
|
-
const currentUrl = new URL(window.location.href);
|
|
41
|
-
const previewObjects = [];
|
|
42
|
-
let currentObject = {};
|
|
43
|
-
for (const [key, value] of currentUrl.searchParams.entries()) {
|
|
44
|
-
if (key === "adhesePreviewCreativeId" && Object.keys(currentObject).length > 0) {
|
|
45
|
-
previewObjects.push(currentObject);
|
|
46
|
-
currentObject = {};
|
|
47
|
-
}
|
|
48
|
-
currentObject[key] = value;
|
|
49
|
-
}
|
|
50
|
-
if (Object.keys(currentObject).length > 0)
|
|
51
|
-
previewObjects.push(currentObject);
|
|
52
|
-
return previewObjects;
|
|
53
|
-
}
|
|
54
|
-
function requestWithPost({
|
|
55
|
-
context,
|
|
56
|
-
...options
|
|
57
|
-
}) {
|
|
58
|
-
const payload = {
|
|
59
|
-
...options,
|
|
60
|
-
slots: options.slots.map((slot) => ({
|
|
61
|
-
slotname: toValue(slot.name),
|
|
62
|
-
parameters: parseParameters(slot.parameters)
|
|
63
|
-
})),
|
|
64
|
-
parameters: context.parameters && parseParameters(context.parameters)
|
|
65
|
-
};
|
|
66
|
-
return fetch(`${new URL(context.options.host).href}json`, {
|
|
67
|
-
method: "POST",
|
|
68
|
-
body: JSON.stringify(payload),
|
|
69
|
-
headers: {
|
|
70
|
-
// eslint-disable-next-line ts/naming-convention
|
|
71
|
-
"Content-Type": "application/json"
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
async function requestWithGet({ context, slots }) {
|
|
76
|
-
return fetch(new URL(`${context.options.host}/json/sl${slots.map((slot) => toValue(slot.name)).join("/sl")}`), {
|
|
77
|
-
method: "GET",
|
|
78
|
-
headers: {
|
|
79
|
-
// eslint-disable-next-line ts/naming-convention
|
|
80
|
-
"Content-Type": "application/json"
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function parseParameters(parameters) {
|
|
85
|
-
return Object.fromEntries(Array.from(parameters.entries()).filter(([key]) => {
|
|
86
|
-
if (key.length === 2)
|
|
87
|
-
return true;
|
|
88
|
-
logger.warn(`Invalid parameter key: ${key}. Key should be exactly 2 characters long. Key will be ignored.`);
|
|
89
|
-
return false;
|
|
90
|
-
}).map(([key, value]) => {
|
|
91
|
-
if (typeof value === "string")
|
|
92
|
-
return [key, filterSpecialChars(value)];
|
|
93
|
-
return [key, value.map(filterSpecialChars)];
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
96
|
-
function filterSpecialChars(value) {
|
|
97
|
-
const specialRegex = /[^\p{L}\p{N}_]/gu;
|
|
98
|
-
return value.replaceAll(specialRegex, "_");
|
|
99
|
-
}
|
|
100
|
-
const batch = /* @__PURE__ */ new Map();
|
|
101
|
-
const runRequestAdsBatch = debounce(async (context) => {
|
|
102
|
-
if (batch.size === 0)
|
|
103
|
-
return [];
|
|
104
|
-
const ads = await requestAds({
|
|
105
|
-
slots: Array.from(batch.values()).map(({ options }) => options.slot),
|
|
106
|
-
context
|
|
107
|
-
});
|
|
108
|
-
for (const { options, resolve } of batch.values()) {
|
|
109
|
-
const ad = ads.find(({ slotName }) => toValue(slotName) === toValue(options.slot.name));
|
|
110
|
-
if (ad)
|
|
111
|
-
resolve(ad);
|
|
112
|
-
else
|
|
113
|
-
resolve(null);
|
|
114
|
-
}
|
|
115
|
-
batch.clear();
|
|
116
|
-
return ads;
|
|
117
|
-
}, {
|
|
118
|
-
waitMs: 20,
|
|
119
|
-
timing: "trailing"
|
|
120
|
-
});
|
|
121
|
-
async function requestAd(options) {
|
|
122
|
-
const promise = new Promise(
|
|
123
|
-
(resolve) => {
|
|
124
|
-
batch.set(toValue(options.slot.name), { options, resolve });
|
|
125
|
-
}
|
|
126
|
-
);
|
|
127
|
-
await runRequestAdsBatch.call(options.context);
|
|
128
|
-
return promise;
|
|
129
|
-
}
|
|
130
|
-
async function requestAds(requestOptions) {
|
|
131
|
-
var _a, _b, _c, _d, _e;
|
|
132
|
-
const options = await requestOptions.context.hooks.runOnRequest(requestOptions);
|
|
133
|
-
const { context } = options;
|
|
134
|
-
try {
|
|
135
|
-
(_a = context == null ? void 0 : context.events) == null ? void 0 : _a.requestAd.dispatch({
|
|
136
|
-
...options,
|
|
137
|
-
context
|
|
138
|
-
});
|
|
139
|
-
const [response, previews, parseResponse] = await Promise.all([
|
|
140
|
-
((_b = context.options.requestType) == null ? void 0 : _b.toUpperCase()) === "POST" ? requestWithPost(options) : requestWithGet(options),
|
|
141
|
-
requestPreviews(context.options.account),
|
|
142
|
-
import("./requestAds.schema-BsJYUvgz.js").then((module) => module.parseResponse)
|
|
143
|
-
]);
|
|
144
|
-
logger.debug("Received response", response);
|
|
145
|
-
if (!response.ok)
|
|
146
|
-
throw new Error(`Failed to request ad: ${response.status} ${response.statusText}`);
|
|
147
|
-
const result = parseResponse(await response.json());
|
|
148
|
-
logger.debug("Parsed ad", result);
|
|
149
|
-
if (previews.length > 0)
|
|
150
|
-
logger.info(`Found ${previews.length} ${previews.length === 1 ? "preview" : "previews"}. Replacing ads in response with preview items`, previews);
|
|
151
|
-
const matchedPreviews = previews.map(({ slotName, ...preview }) => {
|
|
152
|
-
const partnerAd = result.find((ad) => ad.libId === preview.libId);
|
|
153
|
-
return {
|
|
154
|
-
slotName: `${(partnerAd == null ? void 0 : partnerAd.slotName) ?? slotName}`,
|
|
155
|
-
...preview
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
if (matchedPreviews.length > 0)
|
|
159
|
-
(_c = context.events) == null ? void 0 : _c.previewReceived.dispatch(matchedPreviews);
|
|
160
|
-
const mergedResult = await context.hooks.runOnResponse([
|
|
161
|
-
...result.filter((ad) => !previews.some((preview) => preview.libId === ad.libId)),
|
|
162
|
-
...matchedPreviews
|
|
163
|
-
]);
|
|
164
|
-
(_d = context.events) == null ? void 0 : _d.responseReceived.dispatch(mergedResult);
|
|
165
|
-
return mergedResult;
|
|
166
|
-
} catch (error) {
|
|
167
|
-
logger.error(String(error));
|
|
168
|
-
(_e = context == null ? void 0 : context.events) == null ? void 0 : _e.requestError.dispatch(error);
|
|
169
|
-
throw error;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
function useQueryDetector(context, queries = {
|
|
173
|
-
mobile: "(max-width: 768px)",
|
|
174
|
-
tablet: "(min-width: 769px) and (max-width: 1024px)",
|
|
175
|
-
desktop: "(min-width: 1025px)"
|
|
176
|
-
}) {
|
|
177
|
-
const entries = Object.entries(queries);
|
|
178
|
-
const active = ref(getQuery(entries));
|
|
179
|
-
const queryList = entries.map(([, query]) => window.matchMedia(query));
|
|
180
|
-
const handleOnChange = debounce(() => {
|
|
181
|
-
active.value = getQuery(entries);
|
|
182
|
-
}, {
|
|
183
|
-
waitMs: 50
|
|
184
|
-
});
|
|
185
|
-
context.hooks.onInit(() => {
|
|
186
|
-
for (const query of queryList)
|
|
187
|
-
query.addEventListener("change", handleOnChange.call);
|
|
188
|
-
handleOnChange.call();
|
|
189
|
-
});
|
|
190
|
-
function dispose() {
|
|
191
|
-
for (const query of queryList)
|
|
192
|
-
query.removeEventListener("change", handleOnChange.call);
|
|
193
|
-
}
|
|
194
|
-
context.hooks.onDispose(dispose);
|
|
195
|
-
return [computed(() => active.value), dispose];
|
|
196
|
-
}
|
|
197
|
-
function getQuery(entries) {
|
|
198
|
-
for (const [device, query] of entries) {
|
|
199
|
-
if (window.matchMedia(query).matches)
|
|
200
|
-
return device;
|
|
201
|
-
}
|
|
202
|
-
return "unknown";
|
|
203
|
-
}
|
|
204
|
-
function renderIframe(ad, element) {
|
|
205
|
-
const iframe = document.createElement("iframe");
|
|
206
|
-
iframe.srcdoc = `
|
|
207
|
-
<!DOCTYPE html>
|
|
208
|
-
<html>
|
|
209
|
-
<head>
|
|
210
|
-
<style>
|
|
211
|
-
body {
|
|
212
|
-
margin: 0;
|
|
213
|
-
padding: 0;
|
|
214
|
-
overflow: hidden;
|
|
215
|
-
}
|
|
216
|
-
</style>
|
|
217
|
-
</head>
|
|
218
|
-
<body>
|
|
219
|
-
${String(ad.tag)}
|
|
220
|
-
</body>
|
|
221
|
-
`.replaceAll(/\s+/g, " ").trim();
|
|
222
|
-
iframe.style.border = "none";
|
|
223
|
-
iframe.style.width = ad.width ? `${ad.width}px` : "auto";
|
|
224
|
-
iframe.style.height = ad.height ? `${ad.height}px` : "auto";
|
|
225
|
-
element.replaceChildren(iframe);
|
|
226
|
-
}
|
|
227
|
-
function renderInline(ad, element) {
|
|
228
|
-
element.innerHTML = String(ad.tag);
|
|
229
|
-
}
|
|
230
|
-
function useDomLoaded(context) {
|
|
231
|
-
const isDomLoaded = ref(false);
|
|
232
|
-
context.hooks.onInit(async () => {
|
|
233
|
-
await waitForDomLoad();
|
|
234
|
-
isDomLoaded.value = true;
|
|
235
|
-
});
|
|
236
|
-
return isDomLoaded;
|
|
237
|
-
}
|
|
238
|
-
function useRenderIntersectionObserver({ options, element, hooks }) {
|
|
239
|
-
var _a;
|
|
240
|
-
const isInViewport = ref(false);
|
|
241
|
-
const renderIntersectionObserver = new IntersectionObserver((entries) => {
|
|
242
|
-
isInViewport.value = entries.some((entry) => entry.isIntersecting);
|
|
243
|
-
}, {
|
|
244
|
-
rootMargin: ((_a = options.lazyLoadingOptions) == null ? void 0 : _a.rootMargin) ?? "200px",
|
|
245
|
-
threshold: 0
|
|
246
|
-
});
|
|
247
|
-
function observe(newElement, oldElement) {
|
|
248
|
-
if (oldElement)
|
|
249
|
-
renderIntersectionObserver.unobserve(oldElement);
|
|
250
|
-
if (newElement)
|
|
251
|
-
renderIntersectionObserver.observe(newElement);
|
|
252
|
-
return () => {
|
|
253
|
-
if (newElement)
|
|
254
|
-
renderIntersectionObserver.unobserve(newElement);
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
watch(element, observe);
|
|
258
|
-
observe(element.value);
|
|
259
|
-
hooks.onDispose(() => {
|
|
260
|
-
renderIntersectionObserver.disconnect();
|
|
261
|
-
});
|
|
262
|
-
return isInViewport;
|
|
263
|
-
}
|
|
264
|
-
function useViewabilityObserver({ context, slotContext, hooks, onTracked }) {
|
|
265
|
-
let timeoutId = null;
|
|
266
|
-
const {
|
|
267
|
-
threshold,
|
|
268
|
-
duration,
|
|
269
|
-
rootMargin
|
|
270
|
-
} = {
|
|
271
|
-
threshold: 0.2,
|
|
272
|
-
duration: 1e3,
|
|
273
|
-
rootMargin: "0px",
|
|
274
|
-
...context.options.viewabilityTrackingOptions
|
|
275
|
-
};
|
|
276
|
-
const trackingPixel = ref(null);
|
|
277
|
-
const isTracked = ref(false);
|
|
278
|
-
const viewabilityObserver = new IntersectionObserver(([entry]) => {
|
|
279
|
-
if (context.options.viewabilityTracking && !trackingPixel.value) {
|
|
280
|
-
const ratio = round(entry.intersectionRatio, 1);
|
|
281
|
-
if (ratio >= threshold && !timeoutId) {
|
|
282
|
-
timeoutId = setTimeout(() => {
|
|
283
|
-
timeoutId = null;
|
|
284
|
-
onTracked == null ? void 0 : onTracked(trackingPixel);
|
|
285
|
-
isTracked.value = true;
|
|
286
|
-
}, duration);
|
|
287
|
-
} else if (ratio < threshold && timeoutId) {
|
|
288
|
-
clearTimeout(timeoutId);
|
|
289
|
-
timeoutId = null;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}, {
|
|
293
|
-
rootMargin,
|
|
294
|
-
threshold: Array.from({ length: 11 }, (_, i) => i * 0.1)
|
|
295
|
-
});
|
|
296
|
-
function observe(newElement, oldElement) {
|
|
297
|
-
if (newElement && context.options.viewabilityTracking)
|
|
298
|
-
viewabilityObserver.observe(newElement);
|
|
299
|
-
return () => {
|
|
300
|
-
if (newElement)
|
|
301
|
-
viewabilityObserver.unobserve(newElement);
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
watch(() => {
|
|
305
|
-
var _a;
|
|
306
|
-
return (_a = slotContext.value) == null ? void 0 : _a.element;
|
|
307
|
-
}, (element) => {
|
|
308
|
-
if (element)
|
|
309
|
-
observe(element);
|
|
310
|
-
}, { immediate: true });
|
|
311
|
-
watch(slotContext, (slot) => {
|
|
312
|
-
if (slot == null ? void 0 : slot.element)
|
|
313
|
-
viewabilityObserver.observe(slot.element);
|
|
314
|
-
}, { once: true });
|
|
315
|
-
hooks.onDispose(() => {
|
|
316
|
-
var _a;
|
|
317
|
-
(_a = trackingPixel.value) == null ? void 0 : _a.remove();
|
|
318
|
-
viewabilityObserver.disconnect();
|
|
319
|
-
});
|
|
320
|
-
return isTracked;
|
|
321
|
-
}
|
|
322
|
-
function useSlotHooks({ setup }, slotContext) {
|
|
323
|
-
const [runOnBeforeRender, onBeforeRender, disposeOnBeforeRender] = createAsyncHook();
|
|
324
|
-
const [runOnRender, onRender, disposeOnRender] = createAsyncHook();
|
|
325
|
-
const [runOnBeforeRequest, onBeforeRequest, disposeOnBeforeRequest] = createAsyncHook();
|
|
326
|
-
const [runOnRequest, onRequest, disposeOnRequest] = createAsyncHook();
|
|
327
|
-
const [runOnDispose, onDispose, disposeOnDispose] = createPassiveHook();
|
|
328
|
-
setup == null ? void 0 : setup(slotContext, {
|
|
329
|
-
onBeforeRender,
|
|
330
|
-
onRender,
|
|
331
|
-
onBeforeRequest,
|
|
332
|
-
onDispose,
|
|
333
|
-
onRequest
|
|
334
|
-
});
|
|
335
|
-
onDispose(() => {
|
|
336
|
-
disposeOnBeforeRender();
|
|
337
|
-
disposeOnRender();
|
|
338
|
-
disposeOnBeforeRequest();
|
|
339
|
-
disposeOnRequest();
|
|
340
|
-
disposeOnDispose();
|
|
341
|
-
});
|
|
342
|
-
return { runOnBeforeRender, runOnRender, runOnBeforeRequest, runOnRequest, runOnDispose, onDispose, onBeforeRequest, onRequest, onBeforeRender, onRender };
|
|
343
|
-
}
|
|
344
|
-
const renderFunctions = {
|
|
345
|
-
iframe: renderIframe,
|
|
346
|
-
inline: renderInline,
|
|
347
|
-
none: doNothing
|
|
348
|
-
};
|
|
349
|
-
const defaultOptions = {
|
|
350
|
-
renderMode: "iframe",
|
|
351
|
-
type: "normal"
|
|
352
|
-
};
|
|
353
|
-
function createSlot(slotOptions) {
|
|
354
|
-
const scope = effectScope();
|
|
355
|
-
return scope.run(() => {
|
|
356
|
-
const slotContext = ref(null);
|
|
357
|
-
const options = slotOptions.context.hooks.runOnSlotCreate({
|
|
358
|
-
...defaultOptions,
|
|
359
|
-
...slotOptions
|
|
360
|
-
});
|
|
361
|
-
const {
|
|
362
|
-
containingElement,
|
|
363
|
-
slot,
|
|
364
|
-
context,
|
|
365
|
-
pluginOptions,
|
|
366
|
-
renderMode = "iframe",
|
|
367
|
-
type = "normal"
|
|
368
|
-
} = options;
|
|
369
|
-
const id = uniqueId();
|
|
370
|
-
const {
|
|
371
|
-
runOnBeforeRender,
|
|
372
|
-
runOnRender,
|
|
373
|
-
runOnBeforeRequest,
|
|
374
|
-
runOnRequest,
|
|
375
|
-
runOnDispose,
|
|
376
|
-
...hooks
|
|
377
|
-
} = useSlotHooks(options, slotContext);
|
|
378
|
-
const isDisposed = ref(false);
|
|
379
|
-
const parameters = reactive(new Map(Object.entries(options.parameters ?? {})));
|
|
380
|
-
const [device, disposeQueryDetector] = useQueryDetector(context, typeof options.format === "string" ? {
|
|
381
|
-
[options.format]: "(min-width: 0px)"
|
|
382
|
-
} : Object.fromEntries(options.format.map((item) => [item.format, item.query])));
|
|
383
|
-
const format = computed(() => typeof options.format === "string" ? options.format : device.value);
|
|
384
|
-
const data = ref(null);
|
|
385
|
-
const originalData = ref(data.value);
|
|
386
|
-
const name2 = computed(() => generateName(options.context.location, format.value, options.slot));
|
|
387
|
-
watch(name2, async (newName, oldName) => {
|
|
388
|
-
var _a, _b;
|
|
389
|
-
if (newName === oldName)
|
|
390
|
-
return;
|
|
391
|
-
const newAd = await ((_a = slotContext.value) == null ? void 0 : _a.request());
|
|
392
|
-
if (!newAd)
|
|
393
|
-
return;
|
|
394
|
-
(_b = slotContext.value) == null ? void 0 : _b.cleanElement();
|
|
395
|
-
data.value = newAd;
|
|
396
|
-
originalData.value = newAd;
|
|
397
|
-
});
|
|
398
|
-
const isDomLoaded = useDomLoaded(context);
|
|
399
|
-
const element = computed(
|
|
400
|
-
() => {
|
|
401
|
-
var _a;
|
|
402
|
-
if (!(typeof options.containingElement === "string" || !options.containingElement))
|
|
403
|
-
return options.containingElement;
|
|
404
|
-
if (!isDomLoaded.value || ((_a = slotContext.value) == null ? void 0 : _a.isDisposed))
|
|
405
|
-
return null;
|
|
406
|
-
return document.querySelector(`.adunit[data-format="${format.value}"]#${options.containingElement}${options.slot ? `[data-slot="${options.slot}"]` : ""}`);
|
|
407
|
-
}
|
|
408
|
-
);
|
|
409
|
-
const isInViewport = useRenderIntersectionObserver({
|
|
410
|
-
options,
|
|
411
|
-
element,
|
|
412
|
-
hooks
|
|
413
|
-
});
|
|
414
|
-
const status = ref("initializing");
|
|
415
|
-
watch([data, isInViewport], async ([newData, newIsInViewport], [oldData]) => {
|
|
416
|
-
var _a;
|
|
417
|
-
if ((!newData || oldData && isDeepEqual(newData, oldData)) && status.value === "rendered")
|
|
418
|
-
return;
|
|
419
|
-
if (newIsInViewport)
|
|
420
|
-
await ((_a = slotContext.value) == null ? void 0 : _a.render(newData ?? void 0));
|
|
421
|
-
});
|
|
422
|
-
hooks.onDispose(() => {
|
|
423
|
-
disposeQueryDetector();
|
|
424
|
-
});
|
|
425
|
-
context.hooks.onInit(async () => {
|
|
426
|
-
var _a;
|
|
427
|
-
status.value = "initialized";
|
|
428
|
-
if (options.lazyLoading)
|
|
429
|
-
return;
|
|
430
|
-
data.value = await ((_a = slotContext.value) == null ? void 0 : _a.request()) ?? null;
|
|
431
|
-
});
|
|
432
|
-
const isViewabilityTracked = useViewabilityObserver({
|
|
433
|
-
context,
|
|
434
|
-
slotContext,
|
|
435
|
-
hooks,
|
|
436
|
-
onTracked(trackingPixel) {
|
|
437
|
-
var _a, _b, _c, _d, _e;
|
|
438
|
-
if ((_b = (_a = slotContext.value) == null ? void 0 : _a.data) == null ? void 0 : _b.viewableImpressionCounter) {
|
|
439
|
-
trackingPixel.value = addTrackingPixel((_d = (_c = slotContext.value) == null ? void 0 : _c.data) == null ? void 0 : _d.viewableImpressionCounter);
|
|
440
|
-
context.logger.debug(`Viewability tracking pixel fired for ${(_e = slotContext.value) == null ? void 0 : _e.name}`);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
const impressionTrackingPixelElement = ref(null);
|
|
445
|
-
const isImpressionTracked = ref(false);
|
|
446
|
-
hooks.onDispose(() => {
|
|
447
|
-
if (impressionTrackingPixelElement.value)
|
|
448
|
-
impressionTrackingPixelElement.value.remove();
|
|
449
|
-
});
|
|
450
|
-
async function request() {
|
|
451
|
-
if (options.lazyLoading && !isInViewport.value)
|
|
452
|
-
return null;
|
|
453
|
-
status.value = "loading";
|
|
454
|
-
let response = await runOnBeforeRequest(null);
|
|
455
|
-
if (!response) {
|
|
456
|
-
response = await requestAd({
|
|
457
|
-
slot: {
|
|
458
|
-
name: name2.value,
|
|
459
|
-
parameters
|
|
460
|
-
},
|
|
461
|
-
context
|
|
462
|
-
});
|
|
463
|
-
}
|
|
464
|
-
if (response)
|
|
465
|
-
response = await runOnRequest(response);
|
|
466
|
-
data.value = response;
|
|
467
|
-
if (!originalData.value)
|
|
468
|
-
originalData.value = response;
|
|
469
|
-
status.value = response ? "loaded" : "empty";
|
|
470
|
-
if (!response)
|
|
471
|
-
cleanElement();
|
|
472
|
-
return response;
|
|
473
|
-
}
|
|
474
|
-
async function render(adToRender) {
|
|
475
|
-
status.value = "rendering";
|
|
476
|
-
await waitForDomLoad();
|
|
477
|
-
let renderAd = adToRender ?? data.value ?? originalData.value ?? await request();
|
|
478
|
-
renderAd = renderAd && await runOnBeforeRender(renderAd);
|
|
479
|
-
if (!renderAd) {
|
|
480
|
-
status.value = "empty";
|
|
481
|
-
logger.debug(`No ad to render for slot ${name2.value}`);
|
|
482
|
-
return null;
|
|
483
|
-
}
|
|
484
|
-
renderAd = await runOnRender(renderAd);
|
|
485
|
-
if (!element.value) {
|
|
486
|
-
const error = `Could not create slot for format ${format.value}. No element found.`;
|
|
487
|
-
logger.error(error, options);
|
|
488
|
-
throw new Error(error);
|
|
489
|
-
}
|
|
490
|
-
if (context.debug)
|
|
491
|
-
element.value.style.position = "relative";
|
|
492
|
-
if (typeof (renderAd == null ? void 0 : renderAd.tag) !== "string") {
|
|
493
|
-
const error = `Could not render slot for slot ${name2.value}. A valid tag doesn't exist or is not HTML string.`;
|
|
494
|
-
logger.error(error, options);
|
|
495
|
-
status.value = "error";
|
|
496
|
-
throw new Error(error);
|
|
497
|
-
}
|
|
498
|
-
renderFunctions[renderMode](renderAd, element.value);
|
|
499
|
-
if (renderAd.impressionCounter && !impressionTrackingPixelElement.value)
|
|
500
|
-
impressionTrackingPixelElement.value = addTrackingPixel(renderAd.impressionCounter);
|
|
501
|
-
isImpressionTracked.value = true;
|
|
502
|
-
logger.debug("Slot rendered", {
|
|
503
|
-
renderedElement: element,
|
|
504
|
-
location: context.location,
|
|
505
|
-
format,
|
|
506
|
-
containingElement
|
|
507
|
-
});
|
|
508
|
-
data.value = renderAd;
|
|
509
|
-
status.value = "rendered";
|
|
510
|
-
return element.value;
|
|
511
|
-
}
|
|
512
|
-
function cleanElement() {
|
|
513
|
-
if (!element.value)
|
|
514
|
-
return;
|
|
515
|
-
element.value.innerHTML = "";
|
|
516
|
-
element.value.style.position = "";
|
|
517
|
-
element.value.style.width = "";
|
|
518
|
-
element.value.style.height = "";
|
|
519
|
-
data.value = null;
|
|
520
|
-
originalData.value = null;
|
|
521
|
-
}
|
|
522
|
-
function dispose() {
|
|
523
|
-
cleanElement();
|
|
524
|
-
data.value = null;
|
|
525
|
-
runOnDispose();
|
|
526
|
-
isDisposed.value = true;
|
|
527
|
-
scope.stop();
|
|
528
|
-
}
|
|
529
|
-
const state = reactive({
|
|
530
|
-
location: context.location ?? "",
|
|
531
|
-
lazyLoading: options.lazyLoading ?? false,
|
|
532
|
-
type,
|
|
533
|
-
slot,
|
|
534
|
-
parameters,
|
|
535
|
-
format,
|
|
536
|
-
name: name2,
|
|
537
|
-
data,
|
|
538
|
-
isViewabilityTracked,
|
|
539
|
-
isImpressionTracked,
|
|
540
|
-
status,
|
|
541
|
-
element,
|
|
542
|
-
isDisposed,
|
|
543
|
-
id,
|
|
544
|
-
pluginOptions,
|
|
545
|
-
render,
|
|
546
|
-
request,
|
|
547
|
-
dispose,
|
|
548
|
-
cleanElement,
|
|
549
|
-
...hooks
|
|
550
|
-
});
|
|
551
|
-
watch(state, (newState) => {
|
|
552
|
-
slotContext.value = newState;
|
|
553
|
-
}, {
|
|
554
|
-
deep: true,
|
|
555
|
-
immediate: true
|
|
556
|
-
});
|
|
557
|
-
return state;
|
|
558
|
-
});
|
|
559
|
-
}
|
|
560
|
-
async function findDomSlots(context) {
|
|
561
|
-
await waitForDomLoad();
|
|
562
|
-
return Array.from(document.querySelectorAll(".adunit")).filter((element) => {
|
|
563
|
-
var _a;
|
|
564
|
-
if (!element.dataset.format)
|
|
565
|
-
return false;
|
|
566
|
-
const name2 = generateName(
|
|
567
|
-
context.location,
|
|
568
|
-
element.dataset.format,
|
|
569
|
-
element.dataset.slot
|
|
570
|
-
);
|
|
571
|
-
return !((_a = context.getAll) == null ? void 0 : _a.call(context).some((activeSlot) => activeSlot.name === name2));
|
|
572
|
-
}).map((element) => createSlot({
|
|
573
|
-
format: element.dataset.format,
|
|
574
|
-
containingElement: element,
|
|
575
|
-
slot: element.dataset.slot,
|
|
576
|
-
context
|
|
577
|
-
})).filter((slot) => {
|
|
578
|
-
var _a;
|
|
579
|
-
return !((_a = context.getAll) == null ? void 0 : _a.call(context).some((activeSlot) => activeSlot.name === slot.name));
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
function createSlotManager({
|
|
583
|
-
initialSlots = [],
|
|
584
|
-
context
|
|
585
|
-
}) {
|
|
586
|
-
context.slots = /* @__PURE__ */ new Map();
|
|
587
|
-
function getAll() {
|
|
588
|
-
return Array.from(context.slots).map(([, slot]) => slot);
|
|
589
|
-
}
|
|
590
|
-
function add(options) {
|
|
591
|
-
var _a;
|
|
592
|
-
const slot = createSlot({
|
|
593
|
-
...options,
|
|
594
|
-
context,
|
|
595
|
-
setup(slotContext, slotHooks) {
|
|
596
|
-
var _a2;
|
|
597
|
-
(_a2 = options.setup) == null ? void 0 : _a2.call(options, slotContext, slotHooks);
|
|
598
|
-
slotHooks.onDispose(() => {
|
|
599
|
-
var _a3;
|
|
600
|
-
context.slots.delete(slot.id);
|
|
601
|
-
logger.debug("Slot removed", {
|
|
602
|
-
slot
|
|
603
|
-
});
|
|
604
|
-
(_a3 = context.events) == null ? void 0 : _a3.removeSlot.dispatch(slot);
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
});
|
|
608
|
-
if (get(slot.name)) {
|
|
609
|
-
slot.dispose();
|
|
610
|
-
throw new Error(`Slot with the name: ${slot.name} already exists. Create a new slot with a different format, slot, or the location.`);
|
|
611
|
-
}
|
|
612
|
-
context.slots.set(slot.id, slot);
|
|
613
|
-
logger.debug("Slot added", {
|
|
614
|
-
slot,
|
|
615
|
-
slots: Array.from(context.slots.values())
|
|
616
|
-
});
|
|
617
|
-
(_a = context.events) == null ? void 0 : _a.addSlot.dispatch(slot);
|
|
618
|
-
return slot;
|
|
619
|
-
}
|
|
620
|
-
async function findDomSlots$1() {
|
|
621
|
-
const domSlots = await findDomSlots(
|
|
622
|
-
context
|
|
623
|
-
);
|
|
624
|
-
for (const slot of domSlots)
|
|
625
|
-
context.slots.set(slot.id, slot);
|
|
626
|
-
return domSlots;
|
|
627
|
-
}
|
|
628
|
-
function get(name2) {
|
|
629
|
-
return getAll().find((slot) => slot.name === name2);
|
|
630
|
-
}
|
|
631
|
-
function dispose() {
|
|
632
|
-
for (const slot of context.slots.values())
|
|
633
|
-
slot.dispose();
|
|
634
|
-
context.slots.clear();
|
|
635
|
-
}
|
|
636
|
-
for (const options of initialSlots) {
|
|
637
|
-
add({
|
|
638
|
-
...options,
|
|
639
|
-
lazyLoading: false
|
|
640
|
-
});
|
|
641
|
-
}
|
|
642
|
-
return {
|
|
643
|
-
getAll,
|
|
644
|
-
add,
|
|
645
|
-
findDomSlots: findDomSlots$1,
|
|
646
|
-
get,
|
|
647
|
-
dispose
|
|
648
|
-
};
|
|
649
|
-
}
|
|
650
|
-
function useConsent(context) {
|
|
651
|
-
const consent = ref("none");
|
|
652
|
-
const consentType = computed(() => consent.value === "none" || consent.value === "all" ? "binary" : "tcf");
|
|
653
|
-
function onTcfConsentChange(data) {
|
|
654
|
-
if (data.tcString)
|
|
655
|
-
consent.value = data.tcString;
|
|
656
|
-
}
|
|
657
|
-
context.hooks.onInit(() => {
|
|
658
|
-
var _a;
|
|
659
|
-
(_a = window.__tcfapi) == null ? void 0 : _a.call(window, "addEventListener", 2, onTcfConsentChange);
|
|
660
|
-
});
|
|
661
|
-
context.hooks.onDispose(() => {
|
|
662
|
-
var _a;
|
|
663
|
-
(_a = window.__tcfapi) == null ? void 0 : _a.call(window, "removeEventListener", 2, onTcfConsentChange);
|
|
664
|
-
});
|
|
665
|
-
watch(() => context.consent, (newConsent) => {
|
|
666
|
-
consent.value = newConsent ? "all" : "none";
|
|
667
|
-
}, { immediate: true });
|
|
668
|
-
watch([consent, consentType], ([newConsent, newConsentType]) => {
|
|
669
|
-
if (newConsentType === "binary") {
|
|
670
|
-
context.parameters.set("tl", newConsent);
|
|
671
|
-
context.parameters.delete("xt");
|
|
672
|
-
} else {
|
|
673
|
-
context.parameters.set("xt", newConsent);
|
|
674
|
-
context.parameters.delete("tl");
|
|
675
|
-
}
|
|
676
|
-
}, { immediate: true });
|
|
677
|
-
watch(consent, (newConsent) => {
|
|
678
|
-
context.consentString = newConsent;
|
|
679
|
-
}, { immediate: true });
|
|
680
|
-
return [consent, consentType];
|
|
681
|
-
}
|
|
682
|
-
function setupLogging(mergedOptions) {
|
|
683
|
-
if (mergedOptions.debug || window.location.search.includes("adhese_debug=true")) {
|
|
684
|
-
logger.setMinLogLevelThreshold("debug");
|
|
685
|
-
logger.debug("Debug logging enabled");
|
|
686
|
-
}
|
|
687
|
-
logger.debug("Created Adhese SDK instance", {
|
|
688
|
-
mergedOptions
|
|
689
|
-
});
|
|
690
|
-
}
|
|
691
|
-
function isPreviewMode() {
|
|
692
|
-
return window.location.search.includes("adhesePreviewCreativeId");
|
|
693
|
-
}
|
|
694
|
-
async function fetchAllUnrenderedSlots(slots) {
|
|
695
|
-
const filteredSlots = slots.filter((slot) => !slot.lazyLoading && !slot.data);
|
|
696
|
-
if (filteredSlots.length === 0)
|
|
697
|
-
return;
|
|
698
|
-
await Promise.allSettled(filteredSlots.map((slot) => slot.request()));
|
|
699
|
-
}
|
|
700
|
-
function useMainQueryDetector(mergedOptions, context) {
|
|
701
|
-
const [device] = useQueryDetector(context, mergedOptions.queries);
|
|
702
|
-
watch(device, async (newDevice) => {
|
|
703
|
-
var _a, _b;
|
|
704
|
-
context.device = newDevice;
|
|
705
|
-
(_a = context.parameters) == null ? void 0 : _a.set("dt", newDevice);
|
|
706
|
-
(_b = context.parameters) == null ? void 0 : _b.set("br", newDevice);
|
|
707
|
-
await Promise.allSettled(context.getAll().map((slot) => slot.request()));
|
|
708
|
-
}, { immediate: true });
|
|
709
|
-
}
|
|
710
|
-
function useMainDebugMode(context) {
|
|
711
|
-
watch(() => context.debug, async (newDebug) => {
|
|
712
|
-
var _a, _b;
|
|
713
|
-
if (newDebug) {
|
|
714
|
-
context.logger.setMinLogLevelThreshold("debug");
|
|
715
|
-
context.logger.debug("Debug mode enabled");
|
|
716
|
-
(_a = context.events) == null ? void 0 : _a.debugChange.dispatch(true);
|
|
717
|
-
} else {
|
|
718
|
-
context.logger.debug("Debug mode disabled");
|
|
719
|
-
context.logger.setMinLogLevelThreshold("info");
|
|
720
|
-
(_b = context.events) == null ? void 0 : _b.debugChange.dispatch(false);
|
|
721
|
-
}
|
|
722
|
-
}, {
|
|
723
|
-
immediate: true
|
|
724
|
-
});
|
|
725
|
-
context.hooks.onDispose(() => {
|
|
726
|
-
context.logger.resetLogs();
|
|
727
|
-
context.logger.info("Adhese instance disposed");
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
function useMainParameters(context, options) {
|
|
731
|
-
const parameters = /* @__PURE__ */ new Map();
|
|
732
|
-
if (options.logReferrer)
|
|
733
|
-
parameters.set("re", btoa(document.referrer));
|
|
734
|
-
if (options.logUrl)
|
|
735
|
-
parameters.set("ur", btoa(window.location.href));
|
|
736
|
-
for (const [key, value] of Object.entries({
|
|
737
|
-
...options.parameters ?? {},
|
|
738
|
-
rn: Math.round(Math.random() * 1e4).toString()
|
|
739
|
-
}))
|
|
740
|
-
parameters.set(key, value);
|
|
741
|
-
context.parameters = parameters;
|
|
742
|
-
watch(
|
|
743
|
-
() => context.parameters,
|
|
744
|
-
(newParameters) => {
|
|
745
|
-
var _a;
|
|
746
|
-
(_a = context.events) == null ? void 0 : _a.parametersChange.dispatch(newParameters);
|
|
747
|
-
},
|
|
748
|
-
{
|
|
749
|
-
deep: true
|
|
750
|
-
}
|
|
751
|
-
);
|
|
752
|
-
}
|
|
753
|
-
function createGlobalHooks() {
|
|
754
|
-
const disposeFunctions = /* @__PURE__ */ new Set();
|
|
755
|
-
let isInit = false;
|
|
756
|
-
const [runOnInit, onInit, disposeOnInit] = createSyncHook({
|
|
757
|
-
onRun(callbacks) {
|
|
758
|
-
isInit = true;
|
|
759
|
-
callbacks == null ? void 0 : callbacks.clear();
|
|
760
|
-
},
|
|
761
|
-
onAdd() {
|
|
762
|
-
if (isInit)
|
|
763
|
-
runOnInit();
|
|
764
|
-
}
|
|
765
|
-
});
|
|
766
|
-
disposeFunctions.add(disposeOnInit);
|
|
767
|
-
let isDisposed = false;
|
|
768
|
-
const [runOnDispose, onDispose, disposeOnDispose] = createSyncHook({
|
|
769
|
-
onRun(callbacks) {
|
|
770
|
-
isDisposed = true;
|
|
771
|
-
callbacks == null ? void 0 : callbacks.clear();
|
|
772
|
-
},
|
|
773
|
-
onAdd() {
|
|
774
|
-
if (isDisposed)
|
|
775
|
-
runOnDispose();
|
|
776
|
-
}
|
|
777
|
-
});
|
|
778
|
-
disposeFunctions.add(disposeOnDispose);
|
|
779
|
-
const [runOnRequest, onRequest, disposeOnRequest] = createAsyncHook();
|
|
780
|
-
disposeFunctions.add(disposeOnRequest);
|
|
781
|
-
const [runOnResponse, onResponse, disposeOnResponse] = createAsyncHook();
|
|
782
|
-
disposeFunctions.add(disposeOnResponse);
|
|
783
|
-
const [runOnSlotCreate, onSlotCreate, disposeOnSlotCreate] = createSyncHook();
|
|
784
|
-
disposeFunctions.add(disposeOnSlotCreate);
|
|
785
|
-
function clearAll() {
|
|
786
|
-
for (const disposeFunction of disposeFunctions)
|
|
787
|
-
disposeFunction();
|
|
788
|
-
}
|
|
789
|
-
return {
|
|
790
|
-
runOnInit,
|
|
791
|
-
onInit,
|
|
792
|
-
runOnDispose,
|
|
793
|
-
onDispose,
|
|
794
|
-
runOnRequest,
|
|
795
|
-
onRequest,
|
|
796
|
-
runOnResponse,
|
|
797
|
-
onResponse,
|
|
798
|
-
runOnSlotCreate,
|
|
799
|
-
onSlotCreate,
|
|
800
|
-
clearAll
|
|
801
|
-
};
|
|
802
|
-
}
|
|
803
|
-
function createAdhese(options) {
|
|
804
|
-
const scope = effectScope();
|
|
805
|
-
return scope.run(() => {
|
|
806
|
-
var _a;
|
|
807
|
-
const mergedOptions = {
|
|
808
|
-
host: `https://ads-${options.account}.adhese.com`,
|
|
809
|
-
poolHost: `https://pool-${options.account}.adhese.com`,
|
|
810
|
-
location: "homepage",
|
|
811
|
-
requestType: "POST",
|
|
812
|
-
debug: false,
|
|
813
|
-
initialSlots: [],
|
|
814
|
-
findDomSlotsOnLoad: false,
|
|
815
|
-
consent: false,
|
|
816
|
-
logReferrer: true,
|
|
817
|
-
logUrl: true,
|
|
818
|
-
eagerRendering: false,
|
|
819
|
-
viewabilityTracking: true,
|
|
820
|
-
...options
|
|
821
|
-
};
|
|
822
|
-
setupLogging(mergedOptions);
|
|
823
|
-
const hooks = createGlobalHooks();
|
|
824
|
-
const context = reactive({
|
|
825
|
-
location: mergedOptions.location,
|
|
826
|
-
consent: mergedOptions.consent,
|
|
827
|
-
debug: mergedOptions.debug,
|
|
828
|
-
options: mergedOptions,
|
|
829
|
-
logger,
|
|
830
|
-
isDisposed: false,
|
|
831
|
-
parameters: /* @__PURE__ */ new Map(),
|
|
832
|
-
events: createEventManager(),
|
|
833
|
-
slots: /* @__PURE__ */ new Map(),
|
|
834
|
-
device: "unknown",
|
|
835
|
-
hooks,
|
|
836
|
-
plugins: {},
|
|
837
|
-
dispose,
|
|
838
|
-
findDomSlots: findDomSlots2,
|
|
839
|
-
getAll,
|
|
840
|
-
get,
|
|
841
|
-
addSlot
|
|
842
|
-
});
|
|
843
|
-
for (const [index, plugin] of ((_a = options.plugins) == null ? void 0 : _a.entries()) ?? []) {
|
|
844
|
-
const data = plugin(context, {
|
|
845
|
-
index,
|
|
846
|
-
version,
|
|
847
|
-
hooks
|
|
848
|
-
});
|
|
849
|
-
const name2 = data.name;
|
|
850
|
-
context.plugins[name2] = omit(data, ["name"]);
|
|
851
|
-
}
|
|
852
|
-
watch(() => context.location, (newLocation) => {
|
|
853
|
-
var _a2;
|
|
854
|
-
(_a2 = context.events) == null ? void 0 : _a2.locationChange.dispatch(newLocation);
|
|
855
|
-
});
|
|
856
|
-
useMainParameters(context, mergedOptions);
|
|
857
|
-
const slotManager = createSlotManager({
|
|
858
|
-
initialSlots: mergedOptions.initialSlots,
|
|
859
|
-
context
|
|
860
|
-
});
|
|
861
|
-
function getAll() {
|
|
862
|
-
return slotManager.getAll() ?? [];
|
|
863
|
-
}
|
|
864
|
-
context.getAll = getAll;
|
|
865
|
-
function get(name2) {
|
|
866
|
-
return slotManager.get(name2);
|
|
867
|
-
}
|
|
868
|
-
context.get = get;
|
|
869
|
-
function addSlot(slotOptions) {
|
|
870
|
-
return slotManager.add(slotOptions);
|
|
871
|
-
}
|
|
872
|
-
context.addSlot = addSlot;
|
|
873
|
-
async function findDomSlots2() {
|
|
874
|
-
const domSlots = (await slotManager.findDomSlots() ?? []).filter((slot) => !slot.lazyLoading);
|
|
875
|
-
if (domSlots.length <= 0)
|
|
876
|
-
return [];
|
|
877
|
-
await fetchAllUnrenderedSlots(context.getAll());
|
|
878
|
-
return domSlots;
|
|
879
|
-
}
|
|
880
|
-
context.findDomSlots = findDomSlots2;
|
|
881
|
-
useMainDebugMode(context);
|
|
882
|
-
useMainQueryDetector(mergedOptions, context);
|
|
883
|
-
useConsent(context);
|
|
884
|
-
function dispose() {
|
|
885
|
-
var _a2, _b;
|
|
886
|
-
context.isDisposed = true;
|
|
887
|
-
slotManager.dispose();
|
|
888
|
-
(_a2 = context.parameters) == null ? void 0 : _a2.clear();
|
|
889
|
-
(_b = context.events) == null ? void 0 : _b.dispose();
|
|
890
|
-
hooks.runOnDispose();
|
|
891
|
-
hooks.clearAll();
|
|
892
|
-
scope.stop();
|
|
893
|
-
}
|
|
894
|
-
context.dispose = dispose;
|
|
895
|
-
hooks.onInit(async () => {
|
|
896
|
-
var _a2;
|
|
897
|
-
await awaitTimeout(0);
|
|
898
|
-
if ((slotManager.getAll().length ?? 0) > 0)
|
|
899
|
-
await fetchAllUnrenderedSlots(context.getAll()).catch(logger.error);
|
|
900
|
-
if (mergedOptions.findDomSlotsOnLoad)
|
|
901
|
-
await (context == null ? void 0 : context.findDomSlots());
|
|
902
|
-
if (mergedOptions.debug || window.location.search.includes("adhese_debug=true") || isPreviewMode())
|
|
903
|
-
(_a2 = context.events) == null ? void 0 : _a2.debugChange.dispatch(true);
|
|
904
|
-
if (!scope.active)
|
|
905
|
-
dispose();
|
|
906
|
-
});
|
|
907
|
-
hooks.runOnInit();
|
|
908
|
-
return context;
|
|
909
|
-
});
|
|
910
|
-
}
|
|
1
|
+
import { createAdhese } from "./main.js";
|
|
911
2
|
export {
|
|
912
3
|
createAdhese
|
|
913
4
|
};
|