aboutsummaryrefslogtreecommitdiffhomepage
path: root/services/blog/nuldoc-src/jsx
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-11-02 17:49:34 +0900
committernsfisis <nsfisis@gmail.com>2025-11-02 17:49:34 +0900
commit57315c52be96d2a2c013f0cfb0de5429980e301a (patch)
tree5d691497772fddfe401cd970ead4e9a74b34ef38 /services/blog/nuldoc-src/jsx
parentcf4091a93ed831456e8b30e2a9e1fc2650dcae02 (diff)
downloadnsfisis.dev-57315c52be96d2a2c013f0cfb0de5429980e301a.tar.gz
nsfisis.dev-57315c52be96d2a2c013f0cfb0de5429980e301a.tar.zst
nsfisis.dev-57315c52be96d2a2c013f0cfb0de5429980e301a.zip
refactor(blog): rename directory, services/{blog => nuldoc}/
Diffstat (limited to 'services/blog/nuldoc-src/jsx')
-rw-r--r--services/blog/nuldoc-src/jsx/jsx-runtime.ts27
-rw-r--r--services/blog/nuldoc-src/jsx/render.ts41
-rw-r--r--services/blog/nuldoc-src/jsx/types.d.ts84
3 files changed, 0 insertions, 152 deletions
diff --git a/services/blog/nuldoc-src/jsx/jsx-runtime.ts b/services/blog/nuldoc-src/jsx/jsx-runtime.ts
deleted file mode 100644
index 9571e87..0000000
--- a/services/blog/nuldoc-src/jsx/jsx-runtime.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import type { Node } from "../dom.ts";
-
-export type JSXElement = {
- tag: string | FunctionComponent;
- props: Props;
-};
-
-export type JSXNullNode = false | null | undefined;
-export type JSXSimpleNode = JSXElement | Node | string;
-export type JSXNullableSimpleNode = JSXSimpleNode | JSXNullNode;
-export type JSXNode = JSXNullableSimpleNode | JSXNode[];
-export type RenderableJSXNode = JSXElement;
-
-type Props = { children?: JSXNode } & Record<string, unknown>;
-export type FunctionComponentResult = JSXElement | Promise<JSXElement>;
-type FunctionComponent = (props: Props) => FunctionComponentResult;
-
-export function jsx(
- tag: string | FunctionComponent,
- props: Props,
-): JSXElement {
- return { tag, props };
-}
-
-export { jsx as jsxs };
-
-// TODO: support Fragment
diff --git a/services/blog/nuldoc-src/jsx/render.ts b/services/blog/nuldoc-src/jsx/render.ts
deleted file mode 100644
index a72d9ad..0000000
--- a/services/blog/nuldoc-src/jsx/render.ts
+++ /dev/null
@@ -1,41 +0,0 @@
-import type { Element, Node } from "../dom.ts";
-import { elem, text } from "../dom.ts";
-import type {
- JSXNode,
- JSXNullableSimpleNode,
- JSXSimpleNode,
- RenderableJSXNode,
-} from "myjsx/jsx-runtime";
-
-function transformNode(node: JSXNode): Promise<Node[]> {
- const flattenNodes: JSXNullableSimpleNode[] = Array.isArray(node)
- // @ts-ignore prevents infinite recursion
- ? (node.flat(Infinity) as JSXNullableSimpleNode[])
- : [node];
- return Promise.all(
- flattenNodes
- .filter((c): c is JSXSimpleNode => c != null && c !== false)
- .map((c) => {
- if (typeof c === "string") {
- return text(c);
- } else if ("kind" in c) {
- return c;
- } else {
- return renderToDOM(c);
- }
- }),
- );
-}
-
-export async function renderToDOM(
- element: RenderableJSXNode,
-): Promise<Element> {
- const { tag, props } = element;
- if (typeof tag === "string") {
- const { children, ...attrs } = props;
- const attrsMap = attrs as Record<string, string>;
- return elem(tag, attrsMap, ...(await transformNode(children)));
- } else {
- return renderToDOM(await tag(props));
- }
-}
diff --git a/services/blog/nuldoc-src/jsx/types.d.ts b/services/blog/nuldoc-src/jsx/types.d.ts
deleted file mode 100644
index 973b852..0000000
--- a/services/blog/nuldoc-src/jsx/types.d.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-import type {
- FunctionComponentResult,
- JSXElement,
- JSXNode,
-} from "myjsx/jsx-runtime";
-
-export { JSXNode };
-
-interface IntrinsicElementType {
- children?: JSXNode;
- className?: string;
- id?: string;
- // My JSX runtime does not use key. It is only for linter that complains about missing key.
- key?: string;
-}
-
-declare global {
- namespace JSX {
- type Element = JSXElement;
- type ElementType =
- | string
- // deno-lint-ignore no-explicit-any
- | ((props: any) => FunctionComponentResult);
-
- // TODO: HTML 用の element と XML 用の element を分ける
- interface IntrinsicElements {
- // XML (Atom)
- author: IntrinsicElementType;
- entry: IntrinsicElementType;
- feed: IntrinsicElementType & { xmlns: string };
- id: IntrinsicElementType;
- name: IntrinsicElementType;
- published: IntrinsicElementType;
- summary: IntrinsicElementType;
- updated: IntrinsicElementType;
- // HTML
- a: IntrinsicElementType & {
- href?: string;
- rel?: "noreferrer";
- target?: "_blank";
- };
- article: IntrinsicElementType;
- body: IntrinsicElementType;
- button: IntrinsicElementType & { type: string };
- canvas: { id?: string; "data-slide-link"?: string };
- div: IntrinsicElementType;
- footer: IntrinsicElementType;
- h1: IntrinsicElementType;
- h2: IntrinsicElementType;
- head: unknown;
- header: IntrinsicElementType;
- html: IntrinsicElementType & { lang?: string };
- img: { src: string };
- li: IntrinsicElementType;
- link: { rel: string; href: string; type?: string };
- main: IntrinsicElementType;
- meta: {
- charset?: string;
- name?: string;
- content?: string;
- property?: string;
- };
- nav: IntrinsicElementType;
- noscript: IntrinsicElementType;
- ol: IntrinsicElementType;
- p: IntrinsicElementType;
- script: { src: string; type?: string; defer?: "true" };
- section: IntrinsicElementType;
- span: IntrinsicElementType;
- time: IntrinsicElementType & { datetime?: string };
- title: IntrinsicElementType;
- ul: IntrinsicElementType;
- }
-
- interface ElementChildrenAttribute {
- children: unknown;
- }
-
- type LibraryManagedAttributes<_F, P> = P & {
- // My JSX runtime does not use key. It is only for linter that complains about missing key.
- key?: string;
- };
- }
-}