This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Hono } from 'hono' | |
import { handle } from 'hono/cloudflare-pages' | |
const app = new Hono().basePath('/api') | |
app.get('/', (c) => { | |
return c.json({ | |
from: 'hono' | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { css } from 'hono/css' | |
import { useState } from 'hono/jsx' | |
import { marked } from 'marked' | |
const classContentTextarea = css` | |
padding: 0.5rem; | |
border-color: rgb(209 213 219); | |
border-width: 1px; | |
border-radius: 0.375rem; | |
width: 80%; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { type ExportedHandler } from '@cloudflare/workers-types' | |
import { Ai } from '@cloudflare/ai' | |
type Env = { | |
AI: any | |
} | |
export default { | |
fetch: async (req, env) => { | |
const ai = new Ai(env.AI) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState, startViewTransition, Suspense } from 'hono/jsx' | |
import { use } from 'hono/jsx' | |
import { render } from 'hono/jsx/dom' | |
import { Style, css, keyframes } from 'hono/css' | |
const App = () => { | |
const [show, setShow] = useState(false) | |
return ( | |
<div onClick={() => startViewTransition(() => setShow(!show))}> | |
{show ? ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function streamToElement(response: Response, element: HTMLElement) { | |
if (response.body) { | |
const reader = response.body.getReader() | |
const decoder = new TextDecoder('utf-8') | |
while (true) { | |
const { done, value } = await reader.read() | |
if (done) break | |
const text = decoder.decode(value, { stream: true }) | |
const textNode = document.createTextNode(text) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fs from 'fs/promises' | |
import { parse } from '@babel/parser' | |
import _traverse from '@babel/traverse' | |
const traverse = _traverse.default | |
import _generate from '@babel/generator' | |
const generate = _generate.default | |
import * as t from '@babel/types' | |
import type { Plugin } from 'vite' | |
function wrapRenderMethod(ast: t.File, componentName: string) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface JSXNode { | |
tag: keyof HTMLElementTagNameMap | |
props?: { [key: string]: any } | |
children?: (JSXNode | string)[] | |
} | |
export class Component { | |
public elements: HTMLElement[] = [] | |
public render(): JSX.Element { | |
return <></> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @jsxImportSource hono/jsx */ | |
import './style.css' | |
import { Component, render } from './front' | |
class Counter extends Component { | |
count = 0 | |
increment() { | |
this.count++ | |
this.update() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Context, MiddlewareHandler } from 'hono' | |
import React, { ReactElement } from 'react' | |
import { renderToString, renderToReadableStream } from 'react-dom/server' | |
declare module 'hono' { | |
interface ContextRenderer { | |
(children: React.ReactElement, props: Props): Response | Promise<Response> | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Hono } from 'hono' | |
import type { H, MiddlewareHandler } from 'hono/types' | |
const METHODS = ['GET', 'POST', 'PUT', 'DELETE'] as const | |
type RouteFile = { | |
default?: Hono | Function | |
} & { [M in (typeof METHODS)[number]]?: H[] } | |
type RendererFile = { |