UNPKG

one

Version:

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

73 lines 2.87 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 path_exports = {}; __export(path_exports, { getPathWithRecoveredDynamicSegment: () => getPathWithRecoveredDynamicSegment, getPathnameWithRecoveredDynamicSegment: () => getPathnameWithRecoveredDynamicSegment, getSafeWindowPath: () => getSafeWindowPath, getSafeWindowPathname: () => getSafeWindowPathname, hasLostDynamicSegment: () => hasLostDynamicSegment, normalizeRoutePathname: () => normalizeRoutePathname, stripTrailingSlash: () => stripTrailingSlash }); module.exports = __toCommonJS(path_exports); var import_getStateFromPath_mods = require("../fork/getStateFromPath-mods.cjs"); function stripPathSuffix(path) { const queryIndex = path.indexOf("?"); const hashIndex = path.indexOf("#"); let end = path.length; if (queryIndex >= 0) end = Math.min(end, queryIndex); if (hashIndex >= 0) end = Math.min(end, hashIndex); return path.slice(0, end); } function stripTrailingSlash(pathname) { return pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname; } function normalizeRoutePathname(pathname) { return stripTrailingSlash((0, import_getStateFromPath_mods.stripBaseUrl)(stripPathSuffix(pathname))); } function hasLostDynamicSegment(path) { return stripPathSuffix(path).split("/").includes("undefined"); } function getSafeWindowPathname() { if (typeof window === "undefined" || !window.location || typeof window.location.pathname !== "string") { return void 0; } return window.location.pathname; } function getSafeWindowPath() { const pathname = getSafeWindowPathname(); if (pathname === void 0) return void 0; return pathname + (window.location.search || ""); } function getPathWithRecoveredDynamicSegment(paths, fallbackPath = getSafeWindowPath()) { for (const path of paths) { if (path !== void 0 && !hasLostDynamicSegment(path)) { return path; } } return fallbackPath; } function getPathnameWithRecoveredDynamicSegment(pathname, fallbackPath = getSafeWindowPath()) { return normalizeRoutePathname(getPathWithRecoveredDynamicSegment([pathname], fallbackPath) ?? pathname); }