> For the complete documentation index, see [llms.txt](https://declarativas.mrbarry.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://declarativas.mrbarry.com/boilerplates/vanilla-html-js.md).

# Vanilla HTML/JS

## Single render drawing

```markup
<!doctype html>
<html>
<body>
<canvas></canvas>
<script type="module">
import { render, c } from 'https://unpkg.com/declarativas@^0.0.1-beta?module=1';

const canvas = document.querySelector('canvas');

render(
  canvas.getContext('2d'),
  [
    c('clearRect', {
      x: 0,
      y: 0,
      width: canvas.width,
      height: canvas.height,
    }),
    c('strokeStyle', { value: '#000' }),
    c('strokeRect', {
      x: 50,
      y: 50,
      width: 100,
      height: 100,
    })
  ]
);
</script>
</body>
</html>
```

## Render loop

```markup
<!doctype html>
<html>
<body>
<canvas width="640" height="480"></canvas>
<script type="module">
import { render, c } from 'https://unpkg.com/declarativas';

const makeApp = (canvas) => {
  const myApp = (previousState) => (timestamp) => {
    // -- state manipulation
    const delta = previousState.lastRender > 0
      ? ((timestamp - previousState.lastRender) / 1000)
      : 0;
    
    const state = {
      ...previousState,
      angle: (previousState.angle + (60 * delta)) % 360,
      lastRender: timestamp,
    };
    
    // -- render
    render(
      canvas.getContext('2d'),
      [
        c('save'),
        c('clearRect', {
          x: 0,
          y: 0,
          width: canvas.width,
          height: canvas.height,
        }),
        c('translate', { x: canvas.width / 2, y: canvas.height / 2 }),
        c('rotate', { value: state.angle * Math.PI / 180 }),
        c('fillStyle', { value: '#f0f' }),
        c('fillRect', {
          x: -50,
          y: -50,
          width: 100,
          height: 100,
        }),
        c('restore'),
      ]
    );
    
    requestAnimationFrame(
      myApp(nextState)
    );
  };
  
  return myApp;
};

const app = makeApp(document.querySelector('canvas'));
requestAnimationFrame(app({
  angle: 0,
  lastRender: 0,
}));

</script>
</body>
</html>
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://declarativas.mrbarry.com/boilerplates/vanilla-html-js.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
