This commit is contained in:
2026-08-14 16:03:47 +01:00
parent fd53e3f4fb
commit dfdc3b2840
2463 changed files with 186456 additions and 111315 deletions
+59 -8
View File
@@ -21,6 +21,24 @@ var toHash = (str) => {
}
return "css-" + out;
};
var normalizeLabel = (label) => {
return label.trim().replace(/\s+/g, "-");
};
var isValidClassName = (name) => /^-?[_a-zA-Z][_a-zA-Z0-9-]*$/.test(name);
var hasUnsafeSelectorChar = (name) => /[<{}]/.test(name);
var RESERVED_KEYFRAME_NAMES = /* @__PURE__ */ new Set([
"default",
"inherit",
"initial",
"none",
"revert",
"revert-layer",
"unset"
]);
var isValidKeyframeName = (name) => isValidClassName(name) && !RESERVED_KEYFRAME_NAMES.has(name.toLowerCase());
var defaultOnInvalidSlug = (slug) => {
console.warn(`Invalid slug: ${slug}`);
};
var cssStringReStr = [
'"(?:(?:\\\\[\\s\\S]|[^"\\\\])*)"',
// double quoted string
@@ -107,13 +125,26 @@ var buildStyleString = (strings, values) => {
}
return [label, minify(styleString), selectors, externalClassNames];
};
var cssCommon = (strings, values) => {
var cssCommon = (strings, values, classNameSlug, onInvalidSlug) => {
let [label, thisStyleString, selectors, externalClassNames] = buildStyleString(strings, values);
const isPseudoGlobal = isPseudoGlobalSelectorRe.exec(thisStyleString);
if (isPseudoGlobal) {
thisStyleString = isPseudoGlobal[1];
}
const selector = (isPseudoGlobal ? PSEUDO_GLOBAL_SELECTOR : "") + toHash(label + thisStyleString);
const hash = toHash(label + thisStyleString);
let customSlug;
if (classNameSlug) {
const slug = classNameSlug(hash, normalizeLabel(label), thisStyleString);
if (slug) {
if (isValidClassName(slug)) {
customSlug = slug;
} else {
;
(onInvalidSlug || defaultOnInvalidSlug)(slug);
}
}
}
const selector = (isPseudoGlobal ? PSEUDO_GLOBAL_SELECTOR : "") + (customSlug || hash);
const className = (isPseudoGlobal ? selectors.map((s) => s[CLASS_NAME]) : [selector, ...externalClassNames]).join(" ");
return {
[SELECTOR]: selector,
@@ -132,30 +163,50 @@ var cxCommon = (args) => {
[CLASS_NAME]: "",
[STYLE_STRING]: "",
[SELECTORS]: [],
[EXTERNAL_CLASS_NAMES]: [arg]
// drop names that are unsafe to emit as a selector
[EXTERNAL_CLASS_NAMES]: hasUnsafeSelectorChar(arg) ? [] : [arg]
};
}
}
return args;
};
var keyframesCommon = (strings, ...values) => {
var keyframesCommon = (strings, values, classNameSlug, onInvalidSlug) => {
const [label, styleString] = buildStyleString(strings, values);
const hash = toHash(label + styleString);
let customSlug;
if (classNameSlug) {
const slug = classNameSlug(hash, normalizeLabel(label), styleString);
if (slug) {
if (isValidKeyframeName(slug)) {
customSlug = slug;
} else {
;
(onInvalidSlug || defaultOnInvalidSlug)(slug);
}
}
}
return {
[SELECTOR]: "",
[CLASS_NAME]: `@keyframes ${toHash(label + styleString)}`,
[CLASS_NAME]: `@keyframes ${customSlug || hash}`,
[STYLE_STRING]: styleString,
[SELECTORS]: [],
[EXTERNAL_CLASS_NAMES]: []
};
};
var viewTransitionNameIndex = 0;
var viewTransitionCommon = ((strings, values) => {
var viewTransitionCommon = ((strings, values, classNameSlug, onInvalidSlug) => {
if (!strings) {
strings = [`/* h-v-t ${viewTransitionNameIndex++} */`];
}
const content = Array.isArray(strings) ? cssCommon(strings, values) : strings;
const content = Array.isArray(strings) ? cssCommon(strings, values, classNameSlug, onInvalidSlug) : strings;
const transitionName = content[CLASS_NAME];
const res = cssCommon(["view-transition-name:", ""], [transitionName]);
const res = cssCommon(
["view-transition-name:", ""],
// eslint-disable-line @typescript-eslint/no-explicit-any
[transitionName],
classNameSlug,
onInvalidSlug
);
content[CLASS_NAME] = PSEUDO_GLOBAL_SELECTOR + content[CLASS_NAME];
content[STYLE_STRING] = content[STYLE_STRING].replace(
/(?<=::view-transition(?:[a-z-]*)\()(?=\))/g,
+20 -5
View File
@@ -2,6 +2,7 @@
import { raw } from "../../helper/html/index.js";
import { DOM_RENDERER } from "../../jsx/constants.js";
import { createCssJsxDomObjects } from "../../jsx/dom/css.js";
import { escapeToBuffer } from "../../utils/html.js";
import {
CLASS_NAME,
DEFAULT_STYLE_ID,
@@ -15,7 +16,11 @@ import {
viewTransitionCommon
} from "./common.js";
import { rawCssString } from "./common.js";
var createCssContext = ({ id }) => {
var createCssContext = ({
id,
classNameSlug,
onInvalidSlug
}) => {
const [cssJsxDomObject, StyleRenderToDom] = createCssJsxDomObjects({ id });
const contextMap = /* @__PURE__ */ new WeakMap();
const nonceMap = /* @__PURE__ */ new WeakMap();
@@ -68,7 +73,14 @@ var createCssContext = ({ id }) => {
}
return Promise.resolve(raw("", [appendStyle]));
};
const className = new String(cssClassName[CLASS_NAME]);
const rawClassName = cssClassName[CLASS_NAME];
let escapedClassName = rawClassName;
if (/[&<>'"]/.test(rawClassName)) {
const escapedBuffer = [""];
escapeToBuffer(rawClassName, escapedBuffer);
escapedClassName = escapedBuffer[0];
}
const className = new String(escapedClassName);
Object.assign(className, cssClassName);
className.isEscaped = true;
className.callbacks = [addClassNameToContext];
@@ -78,15 +90,18 @@ var createCssContext = ({ id }) => {
return promise;
};
const css2 = (strings, ...values) => {
return newCssClassNameObject(cssCommon(strings, values));
return newCssClassNameObject(cssCommon(strings, values, classNameSlug, onInvalidSlug));
};
const cx2 = (...args) => {
args = cxCommon(args);
return css2(Array(args.length).fill(""), ...args);
};
const keyframes2 = keyframesCommon;
const keyframes2 = (strings, ...values) => keyframesCommon(strings, values, classNameSlug, onInvalidSlug);
const viewTransition2 = ((strings, ...values) => {
return newCssClassNameObject(viewTransitionCommon(strings, values));
return newCssClassNameObject(
viewTransitionCommon(strings, values, classNameSlug, onInvalidSlug)
// eslint-disable-line @typescript-eslint/no-explicit-any
);
});
const Style2 = ({ children, nonce } = {}) => raw(
`<style id="${id}"${nonce ? ` nonce="${nonce}"` : ""}>${children ? children[STYLE_STRING] : ""}</style>`,
+20 -10
View File
@@ -4,22 +4,30 @@ import { createPool } from "../../utils/concurrent.js";
import { getExtension } from "../../utils/mime.js";
import { SSG_CONTEXT, X_HONO_DISABLE_SSG_HEADER_KEY } from "./middleware.js";
import { defaultPlugin } from "./plugins.js";
import { dirname, filterStaticGenerateRoutes, isDynamicRoute, joinPaths } from "./utils.js";
import {
dirname,
ensureWithinOutDir,
filterStaticGenerateRoutes,
isDynamicRoute,
joinPaths
} from "./utils.js";
var DEFAULT_CONCURRENCY = 2;
var DEFAULT_CONTENT_TYPE = "text/plain";
var DEFAULT_OUTPUT_DIR = "./static";
var generateFilePath = (routePath, outDir, mimeType, extensionMap) => {
const extension = determineExtension(mimeType, extensionMap);
let filePath;
if (routePath.endsWith(`.${extension}`)) {
return joinPaths(outDir, routePath);
filePath = joinPaths(outDir, routePath);
} else if (routePath === "/") {
filePath = joinPaths(outDir, `index.${extension}`);
} else if (routePath.endsWith("/")) {
filePath = joinPaths(outDir, routePath, `index.${extension}`);
} else {
filePath = joinPaths(outDir, `${routePath}.${extension}`);
}
if (routePath === "/") {
return joinPaths(outDir, `index.${extension}`);
}
if (routePath.endsWith("/")) {
return joinPaths(outDir, routePath, `index.${extension}`);
}
return joinPaths(outDir, `${routePath}.${extension}`);
ensureWithinOutDir(outDir, filePath);
return filePath;
};
var parseResponseContent = async (response) => {
const contentType = response.headers.get("Content-Type");
@@ -39,6 +47,8 @@ var defaultExtensionMap = {
"text/html": "html",
"text/xml": "xml",
"application/xml": "xml",
"application/atom+xml": "xml",
"application/rss+xml": "xml",
"application/yaml": "yaml"
};
var determineExtension = (mimeType, userExtensionMap) => {
@@ -110,7 +120,7 @@ var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, c
}
forGetInfoURLRequest = maybeRequest;
}
await pool.run(() => app.fetch(forGetInfoURLRequest));
await pool.run(() => app.fetch(forGetInfoURLRequest, { [SSG_CONTEXT]: true }));
if (!forGetInfoURLRequest.ssgParams) {
if (isDynamicRoute(route.path)) {
resolveGetInfo(void 0);
+8
View File
@@ -51,8 +51,16 @@ var filterStaticGenerateRoutes = (hono) => {
var isDynamicRoute = (path) => {
return path.split("/").some((segment) => segment.startsWith(":") || segment.includes("*"));
};
var ensureWithinOutDir = (outDir, filePath) => {
const normalizedOutDir = joinPaths("/", outDir);
const normalizedFilePath = joinPaths("/", filePath);
if (normalizedFilePath !== normalizedOutDir && !normalizedFilePath.startsWith(`${normalizedOutDir}/`)) {
throw new Error(`Path traversal detected: "${filePath}" is outside the output directory`);
}
};
export {
dirname,
ensureWithinOutDir,
filterStaticGenerateRoutes,
isDynamicRoute,
joinPaths