{"id":25504325,"url":"https://github.com/errilaz/squirt","last_synced_at":"2025-07-29T11:09:31.031Z","repository":{"id":86357850,"uuid":"606772565","full_name":"errilaz/squirt","owner":"errilaz","description":"HTML Over The Wire On The Bun","archived":false,"fork":false,"pushed_at":"2023-03-16T11:19:05.000Z","size":781,"stargazers_count":16,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-25T08:59:56.602Z","etag":null,"topics":["bun","civet","ssr"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/errilaz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-26T14:24:29.000Z","updated_at":"2025-03-02T01:36:15.000Z","dependencies_parsed_at":"2023-04-04T14:48:51.513Z","dependency_job_id":null,"html_url":"https://github.com/errilaz/squirt","commit_stats":{"total_commits":50,"total_committers":1,"mean_commits":50.0,"dds":0.0,"last_synced_commit":"f511e42f8eda387bcaf89f4143d87419dd0ad772"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/errilaz/squirt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/errilaz%2Fsquirt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/errilaz%2Fsquirt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/errilaz%2Fsquirt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/errilaz%2Fsquirt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/errilaz","download_url":"https://codeload.github.com/errilaz/squirt/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/errilaz%2Fsquirt/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267677314,"owners_count":24126313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bun","civet","ssr"],"created_at":"2025-02-19T05:35:05.492Z","updated_at":"2025-07-29T11:09:30.995Z","avatar_url":"https://github.com/errilaz.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"logo.png\" width=\"200\" height=\"200\"\u003e\n\n# Squirt\n\n\u003ca href=\"https://www.npmjs.com/package/@squirt/server\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@squirt/server?label=%40squirt%2Fserver\u0026style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/@squirt/markup\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/@squirt/markup?label=%40squirt%2Fmarkup\u0026style=flat-square\"\u003e\u003c/a\u003e\n\n\u003e HTML Over The Wire On The Bun\n\nSquirt is a (🚧 pre-alpha 🚧) do-everything SSR/HOTW/AHAH server and framework built on [Bun](https://bun.sh).\n\n- [Civet](https://civet.dev) support\n- Next/Astro-style filesystem routing\n- Live reload\n- Hyperscript-style HTML/CSS (all elements, properties, and at-rules are available on `globalThis` 😆)\n- SOON: tiny client-side runtime for declarative interactivity\n\n## Usage\n\n### Install\n\n```sh\nbun add @squirt/markup @squirt/server\n```\n\n### Types\n\nIf you are using TypeScript and/or Civet, configure your `tsconfig.json`:\n\n```json\n{\n  \"compilerOptions\": {\n    \"types\": [\n      \"bun-types\",\n      \"@squirt/markup\",\n      \"@squirt/server\"\n    ]\n  }\n}\n```\n\n### Use\n\n`bun run squirt`\n\n## Routing\n\nAll routes are contained in the `src/routes` directory of your project.\n\nFiles with a leading dot `.` or underscore `_` are ignored.\n\nFiles named `index.*` matching route patterns will act as default routes for the directory.\n\nAll routes are modules. Named exports matching HTTP methods (in lowercase) will route those methods (except for `export del` which will match `DELETE` requests.)\n\nPages and stylesheets can `export default` to match `GET`, while API routes with `export default` will match **all** methods. All WebSocket routes should `export default`, as `GET` is the only valid method to upgrade the connection.\n\nThe export can be an object or a function. If it is a function, it will be called and passed a `Context` object, which contains the `request`, `route`, and `url` properties. If the route is dynamic, a second object will be passed containing the route parameters and values.\n\nUse `src/public` for static files.\n\n### Page Routes\n\n- `*.html.ts`\n- `*.html.civet`\n- `*.html.js`\n\nPage routes return HTML, typically created with the [`@squirt/markup`](#markup) builder DSL. Simple example:\n\n```ts\n// index.html.ts\nexport default ({ url }) =\u003e [\n  doctype.html5,\n  html(\n    head(\n      title(\"hello world!\"),\n      liveReload(development),\n    ),\n    body(\n      div.hello(\n        `hello from ${url.pathname}!`,\n        color(\"lime\")\n      ),\n    ),\n  ),\n]\n```\n\nPage routes can also directly return a `Response` to override rendering.\n\n### Stylesheet Routes\n\n- `*.css.ts`\n- `*.css.civet`\n- `*.css.js`\n\nStylesheet routes return CSS, also typically created with the [`@squirt/markup`](#markup) builder DSL. Unlike other routes, the `.css` extension is matched in the URL.\n\n```ts\n// theme.css.ts\nexport default [\n  rule(\"body\",\n    backgroundColor(\"black\"),\n    color(\"silver\"),\n  )\n]\n```\n\n### API Routes\n\n- `*.api.ts`\n- `*.api.civet`\n- `*.api.js`\n\nAPI routes should return a Response object.\n\n```ts\n// echo.api.ts\nexport function get({ url }: Context) {\n  return new Response(url.search.substring(1))\n}\n```\n\n### WebSocket Routes\n\n- `*.socket.ts`\n- `*.socket.civet`\n- `*.socket.js`\n\nSocket routes should return an object with methods matching the [Bun WebSocket event handlers](https://bun.sh/docs/api/websockets):\n\n```ts\n// upper.socket.ts\nexport default \u003cSocketHandler\u003e{\n  open(ws) {\n    console.log(\"server socket connected\")\n  },\n  message(ws, message) {\n    ws.sendText(message.toString().toUpperCase())\n  },\n}\n```\n\n### Dynamic Routes\n\nRoutes can be parameterized with square-braced file or directory names (such as `[foo].api.ts` or `[user]/index.html.ts`) \n\n### Wildcard Routes\n\nRest-style dynamic routes work, as well: `[...myParam].html.ts`\n\n## Live Reload\n\nThe `liveReload()` function can be included in a page - this will embed a `\u003cscript\u003e` tag which reloads the page when the source changes. Currently this reloads any page when any source changes. You can pass an optional boolean to enable/disable this setting.\n\n## Globals\n\n- `root`: absolute path to the project's root directory.\n- `production`: true in production\n- `development`: true in development\n- `redirect(location: string, temporary: boolean = false)`: returns a 302 redirect `Response`, or 307 if `temporary` is `true`.\n\n### Extending Globals\n\nSquirt is crazy with globals, so it provides the ability to define your own. Project-specific globals can be defined in files matching these patterns:\n\n- `*.global.ts`\n- `*.global.civet`\n- `*.global.js`\n\nThese will work with Live Reload. You can use the default export with an object containing keys, or use named exports. Example:\n\n```ts\n// db.global.ts\nimport _db from \"./db\"\n\ndeclare global {\n  const db: typeof _db\n}\n\nexport default {\n  db: _db\n}\n```\n\n## Extending Context\n\nFiles matching these patterns are `Context` extensions:\n\n- `*.context.ts`\n- `*.context.civet`\n- `*.context.js`\n\nThese are run on each request to augment the `Context` object with your own values. They should export a default function which returns an object containing additional keys/values. Example:\n\n```ts\n// session.global.ts\ndeclare global {\n  // Augmenting the global Context with a possible session field\n  interface Context {\n    session?: MySessionType\n  }\n\n  // Creating a Context type for when session is known to be present\n  interface SessionContext extends Context {\n    session: MySessionType\n  }\n}\n\nexport default ({ request }: Context) =\u003e {\n  const session = getMySession(request)\n  return { session }\n}\n```\n\nHere is an example adding a utility for marking hyperlinks matching the current page with a CSS class:\n\n```ts\n// utility.context.ts\ndeclare global {\n  interface Context {\n    href(href: string): any\n  }\n}\n\nexport default ({ url }: Context) =\u003e ({\n  href(href: string) {\n    return [{ href }, url.pathname === href \u0026\u0026 { class: \"current\" }]\n  }\n})\n```\n\nWhich can be then used in `a` elements:\n\n```ts\na(\"Profile\", context.href(\"/profile\")),\na(\"Inbox\", context.href(\"/inbox\")),\n```\n\n\n## Layouts \u0026 Partials\n\nLayouts and partial views can be simply be defined as functions and imported.\n\n```ts\n// site.layout.ts\nexport default (_title: any, _content: any) =\u003e [\n  doctype.html5,\n  html(\n    head(\n      meta({ charset: \"UTF-8\" }),\n      meta({ name: \"viewport\", content: \"width=device-width, initial-scale=1.0\" }),\n      title(_title),\n      liveReload(development),\n    ),\n    body(_content),\n  )\n]\n```\n\n## Markup\n\nAll HTML element and CSS property/at-rule names are defined globally as functions which create virtual DOM nodes. At render time, these are converted to HTML and CSS.\n\nTypeScript/JavaScript example:\n\n```ts\ndiv(\n  span(\"Password: \"),\n  input({ type: \"password\" })\n  style(\n    rule.someClass(\n      color.red,\n    ),\n  ),\n)\n```\n\nCivet example:\n\n```coffee\ndiv [\n  span \"Password: \"\n  input { type: \"password\" }\n  style [\n    rule \".some-class\",\n      color.red\n  ]\n]\n```\n\nStrings, numbers, arrays, etc. are supported as children. `null`, `undefined`, and `false` will render as empty. Anything unrecognized will be converted with `.toString()`. Attributes are defined with plain `{}` objects. Multiple objects can be defined for conveninent composition, and these can appear *after* child elements, text nodes, etc.\n\n```ts\na.someClass(\"My Link\", { href: \"/my_link\" }, { class: \"another-class\" })\n```\n\nThe `raw` function will skip HTML escaping for its contents:\n\n```ts\nraw(\"\u003cspan\u003ehello!\u003c/span\u003e\")\n```\n\nThe `var` element is named `_var` due to conflict with the JS keyword.\n\n### Element Class Shorthand\n\nYou can apply classes directly to element functions:\n\n```ts\ndiv(\n  div.redBold(\"this is bold and red!\"),\n  div.redBold.alsoItalic(\"this has two classes!\")\n)\n```\n\nClass names are automatically converted to `kebab-case`.\n\n### Styles\n\nAll standard and known vendor-specific CSS properties are global functions:\n\n```ts\ncolor(\"#ff0000\"),\nborder(\"solid 1px red\"),\nwebkitBorderImageWidth(\"4px\"),\n_continue(\"auto\"),  // conflicts with JS keywords are prefixed with underscore\n```\n\nStandard values are also available as properties on these functions:\n\n```ts\ncolor.red,\nborderStyle.dashed,\n_continue.auto,\n```\n\n#### Rules\n\nThe `rule` function can be used within style elements to define CSS rules. Custom properties may use the `prop` function.\n\n```ts\nstyle(\n  rule(\".red-bold\",\n    color.red,\n    fontWeight.bold,\n    prop(\"-some-nonstandard\", \"value\"),\n  )\n)\n```\n\n#### Rule Shorthand Selectors\n\nElement functions may be used as selectors:\n\n```ts\nrule(textarea,\n  borderColor.black,\n)\n```\n\nClass names may be used as selectors (these are converted to `kebab-case`):\n\n```ts\nrule.container(\n  width(\"1200px\"),\n)\n```\n\n### Inline Styles\n\nYou can add CSS properties directly to elements:\n\n```ts\ndiv(\n  color.red,\n  fontWeight.bold,\n  \"this is bold and red!\",\n)\n```\n\n### Nested Rules\n\nRules may be nested:\n\n```ts\nrule(\".danger\",\n  color.red,\n  rule(\".icon\",\n    float.right,\n  ),\n)\n```\n\nChild selectors can be combined with the parent selector, similar to Sass and Less.js. This example produces two rules, the second with the selector `.danger.large`:\n\n```ts\nrule(\".danger\",\n  color.red,\n  rule(\"\u0026.large\",\n    fontSize(\"40px\")\n  ),\n)\n```\n\nNested selectors with pseudo-classes do the same:\n\n```ts\nrule(a,\n  color.red,\n  textDecorationLine.none,\n  rule(\":hover\",\n    textDecorationLine.underline,\n  ),\n)\n```\n\nSquirt detects multiple selectors in a rule and will generate the necessary CSS:\n\n```ts\nrule(\"input, textarea\",\n  border(\"solid 1px gray\"),\n  rule(\":hover, :focus\",\n    borderColor.black,\n  ),\n)\n```\n\n### At-rules\n\nMedia queries and other [at-rules](https://developer.mozilla.org/en-US/docs/Web/CSS/At-rule) are supported\nwith the `$` prefix: \n\n```ts\n$media(\"(prefers-color-scheme: dark)\",\n  rule(\":root\",\n    prop(\"--fg\", \"white\"),\n    prop(\"--bg\", \"black\"),\n  ),\n)\n```\n\n```ts\n$layer(\n  rule(\"p\",\n    color.red,\n  )\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferrilaz%2Fsquirt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferrilaz%2Fsquirt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferrilaz%2Fsquirt/lists"}