UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

80 lines 2.29 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var prefetchViewport_exports = {}; __export(prefetchViewport_exports, { createPrefetchViewport: () => createPrefetchViewport, observePrefetchViewport: () => observePrefetchViewport, startPrefetchViewport: () => startPrefetchViewport }); module.exports = __toCommonJS(prefetchViewport_exports); function createPrefetchViewport() { const done = /* @__PURE__ */new Set(); const nodes = /* @__PURE__ */new Map(); let io = null; let onPrefetch = null; function getObserver() { if (io) return io; io = new IntersectionObserver(entries => { for (const entry of entries) { if (!entry.isIntersecting) continue; const href = nodes.get(entry.target); if (href && !done.has(href)) { done.add(href); onPrefetch?.(href); } } }, { threshold: 0.5 } // fires when mostly visible ); return io; } function start(prefetch) { onPrefetch = prefetch; } function observe(el, href) { nodes.set(el, href); getObserver().observe(el); return () => { nodes.delete(el); io?.unobserve(el); done.delete(href); }; } return { start, observe, done, nodes }; } let instance = null; function startPrefetchViewport(prefetch) { if (!instance) instance = createPrefetchViewport(); instance.start(prefetch); } function observePrefetchViewport(el, href) { if (!instance) instance = createPrefetchViewport(); return instance.observe(el, href); }