Files
SnowLuma/.pnpm-store/v11/files/e5/22b2aef123c0579b42254f5710e25622ec4ba918d1e4811a1b392cfe5c9a99a364ff93682f75db2474517e0a3eebbb1a4952824e44901f0556018b433731fa
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

141 lines
5.0 KiB
Plaintext

"use client";
import { useHydrated } from "./ClientOnly.js";
import { useRouter } from "./useRouter.js";
import * as React$1 from "react";
import { jsx } from "react/jsx-runtime";
import { isServer } from "@tanstack/router-core/isServer";
//#region src/Asset.tsx
var INLINE_CSS_HYDRATION_ATTR = "data-tsr-inline-css";
function Asset(asset) {
const { attrs, children, nonce } = asset;
switch (asset.tag) {
case "title": return /* @__PURE__ */ jsx("title", {
...attrs,
suppressHydrationWarning: true,
children
});
case "meta": return /* @__PURE__ */ jsx("meta", {
...attrs,
suppressHydrationWarning: true
});
case "link": return /* @__PURE__ */ jsx("link", {
...attrs,
precedence: attrs?.precedence ?? (attrs?.rel === "stylesheet" ? "default" : void 0),
nonce,
suppressHydrationWarning: true
});
case "style":
if (asset.inlineCss && (process.env.TSS_INLINE_CSS_ENABLED === "true" || process.env.TSS_INLINE_CSS_ENABLED === void 0 && isServer)) return /* @__PURE__ */ jsx(InlineCssStyle, {
attrs,
nonce,
children
});
return /* @__PURE__ */ jsx("style", {
...attrs,
dangerouslySetInnerHTML: { __html: children },
nonce
});
case "script": return /* @__PURE__ */ jsx(Script, {
attrs,
children
});
default: return null;
}
}
function InlineCssStyle({ attrs, children, nonce }) {
const isInlineCssPlaceholder = children === void 0;
const [hydratedInlineCss] = React$1.useState(() => {
if (!isInlineCssPlaceholder || typeof document === "undefined") return;
return document.querySelector(`style[${INLINE_CSS_HYDRATION_ATTR}]`)?.textContent ?? void 0;
});
const html = isInlineCssPlaceholder ? hydratedInlineCss ?? "" : children ?? "";
return /* @__PURE__ */ jsx("style", {
...attrs,
[INLINE_CSS_HYDRATION_ATTR]: "",
dangerouslySetInnerHTML: { __html: html },
nonce,
suppressHydrationWarning: true
});
}
function Script({ attrs, children }) {
const router = useRouter();
const hydrated = useHydrated();
const dataScript = typeof attrs?.type === "string" && attrs.type !== "" && attrs.type !== "text/javascript" && attrs.type !== "module";
if (process.env.NODE_ENV !== "production" && attrs?.src && typeof children === "string" && children.trim().length) console.warn("[TanStack Router] <Script> received both `src` and `children`. The `children` content will be ignored. Remove `children` or remove `src`.");
React$1.useEffect(() => {
if (dataScript) return;
if (attrs?.src) {
const normSrc = (() => {
try {
const base = document.baseURI || window.location.href;
return new URL(attrs.src, base).href;
} catch {
return attrs.src;
}
})();
if (Array.from(document.querySelectorAll("script[src]")).find((el) => el.src === normSrc)) return;
const script = document.createElement("script");
for (const [key, value] of Object.entries(attrs)) if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) script.setAttribute(key, typeof value === "boolean" ? "" : String(value));
document.head.appendChild(script);
return () => {
if (script.parentNode) script.parentNode.removeChild(script);
};
}
if (typeof children === "string") {
const typeAttr = typeof attrs?.type === "string" ? attrs.type : "text/javascript";
const nonceAttr = typeof attrs?.nonce === "string" ? attrs.nonce : void 0;
if (Array.from(document.querySelectorAll("script:not([src])")).find((el) => {
if (!(el instanceof HTMLScriptElement)) return false;
const sType = el.getAttribute("type") ?? "text/javascript";
const sNonce = el.getAttribute("nonce") ?? void 0;
return el.textContent === children && sType === typeAttr && sNonce === nonceAttr;
})) return;
const script = document.createElement("script");
script.textContent = children;
if (attrs) {
for (const [key, value] of Object.entries(attrs)) if (key !== "suppressHydrationWarning" && value !== void 0 && value !== false) script.setAttribute(key, typeof value === "boolean" ? "" : String(value));
}
document.head.appendChild(script);
return () => {
if (script.parentNode) script.parentNode.removeChild(script);
};
}
}, [
attrs,
children,
dataScript
]);
if (isServer ?? router.isServer) {
if (attrs?.src) return /* @__PURE__ */ jsx("script", {
...attrs,
suppressHydrationWarning: true
});
if (typeof children === "string") return /* @__PURE__ */ jsx("script", {
...attrs,
dangerouslySetInnerHTML: { __html: children },
suppressHydrationWarning: true
});
return null;
}
if (dataScript && typeof children === "string") return /* @__PURE__ */ jsx("script", {
...attrs,
suppressHydrationWarning: true,
dangerouslySetInnerHTML: { __html: children }
});
if (!hydrated) {
if (attrs?.src) return /* @__PURE__ */ jsx("script", {
...attrs,
suppressHydrationWarning: true
});
if (typeof children === "string") return /* @__PURE__ */ jsx("script", {
...attrs,
dangerouslySetInnerHTML: { __html: children },
suppressHydrationWarning: true
});
}
return null;
}
//#endregion
export { Asset };
//# sourceMappingURL=Asset.js.map