one 1.2.79 → 1.2.81
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/cjs/Root.cjs +1 -1
- package/dist/cjs/Root.js +1 -1
- package/dist/cjs/Root.js.map +1 -1
- package/dist/cjs/Root.native.js +1 -1
- package/dist/cjs/Root.native.js.map +1 -1
- package/dist/cjs/drawer.cjs +27 -0
- package/dist/cjs/drawer.js +22 -0
- package/dist/cjs/drawer.js.map +6 -0
- package/dist/cjs/drawer.native.js +30 -0
- package/dist/cjs/drawer.native.js.map +1 -0
- package/dist/cjs/hooks.cjs +25 -2
- package/dist/cjs/hooks.js +23 -2
- package/dist/cjs/hooks.js.map +1 -1
- package/dist/cjs/hooks.native.js +147 -14
- package/dist/cjs/hooks.native.js.map +1 -1
- package/dist/cjs/hooks.test.cjs +73 -0
- package/dist/cjs/hooks.test.js +98 -0
- package/dist/cjs/hooks.test.js.map +6 -0
- package/dist/cjs/hooks.test.native.js +194 -0
- package/dist/cjs/hooks.test.native.js.map +1 -0
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +1 -0
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/link/prefetchIntent.cjs +122 -0
- package/dist/cjs/link/prefetchIntent.js +85 -0
- package/dist/cjs/link/prefetchIntent.js.map +6 -0
- package/dist/cjs/link/prefetchIntent.native.js +155 -0
- package/dist/cjs/link/prefetchIntent.native.js.map +1 -0
- package/dist/cjs/link/prefetchIntent.test.cjs +217 -0
- package/dist/cjs/link/prefetchIntent.test.js +149 -0
- package/dist/cjs/link/prefetchIntent.test.js.map +6 -0
- package/dist/cjs/link/prefetchIntent.test.native.js +239 -0
- package/dist/cjs/link/prefetchIntent.test.native.js.map +1 -0
- package/dist/cjs/link/prefetchViewport.cjs +67 -0
- package/dist/cjs/link/prefetchViewport.js +55 -0
- package/dist/cjs/link/prefetchViewport.js.map +6 -0
- package/dist/cjs/link/prefetchViewport.native.js +83 -0
- package/dist/cjs/link/prefetchViewport.native.js.map +1 -0
- package/dist/cjs/link/prefetchViewport.test.cjs +57 -0
- package/dist/cjs/link/prefetchViewport.test.js +59 -0
- package/dist/cjs/link/prefetchViewport.test.js.map +6 -0
- package/dist/cjs/link/prefetchViewport.test.native.js +85 -0
- package/dist/cjs/link/prefetchViewport.test.native.js.map +1 -0
- package/dist/cjs/router/findRouteNode.cjs +26 -0
- package/dist/cjs/router/findRouteNode.js +28 -0
- package/dist/cjs/router/findRouteNode.js.map +1 -1
- package/dist/cjs/router/findRouteNode.native.js +31 -0
- package/dist/cjs/router/findRouteNode.native.js.map +1 -1
- package/dist/cjs/router/router.cjs +11 -13
- package/dist/cjs/router/router.js +8 -10
- package/dist/cjs/router/router.js.map +2 -2
- package/dist/cjs/router/router.native.js +38 -122
- package/dist/cjs/router/router.native.js.map +1 -1
- package/dist/cjs/views/PreloadLinks.cjs +102 -18
- package/dist/cjs/views/PreloadLinks.js +95 -19
- package/dist/cjs/views/PreloadLinks.js.map +1 -1
- package/dist/cjs/vite/one.cjs +3 -0
- package/dist/cjs/vite/one.js +3 -0
- package/dist/cjs/vite/one.js.map +1 -1
- package/dist/cjs/vite/one.native.js +4 -0
- package/dist/cjs/vite/one.native.js.map +1 -1
- package/dist/esm/Root.js +1 -1
- package/dist/esm/Root.js.map +1 -1
- package/dist/esm/Root.mjs +1 -1
- package/dist/esm/Root.mjs.map +1 -1
- package/dist/esm/Root.native.js +1 -1
- package/dist/esm/Root.native.js.map +1 -1
- package/dist/esm/drawer.js +6 -0
- package/dist/esm/drawer.js.map +6 -0
- package/dist/esm/drawer.mjs +3 -0
- package/dist/esm/drawer.mjs.map +1 -0
- package/dist/esm/drawer.native.js +3 -0
- package/dist/esm/drawer.native.js.map +1 -0
- package/dist/esm/hooks.js +23 -2
- package/dist/esm/hooks.js.map +1 -1
- package/dist/esm/hooks.mjs +25 -3
- package/dist/esm/hooks.mjs.map +1 -1
- package/dist/esm/hooks.native.js +147 -15
- package/dist/esm/hooks.native.js.map +1 -1
- package/dist/esm/hooks.test.js +98 -0
- package/dist/esm/hooks.test.js.map +6 -0
- package/dist/esm/hooks.test.mjs +74 -0
- package/dist/esm/hooks.test.mjs.map +1 -0
- package/dist/esm/hooks.test.native.js +192 -0
- package/dist/esm/hooks.test.native.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +2 -2
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/link/prefetchIntent.js +69 -0
- package/dist/esm/link/prefetchIntent.js.map +6 -0
- package/dist/esm/link/prefetchIntent.mjs +97 -0
- package/dist/esm/link/prefetchIntent.mjs.map +1 -0
- package/dist/esm/link/prefetchIntent.native.js +127 -0
- package/dist/esm/link/prefetchIntent.native.js.map +1 -0
- package/dist/esm/link/prefetchIntent.test.js +150 -0
- package/dist/esm/link/prefetchIntent.test.js.map +6 -0
- package/dist/esm/link/prefetchIntent.test.mjs +218 -0
- package/dist/esm/link/prefetchIntent.test.mjs.map +1 -0
- package/dist/esm/link/prefetchIntent.test.native.js +237 -0
- package/dist/esm/link/prefetchIntent.test.native.js.map +1 -0
- package/dist/esm/link/prefetchViewport.js +39 -0
- package/dist/esm/link/prefetchViewport.js.map +6 -0
- package/dist/esm/link/prefetchViewport.mjs +42 -0
- package/dist/esm/link/prefetchViewport.mjs.map +1 -0
- package/dist/esm/link/prefetchViewport.native.js +55 -0
- package/dist/esm/link/prefetchViewport.native.js.map +1 -0
- package/dist/esm/link/prefetchViewport.test.js +60 -0
- package/dist/esm/link/prefetchViewport.test.js.map +6 -0
- package/dist/esm/link/prefetchViewport.test.mjs +58 -0
- package/dist/esm/link/prefetchViewport.test.mjs.map +1 -0
- package/dist/esm/link/prefetchViewport.test.native.js +83 -0
- package/dist/esm/link/prefetchViewport.test.native.js.map +1 -0
- package/dist/esm/router/findRouteNode.js +28 -0
- package/dist/esm/router/findRouteNode.js.map +1 -1
- package/dist/esm/router/findRouteNode.mjs +26 -1
- package/dist/esm/router/findRouteNode.mjs.map +1 -1
- package/dist/esm/router/findRouteNode.native.js +31 -1
- package/dist/esm/router/findRouteNode.native.js.map +1 -1
- package/dist/esm/router/router.js +10 -11
- package/dist/esm/router/router.js.map +2 -2
- package/dist/esm/router/router.mjs +12 -14
- package/dist/esm/router/router.mjs.map +1 -1
- package/dist/esm/router/router.native.js +39 -123
- package/dist/esm/router/router.native.js.map +1 -1
- package/dist/esm/views/PreloadLinks.js +86 -17
- package/dist/esm/views/PreloadLinks.js.map +1 -1
- package/dist/esm/views/PreloadLinks.mjs +87 -14
- package/dist/esm/views/PreloadLinks.mjs.map +1 -1
- package/dist/esm/vite/one.js +3 -0
- package/dist/esm/vite/one.js.map +1 -1
- package/dist/esm/vite/one.mjs +3 -0
- package/dist/esm/vite/one.mjs.map +1 -1
- package/dist/esm/vite/one.native.js +4 -0
- package/dist/esm/vite/one.native.js.map +1 -1
- package/package.json +33 -12
- package/src/Root.tsx +1 -1
- package/src/drawer.ts +1 -0
- package/src/hooks.test.ts +157 -0
- package/src/hooks.tsx +79 -23
- package/src/index.ts +1 -0
- package/src/link/prefetchIntent.test.ts +416 -0
- package/src/link/prefetchIntent.ts +174 -0
- package/src/link/prefetchViewport.test.ts +120 -0
- package/src/link/prefetchViewport.ts +62 -0
- package/src/router/findRouteNode.ts +67 -0
- package/src/router/router.ts +68 -41
- package/src/views/PreloadLinks.tsx +156 -20
- package/src/vite/one.ts +4 -0
- package/src/vite/types.ts +12 -0
- package/types/drawer.d.ts +2 -0
- package/types/drawer.d.ts.map +1 -0
- package/types/hooks.d.ts +22 -0
- package/types/hooks.d.ts.map +1 -1
- package/types/hooks.test.d.ts +2 -0
- package/types/hooks.test.d.ts.map +1 -0
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/link/prefetchIntent.d.ts +43 -0
- package/types/link/prefetchIntent.d.ts.map +1 -0
- package/types/link/prefetchIntent.test.d.ts +2 -0
- package/types/link/prefetchIntent.test.d.ts.map +1 -0
- package/types/link/prefetchViewport.d.ts +16 -0
- package/types/link/prefetchViewport.d.ts.map +1 -0
- package/types/link/prefetchViewport.test.d.ts +2 -0
- package/types/link/prefetchViewport.test.d.ts.map +1 -0
- package/types/router/findRouteNode.d.ts +11 -0
- package/types/router/findRouteNode.d.ts.map +1 -1
- package/types/router/router.d.ts.map +1 -1
- package/types/views/PreloadLinks.d.ts +9 -0
- package/types/views/PreloadLinks.d.ts.map +1 -1
- package/types/vite/one.d.ts.map +1 -1
- package/types/vite/types.d.ts +11 -0
- package/types/vite/types.d.ts.map +1 -1
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var import_vitest = require("vitest"),
|
|
4
|
+
import_prefetchIntent = require("./prefetchIntent.native.js"),
|
|
5
|
+
rect = function (x, y) {
|
|
6
|
+
var w = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 100,
|
|
7
|
+
h = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 40;
|
|
8
|
+
return {
|
|
9
|
+
left: x,
|
|
10
|
+
top: y,
|
|
11
|
+
right: x + w,
|
|
12
|
+
bottom: y + h,
|
|
13
|
+
width: w,
|
|
14
|
+
height: h,
|
|
15
|
+
x,
|
|
16
|
+
y,
|
|
17
|
+
toJSON: function () {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
(0, import_vitest.describe)("prefetchIntent", function () {
|
|
23
|
+
var prefetched, intent;
|
|
24
|
+
(0, import_vitest.beforeEach)(function () {
|
|
25
|
+
prefetched = [], intent = (0, import_prefetchIntent.createPrefetchIntent)({
|
|
26
|
+
onPrefetch: function (href) {
|
|
27
|
+
return prefetched.push(href);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}), (0, import_vitest.describe)("basic targeting", function () {
|
|
31
|
+
(0, import_vitest.it)("prefetches when moving directly toward a link", function () {
|
|
32
|
+
intent.setRects([{
|
|
33
|
+
r: rect(500, 300),
|
|
34
|
+
h: "/about"
|
|
35
|
+
}]), intent.move(100, 300, 0, 0), intent.move(140, 300, 40, 0), intent.move(200, 300, 60, 0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]);
|
|
36
|
+
}), (0, import_vitest.it)("does not prefetch when moving away from a link", function () {
|
|
37
|
+
intent.setRects([{
|
|
38
|
+
r: rect(500, 300),
|
|
39
|
+
h: "/about"
|
|
40
|
+
}]), intent.move(400, 300, 0, 0), intent.move(380, 300, -20, 0), intent.move(350, 300, -30, 0), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
41
|
+
}), (0, import_vitest.it)("does not prefetch when moving perpendicular to a link", function () {
|
|
42
|
+
intent.setRects([{
|
|
43
|
+
r: rect(500, 300),
|
|
44
|
+
h: "/about"
|
|
45
|
+
}]), intent.move(200, 300, 0, 0), intent.move(200, 330, 0, 30), intent.move(200, 370, 0, 40), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
46
|
+
}), (0, import_vitest.it)("prefetches link at long distance with good aim", function () {
|
|
47
|
+
intent.setRects([{
|
|
48
|
+
r: rect(500, 280),
|
|
49
|
+
h: "/far"
|
|
50
|
+
}]), intent.move(100, 300, 0, 0), intent.move(140, 300, 40, 0), intent.move(200, 300, 60, 0), (0, import_vitest.expect)(prefetched).toEqual(["/far"]);
|
|
51
|
+
}), (0, import_vitest.it)("does not prefetch when aim is slightly off at long distance", function () {
|
|
52
|
+
intent.setRects([{
|
|
53
|
+
r: rect(600, 300),
|
|
54
|
+
h: "/far"
|
|
55
|
+
}]), intent.move(100, 300, 0, 0), intent.move(140, 320, 40, 20), intent.move(200, 360, 60, 40), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
}), (0, import_vitest.describe)("prevents over-fetching", function () {
|
|
58
|
+
(0, import_vitest.it)("only prefetches each href once", function () {
|
|
59
|
+
intent.setRects([{
|
|
60
|
+
r: rect(500, 300),
|
|
61
|
+
h: "/about"
|
|
62
|
+
}]), intent.move(100, 300, 0, 0), intent.move(140, 300, 40, 0), intent.move(200, 300, 60, 0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]), intent.move(100, 300, -100, 0), intent.move(140, 300, 40, 0), intent.move(200, 300, 60, 0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]);
|
|
63
|
+
}), (0, import_vitest.it)("removes prefetched links from future consideration", function () {
|
|
64
|
+
intent.setRects([{
|
|
65
|
+
r: rect(400, 300),
|
|
66
|
+
h: "/first"
|
|
67
|
+
}, {
|
|
68
|
+
r: rect(600, 300),
|
|
69
|
+
h: "/second"
|
|
70
|
+
}]), intent.move(100, 300, 0, 0), intent.move(150, 300, 50, 0), (0, import_vitest.expect)(prefetched).toEqual(["/first"]), intent.move(250, 300, 100, 0), intent.move(350, 300, 100, 0), (0, import_vitest.expect)(prefetched).toEqual(["/first", "/second"]);
|
|
71
|
+
});
|
|
72
|
+
}), (0, import_vitest.describe)("winner-takes-all with clustered links", function () {
|
|
73
|
+
(0, import_vitest.it)("only prefetches the best target when multiple links are in path", function () {
|
|
74
|
+
intent.setRects([{
|
|
75
|
+
r: rect(500, 280),
|
|
76
|
+
h: "/top"
|
|
77
|
+
}, {
|
|
78
|
+
r: rect(500, 320),
|
|
79
|
+
h: "/middle"
|
|
80
|
+
}, {
|
|
81
|
+
r: rect(500, 360),
|
|
82
|
+
h: "/bottom"
|
|
83
|
+
}]), intent.move(100, 340, 0, 0), intent.move(150, 340, 50, 0), (0, import_vitest.expect)(prefetched.length).toBe(1), (0, import_vitest.expect)(prefetched[0]).toBe("/middle");
|
|
84
|
+
}), (0, import_vitest.it)("handles dense nav with 20 links", function () {
|
|
85
|
+
var links = Array.from({
|
|
86
|
+
length: 20
|
|
87
|
+
}, function (_, i) {
|
|
88
|
+
return {
|
|
89
|
+
r: rect(100 + i * 60, 50, 50, 30),
|
|
90
|
+
h: `/nav-${i}`
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
intent.setRects(links), intent.move(700, 200, 0, 0), intent.move(700, 150, 0, -50), intent.move(700, 100, 0, -50), (0, import_vitest.expect)(prefetched.length).toBe(1), (0, import_vitest.expect)(prefetched[0]).toBe("/nav-10");
|
|
94
|
+
}), (0, import_vitest.it)("picks closer link when two are roughly aligned", function () {
|
|
95
|
+
intent.setRects([{
|
|
96
|
+
r: rect(300, 300),
|
|
97
|
+
h: "/near"
|
|
98
|
+
}, {
|
|
99
|
+
r: rect(600, 300),
|
|
100
|
+
h: "/far"
|
|
101
|
+
}]), intent.move(100, 320, 0, 0), intent.move(150, 320, 50, 0), (0, import_vitest.expect)(prefetched).toEqual(["/near"]);
|
|
102
|
+
}), (0, import_vitest.it)("picks better-aimed link over closer link", function () {
|
|
103
|
+
intent.setRects([{
|
|
104
|
+
r: rect(200, 400),
|
|
105
|
+
h: "/close-but-off"
|
|
106
|
+
},
|
|
107
|
+
// closer but significantly off-axis
|
|
108
|
+
{
|
|
109
|
+
r: rect(400, 300),
|
|
110
|
+
h: "/far-but-aimed"
|
|
111
|
+
}]), intent.move(100, 300, 0, 0), intent.move(150, 300, 50, 0), (0, import_vitest.expect)(prefetched).toEqual(["/far-but-aimed"]);
|
|
112
|
+
});
|
|
113
|
+
}), (0, import_vitest.describe)("velocity and smoothing", function () {
|
|
114
|
+
(0, import_vitest.it)("does not prefetch when mouse is stationary", function () {
|
|
115
|
+
intent.setRects([{
|
|
116
|
+
r: rect(500, 300),
|
|
117
|
+
h: "/about"
|
|
118
|
+
}]), intent.move(400, 300, 0, 0), intent.move(400, 300, 0, 0), intent.move(400, 300, 0, 0), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
119
|
+
}), (0, import_vitest.it)("does not prefetch when mouse is moving slowly", function () {
|
|
120
|
+
intent.setRects([{
|
|
121
|
+
r: rect(500, 300),
|
|
122
|
+
h: "/about"
|
|
123
|
+
}]), intent.move(400, 300, 0, 0), intent.move(401, 300, 1, 0), intent.move(402, 300, 1, 0), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
124
|
+
}), (0, import_vitest.it)("smooths velocity to avoid jitter false positives", function () {
|
|
125
|
+
intent.setRects([{
|
|
126
|
+
r: rect(500, 300),
|
|
127
|
+
h: "/about"
|
|
128
|
+
}]), intent.move(100, 300, 0, 0), intent.move(130, 305, 30, 5), intent.move(160, 298, 30, -7), intent.move(195, 303, 35, 5), (0, import_vitest.expect)(prefetched).toEqual(["/about"]);
|
|
129
|
+
});
|
|
130
|
+
}), (0, import_vitest.describe)("diagonal movement", function () {
|
|
131
|
+
(0, import_vitest.it)("prefetches with diagonal approach", function () {
|
|
132
|
+
intent.setRects([{
|
|
133
|
+
r: rect(500, 500),
|
|
134
|
+
h: "/corner"
|
|
135
|
+
}]), intent.move(200, 200, 0, 0), intent.move(240, 240, 40, 40), intent.move(290, 290, 50, 50), (0, import_vitest.expect)(prefetched).toEqual(["/corner"]);
|
|
136
|
+
}), (0, import_vitest.it)("handles angled approach to horizontal nav", function () {
|
|
137
|
+
intent.setRects([{
|
|
138
|
+
r: rect(400, 50),
|
|
139
|
+
h: "/link1"
|
|
140
|
+
}, {
|
|
141
|
+
r: rect(500, 50),
|
|
142
|
+
h: "/link2"
|
|
143
|
+
}, {
|
|
144
|
+
r: rect(600, 50),
|
|
145
|
+
h: "/link3"
|
|
146
|
+
}]), intent.move(300, 300, 0, 0), intent.move(340, 260, 40, -40), intent.move(390, 210, 50, -50), (0, import_vitest.expect)(prefetched.length).toBe(1);
|
|
147
|
+
});
|
|
148
|
+
}), (0, import_vitest.describe)("edge cases", function () {
|
|
149
|
+
(0, import_vitest.it)("handles empty rect list", function () {
|
|
150
|
+
intent.setRects([]), intent.move(100, 100, 0, 0), intent.move(150, 100, 50, 0), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
151
|
+
}), (0, import_vitest.it)("handles link at cursor position", function () {
|
|
152
|
+
intent.setRects([{
|
|
153
|
+
r: rect(100, 100),
|
|
154
|
+
h: "/here"
|
|
155
|
+
}]), intent.move(150, 120, 0, 0), intent.move(160, 120, 10, 0), (0, import_vitest.expect)(prefetched.length).toBeLessThanOrEqual(1);
|
|
156
|
+
}), (0, import_vitest.it)("cleans up when observe returns cleanup function", function () {
|
|
157
|
+
var cleanup = intent.observe({
|
|
158
|
+
getBoundingClientRect: function () {
|
|
159
|
+
return rect(500, 300);
|
|
160
|
+
}
|
|
161
|
+
}, "/test");
|
|
162
|
+
cleanup(), intent.move(100, 300, 0, 0), intent.move(150, 300, 50, 0), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
163
|
+
}), (0, import_vitest.it)("re-enables prefetch for href after cleanup", function () {
|
|
164
|
+
var el = {
|
|
165
|
+
getBoundingClientRect: function () {
|
|
166
|
+
return rect(500, 300);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
cleanup = intent.observe(el, "/test");
|
|
170
|
+
intent.setRects([{
|
|
171
|
+
r: rect(500, 300),
|
|
172
|
+
h: "/test"
|
|
173
|
+
}]), intent.move(100, 300, 0, 0), intent.move(140, 300, 40, 0), intent.move(200, 300, 60, 0), (0, import_vitest.expect)(prefetched).toEqual(["/test"]), cleanup(), prefetched.length = 0, intent.observe(el, "/test"), intent.setRects([{
|
|
174
|
+
r: rect(500, 300),
|
|
175
|
+
h: "/test"
|
|
176
|
+
}]), intent.move(100, 300, 0, 0), intent.move(140, 300, 40, 0), intent.move(200, 300, 60, 0), (0, import_vitest.expect)(prefetched).toEqual(["/test"]);
|
|
177
|
+
});
|
|
178
|
+
}), (0, import_vitest.describe)("reach configuration", function () {
|
|
179
|
+
(0, import_vitest.it)("respects maxReach option", function () {
|
|
180
|
+
var shortReach = (0, import_prefetchIntent.createPrefetchIntent)({
|
|
181
|
+
onPrefetch: function (href) {
|
|
182
|
+
return prefetched.push(href);
|
|
183
|
+
},
|
|
184
|
+
maxReach: 200
|
|
185
|
+
});
|
|
186
|
+
shortReach.setRects([{
|
|
187
|
+
r: rect(500, 300),
|
|
188
|
+
h: "/far"
|
|
189
|
+
}]), shortReach.move(100, 300, 0, 0), shortReach.move(150, 300, 50, 0), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
190
|
+
}), (0, import_vitest.it)("respects perpWeight option for aim strictness", function () {
|
|
191
|
+
var strictAim = (0, import_prefetchIntent.createPrefetchIntent)({
|
|
192
|
+
onPrefetch: function (href) {
|
|
193
|
+
return prefetched.push(href);
|
|
194
|
+
},
|
|
195
|
+
perpWeight: 10
|
|
196
|
+
});
|
|
197
|
+
strictAim.setRects([{
|
|
198
|
+
r: rect(400, 350),
|
|
199
|
+
h: "/off"
|
|
200
|
+
}]), strictAim.move(100, 300, 0, 0), strictAim.move(150, 300, 50, 0), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
201
|
+
});
|
|
202
|
+
}), (0, import_vitest.describe)("memory and performance", function () {
|
|
203
|
+
(0, import_vitest.it)("does not leak elements after cleanup", function () {
|
|
204
|
+
for (var cleanups = [], i = 0; i < 100; i++) {
|
|
205
|
+
var el = {};
|
|
206
|
+
cleanups.push(intent.observe(el, `/page-${i}`));
|
|
207
|
+
}
|
|
208
|
+
(0, import_vitest.expect)(intent.nodes.size).toBe(100), cleanups.forEach(function (c) {
|
|
209
|
+
return c();
|
|
210
|
+
}), (0, import_vitest.expect)(intent.nodes.size).toBe(0), (0, import_vitest.expect)(intent.done.size).toBe(0);
|
|
211
|
+
}), (0, import_vitest.it)("handles rapid observe/unobserve cycles", function () {
|
|
212
|
+
for (var el = {}, i = 0; i < 100; i++) {
|
|
213
|
+
var cleanup = intent.observe(el, "/test");
|
|
214
|
+
cleanup();
|
|
215
|
+
}
|
|
216
|
+
(0, import_vitest.expect)(intent.nodes.size).toBe(0);
|
|
217
|
+
}), (0, import_vitest.it)("processes 100 links efficiently", function () {
|
|
218
|
+
for (var links = [], row = 0; row < 10; row++) for (var col = 0; col < 10; col++) links.push({
|
|
219
|
+
r: rect(100 + col * 80, 100 + row * 50, 60, 30),
|
|
220
|
+
h: `/link-${row}-${col}`
|
|
221
|
+
});
|
|
222
|
+
intent.setRects(links);
|
|
223
|
+
for (var start = performance.now(), i = 0; i < 100; i++) intent.move(50 + i * 5, 300, 5, 0);
|
|
224
|
+
var elapsed = performance.now() - start;
|
|
225
|
+
(0, import_vitest.expect)(elapsed).toBeLessThan(50);
|
|
226
|
+
}), (0, import_vitest.it)("removes prefetched links from rects to speed up future checks", function () {
|
|
227
|
+
var links = Array.from({
|
|
228
|
+
length: 10
|
|
229
|
+
}, function (_, i) {
|
|
230
|
+
return {
|
|
231
|
+
r: rect(200 + i * 100, 300),
|
|
232
|
+
h: `/link-${i}`
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
intent.setRects(links), intent.move(100, 320, 0, 0), intent.move(150, 320, 50, 0), (0, import_vitest.expect)(prefetched.length).toBe(1), intent.move(100, 320, -50, 0), intent.move(150, 320, 50, 0), intent.move(200, 320, 50, 0), (0, import_vitest.expect)(prefetched.length).toBe(2), (0, import_vitest.expect)(prefetched[0]).not.toBe(prefetched[1]);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
//# sourceMappingURL=prefetchIntent.test.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["import_vitest","require","import_prefetchIntent","rect","x","y","w","arguments","length","h","left","top","right","bottom","width","height","toJSON","describe","prefetched","intent","beforeEach","createPrefetchIntent","onPrefetch","href","push","it","setRects","r","move","expect","toEqual","toBe","links","Array","from","_","i"],"sources":["../../../src/link/prefetchIntent.test.ts"],"sourcesContent":[null],"mappings":"AAAA;;AAIA,IAAAA,aAAyB,GAAWC,OAAI,SAAS;EAAAC,qBAAyB,GAAAD,OAAA;EAAAE,IAAA,YAAAA,CAAAC,CAAA,EAAAC,CAAA;IACxE,IAAAC,CAAA,GAAMC,SAAA,CAAAC,MAAA,QAAAD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,IAAU;QACbM,CAAA;MACF,EAkBD,GAAAU,MAAA,CAAAS,IAAA,kBAAAT,MAAA,CAAAS,IAAA,uBAAA5B,aAAA,CAAA6B,MAAA,EAAAX,UAAA,EAAAY,OAAA,EACF,iBACF","ignoreList":[]}
|
|
@@ -0,0 +1,67 @@
|
|
|
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) __defProp(target, name, {
|
|
7
|
+
get: all[name],
|
|
8
|
+
enumerable: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var prefetchViewport_exports = {};
|
|
22
|
+
__export(prefetchViewport_exports, {
|
|
23
|
+
createPrefetchViewport: () => createPrefetchViewport,
|
|
24
|
+
observePrefetchViewport: () => observePrefetchViewport,
|
|
25
|
+
startPrefetchViewport: () => startPrefetchViewport
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(prefetchViewport_exports);
|
|
28
|
+
function createPrefetchViewport() {
|
|
29
|
+
const done = /* @__PURE__ */new Set(),
|
|
30
|
+
nodes = /* @__PURE__ */new Map();
|
|
31
|
+
let io = null,
|
|
32
|
+
onPrefetch = null;
|
|
33
|
+
function getObserver() {
|
|
34
|
+
return io || (io = new IntersectionObserver(entries => {
|
|
35
|
+
for (const entry of entries) {
|
|
36
|
+
if (!entry.isIntersecting) continue;
|
|
37
|
+
const href = nodes.get(entry.target);
|
|
38
|
+
href && !done.has(href) && (done.add(href), onPrefetch?.(href));
|
|
39
|
+
}
|
|
40
|
+
}, {
|
|
41
|
+
threshold: 0.5
|
|
42
|
+
}
|
|
43
|
+
// fires when mostly visible
|
|
44
|
+
), io);
|
|
45
|
+
}
|
|
46
|
+
function start(prefetch) {
|
|
47
|
+
onPrefetch = prefetch;
|
|
48
|
+
}
|
|
49
|
+
function observe(el, href) {
|
|
50
|
+
return nodes.set(el, href), getObserver().observe(el), () => {
|
|
51
|
+
nodes.delete(el), io?.unobserve(el), done.delete(href);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
start,
|
|
56
|
+
observe,
|
|
57
|
+
done,
|
|
58
|
+
nodes
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
let instance = null;
|
|
62
|
+
function startPrefetchViewport(prefetch) {
|
|
63
|
+
instance || (instance = createPrefetchViewport()), instance.start(prefetch);
|
|
64
|
+
}
|
|
65
|
+
function observePrefetchViewport(el, href) {
|
|
66
|
+
return instance || (instance = createPrefetchViewport()), instance.observe(el, href);
|
|
67
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var prefetchViewport_exports = {};
|
|
16
|
+
__export(prefetchViewport_exports, {
|
|
17
|
+
createPrefetchViewport: () => createPrefetchViewport,
|
|
18
|
+
observePrefetchViewport: () => observePrefetchViewport,
|
|
19
|
+
startPrefetchViewport: () => startPrefetchViewport
|
|
20
|
+
});
|
|
21
|
+
module.exports = __toCommonJS(prefetchViewport_exports);
|
|
22
|
+
function createPrefetchViewport() {
|
|
23
|
+
const done = /* @__PURE__ */ new Set(), nodes = /* @__PURE__ */ new Map();
|
|
24
|
+
let io = null, onPrefetch = null;
|
|
25
|
+
function getObserver() {
|
|
26
|
+
return io || (io = new IntersectionObserver(
|
|
27
|
+
(entries) => {
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
if (!entry.isIntersecting) continue;
|
|
30
|
+
const href = nodes.get(entry.target);
|
|
31
|
+
href && !done.has(href) && (done.add(href), onPrefetch?.(href));
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{ threshold: 0.5 }
|
|
35
|
+
// fires when mostly visible
|
|
36
|
+
), io);
|
|
37
|
+
}
|
|
38
|
+
function start(prefetch) {
|
|
39
|
+
onPrefetch = prefetch;
|
|
40
|
+
}
|
|
41
|
+
function observe(el, href) {
|
|
42
|
+
return nodes.set(el, href), getObserver().observe(el), () => {
|
|
43
|
+
nodes.delete(el), io?.unobserve(el), done.delete(href);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return { start, observe, done, nodes };
|
|
47
|
+
}
|
|
48
|
+
let instance = null;
|
|
49
|
+
function startPrefetchViewport(prefetch) {
|
|
50
|
+
instance || (instance = createPrefetchViewport()), instance.start(prefetch);
|
|
51
|
+
}
|
|
52
|
+
function observePrefetchViewport(el, href) {
|
|
53
|
+
return instance || (instance = createPrefetchViewport()), instance.observe(el, href);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=prefetchViewport.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/link/prefetchViewport.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASO,SAAS,yBAAyB;AACvC,QAAM,OAAO,oBAAI,IAAY,GACvB,QAAQ,oBAAI,IAAyB;AAC3C,MAAI,KAAkC,MAClC,aAA8C;AAElD,WAAS,cAAc;AACrB,WAAI,OACJ,KAAK,IAAI;AAAA,MACP,CAAC,YAAY;AACX,mBAAW,SAAS,SAAS;AAC3B,cAAI,CAAC,MAAM,eAAgB;AAC3B,gBAAM,OAAO,MAAM,IAAI,MAAM,MAAqB;AAClD,UAAI,QAAQ,CAAC,KAAK,IAAI,IAAI,MACxB,KAAK,IAAI,IAAI,GACb,aAAa,IAAI;AAAA,QAErB;AAAA,MACF;AAAA,MACA,EAAE,WAAW,IAAI;AAAA;AAAA,IACnB,GACO;AAAA,EACT;AAEA,WAAS,MAAM,UAAkC;AAC/C,iBAAa;AAAA,EACf;AAEA,WAAS,QAAQ,IAAiB,MAAc;AAC9C,iBAAM,IAAI,IAAI,IAAI,GAClB,YAAY,EAAE,QAAQ,EAAE,GACjB,MAAM;AACX,YAAM,OAAO,EAAE,GACf,IAAI,UAAU,EAAE,GAChB,KAAK,OAAO,IAAI;AAAA,IAClB;AAAA,EACF;AAEA,SAAO,EAAE,OAAO,SAAS,MAAM,MAAM;AACvC;AAGA,IAAI,WAAsC;AAEnC,SAAS,sBAAsB,UAAkC;AACtE,EAAK,aAAU,WAAW,uBAAuB,IACjD,SAAS,MAAM,QAAQ;AACzB;AAEO,SAAS,wBAAwB,IAAiB,MAAc;AACrE,SAAK,aAAU,WAAW,uBAAuB,IAC1C,SAAS,QAAQ,IAAI,IAAI;AAClC;",
|
|
5
|
+
"names": []
|
|
6
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: !0
|
|
11
|
+
});
|
|
12
|
+
},
|
|
13
|
+
__copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
22
|
+
}), mod);
|
|
23
|
+
var prefetchViewport_exports = {};
|
|
24
|
+
__export(prefetchViewport_exports, {
|
|
25
|
+
createPrefetchViewport: () => createPrefetchViewport,
|
|
26
|
+
observePrefetchViewport: () => observePrefetchViewport,
|
|
27
|
+
startPrefetchViewport: () => startPrefetchViewport
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(prefetchViewport_exports);
|
|
30
|
+
function createPrefetchViewport() {
|
|
31
|
+
var done = /* @__PURE__ */new Set(),
|
|
32
|
+
nodes = /* @__PURE__ */new Map(),
|
|
33
|
+
io = null,
|
|
34
|
+
onPrefetch = null;
|
|
35
|
+
function getObserver() {
|
|
36
|
+
return io || (io = new IntersectionObserver(function (entries) {
|
|
37
|
+
var _iteratorNormalCompletion = !0,
|
|
38
|
+
_didIteratorError = !1,
|
|
39
|
+
_iteratorError = void 0;
|
|
40
|
+
try {
|
|
41
|
+
for (var _iterator = entries[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0) {
|
|
42
|
+
var entry = _step.value;
|
|
43
|
+
if (entry.isIntersecting) {
|
|
44
|
+
var href = nodes.get(entry.target);
|
|
45
|
+
href && !done.has(href) && (done.add(href), onPrefetch?.(href));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch (err) {
|
|
49
|
+
_didIteratorError = !0, _iteratorError = err;
|
|
50
|
+
} finally {
|
|
51
|
+
try {
|
|
52
|
+
!_iteratorNormalCompletion && _iterator.return != null && _iterator.return();
|
|
53
|
+
} finally {
|
|
54
|
+
if (_didIteratorError) throw _iteratorError;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
threshold: 0.5
|
|
59
|
+
}), io);
|
|
60
|
+
}
|
|
61
|
+
function start(prefetch) {
|
|
62
|
+
onPrefetch = prefetch;
|
|
63
|
+
}
|
|
64
|
+
function observe(el, href) {
|
|
65
|
+
return nodes.set(el, href), getObserver().observe(el), function () {
|
|
66
|
+
nodes.delete(el), io?.unobserve(el), done.delete(href);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
start,
|
|
71
|
+
observe,
|
|
72
|
+
done,
|
|
73
|
+
nodes
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var instance = null;
|
|
77
|
+
function startPrefetchViewport(prefetch) {
|
|
78
|
+
instance || (instance = createPrefetchViewport()), instance.start(prefetch);
|
|
79
|
+
}
|
|
80
|
+
function observePrefetchViewport(el, href) {
|
|
81
|
+
return instance || (instance = createPrefetchViewport()), instance.observe(el, href);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=prefetchViewport.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","prefetchViewport_exports","__export","createPrefetchViewport","observePrefetchViewport","startPrefetchViewport","module","exports","done","Set","nodes","Map","io","onPrefetch","getObserver","IntersectionObserver","entries","_iteratorNormalCompletion","_didIteratorError","_iteratorError","_iterator","Symbol","iterator","_step","next","entry","isIntersecting","href","get","target","has","add","err","return","threshold","start","prefetch","observe","el","set"],"sources":["../../../src/link/prefetchViewport.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,wBAAA;AAAAC,QAAA,CAAAD,wBAAA;EAAAE,sBAAA,EAAAA,CAAA,KAAAA,sBAAA;EAAAC,uBAAA,EAAAA,CAAA,KAAAA,uBAAA;EAAAC,qBAAA,EAAAA,CAAA,KAAAA;AAAA;AASOC,MAAA,CAAAC,OAAS,GAAAX,YAAA,CAAAK,wBAAyB;AACvC,SAAME,sBAAOA,CAAA;EAEb,IAAIK,IAAA,GAAkC,eAClC,IAA8CC,GAAA;IAAAC,KAAA,sBAAAC,GAAA;IAAAC,EAAA;IAAAC,UAAA;EAElD,SAASC,YAAA,EAAc;IACrB,OAAIF,EAAA,KACJA,EAAA,GAAK,IAAIG,oBAAA,WAAAC,OAAA;MACP,IAACC,yBAAY;QAAAC,iBAAA;QAAAC,cAAA;MACX;QACE,SAAKC,SAAM,GAAAJ,OAAgB,CAAAK,MAAA,CAAAC,QAAA,KAAAC,KAAA,IAAAN,yBAAA,IAAAM,KAAA,GAAAH,SAAA,CAAAI,IAAA,IAAAhB,IAAA,GAAAS,yBAAA;UAC3B,IAAAQ,KAAM,GAAAF,KAAO,CAAAvB,KAAU;UACnB,IAAAyB,KAAS,CAAAC,cAAa;YAI5B,IAAAC,IAAA,GAAAjB,KAAA,CAAAkB,GAAA,CAAAH,KAAA,CAAAI,MAAA;YACFF,IAAA,KAAAnB,IAAA,CAAAsB,GAAA,CAAAH,IAAA,MAAAnB,IAAA,CAAAuB,GAAA,CAAAJ,IAAA,GAAAd,UAAA,GAAAc,IAAA;UACE;QAAe;MACnB,CACO,QAAAK,GAAA;QACTd,iBAAA,OAAAC,cAAA,GAAAa,GAAA;MAEA,UAAS;QACP;UACF,CAAAf,yBAAA,IAAAG,SAAA,CAAAa,MAAA,YAAAb,SAAA,CAAAa,MAAA;QAEA,UAAS;UACP,IAAAf,iBAAkB,EAGV,MAAAC,cACF;QAEN;MACF;IAEA;MACFe,SAAA;IAGI,IAAAtB,EAAA;EAEG;EACA,SAAAuB,KAAUA,CAAAC,QAAA,EAAW;IAE5BvB,UAAA,GAAAuB,QAAA;EAEO;EACL,SAAKC,QAAAC,EAAA,EAAUX,IAAA;IAEjB,OAAAjB,KAAA,CAAA6B,GAAA,CAAAD,EAAA,EAAAX,IAAA,GAAAb,WAAA,GAAAuB,OAAA,CAAAC,EAAA","ignoreList":[]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
var import_vitest = require("vitest"),
|
|
2
|
+
import_prefetchViewport = require("./prefetchViewport.cjs");
|
|
3
|
+
let mockIOCallback;
|
|
4
|
+
const mockObserved = /* @__PURE__ */new Set();
|
|
5
|
+
import_vitest.vi.stubGlobal("IntersectionObserver", class {
|
|
6
|
+
constructor(callback) {
|
|
7
|
+
mockIOCallback = callback;
|
|
8
|
+
}
|
|
9
|
+
observe(el) {
|
|
10
|
+
mockObserved.add(el);
|
|
11
|
+
}
|
|
12
|
+
unobserve(el) {
|
|
13
|
+
mockObserved.delete(el);
|
|
14
|
+
}
|
|
15
|
+
disconnect() {
|
|
16
|
+
mockObserved.clear();
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
function simulateIntersect(el, isIntersecting) {
|
|
20
|
+
mockIOCallback([{
|
|
21
|
+
target: el,
|
|
22
|
+
isIntersecting
|
|
23
|
+
}], {});
|
|
24
|
+
}
|
|
25
|
+
(0, import_vitest.describe)("prefetchViewport", () => {
|
|
26
|
+
let prefetched, vp;
|
|
27
|
+
(0, import_vitest.beforeEach)(() => {
|
|
28
|
+
prefetched = [], mockObserved.clear(), vp = (0, import_prefetchViewport.createPrefetchViewport)(), vp.start(href => prefetched.push(href));
|
|
29
|
+
}), (0, import_vitest.it)("prefetches when link enters viewport", () => {
|
|
30
|
+
const el = {};
|
|
31
|
+
vp.observe(el, "/about"), simulateIntersect(el, !0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]);
|
|
32
|
+
}), (0, import_vitest.it)("does not prefetch when link exits viewport", () => {
|
|
33
|
+
const el = {};
|
|
34
|
+
vp.observe(el, "/about"), simulateIntersect(el, !1), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
35
|
+
}), (0, import_vitest.it)("only prefetches each href once", () => {
|
|
36
|
+
const el = {};
|
|
37
|
+
vp.observe(el, "/about"), simulateIntersect(el, !0), simulateIntersect(el, !1), simulateIntersect(el, !0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]);
|
|
38
|
+
}), (0, import_vitest.it)("cleanup re-enables prefetch for href", () => {
|
|
39
|
+
const el = {},
|
|
40
|
+
cleanup = vp.observe(el, "/about");
|
|
41
|
+
simulateIntersect(el, !0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]), cleanup(), prefetched.length = 0, vp.observe(el, "/about"), simulateIntersect(el, !0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]);
|
|
42
|
+
}), (0, import_vitest.describe)("memory and performance", () => {
|
|
43
|
+
(0, import_vitest.it)("does not leak elements after cleanup", () => {
|
|
44
|
+
const elements = [],
|
|
45
|
+
cleanups = [];
|
|
46
|
+
for (let i = 0; i < 100; i++) {
|
|
47
|
+
const el = {};
|
|
48
|
+
elements.push(el), cleanups.push(vp.observe(el, `/page-${i}`));
|
|
49
|
+
}
|
|
50
|
+
(0, import_vitest.expect)(vp.nodes.size).toBe(100), cleanups.forEach(c => c()), (0, import_vitest.expect)(vp.nodes.size).toBe(0), (0, import_vitest.expect)(vp.done.size).toBe(0);
|
|
51
|
+
}), (0, import_vitest.it)("handles rapid observe/unobserve cycles", () => {
|
|
52
|
+
const el = {};
|
|
53
|
+
for (let i = 0; i < 100; i++) vp.observe(el, "/test")();
|
|
54
|
+
(0, import_vitest.expect)(vp.nodes.size).toBe(0);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var import_vitest = require("vitest"), import_prefetchViewport = require("./prefetchViewport");
|
|
2
|
+
let mockIOCallback;
|
|
3
|
+
const mockObserved = /* @__PURE__ */ new Set();
|
|
4
|
+
import_vitest.vi.stubGlobal(
|
|
5
|
+
"IntersectionObserver",
|
|
6
|
+
class {
|
|
7
|
+
constructor(callback) {
|
|
8
|
+
mockIOCallback = callback;
|
|
9
|
+
}
|
|
10
|
+
observe(el) {
|
|
11
|
+
mockObserved.add(el);
|
|
12
|
+
}
|
|
13
|
+
unobserve(el) {
|
|
14
|
+
mockObserved.delete(el);
|
|
15
|
+
}
|
|
16
|
+
disconnect() {
|
|
17
|
+
mockObserved.clear();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
);
|
|
21
|
+
function simulateIntersect(el, isIntersecting) {
|
|
22
|
+
mockIOCallback(
|
|
23
|
+
[{ target: el, isIntersecting }],
|
|
24
|
+
{}
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
(0, import_vitest.describe)("prefetchViewport", () => {
|
|
28
|
+
let prefetched, vp;
|
|
29
|
+
(0, import_vitest.beforeEach)(() => {
|
|
30
|
+
prefetched = [], mockObserved.clear(), vp = (0, import_prefetchViewport.createPrefetchViewport)(), vp.start((href) => prefetched.push(href));
|
|
31
|
+
}), (0, import_vitest.it)("prefetches when link enters viewport", () => {
|
|
32
|
+
const el = {};
|
|
33
|
+
vp.observe(el, "/about"), simulateIntersect(el, !0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]);
|
|
34
|
+
}), (0, import_vitest.it)("does not prefetch when link exits viewport", () => {
|
|
35
|
+
const el = {};
|
|
36
|
+
vp.observe(el, "/about"), simulateIntersect(el, !1), (0, import_vitest.expect)(prefetched).toEqual([]);
|
|
37
|
+
}), (0, import_vitest.it)("only prefetches each href once", () => {
|
|
38
|
+
const el = {};
|
|
39
|
+
vp.observe(el, "/about"), simulateIntersect(el, !0), simulateIntersect(el, !1), simulateIntersect(el, !0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]);
|
|
40
|
+
}), (0, import_vitest.it)("cleanup re-enables prefetch for href", () => {
|
|
41
|
+
const el = {}, cleanup = vp.observe(el, "/about");
|
|
42
|
+
simulateIntersect(el, !0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]), cleanup(), prefetched.length = 0, vp.observe(el, "/about"), simulateIntersect(el, !0), (0, import_vitest.expect)(prefetched).toEqual(["/about"]);
|
|
43
|
+
}), (0, import_vitest.describe)("memory and performance", () => {
|
|
44
|
+
(0, import_vitest.it)("does not leak elements after cleanup", () => {
|
|
45
|
+
const elements = [], cleanups = [];
|
|
46
|
+
for (let i = 0; i < 100; i++) {
|
|
47
|
+
const el = {};
|
|
48
|
+
elements.push(el), cleanups.push(vp.observe(el, `/page-${i}`));
|
|
49
|
+
}
|
|
50
|
+
(0, import_vitest.expect)(vp.nodes.size).toBe(100), cleanups.forEach((c) => c()), (0, import_vitest.expect)(vp.nodes.size).toBe(0), (0, import_vitest.expect)(vp.done.size).toBe(0);
|
|
51
|
+
}), (0, import_vitest.it)("handles rapid observe/unobserve cycles", () => {
|
|
52
|
+
const el = {};
|
|
53
|
+
for (let i = 0; i < 100; i++)
|
|
54
|
+
vp.observe(el, "/test")();
|
|
55
|
+
(0, import_vitest.expect)(vp.nodes.size).toBe(0);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=prefetchViewport.test.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
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