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
+15 -16
View File
@@ -1,4 +1,3 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -126,8 +125,11 @@ class JSXNode {
key;
children;
isEscaped = true;
localContexts;
suspendedContext;
constructor(tag, props, children) {
if (typeof tag !== "function" && !(0, import_utils.isValidTagName)(tag)) {
throw new Error(`Invalid JSX tag name: ${tag}`);
}
this.tag = tag;
this.props = props;
this.children = children;
@@ -141,27 +143,24 @@ class JSXNode {
return this.props.ref || null;
}
toString() {
const buffer = [""];
this.localContexts?.forEach(([context, value]) => {
context.values.push(value);
});
try {
const render = () => {
const buffer = [""];
this.toStringToBuffer(buffer);
} finally {
this.localContexts?.forEach(([context]) => {
context.values.pop();
});
}
return buffer.length === 1 ? "callbacks" in buffer ? (0, import_html2.resolveCallbackSync)((0, import_html.raw)(buffer[0], buffer.callbacks)).toString() : buffer[0] : (0, import_html2.stringBufferToString)(buffer, buffer.callbacks);
return buffer.length === 1 ? "callbacks" in buffer ? (0, import_html2.resolveCallbackSync)((0, import_html.raw)(buffer[0], buffer.callbacks)).toString() : buffer[0] : (0, import_html2.stringBufferToString)(buffer, buffer.callbacks);
};
return this.suspendedContext ? this.suspendedContext(render) : (0, import_context.runWithRenderContext)(render);
}
toStringToBuffer(buffer) {
const tag = this.tag;
const props = this.props;
let { children } = this;
buffer[0] += `<${tag}`;
const normalizeKey = nameSpaceContext && (0, import_context.useContext)(nameSpaceContext) === "svg" ? (key) => toSVGAttributeName((0, import_utils.normalizeIntrinsicElementKey)(key)) : (key) => (0, import_utils.normalizeIntrinsicElementKey)(key);
const normalizeKey = tag === "svg" || nameSpaceContext && (0, import_context.useContext)(nameSpaceContext) === "svg" ? (key) => toSVGAttributeName((0, import_utils.normalizeIntrinsicElementKey)(key)) : (key) => (0, import_utils.normalizeIntrinsicElementKey)(key);
for (let [key, v] of Object.entries(props)) {
key = normalizeKey(key);
if (!(0, import_utils.isValidAttributeName)(key)) {
continue;
}
if (key === "children") {
} else if (key === "style" && typeof v === "object") {
let styleStr = "";
@@ -225,12 +224,12 @@ class JSXFunctionNode extends JSXNode {
if (import_context.globalContexts.length === 0) {
buffer.unshift("", res);
} else {
const currentContexts = import_context.globalContexts.map((c) => [c, c.values.at(-1)]);
const suspendedContext = (0, import_context.captureRenderContext)();
buffer.unshift(
"",
res.then((childRes) => {
if (childRes instanceof JSXNode) {
childRes.localContexts = currentContexts;
childRes.suspendedContext = suspendedContext;
}
return childRes;
})
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+41 -22
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -35,8 +34,9 @@ const childrenToString = async (children) => {
return children.flat().map((c) => c == null || typeof c === "boolean" ? "" : c.toString());
} catch (e) {
if (e instanceof Promise) {
const resume = (0, import_context.captureRenderContext)();
await e;
return childrenToString(children);
return resume(() => childrenToString(children));
} else {
throw e;
}
@@ -64,51 +64,68 @@ const ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) =>
children = [children];
}
const nonce = (0, import_context.useContext)(import_streaming.StreamingContext)?.scriptNonce;
let fallbackStr;
const resolveFallbackStr = async () => {
let resume;
const getResume = () => resume ||= (0, import_context.captureRenderContext)();
let fallbackStrPromise;
const resolveFallbackStr = () => fallbackStrPromise ||= (async () => {
const awaitedFallback = await fallback;
if (typeof awaitedFallback === "string") {
fallbackStr = awaitedFallback;
return awaitedFallback;
} else {
fallbackStr = await awaitedFallback?.toString();
if (typeof fallbackStr === "string") {
fallbackStr = (0, import_html.raw)(fallbackStr);
const fallbackResult = await getResume()(() => awaitedFallback?.toString());
if (typeof fallbackResult === "string") {
return (0, import_html.raw)(
fallbackResult,
fallbackResult.callbacks || awaitedFallback?.callbacks
);
}
}
};
const fallbackRes = (error) => {
onError?.(error);
return fallbackStr || fallbackRender && (0, import_base.jsx)(import_base.Fragment, {}, fallbackRender(error)) || "";
})();
const renderFallback = async (error) => {
const fallbackStr = await resolveFallbackStr();
return getResume()(async () => {
onError?.(error);
const fallbackRes = fallbackStr !== void 0 ? fallbackStr : fallbackRender && (0, import_base.jsx)(import_base.Fragment, {}, fallbackRender(error)) || "";
const fallbackResString = await (0, import_base.Fragment)({
children: fallbackRes
}).toString();
return (0, import_html.raw)(
fallbackResString,
fallbackResString.callbacks || fallbackRes.callbacks
);
});
};
let resArray = [];
try {
resArray = children.map(resolveChildEarly);
} catch (e) {
await resolveFallbackStr();
const resume2 = getResume();
if (e instanceof Promise) {
resArray = [
e.then(() => childrenToString(children)).catch((e2) => fallbackRes(e2))
e.then(() => resume2(() => childrenToString(children))).catch((e2) => renderFallback(e2))
];
} else {
resArray = [fallbackRes(e)];
resArray = [await renderFallback(e)];
}
}
if (resArray.some((res) => res instanceof Promise)) {
await resolveFallbackStr();
getResume();
const index = errorBoundaryCounter++;
const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
const caught = false;
let caught = false;
const catchCallback = async ({ error: error2, buffer }) => {
if (caught) {
return "";
}
const fallbackResString = await (0, import_base.Fragment)({
children: fallbackRes(error2)
}).toString();
caught = true;
const fallbackResString = await renderFallback(error2);
const fallbackCallbacks = fallbackResString.callbacks;
if (buffer) {
buffer[0] = buffer[0].replace(replaceRe, fallbackResString);
return fallbackCallbacks?.length ? (0, import_html.raw)("", fallbackCallbacks) : "";
}
return buffer ? "" : `<template data-hono-target="E:${index}">${fallbackResString}</template><script>
return (0, import_html.raw)(
`<template data-hono-target="E:${index}">${fallbackResString}</template><script>
((d,c,n) => {
c=d.currentScript.previousSibling
d=d.getElementById('E:${index}')
@@ -116,7 +133,9 @@ if(!d)return
do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='E:${index}')
d.replaceWith(c.content)
})(document)
</script>`;
</script>`,
fallbackCallbacks
);
};
let error;
const promiseAll = Promise.all(resArray).catch((e) => error = e);
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+131 -6
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -18,8 +17,10 @@ var __copyProps = (to, from, except, desc) => {
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var context_exports = {};
__export(context_exports, {
captureRenderContext: () => captureRenderContext,
createContext: () => createContext,
globalContexts: () => globalContexts,
runWithRenderContext: () => runWithRenderContext,
useContext: () => useContext
});
module.exports = __toCommonJS(context_exports);
@@ -28,21 +29,143 @@ var import_base = require("./base");
var import_constants = require("./constants");
var import_context = require("./dom/context");
const globalContexts = [];
let alsProbed = false;
let asyncLocalStorage;
let fallbackStore;
let fallbackRendersInFlight = 0;
let warnedFallbackDefault = false;
const loadAsyncLocalStorage = () => {
if (alsProbed) {
return asyncLocalStorage;
}
alsProbed = true;
const global = globalThis;
let AsyncLocalStorage;
for (const probe of [
// Node.js >= 20.16, Deno, Bun, Cloudflare Workers (nodejs_compat). Property
// access only, so bundlers don't statically resolve `node:async_hooks`.
() => global.process?.getBuiltinModule?.("node:async_hooks")?.AsyncLocalStorage,
// Node.js < 20.16 has no `process.getBuiltinModule`, but a CJS entrypoint
// exposes the main module's `require` here.
() => global.process?.mainModule?.require?.("node:async_hooks")?.AsyncLocalStorage
]) {
try {
AsyncLocalStorage = probe();
} catch {
}
if (AsyncLocalStorage) {
break;
}
}
if (AsyncLocalStorage) {
asyncLocalStorage = new AsyncLocalStorage();
}
return asyncLocalStorage;
};
const getCurrentStore = () => {
return loadAsyncLocalStorage()?.getStore() || fallbackStore;
};
const warnIfStorelessAccess = () => {
if (fallbackRendersInFlight > 0 && !warnedFallbackDefault) {
warnedFallbackDefault = true;
console.warn(
"hono/jsx: AsyncLocalStorage is unavailable in this runtime, so useContext() after an await in an async component falls back to the context default value during server-side rendering. To get provided values across await boundaries, use a runtime with AsyncLocalStorage (Node.js >= 20.16, Deno, Bun, or Cloudflare Workers with the nodejs_compat flag)."
);
}
};
const getContextValuesIn = (store, context) => {
if (!store) {
warnIfStorelessAccess();
return context.values;
}
let values = store.get(context);
if (!values) {
values = [context.values[0]];
store.set(context, values);
}
return values;
};
const readContextValueIn = (store, context) => {
if (!store) {
warnIfStorelessAccess();
return context.values.at(-1);
}
const values = store.get(context);
return values?.length ? values.at(-1) : context.values[0];
};
const captureContextValues = (store) => (store ? globalContexts.filter((c) => store.has(c)) : globalContexts).map((c) => [
c,
readContextValueIn(store, c)
]);
const resumeWithContextValues = (callback, store, contexts) => runWithRenderContext(() => {
const currentStore = getCurrentStore();
const valuesPerContext = contexts.map(([context, value]) => {
const values = getContextValuesIn(currentStore, context);
values.push(value);
return values;
});
const popContextValues = () => {
valuesPerContext.forEach((values) => {
values.pop();
});
};
try {
const result = callback();
if (result instanceof Promise) {
return result.finally(popContextValues);
}
popContextValues();
return result;
} catch (e) {
popContextValues();
throw e;
}
}, store);
const runWithRenderContext = (callback, resumeStore) => {
if (getCurrentStore()) {
return callback();
}
const store = resumeStore ?? /* @__PURE__ */ new WeakMap();
const storage = loadAsyncLocalStorage();
if (storage) {
return storage.run(store, callback);
}
fallbackStore = store;
let result;
try {
result = callback();
} finally {
fallbackStore = void 0;
}
if (!warnedFallbackDefault && result instanceof Promise) {
fallbackRendersInFlight++;
result = result.finally(() => {
fallbackRendersInFlight--;
});
}
return result;
};
const captureRenderContext = () => {
const store = getCurrentStore();
const contexts = captureContextValues(store);
return (callback) => resumeWithContextValues(callback, store, contexts);
};
const createContext = (defaultValue) => {
const values = [defaultValue];
const context = ((props) => {
values.push(props.value);
const contextValues = getContextValuesIn(getCurrentStore(), context);
contextValues.push(props.value);
let string;
try {
string = props.children ? (Array.isArray(props.children) ? new import_base.JSXFragmentNode("", {}, props.children) : props.children).toString() : "";
} catch (e) {
values.pop();
contextValues.pop();
throw e;
}
if (string instanceof Promise) {
return string.finally(() => values.pop()).then((resString) => (0, import_html.raw)(resString, resString.callbacks));
return string.finally(() => contextValues.pop()).then((resString) => (0, import_html.raw)(resString, resString.callbacks));
} else {
values.pop();
contextValues.pop();
return (0, import_html.raw)(string);
}
});
@@ -53,11 +176,13 @@ const createContext = (defaultValue) => {
return context;
};
const useContext = (context) => {
return context.values.at(-1);
return readContextValueIn(getCurrentStore(), context);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
captureRenderContext,
createContext,
globalContexts,
runWithRenderContext,
useContext
});
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+11 -5
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -118,22 +117,29 @@ const createCssJsxDomObjects = ({ id }) => {
});
return [cssObject, Style2];
};
const createCssContext = ({ id }) => {
const createCssContext = ({
id,
classNameSlug,
onInvalidSlug
}) => {
const [cssObject, Style2] = createCssJsxDomObjects({ id });
const newCssClassNameObject = (cssClassName) => {
cssClassName.toString = cssObject.toString;
return cssClassName;
};
const css2 = (strings, ...values) => {
return newCssClassNameObject((0, import_common.cssCommon)(strings, values));
return newCssClassNameObject((0, import_common.cssCommon)(strings, values, classNameSlug, onInvalidSlug));
};
const cx2 = (...args) => {
args = (0, import_common.cxCommon)(args);
return css2(Array(args.length).fill(""), ...args);
};
const keyframes2 = import_common.keyframesCommon;
const keyframes2 = (strings, ...values) => (0, import_common.keyframesCommon)(strings, values, classNameSlug, onInvalidSlug);
const viewTransition2 = ((strings, ...values) => {
return newCssClassNameObject((0, import_common.viewTransitionCommon)(strings, values));
return newCssClassNameObject(
(0, import_common.viewTransitionCommon)(strings, values, classNameSlug, onInvalidSlug)
// eslint-disable-line @typescript-eslint/no-explicit-any
);
});
return {
css: css2,
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+40 -10
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -80,11 +79,16 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
let element = null;
let created = false;
const deDupeKeys = import_common.deDupeKeyMap[tag];
const deDupeByKey = (0, import_common.shouldDeDupeByKey)(tag, supportSort);
const isDeDupeCandidateLink = (e) => e.getAttribute("rel") === "stylesheet" && e.getAttribute(import_common.dataPrecedenceAttr) !== null;
let existingElements = void 0;
if (deDupeKeys.length > 0) {
if (deDupeByKey) {
const tags = head.querySelectorAll(tag);
LOOP: for (const e of tags) {
for (const key of import_common.deDupeKeyMap[tag]) {
if (tag === "link" && !isDeDupeCandidateLink(e)) {
continue;
}
for (const key of deDupeKeys) {
if (e.getAttribute(key) === props[key]) {
element = e;
break LOOP;
@@ -103,9 +107,9 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
if (props[key] !== void 0) {
e.setAttribute(key, props[key]);
}
if (props.rel) {
e.setAttribute("rel", props.rel);
}
}
if (props.rel) {
e.setAttribute("rel", props.rel);
}
return e;
})();
@@ -119,7 +123,26 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
}
const insert = (0, import_hooks.useCallback)(
(e) => {
if (deDupeKeys.length > 0) {
if (deDupeByKey) {
if (tag === "link" && precedence !== void 0) {
let found2 = false;
for (const existingElement of head.querySelectorAll(tag)) {
const existingPrecedence = existingElement.getAttribute(import_common.dataPrecedenceAttr);
if (existingPrecedence === null) {
head.insertBefore(e, existingElement);
return;
}
if (found2 && existingPrecedence !== precedence) {
head.insertBefore(e, existingElement);
return;
}
if (existingPrecedence === precedence) {
found2 = true;
}
}
head.appendChild(e);
return;
}
let found = false;
for (const existingElement of head.querySelectorAll(tag)) {
if (found && existingElement.getAttribute(import_common.dataPrecedenceAttr) !== precedence) {
@@ -131,6 +154,10 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
}
}
head.appendChild(e);
} else if (tag === "link") {
if (!head.contains(e)) {
head.appendChild(e);
}
} else if (existingElements) {
let found = false;
for (const existingElement of existingElements) {
@@ -148,7 +175,7 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
existingElements = void 0;
}
},
[precedence]
[deDupeByKey, precedence, tag]
);
const ref = composeRef(props.ref, (e) => {
const key = deDupeKeys[0];
@@ -161,6 +188,9 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
if (!onError && !onLoad) {
return;
}
if (!key) {
return;
}
let promise = blockingPromiseMap[e.getAttribute(key)] ||= new Promise(
(resolve, reject) => {
e.addEventListener("load", resolve);
@@ -178,7 +208,7 @@ const documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportB
});
if (supportBlocking && blocking === "render") {
const key = import_common.deDupeKeyMap[tag][0];
if (props[key]) {
if (key && props[key]) {
const value = props[key];
const promise = blockingPromiseMap[value] ||= new Promise((resolve, reject) => {
insert(element);
@@ -254,7 +284,7 @@ const link = (props) => {
ref: props.ref
};
}
return documentMetadataTag("link", props, 1, "precedence" in props, true);
return documentMetadataTag("link", props, 1, (0, import_common.isStylesheetLinkWithPrecedence)(props), true);
};
const meta = (props) => {
return documentMetadataTag("meta", props, void 0, false, false);
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+39 -18
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -69,6 +68,17 @@ const getEventSpec = (key) => {
};
const toAttributeName = (element, key) => nameSpaceContext && element instanceof SVGElement && /[A-Z]/.test(key) && (key in element.style || // Presentation attributes are findable in style object. "clip-path", "font-size", "stroke-width", etc.
key.match(/^(?:o|pai|str|u|ve)/)) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
const normalizeFormValue = (value) => value === null || value === void 0 || value === false ? null : value;
const applySelectValue = (select, props) => {
if (!("value" in props)) {
return;
}
select.value = normalizeFormValue(props["value"]);
if (!select.multiple && select.selectedIndex === -1) {
select.selectedIndex = 0;
}
};
const isIgnorableAttributeError = (error) => error instanceof DOMException && error.name === "InvalidCharacterError";
const applyProps = (container, attributes, oldAttributes) => {
attributes ||= {};
for (let key in attributes) {
@@ -112,18 +122,14 @@ const applyProps = (container, attributes, oldAttributes) => {
} else {
if (key === "value") {
const nodeName = container.nodeName;
if (nodeName === "INPUT" || nodeName === "TEXTAREA" || nodeName === "SELECT") {
if (nodeName === "SELECT") {
continue;
} else if (nodeName === "INPUT" || nodeName === "TEXTAREA") {
;
container.value = value === null || value === void 0 || value === false ? null : value;
container.value = normalizeFormValue(value);
if (nodeName === "TEXTAREA") {
container.textContent = value;
continue;
} else if (nodeName === "SELECT") {
if (container.selectedIndex === -1) {
;
container.selectedIndex = 0;
}
continue;
}
}
} else if (key === "checked" && container.nodeName === "INPUT" || key === "selected" && container.nodeName === "OPTION") {
@@ -131,14 +137,20 @@ const applyProps = (container, attributes, oldAttributes) => {
container[key] = value;
}
const k = toAttributeName(container, key);
if (value === null || value === void 0 || value === false) {
container.removeAttribute(k);
} else if (value === true) {
container.setAttribute(k, "");
} else if (typeof value === "string" || typeof value === "number") {
container.setAttribute(k, value);
} else {
container.setAttribute(k, value.toString());
try {
if (value === null || value === void 0 || value === false) {
container.removeAttribute(k);
} else if (value === true) {
container.setAttribute(k, "");
} else if (typeof value === "string" || typeof value === "number") {
container.setAttribute(k, value);
} else {
container.setAttribute(k, value.toString());
}
} catch (e) {
if (!isIgnorableAttributeError(e)) {
throw e;
}
}
}
}
@@ -154,7 +166,13 @@ const applyProps = (container, attributes, oldAttributes) => {
} else if (key === "ref") {
refCleanupMap.get(container)?.();
} else {
container.removeAttribute(toAttributeName(container, key));
try {
container.removeAttribute(toAttributeName(container, key));
} catch (e) {
if (!isIgnorableAttributeError(e)) {
throw e;
}
}
}
}
}
@@ -292,6 +310,9 @@ const applyNodeObject = (node, container, isNew) => {
el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
applyProps(el, child.props, child.pP);
applyNodeObject(child, el, isNewLocal);
if (child.tag === "select") {
applySelectValue(el, child.props);
}
}
}
if (child.tag === HONO_PORTAL_ELEMENT) {
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+13 -3
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -20,7 +19,9 @@ var common_exports = {};
__export(common_exports, {
dataPrecedenceAttr: () => dataPrecedenceAttr,
deDupeKeyMap: () => deDupeKeyMap,
domRenderers: () => domRenderers
domRenderers: () => domRenderers,
isStylesheetLinkWithPrecedence: () => isStylesheetLinkWithPrecedence,
shouldDeDupeByKey: () => shouldDeDupeByKey
});
module.exports = __toCommonJS(common_exports);
const deDupeKeyMap = {
@@ -32,9 +33,18 @@ const deDupeKeyMap = {
};
const domRenderers = {};
const dataPrecedenceAttr = "data-precedence";
const isStylesheetLinkWithPrecedence = (props) => props.rel === "stylesheet" && "precedence" in props;
const shouldDeDupeByKey = (tagName, supportSort) => {
if (tagName === "link") {
return supportSort;
}
return deDupeKeyMap[tagName].length > 0;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
dataPrecedenceAttr,
deDupeKeyMap,
domRenderers
domRenderers,
isStylesheetLinkWithPrecedence,
shouldDeDupeByKey
});
+18 -12
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -44,8 +43,12 @@ const insertIntoHead = (tagName, tag, props, precedence) => ({ buffer, context }
const tags = map[tagName] ||= [];
let duped = false;
const deDupeKeys = import_common.deDupeKeyMap[tagName];
if (deDupeKeys.length > 0) {
const deDupeByKey = (0, import_common.shouldDeDupeByKey)(tagName, precedence !== void 0);
if (deDupeByKey) {
LOOP: for (const [, tagProps] of tags) {
if (tagName === "link" && !(tagProps.rel === "stylesheet" && tagProps[import_common.dataPrecedenceAttr] !== void 0)) {
continue;
}
for (const key of deDupeKeys) {
if ((tagProps?.[key] ?? null) === props?.[key]) {
duped = true;
@@ -56,25 +59,28 @@ const insertIntoHead = (tagName, tag, props, precedence) => ({ buffer, context }
}
if (duped) {
buffer[0] = buffer[0].replaceAll(tag, "");
} else if (deDupeKeys.length > 0) {
} else if (deDupeByKey || tagName === "link") {
tags.push([tag, props, precedence]);
} else {
tags.unshift([tag, props, precedence]);
}
if (buffer[0].indexOf("</head>") !== -1) {
let insertTags;
if (precedence === void 0) {
insertTags = tags.map(([tag2]) => tag2);
} else {
if (tagName === "link" || precedence !== void 0) {
const precedences = [];
insertTags = tags.map(([tag2, , precedence2]) => {
let order = precedences.indexOf(precedence2);
insertTags = tags.map(([tag2, , tagPrecedence], index) => {
if (tagPrecedence === void 0) {
return [tag2, Number.MAX_SAFE_INTEGER, index];
}
let order = precedences.indexOf(tagPrecedence);
if (order === -1) {
precedences.push(precedence2);
precedences.push(tagPrecedence);
order = precedences.length - 1;
}
return [tag2, order];
}).sort((a, b) => a[1] - b[1]).map(([tag2]) => tag2);
return [tag2, order, index];
}).sort((a, b) => a[1] - b[1] || a[2] - b[2]).map(([tag2]) => tag2);
} else {
insertTags = tags.map(([tag2]) => tag2);
}
insertTags.forEach((tag2) => {
buffer[0] = buffer[0].replaceAll(tag2, "");
@@ -143,7 +149,7 @@ const link = ({ children, ...props }) => {
if (["onLoad", "onError"].some((k) => k in props) || props.rel === "stylesheet" && (!("precedence" in props) || "disabled" in props)) {
return returnWithoutSpecialBehavior("link", children, props);
}
return documentMetadataTag("link", children, props, "precedence" in props);
return documentMetadataTag("link", children, props, (0, import_common.isStylesheetLinkWithPrecedence)(props));
};
const meta = ({ children, ...props }) => {
const nameSpaceContext = (0, import_base.getNameSpaceContext)();
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+3 -1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -32,6 +31,9 @@ var import_html = require("../helper/html");
var import_html2 = require("../utils/html");
var import_utils = require("./utils");
const jsxAttr = (key, v) => {
if (!(0, import_utils.isValidAttributeName)(key)) {
return (0, import_html.raw)("");
}
const buffer = [`${key}="`];
if (key === "style" && typeof v === "object") {
let styleStr = "";
+9 -8
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -43,9 +42,8 @@ const Suspense = async ({
const nonce = (0, import_context.useContext)(StreamingContext)?.scriptNonce;
let resArray = [];
const stackNode = { [import_constants.DOM_STASH]: [0, []] };
const popNodeStack = (value) => {
const popNodeStack = () => {
import_render.buildDataStack.pop();
return value;
};
try {
stackNode[import_constants.DOM_STASH][0] = 0;
@@ -55,12 +53,15 @@ const Suspense = async ({
);
} catch (e) {
if (e instanceof Promise) {
const resume = (0, import_context.captureRenderContext)();
resArray = [
e.then(() => {
stackNode[import_constants.DOM_STASH][0] = 0;
import_render.buildDataStack.push([[], stackNode]);
return (0, import_components.childrenToString)(children).then(popNodeStack);
})
e.then(
() => resume(() => {
stackNode[import_constants.DOM_STASH][0] = 0;
import_render.buildDataStack.push([[], stackNode]);
return (0, import_components.childrenToString)(children).finally(popNodeStack);
})
)
];
} else {
throw e;
-1
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
+155 -6
View File
@@ -1,4 +1,3 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -18,6 +17,8 @@ var __copyProps = (to, from, except, desc) => {
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var utils_exports = {};
__export(utils_exports, {
isValidAttributeName: () => isValidAttributeName,
isValidTagName: () => isValidTagName,
normalizeIntrinsicElementKey: () => normalizeIntrinsicElementKey,
styleObjectForEach: () => styleObjectForEach
});
@@ -33,19 +34,167 @@ const normalizeElementKeyMap = /* @__PURE__ */ new Map([
["formAction", "formaction"]
]);
const normalizeIntrinsicElementKey = (key) => normalizeElementKeyMap.get(key) || key;
const invalidAttributeNameCharRe = /[\s"'<>/=`\\\x00-\x1f\x7f-\x9f]/;
const validAttributeNameCache = /* @__PURE__ */ new Set();
const validAttributeNameCacheMax = 1024;
const invalidTagNameCharRe = /^[!?]|[\s"'<>/=`\\\x00-\x1f\x7f-\x9f]/;
const validTagNameCache = /* @__PURE__ */ new Set();
const validTagNameCacheMax = 256;
const cacheValidName = (cache, max, name) => {
if (cache.size >= max) {
cache.clear();
}
cache.add(name);
};
const isValidTagName = (name) => {
if (validTagNameCache.has(name)) {
return true;
}
if (typeof name !== "string") {
return false;
}
if (name.length === 0) {
return true;
}
if (invalidTagNameCharRe.test(name)) {
return false;
}
cacheValidName(validTagNameCache, validTagNameCacheMax, name);
return true;
};
const isValidAttributeName = (name) => {
if (validAttributeNameCache.has(name)) {
return true;
}
const len = name.length;
if (len === 0) {
return false;
}
for (let i = 0; i < len; i++) {
const c = name.charCodeAt(i);
if (!(c >= 97 && c <= 122 || // a-z
c >= 65 && c <= 90 || // A-Z
c >= 48 && c <= 57 || // 0-9
c === 45 || // -
c === 95 || // _
c === 46 || // .
c === 58)) {
if (!invalidAttributeNameCharRe.test(name)) {
cacheValidName(validAttributeNameCache, validAttributeNameCacheMax, name);
return true;
} else {
return false;
}
}
}
cacheValidName(validAttributeNameCache, validAttributeNameCacheMax, name);
return true;
};
const invalidStylePropertyNameCharRe = /[\s"'():;\\/\[\]{}\x00-\x1f\x7f-\x9f]/;
const validStylePropertyNameCache = /* @__PURE__ */ new Set();
const validStylePropertyNameCacheMax = 1024;
const isValidStylePropertyName = (name) => {
if (validStylePropertyNameCache.has(name)) {
return true;
}
const len = name.length;
if (len === 0) {
return false;
}
for (let i = 0; i < len; i++) {
const c = name.charCodeAt(i);
if (!(c >= 97 && c <= 122 || // a-z
c >= 65 && c <= 90 || // A-Z
c >= 48 && c <= 57 || // 0-9
c === 45 || // -
c === 95)) {
if (!invalidStylePropertyNameCharRe.test(name)) {
cacheValidName(validStylePropertyNameCache, validStylePropertyNameCacheMax, name);
return true;
} else {
return false;
}
}
}
cacheValidName(validStylePropertyNameCache, validStylePropertyNameCacheMax, name);
return true;
};
const unsafeStyleValueCharRe = /[;"'\\/\[\](){}]/;
const hasUnsafeStyleValue = (value) => {
if (!unsafeStyleValueCharRe.test(value)) {
return false;
}
let quote = 0;
const blockStack = [];
for (let i = 0, len = value.length; i < len; i++) {
const c = value.charCodeAt(i);
if (c === 92) {
if (i === len - 1) {
return true;
}
i++;
} else if (quote !== 0) {
if (c === 10 || c === 12 || c === 13) {
return true;
}
if (c === quote) {
quote = 0;
}
} else if (c === 47 && value.charCodeAt(i + 1) === 42) {
const end = value.indexOf("*/", i + 2);
if (end === -1) {
return true;
}
i = end + 1;
} else if (c === 34 || c === 39) {
quote = c;
} else if (c === 40) {
blockStack.push(41);
} else if (c === 91) {
blockStack.push(93);
} else if (c === 123 || c === 125) {
return true;
} else if (c === 41 || c === 93) {
if (blockStack[blockStack.length - 1] !== c) {
return true;
}
blockStack.pop();
} else if (c === 59 && blockStack.length === 0) {
return true;
}
}
return quote !== 0 || blockStack.length !== 0;
};
const styleObjectForEach = (style, fn) => {
for (const [k, v] of Object.entries(style)) {
const key = k[0] === "-" || !/[A-Z]/.test(k) ? k : k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
fn(
key,
v == null ? null : typeof v === "number" ? !key.match(
if (!isValidStylePropertyName(key)) {
continue;
}
if (v == null) {
fn(key, null);
continue;
}
let value;
if (typeof v === "number") {
value = !key.match(
/^(?:a|border-im|column(?:-c|s)|flex(?:$|-[^b])|grid-(?:ar|[^a])|font-w|li|or|sca|st|ta|wido|z)|ty$/
) ? `${v}px` : `${v}` : v
);
) ? `${v}px` : `${v}`;
} else if (typeof v === "string") {
if (hasUnsafeStyleValue(v)) {
continue;
}
value = v;
} else {
continue;
}
fn(key, value);
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
isValidAttributeName,
isValidTagName,
normalizeIntrinsicElementKey,
styleObjectForEach
});