one
Version:
One is a new React Framework that makes Vite serve both native and web.
75 lines (73 loc) • 3.36 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: 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 cleanUrl_exports = {};
__export(cleanUrl_exports, {
decodeReservedFilenameChars: () => decodeReservedFilenameChars,
encodeReservedFilenameChars: () => encodeReservedFilenameChars,
getLoaderPath: () => getLoaderPath,
getPathFromLoaderPath: () => getPathFromLoaderPath,
getPreloadCSSPath: () => getPreloadCSSPath,
getPreloadPath: () => getPreloadPath
});
module.exports = __toCommonJS(cleanUrl_exports);
var import_constants = require("../constants.native.js");
var import_getURL = require("../getURL.native.js");
var import_removeSearch = require("./removeSearch.native.js");
function encodeReservedFilenameChars(path) {
return path.replaceAll("=", "=3d").replace(/[<>:"|?*]/g, function (char) {
return `=${char.charCodeAt(0).toString(16).padStart(2, "0")}`;
});
}
function decodeReservedFilenameChars(path) {
return path.replace(/=([0-9a-f]{2})/g, function (_match, hexCode) {
return String.fromCharCode(Number.parseInt(hexCode, 16));
});
}
function cleanUrl(path) {
return encodeReservedFilenameChars((0, import_removeSearch.removeSearch)(path).replace(/\/$/, "")).replaceAll("_", "__").replaceAll("/", "_");
}
var isClient = typeof window !== "undefined";
var clientSideURL = isClient ? (0, import_getURL.getURL)() : "";
function getPreloadPath(currentPath) {
return `${clientSideURL}/assets/${cleanUrl(currentPath.slice(1))}${import_constants.PRELOAD_JS_POSTFIX}`;
}
function getPreloadCSSPath(currentPath) {
return `${clientSideURL}/assets/${cleanUrl(currentPath.slice(1))}${import_constants.CSS_PRELOAD_JS_POSTFIX}`;
}
function getLoaderPath(currentPath) {
var includeUrl = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : import_constants.isNative,
cacheBust = arguments.length > 2 ? arguments[2] : void 0;
var baseURL = includeUrl ? (0, import_getURL.getURL)() : "";
var devPath = process.env.NODE_ENV === "development" ? "/_one" : "";
var currentPathUrl = new URL(currentPath, "http://example.com");
var cleanedUrl = cleanUrl(currentPathUrl.pathname.slice(1));
var cacheBustSegment = cacheBust ? `_refetch_${cacheBust}_` : "";
return `${baseURL}${devPath}/assets/${cleanedUrl}${cacheBustSegment}${import_constants.LOADER_JS_POSTFIX}`;
}
function getPathFromLoaderPath(loaderPath) {
return decodeReservedFilenameChars(loaderPath.replace(import_constants.LOADER_JS_POSTFIX_REGEX, "").replace(/^(\/_one)?\/assets/, "").replace(/_refetch_\d+_?/, "").replace(/__|_/g, function (match) {
return match === "__" ? "_" : "/";
}));
}
//# sourceMappingURL=cleanUrl.native.js.map