pageturn 0.1.0 → 0.2.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 +41 -0
- package/README.md +179 -4
- package/dist/astro.js +0 -2
- package/dist/chunks/chunk-3ABPYO7H.js +43 -0
- package/dist/chunks/chunk-6FXXBNAF.js +197 -0
- package/dist/chunks/chunk-AEOAXMU3.js +33 -0
- package/dist/chunks/chunk-BOM5VXA5.js +167 -0
- package/dist/chunks/chunk-C3T7BGNG.js +30 -0
- package/dist/chunks/chunk-FYSSNYA4.js +17 -0
- package/dist/chunks/chunk-JHM7F4CH.js +172 -0
- package/dist/chunks/chunk-LM3XLSCW.js +799 -0
- package/dist/chunks/{chunk-QJ7GGFM4.js → chunk-YAL4MNCU.js} +4 -6
- package/dist/core.js +4 -3
- package/dist/dev/chunks/chunk-3JAWIMHB.js +184 -0
- package/dist/dev/chunks/chunk-3SU4CIKL.js +799 -0
- package/dist/dev/chunks/chunk-AEOAXMU3.js +33 -0
- package/dist/dev/chunks/chunk-C3T7BGNG.js +30 -0
- package/dist/dev/chunks/chunk-FYSSNYA4.js +17 -0
- package/dist/dev/chunks/chunk-I4SBUABE.js +175 -0
- package/dist/dev/chunks/chunk-U3XN54YY.js +219 -0
- package/dist/dev/chunks/chunk-Y6TD2T53.js +43 -0
- package/dist/dev/chunks/chunk-YAL4MNCU.js +22 -0
- package/dist/dev/core.js +19 -0
- package/dist/dev/index.js +21 -0
- package/dist/dev/morph-markup.js +34 -0
- package/dist/dev/morph.js +457 -0
- package/dist/dev/native.js +3 -0
- package/dist/dev/next.js +79 -0
- package/dist/dev/nuxt-plugin.js +24 -0
- package/dist/dev/prefetch.js +2 -0
- package/dist/dev/react-router.js +46 -0
- package/dist/dev/router.js +9 -0
- package/dist/dev/sveltekit.js +32 -0
- package/dist/dev/testing.js +48 -0
- package/dist/dev/turbo.js +49 -0
- package/dist/dev/vue.js +11 -0
- package/dist/head-core.js +1 -1
- package/dist/head-string.js +6 -6
- package/dist/head.js +1 -1
- package/dist/index.js +6 -5
- package/dist/morph-head.js +1 -1
- package/dist/morph-markup.js +11 -9
- package/dist/morph.js +145 -287
- package/dist/native.js +3 -2
- package/dist/next.js +79 -0
- package/dist/nuxt-plugin.js +24 -0
- package/dist/nuxt.js +34 -0
- package/dist/pageturn-morph.js +1 -1
- package/dist/pageturn.js +1 -1
- package/dist/prefetch.js +2 -2
- package/dist/react-router.js +46 -0
- package/dist/router.js +5 -183
- package/dist/sveltekit-server.js +22 -0
- package/dist/sveltekit.js +32 -0
- package/dist/testing.js +12 -22
- package/dist/turbo.js +49 -0
- package/dist/types/astro/integration.d.ts +0 -4
- package/dist/types/common/dev.d.ts +6 -0
- package/dist/types/common/page.d.ts +5 -0
- package/dist/types/common/registry.d.ts +3 -1
- package/dist/types/next/next.d.ts +27 -0
- package/dist/types/nuxt/module.d.ts +32 -0
- package/dist/types/react-router/react-router.d.ts +12 -0
- package/dist/types/router/router.d.ts +4 -2
- package/dist/types/sveltekit/server.d.ts +21 -0
- package/dist/types/sveltekit/sveltekit.d.ts +32 -0
- package/dist/types/turbo/turbo.d.ts +1 -0
- package/dist/types/vue/vue.d.ts +36 -0
- package/dist/vue.js +11 -0
- package/package.json +102 -23
- package/dist/chunks/chunk-237GNQNZ.js +0 -37
- package/dist/chunks/chunk-7LMNJ25V.js +0 -244
- package/dist/chunks/chunk-QC36TQP3.js +0 -24
- package/dist/chunks/chunk-WTHN3UIQ.js +0 -1000
- package/dist/chunks/chunk-YBAP3PHO.js +0 -247
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
STORE_VERSION,
|
|
3
|
-
choose,
|
|
4
|
-
followArrival,
|
|
5
|
-
leave,
|
|
6
|
-
reducesMotion,
|
|
7
|
-
stopFollowing,
|
|
8
|
-
tellArrival,
|
|
9
|
-
turnOf
|
|
10
|
-
} from "./chunk-YBAP3PHO.js";
|
|
11
|
-
import {
|
|
12
|
-
registry
|
|
13
|
-
} from "./chunk-QJ7GGFM4.js";
|
|
14
|
-
|
|
15
|
-
// src/kernel/kernel.ts
|
|
16
|
-
var root = document.documentElement;
|
|
17
|
-
var store;
|
|
18
|
-
var current = null;
|
|
19
|
-
var stuckTimer;
|
|
20
|
-
function install() {
|
|
21
|
-
const published = window.pageturn?.i;
|
|
22
|
-
if (registry.k || published?.m !== STORE_VERSION) return;
|
|
23
|
-
store = published;
|
|
24
|
-
registry.k = true;
|
|
25
|
-
addEventListener("click", putClickLast, true);
|
|
26
|
-
addEventListener("pointerdown", pressed, true);
|
|
27
|
-
addEventListener("pagehide", pageHidden, true);
|
|
28
|
-
addEventListener("pageshow", pageShown);
|
|
29
|
-
followArrival();
|
|
30
|
-
}
|
|
31
|
-
function putClickLast() {
|
|
32
|
-
removeEventListener("click", clicked);
|
|
33
|
-
addEventListener("click", clicked);
|
|
34
|
-
}
|
|
35
|
-
function linkIn(event) {
|
|
36
|
-
for (const target of event.composedPath()) {
|
|
37
|
-
if (target instanceof HTMLAnchorElement) {
|
|
38
|
-
return target.hasAttribute("href") ? target : null;
|
|
39
|
-
}
|
|
40
|
-
if (target instanceof SVGAElement) return null;
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
function isEditable(event) {
|
|
45
|
-
const [target] = event.composedPath();
|
|
46
|
-
return target instanceof HTMLElement && target.isContentEditable;
|
|
47
|
-
}
|
|
48
|
-
function destinationOf(link) {
|
|
49
|
-
const target = link.target || document.querySelector("base[target]")?.getAttribute("target");
|
|
50
|
-
if (target && target !== "_self" || link.hasAttribute("download")) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
const to = new URL(link.href);
|
|
54
|
-
const isThisPage = to.pathname === location.pathname && to.search === location.search;
|
|
55
|
-
return to.origin === location.origin && !isThisPage ? to : null;
|
|
56
|
-
}
|
|
57
|
-
function prefetch(to) {
|
|
58
|
-
if (registry.settings.prefetch) registry.u?.(to);
|
|
59
|
-
}
|
|
60
|
-
function pressed(event) {
|
|
61
|
-
if (event.button !== 0 || isEditable(event)) return;
|
|
62
|
-
const link = linkIn(event);
|
|
63
|
-
const to = link && destinationOf(link);
|
|
64
|
-
if (to) prefetch(to);
|
|
65
|
-
}
|
|
66
|
-
function clicked(event) {
|
|
67
|
-
if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || isEditable(event)) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const link = linkIn(event);
|
|
71
|
-
const to = link && destinationOf(link);
|
|
72
|
-
if (!link || !to) return;
|
|
73
|
-
if (current) {
|
|
74
|
-
event.preventDefault();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
store.n();
|
|
78
|
-
if (event.detail === 0) prefetch(to);
|
|
79
|
-
if (reducesMotion()) return;
|
|
80
|
-
const { a: native } = registry;
|
|
81
|
-
const visit = {
|
|
82
|
-
link,
|
|
83
|
-
via: "link",
|
|
84
|
-
from: new URL(location.href),
|
|
85
|
-
to,
|
|
86
|
-
canHandOver: store.q()
|
|
87
|
-
};
|
|
88
|
-
const name = choose(visit);
|
|
89
|
-
if (name === null) {
|
|
90
|
-
native?.c(null);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
const turn = turnOf(visit, name);
|
|
94
|
-
const isWanted = document.dispatchEvent(
|
|
95
|
-
new CustomEvent("pageturn:leaving", { cancelable: true, detail: turn })
|
|
96
|
-
);
|
|
97
|
-
if (!isWanted) {
|
|
98
|
-
native?.c(null);
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (name === registry.settings.defaultMove && !registry.b.get(name)?.leave && native?.v(name, to)) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
event.preventDefault();
|
|
105
|
-
const playing = { turn };
|
|
106
|
-
current = playing;
|
|
107
|
-
leave(turn, (played) => {
|
|
108
|
-
playing.turn = played;
|
|
109
|
-
}).then((handover) => depart(playing, handover));
|
|
110
|
-
}
|
|
111
|
-
function depart(playing, handover) {
|
|
112
|
-
if (current !== playing || playing.handover !== void 0) return;
|
|
113
|
-
const { turn } = playing;
|
|
114
|
-
playing.handover = handover;
|
|
115
|
-
if (handover && handover.arriveAs !== null) {
|
|
116
|
-
store.g(
|
|
117
|
-
{
|
|
118
|
-
move: handover.arriveAs ?? turn.move,
|
|
119
|
-
data: handover.data ?? null,
|
|
120
|
-
from: location.pathname,
|
|
121
|
-
at: Date.now()
|
|
122
|
-
},
|
|
123
|
-
turn.to
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
playing.entry = handover?.returnAs ? {
|
|
127
|
-
move: turn.move,
|
|
128
|
-
to: turn.to.pathname,
|
|
129
|
-
returnAs: handover.returnAs,
|
|
130
|
-
remember: handover.remember ?? null
|
|
131
|
-
} : null;
|
|
132
|
-
store.h(playing.entry);
|
|
133
|
-
registry.a?.c(null);
|
|
134
|
-
location.assign(turn.to.href);
|
|
135
|
-
stuckTimer = setTimeout(
|
|
136
|
-
() => endWithoutDeparture(playing, "stuck"),
|
|
137
|
-
registry.settings.stuckTimeout
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
function endWithoutDeparture(playing, reason) {
|
|
141
|
-
if (current !== playing) return;
|
|
142
|
-
current = null;
|
|
143
|
-
clearTimeout(stuckTimer);
|
|
144
|
-
registry.a?.c(void 0);
|
|
145
|
-
delete root.dataset.turnLeaving;
|
|
146
|
-
const stay = { reason, handover: playing.handover ?? null };
|
|
147
|
-
try {
|
|
148
|
-
registry.b.get(playing.turn.move)?.stay?.(playing.turn, stay);
|
|
149
|
-
} catch (error) {
|
|
150
|
-
reportError(error);
|
|
151
|
-
}
|
|
152
|
-
document.dispatchEvent(
|
|
153
|
-
new CustomEvent("pageturn:stayed", {
|
|
154
|
-
detail: { turn: playing.turn, stay }
|
|
155
|
-
})
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
function pageHidden() {
|
|
159
|
-
clearTimeout(stuckTimer);
|
|
160
|
-
stopFollowing();
|
|
161
|
-
const { e: report } = registry;
|
|
162
|
-
if (!report && !window.pageturn?.arrival) return;
|
|
163
|
-
let data = null;
|
|
164
|
-
try {
|
|
165
|
-
data = report?.({ decline: () => registry.f }) ?? null;
|
|
166
|
-
} catch (error) {
|
|
167
|
-
reportError(error);
|
|
168
|
-
}
|
|
169
|
-
const isNone = data === registry.f;
|
|
170
|
-
store.p({
|
|
171
|
-
from: location.pathname,
|
|
172
|
-
at: Date.now(),
|
|
173
|
-
data: isNone ? null : data,
|
|
174
|
-
...isNone ? { none: true } : {}
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
function pageShown(event) {
|
|
178
|
-
if (!event.persisted) return;
|
|
179
|
-
registry.a?.c(void 0);
|
|
180
|
-
const playing = current;
|
|
181
|
-
const published = window.pageturn;
|
|
182
|
-
if (!published) return;
|
|
183
|
-
const entry = playing ? playing.entry ?? null : store.r();
|
|
184
|
-
const arrival2 = store.s(entry, store.o());
|
|
185
|
-
published.arrival = arrival2;
|
|
186
|
-
if (arrival2) {
|
|
187
|
-
published.t?.(arrival2);
|
|
188
|
-
published.j?.skipTransition();
|
|
189
|
-
followArrival();
|
|
190
|
-
}
|
|
191
|
-
if (playing) endWithoutDeparture(playing, "returned");
|
|
192
|
-
if (arrival2) tellArrival(arrival2);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// src/kernel/core.ts
|
|
196
|
-
function defineMove(name, move) {
|
|
197
|
-
const stored = move;
|
|
198
|
-
registry.b.set(name, stored);
|
|
199
|
-
const reached = window.pageturn?.arrival;
|
|
200
|
-
if (reached?.move === name && stored.arrive) {
|
|
201
|
-
queueMicrotask(() => {
|
|
202
|
-
if (registry.b.get(name) === stored) tellArrival(reached);
|
|
203
|
-
});
|
|
204
|
-
}
|
|
205
|
-
return () => {
|
|
206
|
-
if (registry.b.get(name) === stored) registry.b.delete(name);
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
function chooseMove(chooser) {
|
|
210
|
-
const stored = chooser;
|
|
211
|
-
registry.d.push(stored);
|
|
212
|
-
return () => {
|
|
213
|
-
const index = registry.d.indexOf(stored);
|
|
214
|
-
if (index >= 0) registry.d.splice(index, 1);
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
function arrival() {
|
|
218
|
-
return window.pageturn?.arrival ?? null;
|
|
219
|
-
}
|
|
220
|
-
function endArrival(move) {
|
|
221
|
-
window.pageturn?.endArrival(move);
|
|
222
|
-
}
|
|
223
|
-
function whenLeft(report) {
|
|
224
|
-
const stored = report;
|
|
225
|
-
registry.e = stored;
|
|
226
|
-
return () => {
|
|
227
|
-
if (registry.e === stored) registry.e = null;
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
function configure(settings) {
|
|
231
|
-
for (const [key, value] of Object.entries(settings)) {
|
|
232
|
-
if (value !== void 0) Object.assign(registry.settings, { [key]: value });
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
install();
|
|
236
|
-
|
|
237
|
-
export {
|
|
238
|
-
defineMove,
|
|
239
|
-
chooseMove,
|
|
240
|
-
arrival,
|
|
241
|
-
endArrival,
|
|
242
|
-
whenLeft,
|
|
243
|
-
configure
|
|
244
|
-
};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
registry
|
|
3
|
-
} from "./chunk-QJ7GGFM4.js";
|
|
4
|
-
|
|
5
|
-
// src/prefetch/prefetch.ts
|
|
6
|
-
var asked = /* @__PURE__ */ new Set();
|
|
7
|
-
registry.u ??= (to) => {
|
|
8
|
-
const address = to.href.split("#")[0] ?? to.href;
|
|
9
|
-
if (asked.has(address)) return;
|
|
10
|
-
const connection = navigator.connection;
|
|
11
|
-
if (connection?.saveData || /2g/.test(connection?.effectiveType ?? "")) {
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
asked.add(address);
|
|
15
|
-
const link = document.createElement("link");
|
|
16
|
-
if (link.relList.supports("prefetch")) {
|
|
17
|
-
link.rel = "prefetch";
|
|
18
|
-
link.href = address;
|
|
19
|
-
document.head.append(link);
|
|
20
|
-
} else {
|
|
21
|
-
fetch(address, { priority: "low" }).catch(() => {
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|