one
Version:
One is a new React Framework that makes Vite serve both native and web.
56 lines (55 loc) • 2.21 kB
JavaScript
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: !0 });
}, __copyProps = (to, from, except, desc) => {
if (from && typeof from == "object" || typeof from == "function")
for (let key of __getOwnPropNames(from))
!__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: !0 }), 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(), nodes = /* @__PURE__ */ new Map();
let io = null, onPrefetch = null;
function getObserver() {
return io || (io = new IntersectionObserver(
(entries) => {
for (const entry of entries) {
if (!entry.isIntersecting) continue;
const href = nodes.get(entry.target);
href && !done.has(href) && (done.add(href), onPrefetch?.(href));
}
},
{ threshold: 0.5 }
// fires when mostly visible
), io);
}
function start(prefetch) {
onPrefetch = prefetch;
}
function observe(el, href) {
return nodes.set(el, href), getObserver().observe(el), () => {
nodes.delete(el), io?.unobserve(el), done.delete(href);
};
}
return { start, observe, done, nodes };
}
let instance = null;
function startPrefetchViewport(prefetch) {
instance || (instance = createPrefetchViewport()), instance.start(prefetch);
}
function observePrefetchViewport(el, href) {
return instance || (instance = createPrefetchViewport()), instance.observe(el, href);
}
//# sourceMappingURL=prefetchViewport.js.map