real-view 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +197 -0
- package/dist/angular.cjs +174 -0
- package/dist/angular.d.cts +14 -0
- package/dist/angular.d.ts +14 -0
- package/dist/angular.js +37 -0
- package/dist/chunk-UW5FKFTH.js +123 -0
- package/dist/index.cjs +136 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +6 -0
- package/dist/react.cjs +149 -0
- package/dist/react.d.cts +6 -0
- package/dist/react.d.ts +6 -0
- package/dist/react.js +19 -0
- package/dist/solid.cjs +150 -0
- package/dist/solid.d.cts +6 -0
- package/dist/solid.d.ts +6 -0
- package/dist/solid.js +20 -0
- package/dist/svelte.cjs +146 -0
- package/dist/svelte.d.cts +11 -0
- package/dist/svelte.d.ts +11 -0
- package/dist/svelte.js +16 -0
- package/dist/vue.cjs +150 -0
- package/dist/vue.d.cts +6 -0
- package/dist/vue.d.ts +6 -0
- package/dist/vue.js +20 -0
- package/license +9 -0
- package/package.json +87 -0
package/dist/vue.cjs
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/vue.ts
|
|
20
|
+
var vue_exports = {};
|
|
21
|
+
__export(vue_exports, {
|
|
22
|
+
userealView: () => userealView
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(vue_exports);
|
|
25
|
+
var import_vue = require("vue");
|
|
26
|
+
|
|
27
|
+
// src/core/utils.ts
|
|
28
|
+
var isBrowser = () => {
|
|
29
|
+
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// src/core/engine.ts
|
|
33
|
+
var realViewEngine = class _realViewEngine {
|
|
34
|
+
constructor() {
|
|
35
|
+
this.observer = null;
|
|
36
|
+
this.watchers = /* @__PURE__ */ new Map();
|
|
37
|
+
if (!isBrowser()) return;
|
|
38
|
+
this.initObserver();
|
|
39
|
+
this.initTabListener();
|
|
40
|
+
}
|
|
41
|
+
static get() {
|
|
42
|
+
if (!this.instance) this.instance = new _realViewEngine();
|
|
43
|
+
return this.instance;
|
|
44
|
+
}
|
|
45
|
+
initObserver() {
|
|
46
|
+
this.observer = new IntersectionObserver(this.handleIntersect.bind(this), {
|
|
47
|
+
threshold: 0
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
initTabListener() {
|
|
51
|
+
document.addEventListener("visibilitychange", () => {
|
|
52
|
+
const isHidden = document.hidden;
|
|
53
|
+
this.watchers.forEach((w) => {
|
|
54
|
+
if (w.opts.trackTab && isHidden) {
|
|
55
|
+
this.notify(w, false);
|
|
56
|
+
} else if (w.state.inViewport && !isHidden) {
|
|
57
|
+
this.checkOcclusion(w);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
handleIntersect(entries) {
|
|
63
|
+
entries.forEach((entry) => {
|
|
64
|
+
const watcher = this.watchers.get(entry.target);
|
|
65
|
+
if (!watcher) return;
|
|
66
|
+
watcher.state.inViewport = entry.isIntersecting;
|
|
67
|
+
if (entry.isIntersecting) {
|
|
68
|
+
this.startPolling(watcher);
|
|
69
|
+
} else {
|
|
70
|
+
this.stopPolling(watcher);
|
|
71
|
+
this.notify(watcher, false);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
checkOcclusion(w) {
|
|
76
|
+
if (w.opts.trackTab && document.hidden) return this.notify(w, false);
|
|
77
|
+
const rect = w.el.getBoundingClientRect();
|
|
78
|
+
if (rect.width === 0 || rect.height === 0) return this.notify(w, false);
|
|
79
|
+
const style = window.getComputedStyle(w.el);
|
|
80
|
+
if (style.opacity === "0" || style.visibility === "hidden") return this.notify(w, false);
|
|
81
|
+
const x = rect.left + rect.width / 2;
|
|
82
|
+
const y = rect.top + rect.height / 2;
|
|
83
|
+
const topEl = document.elementFromPoint(x, y);
|
|
84
|
+
const isVisible = topEl ? w.el.contains(topEl) || w.el === topEl : false;
|
|
85
|
+
this.notify(w, isVisible);
|
|
86
|
+
}
|
|
87
|
+
startPolling(w) {
|
|
88
|
+
if (w.state.timer) return;
|
|
89
|
+
const tick = () => {
|
|
90
|
+
if ("requestIdleCallback" in window) {
|
|
91
|
+
window.requestIdleCallback(() => this.checkOcclusion(w));
|
|
92
|
+
} else {
|
|
93
|
+
this.checkOcclusion(w);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
tick();
|
|
97
|
+
w.state.timer = window.setInterval(tick, w.opts.pollInterval);
|
|
98
|
+
}
|
|
99
|
+
stopPolling(w) {
|
|
100
|
+
if (w.state.timer) {
|
|
101
|
+
clearInterval(w.state.timer);
|
|
102
|
+
w.state.timer = null;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
notify(w, isVisible) {
|
|
106
|
+
if (w.state.isOccluded !== !isVisible) {
|
|
107
|
+
w.state.isOccluded = !isVisible;
|
|
108
|
+
w.cb(isVisible);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
observe(el, cb, options = {}) {
|
|
112
|
+
if (!isBrowser()) return () => {
|
|
113
|
+
};
|
|
114
|
+
const opts = {
|
|
115
|
+
threshold: 0,
|
|
116
|
+
pollInterval: 1e3,
|
|
117
|
+
trackTab: true,
|
|
118
|
+
...options
|
|
119
|
+
};
|
|
120
|
+
this.watchers.set(el, {
|
|
121
|
+
el,
|
|
122
|
+
cb,
|
|
123
|
+
opts,
|
|
124
|
+
state: { inViewport: false, isOccluded: false, timer: null }
|
|
125
|
+
});
|
|
126
|
+
this.observer?.observe(el);
|
|
127
|
+
return () => {
|
|
128
|
+
this.stopPolling(this.watchers.get(el));
|
|
129
|
+
this.observer?.unobserve(el);
|
|
130
|
+
this.watchers.delete(el);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/vue.ts
|
|
136
|
+
function userealView(target, options) {
|
|
137
|
+
const isVisible = (0, import_vue.ref)(false);
|
|
138
|
+
let stop;
|
|
139
|
+
(0, import_vue.onMounted)(() => {
|
|
140
|
+
if (target.value) {
|
|
141
|
+
stop = realViewEngine.get().observe(target.value, (v) => isVisible.value = v, options);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
(0, import_vue.onUnmounted)(() => stop?.());
|
|
145
|
+
return isVisible;
|
|
146
|
+
}
|
|
147
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
148
|
+
0 && (module.exports = {
|
|
149
|
+
userealView
|
|
150
|
+
});
|
package/dist/vue.d.cts
ADDED
package/dist/vue.d.ts
ADDED
package/dist/vue.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
realViewEngine
|
|
3
|
+
} from "./chunk-UW5FKFTH.js";
|
|
4
|
+
|
|
5
|
+
// src/vue.ts
|
|
6
|
+
import { ref, onMounted, onUnmounted } from "vue";
|
|
7
|
+
function userealView(target, options) {
|
|
8
|
+
const isVisible = ref(false);
|
|
9
|
+
let stop;
|
|
10
|
+
onMounted(() => {
|
|
11
|
+
if (target.value) {
|
|
12
|
+
stop = realViewEngine.get().observe(target.value, (v) => isVisible.value = v, options);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
onUnmounted(() => stop?.());
|
|
16
|
+
return isVisible;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
userealView
|
|
20
|
+
};
|
package/license
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) AntonVoronezh <anton.voronezh.1990@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "real-view",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Occlusion-aware visibility sensor. Combines IntersectionObserver with Raycasting to track real impressions in React, Vue, Svelte, Angular, and Solid.",
|
|
5
|
+
"author": {
|
|
6
|
+
"name": "AntonVoronezh",
|
|
7
|
+
"email": "anton.voronezh.1990@gmail.com",
|
|
8
|
+
"url": "https://github.com/AntonVoronezh"
|
|
9
|
+
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/AntonVoronezh/real-view.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/AntonVoronezh/real-view/issues"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/AntonVoronezh/real-view#readme",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "./dist/index.js",
|
|
20
|
+
"module": "./dist/index.mjs",
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"exports": {
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup src/index.ts src/react.ts src/vue.ts src/svelte.ts src/solid.ts src/angular.ts --format cjs,esm --dts --clean",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"lint": "tsc --noEmit",
|
|
33
|
+
"prepublishOnly": "npm run build"
|
|
34
|
+
},
|
|
35
|
+
"keywords": [
|
|
36
|
+
"visibility",
|
|
37
|
+
"viewport",
|
|
38
|
+
"intersection",
|
|
39
|
+
"occlusion" ,
|
|
40
|
+
"tracking",
|
|
41
|
+
"analytics",
|
|
42
|
+
"impression",
|
|
43
|
+
"react",
|
|
44
|
+
"vue",
|
|
45
|
+
"svelte",
|
|
46
|
+
"angular",
|
|
47
|
+
"solid",
|
|
48
|
+
"dom",
|
|
49
|
+
"monitor",
|
|
50
|
+
"viewability"
|
|
51
|
+
],
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/AntonVoronezh/real-view.git"
|
|
55
|
+
},
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/AntonVoronezh/real-view/issues"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://github.com/AntonVoronezh/real-view#readme",
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"react": ">=16.8.0",
|
|
63
|
+
"vue": ">=3.0.0",
|
|
64
|
+
"svelte": ">=3.0.0",
|
|
65
|
+
"solid-js": ">=1.0.0",
|
|
66
|
+
"@angular/core": ">=14.0.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependenciesMeta": {
|
|
69
|
+
"react": { "optional": true },
|
|
70
|
+
"vue": { "optional": true },
|
|
71
|
+
"svelte": { "optional": true },
|
|
72
|
+
"solid-js": { "optional": true },
|
|
73
|
+
"@angular/core": { "optional": true }
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@angular/core": "^17.0.0",
|
|
77
|
+
"@types/react": "^18.2.0",
|
|
78
|
+
"react": "^18.2.0",
|
|
79
|
+
"vue": "^3.3.0",
|
|
80
|
+
"svelte": "^4.0.0",
|
|
81
|
+
"solid-js": "^1.8.0",
|
|
82
|
+
"tsup": "^8.0.0",
|
|
83
|
+
"typescript": "^5.3.0",
|
|
84
|
+
"vitest": "^1.0.0",
|
|
85
|
+
"jsdom": "^23.0.0"
|
|
86
|
+
}
|
|
87
|
+
}
|