ad-blockguard 0.1.0-pre
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/LICENSE +21 -0
- package/dist/blockguard.cjs.js +364 -0
- package/dist/blockguard.cjs.js.map +7 -0
- package/dist/blockguard.esm.js +344 -0
- package/dist/blockguard.esm.js.map +7 -0
- package/dist/blockguard.min.js +8 -0
- package/dist/blockguard.min.js.map +7 -0
- package/dist/blockguard.react.js +370 -0
- package/dist/blockguard.react.js.map +7 -0
- package/dist/blockguard.umd.js +366 -0
- package/dist/blockguard.umd.js.map +7 -0
- package/dist/blockguard.vue.js +372 -0
- package/dist/blockguard.vue.js.map +7 -0
- package/dist/index.html +167 -0
- package/package.json +60 -0
- package/readme.md +339 -0
- package/types/index.d.ts +43 -0
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
// src/vue.js
|
|
2
|
+
import { ref, onMounted, onUnmounted } from "vue";
|
|
3
|
+
|
|
4
|
+
// src/core.js
|
|
5
|
+
var DEFAULT_TEST_URLS = [
|
|
6
|
+
"https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js",
|
|
7
|
+
"https://www.google-analytics.com/analytics.js",
|
|
8
|
+
"https://ad.doubleclick.net/ddm/pixel/1/1",
|
|
9
|
+
"https://www.googleadservices.com/pagead/conversion.js",
|
|
10
|
+
"https://cdn.taboola.com/libtrc/loader.js",
|
|
11
|
+
"https://connect.facebook.net/en_US/fbevents.js",
|
|
12
|
+
"https://www.googletagmanager.com/gtag/js"
|
|
13
|
+
];
|
|
14
|
+
var DEFAULT_BAIT_CONFIGS = [
|
|
15
|
+
{ classes: "ad ads ad-container banner-ad advertisement", attrs: { "data-ad-slot": "1234567890" } },
|
|
16
|
+
{ classes: "pub_300x250 pub_728x90 text-ad", attrs: { "data-ad-client": "ca-pub-0000000000000000" } },
|
|
17
|
+
{ classes: "adsbygoogle adsbox ad-placement AdContent", attrs: { "data-full-width-responsive": "true" } },
|
|
18
|
+
{ classes: "google-ad sponsored-content ad-banner BannerAd", attrs: { "data-ad-type": "banner" } }
|
|
19
|
+
];
|
|
20
|
+
var generateId = () => Math.random().toString(36).substring(2, 11);
|
|
21
|
+
var BlockGuard = class {
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
this._isBrowser = typeof window !== "undefined" && typeof document !== "undefined";
|
|
24
|
+
this.config = {
|
|
25
|
+
// Core
|
|
26
|
+
checkOnLoad: options.checkOnLoad !== false,
|
|
27
|
+
debug: options.debug === true,
|
|
28
|
+
// Detection methods
|
|
29
|
+
networkTest: options.networkTest !== false,
|
|
30
|
+
// Primary – DNS blockers
|
|
31
|
+
bannerScan: options.bannerScan === true,
|
|
32
|
+
// Secondary – visual blockers, DEFAULT OFF
|
|
33
|
+
// Network config
|
|
34
|
+
testUrls: options.testUrls || DEFAULT_TEST_URLS,
|
|
35
|
+
// Completely replace defaults
|
|
36
|
+
extraTestUrls: options.extraTestUrls || [],
|
|
37
|
+
// Append to defaults
|
|
38
|
+
networkTestCount: options.networkTestCount || 3,
|
|
39
|
+
networkTimeout: options.networkTimeout || 5e3,
|
|
40
|
+
networkThreshold: options.networkThreshold || 2,
|
|
41
|
+
// Min blocked to trigger
|
|
42
|
+
// Banner scan config (only relevant if bannerScan: true)
|
|
43
|
+
customBaitClasses: options.customBaitClasses || [],
|
|
44
|
+
baitCheckInterval: options.baitCheckInterval || 100,
|
|
45
|
+
baitCheckAttempts: options.baitCheckAttempts || 5,
|
|
46
|
+
// Analytics
|
|
47
|
+
gtag: options.gtag === true,
|
|
48
|
+
// Auto-fire gtag if present, DEFAULT OFF (need on in config.)
|
|
49
|
+
gtagEventName: options.gtagEventName || "adblock_detected",
|
|
50
|
+
gtagParams: options.gtagParams || {},
|
|
51
|
+
// Custom analytics callback (result, reason, details) => void
|
|
52
|
+
analyticsCallback: options.analyticsCallback || null,
|
|
53
|
+
// Result callbacks
|
|
54
|
+
onDetected: options.onDetected || null,
|
|
55
|
+
onNotDetected: options.onNotDetected || null,
|
|
56
|
+
onResult: options.onResult || null
|
|
57
|
+
// Always fired: (detected, reason, details)
|
|
58
|
+
};
|
|
59
|
+
this._state = {
|
|
60
|
+
isChecking: false,
|
|
61
|
+
result: null,
|
|
62
|
+
reason: null,
|
|
63
|
+
details: {},
|
|
64
|
+
baits: [],
|
|
65
|
+
observer: null,
|
|
66
|
+
networkResults: []
|
|
67
|
+
};
|
|
68
|
+
this._callbacks = { detected: [], notDetected: [] };
|
|
69
|
+
if (this.config.onDetected) this.onDetected(this.config.onDetected);
|
|
70
|
+
if (this.config.onNotDetected) this.onNotDetected(this.config.onNotDetected);
|
|
71
|
+
if (this._isBrowser && this.config.checkOnLoad) {
|
|
72
|
+
if (document.readyState === "loading") {
|
|
73
|
+
document.addEventListener("DOMContentLoaded", () => this.check());
|
|
74
|
+
} else {
|
|
75
|
+
setTimeout(() => this.check(), 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// --- Public API -------------
|
|
80
|
+
onDetected(fn) {
|
|
81
|
+
if (typeof fn === "function") this._callbacks.detected.push(fn);
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
onNotDetected(fn) {
|
|
85
|
+
if (typeof fn === "function") this._callbacks.notDetected.push(fn);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
getResult() {
|
|
89
|
+
return this._state.result;
|
|
90
|
+
}
|
|
91
|
+
getReason() {
|
|
92
|
+
return this._state.reason;
|
|
93
|
+
}
|
|
94
|
+
getDetails() {
|
|
95
|
+
return this._state.details;
|
|
96
|
+
}
|
|
97
|
+
async check() {
|
|
98
|
+
if (!this._isBrowser) return null;
|
|
99
|
+
if (this._state.isChecking) {
|
|
100
|
+
this._log("Check already running");
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
if (this._state.result !== null) {
|
|
104
|
+
this._fireCallbacks(this._state.result);
|
|
105
|
+
return this._state.result;
|
|
106
|
+
}
|
|
107
|
+
this._state.isChecking = true;
|
|
108
|
+
this._log("Detection started");
|
|
109
|
+
if (this.config.bannerScan) {
|
|
110
|
+
this._injectBaits();
|
|
111
|
+
const baitDetected = await this._executeBaitChecks();
|
|
112
|
+
if (baitDetected) return this._state.result;
|
|
113
|
+
}
|
|
114
|
+
if (this.config.networkTest) {
|
|
115
|
+
const networkDetected = await this._runNetworkTests();
|
|
116
|
+
if (networkDetected) {
|
|
117
|
+
this._triggerDetection("network_blocked");
|
|
118
|
+
} else {
|
|
119
|
+
this._triggerClean();
|
|
120
|
+
}
|
|
121
|
+
} else if (!this.config.bannerScan) {
|
|
122
|
+
this._triggerClean();
|
|
123
|
+
}
|
|
124
|
+
return this._state.result;
|
|
125
|
+
}
|
|
126
|
+
reset() {
|
|
127
|
+
this._cleanup();
|
|
128
|
+
this._state.result = null;
|
|
129
|
+
this._state.reason = null;
|
|
130
|
+
this._state.details = {};
|
|
131
|
+
this._state.networkResults = [];
|
|
132
|
+
return this;
|
|
133
|
+
}
|
|
134
|
+
destroy() {
|
|
135
|
+
this._cleanup();
|
|
136
|
+
this._callbacks.detected = [];
|
|
137
|
+
this._callbacks.notDetected = [];
|
|
138
|
+
}
|
|
139
|
+
// ---- Network Tests ---------------
|
|
140
|
+
async _runNetworkTests() {
|
|
141
|
+
const allUrls = [
|
|
142
|
+
...this.config.testUrls,
|
|
143
|
+
...this.config.extraTestUrls
|
|
144
|
+
];
|
|
145
|
+
const picked = allUrls.sort(() => Math.random() - 0.5).slice(0, this.config.networkTestCount);
|
|
146
|
+
this._log("Network tests:", picked);
|
|
147
|
+
const results = await Promise.all(
|
|
148
|
+
picked.map((url, i) => this._testUrl(url, i))
|
|
149
|
+
);
|
|
150
|
+
this._state.networkResults = results;
|
|
151
|
+
this._state.details.networkResults = results;
|
|
152
|
+
const blockedCount = results.filter((r) => !r.reachable).length;
|
|
153
|
+
this._log(`Network: ${blockedCount}/${results.length} blocked`);
|
|
154
|
+
return blockedCount >= this.config.networkThreshold;
|
|
155
|
+
}
|
|
156
|
+
_testUrl(url, index) {
|
|
157
|
+
return new Promise((resolve) => {
|
|
158
|
+
const testUrl = url + (url.includes("?") ? "&" : "?") + "_bg=" + generateId();
|
|
159
|
+
let timer;
|
|
160
|
+
const img = new Image();
|
|
161
|
+
const done = (reachable, reason) => {
|
|
162
|
+
clearTimeout(timer);
|
|
163
|
+
resolve({ url, reachable, reason });
|
|
164
|
+
};
|
|
165
|
+
timer = setTimeout(() => done(false, "timeout"), this.config.networkTimeout);
|
|
166
|
+
img.onload = () => {
|
|
167
|
+
setTimeout(() => {
|
|
168
|
+
const entry = this._getPerfEntry(testUrl);
|
|
169
|
+
done(
|
|
170
|
+
!!(entry && entry.duration > 0),
|
|
171
|
+
entry ? "timing_confirmed" : "loaded_no_timing"
|
|
172
|
+
);
|
|
173
|
+
}, 100);
|
|
174
|
+
};
|
|
175
|
+
img.onerror = () => {
|
|
176
|
+
const entry = this._getPerfEntry(testUrl);
|
|
177
|
+
done(
|
|
178
|
+
!!(entry && entry.duration > 0),
|
|
179
|
+
entry ? "cors_reached" : "network_error"
|
|
180
|
+
);
|
|
181
|
+
};
|
|
182
|
+
img.src = testUrl;
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
_getPerfEntry(url) {
|
|
186
|
+
if (!window.performance?.getEntriesByType) return null;
|
|
187
|
+
const base = url.split("?")[0];
|
|
188
|
+
const entries = window.performance.getEntriesByType("resource");
|
|
189
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
190
|
+
if (entries[i].name.includes(base)) return entries[i];
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
// ─── Banner / Bait Scan ────────────────────────────────────────
|
|
195
|
+
_injectBaits() {
|
|
196
|
+
if (!document.body) {
|
|
197
|
+
setTimeout(() => this._injectBaits(), 50);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const configs = [
|
|
201
|
+
...DEFAULT_BAIT_CONFIGS,
|
|
202
|
+
...this.config.customBaitClasses.map((cls) => ({ classes: cls, attrs: {} }))
|
|
203
|
+
];
|
|
204
|
+
configs.forEach((cfg) => {
|
|
205
|
+
const el = document.createElement("div");
|
|
206
|
+
el.id = `ad-${generateId()}`;
|
|
207
|
+
el.className = cfg.classes;
|
|
208
|
+
Object.entries(cfg.attrs).forEach(([k, v]) => el.setAttribute(k, v));
|
|
209
|
+
el.style.cssText = "width:1px!important;height:1px!important;position:absolute!important;left:-10000px!important;top:-10000px!important;z-index:-1!important;";
|
|
210
|
+
el.appendChild(Object.assign(document.createElement("ins"), { className: "adsbygoogle" }));
|
|
211
|
+
this._state.baits.push(el);
|
|
212
|
+
document.body.appendChild(el);
|
|
213
|
+
void el.offsetHeight;
|
|
214
|
+
});
|
|
215
|
+
if (window.MutationObserver) {
|
|
216
|
+
this._state.observer = new MutationObserver((mutations) => {
|
|
217
|
+
for (const m of mutations) {
|
|
218
|
+
if (m.type === "childList") {
|
|
219
|
+
for (const node of m.removedNodes) {
|
|
220
|
+
if (this._state.baits.includes(node)) {
|
|
221
|
+
this._triggerDetection("bait_removed");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (m.type === "attributes" && this._state.baits.includes(m.target)) {
|
|
227
|
+
setTimeout(() => {
|
|
228
|
+
if (this._checkBaitsBlocked()) this._triggerDetection("bait_modified");
|
|
229
|
+
}, 50);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
this._state.observer.observe(document.body, {
|
|
234
|
+
childList: true,
|
|
235
|
+
subtree: true,
|
|
236
|
+
attributes: true,
|
|
237
|
+
attributeFilter: ["style", "class"]
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
_checkBaitsBlocked() {
|
|
242
|
+
for (const el of this._state.baits) {
|
|
243
|
+
if (!document.body.contains(el)) return true;
|
|
244
|
+
if (el.offsetParent === null) return true;
|
|
245
|
+
if (el.offsetHeight === 0 || el.offsetWidth === 0) return true;
|
|
246
|
+
if (window.getComputedStyle) {
|
|
247
|
+
const s = window.getComputedStyle(el);
|
|
248
|
+
if (s.display === "none" || s.visibility === "hidden" || parseFloat(s.opacity) === 0) return true;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (document.body.getAttribute("abp") !== null) return true;
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
async _executeBaitChecks() {
|
|
255
|
+
return new Promise((resolve) => {
|
|
256
|
+
let attempts = 0;
|
|
257
|
+
const check = () => {
|
|
258
|
+
if (this._state.result !== null) {
|
|
259
|
+
resolve(true);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (this._checkBaitsBlocked()) {
|
|
263
|
+
this._triggerDetection("bait_blocked");
|
|
264
|
+
resolve(true);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (++attempts >= this.config.baitCheckAttempts) {
|
|
268
|
+
resolve(false);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
setTimeout(check, this.config.baitCheckInterval);
|
|
272
|
+
};
|
|
273
|
+
check();
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
// ─── Trigger / Callbacks ───────────────────────────────────────
|
|
277
|
+
_triggerDetection(reason) {
|
|
278
|
+
if (this._state.result !== null) return;
|
|
279
|
+
this._log("DETECTED:", reason);
|
|
280
|
+
this._state.result = true;
|
|
281
|
+
this._state.reason = reason;
|
|
282
|
+
this._finalize(true);
|
|
283
|
+
}
|
|
284
|
+
_triggerClean() {
|
|
285
|
+
if (this._state.result !== null) return;
|
|
286
|
+
this._log("CLEAN");
|
|
287
|
+
this._state.result = false;
|
|
288
|
+
this._state.reason = "all_passed";
|
|
289
|
+
this._finalize(false);
|
|
290
|
+
}
|
|
291
|
+
_finalize(detected) {
|
|
292
|
+
this._cleanup();
|
|
293
|
+
if (detected && this.config.gtag && typeof window.gtag === "function") {
|
|
294
|
+
window.gtag("event", this.config.gtagEventName, {
|
|
295
|
+
reason: this._state.reason,
|
|
296
|
+
...this.config.gtagParams
|
|
297
|
+
});
|
|
298
|
+
this._log("gtag fired:", this.config.gtagEventName);
|
|
299
|
+
}
|
|
300
|
+
if (typeof this.config.analyticsCallback === "function") {
|
|
301
|
+
try {
|
|
302
|
+
this.config.analyticsCallback(detected, this._state.reason, this._state.details);
|
|
303
|
+
} catch (e) {
|
|
304
|
+
console.error("[BlockGuard] analyticsCallback error:", e);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (typeof this.config.onResult === "function") {
|
|
308
|
+
try {
|
|
309
|
+
this.config.onResult(detected, this._state.reason, this._state.details);
|
|
310
|
+
} catch (e) {
|
|
311
|
+
console.error("[BlockGuard] onResult error:", e);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
this._fireCallbacks(detected);
|
|
315
|
+
}
|
|
316
|
+
_fireCallbacks(detected) {
|
|
317
|
+
const list = this._callbacks[detected ? "detected" : "notDetected"];
|
|
318
|
+
list.forEach((fn) => {
|
|
319
|
+
try {
|
|
320
|
+
fn();
|
|
321
|
+
} catch (e) {
|
|
322
|
+
console.error("[BlockGuard] Callback error:", e);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
_cleanup() {
|
|
327
|
+
this._state.baits.forEach((el) => el?.parentNode?.removeChild(el));
|
|
328
|
+
this._state.baits = [];
|
|
329
|
+
this._state.observer?.disconnect();
|
|
330
|
+
this._state.observer = null;
|
|
331
|
+
this._state.isChecking = false;
|
|
332
|
+
}
|
|
333
|
+
_log(...args) {
|
|
334
|
+
if (this.config.debug) console.log("[BlockGuard]", ...args);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
var core_default = BlockGuard;
|
|
338
|
+
|
|
339
|
+
// src/vue.js
|
|
340
|
+
function useBlockGuard(options = {}) {
|
|
341
|
+
const detected = ref(null);
|
|
342
|
+
const reason = ref(null);
|
|
343
|
+
const checking = ref(true);
|
|
344
|
+
let bg = null;
|
|
345
|
+
onMounted(() => {
|
|
346
|
+
bg = new core_default({
|
|
347
|
+
...options,
|
|
348
|
+
checkOnLoad: false,
|
|
349
|
+
onResult: (det, rsn) => {
|
|
350
|
+
detected.value = det;
|
|
351
|
+
reason.value = rsn;
|
|
352
|
+
checking.value = false;
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
bg.check();
|
|
356
|
+
});
|
|
357
|
+
onUnmounted(() => bg?.destroy());
|
|
358
|
+
return { detected, reason, checking };
|
|
359
|
+
}
|
|
360
|
+
var vue_default = core_default;
|
|
361
|
+
export {
|
|
362
|
+
core_default as BlockGuard,
|
|
363
|
+
vue_default as default,
|
|
364
|
+
useBlockGuard
|
|
365
|
+
};
|
|
366
|
+
/*!
|
|
367
|
+
* BlockGuard 0.1.0
|
|
368
|
+
* Universal AdBlock & DNS-Blocker Detection - stop nasty tools from interfering with your website's ads and analytics.
|
|
369
|
+
* (c) 2026 Ponk445 — MIT License
|
|
370
|
+
* https://github.com/Ponk445/AD-BlockGuard
|
|
371
|
+
*/
|
|
372
|
+
//# sourceMappingURL=blockguard.vue.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/vue.js", "../src/core.js"],
|
|
4
|
+
"sourcesContent": ["import { ref, onMounted, onUnmounted } from 'vue';\r\nimport BlockGuard from './core.js';\r\n\r\nexport function useBlockGuard(options = {}) {\r\n const detected = ref(null);\r\n const reason = ref(null);\r\n const checking = ref(true);\r\n let bg = null;\r\n\r\n onMounted(() => {\r\n bg = new BlockGuard({\r\n ...options,\r\n checkOnLoad: false,\r\n onResult: (det, rsn) => {\r\n detected.value = det;\r\n reason.value = rsn;\r\n checking.value = false;\r\n },\r\n });\r\n bg.check();\r\n });\r\n\r\n onUnmounted(() => bg?.destroy());\r\n\r\n return { detected, reason, checking };\r\n}\r\n\r\nexport { BlockGuard };\r\nexport default BlockGuard;\r\n", "/*!\r\n * BlockGuard 0.1.0\r\n * Universal AdBlock & DNS-Blocker Detection - stop nasty tools from interfering with your website's ads and analytics.\r\n * (c) 2026 Ponk445 \u2014 MIT License\r\n * https://github.com/Ponk445/AD-BlockGuard\r\n */\r\n\r\nconst DEFAULT_TEST_URLS = [\r\n 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js',\r\n 'https://www.google-analytics.com/analytics.js',\r\n 'https://ad.doubleclick.net/ddm/pixel/1/1',\r\n 'https://www.googleadservices.com/pagead/conversion.js',\r\n 'https://cdn.taboola.com/libtrc/loader.js',\r\n 'https://connect.facebook.net/en_US/fbevents.js',\r\n 'https://www.googletagmanager.com/gtag/js',\r\n];\r\n\r\nconst DEFAULT_BAIT_CONFIGS = [\r\n { classes: 'ad ads ad-container banner-ad advertisement', attrs: { 'data-ad-slot': '1234567890' } },\r\n { classes: 'pub_300x250 pub_728x90 text-ad', attrs: { 'data-ad-client': 'ca-pub-0000000000000000' } },\r\n { classes: 'adsbygoogle adsbox ad-placement AdContent', attrs: { 'data-full-width-responsive': 'true' } },\r\n { classes: 'google-ad sponsored-content ad-banner BannerAd', attrs: { 'data-ad-type': 'banner' } },\r\n];\r\n\r\nconst generateId = () => Math.random().toString(36).substring(2, 11);\r\n\r\nclass BlockGuard {\r\n constructor(options = {}) {\r\n // \u2500\u2500 SSR guard (Next.js, Nuxt SSR etc.)\r\n this._isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';\r\n\r\n this.config = {\r\n // Core\r\n checkOnLoad: options.checkOnLoad !== false,\r\n debug: options.debug === true,\r\n\r\n // Detection methods\r\n networkTest: options.networkTest !== false, // Primary \u2013 DNS blockers\r\n bannerScan: options.bannerScan === true, // Secondary \u2013 visual blockers, DEFAULT OFF\r\n\r\n // Network config\r\n testUrls: options.testUrls || DEFAULT_TEST_URLS, // Completely replace defaults\r\n extraTestUrls: options.extraTestUrls || [], // Append to defaults\r\n networkTestCount: options.networkTestCount || 3,\r\n networkTimeout: options.networkTimeout || 5000,\r\n networkThreshold: options.networkThreshold || 2, // Min blocked to trigger\r\n\r\n // Banner scan config (only relevant if bannerScan: true)\r\n customBaitClasses: options.customBaitClasses || [],\r\n baitCheckInterval: options.baitCheckInterval || 100,\r\n baitCheckAttempts: options.baitCheckAttempts || 5,\r\n\r\n // Analytics\r\n gtag: options.gtag === true, // Auto-fire gtag if present, DEFAULT OFF (need on in config.)\r\n gtagEventName: options.gtagEventName || 'adblock_detected',\r\n gtagParams: options.gtagParams || {},\r\n\r\n // Custom analytics callback (result, reason, details) => void\r\n analyticsCallback: options.analyticsCallback || null,\r\n\r\n // Result callbacks\r\n onDetected: options.onDetected || null,\r\n onNotDetected: options.onNotDetected || null,\r\n onResult: options.onResult || null, // Always fired: (detected, reason, details)\r\n };\r\n\r\n this._state = {\r\n isChecking: false,\r\n result: null,\r\n reason: null,\r\n details: {},\r\n baits: [],\r\n observer: null,\r\n networkResults: [],\r\n };\r\n\r\n this._callbacks = { detected: [], notDetected: [] };\r\n\r\n if (this.config.onDetected) this.onDetected(this.config.onDetected);\r\n if (this.config.onNotDetected) this.onNotDetected(this.config.onNotDetected);\r\n\r\n if (this._isBrowser && this.config.checkOnLoad) {\r\n if (document.readyState === 'loading') {\r\n document.addEventListener('DOMContentLoaded', () => this.check());\r\n } else {\r\n setTimeout(() => this.check(), 1);\r\n }\r\n }\r\n }\r\n\r\n // --- Public API -------------\r\n onDetected(fn) { if (typeof fn === 'function') this._callbacks.detected.push(fn); return this; }\r\n onNotDetected(fn) { if (typeof fn === 'function') this._callbacks.notDetected.push(fn); return this; }\r\n getResult() { return this._state.result; }\r\n getReason() { return this._state.reason; }\r\n getDetails() { return this._state.details; }\r\n\r\n async check() {\r\n if (!this._isBrowser) return null;\r\n if (this._state.isChecking) { this._log('Check already running'); return null; }\r\n\r\n if (this._state.result !== null) {\r\n this._fireCallbacks(this._state.result);\r\n return this._state.result;\r\n }\r\n\r\n this._state.isChecking = true;\r\n this._log('Detection started');\r\n\r\n // 1: Banner scan (if enabled)\r\n if (this.config.bannerScan) {\r\n this._injectBaits();\r\n const baitDetected = await this._executeBaitChecks();\r\n if (baitDetected) return this._state.result;\r\n }\r\n\r\n // 2: Network test\r\n if (this.config.networkTest) {\r\n const networkDetected = await this._runNetworkTests();\r\n if (networkDetected) {\r\n this._triggerDetection('network_blocked');\r\n } else {\r\n this._triggerClean();\r\n }\r\n } else if (!this.config.bannerScan) {\r\n this._triggerClean();\r\n }\r\n\r\n return this._state.result;\r\n }\r\n\r\n reset() {\r\n this._cleanup();\r\n this._state.result = null;\r\n this._state.reason = null;\r\n this._state.details = {};\r\n this._state.networkResults = [];\r\n return this;\r\n }\r\n\r\n destroy() {\r\n this._cleanup();\r\n this._callbacks.detected = [];\r\n this._callbacks.notDetected = [];\r\n }\r\n\r\n // ---- Network Tests ---------------\r\n\r\n async _runNetworkTests() {\r\n const allUrls = [\r\n ...this.config.testUrls,\r\n ...this.config.extraTestUrls,\r\n ];\r\n\r\n const picked = allUrls\r\n .sort(() => Math.random() - 0.5)\r\n .slice(0, this.config.networkTestCount);\r\n\r\n this._log('Network tests:', picked);\r\n\r\n const results = await Promise.all(\r\n picked.map((url, i) => this._testUrl(url, i))\r\n );\r\n\r\n this._state.networkResults = results;\r\n this._state.details.networkResults = results;\r\n\r\n const blockedCount = results.filter(r => !r.reachable).length;\r\n this._log(`Network: ${blockedCount}/${results.length} blocked`);\r\n\r\n return blockedCount >= this.config.networkThreshold;\r\n }\r\n\r\n _testUrl(url, index) {\r\n return new Promise((resolve) => {\r\n const testUrl = url + (url.includes('?') ? '&' : '?') + '_bg=' + generateId();\r\n let timer;\r\n const img = new Image();\r\n\r\n const done = (reachable, reason) => {\r\n clearTimeout(timer);\r\n resolve({ url, reachable, reason });\r\n };\r\n\r\n timer = setTimeout(() => done(false, 'timeout'), this.config.networkTimeout);\r\n\r\n img.onload = () => {\r\n setTimeout(() => {\r\n const entry = this._getPerfEntry(testUrl);\r\n done(\r\n !!(entry && entry.duration > 0),\r\n entry ? 'timing_confirmed' : 'loaded_no_timing'\r\n );\r\n }, 100);\r\n };\r\n\r\n img.onerror = () => {\r\n const entry = this._getPerfEntry(testUrl);\r\n // CORS error but server reached, so not blocked\r\n done(\r\n !!(entry && entry.duration > 0),\r\n entry ? 'cors_reached' : 'network_error'\r\n );\r\n };\r\n\r\n img.src = testUrl;\r\n });\r\n }\r\n\r\n _getPerfEntry(url) {\r\n if (!window.performance?.getEntriesByType) return null;\r\n const base = url.split('?')[0];\r\n const entries = window.performance.getEntriesByType('resource');\r\n for (let i = entries.length - 1; i >= 0; i--) {\r\n if (entries[i].name.includes(base)) return entries[i];\r\n }\r\n return null;\r\n }\r\n\r\n // \u2500\u2500\u2500 Banner / Bait Scan \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n _injectBaits() {\r\n if (!document.body) {\r\n setTimeout(() => this._injectBaits(), 50);\r\n return;\r\n }\r\n\r\n const configs = [\r\n ...DEFAULT_BAIT_CONFIGS,\r\n ...this.config.customBaitClasses.map(cls => ({ classes: cls, attrs: {} })),\r\n ];\r\n\r\n configs.forEach(cfg => {\r\n const el = document.createElement('div');\r\n el.id = `ad-${generateId()}`;\r\n el.className = cfg.classes;\r\n Object.entries(cfg.attrs).forEach(([k, v]) => el.setAttribute(k, v));\r\n el.style.cssText = 'width:1px!important;height:1px!important;position:absolute!important;left:-10000px!important;top:-10000px!important;z-index:-1!important;';\r\n el.appendChild(Object.assign(document.createElement('ins'), { className: 'adsbygoogle' }));\r\n this._state.baits.push(el);\r\n document.body.appendChild(el);\r\n void el.offsetHeight;\r\n });\r\n\r\n if (window.MutationObserver) {\r\n this._state.observer = new MutationObserver(mutations => {\r\n for (const m of mutations) {\r\n if (m.type === 'childList') {\r\n for (const node of m.removedNodes) {\r\n if (this._state.baits.includes(node)) {\r\n this._triggerDetection('bait_removed');\r\n return;\r\n }\r\n }\r\n }\r\n if (m.type === 'attributes' && this._state.baits.includes(m.target)) {\r\n setTimeout(() => {\r\n if (this._checkBaitsBlocked()) this._triggerDetection('bait_modified');\r\n }, 50);\r\n }\r\n }\r\n });\r\n this._state.observer.observe(document.body, {\r\n childList: true, subtree: true,\r\n attributes: true, attributeFilter: ['style', 'class'],\r\n });\r\n }\r\n }\r\n\r\n _checkBaitsBlocked() {\r\n for (const el of this._state.baits) {\r\n if (!document.body.contains(el)) return true;\r\n if (el.offsetParent === null) return true;\r\n if (el.offsetHeight === 0 || el.offsetWidth === 0) return true;\r\n if (window.getComputedStyle) {\r\n const s = window.getComputedStyle(el);\r\n if (s.display === 'none' || s.visibility === 'hidden' || parseFloat(s.opacity) === 0) return true;\r\n }\r\n }\r\n if (document.body.getAttribute('abp') !== null) return true;\r\n return false;\r\n }\r\n\r\n async _executeBaitChecks() {\r\n return new Promise(resolve => {\r\n let attempts = 0;\r\n const check = () => {\r\n if (this._state.result !== null) { resolve(true); return; }\r\n if (this._checkBaitsBlocked()) {\r\n this._triggerDetection('bait_blocked');\r\n resolve(true);\r\n return;\r\n }\r\n if (++attempts >= this.config.baitCheckAttempts) { resolve(false); return; }\r\n setTimeout(check, this.config.baitCheckInterval);\r\n };\r\n check();\r\n });\r\n }\r\n\r\n // \u2500\u2500\u2500 Trigger / Callbacks \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\r\n\r\n _triggerDetection(reason) {\r\n if (this._state.result !== null) return;\r\n this._log('DETECTED:', reason);\r\n this._state.result = true;\r\n this._state.reason = reason;\r\n this._finalize(true);\r\n }\r\n\r\n _triggerClean() {\r\n if (this._state.result !== null) return;\r\n this._log('CLEAN');\r\n this._state.result = false;\r\n this._state.reason = 'all_passed';\r\n this._finalize(false);\r\n }\r\n\r\n _finalize(detected) {\r\n this._cleanup();\r\n\r\n // Built-in gtag\r\n if (detected && this.config.gtag && typeof window.gtag === 'function') {\r\n window.gtag('event', this.config.gtagEventName, {\r\n reason: this._state.reason,\r\n ...this.config.gtagParams,\r\n });\r\n this._log('gtag fired:', this.config.gtagEventName);\r\n }\r\n\r\n // Custom analytics callback\r\n if (typeof this.config.analyticsCallback === 'function') {\r\n try {\r\n this.config.analyticsCallback(detected, this._state.reason, this._state.details);\r\n } catch (e) { console.error('[BlockGuard] analyticsCallback error:', e); }\r\n }\r\n\r\n // onResult (always)\r\n if (typeof this.config.onResult === 'function') {\r\n try { this.config.onResult(detected, this._state.reason, this._state.details); }\r\n catch (e) { console.error('[BlockGuard] onResult error:', e); }\r\n }\r\n\r\n this._fireCallbacks(detected);\r\n }\r\n\r\n _fireCallbacks(detected) {\r\n const list = this._callbacks[detected ? 'detected' : 'notDetected'];\r\n list.forEach(fn => { try { fn(); } catch (e) { console.error('[BlockGuard] Callback error:', e); } });\r\n }\r\n\r\n _cleanup() {\r\n this._state.baits.forEach(el => el?.parentNode?.removeChild(el));\r\n this._state.baits = [];\r\n this._state.observer?.disconnect();\r\n this._state.observer = null;\r\n this._state.isChecking = false;\r\n }\r\n\r\n _log(...args) {\r\n if (this.config.debug) console.log('[BlockGuard]', ...args);\r\n }\r\n}\r\n\r\nexport default BlockGuard;\r\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,KAAK,WAAW,mBAAmB;;;ACO5C,IAAM,oBAAoB;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,uBAAuB;AAAA,EAC3B,EAAE,SAAS,+CAA+C,OAAO,EAAE,gBAAgB,aAAa,EAAE;AAAA,EAClG,EAAE,SAAS,kCAAkC,OAAO,EAA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Z,QAAI,KAAK,OAAO,MAAO,SAAQ,IAAI,gBAAgB,GAAG,IAAI;AAAA,EAC5D;AACF;AAEA,IAAO,eAAQ;;;ADzWR,SAAS,cAAc,UAAU,CAAC,GAAG;AAC1C,QAAM,WAAW,IAAI,IAAI;AACzB,QAAM,SAAW,IAAI,IAAI;AACzB,QAAM,WAAW,IAAI,IAAI;AACzB,MAAI,KAAK;AAET,YAAU,MAAM;AACd,SAAK,IAAI,aAAW;AAAA,MAClB,GAAG;AAAA,MACH,aAAa;AAAA,MACb,UAAU,CAAC,KAAK,QAAQ;AACtB,iBAAS,QAAQ;AACjB,eAAO,QAAU;AACjB,iBAAS,QAAQ;AAAA,MACnB;AAAA,IACF,CAAC;AACD,OAAG,MAAM;AAAA,EACX,CAAC;AAED,cAAY,MAAM,IAAI,QAAQ,CAAC;AAE/B,SAAO,EAAE,UAAU,QAAQ,SAAS;AACtC;AAGA,IAAO,cAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.html
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="de">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>BlockGuard Test</title>
|
|
7
|
+
|
|
8
|
+
<style>
|
|
9
|
+
body {
|
|
10
|
+
font-family: system-ui, -apple-system, sans-serif;
|
|
11
|
+
background-color: #f4f4f9;
|
|
12
|
+
color: #333;
|
|
13
|
+
line-height: 1.6;
|
|
14
|
+
padding: 2rem;
|
|
15
|
+
max-width: 800px;
|
|
16
|
+
margin: 0 auto;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.content-box {
|
|
20
|
+
background: white;
|
|
21
|
+
padding: 2rem;
|
|
22
|
+
border-radius: 12px;
|
|
23
|
+
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.status {
|
|
27
|
+
padding: 1rem;
|
|
28
|
+
margin-bottom: 2rem;
|
|
29
|
+
border-radius: 8px;
|
|
30
|
+
background: #e2e8f0;
|
|
31
|
+
font-weight: bold;
|
|
32
|
+
text-align: center;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* Das AdBlocker Warn-Overlay (Paywall) */
|
|
36
|
+
#adblock-modal {
|
|
37
|
+
display: none; /* Standardmäßig versteckt */
|
|
38
|
+
position: fixed;
|
|
39
|
+
top: 0; left: 0; width: 100%; height: 100%;
|
|
40
|
+
background: rgba(0, 0, 0, 0.85);
|
|
41
|
+
backdrop-filter: blur(5px);
|
|
42
|
+
z-index: 9999;
|
|
43
|
+
justify-content: center;
|
|
44
|
+
align-items: center;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.modal-content {
|
|
48
|
+
background: white;
|
|
49
|
+
padding: 3rem;
|
|
50
|
+
border-radius: 16px;
|
|
51
|
+
max-width: 500px;
|
|
52
|
+
text-align: center;
|
|
53
|
+
box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.modal-content h2 {
|
|
57
|
+
color: #e53e3e;
|
|
58
|
+
margin-top: 0;
|
|
59
|
+
font-size: 1.8rem;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.modal-content p {
|
|
63
|
+
font-size: 1.1rem;
|
|
64
|
+
color: #4a5568;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.btn-reload {
|
|
68
|
+
margin-top: 1.5rem;
|
|
69
|
+
background: #3182ce;
|
|
70
|
+
color: white;
|
|
71
|
+
border: none;
|
|
72
|
+
padding: 12px 24px;
|
|
73
|
+
font-size: 1.1rem;
|
|
74
|
+
border-radius: 8px;
|
|
75
|
+
cursor: pointer;
|
|
76
|
+
transition: background 0.2s;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.btn-reload:hover {
|
|
80
|
+
background: #2b6cb0;
|
|
81
|
+
}
|
|
82
|
+
</style>
|
|
83
|
+
</head>
|
|
84
|
+
<body>
|
|
85
|
+
<div class="status" id="status-bar">
|
|
86
|
+
⏳ Überprüfe auf AdBlocker...
|
|
87
|
+
</div>
|
|
88
|
+
<noscript>
|
|
89
|
+
<style>
|
|
90
|
+
.content-box {
|
|
91
|
+
display: none;
|
|
92
|
+
}
|
|
93
|
+
</style>
|
|
94
|
+
<div>
|
|
95
|
+
<h1>JavaScript is Disabled</h1>
|
|
96
|
+
<p>Please enable JavaScript in your browser for the best experience.</p>
|
|
97
|
+
</div>
|
|
98
|
+
</noscript>
|
|
99
|
+
<div class="content-box">
|
|
100
|
+
<h1>Willkommen auf meiner Webseite!</h1>
|
|
101
|
+
<p>Dies ist ein Premium-Artikel, der durch Werbung finanziert wird. Wenn BlockGuard richtig funktioniert, solltest du diesen Text ohne Probleme lesen können, solange du keinen AdBlocker aktiviert hast.</p>
|
|
102
|
+
<p>Aktiviere nun deinen AdBlocker (z.B. uBlock Origin oder AdGuard) und lade die Seite neu, um zu sehen, wie das Overlay auftaucht.</p>
|
|
103
|
+
|
|
104
|
+
<!-- Ein echter Banner-Platzhalter (als Köder) -->
|
|
105
|
+
<div class="ad-banner" style="width:300px; height:250px; background:#ddd; margin: 2rem auto; display:flex; align-items:center; justify-content:center; color:#888;">
|
|
106
|
+
Werbeplatz
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
|
|
110
|
+
<!-- Das Warn-Overlay -->
|
|
111
|
+
<div id="adblock-modal">
|
|
112
|
+
<div class="modal-content">
|
|
113
|
+
<h2>🛑 AdBlocker erkannt!</h2>
|
|
114
|
+
<p>Wir haben festgestellt, dass du einen Werbeblocker nutzt (oder DNS-Anfragen blockiert werden).</p>
|
|
115
|
+
<p>Bitte deaktiviere ihn, um unsere Inhalte weiterhin kostenlos genießen zu können. Unterstütze unsere Arbeit!</p>
|
|
116
|
+
<button class="btn-reload" onclick="window.location.reload()">Ich habe ihn deaktiviert - Neu laden</button>
|
|
117
|
+
</div>
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<!-- 1. Skript importieren (muss im selben Ordner wie diese HTML-Datei sein) -->
|
|
121
|
+
<script src="blockguard.min.js" crossorigin="anonymous"></script>
|
|
122
|
+
|
|
123
|
+
<!-- 2. BlockGuard initiieren -->
|
|
124
|
+
<script>
|
|
125
|
+
// Wir warten bis die Seite fertig geladen ist
|
|
126
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
127
|
+
|
|
128
|
+
// Überprüfen, ob das Skript wirklich geladen wurde
|
|
129
|
+
if (typeof BlockGuard === 'undefined') {
|
|
130
|
+
document.getElementById('status-bar').innerHTML = '❌ Fehler: blockguard.min.js wurde nicht gefunden! Überprüfe den Dateipfad.';
|
|
131
|
+
document.getElementById('status-bar').style.background = '#fed7d7';
|
|
132
|
+
document.getElementById('status-bar').style.color = '#c53030';
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Wichtig für esbuild UMD/IIFE Exporte: Das Hauptmodul ist oft in .default
|
|
137
|
+
const BGClass = BlockGuard.default || BlockGuard;
|
|
138
|
+
|
|
139
|
+
// Instanz erstellen
|
|
140
|
+
const guard = new BGClass({
|
|
141
|
+
debug: true, // Logs in der Konsole anzeigen (F12)
|
|
142
|
+
bannerScan: true, // Scanne auch nach versteckten Bannern (uBlock)
|
|
143
|
+
networkTest: true, // Scanne nach blockierten URLs (DNS Blocker)
|
|
144
|
+
|
|
145
|
+
onDetected: function() {
|
|
146
|
+
console.log("🛑 DETECTED Callback ausgelöst!");
|
|
147
|
+
// Overlay anzeigen
|
|
148
|
+
document.getElementById('adblock-modal').style.display = 'flex';
|
|
149
|
+
// Status Bar aktualisieren
|
|
150
|
+
document.getElementById('status-bar').innerHTML = '🔴 AdBlocker aktiv! Grund: ' + guard.getReason();
|
|
151
|
+
document.getElementById('status-bar').style.background = '#fed7d7';
|
|
152
|
+
document.getElementById('status-bar').style.color = '#c53030';
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
onNotDetected: function() {
|
|
156
|
+
console.log("✅ CLEAN Callback ausgelöst!");
|
|
157
|
+
document.getElementById('status-bar').innerHTML = '🟢 Alles super! Kein AdBlocker gefunden.';
|
|
158
|
+
document.getElementById('status-bar').style.background = '#c6f6d5';
|
|
159
|
+
document.getElementById('status-bar').style.color = '#2f855a';
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Die Prüfung startet automatisch, da checkOnLoad standardmäßig true ist.
|
|
164
|
+
});
|
|
165
|
+
</script>
|
|
166
|
+
</body>
|
|
167
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ad-blockguard",
|
|
3
|
+
"version": "0.1.0-pre",
|
|
4
|
+
"description": "Universal AdBlock & DNS-Blocker detection for web, WP, React, Vue & Nuxt",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"adblock",
|
|
7
|
+
"adblock-detection",
|
|
8
|
+
"dns-blocker",
|
|
9
|
+
"ublock",
|
|
10
|
+
"adguard",
|
|
11
|
+
"analytics"
|
|
12
|
+
],
|
|
13
|
+
"author": "Ponk445",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/Ponk445/AD-BlockGuard.git"
|
|
18
|
+
},
|
|
19
|
+
"main": "dist/blockguard.cjs.js",
|
|
20
|
+
"module": "dist/blockguard.esm.js",
|
|
21
|
+
"browser": "dist/blockguard.umd.js",
|
|
22
|
+
"unpkg": "dist/blockguard.min.js",
|
|
23
|
+
"jsdelivr": "dist/blockguard.min.js",
|
|
24
|
+
"types": "types/index.d.ts",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"browser": "./dist/blockguard.umd.js",
|
|
29
|
+
"import": "./dist/blockguard.esm.js",
|
|
30
|
+
"require": "./dist/blockguard.cjs.js"
|
|
31
|
+
},
|
|
32
|
+
"./react": "./dist/blockguard.react.js",
|
|
33
|
+
"./vue": "./dist/blockguard.vue.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"types",
|
|
38
|
+
"README.md",
|
|
39
|
+
"LICENSE"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "node build.js",
|
|
43
|
+
"prepublishOnly": "npm run build"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"esbuild": "^0.27.4"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=16.8.0",
|
|
50
|
+
"vue": ">=3.0.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependenciesMeta": {
|
|
53
|
+
"react": {
|
|
54
|
+
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"vue": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|