@aku11i/phantom 6.2.0 → 6.3.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.
@@ -0,0 +1,342 @@
1
+ //#region ../../node_modules/.pnpm/@tanstack+history@1.161.6/node_modules/@tanstack/history/dist/esm/index.js
2
+ var stateIndexKey = "__TSR_index";
3
+ var popStateEvent = "popstate";
4
+ var beforeUnloadEvent = "beforeunload";
5
+ function createHistory(opts) {
6
+ let location = opts.getLocation();
7
+ const subscribers = /* @__PURE__ */ new Set();
8
+ const notify = (action) => {
9
+ location = opts.getLocation();
10
+ subscribers.forEach((subscriber) => subscriber({
11
+ location,
12
+ action
13
+ }));
14
+ };
15
+ const handleIndexChange = (action) => {
16
+ if (opts.notifyOnIndexChange ?? true) notify(action);
17
+ else location = opts.getLocation();
18
+ };
19
+ const tryNavigation = async ({ task, navigateOpts, ...actionInfo }) => {
20
+ if (navigateOpts?.ignoreBlocker ?? false) {
21
+ task();
22
+ return;
23
+ }
24
+ const blockers = opts.getBlockers?.() ?? [];
25
+ const isPushOrReplace = actionInfo.type === "PUSH" || actionInfo.type === "REPLACE";
26
+ if (typeof document !== "undefined" && blockers.length && isPushOrReplace) for (const blocker of blockers) {
27
+ const nextLocation = parseHref(actionInfo.path, actionInfo.state);
28
+ if (await blocker.blockerFn({
29
+ currentLocation: location,
30
+ nextLocation,
31
+ action: actionInfo.type
32
+ })) {
33
+ opts.onBlocked?.();
34
+ return;
35
+ }
36
+ }
37
+ task();
38
+ };
39
+ return {
40
+ get location() {
41
+ return location;
42
+ },
43
+ get length() {
44
+ return opts.getLength();
45
+ },
46
+ subscribers,
47
+ subscribe: (cb) => {
48
+ subscribers.add(cb);
49
+ return () => {
50
+ subscribers.delete(cb);
51
+ };
52
+ },
53
+ push: (path, state, navigateOpts) => {
54
+ const currentIndex = location.state[stateIndexKey];
55
+ state = assignKeyAndIndex(currentIndex + 1, state);
56
+ tryNavigation({
57
+ task: () => {
58
+ opts.pushState(path, state);
59
+ notify({ type: "PUSH" });
60
+ },
61
+ navigateOpts,
62
+ type: "PUSH",
63
+ path,
64
+ state
65
+ });
66
+ },
67
+ replace: (path, state, navigateOpts) => {
68
+ const currentIndex = location.state[stateIndexKey];
69
+ state = assignKeyAndIndex(currentIndex, state);
70
+ tryNavigation({
71
+ task: () => {
72
+ opts.replaceState(path, state);
73
+ notify({ type: "REPLACE" });
74
+ },
75
+ navigateOpts,
76
+ type: "REPLACE",
77
+ path,
78
+ state
79
+ });
80
+ },
81
+ go: (index, navigateOpts) => {
82
+ tryNavigation({
83
+ task: () => {
84
+ opts.go(index);
85
+ handleIndexChange({
86
+ type: "GO",
87
+ index
88
+ });
89
+ },
90
+ navigateOpts,
91
+ type: "GO"
92
+ });
93
+ },
94
+ back: (navigateOpts) => {
95
+ tryNavigation({
96
+ task: () => {
97
+ opts.back(navigateOpts?.ignoreBlocker ?? false);
98
+ handleIndexChange({ type: "BACK" });
99
+ },
100
+ navigateOpts,
101
+ type: "BACK"
102
+ });
103
+ },
104
+ forward: (navigateOpts) => {
105
+ tryNavigation({
106
+ task: () => {
107
+ opts.forward(navigateOpts?.ignoreBlocker ?? false);
108
+ handleIndexChange({ type: "FORWARD" });
109
+ },
110
+ navigateOpts,
111
+ type: "FORWARD"
112
+ });
113
+ },
114
+ canGoBack: () => location.state[stateIndexKey] !== 0,
115
+ createHref: (str) => opts.createHref(str),
116
+ block: (blocker) => {
117
+ if (!opts.setBlockers) return () => {};
118
+ const blockers = opts.getBlockers?.() ?? [];
119
+ opts.setBlockers([...blockers, blocker]);
120
+ return () => {
121
+ const blockers = opts.getBlockers?.() ?? [];
122
+ opts.setBlockers?.(blockers.filter((b) => b !== blocker));
123
+ };
124
+ },
125
+ flush: () => opts.flush?.(),
126
+ destroy: () => opts.destroy?.(),
127
+ notify
128
+ };
129
+ }
130
+ function assignKeyAndIndex(index, state) {
131
+ if (!state) state = {};
132
+ const key = createRandomKey();
133
+ return {
134
+ ...state,
135
+ key,
136
+ __TSR_key: key,
137
+ [stateIndexKey]: index
138
+ };
139
+ }
140
+ /**
141
+ * Creates a history object that can be used to interact with the browser's
142
+ * navigation. This is a lightweight API wrapping the browser's native methods.
143
+ * It is designed to work with TanStack Router, but could be used as a standalone API as well.
144
+ * IMPORTANT: This API implements history throttling via a microtask to prevent
145
+ * excessive calls to the history API. In some browsers, calling history.pushState or
146
+ * history.replaceState in quick succession can cause the browser to ignore subsequent
147
+ * calls. This API smooths out those differences and ensures that your application
148
+ * state will *eventually* match the browser state. In most cases, this is not a problem,
149
+ * but if you need to ensure that the browser state is up to date, you can use the
150
+ * `history.flush` method to immediately flush all pending state changes to the browser URL.
151
+ * @param opts
152
+ * @param opts.getHref A function that returns the current href (path + search + hash)
153
+ * @param opts.createHref A function that takes a path and returns a href (path + search + hash)
154
+ * @returns A history instance
155
+ */
156
+ function createBrowserHistory(opts) {
157
+ const win = opts?.window ?? (typeof document !== "undefined" ? window : void 0);
158
+ const originalPushState = win.history.pushState;
159
+ const originalReplaceState = win.history.replaceState;
160
+ let blockers = [];
161
+ const _getBlockers = () => blockers;
162
+ const _setBlockers = (newBlockers) => blockers = newBlockers;
163
+ const createHref = opts?.createHref ?? ((path) => path);
164
+ const parseLocation = opts?.parseLocation ?? (() => parseHref(`${win.location.pathname}${win.location.search}${win.location.hash}`, win.history.state));
165
+ if (!win.history.state?.__TSR_key && !win.history.state?.key) {
166
+ const addedKey = createRandomKey();
167
+ win.history.replaceState({
168
+ [stateIndexKey]: 0,
169
+ key: addedKey,
170
+ __TSR_key: addedKey
171
+ }, "");
172
+ }
173
+ let currentLocation = parseLocation();
174
+ let rollbackLocation;
175
+ let nextPopIsGo = false;
176
+ let ignoreNextPop = false;
177
+ let skipBlockerNextPop = false;
178
+ let ignoreNextBeforeUnload = false;
179
+ const getLocation = () => currentLocation;
180
+ let next;
181
+ let scheduled;
182
+ const flush = () => {
183
+ if (!next) return;
184
+ history._ignoreSubscribers = true;
185
+ (next.isPush ? win.history.pushState : win.history.replaceState)(next.state, "", next.href);
186
+ history._ignoreSubscribers = false;
187
+ next = void 0;
188
+ scheduled = void 0;
189
+ rollbackLocation = void 0;
190
+ };
191
+ const queueHistoryAction = (type, destHref, state) => {
192
+ const href = createHref(destHref);
193
+ if (!scheduled) rollbackLocation = currentLocation;
194
+ currentLocation = parseHref(destHref, state);
195
+ next = {
196
+ href,
197
+ state,
198
+ isPush: next?.isPush || type === "push"
199
+ };
200
+ if (!scheduled) scheduled = Promise.resolve().then(() => flush());
201
+ };
202
+ const onPushPop = (type) => {
203
+ currentLocation = parseLocation();
204
+ history.notify({ type });
205
+ };
206
+ const onPushPopEvent = async () => {
207
+ if (ignoreNextPop) {
208
+ ignoreNextPop = false;
209
+ return;
210
+ }
211
+ const nextLocation = parseLocation();
212
+ const delta = nextLocation.state[stateIndexKey] - currentLocation.state[stateIndexKey];
213
+ const isForward = delta === 1;
214
+ const isBack = delta === -1;
215
+ const isGo = !isForward && !isBack || nextPopIsGo;
216
+ nextPopIsGo = false;
217
+ const action = isGo ? "GO" : isBack ? "BACK" : "FORWARD";
218
+ const notify = isGo ? {
219
+ type: "GO",
220
+ index: delta
221
+ } : { type: isBack ? "BACK" : "FORWARD" };
222
+ if (skipBlockerNextPop) skipBlockerNextPop = false;
223
+ else {
224
+ const blockers = _getBlockers();
225
+ if (typeof document !== "undefined" && blockers.length) {
226
+ for (const blocker of blockers) if (await blocker.blockerFn({
227
+ currentLocation,
228
+ nextLocation,
229
+ action
230
+ })) {
231
+ ignoreNextPop = true;
232
+ win.history.go(1);
233
+ history.notify(notify);
234
+ return;
235
+ }
236
+ }
237
+ }
238
+ currentLocation = parseLocation();
239
+ history.notify(notify);
240
+ };
241
+ const onBeforeUnload = (e) => {
242
+ if (ignoreNextBeforeUnload) {
243
+ ignoreNextBeforeUnload = false;
244
+ return;
245
+ }
246
+ let shouldBlock = false;
247
+ const blockers = _getBlockers();
248
+ if (typeof document !== "undefined" && blockers.length) for (const blocker of blockers) {
249
+ const shouldHaveBeforeUnload = blocker.enableBeforeUnload ?? true;
250
+ if (shouldHaveBeforeUnload === true) {
251
+ shouldBlock = true;
252
+ break;
253
+ }
254
+ if (typeof shouldHaveBeforeUnload === "function" && shouldHaveBeforeUnload() === true) {
255
+ shouldBlock = true;
256
+ break;
257
+ }
258
+ }
259
+ if (shouldBlock) {
260
+ e.preventDefault();
261
+ return e.returnValue = "";
262
+ }
263
+ };
264
+ const history = createHistory({
265
+ getLocation,
266
+ getLength: () => win.history.length,
267
+ pushState: (href, state) => queueHistoryAction("push", href, state),
268
+ replaceState: (href, state) => queueHistoryAction("replace", href, state),
269
+ back: (ignoreBlocker) => {
270
+ if (ignoreBlocker) skipBlockerNextPop = true;
271
+ ignoreNextBeforeUnload = true;
272
+ return win.history.back();
273
+ },
274
+ forward: (ignoreBlocker) => {
275
+ if (ignoreBlocker) skipBlockerNextPop = true;
276
+ ignoreNextBeforeUnload = true;
277
+ win.history.forward();
278
+ },
279
+ go: (n) => {
280
+ nextPopIsGo = true;
281
+ win.history.go(n);
282
+ },
283
+ createHref: (href) => createHref(href),
284
+ flush,
285
+ destroy: () => {
286
+ win.history.pushState = originalPushState;
287
+ win.history.replaceState = originalReplaceState;
288
+ win.removeEventListener(beforeUnloadEvent, onBeforeUnload, { capture: true });
289
+ win.removeEventListener(popStateEvent, onPushPopEvent);
290
+ },
291
+ onBlocked: () => {
292
+ if (rollbackLocation && currentLocation !== rollbackLocation) currentLocation = rollbackLocation;
293
+ },
294
+ getBlockers: _getBlockers,
295
+ setBlockers: _setBlockers,
296
+ notifyOnIndexChange: false
297
+ });
298
+ win.addEventListener(beforeUnloadEvent, onBeforeUnload, { capture: true });
299
+ win.addEventListener(popStateEvent, onPushPopEvent);
300
+ win.history.pushState = function(...args) {
301
+ const res = originalPushState.apply(win.history, args);
302
+ if (!history._ignoreSubscribers) onPushPop("PUSH");
303
+ return res;
304
+ };
305
+ win.history.replaceState = function(...args) {
306
+ const res = originalReplaceState.apply(win.history, args);
307
+ if (!history._ignoreSubscribers) onPushPop("REPLACE");
308
+ return res;
309
+ };
310
+ return history;
311
+ }
312
+ /**
313
+ * Sanitize a path to prevent open redirect vulnerabilities.
314
+ * Removes control characters and collapses leading double slashes.
315
+ */
316
+ function sanitizePath(path) {
317
+ let sanitized = path.replace(/[\x00-\x1f\x7f]/g, "");
318
+ if (sanitized.startsWith("//")) sanitized = "/" + sanitized.replace(/^\/+/, "");
319
+ return sanitized;
320
+ }
321
+ function parseHref(href, state) {
322
+ const sanitizedHref = sanitizePath(href);
323
+ const hashIndex = sanitizedHref.indexOf("#");
324
+ const searchIndex = sanitizedHref.indexOf("?");
325
+ const addedKey = createRandomKey();
326
+ return {
327
+ href: sanitizedHref,
328
+ pathname: sanitizedHref.substring(0, hashIndex > 0 ? searchIndex > 0 ? Math.min(hashIndex, searchIndex) : hashIndex : searchIndex > 0 ? searchIndex : sanitizedHref.length),
329
+ hash: hashIndex > -1 ? sanitizedHref.substring(hashIndex) : "",
330
+ search: searchIndex > -1 ? sanitizedHref.slice(searchIndex, hashIndex === -1 ? void 0 : hashIndex) : "",
331
+ state: state || {
332
+ [stateIndexKey]: 0,
333
+ key: addedKey,
334
+ __TSR_key: addedKey
335
+ }
336
+ };
337
+ }
338
+ function createRandomKey() {
339
+ return (Math.random() + 1).toString(36).substring(7);
340
+ }
341
+ //#endregion
342
+ export { parseHref as n, createBrowserHistory as t };
@@ -0,0 +1,6 @@
1
+ //#region ../../node_modules/.pnpm/@tanstack+router-core@1.168.15/node_modules/@tanstack/router-core/dist/esm/ssr/handlerCallback.js
2
+ function defineHandlerCallback(handler) {
3
+ return handler;
4
+ }
5
+ //#endregion
6
+ export { defineHandlerCallback as t };
@@ -0,0 +1,64 @@
1
+ String.fromCharCode;
2
+ var ENC_SLASH_RE = /%2f/gi;
3
+ function decode(text = "") {
4
+ try {
5
+ return decodeURIComponent("" + text);
6
+ } catch {
7
+ return "" + text;
8
+ }
9
+ }
10
+ function decodePath(text) {
11
+ return decode(text.replace(ENC_SLASH_RE, "%252F"));
12
+ }
13
+ var TRAILING_SLASH_RE = /\/$|\/\?|\/#/;
14
+ var JOIN_LEADING_SLASH_RE = /^\.?\//;
15
+ function hasTrailingSlash(input = "", respectQueryAndFragment) {
16
+ if (!respectQueryAndFragment) return input.endsWith("/");
17
+ return TRAILING_SLASH_RE.test(input);
18
+ }
19
+ function withoutTrailingSlash(input = "", respectQueryAndFragment) {
20
+ if (!respectQueryAndFragment) return (hasTrailingSlash(input) ? input.slice(0, -1) : input) || "/";
21
+ if (!hasTrailingSlash(input, true)) return input || "/";
22
+ let path = input;
23
+ let fragment = "";
24
+ const fragmentIndex = input.indexOf("#");
25
+ if (fragmentIndex !== -1) {
26
+ path = input.slice(0, fragmentIndex);
27
+ fragment = input.slice(fragmentIndex);
28
+ }
29
+ const [s0, ...s] = path.split("?");
30
+ return ((s0.endsWith("/") ? s0.slice(0, -1) : s0) || "/") + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
31
+ }
32
+ function withTrailingSlash(input = "", respectQueryAndFragment) {
33
+ if (!respectQueryAndFragment) return input.endsWith("/") ? input : input + "/";
34
+ if (hasTrailingSlash(input, true)) return input || "/";
35
+ let path = input;
36
+ let fragment = "";
37
+ const fragmentIndex = input.indexOf("#");
38
+ if (fragmentIndex !== -1) {
39
+ path = input.slice(0, fragmentIndex);
40
+ fragment = input.slice(fragmentIndex);
41
+ if (!path) return fragment;
42
+ }
43
+ const [s0, ...s] = path.split("?");
44
+ return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
45
+ }
46
+ function hasLeadingSlash(input = "") {
47
+ return input.startsWith("/");
48
+ }
49
+ function withLeadingSlash(input = "") {
50
+ return hasLeadingSlash(input) ? input : "/" + input;
51
+ }
52
+ function isNonEmptyURL(url) {
53
+ return url && url !== "/";
54
+ }
55
+ function joinURL(base, ...input) {
56
+ let url = base || "";
57
+ for (const segment of input.filter((url2) => isNonEmptyURL(url2))) if (url) {
58
+ const _segment = segment.replace(JOIN_LEADING_SLASH_RE, "");
59
+ url = withTrailingSlash(url) + _segment;
60
+ } else url = segment;
61
+ return url;
62
+ }
63
+ //#endregion
64
+ export { withoutTrailingSlash as i, joinURL as n, withLeadingSlash as r, decodePath as t };