Searching Puzzle

Type to search Puzzle.

Puzzle

What Puzzle is, who it's for, and the shape of a Puzzle app in one page.

Puzzle is a SPA-first JavaScript framework built around single-file components, reactive data, and a Go-based compiler. You write .pzl files that hold a component's template, logic, and styles together, and the compiler turns them into a small, fast bundle. A minimal app is 23.0 KB gzip with the router, store, and validation included, and the complete todos example ships at 27.0 KB gzip.

Puzzle renders in the browser. There's no server-rendering layer to configure and no hydration protocol to reason about. When you need pages to ship as plain HTML, for a marketing site, docs, or SEO, the same app can prerender to static files: either a true static site with small per-page modules, or prerendered entry pages that wake up as a live SPA. One codebase, static where it can be and interactive where it needs to be.

What's in the box

  • Single-file components (.pzl): template, <script>, and optional <style> in one file. TypeScript and scoped styles are supported.
  • Reactive data: a component's data() method declares what it needs. When the underlying store records change, it re-runs and the view updates.
  • A data layer: models with a schema, computed properties, validation, and relationships, plus a store that can fetch what views read from your API and save what they change.
  • A router: nested routes, layouts, guards, lazy views, query-string state, scroll and focus management, and three modes (path, hash, and memory).
  • JavaScript-shaped templates: each brace holds one JavaScript-shaped expression, with string and array methods, arrow functions as call arguments, and a library of display functions ({ currency(price) }), plus translations through the t function.
  • Animations: declarative enter/leave animations, scroll reveals, and route transitions via the Web Animations API.
  • A CLI: dev (live reload), build (including static output), preview, check, plus scaffolding and diagnostics.

A component at a glance

<puzzle-view>
  <button class="counter" @click={ increment }>Clicked { count } times</button>
</puzzle-view>

<script>
import { PuzzleView } from '@magic-spells/puzzle';

export default class Counter extends PuzzleView {
  created() {
    this.setData({ count: 0 });
  }

  data(params, props) {
    return { count: this.getData().count };
  }

  events = {
    increment: () => {
      this.setData('count', this.getData().count + 1);
      this.refresh();
    },
  };
}
</script>

Three ideas run through everything below:

  1. One file per component. A .pzl is a single thing you read top to bottom.
  2. Data down, events up. Views compute their model in data(); interactions flow back out through plain event handlers and self-binding form inputs.
  3. Static when it can be. Content pages prerender to HTML; interactive pages stay live, with no second codebase.

Where to go next

Licensing

Puzzle is open source under the MIT license. See LICENSE.txt in the package for the full terms.