vite-plugin-smart-prefetch 0.3.3 → 0.3.5

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,700 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/frameworks/react/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ PrefetchDebugPanel: () => PrefetchDebugPanel,
34
+ PrefetchLink: () => PrefetchLink,
35
+ getPrefetchManager: () => getPrefetchManager,
36
+ usePrefetch: () => usePrefetch
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
39
+
40
+ // src/frameworks/react/usePrefetch.ts
41
+ var import_react = require("react");
42
+ var import_react_router_dom = require("react-router-dom");
43
+
44
+ // src/runtime/prefetch-manager.ts
45
+ var PrefetchManager = class {
46
+ constructor(strategy = "hybrid", debug = false) {
47
+ this.config = null;
48
+ this.prefetched = /* @__PURE__ */ new Set();
49
+ this.observer = null;
50
+ this.strategy = strategy;
51
+ this.debug = debug;
52
+ }
53
+ /**
54
+ * Initialize the prefetch manager
55
+ * Loads configuration and sets up observers
56
+ */
57
+ async init() {
58
+ if (this.debug) {
59
+ console.log("\u{1F680} Smart Prefetch Manager - Initializing...");
60
+ console.log(" Strategy:", this.strategy);
61
+ console.log(" Debug mode: enabled");
62
+ }
63
+ try {
64
+ if (this.debug) {
65
+ console.log("\u{1F4E5} Fetching prefetch-config.json...");
66
+ }
67
+ const response = await fetch("/prefetch-config.json");
68
+ if (!response.ok) {
69
+ if (response.status === 404) {
70
+ if (this.debug) {
71
+ console.warn("\u26A0\uFE0F Prefetch config not found (404)");
72
+ console.log(" This is expected if:");
73
+ console.log(" 1. You haven't built the app yet (run `pnpm build`)");
74
+ console.log(" 2. The plugin failed to generate the config during build");
75
+ console.log(" Prefetch manager will be inactive until config is available");
76
+ }
77
+ return;
78
+ }
79
+ throw new Error(`Failed to load prefetch config: ${response.statusText}`);
80
+ }
81
+ this.config = await response.json();
82
+ if (this.debug && this.config) {
83
+ console.log("\u2705 Config loaded successfully");
84
+ console.log(` Routes with prefetch rules: ${Object.keys(this.config.routes).length} ${typeof this.config.routes}`);
85
+ console.log(` Environment: ${this.config.environment}`);
86
+ console.log(` Config version: ${this.config.version || "N/A"}`);
87
+ console.groupCollapsed("\u{1F4CB} Available prefetch rules:");
88
+ Object.entries(this.config.routes).forEach(([source, data]) => {
89
+ console.log(
90
+ `${source} \u2192 ${data.prefetch.length} target(s)`,
91
+ data.prefetch.map((t) => t.route)
92
+ );
93
+ });
94
+ console.groupEnd();
95
+ }
96
+ if (this.strategy === "visible" || this.strategy === "hybrid") {
97
+ this.initIntersectionObserver();
98
+ if (this.debug) {
99
+ console.log("\u{1F441}\uFE0F IntersectionObserver initialized for visibility-based prefetching");
100
+ }
101
+ }
102
+ if (this.debug) {
103
+ console.log("\u2705 Prefetch Manager fully initialized");
104
+ console.log("\u{1F4A1} Run window.__PREFETCH_DEBUG__() to see current state");
105
+ window.__PREFETCH_DEBUG__ = () => this.logDebugInfo();
106
+ }
107
+ } catch (error) {
108
+ if (this.debug) {
109
+ console.error("\u274C Failed to initialize Prefetch Manager:", error);
110
+ }
111
+ }
112
+ }
113
+ /**
114
+ * Prefetch routes based on current route
115
+ */
116
+ prefetch(currentRoute) {
117
+ const cleanRoute = currentRoute.split("?")[0].split("#")[0];
118
+ if (this.debug) {
119
+ console.log(`\u{1F4CD} Checking prefetch for route: ${currentRoute}`);
120
+ if (currentRoute !== cleanRoute) {
121
+ console.log(` Clean route: ${cleanRoute}`);
122
+ }
123
+ }
124
+ if (!this.config) {
125
+ if (this.debug) {
126
+ console.warn("\u26A0\uFE0F Config not loaded yet - cannot prefetch");
127
+ console.log(" Make sure the app was built with the plugin enabled");
128
+ }
129
+ return;
130
+ }
131
+ if (!this.shouldPrefetch()) {
132
+ if (this.debug) {
133
+ console.log("\u23ED\uFE0F Skipping prefetch due to network conditions");
134
+ }
135
+ return;
136
+ }
137
+ let routeConfig = this.config.routes[cleanRoute] || this.config.routes[currentRoute];
138
+ const matchedRoute = routeConfig ? this.config.routes[cleanRoute] ? cleanRoute : currentRoute : null;
139
+ if (!routeConfig) {
140
+ if (this.debug) {
141
+ console.warn(`\u26A0\uFE0F No prefetch rules configured for route: ${cleanRoute}`);
142
+ console.groupCollapsed("Available routes in config:");
143
+ Object.keys(this.config.routes).forEach((route) => {
144
+ const targets = this.config.routes[route].prefetch;
145
+ console.log(` ${route} \u2192 ${targets.length} target(s)`, targets.map((t) => t.route));
146
+ });
147
+ console.groupEnd();
148
+ console.log(`\u{1F4A1} Tip: Make sure your manualRules key matches exactly: "${cleanRoute}"`);
149
+ }
150
+ return;
151
+ }
152
+ console.log(`\u2705 Found prefetch rule for: ${matchedRoute}`);
153
+ console.log(` Total targets to prefetch: ${routeConfig.prefetch.length}`);
154
+ console.log(` Strategy: ${this.strategy}`);
155
+ if (this.debug) {
156
+ console.groupCollapsed(`\u{1F4CA} Prefetch Rules for: ${matchedRoute}`);
157
+ routeConfig.prefetch.forEach((target, index) => {
158
+ console.log(` ${index + 1}. ${target.route} (${target.priority} priority, ${(target.probability * 100).toFixed(1)}%)`);
159
+ });
160
+ console.groupEnd();
161
+ }
162
+ routeConfig.prefetch.forEach((target) => {
163
+ this.prefetchTarget(target);
164
+ });
165
+ }
166
+ /**
167
+ * Prefetch a specific target
168
+ */
169
+ prefetchTarget(target) {
170
+ if (this.prefetched.has(target.route)) {
171
+ return;
172
+ }
173
+ switch (this.strategy) {
174
+ case "auto":
175
+ this.injectPrefetchLink(target);
176
+ break;
177
+ case "hover":
178
+ break;
179
+ case "visible":
180
+ break;
181
+ case "idle":
182
+ this.prefetchOnIdle(target);
183
+ break;
184
+ case "hybrid":
185
+ this.prefetchHybrid(target);
186
+ break;
187
+ }
188
+ }
189
+ /**
190
+ * Hybrid strategy: prioritize based on probability
191
+ * FOR TESTING: Fetch all priorities to verify chunks are correct
192
+ */
193
+ prefetchHybrid(target) {
194
+ if (target.priority === "high" || target.probability >= 0.7) {
195
+ console.log(` \u26A1 High priority (${(target.probability * 100).toFixed(1)}%) - Prefetching immediately`);
196
+ this.injectPrefetchLink(target);
197
+ } else if (target.priority === "medium" || target.probability >= 0.4) {
198
+ console.log(` \u23F1\uFE0F Medium priority (${(target.probability * 100).toFixed(1)}%) - Fetching immediately (TESTING MODE)`);
199
+ this.injectPrefetchLink(target);
200
+ } else {
201
+ console.log(` \u{1F514} Low priority (${(target.probability * 100).toFixed(1)}%) - Fetching immediately (TESTING MODE)`);
202
+ this.injectPrefetchLink(target);
203
+ }
204
+ }
205
+ /**
206
+ * Prefetch during idle time
207
+ */
208
+ prefetchOnIdle(target) {
209
+ if ("requestIdleCallback" in window) {
210
+ requestIdleCallback(() => {
211
+ this.injectPrefetchLink(target);
212
+ });
213
+ } else {
214
+ setTimeout(() => {
215
+ this.injectPrefetchLink(target);
216
+ }, 1e3);
217
+ }
218
+ }
219
+ /**
220
+ * Inject prefetch link into DOM
221
+ */
222
+ injectPrefetchLink(target) {
223
+ if (this.prefetched.has(target.route)) {
224
+ if (this.debug) {
225
+ console.log(` \u23ED\uFE0F Already prefetched: ${target.route}`);
226
+ }
227
+ return;
228
+ }
229
+ const link = document.createElement("link");
230
+ link.rel = "modulepreload";
231
+ link.href = `/${target.chunk}`;
232
+ link.setAttribute("data-prefetch-route", target.route);
233
+ link.setAttribute("data-prefetch-priority", target.priority);
234
+ link.setAttribute("data-prefetch-probability", target.probability.toString());
235
+ console.groupCollapsed(`\u{1F517} PREFETCH: ${target.route}`);
236
+ console.log(` \u{1F4C4} Page/Route: ${target.route}`);
237
+ console.log(` \u{1F4E6} Main Chunk: ${target.chunk}`);
238
+ console.log(` \u{1F310} Full URL: ${window.location.origin}/${target.chunk}`);
239
+ console.log(` \u2B50 Priority: ${target.priority}`);
240
+ console.log(` \u{1F4CA} Probability: ${(target.probability * 100).toFixed(1)}%`);
241
+ if (this.debug) {
242
+ console.log(` Link element:`, link);
243
+ }
244
+ document.head.appendChild(link);
245
+ let totalChunksForThisRoute = 1;
246
+ if (target.imports && target.imports.length > 0) {
247
+ console.log(` \u{1F4DA} Dependencies (${target.imports.length}):`);
248
+ target.imports.forEach((importChunk, index) => {
249
+ const importId = `import:${importChunk}`;
250
+ if (this.prefetched.has(importId)) {
251
+ console.log(` ${index + 1}. ${importChunk} (already prefetched)`);
252
+ return;
253
+ }
254
+ const importLink = document.createElement("link");
255
+ importLink.rel = "modulepreload";
256
+ importLink.href = `/${importChunk}`;
257
+ importLink.setAttribute("data-prefetch-import", "true");
258
+ importLink.setAttribute("data-prefetch-parent", target.route);
259
+ document.head.appendChild(importLink);
260
+ this.prefetched.add(importId);
261
+ totalChunksForThisRoute++;
262
+ console.log(` ${index + 1}. ${importChunk} \u2705`);
263
+ });
264
+ }
265
+ this.prefetched.add(target.route);
266
+ console.log(` \u2705 Total chunks injected: ${totalChunksForThisRoute}`);
267
+ console.log(` \u{1F4C8} Overall prefetched count: ${this.prefetched.size}`);
268
+ if (this.debug) {
269
+ console.log(` DOM Status: Link tag added to document.head`);
270
+ setTimeout(() => {
271
+ const addedLink = document.querySelector(`link[data-prefetch-route="${target.route}"]`);
272
+ if (addedLink) {
273
+ console.log(` \u2714\uFE0F DOM Verification: Link exists`);
274
+ console.log(` href:`, addedLink.href);
275
+ } else {
276
+ console.error(` \u274C ERROR: Link tag not found in DOM`);
277
+ }
278
+ }, 100);
279
+ }
280
+ console.groupEnd();
281
+ }
282
+ /**
283
+ * Check if prefetching should be performed based on network conditions
284
+ */
285
+ shouldPrefetch() {
286
+ const nav = navigator;
287
+ const connection = nav.connection || nav.mozConnection || nav.webkitConnection;
288
+ if (!connection) {
289
+ return true;
290
+ }
291
+ if (connection.saveData) {
292
+ if (this.debug) console.log(" \u26A0\uFE0F Data Saver enabled");
293
+ return false;
294
+ }
295
+ const slowConnections = ["slow-2g", "2g"];
296
+ if (slowConnections.includes(connection.effectiveType)) {
297
+ if (this.debug) console.log(` \u26A0\uFE0F Slow connection: ${connection.effectiveType}`);
298
+ return false;
299
+ }
300
+ if (connection.type === "cellular" && connection.effectiveType !== "4g") {
301
+ if (this.debug) console.log(" \u26A0\uFE0F Metered connection");
302
+ return false;
303
+ }
304
+ return true;
305
+ }
306
+ /**
307
+ * Initialize IntersectionObserver for 'visible' strategy
308
+ */
309
+ initIntersectionObserver() {
310
+ this.observer = new IntersectionObserver(
311
+ (entries) => {
312
+ entries.forEach((entry) => {
313
+ if (entry.isIntersecting) {
314
+ const route = entry.target.getAttribute("data-prefetch-route");
315
+ if (route && this.config) {
316
+ Object.values(this.config.routes).forEach((routeConfig) => {
317
+ const target = routeConfig.prefetch.find((t) => t.route === route);
318
+ if (target) {
319
+ this.injectPrefetchLink(target);
320
+ }
321
+ });
322
+ }
323
+ }
324
+ });
325
+ },
326
+ {
327
+ rootMargin: "50px"
328
+ // Start prefetch 50px before element is visible
329
+ }
330
+ );
331
+ }
332
+ /**
333
+ * Observe an element for visibility-based prefetching
334
+ */
335
+ observeLink(element, route) {
336
+ if (this.observer) {
337
+ element.setAttribute("data-prefetch-route", route);
338
+ this.observer.observe(element);
339
+ }
340
+ }
341
+ /**
342
+ * Manually trigger prefetch for a specific route
343
+ * Useful for hover events
344
+ */
345
+ prefetchRoute(route) {
346
+ if (!this.config) return;
347
+ Object.values(this.config.routes).forEach((routeConfig) => {
348
+ const target = routeConfig.prefetch.find((t) => t.route === route);
349
+ if (target) {
350
+ this.injectPrefetchLink(target);
351
+ }
352
+ });
353
+ }
354
+ /**
355
+ * Get prefetch statistics
356
+ */
357
+ getStats() {
358
+ return {
359
+ totalPrefetched: this.prefetched.size,
360
+ prefetchedRoutes: Array.from(this.prefetched),
361
+ configLoaded: this.config !== null,
362
+ strategy: this.strategy
363
+ };
364
+ }
365
+ /**
366
+ * Check if a route has been prefetched
367
+ */
368
+ isPrefetched(route) {
369
+ return this.prefetched.has(route);
370
+ }
371
+ /**
372
+ * Clear all prefetch state
373
+ */
374
+ clear() {
375
+ this.prefetched.clear();
376
+ if (this.observer) {
377
+ this.observer.disconnect();
378
+ }
379
+ }
380
+ /**
381
+ * Get all prefetch link elements currently in the DOM
382
+ */
383
+ getActivePrefetchLinks() {
384
+ return Array.from(document.querySelectorAll('link[rel="modulepreload"][data-prefetch-route]'));
385
+ }
386
+ /**
387
+ * Log current state for debugging
388
+ */
389
+ logDebugInfo() {
390
+ console.group("\u{1F41B} Smart Prefetch Debug Info");
391
+ console.log("Strategy:", this.strategy);
392
+ console.log("Config loaded:", this.config !== null);
393
+ console.log("Total prefetch entries:", this.prefetched.size);
394
+ console.log("Prefetched items:", Array.from(this.prefetched));
395
+ const links = this.getActivePrefetchLinks();
396
+ console.log("\n\u{1F517} Active Link Tags in DOM:", links.length);
397
+ if (links.length > 0) {
398
+ console.table(links.map((link) => ({
399
+ route: link.getAttribute("data-prefetch-route"),
400
+ chunk: link.href.replace(window.location.origin + "/", ""),
401
+ priority: link.getAttribute("data-prefetch-priority"),
402
+ probability: link.getAttribute("data-prefetch-probability")
403
+ })));
404
+ }
405
+ if (this.config) {
406
+ console.log("\n\u{1F4CA} Configuration Summary:");
407
+ console.log("Available routes in config:", Object.keys(this.config.routes).length);
408
+ console.log("Config environment:", this.config.environment);
409
+ console.group("\u{1F4CB} All configured routes with prefetch targets:");
410
+ Object.entries(this.config.routes).forEach(([route, data]) => {
411
+ console.group(`${route}`);
412
+ data.prefetch.forEach((t, idx) => {
413
+ console.log(` ${idx + 1}. ${t.route} (${t.priority}, ${(t.probability * 100).toFixed(1)}%) \u2192 ${t.chunk}`);
414
+ });
415
+ console.groupEnd();
416
+ });
417
+ console.groupEnd();
418
+ console.log("\n\u{1F4A1} Current location:", window.location.pathname);
419
+ console.log("\u{1F4A1} Clean route:", window.location.pathname.split("?")[0].split("#")[0]);
420
+ }
421
+ console.groupEnd();
422
+ }
423
+ /**
424
+ * Log all prefetched pages and chunks (summary view)
425
+ */
426
+ logPrefetchSummary() {
427
+ const links = this.getActivePrefetchLinks();
428
+ const routeLinks = links.filter((l) => !l.getAttribute("data-prefetch-import"));
429
+ const dependencyLinks = links.filter((l) => l.getAttribute("data-prefetch-import"));
430
+ console.group("\u{1F4CA} PREFETCH SUMMARY");
431
+ console.log(`Total pages prefetched: ${routeLinks.length}`);
432
+ console.log(`Total dependency chunks: ${dependencyLinks.length}`);
433
+ console.log(`Total overall entries: ${this.prefetched.size}`);
434
+ if (routeLinks.length > 0) {
435
+ console.group("\u{1F4C4} Pages/Routes Prefetched:");
436
+ const pageTable = routeLinks.map((link) => ({
437
+ route: link.getAttribute("data-prefetch-route"),
438
+ chunk: link.href.replace(window.location.origin + "/", ""),
439
+ priority: link.getAttribute("data-prefetch-priority"),
440
+ probability: `${link.getAttribute("data-prefetch-probability")}`
441
+ }));
442
+ console.table(pageTable);
443
+ console.groupEnd();
444
+ }
445
+ if (dependencyLinks.length > 0) {
446
+ console.group("\u{1F4E6} Dependency Chunks Prefetched:");
447
+ const depsTable = dependencyLinks.map((link) => ({
448
+ parentRoute: link.getAttribute("data-prefetch-parent"),
449
+ chunk: link.href.replace(window.location.origin + "/", "")
450
+ }));
451
+ console.table(depsTable);
452
+ console.groupEnd();
453
+ }
454
+ console.groupEnd();
455
+ }
456
+ };
457
+
458
+ // src/frameworks/react/usePrefetch.ts
459
+ var managerInstance = null;
460
+ function usePrefetch() {
461
+ const location = (0, import_react_router_dom.useLocation)();
462
+ const initialized = (0, import_react.useRef)(false);
463
+ (0, import_react.useEffect)(() => {
464
+ if (!initialized.current) {
465
+ const config = window.__SMART_PREFETCH__ || {};
466
+ const strategy = config.strategy || "hybrid";
467
+ const debug = config.debug || false;
468
+ managerInstance = new PrefetchManager(strategy, debug);
469
+ managerInstance.init();
470
+ initialized.current = true;
471
+ if (debug) {
472
+ console.log("\u2705 usePrefetch initialized");
473
+ }
474
+ }
475
+ }, []);
476
+ (0, import_react.useEffect)(() => {
477
+ if (managerInstance) {
478
+ managerInstance.prefetch(location.pathname);
479
+ }
480
+ }, [location.pathname]);
481
+ return managerInstance;
482
+ }
483
+ function getPrefetchManager() {
484
+ return managerInstance;
485
+ }
486
+
487
+ // src/frameworks/react/PrefetchLink.tsx
488
+ var import_react2 = __toESM(require("react"), 1);
489
+ var import_react_router_dom2 = require("react-router-dom");
490
+ var import_jsx_runtime = require("react/jsx-runtime");
491
+ var PrefetchLink = import_react2.default.forwardRef(
492
+ ({ prefetch, to, children, onMouseEnter, ...props }, forwardedRef) => {
493
+ const linkRef = (0, import_react2.useRef)(null);
494
+ const manager = getPrefetchManager();
495
+ const route = typeof to === "string" ? to : to.pathname || "";
496
+ (0, import_react2.useEffect)(() => {
497
+ if (prefetch === "visible" && linkRef.current && manager) {
498
+ manager.observeLink(linkRef.current, route);
499
+ }
500
+ }, [prefetch, route, manager]);
501
+ const handleMouseEnter = (e) => {
502
+ if (prefetch === "hover" && manager) {
503
+ manager.prefetchRoute(route);
504
+ }
505
+ if (onMouseEnter) {
506
+ onMouseEnter(e);
507
+ }
508
+ };
509
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
510
+ import_react_router_dom2.Link,
511
+ {
512
+ ref: (node) => {
513
+ if (node) {
514
+ linkRef.current = node;
515
+ if (typeof forwardedRef === "function") {
516
+ forwardedRef(node);
517
+ } else if (forwardedRef) {
518
+ forwardedRef.current = node;
519
+ }
520
+ }
521
+ },
522
+ to,
523
+ onMouseEnter: handleMouseEnter,
524
+ ...props,
525
+ children
526
+ }
527
+ );
528
+ }
529
+ );
530
+ PrefetchLink.displayName = "PrefetchLink";
531
+
532
+ // src/frameworks/react/PrefetchDebugPanel.tsx
533
+ var import_react3 = require("react");
534
+ var import_jsx_runtime2 = require("react/jsx-runtime");
535
+ function PrefetchDebugPanel({
536
+ manager,
537
+ position = "bottom-right",
538
+ defaultOpen = false
539
+ }) {
540
+ const [isOpen, setIsOpen] = (0, import_react3.useState)(defaultOpen);
541
+ const [stats, setStats] = (0, import_react3.useState)(null);
542
+ const [links, setLinks] = (0, import_react3.useState)([]);
543
+ (0, import_react3.useEffect)(() => {
544
+ if (!manager) return;
545
+ const updateStats = () => {
546
+ setStats(manager.getStats());
547
+ const linkElements = manager.getActivePrefetchLinks();
548
+ setLinks(
549
+ linkElements.map((link) => ({
550
+ route: link.getAttribute("data-prefetch-route") || "",
551
+ href: link.href,
552
+ priority: link.getAttribute("data-prefetch-priority") || "",
553
+ probability: link.getAttribute("data-prefetch-probability") || ""
554
+ }))
555
+ );
556
+ };
557
+ updateStats();
558
+ const interval = setInterval(updateStats, 1e3);
559
+ return () => clearInterval(interval);
560
+ }, [manager]);
561
+ if (!manager) {
562
+ return null;
563
+ }
564
+ const positionStyles = {
565
+ "top-left": { top: 10, left: 10 },
566
+ "top-right": { top: 10, right: 10 },
567
+ "bottom-left": { bottom: 10, left: 10 },
568
+ "bottom-right": { bottom: 10, right: 10 }
569
+ };
570
+ const containerStyle = {
571
+ position: "fixed",
572
+ ...positionStyles[position],
573
+ zIndex: 99999,
574
+ fontFamily: "system-ui, -apple-system, sans-serif",
575
+ fontSize: "12px"
576
+ };
577
+ const buttonStyle = {
578
+ background: "#4CAF50",
579
+ color: "white",
580
+ border: "none",
581
+ borderRadius: "50%",
582
+ width: "48px",
583
+ height: "48px",
584
+ cursor: "pointer",
585
+ boxShadow: "0 4px 8px rgba(0,0,0,0.2)",
586
+ display: "flex",
587
+ alignItems: "center",
588
+ justifyContent: "center",
589
+ fontSize: "20px"
590
+ };
591
+ const panelStyle = {
592
+ background: "white",
593
+ border: "1px solid #ddd",
594
+ borderRadius: "8px",
595
+ boxShadow: "0 4px 12px rgba(0,0,0,0.15)",
596
+ padding: "12px",
597
+ minWidth: "320px",
598
+ maxWidth: "400px",
599
+ maxHeight: "500px",
600
+ overflow: "auto",
601
+ marginBottom: "8px"
602
+ };
603
+ const headerStyle = {
604
+ fontWeight: "bold",
605
+ marginBottom: "8px",
606
+ color: "#333",
607
+ borderBottom: "2px solid #4CAF50",
608
+ paddingBottom: "4px"
609
+ };
610
+ const statStyle = {
611
+ display: "flex",
612
+ justifyContent: "space-between",
613
+ padding: "4px 0",
614
+ borderBottom: "1px solid #eee"
615
+ };
616
+ const linkStyle = {
617
+ background: "#f5f5f5",
618
+ padding: "8px",
619
+ borderRadius: "4px",
620
+ marginBottom: "8px",
621
+ fontSize: "11px"
622
+ };
623
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: containerStyle, children: [
624
+ isOpen && stats && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: panelStyle, children: [
625
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: headerStyle, children: "\u{1F680} Smart Prefetch Debug" }),
626
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { marginBottom: "12px" }, children: [
627
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: statStyle, children: [
628
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Strategy:" }),
629
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: stats.strategy })
630
+ ] }),
631
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: statStyle, children: [
632
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Config Loaded:" }),
633
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: stats.configLoaded ? "\u2705" : "\u274C" })
634
+ ] }),
635
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: statStyle, children: [
636
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Total Prefetched:" }),
637
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: stats.totalPrefetched })
638
+ ] }),
639
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: statStyle, children: [
640
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "Link Tags in DOM:" }),
641
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: links.length })
642
+ ] })
643
+ ] }),
644
+ stats.prefetchedRoutes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
645
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { ...headerStyle, fontSize: "11px" }, children: "Prefetched Routes:" }),
646
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { fontSize: "11px", color: "#666", marginBottom: "8px" }, children: stats.prefetchedRoutes.join(", ") })
647
+ ] }),
648
+ links.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
649
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { ...headerStyle, fontSize: "11px" }, children: "Active Link Tags:" }),
650
+ links.map((link, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: linkStyle, children: [
651
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("strong", { children: link.route }) }),
652
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: { color: "#666", marginTop: "4px" }, children: [
653
+ "Priority: ",
654
+ link.priority,
655
+ " | Prob: ",
656
+ (parseFloat(link.probability) * 100).toFixed(1),
657
+ "%"
658
+ ] }),
659
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: { color: "#999", marginTop: "2px", wordBreak: "break-all" }, children: link.href.split("/").pop() })
660
+ ] }, i))
661
+ ] }),
662
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
663
+ "button",
664
+ {
665
+ onClick: () => {
666
+ manager.logDebugInfo();
667
+ },
668
+ style: {
669
+ width: "100%",
670
+ padding: "8px",
671
+ background: "#2196F3",
672
+ color: "white",
673
+ border: "none",
674
+ borderRadius: "4px",
675
+ cursor: "pointer",
676
+ marginTop: "8px"
677
+ },
678
+ children: "Log Debug Info to Console"
679
+ }
680
+ )
681
+ ] }),
682
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
683
+ "button",
684
+ {
685
+ style: buttonStyle,
686
+ onClick: () => setIsOpen(!isOpen),
687
+ title: "Smart Prefetch Debug Panel",
688
+ children: "\u{1F517}"
689
+ }
690
+ )
691
+ ] });
692
+ }
693
+ // Annotate the CommonJS export names for ESM import in node:
694
+ 0 && (module.exports = {
695
+ PrefetchDebugPanel,
696
+ PrefetchLink,
697
+ getPrefetchManager,
698
+ usePrefetch
699
+ });
700
+ //# sourceMappingURL=index.cjs.map