Erster Docker-Stand
This commit is contained in:
331
_node_modules/hono/dist/jsx/base.js
generated
vendored
Normal file
331
_node_modules/hono/dist/jsx/base.js
generated
vendored
Normal file
@@ -0,0 +1,331 @@
|
||||
// src/jsx/base.ts
|
||||
import { raw } from "../helper/html/index.js";
|
||||
import { escapeToBuffer, resolveCallbackSync, stringBufferToString } from "../utils/html.js";
|
||||
import { DOM_RENDERER, DOM_MEMO } from "./constants.js";
|
||||
import { createContext, globalContexts, useContext } from "./context.js";
|
||||
import { domRenderers } from "./intrinsic-element/common.js";
|
||||
import * as intrinsicElementTags from "./intrinsic-element/components.js";
|
||||
import { normalizeIntrinsicElementKey, styleObjectForEach } from "./utils.js";
|
||||
var nameSpaceContext = void 0;
|
||||
var getNameSpaceContext = () => nameSpaceContext;
|
||||
var toSVGAttributeName = (key) => /[A-Z]/.test(key) && // Presentation attributes are findable in style object. "clip-path", "font-size", "stroke-width", etc.
|
||||
// Or other un-deprecated kebab-case attributes. "overline-position", "paint-order", "strikethrough-position", etc.
|
||||
key.match(
|
||||
/^(?:al|basel|clip(?:Path|Rule)$|co|do|fill|fl|fo|gl|let|lig|i|marker[EMS]|o|pai|pointe|sh|st[or]|text[^L]|tr|u|ve|w)/
|
||||
) ? key.replace(/([A-Z])/g, "-$1").toLowerCase() : key;
|
||||
var emptyTags = [
|
||||
"area",
|
||||
"base",
|
||||
"br",
|
||||
"col",
|
||||
"embed",
|
||||
"hr",
|
||||
"img",
|
||||
"input",
|
||||
"keygen",
|
||||
"link",
|
||||
"meta",
|
||||
"param",
|
||||
"source",
|
||||
"track",
|
||||
"wbr"
|
||||
];
|
||||
var booleanAttributes = [
|
||||
"allowfullscreen",
|
||||
"async",
|
||||
"autofocus",
|
||||
"autoplay",
|
||||
"checked",
|
||||
"controls",
|
||||
"default",
|
||||
"defer",
|
||||
"disabled",
|
||||
"download",
|
||||
"formnovalidate",
|
||||
"hidden",
|
||||
"inert",
|
||||
"ismap",
|
||||
"itemscope",
|
||||
"loop",
|
||||
"multiple",
|
||||
"muted",
|
||||
"nomodule",
|
||||
"novalidate",
|
||||
"open",
|
||||
"playsinline",
|
||||
"readonly",
|
||||
"required",
|
||||
"reversed",
|
||||
"selected"
|
||||
];
|
||||
var childrenToStringToBuffer = (children, buffer) => {
|
||||
for (let i = 0, len = children.length; i < len; i++) {
|
||||
const child = children[i];
|
||||
if (typeof child === "string") {
|
||||
escapeToBuffer(child, buffer);
|
||||
} else if (typeof child === "boolean" || child === null || child === void 0) {
|
||||
continue;
|
||||
} else if (child instanceof JSXNode) {
|
||||
child.toStringToBuffer(buffer);
|
||||
} else if (typeof child === "number" || child.isEscaped) {
|
||||
;
|
||||
buffer[0] += child;
|
||||
} else if (child instanceof Promise) {
|
||||
buffer.unshift("", child);
|
||||
} else {
|
||||
childrenToStringToBuffer(child, buffer);
|
||||
}
|
||||
}
|
||||
};
|
||||
var JSXNode = class {
|
||||
tag;
|
||||
props;
|
||||
key;
|
||||
children;
|
||||
isEscaped = true;
|
||||
localContexts;
|
||||
constructor(tag, props, children) {
|
||||
this.tag = tag;
|
||||
this.props = props;
|
||||
this.children = children;
|
||||
}
|
||||
get type() {
|
||||
return this.tag;
|
||||
}
|
||||
// Added for compatibility with libraries that rely on React's internal structure
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
get ref() {
|
||||
return this.props.ref || null;
|
||||
}
|
||||
toString() {
|
||||
const buffer = [""];
|
||||
this.localContexts?.forEach(([context, value]) => {
|
||||
context.values.push(value);
|
||||
});
|
||||
try {
|
||||
this.toStringToBuffer(buffer);
|
||||
} finally {
|
||||
this.localContexts?.forEach(([context]) => {
|
||||
context.values.pop();
|
||||
});
|
||||
}
|
||||
return buffer.length === 1 ? "callbacks" in buffer ? resolveCallbackSync(raw(buffer[0], buffer.callbacks)).toString() : buffer[0] : stringBufferToString(buffer, buffer.callbacks);
|
||||
}
|
||||
toStringToBuffer(buffer) {
|
||||
const tag = this.tag;
|
||||
const props = this.props;
|
||||
let { children } = this;
|
||||
buffer[0] += `<${tag}`;
|
||||
const normalizeKey = nameSpaceContext && useContext(nameSpaceContext) === "svg" ? (key) => toSVGAttributeName(normalizeIntrinsicElementKey(key)) : (key) => normalizeIntrinsicElementKey(key);
|
||||
for (let [key, v] of Object.entries(props)) {
|
||||
key = normalizeKey(key);
|
||||
if (key === "children") {
|
||||
} else if (key === "style" && typeof v === "object") {
|
||||
let styleStr = "";
|
||||
styleObjectForEach(v, (property, value) => {
|
||||
if (value != null) {
|
||||
styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
||||
}
|
||||
});
|
||||
buffer[0] += ' style="';
|
||||
escapeToBuffer(styleStr, buffer);
|
||||
buffer[0] += '"';
|
||||
} else if (typeof v === "string") {
|
||||
buffer[0] += ` ${key}="`;
|
||||
escapeToBuffer(v, buffer);
|
||||
buffer[0] += '"';
|
||||
} else if (v === null || v === void 0) {
|
||||
} else if (typeof v === "number" || v.isEscaped) {
|
||||
buffer[0] += ` ${key}="${v}"`;
|
||||
} else if (typeof v === "boolean" && booleanAttributes.includes(key)) {
|
||||
if (v) {
|
||||
buffer[0] += ` ${key}=""`;
|
||||
}
|
||||
} else if (key === "dangerouslySetInnerHTML") {
|
||||
if (children.length > 0) {
|
||||
throw new Error("Can only set one of `children` or `props.dangerouslySetInnerHTML`.");
|
||||
}
|
||||
children = [raw(v.__html)];
|
||||
} else if (v instanceof Promise) {
|
||||
buffer[0] += ` ${key}="`;
|
||||
buffer.unshift('"', v);
|
||||
} else if (typeof v === "function") {
|
||||
if (!key.startsWith("on") && key !== "ref") {
|
||||
throw new Error(`Invalid prop '${key}' of type 'function' supplied to '${tag}'.`);
|
||||
}
|
||||
} else {
|
||||
buffer[0] += ` ${key}="`;
|
||||
escapeToBuffer(v.toString(), buffer);
|
||||
buffer[0] += '"';
|
||||
}
|
||||
}
|
||||
if (emptyTags.includes(tag) && children.length === 0) {
|
||||
buffer[0] += "/>";
|
||||
return;
|
||||
}
|
||||
buffer[0] += ">";
|
||||
childrenToStringToBuffer(children, buffer);
|
||||
buffer[0] += `</${tag}>`;
|
||||
}
|
||||
};
|
||||
var JSXFunctionNode = class extends JSXNode {
|
||||
toStringToBuffer(buffer) {
|
||||
const { children } = this;
|
||||
const props = { ...this.props };
|
||||
if (children.length) {
|
||||
props.children = children.length === 1 ? children[0] : children;
|
||||
}
|
||||
const res = this.tag.call(null, props);
|
||||
if (typeof res === "boolean" || res == null) {
|
||||
return;
|
||||
} else if (res instanceof Promise) {
|
||||
if (globalContexts.length === 0) {
|
||||
buffer.unshift("", res);
|
||||
} else {
|
||||
const currentContexts = globalContexts.map((c) => [c, c.values.at(-1)]);
|
||||
buffer.unshift(
|
||||
"",
|
||||
res.then((childRes) => {
|
||||
if (childRes instanceof JSXNode) {
|
||||
childRes.localContexts = currentContexts;
|
||||
}
|
||||
return childRes;
|
||||
})
|
||||
);
|
||||
}
|
||||
} else if (res instanceof JSXNode) {
|
||||
res.toStringToBuffer(buffer);
|
||||
} else if (typeof res === "number" || res.isEscaped) {
|
||||
buffer[0] += res;
|
||||
if (res.callbacks) {
|
||||
buffer.callbacks ||= [];
|
||||
buffer.callbacks.push(...res.callbacks);
|
||||
}
|
||||
} else {
|
||||
escapeToBuffer(res, buffer);
|
||||
}
|
||||
}
|
||||
};
|
||||
var JSXFragmentNode = class extends JSXNode {
|
||||
toStringToBuffer(buffer) {
|
||||
childrenToStringToBuffer(this.children, buffer);
|
||||
}
|
||||
};
|
||||
var jsx = (tag, props, ...children) => {
|
||||
props ??= {};
|
||||
if (children.length) {
|
||||
props.children = children.length === 1 ? children[0] : children;
|
||||
}
|
||||
const key = props.key;
|
||||
delete props["key"];
|
||||
const node = jsxFn(tag, props, children);
|
||||
node.key = key;
|
||||
return node;
|
||||
};
|
||||
var initDomRenderer = false;
|
||||
var jsxFn = (tag, props, children) => {
|
||||
if (!initDomRenderer) {
|
||||
for (const k in domRenderers) {
|
||||
;
|
||||
intrinsicElementTags[k][DOM_RENDERER] = domRenderers[k];
|
||||
}
|
||||
initDomRenderer = true;
|
||||
}
|
||||
if (typeof tag === "function") {
|
||||
return new JSXFunctionNode(tag, props, children);
|
||||
} else if (intrinsicElementTags[tag]) {
|
||||
return new JSXFunctionNode(
|
||||
intrinsicElementTags[tag],
|
||||
props,
|
||||
children
|
||||
);
|
||||
} else if (tag === "svg" || tag === "head") {
|
||||
nameSpaceContext ||= createContext("");
|
||||
return new JSXNode(tag, props, [
|
||||
new JSXFunctionNode(
|
||||
nameSpaceContext,
|
||||
{
|
||||
value: tag
|
||||
},
|
||||
children
|
||||
)
|
||||
]);
|
||||
} else {
|
||||
return new JSXNode(tag, props, children);
|
||||
}
|
||||
};
|
||||
var shallowEqual = (a, b) => {
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
const aKeys = Object.keys(a).sort();
|
||||
const bKeys = Object.keys(b).sort();
|
||||
if (aKeys.length !== bKeys.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0, len = aKeys.length; i < len; i++) {
|
||||
if (aKeys[i] === "children" && bKeys[i] === "children" && !a.children?.length && !b.children?.length) {
|
||||
continue;
|
||||
} else if (a[aKeys[i]] !== b[aKeys[i]]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
var memo = (component, propsAreEqual = shallowEqual) => {
|
||||
let computed = null;
|
||||
let prevProps = void 0;
|
||||
const wrapper = ((props) => {
|
||||
if (prevProps && !propsAreEqual(prevProps, props)) {
|
||||
computed = null;
|
||||
}
|
||||
prevProps = props;
|
||||
return computed ||= component(props);
|
||||
});
|
||||
wrapper[DOM_MEMO] = propsAreEqual;
|
||||
wrapper[DOM_RENDERER] = component;
|
||||
return wrapper;
|
||||
};
|
||||
var Fragment = ({
|
||||
children
|
||||
}) => {
|
||||
return new JSXFragmentNode(
|
||||
"",
|
||||
{
|
||||
children
|
||||
},
|
||||
Array.isArray(children) ? children : children ? [children] : []
|
||||
);
|
||||
};
|
||||
var isValidElement = (element) => {
|
||||
return !!(element && typeof element === "object" && "tag" in element && "props" in element);
|
||||
};
|
||||
var cloneElement = (element, props, ...children) => {
|
||||
let childrenToClone;
|
||||
if (children.length > 0) {
|
||||
childrenToClone = children;
|
||||
} else {
|
||||
const c = element.props.children;
|
||||
childrenToClone = Array.isArray(c) ? c : [c];
|
||||
}
|
||||
return jsx(
|
||||
element.tag,
|
||||
{ ...element.props, ...props },
|
||||
...childrenToClone
|
||||
);
|
||||
};
|
||||
var reactAPICompatVersion = "19.0.0-hono-jsx";
|
||||
export {
|
||||
Fragment,
|
||||
JSXFragmentNode,
|
||||
JSXNode,
|
||||
booleanAttributes,
|
||||
cloneElement,
|
||||
getNameSpaceContext,
|
||||
isValidElement,
|
||||
jsx,
|
||||
jsxFn,
|
||||
memo,
|
||||
reactAPICompatVersion,
|
||||
shallowEqual
|
||||
};
|
||||
21
_node_modules/hono/dist/jsx/children.js
generated
vendored
Normal file
21
_node_modules/hono/dist/jsx/children.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
// src/jsx/children.ts
|
||||
var toArray = (children) => Array.isArray(children) ? children : [children];
|
||||
var Children = {
|
||||
map: (children, fn) => toArray(children).map(fn),
|
||||
forEach: (children, fn) => {
|
||||
toArray(children).forEach(fn);
|
||||
},
|
||||
count: (children) => toArray(children).length,
|
||||
only: (_children) => {
|
||||
const children = toArray(_children);
|
||||
if (children.length !== 1) {
|
||||
throw new Error("Children.only() expects only one child");
|
||||
}
|
||||
return children[0];
|
||||
},
|
||||
toArray
|
||||
};
|
||||
export {
|
||||
Children,
|
||||
toArray
|
||||
};
|
||||
152
_node_modules/hono/dist/jsx/components.js
generated
vendored
Normal file
152
_node_modules/hono/dist/jsx/components.js
generated
vendored
Normal file
@@ -0,0 +1,152 @@
|
||||
// src/jsx/components.ts
|
||||
import { raw } from "../helper/html/index.js";
|
||||
import { HtmlEscapedCallbackPhase, resolveCallback } from "../utils/html.js";
|
||||
import { DOM_RENDERER } from "./constants.js";
|
||||
import { useContext } from "./context.js";
|
||||
import { ErrorBoundary as ErrorBoundaryDomRenderer } from "./dom/components.js";
|
||||
import { StreamingContext } from "./streaming.js";
|
||||
var errorBoundaryCounter = 0;
|
||||
var childrenToString = async (children) => {
|
||||
try {
|
||||
return children.flat().map((c) => c == null || typeof c === "boolean" ? "" : c.toString());
|
||||
} catch (e) {
|
||||
if (e instanceof Promise) {
|
||||
await e;
|
||||
return childrenToString(children);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
var ErrorBoundary = async ({ children, fallback, fallbackRender, onError }) => {
|
||||
if (!children) {
|
||||
return raw("");
|
||||
}
|
||||
if (!Array.isArray(children)) {
|
||||
children = [children];
|
||||
}
|
||||
const nonce = useContext(StreamingContext)?.scriptNonce;
|
||||
let fallbackStr;
|
||||
const fallbackRes = (error) => {
|
||||
onError?.(error);
|
||||
return (fallbackStr || fallbackRender?.(error) || "").toString();
|
||||
};
|
||||
let resArray = [];
|
||||
try {
|
||||
resArray = children.map(
|
||||
(c) => c == null || typeof c === "boolean" ? "" : c.toString()
|
||||
);
|
||||
} catch (e) {
|
||||
fallbackStr = await fallback?.toString();
|
||||
if (e instanceof Promise) {
|
||||
resArray = [
|
||||
e.then(() => childrenToString(children)).catch((e2) => fallbackRes(e2))
|
||||
];
|
||||
} else {
|
||||
resArray = [fallbackRes(e)];
|
||||
}
|
||||
}
|
||||
if (resArray.some((res) => res instanceof Promise)) {
|
||||
fallbackStr ||= await fallback?.toString();
|
||||
const index = errorBoundaryCounter++;
|
||||
const replaceRe = RegExp(`(<template id="E:${index}"></template>.*?)(.*?)(<!--E:${index}-->)`);
|
||||
const caught = false;
|
||||
const catchCallback = ({ error: error2, buffer }) => {
|
||||
if (caught) {
|
||||
return "";
|
||||
}
|
||||
const fallbackResString = fallbackRes(error2);
|
||||
if (buffer) {
|
||||
buffer[0] = buffer[0].replace(replaceRe, fallbackResString);
|
||||
}
|
||||
return buffer ? "" : `<template data-hono-target="E:${index}">${fallbackResString}</template><script>
|
||||
((d,c,n) => {
|
||||
c=d.currentScript.previousSibling
|
||||
d=d.getElementById('E:${index}')
|
||||
if(!d)return
|
||||
do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='E:${index}')
|
||||
d.replaceWith(c.content)
|
||||
})(document)
|
||||
</script>`;
|
||||
};
|
||||
let error;
|
||||
const promiseAll = Promise.all(resArray).catch((e) => error = e);
|
||||
return raw(`<template id="E:${index}"></template><!--E:${index}-->`, [
|
||||
({ phase, buffer, context }) => {
|
||||
if (phase === HtmlEscapedCallbackPhase.BeforeStream) {
|
||||
return;
|
||||
}
|
||||
return promiseAll.then(async (htmlArray) => {
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
htmlArray = htmlArray.flat();
|
||||
const content = htmlArray.join("");
|
||||
let html = buffer ? "" : `<template data-hono-target="E:${index}">${content}</template><script${nonce ? ` nonce="${nonce}"` : ""}>
|
||||
((d,c) => {
|
||||
c=d.currentScript.previousSibling
|
||||
d=d.getElementById('E:${index}')
|
||||
if(!d)return
|
||||
d.parentElement.insertBefore(c.content,d.nextSibling)
|
||||
})(document)
|
||||
</script>`;
|
||||
if (htmlArray.every((html2) => !html2.callbacks?.length)) {
|
||||
if (buffer) {
|
||||
buffer[0] = buffer[0].replace(replaceRe, content);
|
||||
}
|
||||
return html;
|
||||
}
|
||||
if (buffer) {
|
||||
buffer[0] = buffer[0].replace(
|
||||
replaceRe,
|
||||
(_all, pre, _, post) => `${pre}${content}${post}`
|
||||
);
|
||||
}
|
||||
const callbacks = htmlArray.map((html2) => html2.callbacks || []).flat();
|
||||
if (phase === HtmlEscapedCallbackPhase.Stream) {
|
||||
html = await resolveCallback(
|
||||
html,
|
||||
HtmlEscapedCallbackPhase.BeforeStream,
|
||||
true,
|
||||
context
|
||||
);
|
||||
}
|
||||
let resolvedCount = 0;
|
||||
const promises = callbacks.map(
|
||||
(c) => (...args) => c(...args)?.then((content2) => {
|
||||
resolvedCount++;
|
||||
if (buffer) {
|
||||
if (resolvedCount === callbacks.length) {
|
||||
buffer[0] = buffer[0].replace(replaceRe, (_all, _pre, content3) => content3);
|
||||
}
|
||||
buffer[0] += content2;
|
||||
return raw("", content2.callbacks);
|
||||
}
|
||||
return raw(
|
||||
content2 + (resolvedCount !== callbacks.length ? "" : `<script>
|
||||
((d,c,n) => {
|
||||
d=d.getElementById('E:${index}')
|
||||
if(!d)return
|
||||
n=d.nextSibling
|
||||
while(n.nodeType!=8||n.nodeValue!='E:${index}'){n=n.nextSibling}
|
||||
n.remove()
|
||||
d.remove()
|
||||
})(document)
|
||||
</script>`),
|
||||
content2.callbacks
|
||||
);
|
||||
}).catch((error2) => catchCallback({ error: error2, buffer }))
|
||||
);
|
||||
return raw(html, promises);
|
||||
}).catch((error2) => catchCallback({ error: error2, buffer }));
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
return raw(resArray.join(""));
|
||||
}
|
||||
};
|
||||
ErrorBoundary[DOM_RENDERER] = ErrorBoundaryDomRenderer;
|
||||
export {
|
||||
ErrorBoundary,
|
||||
childrenToString
|
||||
};
|
||||
15
_node_modules/hono/dist/jsx/constants.js
generated
vendored
Normal file
15
_node_modules/hono/dist/jsx/constants.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// src/jsx/constants.ts
|
||||
var DOM_RENDERER = /* @__PURE__ */ Symbol("RENDERER");
|
||||
var DOM_ERROR_HANDLER = /* @__PURE__ */ Symbol("ERROR_HANDLER");
|
||||
var DOM_STASH = /* @__PURE__ */ Symbol("STASH");
|
||||
var DOM_INTERNAL_TAG = /* @__PURE__ */ Symbol("INTERNAL");
|
||||
var DOM_MEMO = /* @__PURE__ */ Symbol("MEMO");
|
||||
var PERMALINK = /* @__PURE__ */ Symbol("PERMALINK");
|
||||
export {
|
||||
DOM_ERROR_HANDLER,
|
||||
DOM_INTERNAL_TAG,
|
||||
DOM_MEMO,
|
||||
DOM_RENDERER,
|
||||
DOM_STASH,
|
||||
PERMALINK
|
||||
};
|
||||
36
_node_modules/hono/dist/jsx/context.js
generated
vendored
Normal file
36
_node_modules/hono/dist/jsx/context.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
// src/jsx/context.ts
|
||||
import { raw } from "../helper/html/index.js";
|
||||
import { JSXFragmentNode } from "./base.js";
|
||||
import { DOM_RENDERER } from "./constants.js";
|
||||
import { createContextProviderFunction } from "./dom/context.js";
|
||||
var globalContexts = [];
|
||||
var createContext = (defaultValue) => {
|
||||
const values = [defaultValue];
|
||||
const context = ((props) => {
|
||||
values.push(props.value);
|
||||
let string;
|
||||
try {
|
||||
string = props.children ? (Array.isArray(props.children) ? new JSXFragmentNode("", {}, props.children) : props.children).toString() : "";
|
||||
} finally {
|
||||
values.pop();
|
||||
}
|
||||
if (string instanceof Promise) {
|
||||
return string.then((resString) => raw(resString, resString.callbacks));
|
||||
} else {
|
||||
return raw(string);
|
||||
}
|
||||
});
|
||||
context.values = values;
|
||||
context.Provider = context;
|
||||
context[DOM_RENDERER] = createContextProviderFunction(values);
|
||||
globalContexts.push(context);
|
||||
return context;
|
||||
};
|
||||
var useContext = (context) => {
|
||||
return context.values.at(-1);
|
||||
};
|
||||
export {
|
||||
createContext,
|
||||
globalContexts,
|
||||
useContext
|
||||
};
|
||||
53
_node_modules/hono/dist/jsx/dom/client.js
generated
vendored
Normal file
53
_node_modules/hono/dist/jsx/dom/client.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
// src/jsx/dom/client.ts
|
||||
import { useState } from "../hooks/index.js";
|
||||
import { buildNode, renderNode } from "./render.js";
|
||||
var createRoot = (element, options = {}) => {
|
||||
let setJsxNode = (
|
||||
// unmounted
|
||||
void 0
|
||||
);
|
||||
if (Object.keys(options).length > 0) {
|
||||
console.warn("createRoot options are not supported yet");
|
||||
}
|
||||
return {
|
||||
render(jsxNode) {
|
||||
if (setJsxNode === null) {
|
||||
throw new Error("Cannot update an unmounted root");
|
||||
}
|
||||
if (setJsxNode) {
|
||||
setJsxNode(jsxNode);
|
||||
} else {
|
||||
renderNode(
|
||||
buildNode({
|
||||
tag: () => {
|
||||
const [_jsxNode, _setJsxNode] = useState(jsxNode);
|
||||
setJsxNode = _setJsxNode;
|
||||
return _jsxNode;
|
||||
},
|
||||
props: {}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
}),
|
||||
element
|
||||
);
|
||||
}
|
||||
},
|
||||
unmount() {
|
||||
setJsxNode?.(null);
|
||||
setJsxNode = null;
|
||||
}
|
||||
};
|
||||
};
|
||||
var hydrateRoot = (element, reactNode, options = {}) => {
|
||||
const root = createRoot(element, options);
|
||||
root.render(reactNode);
|
||||
return root;
|
||||
};
|
||||
var client_default = {
|
||||
createRoot,
|
||||
hydrateRoot
|
||||
};
|
||||
export {
|
||||
createRoot,
|
||||
client_default as default,
|
||||
hydrateRoot
|
||||
};
|
||||
32
_node_modules/hono/dist/jsx/dom/components.js
generated
vendored
Normal file
32
_node_modules/hono/dist/jsx/dom/components.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
// src/jsx/dom/components.ts
|
||||
import { DOM_ERROR_HANDLER } from "../constants.js";
|
||||
import { Fragment } from "./jsx-runtime.js";
|
||||
var ErrorBoundary = (({ children, fallback, fallbackRender, onError }) => {
|
||||
const res = Fragment({ children });
|
||||
res[DOM_ERROR_HANDLER] = (err) => {
|
||||
if (err instanceof Promise) {
|
||||
throw err;
|
||||
}
|
||||
onError?.(err);
|
||||
return fallbackRender?.(err) || fallback;
|
||||
};
|
||||
return res;
|
||||
});
|
||||
var Suspense = (({
|
||||
children,
|
||||
fallback
|
||||
}) => {
|
||||
const res = Fragment({ children });
|
||||
res[DOM_ERROR_HANDLER] = (err, retry) => {
|
||||
if (!(err instanceof Promise)) {
|
||||
throw err;
|
||||
}
|
||||
err.finally(retry);
|
||||
return fallback;
|
||||
};
|
||||
return res;
|
||||
});
|
||||
export {
|
||||
ErrorBoundary,
|
||||
Suspense
|
||||
};
|
||||
48
_node_modules/hono/dist/jsx/dom/context.js
generated
vendored
Normal file
48
_node_modules/hono/dist/jsx/dom/context.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
// src/jsx/dom/context.ts
|
||||
import { DOM_ERROR_HANDLER } from "../constants.js";
|
||||
import { globalContexts } from "../context.js";
|
||||
import { setInternalTagFlag } from "./utils.js";
|
||||
var createContextProviderFunction = (values) => ({ value, children }) => {
|
||||
if (!children) {
|
||||
return void 0;
|
||||
}
|
||||
const props = {
|
||||
children: [
|
||||
{
|
||||
tag: setInternalTagFlag(() => {
|
||||
values.push(value);
|
||||
}),
|
||||
props: {}
|
||||
}
|
||||
]
|
||||
};
|
||||
if (Array.isArray(children)) {
|
||||
props.children.push(...children.flat());
|
||||
} else {
|
||||
props.children.push(children);
|
||||
}
|
||||
props.children.push({
|
||||
tag: setInternalTagFlag(() => {
|
||||
values.pop();
|
||||
}),
|
||||
props: {}
|
||||
});
|
||||
const res = { tag: "", props, type: "" };
|
||||
res[DOM_ERROR_HANDLER] = (err) => {
|
||||
values.pop();
|
||||
throw err;
|
||||
};
|
||||
return res;
|
||||
};
|
||||
var createContext = (defaultValue) => {
|
||||
const values = [defaultValue];
|
||||
const context = createContextProviderFunction(values);
|
||||
context.values = values;
|
||||
context.Provider = context;
|
||||
globalContexts.push(context);
|
||||
return context;
|
||||
};
|
||||
export {
|
||||
createContext,
|
||||
createContextProviderFunction
|
||||
};
|
||||
143
_node_modules/hono/dist/jsx/dom/css.js
generated
vendored
Normal file
143
_node_modules/hono/dist/jsx/dom/css.js
generated
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
// src/jsx/dom/css.ts
|
||||
import {
|
||||
CLASS_NAME,
|
||||
DEFAULT_STYLE_ID,
|
||||
PSEUDO_GLOBAL_SELECTOR,
|
||||
SELECTOR,
|
||||
SELECTORS,
|
||||
STYLE_STRING,
|
||||
cssCommon,
|
||||
cxCommon,
|
||||
keyframesCommon,
|
||||
viewTransitionCommon
|
||||
} from "../../helper/css/common.js";
|
||||
import { rawCssString } from "../../helper/css/common.js";
|
||||
var splitRule = (rule) => {
|
||||
const result = [];
|
||||
let startPos = 0;
|
||||
let depth = 0;
|
||||
for (let i = 0, len = rule.length; i < len; i++) {
|
||||
const char = rule[i];
|
||||
if (char === "'" || char === '"') {
|
||||
const quote = char;
|
||||
i++;
|
||||
for (; i < len; i++) {
|
||||
if (rule[i] === "\\") {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
if (rule[i] === quote) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (char === "{") {
|
||||
depth++;
|
||||
continue;
|
||||
}
|
||||
if (char === "}") {
|
||||
depth--;
|
||||
if (depth === 0) {
|
||||
result.push(rule.slice(startPos, i + 1));
|
||||
startPos = i + 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
var createCssJsxDomObjects = ({ id }) => {
|
||||
let styleSheet = void 0;
|
||||
const findStyleSheet = () => {
|
||||
if (!styleSheet) {
|
||||
styleSheet = document.querySelector(`style#${id}`)?.sheet;
|
||||
if (styleSheet) {
|
||||
;
|
||||
styleSheet.addedStyles = /* @__PURE__ */ new Set();
|
||||
}
|
||||
}
|
||||
return styleSheet ? [styleSheet, styleSheet.addedStyles] : [];
|
||||
};
|
||||
const insertRule = (className, styleString) => {
|
||||
const [sheet, addedStyles] = findStyleSheet();
|
||||
if (!sheet || !addedStyles) {
|
||||
Promise.resolve().then(() => {
|
||||
if (!findStyleSheet()[0]) {
|
||||
throw new Error("style sheet not found");
|
||||
}
|
||||
insertRule(className, styleString);
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (!addedStyles.has(className)) {
|
||||
addedStyles.add(className);
|
||||
(className.startsWith(PSEUDO_GLOBAL_SELECTOR) ? splitRule(styleString) : [`${className[0] === "@" ? "" : "."}${className}{${styleString}}`]).forEach((rule) => {
|
||||
sheet.insertRule(rule, sheet.cssRules.length);
|
||||
});
|
||||
}
|
||||
};
|
||||
const cssObject = {
|
||||
toString() {
|
||||
const selector = this[SELECTOR];
|
||||
insertRule(selector, this[STYLE_STRING]);
|
||||
this[SELECTORS].forEach(({ [CLASS_NAME]: className, [STYLE_STRING]: styleString }) => {
|
||||
insertRule(className, styleString);
|
||||
});
|
||||
return this[CLASS_NAME];
|
||||
}
|
||||
};
|
||||
const Style2 = ({ children, nonce }) => ({
|
||||
tag: "style",
|
||||
props: {
|
||||
id,
|
||||
nonce,
|
||||
children: children && (Array.isArray(children) ? children : [children]).map(
|
||||
(c) => c[STYLE_STRING]
|
||||
)
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
});
|
||||
return [cssObject, Style2];
|
||||
};
|
||||
var createCssContext = ({ id }) => {
|
||||
const [cssObject, Style2] = createCssJsxDomObjects({ id });
|
||||
const newCssClassNameObject = (cssClassName) => {
|
||||
cssClassName.toString = cssObject.toString;
|
||||
return cssClassName;
|
||||
};
|
||||
const css2 = (strings, ...values) => {
|
||||
return newCssClassNameObject(cssCommon(strings, values));
|
||||
};
|
||||
const cx2 = (...args) => {
|
||||
args = cxCommon(args);
|
||||
return css2(Array(args.length).fill(""), ...args);
|
||||
};
|
||||
const keyframes2 = keyframesCommon;
|
||||
const viewTransition2 = ((strings, ...values) => {
|
||||
return newCssClassNameObject(viewTransitionCommon(strings, values));
|
||||
});
|
||||
return {
|
||||
css: css2,
|
||||
cx: cx2,
|
||||
keyframes: keyframes2,
|
||||
viewTransition: viewTransition2,
|
||||
Style: Style2
|
||||
};
|
||||
};
|
||||
var defaultContext = createCssContext({ id: DEFAULT_STYLE_ID });
|
||||
var css = defaultContext.css;
|
||||
var cx = defaultContext.cx;
|
||||
var keyframes = defaultContext.keyframes;
|
||||
var viewTransition = defaultContext.viewTransition;
|
||||
var Style = defaultContext.Style;
|
||||
export {
|
||||
Style,
|
||||
createCssContext,
|
||||
createCssJsxDomObjects,
|
||||
css,
|
||||
cx,
|
||||
keyframes,
|
||||
rawCssString,
|
||||
viewTransition
|
||||
};
|
||||
48
_node_modules/hono/dist/jsx/dom/hooks/index.js
generated
vendored
Normal file
48
_node_modules/hono/dist/jsx/dom/hooks/index.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
// src/jsx/dom/hooks/index.ts
|
||||
import { PERMALINK } from "../../constants.js";
|
||||
import { useContext } from "../../context.js";
|
||||
import { useCallback, useState } from "../../hooks/index.js";
|
||||
import { createContext } from "../context.js";
|
||||
var FormContext = createContext({
|
||||
pending: false,
|
||||
data: null,
|
||||
method: null,
|
||||
action: null
|
||||
});
|
||||
var actions = /* @__PURE__ */ new Set();
|
||||
var registerAction = (action) => {
|
||||
actions.add(action);
|
||||
action.finally(() => actions.delete(action));
|
||||
};
|
||||
var useFormStatus = () => {
|
||||
return useContext(FormContext);
|
||||
};
|
||||
var useOptimistic = (state, updateState) => {
|
||||
const [optimisticState, setOptimisticState] = useState(state);
|
||||
if (actions.size > 0) {
|
||||
Promise.all(actions).finally(() => {
|
||||
setOptimisticState(state);
|
||||
});
|
||||
} else {
|
||||
setOptimisticState(state);
|
||||
}
|
||||
const cb = useCallback((newData) => {
|
||||
setOptimisticState((currentState) => updateState(currentState, newData));
|
||||
}, []);
|
||||
return [optimisticState, cb];
|
||||
};
|
||||
var useActionState = (fn, initialState, permalink) => {
|
||||
const [state, setState] = useState(initialState);
|
||||
const actionState = async (data) => {
|
||||
setState(await fn(state, data));
|
||||
};
|
||||
actionState[PERMALINK] = permalink;
|
||||
return [state, actionState];
|
||||
};
|
||||
export {
|
||||
FormContext,
|
||||
registerAction,
|
||||
useActionState,
|
||||
useFormStatus,
|
||||
useOptimistic
|
||||
};
|
||||
142
_node_modules/hono/dist/jsx/dom/index.js
generated
vendored
Normal file
142
_node_modules/hono/dist/jsx/dom/index.js
generated
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
// src/jsx/dom/index.ts
|
||||
import { isValidElement, reactAPICompatVersion, shallowEqual } from "../base.js";
|
||||
import { Children } from "../children.js";
|
||||
import { DOM_MEMO } from "../constants.js";
|
||||
import { useContext } from "../context.js";
|
||||
import {
|
||||
createRef,
|
||||
forwardRef,
|
||||
startTransition,
|
||||
startViewTransition,
|
||||
use,
|
||||
useCallback,
|
||||
useDebugValue,
|
||||
useDeferredValue,
|
||||
useEffect,
|
||||
useId,
|
||||
useImperativeHandle,
|
||||
useInsertionEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useReducer,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
useTransition,
|
||||
useViewTransition
|
||||
} from "../hooks/index.js";
|
||||
import { ErrorBoundary, Suspense } from "./components.js";
|
||||
import { createContext } from "./context.js";
|
||||
import { useActionState, useFormStatus, useOptimistic } from "./hooks/index.js";
|
||||
import { Fragment, jsx } from "./jsx-runtime.js";
|
||||
import { createPortal, flushSync } from "./render.js";
|
||||
import { render } from "./render.js";
|
||||
var createElement = (tag, props, ...children) => {
|
||||
const jsxProps = props ? { ...props } : {};
|
||||
if (children.length) {
|
||||
jsxProps.children = children.length === 1 ? children[0] : children;
|
||||
}
|
||||
let key = void 0;
|
||||
if ("key" in jsxProps) {
|
||||
key = jsxProps.key;
|
||||
delete jsxProps.key;
|
||||
}
|
||||
return jsx(tag, jsxProps, key);
|
||||
};
|
||||
var cloneElement = (element, props, ...children) => {
|
||||
return jsx(
|
||||
element.tag,
|
||||
{
|
||||
...element.props,
|
||||
...props,
|
||||
children: children.length ? children : element.props.children
|
||||
},
|
||||
element.key
|
||||
);
|
||||
};
|
||||
var memo = (component, propsAreEqual = shallowEqual) => {
|
||||
const wrapper = ((props) => component(props));
|
||||
wrapper[DOM_MEMO] = propsAreEqual;
|
||||
return wrapper;
|
||||
};
|
||||
var dom_default = {
|
||||
version: reactAPICompatVersion,
|
||||
useState,
|
||||
useEffect,
|
||||
useRef,
|
||||
useCallback,
|
||||
use,
|
||||
startTransition,
|
||||
useTransition,
|
||||
useDeferredValue,
|
||||
startViewTransition,
|
||||
useViewTransition,
|
||||
useMemo,
|
||||
useLayoutEffect,
|
||||
useInsertionEffect,
|
||||
useReducer,
|
||||
useId,
|
||||
useDebugValue,
|
||||
createRef,
|
||||
forwardRef,
|
||||
useImperativeHandle,
|
||||
useSyncExternalStore,
|
||||
useFormStatus,
|
||||
useActionState,
|
||||
useOptimistic,
|
||||
Suspense,
|
||||
ErrorBoundary,
|
||||
createContext,
|
||||
useContext,
|
||||
memo,
|
||||
isValidElement,
|
||||
createElement,
|
||||
cloneElement,
|
||||
Children,
|
||||
Fragment,
|
||||
StrictMode: Fragment,
|
||||
flushSync,
|
||||
createPortal
|
||||
};
|
||||
export {
|
||||
Children,
|
||||
ErrorBoundary,
|
||||
Fragment,
|
||||
Fragment as StrictMode,
|
||||
Suspense,
|
||||
cloneElement,
|
||||
createContext,
|
||||
createElement,
|
||||
createPortal,
|
||||
createRef,
|
||||
dom_default as default,
|
||||
flushSync,
|
||||
forwardRef,
|
||||
isValidElement,
|
||||
createElement as jsx,
|
||||
memo,
|
||||
render,
|
||||
startTransition,
|
||||
startViewTransition,
|
||||
use,
|
||||
useActionState,
|
||||
useCallback,
|
||||
useContext,
|
||||
useDebugValue,
|
||||
useDeferredValue,
|
||||
useEffect,
|
||||
useFormStatus,
|
||||
useId,
|
||||
useImperativeHandle,
|
||||
useInsertionEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useOptimistic,
|
||||
useReducer,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
useTransition,
|
||||
useViewTransition,
|
||||
reactAPICompatVersion as version
|
||||
};
|
||||
337
_node_modules/hono/dist/jsx/dom/intrinsic-element/components.js
generated
vendored
Normal file
337
_node_modules/hono/dist/jsx/dom/intrinsic-element/components.js
generated
vendored
Normal file
@@ -0,0 +1,337 @@
|
||||
// src/jsx/dom/intrinsic-element/components.ts
|
||||
import { useContext } from "../../context.js";
|
||||
import { use, useCallback, useMemo, useState } from "../../hooks/index.js";
|
||||
import { dataPrecedenceAttr, deDupeKeyMap, domRenderers } from "../../intrinsic-element/common.js";
|
||||
import { FormContext, registerAction } from "../hooks/index.js";
|
||||
import { createPortal, getNameSpaceContext } from "../render.js";
|
||||
var clearCache = () => {
|
||||
blockingPromiseMap = /* @__PURE__ */ Object.create(null);
|
||||
createdElements = /* @__PURE__ */ Object.create(null);
|
||||
};
|
||||
var composeRef = (ref, cb) => {
|
||||
return useMemo(
|
||||
() => (e) => {
|
||||
let refCleanup;
|
||||
if (ref) {
|
||||
if (typeof ref === "function") {
|
||||
refCleanup = ref(e) || (() => {
|
||||
ref(null);
|
||||
});
|
||||
} else if (ref && "current" in ref) {
|
||||
ref.current = e;
|
||||
refCleanup = () => {
|
||||
ref.current = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
const cbCleanup = cb(e);
|
||||
return () => {
|
||||
cbCleanup?.();
|
||||
refCleanup?.();
|
||||
};
|
||||
},
|
||||
[ref]
|
||||
);
|
||||
};
|
||||
var blockingPromiseMap = /* @__PURE__ */ Object.create(null);
|
||||
var createdElements = /* @__PURE__ */ Object.create(null);
|
||||
var documentMetadataTag = (tag, props, preserveNodeType, supportSort, supportBlocking) => {
|
||||
if (props?.itemProp) {
|
||||
return {
|
||||
tag,
|
||||
props,
|
||||
type: tag,
|
||||
ref: props.ref
|
||||
};
|
||||
}
|
||||
const head = document.head;
|
||||
let { onLoad, onError, precedence, blocking, ...restProps } = props;
|
||||
let element = null;
|
||||
let created = false;
|
||||
const deDupeKeys = deDupeKeyMap[tag];
|
||||
let existingElements = void 0;
|
||||
if (deDupeKeys.length > 0) {
|
||||
const tags = head.querySelectorAll(tag);
|
||||
LOOP: for (const e of tags) {
|
||||
for (const key of deDupeKeyMap[tag]) {
|
||||
if (e.getAttribute(key) === props[key]) {
|
||||
element = e;
|
||||
break LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!element) {
|
||||
const cacheKey = deDupeKeys.reduce(
|
||||
(acc, key) => props[key] === void 0 ? acc : `${acc}-${key}-${props[key]}`,
|
||||
tag
|
||||
);
|
||||
created = !createdElements[cacheKey];
|
||||
element = createdElements[cacheKey] ||= (() => {
|
||||
const e = document.createElement(tag);
|
||||
for (const key of deDupeKeys) {
|
||||
if (props[key] !== void 0) {
|
||||
e.setAttribute(key, props[key]);
|
||||
}
|
||||
if (props.rel) {
|
||||
e.setAttribute("rel", props.rel);
|
||||
}
|
||||
}
|
||||
return e;
|
||||
})();
|
||||
}
|
||||
} else {
|
||||
existingElements = head.querySelectorAll(tag);
|
||||
}
|
||||
precedence = supportSort ? precedence ?? "" : void 0;
|
||||
if (supportSort) {
|
||||
restProps[dataPrecedenceAttr] = precedence;
|
||||
}
|
||||
const insert = useCallback(
|
||||
(e) => {
|
||||
if (deDupeKeys.length > 0) {
|
||||
let found = false;
|
||||
for (const existingElement of head.querySelectorAll(tag)) {
|
||||
if (found && existingElement.getAttribute(dataPrecedenceAttr) !== precedence) {
|
||||
head.insertBefore(e, existingElement);
|
||||
return;
|
||||
}
|
||||
if (existingElement.getAttribute(dataPrecedenceAttr) === precedence) {
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
head.appendChild(e);
|
||||
} else if (existingElements) {
|
||||
let found = false;
|
||||
for (const existingElement of existingElements) {
|
||||
if (existingElement === e) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
head.insertBefore(
|
||||
e,
|
||||
head.contains(existingElements[0]) ? existingElements[0] : head.querySelector(tag)
|
||||
);
|
||||
}
|
||||
existingElements = void 0;
|
||||
}
|
||||
},
|
||||
[precedence]
|
||||
);
|
||||
const ref = composeRef(props.ref, (e) => {
|
||||
const key = deDupeKeys[0];
|
||||
if (preserveNodeType === 2) {
|
||||
e.innerHTML = "";
|
||||
}
|
||||
if (created || existingElements) {
|
||||
insert(e);
|
||||
}
|
||||
if (!onError && !onLoad) {
|
||||
return;
|
||||
}
|
||||
let promise = blockingPromiseMap[e.getAttribute(key)] ||= new Promise(
|
||||
(resolve, reject) => {
|
||||
e.addEventListener("load", resolve);
|
||||
e.addEventListener("error", reject);
|
||||
}
|
||||
);
|
||||
if (onLoad) {
|
||||
promise = promise.then(onLoad);
|
||||
}
|
||||
if (onError) {
|
||||
promise = promise.catch(onError);
|
||||
}
|
||||
promise.catch(() => {
|
||||
});
|
||||
});
|
||||
if (supportBlocking && blocking === "render") {
|
||||
const key = deDupeKeyMap[tag][0];
|
||||
if (props[key]) {
|
||||
const value = props[key];
|
||||
const promise = blockingPromiseMap[value] ||= new Promise((resolve, reject) => {
|
||||
insert(element);
|
||||
element.addEventListener("load", resolve);
|
||||
element.addEventListener("error", reject);
|
||||
});
|
||||
use(promise);
|
||||
}
|
||||
}
|
||||
const jsxNode = {
|
||||
tag,
|
||||
type: tag,
|
||||
props: {
|
||||
...restProps,
|
||||
ref
|
||||
},
|
||||
ref
|
||||
};
|
||||
jsxNode.p = preserveNodeType;
|
||||
if (element) {
|
||||
jsxNode.e = element;
|
||||
}
|
||||
return createPortal(
|
||||
jsxNode,
|
||||
head
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
);
|
||||
};
|
||||
var title = (props) => {
|
||||
const nameSpaceContext = getNameSpaceContext();
|
||||
const ns = nameSpaceContext && useContext(nameSpaceContext);
|
||||
if (ns?.endsWith("svg")) {
|
||||
return {
|
||||
tag: "title",
|
||||
props,
|
||||
type: "title",
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
ref: props.ref
|
||||
};
|
||||
}
|
||||
return documentMetadataTag("title", props, void 0, false, false);
|
||||
};
|
||||
var script = (props) => {
|
||||
if (!props || ["src", "async"].some((k) => !props[k])) {
|
||||
return {
|
||||
tag: "script",
|
||||
props,
|
||||
type: "script",
|
||||
ref: props.ref
|
||||
};
|
||||
}
|
||||
return documentMetadataTag("script", props, 1, false, true);
|
||||
};
|
||||
var style = (props) => {
|
||||
if (!props || !["href", "precedence"].every((k) => k in props)) {
|
||||
return {
|
||||
tag: "style",
|
||||
props,
|
||||
type: "style",
|
||||
ref: props.ref
|
||||
};
|
||||
}
|
||||
props["data-href"] = props.href;
|
||||
delete props.href;
|
||||
return documentMetadataTag("style", props, 2, true, true);
|
||||
};
|
||||
var link = (props) => {
|
||||
if (!props || ["onLoad", "onError"].some((k) => k in props) || props.rel === "stylesheet" && (!("precedence" in props) || "disabled" in props)) {
|
||||
return {
|
||||
tag: "link",
|
||||
props,
|
||||
type: "link",
|
||||
ref: props.ref
|
||||
};
|
||||
}
|
||||
return documentMetadataTag("link", props, 1, "precedence" in props, true);
|
||||
};
|
||||
var meta = (props) => {
|
||||
return documentMetadataTag("meta", props, void 0, false, false);
|
||||
};
|
||||
var customEventFormAction = /* @__PURE__ */ Symbol();
|
||||
var form = (props) => {
|
||||
const { action, ...restProps } = props;
|
||||
if (typeof action !== "function") {
|
||||
;
|
||||
restProps.action = action;
|
||||
}
|
||||
const [state, setState] = useState([null, false]);
|
||||
const onSubmit = useCallback(
|
||||
async (ev) => {
|
||||
const currentAction = ev.isTrusted ? action : ev.detail[customEventFormAction];
|
||||
if (typeof currentAction !== "function") {
|
||||
return;
|
||||
}
|
||||
ev.preventDefault();
|
||||
const formData = new FormData(ev.target);
|
||||
setState([formData, true]);
|
||||
const actionRes = currentAction(formData);
|
||||
if (actionRes instanceof Promise) {
|
||||
registerAction(actionRes);
|
||||
await actionRes;
|
||||
}
|
||||
setState([null, true]);
|
||||
},
|
||||
[]
|
||||
);
|
||||
const ref = composeRef(props.ref, (el) => {
|
||||
el.addEventListener("submit", onSubmit);
|
||||
return () => {
|
||||
el.removeEventListener("submit", onSubmit);
|
||||
};
|
||||
});
|
||||
const [data, isDirty] = state;
|
||||
state[1] = false;
|
||||
return {
|
||||
tag: FormContext,
|
||||
props: {
|
||||
value: {
|
||||
pending: data !== null,
|
||||
data,
|
||||
method: data ? "post" : null,
|
||||
action: data ? action : null
|
||||
},
|
||||
children: {
|
||||
tag: "form",
|
||||
props: {
|
||||
...restProps,
|
||||
ref
|
||||
},
|
||||
type: "form",
|
||||
ref
|
||||
}
|
||||
},
|
||||
f: isDirty
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
};
|
||||
};
|
||||
var formActionableElement = (tag, {
|
||||
formAction,
|
||||
...props
|
||||
}) => {
|
||||
if (typeof formAction === "function") {
|
||||
const onClick = useCallback((ev) => {
|
||||
ev.preventDefault();
|
||||
ev.currentTarget.form.dispatchEvent(
|
||||
new CustomEvent("submit", { detail: { [customEventFormAction]: formAction } })
|
||||
);
|
||||
}, []);
|
||||
props.ref = composeRef(props.ref, (el) => {
|
||||
el.addEventListener("click", onClick);
|
||||
return () => {
|
||||
el.removeEventListener("click", onClick);
|
||||
};
|
||||
});
|
||||
}
|
||||
return {
|
||||
tag,
|
||||
props,
|
||||
type: tag,
|
||||
ref: props.ref
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
};
|
||||
};
|
||||
var input = (props) => formActionableElement("input", props);
|
||||
var button = (props) => formActionableElement("button", props);
|
||||
Object.assign(domRenderers, {
|
||||
title,
|
||||
script,
|
||||
style,
|
||||
link,
|
||||
meta,
|
||||
form,
|
||||
input,
|
||||
button
|
||||
});
|
||||
export {
|
||||
button,
|
||||
clearCache,
|
||||
composeRef,
|
||||
form,
|
||||
input,
|
||||
link,
|
||||
meta,
|
||||
script,
|
||||
style,
|
||||
title
|
||||
};
|
||||
19
_node_modules/hono/dist/jsx/dom/jsx-dev-runtime.js
generated
vendored
Normal file
19
_node_modules/hono/dist/jsx/dom/jsx-dev-runtime.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// src/jsx/dom/jsx-dev-runtime.ts
|
||||
import * as intrinsicElementTags from "./intrinsic-element/components.js";
|
||||
var jsxDEV = (tag, props, key) => {
|
||||
if (typeof tag === "string" && intrinsicElementTags[tag]) {
|
||||
tag = intrinsicElementTags[tag];
|
||||
}
|
||||
return {
|
||||
tag,
|
||||
type: tag,
|
||||
props,
|
||||
key,
|
||||
ref: props.ref
|
||||
};
|
||||
};
|
||||
var Fragment = (props) => jsxDEV("", props, void 0);
|
||||
export {
|
||||
Fragment,
|
||||
jsxDEV
|
||||
};
|
||||
8
_node_modules/hono/dist/jsx/dom/jsx-runtime.js
generated
vendored
Normal file
8
_node_modules/hono/dist/jsx/dom/jsx-runtime.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
// src/jsx/dom/jsx-runtime.ts
|
||||
import { jsxDEV, Fragment } from "./jsx-dev-runtime.js";
|
||||
import { jsxDEV as jsxDEV2 } from "./jsx-dev-runtime.js";
|
||||
export {
|
||||
Fragment,
|
||||
jsxDEV as jsx,
|
||||
jsxDEV2 as jsxs
|
||||
};
|
||||
597
_node_modules/hono/dist/jsx/dom/render.js
generated
vendored
Normal file
597
_node_modules/hono/dist/jsx/dom/render.js
generated
vendored
Normal file
@@ -0,0 +1,597 @@
|
||||
// src/jsx/dom/render.ts
|
||||
import { toArray } from "../children.js";
|
||||
import {
|
||||
DOM_ERROR_HANDLER,
|
||||
DOM_INTERNAL_TAG,
|
||||
DOM_MEMO,
|
||||
DOM_RENDERER,
|
||||
DOM_STASH
|
||||
} from "../constants.js";
|
||||
import { globalContexts as globalJSXContexts, useContext } from "../context.js";
|
||||
import { STASH_EFFECT } from "../hooks/index.js";
|
||||
import { normalizeIntrinsicElementKey, styleObjectForEach } from "../utils.js";
|
||||
import { createContext } from "./context.js";
|
||||
var HONO_PORTAL_ELEMENT = "_hp";
|
||||
var eventAliasMap = {
|
||||
Change: "Input",
|
||||
DoubleClick: "DblClick"
|
||||
};
|
||||
var nameSpaceMap = {
|
||||
svg: "2000/svg",
|
||||
math: "1998/Math/MathML"
|
||||
};
|
||||
var buildDataStack = [];
|
||||
var refCleanupMap = /* @__PURE__ */ new WeakMap();
|
||||
var nameSpaceContext = void 0;
|
||||
var getNameSpaceContext = () => nameSpaceContext;
|
||||
var isNodeString = (node) => "t" in node;
|
||||
var eventCache = {
|
||||
// pre-define events that are used very frequently
|
||||
onClick: ["click", false]
|
||||
};
|
||||
var getEventSpec = (key) => {
|
||||
if (!key.startsWith("on")) {
|
||||
return void 0;
|
||||
}
|
||||
if (eventCache[key]) {
|
||||
return eventCache[key];
|
||||
}
|
||||
const match = key.match(/^on([A-Z][a-zA-Z]+?(?:PointerCapture)?)(Capture)?$/);
|
||||
if (match) {
|
||||
const [, eventName, capture] = match;
|
||||
return eventCache[key] = [(eventAliasMap[eventName] || eventName).toLowerCase(), !!capture];
|
||||
}
|
||||
return void 0;
|
||||
};
|
||||
var 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;
|
||||
var applyProps = (container, attributes, oldAttributes) => {
|
||||
attributes ||= {};
|
||||
for (let key in attributes) {
|
||||
const value = attributes[key];
|
||||
if (key !== "children" && (!oldAttributes || oldAttributes[key] !== value)) {
|
||||
key = normalizeIntrinsicElementKey(key);
|
||||
const eventSpec = getEventSpec(key);
|
||||
if (eventSpec) {
|
||||
if (oldAttributes?.[key] !== value) {
|
||||
if (oldAttributes) {
|
||||
container.removeEventListener(eventSpec[0], oldAttributes[key], eventSpec[1]);
|
||||
}
|
||||
if (value != null) {
|
||||
if (typeof value !== "function") {
|
||||
throw new Error(`Event handler for "${key}" is not a function`);
|
||||
}
|
||||
container.addEventListener(eventSpec[0], value, eventSpec[1]);
|
||||
}
|
||||
}
|
||||
} else if (key === "dangerouslySetInnerHTML" && value) {
|
||||
container.innerHTML = value.__html;
|
||||
} else if (key === "ref") {
|
||||
let cleanup;
|
||||
if (typeof value === "function") {
|
||||
cleanup = value(container) || (() => value(null));
|
||||
} else if (value && "current" in value) {
|
||||
value.current = container;
|
||||
cleanup = () => value.current = null;
|
||||
}
|
||||
refCleanupMap.set(container, cleanup);
|
||||
} else if (key === "style") {
|
||||
const style = container.style;
|
||||
if (typeof value === "string") {
|
||||
style.cssText = value;
|
||||
} else {
|
||||
style.cssText = "";
|
||||
if (value != null) {
|
||||
styleObjectForEach(value, style.setProperty.bind(style));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (key === "value") {
|
||||
const nodeName = container.nodeName;
|
||||
if (nodeName === "INPUT" || nodeName === "TEXTAREA" || nodeName === "SELECT") {
|
||||
;
|
||||
container.value = value === null || value === void 0 || value === false ? null : 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") {
|
||||
;
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (oldAttributes) {
|
||||
for (let key in oldAttributes) {
|
||||
const value = oldAttributes[key];
|
||||
if (key !== "children" && !(key in attributes)) {
|
||||
key = normalizeIntrinsicElementKey(key);
|
||||
const eventSpec = getEventSpec(key);
|
||||
if (eventSpec) {
|
||||
container.removeEventListener(eventSpec[0], value, eventSpec[1]);
|
||||
} else if (key === "ref") {
|
||||
refCleanupMap.get(container)?.();
|
||||
} else {
|
||||
container.removeAttribute(toAttributeName(container, key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var invokeTag = (context, node) => {
|
||||
node[DOM_STASH][0] = 0;
|
||||
buildDataStack.push([context, node]);
|
||||
const func = node.tag[DOM_RENDERER] || node.tag;
|
||||
const props = func.defaultProps ? {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
...func.defaultProps,
|
||||
...node.props
|
||||
} : node.props;
|
||||
try {
|
||||
return [func.call(null, props)];
|
||||
} finally {
|
||||
buildDataStack.pop();
|
||||
}
|
||||
};
|
||||
var getNextChildren = (node, container, nextChildren, childrenToRemove, callbacks) => {
|
||||
if (node.vR?.length) {
|
||||
childrenToRemove.push(...node.vR);
|
||||
delete node.vR;
|
||||
}
|
||||
if (typeof node.tag === "function") {
|
||||
node[DOM_STASH][1][STASH_EFFECT]?.forEach((data) => callbacks.push(data));
|
||||
}
|
||||
node.vC.forEach((child) => {
|
||||
if (isNodeString(child)) {
|
||||
nextChildren.push(child);
|
||||
} else {
|
||||
if (typeof child.tag === "function" || child.tag === "") {
|
||||
child.c = container;
|
||||
const currentNextChildrenIndex = nextChildren.length;
|
||||
getNextChildren(child, container, nextChildren, childrenToRemove, callbacks);
|
||||
if (child.s) {
|
||||
for (let i = currentNextChildrenIndex; i < nextChildren.length; i++) {
|
||||
nextChildren[i].s = true;
|
||||
}
|
||||
child.s = false;
|
||||
}
|
||||
} else {
|
||||
nextChildren.push(child);
|
||||
if (child.vR?.length) {
|
||||
childrenToRemove.push(...child.vR);
|
||||
delete child.vR;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
var findInsertBefore = (node) => {
|
||||
for (; ; node = node.tag === HONO_PORTAL_ELEMENT || !node.vC || !node.pP ? node.nN : node.vC[0]) {
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
if (node.tag !== HONO_PORTAL_ELEMENT && node.e) {
|
||||
return node.e;
|
||||
}
|
||||
}
|
||||
};
|
||||
var removeNode = (node) => {
|
||||
if (!isNodeString(node)) {
|
||||
node[DOM_STASH]?.[1][STASH_EFFECT]?.forEach((data) => data[2]?.());
|
||||
refCleanupMap.get(node.e)?.();
|
||||
if (node.p === 2) {
|
||||
node.vC?.forEach((n) => n.p = 2);
|
||||
}
|
||||
node.vC?.forEach(removeNode);
|
||||
}
|
||||
if (!node.p) {
|
||||
node.e?.remove();
|
||||
delete node.e;
|
||||
}
|
||||
if (typeof node.tag === "function") {
|
||||
updateMap.delete(node);
|
||||
fallbackUpdateFnArrayMap.delete(node);
|
||||
delete node[DOM_STASH][3];
|
||||
node.a = true;
|
||||
}
|
||||
};
|
||||
var apply = (node, container, isNew) => {
|
||||
node.c = container;
|
||||
applyNodeObject(node, container, isNew);
|
||||
};
|
||||
var findChildNodeIndex = (childNodes, child) => {
|
||||
if (!child) {
|
||||
return;
|
||||
}
|
||||
for (let i = 0, len = childNodes.length; i < len; i++) {
|
||||
if (childNodes[i] === child) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return;
|
||||
};
|
||||
var cancelBuild = /* @__PURE__ */ Symbol();
|
||||
var applyNodeObject = (node, container, isNew) => {
|
||||
const next = [];
|
||||
const remove = [];
|
||||
const callbacks = [];
|
||||
getNextChildren(node, container, next, remove, callbacks);
|
||||
remove.forEach(removeNode);
|
||||
const childNodes = isNew ? void 0 : container.childNodes;
|
||||
let offset;
|
||||
let insertBeforeNode = null;
|
||||
if (isNew) {
|
||||
offset = -1;
|
||||
} else if (!childNodes.length) {
|
||||
offset = 0;
|
||||
} else {
|
||||
const offsetByNextNode = findChildNodeIndex(childNodes, findInsertBefore(node.nN));
|
||||
if (offsetByNextNode !== void 0) {
|
||||
insertBeforeNode = childNodes[offsetByNextNode];
|
||||
offset = offsetByNextNode;
|
||||
} else {
|
||||
offset = findChildNodeIndex(childNodes, next.find((n) => n.tag !== HONO_PORTAL_ELEMENT && n.e)?.e) ?? -1;
|
||||
}
|
||||
if (offset === -1) {
|
||||
isNew = true;
|
||||
}
|
||||
}
|
||||
for (let i = 0, len = next.length; i < len; i++, offset++) {
|
||||
const child = next[i];
|
||||
let el;
|
||||
if (child.s && child.e) {
|
||||
el = child.e;
|
||||
child.s = false;
|
||||
} else {
|
||||
const isNewLocal = isNew || !child.e;
|
||||
if (isNodeString(child)) {
|
||||
if (child.e && child.d) {
|
||||
child.e.textContent = child.t;
|
||||
}
|
||||
child.d = false;
|
||||
el = child.e ||= document.createTextNode(child.t);
|
||||
} else {
|
||||
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 === HONO_PORTAL_ELEMENT) {
|
||||
offset--;
|
||||
} else if (isNew) {
|
||||
if (!el.parentNode) {
|
||||
container.appendChild(el);
|
||||
}
|
||||
} else if (childNodes[offset] !== el && childNodes[offset - 1] !== el) {
|
||||
if (childNodes[offset + 1] === el) {
|
||||
container.appendChild(childNodes[offset]);
|
||||
} else {
|
||||
container.insertBefore(el, insertBeforeNode || childNodes[offset] || null);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (node.pP) {
|
||||
delete node.pP;
|
||||
}
|
||||
if (callbacks.length) {
|
||||
const useLayoutEffectCbs = [];
|
||||
const useEffectCbs = [];
|
||||
callbacks.forEach(([, useLayoutEffectCb, , useEffectCb, useInsertionEffectCb]) => {
|
||||
if (useLayoutEffectCb) {
|
||||
useLayoutEffectCbs.push(useLayoutEffectCb);
|
||||
}
|
||||
if (useEffectCb) {
|
||||
useEffectCbs.push(useEffectCb);
|
||||
}
|
||||
useInsertionEffectCb?.();
|
||||
});
|
||||
useLayoutEffectCbs.forEach((cb) => cb());
|
||||
if (useEffectCbs.length) {
|
||||
requestAnimationFrame(() => {
|
||||
useEffectCbs.forEach((cb) => cb());
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
var isSameContext = (oldContexts, newContexts) => !!(oldContexts && oldContexts.length === newContexts.length && oldContexts.every((ctx, i) => ctx[1] === newContexts[i][1]));
|
||||
var fallbackUpdateFnArrayMap = /* @__PURE__ */ new WeakMap();
|
||||
var build = (context, node, children) => {
|
||||
const buildWithPreviousChildren = !children && node.pC;
|
||||
if (children) {
|
||||
node.pC ||= node.vC;
|
||||
}
|
||||
let foundErrorHandler;
|
||||
try {
|
||||
children ||= typeof node.tag == "function" ? invokeTag(context, node) : toArray(node.props.children);
|
||||
if (children[0]?.tag === "" && children[0][DOM_ERROR_HANDLER]) {
|
||||
foundErrorHandler = children[0][DOM_ERROR_HANDLER];
|
||||
context[5].push([context, foundErrorHandler, node]);
|
||||
}
|
||||
const oldVChildren = buildWithPreviousChildren ? [...node.pC] : node.vC ? [...node.vC] : void 0;
|
||||
const vChildren = [];
|
||||
let prevNode;
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
if (Array.isArray(children[i])) {
|
||||
children.splice(i, 1, ...children[i].flat());
|
||||
}
|
||||
let child = buildNode(children[i]);
|
||||
if (child) {
|
||||
if (typeof child.tag === "function" && // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
!child.tag[DOM_INTERNAL_TAG]) {
|
||||
if (globalJSXContexts.length > 0) {
|
||||
child[DOM_STASH][2] = globalJSXContexts.map((c) => [c, c.values.at(-1)]);
|
||||
}
|
||||
if (context[5]?.length) {
|
||||
child[DOM_STASH][3] = context[5].at(-1);
|
||||
}
|
||||
}
|
||||
let oldChild;
|
||||
if (oldVChildren && oldVChildren.length) {
|
||||
const i2 = oldVChildren.findIndex(
|
||||
isNodeString(child) ? (c) => isNodeString(c) : child.key !== void 0 ? (c) => c.key === child.key && c.tag === child.tag : (c) => c.tag === child.tag
|
||||
);
|
||||
if (i2 !== -1) {
|
||||
oldChild = oldVChildren[i2];
|
||||
oldVChildren.splice(i2, 1);
|
||||
}
|
||||
}
|
||||
if (oldChild) {
|
||||
if (isNodeString(child)) {
|
||||
if (oldChild.t !== child.t) {
|
||||
;
|
||||
oldChild.t = child.t;
|
||||
oldChild.d = true;
|
||||
}
|
||||
child = oldChild;
|
||||
} else {
|
||||
const pP = oldChild.pP = oldChild.props;
|
||||
oldChild.props = child.props;
|
||||
oldChild.f ||= child.f || node.f;
|
||||
if (typeof child.tag === "function") {
|
||||
const oldContexts = oldChild[DOM_STASH][2];
|
||||
oldChild[DOM_STASH][2] = child[DOM_STASH][2] || [];
|
||||
oldChild[DOM_STASH][3] = child[DOM_STASH][3];
|
||||
if (!oldChild.f && ((oldChild.o || oldChild) === child.o || // The code generated by the react compiler is memoized under this condition.
|
||||
oldChild.tag[DOM_MEMO]?.(pP, oldChild.props)) && // The `memo` function is memoized under this condition.
|
||||
isSameContext(oldContexts, oldChild[DOM_STASH][2])) {
|
||||
oldChild.s = true;
|
||||
}
|
||||
}
|
||||
child = oldChild;
|
||||
}
|
||||
} else if (!isNodeString(child) && nameSpaceContext) {
|
||||
const ns = useContext(nameSpaceContext);
|
||||
if (ns) {
|
||||
child.n = ns;
|
||||
}
|
||||
}
|
||||
if (!isNodeString(child) && !child.s) {
|
||||
build(context, child);
|
||||
delete child.f;
|
||||
}
|
||||
vChildren.push(child);
|
||||
if (prevNode && !prevNode.s && !child.s) {
|
||||
for (let p = prevNode; p && !isNodeString(p); p = p.vC?.at(-1)) {
|
||||
p.nN = child;
|
||||
}
|
||||
}
|
||||
prevNode = child;
|
||||
}
|
||||
}
|
||||
node.vR = buildWithPreviousChildren ? [...node.vC, ...oldVChildren || []] : oldVChildren || [];
|
||||
node.vC = vChildren;
|
||||
if (buildWithPreviousChildren) {
|
||||
delete node.pC;
|
||||
}
|
||||
} catch (e) {
|
||||
node.f = true;
|
||||
if (e === cancelBuild) {
|
||||
if (foundErrorHandler) {
|
||||
return;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
const [errorHandlerContext, errorHandler, errorHandlerNode] = node[DOM_STASH]?.[3] || [];
|
||||
if (errorHandler) {
|
||||
const fallbackUpdateFn = () => update([0, false, context[2]], errorHandlerNode);
|
||||
const fallbackUpdateFnArray = fallbackUpdateFnArrayMap.get(errorHandlerNode) || [];
|
||||
fallbackUpdateFnArray.push(fallbackUpdateFn);
|
||||
fallbackUpdateFnArrayMap.set(errorHandlerNode, fallbackUpdateFnArray);
|
||||
const fallback = errorHandler(e, () => {
|
||||
const fnArray = fallbackUpdateFnArrayMap.get(errorHandlerNode);
|
||||
if (fnArray) {
|
||||
const i = fnArray.indexOf(fallbackUpdateFn);
|
||||
if (i !== -1) {
|
||||
fnArray.splice(i, 1);
|
||||
return fallbackUpdateFn();
|
||||
}
|
||||
}
|
||||
});
|
||||
if (fallback) {
|
||||
if (context[0] === 1) {
|
||||
context[1] = true;
|
||||
} else {
|
||||
build(context, errorHandlerNode, [fallback]);
|
||||
if ((errorHandler.length === 1 || context !== errorHandlerContext) && errorHandlerNode.c) {
|
||||
apply(errorHandlerNode, errorHandlerNode.c, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw cancelBuild;
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
} finally {
|
||||
if (foundErrorHandler) {
|
||||
context[5].pop();
|
||||
}
|
||||
}
|
||||
};
|
||||
var buildNode = (node) => {
|
||||
if (node === void 0 || node === null || typeof node === "boolean") {
|
||||
return void 0;
|
||||
} else if (typeof node === "string" || typeof node === "number") {
|
||||
return { t: node.toString(), d: true };
|
||||
} else {
|
||||
if ("vR" in node) {
|
||||
node = {
|
||||
tag: node.tag,
|
||||
props: node.props,
|
||||
key: node.key,
|
||||
f: node.f,
|
||||
type: node.tag,
|
||||
ref: node.props.ref,
|
||||
o: node.o || node
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
};
|
||||
}
|
||||
if (typeof node.tag === "function") {
|
||||
;
|
||||
node[DOM_STASH] = [0, []];
|
||||
} else {
|
||||
const ns = nameSpaceMap[node.tag];
|
||||
if (ns) {
|
||||
nameSpaceContext ||= createContext("");
|
||||
node.props.children = [
|
||||
{
|
||||
tag: nameSpaceContext,
|
||||
props: {
|
||||
value: node.n = `http://www.w3.org/${ns}`,
|
||||
children: node.props.children
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
};
|
||||
var replaceContainer = (node, from, to) => {
|
||||
if (node.c === from) {
|
||||
node.c = to;
|
||||
node.vC.forEach((child) => replaceContainer(child, from, to));
|
||||
}
|
||||
};
|
||||
var updateSync = (context, node) => {
|
||||
node[DOM_STASH][2]?.forEach(([c, v]) => {
|
||||
c.values.push(v);
|
||||
});
|
||||
try {
|
||||
build(context, node, void 0);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
if (node.a) {
|
||||
delete node.a;
|
||||
return;
|
||||
}
|
||||
node[DOM_STASH][2]?.forEach(([c]) => {
|
||||
c.values.pop();
|
||||
});
|
||||
if (context[0] !== 1 || !context[1]) {
|
||||
apply(node, node.c, false);
|
||||
}
|
||||
};
|
||||
var updateMap = /* @__PURE__ */ new WeakMap();
|
||||
var currentUpdateSets = [];
|
||||
var update = async (context, node) => {
|
||||
context[5] ||= [];
|
||||
const existing = updateMap.get(node);
|
||||
if (existing) {
|
||||
existing[0](void 0);
|
||||
}
|
||||
let resolve;
|
||||
const promise = new Promise((r) => resolve = r);
|
||||
updateMap.set(node, [
|
||||
resolve,
|
||||
() => {
|
||||
if (context[2]) {
|
||||
context[2](context, node, (context2) => {
|
||||
updateSync(context2, node);
|
||||
}).then(() => resolve(node));
|
||||
} else {
|
||||
updateSync(context, node);
|
||||
resolve(node);
|
||||
}
|
||||
}
|
||||
]);
|
||||
if (currentUpdateSets.length) {
|
||||
;
|
||||
currentUpdateSets.at(-1).add(node);
|
||||
} else {
|
||||
await Promise.resolve();
|
||||
const latest = updateMap.get(node);
|
||||
if (latest) {
|
||||
updateMap.delete(node);
|
||||
latest[1]();
|
||||
}
|
||||
}
|
||||
return promise;
|
||||
};
|
||||
var renderNode = (node, container) => {
|
||||
const context = [];
|
||||
context[5] = [];
|
||||
context[4] = true;
|
||||
build(context, node, void 0);
|
||||
context[4] = false;
|
||||
const fragment = document.createDocumentFragment();
|
||||
apply(node, fragment, true);
|
||||
replaceContainer(node, fragment, container);
|
||||
container.replaceChildren(fragment);
|
||||
};
|
||||
var render = (jsxNode, container) => {
|
||||
renderNode(buildNode({ tag: "", props: { children: jsxNode } }), container);
|
||||
};
|
||||
var flushSync = (callback) => {
|
||||
const set = /* @__PURE__ */ new Set();
|
||||
currentUpdateSets.push(set);
|
||||
callback();
|
||||
set.forEach((node) => {
|
||||
const latest = updateMap.get(node);
|
||||
if (latest) {
|
||||
updateMap.delete(node);
|
||||
latest[1]();
|
||||
}
|
||||
});
|
||||
currentUpdateSets.pop();
|
||||
};
|
||||
var createPortal = (children, container, key) => ({
|
||||
tag: HONO_PORTAL_ELEMENT,
|
||||
props: {
|
||||
children
|
||||
},
|
||||
key,
|
||||
e: container,
|
||||
p: 1
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
});
|
||||
export {
|
||||
build,
|
||||
buildDataStack,
|
||||
buildNode,
|
||||
createPortal,
|
||||
flushSync,
|
||||
getNameSpaceContext,
|
||||
render,
|
||||
renderNode,
|
||||
update
|
||||
};
|
||||
33
_node_modules/hono/dist/jsx/dom/server.js
generated
vendored
Normal file
33
_node_modules/hono/dist/jsx/dom/server.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
// src/jsx/dom/server.ts
|
||||
import { renderToReadableStream as renderToReadableStreamHono } from "../streaming.js";
|
||||
import version from "./index.js";
|
||||
var renderToString = (element, options = {}) => {
|
||||
if (Object.keys(options).length > 0) {
|
||||
console.warn("options are not supported yet");
|
||||
}
|
||||
const res = element?.toString() ?? "";
|
||||
if (typeof res !== "string") {
|
||||
throw new Error("Async component is not supported in renderToString");
|
||||
}
|
||||
return res;
|
||||
};
|
||||
var renderToReadableStream = async (element, options = {}) => {
|
||||
if (Object.keys(options).some((key) => key !== "onError")) {
|
||||
console.warn("options are not supported yet, except onError");
|
||||
}
|
||||
if (!element || typeof element !== "object") {
|
||||
element = element?.toString() ?? "";
|
||||
}
|
||||
return renderToReadableStreamHono(element, options.onError);
|
||||
};
|
||||
var server_default = {
|
||||
renderToString,
|
||||
renderToReadableStream,
|
||||
version
|
||||
};
|
||||
export {
|
||||
server_default as default,
|
||||
renderToReadableStream,
|
||||
renderToString,
|
||||
version
|
||||
};
|
||||
10
_node_modules/hono/dist/jsx/dom/utils.js
generated
vendored
Normal file
10
_node_modules/hono/dist/jsx/dom/utils.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
// src/jsx/dom/utils.ts
|
||||
import { DOM_INTERNAL_TAG } from "../constants.js";
|
||||
var setInternalTagFlag = (fn) => {
|
||||
;
|
||||
fn[DOM_INTERNAL_TAG] = true;
|
||||
return fn;
|
||||
};
|
||||
export {
|
||||
setInternalTagFlag
|
||||
};
|
||||
328
_node_modules/hono/dist/jsx/hooks/index.js
generated
vendored
Normal file
328
_node_modules/hono/dist/jsx/hooks/index.js
generated
vendored
Normal file
@@ -0,0 +1,328 @@
|
||||
// src/jsx/hooks/index.ts
|
||||
import { DOM_STASH } from "../constants.js";
|
||||
import { buildDataStack, update } from "../dom/render.js";
|
||||
var STASH_SATE = 0;
|
||||
var STASH_EFFECT = 1;
|
||||
var STASH_CALLBACK = 2;
|
||||
var STASH_MEMO = 3;
|
||||
var STASH_REF = 4;
|
||||
var resolvedPromiseValueMap = /* @__PURE__ */ new WeakMap();
|
||||
var isDepsChanged = (prevDeps, deps) => !prevDeps || !deps || prevDeps.length !== deps.length || deps.some((dep, i) => dep !== prevDeps[i]);
|
||||
var viewTransitionState = void 0;
|
||||
var documentStartViewTransition = (cb) => {
|
||||
if (document?.startViewTransition) {
|
||||
return document.startViewTransition(cb);
|
||||
} else {
|
||||
cb();
|
||||
return { finished: Promise.resolve() };
|
||||
}
|
||||
};
|
||||
var updateHook = void 0;
|
||||
var viewTransitionHook = (context, node, cb) => {
|
||||
const state = [true, false];
|
||||
let lastVC = node.vC;
|
||||
return documentStartViewTransition(() => {
|
||||
if (lastVC === node.vC) {
|
||||
viewTransitionState = state;
|
||||
cb(context);
|
||||
viewTransitionState = void 0;
|
||||
lastVC = node.vC;
|
||||
}
|
||||
}).finished.then(() => {
|
||||
if (state[1] && lastVC === node.vC) {
|
||||
state[0] = false;
|
||||
viewTransitionState = state;
|
||||
cb(context);
|
||||
viewTransitionState = void 0;
|
||||
}
|
||||
});
|
||||
};
|
||||
var startViewTransition = (callback) => {
|
||||
updateHook = viewTransitionHook;
|
||||
try {
|
||||
callback();
|
||||
} finally {
|
||||
updateHook = void 0;
|
||||
}
|
||||
};
|
||||
var useViewTransition = () => {
|
||||
const buildData = buildDataStack.at(-1);
|
||||
if (!buildData) {
|
||||
return [false, () => {
|
||||
}];
|
||||
}
|
||||
if (viewTransitionState) {
|
||||
viewTransitionState[1] = true;
|
||||
}
|
||||
return [!!viewTransitionState?.[0], startViewTransition];
|
||||
};
|
||||
var pendingStack = [];
|
||||
var runCallback = (type, callback) => {
|
||||
let resolve;
|
||||
const promise = new Promise((r) => resolve = r);
|
||||
pendingStack.push([type, promise]);
|
||||
try {
|
||||
const res = callback();
|
||||
if (res instanceof Promise) {
|
||||
res.then(resolve, resolve);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
} finally {
|
||||
pendingStack.pop();
|
||||
}
|
||||
};
|
||||
var startTransition = (callback) => {
|
||||
runCallback(1, callback);
|
||||
};
|
||||
var startTransitionHook = (callback) => {
|
||||
runCallback(2, callback);
|
||||
};
|
||||
var useTransition = () => {
|
||||
const buildData = buildDataStack.at(-1);
|
||||
if (!buildData) {
|
||||
return [false, () => {
|
||||
}];
|
||||
}
|
||||
const [error, setError] = useState();
|
||||
const [state, updateState] = useState();
|
||||
if (error) {
|
||||
throw error[0];
|
||||
}
|
||||
const startTransitionLocalHook = useCallback(
|
||||
(callback) => {
|
||||
startTransitionHook(() => {
|
||||
updateState((state2) => !state2);
|
||||
let res = callback();
|
||||
if (res instanceof Promise) {
|
||||
res = res.catch((e) => {
|
||||
setError([e]);
|
||||
});
|
||||
}
|
||||
return res;
|
||||
});
|
||||
},
|
||||
[state]
|
||||
);
|
||||
const [context] = buildData;
|
||||
return [context[0] === 2, startTransitionLocalHook];
|
||||
};
|
||||
var useDeferredValue = (value, ...rest) => {
|
||||
const [values, setValues] = useState(
|
||||
rest.length ? [rest[0], rest[0]] : [value, value]
|
||||
);
|
||||
if (Object.is(values[1], value)) {
|
||||
return values[1];
|
||||
}
|
||||
pendingStack.push([3, Promise.resolve()]);
|
||||
updateHook = async (context, _, cb) => {
|
||||
cb(context);
|
||||
values[0] = value;
|
||||
};
|
||||
setValues([values[0], value]);
|
||||
updateHook = void 0;
|
||||
pendingStack.pop();
|
||||
return values[0];
|
||||
};
|
||||
var useState = (initialState) => {
|
||||
const resolveInitialState = () => typeof initialState === "function" ? initialState() : initialState;
|
||||
const buildData = buildDataStack.at(-1);
|
||||
if (!buildData) {
|
||||
return [resolveInitialState(), () => {
|
||||
}];
|
||||
}
|
||||
const [, node] = buildData;
|
||||
const stateArray = node[DOM_STASH][1][STASH_SATE] ||= [];
|
||||
const hookIndex = node[DOM_STASH][0]++;
|
||||
return stateArray[hookIndex] ||= [
|
||||
resolveInitialState(),
|
||||
(newState) => {
|
||||
const localUpdateHook = updateHook;
|
||||
const stateData = stateArray[hookIndex];
|
||||
if (typeof newState === "function") {
|
||||
newState = newState(stateData[0]);
|
||||
}
|
||||
if (!Object.is(newState, stateData[0])) {
|
||||
stateData[0] = newState;
|
||||
if (pendingStack.length) {
|
||||
const [pendingType, pendingPromise] = pendingStack.at(-1);
|
||||
Promise.all([
|
||||
pendingType === 3 ? node : update([pendingType, false, localUpdateHook], node),
|
||||
pendingPromise
|
||||
]).then(([node2]) => {
|
||||
if (!node2 || !(pendingType === 2 || pendingType === 3)) {
|
||||
return;
|
||||
}
|
||||
const lastVC = node2.vC;
|
||||
const addUpdateTask = () => {
|
||||
setTimeout(() => {
|
||||
if (lastVC !== node2.vC) {
|
||||
return;
|
||||
}
|
||||
update([pendingType === 3 ? 1 : 0, false, localUpdateHook], node2);
|
||||
});
|
||||
};
|
||||
requestAnimationFrame(addUpdateTask);
|
||||
});
|
||||
} else {
|
||||
update([0, false, localUpdateHook], node);
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
};
|
||||
var useReducer = (reducer, initialArg, init) => {
|
||||
const handler = useCallback(
|
||||
(action) => {
|
||||
setState((state2) => reducer(state2, action));
|
||||
},
|
||||
[reducer]
|
||||
);
|
||||
const [state, setState] = useState(() => init ? init(initialArg) : initialArg);
|
||||
return [state, handler];
|
||||
};
|
||||
var useEffectCommon = (index, effect, deps) => {
|
||||
const buildData = buildDataStack.at(-1);
|
||||
if (!buildData) {
|
||||
return;
|
||||
}
|
||||
const [, node] = buildData;
|
||||
const effectDepsArray = node[DOM_STASH][1][STASH_EFFECT] ||= [];
|
||||
const hookIndex = node[DOM_STASH][0]++;
|
||||
const [prevDeps, , prevCleanup] = effectDepsArray[hookIndex] ||= [];
|
||||
if (isDepsChanged(prevDeps, deps)) {
|
||||
if (prevCleanup) {
|
||||
prevCleanup();
|
||||
}
|
||||
const runner = () => {
|
||||
data[index] = void 0;
|
||||
data[2] = effect();
|
||||
};
|
||||
const data = [deps, void 0, void 0, void 0, void 0];
|
||||
data[index] = runner;
|
||||
effectDepsArray[hookIndex] = data;
|
||||
}
|
||||
};
|
||||
var useEffect = (effect, deps) => useEffectCommon(3, effect, deps);
|
||||
var useLayoutEffect = (effect, deps) => useEffectCommon(1, effect, deps);
|
||||
var useInsertionEffect = (effect, deps) => useEffectCommon(4, effect, deps);
|
||||
var useCallback = (callback, deps) => {
|
||||
const buildData = buildDataStack.at(-1);
|
||||
if (!buildData) {
|
||||
return callback;
|
||||
}
|
||||
const [, node] = buildData;
|
||||
const callbackArray = node[DOM_STASH][1][STASH_CALLBACK] ||= [];
|
||||
const hookIndex = node[DOM_STASH][0]++;
|
||||
const prevDeps = callbackArray[hookIndex];
|
||||
if (isDepsChanged(prevDeps?.[1], deps)) {
|
||||
callbackArray[hookIndex] = [callback, deps];
|
||||
} else {
|
||||
callback = callbackArray[hookIndex][0];
|
||||
}
|
||||
return callback;
|
||||
};
|
||||
var useRef = (initialValue) => {
|
||||
const buildData = buildDataStack.at(-1);
|
||||
if (!buildData) {
|
||||
return { current: initialValue };
|
||||
}
|
||||
const [, node] = buildData;
|
||||
const refArray = node[DOM_STASH][1][STASH_REF] ||= [];
|
||||
const hookIndex = node[DOM_STASH][0]++;
|
||||
return refArray[hookIndex] ||= { current: initialValue };
|
||||
};
|
||||
var use = (promise) => {
|
||||
const cachedRes = resolvedPromiseValueMap.get(promise);
|
||||
if (cachedRes) {
|
||||
if (cachedRes.length === 2) {
|
||||
throw cachedRes[1];
|
||||
}
|
||||
return cachedRes[0];
|
||||
}
|
||||
promise.then(
|
||||
(res) => resolvedPromiseValueMap.set(promise, [res]),
|
||||
(e) => resolvedPromiseValueMap.set(promise, [void 0, e])
|
||||
);
|
||||
throw promise;
|
||||
};
|
||||
var useMemo = (factory, deps) => {
|
||||
const buildData = buildDataStack.at(-1);
|
||||
if (!buildData) {
|
||||
return factory();
|
||||
}
|
||||
const [, node] = buildData;
|
||||
const memoArray = node[DOM_STASH][1][STASH_MEMO] ||= [];
|
||||
const hookIndex = node[DOM_STASH][0]++;
|
||||
const prevDeps = memoArray[hookIndex];
|
||||
if (isDepsChanged(prevDeps?.[1], deps)) {
|
||||
memoArray[hookIndex] = [factory(), deps];
|
||||
}
|
||||
return memoArray[hookIndex][0];
|
||||
};
|
||||
var idCounter = 0;
|
||||
var useId = () => useMemo(() => `:r${(idCounter++).toString(32)}:`, []);
|
||||
var useDebugValue = (_value, _formatter) => {
|
||||
};
|
||||
var createRef = () => {
|
||||
return { current: null };
|
||||
};
|
||||
var forwardRef = (Component) => {
|
||||
return (props) => {
|
||||
const { ref, ...rest } = props;
|
||||
return Component(rest, ref);
|
||||
};
|
||||
};
|
||||
var useImperativeHandle = (ref, createHandle, deps) => {
|
||||
useEffect(() => {
|
||||
ref.current = createHandle();
|
||||
return () => {
|
||||
ref.current = null;
|
||||
};
|
||||
}, deps);
|
||||
};
|
||||
var useSyncExternalStore = (subscribe, getSnapshot, getServerSnapshot) => {
|
||||
const buildData = buildDataStack.at(-1);
|
||||
if (!buildData) {
|
||||
if (!getServerSnapshot) {
|
||||
throw new Error("getServerSnapshot is required for server side rendering");
|
||||
}
|
||||
return getServerSnapshot();
|
||||
}
|
||||
const [serverSnapshotIsUsed] = useState(!!(buildData[0][4] && getServerSnapshot));
|
||||
const [state, setState] = useState(
|
||||
() => serverSnapshotIsUsed ? getServerSnapshot() : getSnapshot()
|
||||
);
|
||||
useEffect(() => {
|
||||
if (serverSnapshotIsUsed) {
|
||||
setState(getSnapshot());
|
||||
}
|
||||
return subscribe(() => {
|
||||
setState(getSnapshot());
|
||||
});
|
||||
}, []);
|
||||
return state;
|
||||
};
|
||||
export {
|
||||
STASH_EFFECT,
|
||||
createRef,
|
||||
forwardRef,
|
||||
startTransition,
|
||||
startViewTransition,
|
||||
use,
|
||||
useCallback,
|
||||
useDebugValue,
|
||||
useDeferredValue,
|
||||
useEffect,
|
||||
useId,
|
||||
useImperativeHandle,
|
||||
useInsertionEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useReducer,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
useTransition,
|
||||
useViewTransition
|
||||
};
|
||||
103
_node_modules/hono/dist/jsx/index.js
generated
vendored
Normal file
103
_node_modules/hono/dist/jsx/index.js
generated
vendored
Normal file
@@ -0,0 +1,103 @@
|
||||
// src/jsx/index.ts
|
||||
import { Fragment, cloneElement, isValidElement, jsx, memo, reactAPICompatVersion } from "./base.js";
|
||||
import { Children } from "./children.js";
|
||||
import { ErrorBoundary } from "./components.js";
|
||||
import { createContext, useContext } from "./context.js";
|
||||
import { useActionState, useOptimistic } from "./dom/hooks/index.js";
|
||||
import {
|
||||
createRef,
|
||||
forwardRef,
|
||||
startTransition,
|
||||
startViewTransition,
|
||||
use,
|
||||
useCallback,
|
||||
useDebugValue,
|
||||
useDeferredValue,
|
||||
useEffect,
|
||||
useId,
|
||||
useImperativeHandle,
|
||||
useInsertionEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useReducer,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
useTransition,
|
||||
useViewTransition
|
||||
} from "./hooks/index.js";
|
||||
import { Suspense } from "./streaming.js";
|
||||
var jsx_default = {
|
||||
version: reactAPICompatVersion,
|
||||
memo,
|
||||
Fragment,
|
||||
StrictMode: Fragment,
|
||||
isValidElement,
|
||||
createElement: jsx,
|
||||
cloneElement,
|
||||
ErrorBoundary,
|
||||
createContext,
|
||||
useContext,
|
||||
useState,
|
||||
useEffect,
|
||||
useRef,
|
||||
useCallback,
|
||||
useReducer,
|
||||
useId,
|
||||
useDebugValue,
|
||||
use,
|
||||
startTransition,
|
||||
useTransition,
|
||||
useDeferredValue,
|
||||
startViewTransition,
|
||||
useViewTransition,
|
||||
useMemo,
|
||||
useLayoutEffect,
|
||||
useInsertionEffect,
|
||||
createRef,
|
||||
forwardRef,
|
||||
useImperativeHandle,
|
||||
useSyncExternalStore,
|
||||
useActionState,
|
||||
useOptimistic,
|
||||
Suspense,
|
||||
Children
|
||||
};
|
||||
export {
|
||||
Children,
|
||||
ErrorBoundary,
|
||||
Fragment,
|
||||
Fragment as StrictMode,
|
||||
Suspense,
|
||||
cloneElement,
|
||||
createContext,
|
||||
jsx as createElement,
|
||||
createRef,
|
||||
jsx_default as default,
|
||||
forwardRef,
|
||||
isValidElement,
|
||||
jsx,
|
||||
memo,
|
||||
startTransition,
|
||||
startViewTransition,
|
||||
use,
|
||||
useActionState,
|
||||
useCallback,
|
||||
useContext,
|
||||
useDebugValue,
|
||||
useDeferredValue,
|
||||
useEffect,
|
||||
useId,
|
||||
useImperativeHandle,
|
||||
useInsertionEffect,
|
||||
useLayoutEffect,
|
||||
useMemo,
|
||||
useOptimistic,
|
||||
useReducer,
|
||||
useRef,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
useTransition,
|
||||
useViewTransition,
|
||||
reactAPICompatVersion as version
|
||||
};
|
||||
15
_node_modules/hono/dist/jsx/intrinsic-element/common.js
generated
vendored
Normal file
15
_node_modules/hono/dist/jsx/intrinsic-element/common.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
// src/jsx/intrinsic-element/common.ts
|
||||
var deDupeKeyMap = {
|
||||
title: [],
|
||||
script: ["src"],
|
||||
style: ["data-href"],
|
||||
link: ["href"],
|
||||
meta: ["name", "httpEquiv", "charset", "itemProp"]
|
||||
};
|
||||
var domRenderers = {};
|
||||
var dataPrecedenceAttr = "data-precedence";
|
||||
export {
|
||||
dataPrecedenceAttr,
|
||||
deDupeKeyMap,
|
||||
domRenderers
|
||||
};
|
||||
153
_node_modules/hono/dist/jsx/intrinsic-element/components.js
generated
vendored
Normal file
153
_node_modules/hono/dist/jsx/intrinsic-element/components.js
generated
vendored
Normal file
@@ -0,0 +1,153 @@
|
||||
// src/jsx/intrinsic-element/components.ts
|
||||
import { raw } from "../../helper/html/index.js";
|
||||
import { JSXNode, getNameSpaceContext } from "../base.js";
|
||||
import { toArray } from "../children.js";
|
||||
import { PERMALINK } from "../constants.js";
|
||||
import { useContext } from "../context.js";
|
||||
import { dataPrecedenceAttr, deDupeKeyMap } from "./common.js";
|
||||
var metaTagMap = /* @__PURE__ */ new WeakMap();
|
||||
var insertIntoHead = (tagName, tag, props, precedence) => ({ buffer, context }) => {
|
||||
if (!buffer) {
|
||||
return;
|
||||
}
|
||||
const map = metaTagMap.get(context) || {};
|
||||
metaTagMap.set(context, map);
|
||||
const tags = map[tagName] ||= [];
|
||||
let duped = false;
|
||||
const deDupeKeys = deDupeKeyMap[tagName];
|
||||
if (deDupeKeys.length > 0) {
|
||||
LOOP: for (const [, tagProps] of tags) {
|
||||
for (const key of deDupeKeys) {
|
||||
if ((tagProps?.[key] ?? null) === props?.[key]) {
|
||||
duped = true;
|
||||
break LOOP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (duped) {
|
||||
buffer[0] = buffer[0].replaceAll(tag, "");
|
||||
} else if (deDupeKeys.length > 0) {
|
||||
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 {
|
||||
const precedences = [];
|
||||
insertTags = tags.map(([tag2, , precedence2]) => {
|
||||
let order = precedences.indexOf(precedence2);
|
||||
if (order === -1) {
|
||||
precedences.push(precedence2);
|
||||
order = precedences.length - 1;
|
||||
}
|
||||
return [tag2, order];
|
||||
}).sort((a, b) => a[1] - b[1]).map(([tag2]) => tag2);
|
||||
}
|
||||
insertTags.forEach((tag2) => {
|
||||
buffer[0] = buffer[0].replaceAll(tag2, "");
|
||||
});
|
||||
buffer[0] = buffer[0].replace(/(?=<\/head>)/, insertTags.join(""));
|
||||
}
|
||||
};
|
||||
var returnWithoutSpecialBehavior = (tag, children, props) => raw(new JSXNode(tag, props, toArray(children ?? [])).toString());
|
||||
var documentMetadataTag = (tag, children, props, sort) => {
|
||||
if ("itemProp" in props) {
|
||||
return returnWithoutSpecialBehavior(tag, children, props);
|
||||
}
|
||||
let { precedence, blocking, ...restProps } = props;
|
||||
precedence = sort ? precedence ?? "" : void 0;
|
||||
if (sort) {
|
||||
restProps[dataPrecedenceAttr] = precedence;
|
||||
}
|
||||
const string = new JSXNode(tag, restProps, toArray(children || [])).toString();
|
||||
if (string instanceof Promise) {
|
||||
return string.then(
|
||||
(resString) => raw(string, [
|
||||
...resString.callbacks || [],
|
||||
insertIntoHead(tag, resString, restProps, precedence)
|
||||
])
|
||||
);
|
||||
} else {
|
||||
return raw(string, [insertIntoHead(tag, string, restProps, precedence)]);
|
||||
}
|
||||
};
|
||||
var title = ({ children, ...props }) => {
|
||||
const nameSpaceContext = getNameSpaceContext();
|
||||
if (nameSpaceContext) {
|
||||
const context = useContext(nameSpaceContext);
|
||||
if (context === "svg" || context === "head") {
|
||||
return new JSXNode(
|
||||
"title",
|
||||
props,
|
||||
toArray(children ?? [])
|
||||
);
|
||||
}
|
||||
}
|
||||
return documentMetadataTag("title", children, props, false);
|
||||
};
|
||||
var script = ({
|
||||
children,
|
||||
...props
|
||||
}) => {
|
||||
const nameSpaceContext = getNameSpaceContext();
|
||||
if (["src", "async"].some((k) => !props[k]) || nameSpaceContext && useContext(nameSpaceContext) === "head") {
|
||||
return returnWithoutSpecialBehavior("script", children, props);
|
||||
}
|
||||
return documentMetadataTag("script", children, props, false);
|
||||
};
|
||||
var style = ({
|
||||
children,
|
||||
...props
|
||||
}) => {
|
||||
if (!["href", "precedence"].every((k) => k in props)) {
|
||||
return returnWithoutSpecialBehavior("style", children, props);
|
||||
}
|
||||
props["data-href"] = props.href;
|
||||
delete props.href;
|
||||
return documentMetadataTag("style", children, props, true);
|
||||
};
|
||||
var 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);
|
||||
};
|
||||
var meta = ({ children, ...props }) => {
|
||||
const nameSpaceContext = getNameSpaceContext();
|
||||
if (nameSpaceContext && useContext(nameSpaceContext) === "head") {
|
||||
return returnWithoutSpecialBehavior("meta", children, props);
|
||||
}
|
||||
return documentMetadataTag("meta", children, props, false);
|
||||
};
|
||||
var newJSXNode = (tag, { children, ...props }) => (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
new JSXNode(tag, props, toArray(children ?? []))
|
||||
);
|
||||
var form = (props) => {
|
||||
if (typeof props.action === "function") {
|
||||
props.action = PERMALINK in props.action ? props.action[PERMALINK] : void 0;
|
||||
}
|
||||
return newJSXNode("form", props);
|
||||
};
|
||||
var formActionableElement = (tag, props) => {
|
||||
if (typeof props.formAction === "function") {
|
||||
props.formAction = PERMALINK in props.formAction ? props.formAction[PERMALINK] : void 0;
|
||||
}
|
||||
return newJSXNode(tag, props);
|
||||
};
|
||||
var input = (props) => formActionableElement("input", props);
|
||||
var button = (props) => formActionableElement("button", props);
|
||||
export {
|
||||
button,
|
||||
form,
|
||||
input,
|
||||
link,
|
||||
meta,
|
||||
script,
|
||||
style,
|
||||
title
|
||||
};
|
||||
0
_node_modules/hono/dist/jsx/intrinsic-elements.js
generated
vendored
Normal file
0
_node_modules/hono/dist/jsx/intrinsic-elements.js
generated
vendored
Normal file
18
_node_modules/hono/dist/jsx/jsx-dev-runtime.js
generated
vendored
Normal file
18
_node_modules/hono/dist/jsx/jsx-dev-runtime.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
// src/jsx/jsx-dev-runtime.ts
|
||||
import { jsxFn } from "./base.js";
|
||||
import { Fragment } from "./base.js";
|
||||
function jsxDEV(tag, props, key) {
|
||||
let node;
|
||||
if (!props || !("children" in props)) {
|
||||
node = jsxFn(tag, props, []);
|
||||
} else {
|
||||
const children = props.children;
|
||||
node = Array.isArray(children) ? jsxFn(tag, props, children) : jsxFn(tag, props, [children]);
|
||||
}
|
||||
node.key = key;
|
||||
return node;
|
||||
}
|
||||
export {
|
||||
Fragment,
|
||||
jsxDEV
|
||||
};
|
||||
41
_node_modules/hono/dist/jsx/jsx-runtime.js
generated
vendored
Normal file
41
_node_modules/hono/dist/jsx/jsx-runtime.js
generated
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
// src/jsx/jsx-runtime.ts
|
||||
import { jsxDEV, Fragment } from "./jsx-dev-runtime.js";
|
||||
import { jsxDEV as jsxDEV2 } from "./jsx-dev-runtime.js";
|
||||
import { html, raw } from "../helper/html/index.js";
|
||||
import { escapeToBuffer, stringBufferToString } from "../utils/html.js";
|
||||
import { styleObjectForEach } from "./utils.js";
|
||||
var jsxAttr = (key, v) => {
|
||||
const buffer = [`${key}="`];
|
||||
if (key === "style" && typeof v === "object") {
|
||||
let styleStr = "";
|
||||
styleObjectForEach(v, (property, value) => {
|
||||
if (value != null) {
|
||||
styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
|
||||
}
|
||||
});
|
||||
escapeToBuffer(styleStr, buffer);
|
||||
buffer[0] += '"';
|
||||
} else if (typeof v === "string") {
|
||||
escapeToBuffer(v, buffer);
|
||||
buffer[0] += '"';
|
||||
} else if (v === null || v === void 0) {
|
||||
return raw("");
|
||||
} else if (typeof v === "number" || v.isEscaped) {
|
||||
buffer[0] += `${v}"`;
|
||||
} else if (v instanceof Promise) {
|
||||
buffer.unshift('"', v);
|
||||
} else {
|
||||
escapeToBuffer(v.toString(), buffer);
|
||||
buffer[0] += '"';
|
||||
}
|
||||
return buffer.length === 1 ? raw(buffer[0]) : stringBufferToString(buffer, void 0);
|
||||
};
|
||||
var jsxEscape = (value) => value;
|
||||
export {
|
||||
Fragment,
|
||||
jsxDEV as jsx,
|
||||
jsxAttr,
|
||||
jsxEscape,
|
||||
html as jsxTemplate,
|
||||
jsxDEV2 as jsxs
|
||||
};
|
||||
143
_node_modules/hono/dist/jsx/streaming.js
generated
vendored
Normal file
143
_node_modules/hono/dist/jsx/streaming.js
generated
vendored
Normal file
@@ -0,0 +1,143 @@
|
||||
// src/jsx/streaming.ts
|
||||
import { raw } from "../helper/html/index.js";
|
||||
import { HtmlEscapedCallbackPhase, resolveCallback } from "../utils/html.js";
|
||||
import { JSXNode } from "./base.js";
|
||||
import { childrenToString } from "./components.js";
|
||||
import { DOM_RENDERER, DOM_STASH } from "./constants.js";
|
||||
import { createContext, useContext } from "./context.js";
|
||||
import { Suspense as SuspenseDomRenderer } from "./dom/components.js";
|
||||
import { buildDataStack } from "./dom/render.js";
|
||||
var StreamingContext = createContext(null);
|
||||
var suspenseCounter = 0;
|
||||
var Suspense = async ({
|
||||
children,
|
||||
fallback
|
||||
}) => {
|
||||
if (!Array.isArray(children)) {
|
||||
children = [children];
|
||||
}
|
||||
const nonce = useContext(StreamingContext)?.scriptNonce;
|
||||
let resArray = [];
|
||||
const stackNode = { [DOM_STASH]: [0, []] };
|
||||
const popNodeStack = (value) => {
|
||||
buildDataStack.pop();
|
||||
return value;
|
||||
};
|
||||
try {
|
||||
stackNode[DOM_STASH][0] = 0;
|
||||
buildDataStack.push([[], stackNode]);
|
||||
resArray = children.map(
|
||||
(c) => c == null || typeof c === "boolean" ? "" : c.toString()
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof Promise) {
|
||||
resArray = [
|
||||
e.then(() => {
|
||||
stackNode[DOM_STASH][0] = 0;
|
||||
buildDataStack.push([[], stackNode]);
|
||||
return childrenToString(children).then(popNodeStack);
|
||||
})
|
||||
];
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
} finally {
|
||||
popNodeStack();
|
||||
}
|
||||
if (resArray.some((res) => res instanceof Promise)) {
|
||||
const index = suspenseCounter++;
|
||||
const fallbackStr = await fallback.toString();
|
||||
return raw(`<template id="H:${index}"></template>${fallbackStr}<!--/$-->`, [
|
||||
...fallbackStr.callbacks || [],
|
||||
({ phase, buffer, context }) => {
|
||||
if (phase === HtmlEscapedCallbackPhase.BeforeStream) {
|
||||
return;
|
||||
}
|
||||
return Promise.all(resArray).then(async (htmlArray) => {
|
||||
htmlArray = htmlArray.flat();
|
||||
const content = htmlArray.join("");
|
||||
if (buffer) {
|
||||
buffer[0] = buffer[0].replace(
|
||||
new RegExp(`<template id="H:${index}"></template>.*?<!--/\\$-->`),
|
||||
content
|
||||
);
|
||||
}
|
||||
let html = buffer ? "" : `<template data-hono-target="H:${index}">${content}</template><script${nonce ? ` nonce="${nonce}"` : ""}>
|
||||
((d,c,n) => {
|
||||
c=d.currentScript.previousSibling
|
||||
d=d.getElementById('H:${index}')
|
||||
if(!d)return
|
||||
do{n=d.nextSibling;n.remove()}while(n.nodeType!=8||n.nodeValue!='/$')
|
||||
d.replaceWith(c.content)
|
||||
})(document)
|
||||
</script>`;
|
||||
const callbacks = htmlArray.map((html2) => html2.callbacks || []).flat();
|
||||
if (!callbacks.length) {
|
||||
return html;
|
||||
}
|
||||
if (phase === HtmlEscapedCallbackPhase.Stream) {
|
||||
html = await resolveCallback(html, HtmlEscapedCallbackPhase.BeforeStream, true, context);
|
||||
}
|
||||
return raw(html, callbacks);
|
||||
});
|
||||
}
|
||||
]);
|
||||
} else {
|
||||
return raw(resArray.join(""));
|
||||
}
|
||||
};
|
||||
Suspense[DOM_RENDERER] = SuspenseDomRenderer;
|
||||
var textEncoder = new TextEncoder();
|
||||
var renderToReadableStream = (content, onError = console.trace) => {
|
||||
const reader = new ReadableStream({
|
||||
async start(controller) {
|
||||
try {
|
||||
if (content instanceof JSXNode) {
|
||||
content = content.toString();
|
||||
}
|
||||
const context = typeof content === "object" ? content : {};
|
||||
const resolved = await resolveCallback(
|
||||
content,
|
||||
HtmlEscapedCallbackPhase.BeforeStream,
|
||||
true,
|
||||
context
|
||||
);
|
||||
controller.enqueue(textEncoder.encode(resolved));
|
||||
let resolvedCount = 0;
|
||||
const callbacks = [];
|
||||
const then = (promise) => {
|
||||
callbacks.push(
|
||||
promise.catch((err) => {
|
||||
console.log(err);
|
||||
onError(err);
|
||||
return "";
|
||||
}).then(async (res) => {
|
||||
res = await resolveCallback(
|
||||
res,
|
||||
HtmlEscapedCallbackPhase.BeforeStream,
|
||||
true,
|
||||
context
|
||||
);
|
||||
res.callbacks?.map((c) => c({ phase: HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
|
||||
resolvedCount++;
|
||||
controller.enqueue(textEncoder.encode(res));
|
||||
})
|
||||
);
|
||||
};
|
||||
resolved.callbacks?.map((c) => c({ phase: HtmlEscapedCallbackPhase.Stream, context })).filter(Boolean).forEach(then);
|
||||
while (resolvedCount !== callbacks.length) {
|
||||
await Promise.all(callbacks);
|
||||
}
|
||||
} catch (e) {
|
||||
onError(e);
|
||||
}
|
||||
controller.close();
|
||||
}
|
||||
});
|
||||
return reader;
|
||||
};
|
||||
export {
|
||||
StreamingContext,
|
||||
Suspense,
|
||||
renderToReadableStream
|
||||
};
|
||||
0
_node_modules/hono/dist/jsx/types.js
generated
vendored
Normal file
0
_node_modules/hono/dist/jsx/types.js
generated
vendored
Normal file
27
_node_modules/hono/dist/jsx/utils.js
generated
vendored
Normal file
27
_node_modules/hono/dist/jsx/utils.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// src/jsx/utils.ts
|
||||
var normalizeElementKeyMap = /* @__PURE__ */ new Map([
|
||||
["className", "class"],
|
||||
["htmlFor", "for"],
|
||||
["crossOrigin", "crossorigin"],
|
||||
["httpEquiv", "http-equiv"],
|
||||
["itemProp", "itemprop"],
|
||||
["fetchPriority", "fetchpriority"],
|
||||
["noModule", "nomodule"],
|
||||
["formAction", "formaction"]
|
||||
]);
|
||||
var normalizeIntrinsicElementKey = (key) => normalizeElementKeyMap.get(key) || key;
|
||||
var 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(
|
||||
/^(?: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
|
||||
);
|
||||
}
|
||||
};
|
||||
export {
|
||||
normalizeIntrinsicElementKey,
|
||||
styleObjectForEach
|
||||
};
|
||||
Reference in New Issue
Block a user