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,22 +1,20 @@
|
|
|
1
1
|
// src/common/registry.ts
|
|
2
|
-
var KEY = /* @__PURE__ */ Symbol.for("pageturn.registry");
|
|
3
|
-
var holder = globalThis;
|
|
2
|
+
var KEY = /* @__PURE__ */ Symbol.for("pageturn.registry"), holder = globalThis;
|
|
4
3
|
holder[KEY] ??= {
|
|
5
4
|
b: /* @__PURE__ */ new Map(),
|
|
6
5
|
d: [],
|
|
7
6
|
e: null,
|
|
8
7
|
settings: {
|
|
9
8
|
defaultMove: "page",
|
|
10
|
-
prefetch:
|
|
9
|
+
prefetch: !0,
|
|
11
10
|
leaveTimeout: 4e3,
|
|
12
11
|
stuckTimeout: 4e3,
|
|
13
12
|
arrivalEnds: "animations"
|
|
14
13
|
},
|
|
15
|
-
|
|
14
|
+
g: !1,
|
|
16
15
|
f: Object.freeze({})
|
|
17
16
|
};
|
|
18
|
-
var registry = holder[KEY];
|
|
19
|
-
var isDeclined = (answer) => answer === registry.f || answer === false;
|
|
17
|
+
var registry = holder[KEY], isDeclined = (answer) => answer === registry.f;
|
|
20
18
|
|
|
21
19
|
export {
|
|
22
20
|
registry,
|
package/dist/core.js
CHANGED
|
@@ -5,9 +5,10 @@ import {
|
|
|
5
5
|
defineMove,
|
|
6
6
|
endArrival,
|
|
7
7
|
whenLeft
|
|
8
|
-
} from "./chunks/chunk-
|
|
9
|
-
import "./chunks/chunk-
|
|
10
|
-
import "./chunks/chunk-
|
|
8
|
+
} from "./chunks/chunk-6FXXBNAF.js";
|
|
9
|
+
import "./chunks/chunk-JHM7F4CH.js";
|
|
10
|
+
import "./chunks/chunk-AEOAXMU3.js";
|
|
11
|
+
import "./chunks/chunk-YAL4MNCU.js";
|
|
11
12
|
export {
|
|
12
13
|
arrival,
|
|
13
14
|
chooseMove,
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import {
|
|
2
|
+
afterDomContentLoaded
|
|
3
|
+
} from "./chunk-AEOAXMU3.js";
|
|
4
|
+
import {
|
|
5
|
+
isDeclined,
|
|
6
|
+
registry
|
|
7
|
+
} from "./chunk-YAL4MNCU.js";
|
|
8
|
+
|
|
9
|
+
// src/common/dev.ts
|
|
10
|
+
var said = /* @__PURE__ */ new Set();
|
|
11
|
+
function warn(key, message) {
|
|
12
|
+
said.has(key) || (said.add(key), console.warn(`pageturn: ${message}`));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/kernel/cap.ts
|
|
16
|
+
function capOf(property, ceiling) {
|
|
17
|
+
let value = getComputedStyle(document.documentElement).getPropertyValue(
|
|
18
|
+
property
|
|
19
|
+
), max = Number.parseFloat(value) * (/ms\s*$/.test(value) ? 1 : 1e3);
|
|
20
|
+
return max >= 0 ? Math.min(max, ceiling) : ceiling;
|
|
21
|
+
}
|
|
22
|
+
var isEnding = (animation) => animation.effect?.getTiming().iterations !== 1 / 0, untilEnded = (animations, milliseconds) => Promise.race([
|
|
23
|
+
Promise.allSettled(animations.map((animation) => animation.finished)),
|
|
24
|
+
new Promise((resolve) => setTimeout(resolve, milliseconds))
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
// src/kernel/arrival.ts
|
|
28
|
+
var root = () => document.documentElement, watching = null, endedBy = null, ARRIVE_MAX_MS = 1e4, isArriving = () => "turnArriving" in root().dataset || "turnEntering" in root().dataset, nextFrame = () => new Promise((resolve) => requestAnimationFrame(resolve));
|
|
29
|
+
function endArrivalBy(by) {
|
|
30
|
+
isArriving() && (endedBy = by, window.pageturn?.endArrival());
|
|
31
|
+
}
|
|
32
|
+
function followArrival() {
|
|
33
|
+
if (stopFollowing(), !isArriving()) return;
|
|
34
|
+
let move = root().dataset.turnArriving ?? null, entering = "turnEntering" in root().dataset, isCut = !1;
|
|
35
|
+
endedBy = null;
|
|
36
|
+
let watch = new MutationObserver(() => {
|
|
37
|
+
if (move = root().dataset.turnArriving ?? move, entering && !("turnEntering" in root().dataset) && window.pageturn?.l ? entering = !1 : endedBy === null && (isCut = !0), isArriving() || (watch.disconnect(), watching === watch && (watching = null), !entering && move === null)) return;
|
|
38
|
+
let isManual = registry.settings.arrivalEnds === "manually", whole = endedBy !== "leave" && (isManual || endedBy === "settled" && !isCut);
|
|
39
|
+
document.dispatchEvent(
|
|
40
|
+
new CustomEvent("pageturn:arrived", {
|
|
41
|
+
detail: { move, entering, whole }
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
watching = watch, watch.observe(root(), {
|
|
46
|
+
attributeFilter: ["data-turn-arriving", "data-turn-entering"]
|
|
47
|
+
}), afterDomContentLoaded(async () => {
|
|
48
|
+
await nextFrame(), await nextFrame(), watching === watch && registry.settings.arrivalEnds !== "manually" && waitForAnimations(watch);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async function waitForAnimations(watch) {
|
|
52
|
+
let until = performance.now() + capOf("--turn-arrive-max", ARRIVE_MAX_MS);
|
|
53
|
+
for (let isFirst = !0; ; isFirst = !1) {
|
|
54
|
+
let running = document.getAnimations().filter(
|
|
55
|
+
(animation) => animation.playState === "running" && // A hover's transition is not part of an arrival.
|
|
56
|
+
!(typeof CSSTransition < "u" && animation instanceof CSSTransition) && isEnding(animation)
|
|
57
|
+
), arrival = window.pageturn?.arrival;
|
|
58
|
+
isFirst && running.length === 0 && arrival?.via === "history" && warn(
|
|
59
|
+
`return:${arrival.move}`,
|
|
60
|
+
`this page was returned to under "${arrival.move}" with no animation: Back cannot play a leave, so the page left goes at once and this one shows at once. Animate it in, as html[data-turn-arriving="${arrival.move}"] main { animation: \u2026 }.`
|
|
61
|
+
);
|
|
62
|
+
let left = until - performance.now();
|
|
63
|
+
if (running.length === 0 || left <= 0) break;
|
|
64
|
+
if (await untilEnded(running, left), await nextFrame(), watching !== watch) return;
|
|
65
|
+
}
|
|
66
|
+
watching === watch && endArrivalBy("settled");
|
|
67
|
+
}
|
|
68
|
+
function tellArrival(arrival) {
|
|
69
|
+
try {
|
|
70
|
+
registry.b.get(arrival.move)?.arrive?.(arrival);
|
|
71
|
+
} catch (error) {
|
|
72
|
+
reportError(error);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function stopFollowing() {
|
|
76
|
+
watching?.disconnect(), watching = null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// src/common/session.ts
|
|
80
|
+
function readSession(key) {
|
|
81
|
+
try {
|
|
82
|
+
let text = sessionStorage.getItem(key);
|
|
83
|
+
return text ? JSON.parse(text) : null;
|
|
84
|
+
} catch {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function writeSession(key, value) {
|
|
89
|
+
try {
|
|
90
|
+
return sessionStorage.setItem(key, JSON.stringify(value)), !0;
|
|
91
|
+
} catch {
|
|
92
|
+
return !1;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function removeSession(key) {
|
|
96
|
+
try {
|
|
97
|
+
sessionStorage.getItem(key) !== null && sessionStorage.removeItem(key);
|
|
98
|
+
} catch {
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// src/head/storage.ts
|
|
103
|
+
var STORE_VERSION = 2;
|
|
104
|
+
var addressOf = (place) => place.pathname + place.search;
|
|
105
|
+
function returnArrival(entry, report) {
|
|
106
|
+
return !entry?.returnAs || !report || report.none || report.from !== entry.to ? null : {
|
|
107
|
+
move: entry.returnAs,
|
|
108
|
+
via: "history",
|
|
109
|
+
from: report.from,
|
|
110
|
+
data: null,
|
|
111
|
+
remembered: entry.remember ?? null,
|
|
112
|
+
reported: report.data ?? null
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/kernel/leaving.ts
|
|
117
|
+
function playCssLeave(name, timeout) {
|
|
118
|
+
let root2 = document.documentElement, before = new Set(document.getAnimations());
|
|
119
|
+
root2.dataset.turnLeaving = name;
|
|
120
|
+
let started = document.getAnimations().filter((animation) => !before.has(animation) && isEnding(animation));
|
|
121
|
+
return started.length === 0 ? Promise.resolve() : untilEnded(started, capOf("--turn-leave-max", timeout)).then(
|
|
122
|
+
() => {
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/kernel/turn.ts
|
|
128
|
+
function choose(visit) {
|
|
129
|
+
let named = visit.link.closest("[data-turn]")?.getAttribute("data-turn");
|
|
130
|
+
if (named) return named === "none" ? null : named;
|
|
131
|
+
try {
|
|
132
|
+
for (let chooser of registry.d) {
|
|
133
|
+
let name = chooser(visit);
|
|
134
|
+
if (name !== void 0) return name;
|
|
135
|
+
}
|
|
136
|
+
for (let [name, move] of registry.b)
|
|
137
|
+
if (move.match?.(visit)) return name;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
reportError(error);
|
|
140
|
+
}
|
|
141
|
+
return registry.settings.defaultMove;
|
|
142
|
+
}
|
|
143
|
+
function turnOf(visit, move) {
|
|
144
|
+
let leaving;
|
|
145
|
+
return {
|
|
146
|
+
...visit,
|
|
147
|
+
move,
|
|
148
|
+
leaving: () => (leaving || endArrivalBy("leave"), leaving ??= playCssLeave(move, registry.settings.leaveTimeout), leaving),
|
|
149
|
+
decline: () => registry.f
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function leave(turn, played) {
|
|
153
|
+
let timedOut = new Promise(
|
|
154
|
+
(resolve) => setTimeout(resolve, registry.settings.leaveTimeout, null)
|
|
155
|
+
);
|
|
156
|
+
return Promise.race([run(turn, played).catch(() => null), timedOut]);
|
|
157
|
+
}
|
|
158
|
+
async function run(turn, played) {
|
|
159
|
+
played(turn);
|
|
160
|
+
let outcome = await registry.b.get(turn.move)?.leave?.(turn);
|
|
161
|
+
if (isDeclined(outcome)) {
|
|
162
|
+
let fallback = registry.settings.defaultMove;
|
|
163
|
+
if (fallback === null) return null;
|
|
164
|
+
if (fallback !== turn.move) return run(turnOf(turn, fallback), played);
|
|
165
|
+
} else if (outcome)
|
|
166
|
+
return outcome;
|
|
167
|
+
return await turn.leaving(), {};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export {
|
|
171
|
+
warn,
|
|
172
|
+
followArrival,
|
|
173
|
+
tellArrival,
|
|
174
|
+
stopFollowing,
|
|
175
|
+
readSession,
|
|
176
|
+
writeSession,
|
|
177
|
+
removeSession,
|
|
178
|
+
STORE_VERSION,
|
|
179
|
+
addressOf,
|
|
180
|
+
returnArrival,
|
|
181
|
+
choose,
|
|
182
|
+
turnOf,
|
|
183
|
+
leave
|
|
184
|
+
};
|