|
1 | 1 | <h1 id="api"><a href="#api">API</a></h1> |
2 | | -<div class="flash attention"> |
| 2 | +<section> |
| 3 | + <h2 id="api-user"><a href="#api-user">User API</a></h2> |
3 | 4 | <p> |
4 | | - This section has not been documented yet. |
| 5 | + This section is targeted at users who want to use <em>mizu.js</em> rendering and directives. |
5 | 6 | </p> |
6 | | -</div> |
7 | | -<p> |
8 | | - Full API documentation is available at <a href="https://jsr.io/@mizu/mizu/doc">jsr.io/@mizu/mizu</a>. |
9 | | -</p> |
| 7 | + <p> |
| 8 | + If you wish to develop custom directives, please refer to the <a href="#api-dev">Developer API</a> section instead. |
| 9 | + </p> |
| 10 | + <section> |
| 11 | + <h3 id="api-client"><a href="#api-client">Client-side API</a></h3> |
| 12 | + <p> |
| 13 | + There are two ways to setup <em>mizu.js</em> in a browser environment: |
| 14 | + <ul> |
| 15 | + <li><a href="https://developer.mozilla.org/docs/Glossary/IIFE">Immediately Invoked Function Expression (IIFE)</a></li> |
| 16 | + <li><a href="https://developer.mozilla.org/docs/Web/JavaScript/Guide/Modules">EcmaScript Module (ESM)</a></li> |
| 17 | + </ul> |
| 18 | + </p> |
| 19 | + <section> |
| 20 | + <h4 id="api-client-iife"><a href="#api-client-iife">IIFE <i>(<code>.js</code>)</i></a></h4> |
| 21 | + <p> |
| 22 | + In this setup <em>mizu.js</em> will automatically start rendering the page once the script is loaded. |
| 23 | + It is the simplest way to get started, but you will be limited to the default configuration. |
| 24 | + </p> |
| 25 | + <pre><code *code[html]><script src="https://mizu.sh/client.js" defer></script></code></pre> |
| 26 | + </section> |
| 27 | + <section> |
| 28 | + <h4 id="api-client-esm"><a href="#api-client-esm">ESM <i>(<code>.mjs</code>)</i></a></h4> |
| 29 | + <p> |
| 30 | + In this setup <em>mizu.js</em> needs to be imported and started manually. |
| 31 | + This allows you to customize the rendering process like setting the initial context, loading additional directives, etc. |
| 32 | + </p> |
| 33 | + <pre><code *clean.spaces> |
| 34 | + <span *code[html]><script type="module"></span><br> |
| 35 | + <span *code[ts]>import Mizu from "https://mizu.sh/client.mjs"</span><br> |
| 36 | + <span *code[ts]>await Mizu.render(document.body, { context: { foo: "🌊 Yaa, mizu!" } })</span><br> |
| 37 | + <span *code[html]></script></span> |
| 38 | + </code></pre> |
| 39 | + </section> |
| 40 | + <section> |
| 41 | + <h4 id="api-client-defaults"><a href="#api-client-defaults">Defaults</a></h4> |
| 42 | + <p> |
| 43 | + When using the client-side API, the following defaults are applied: |
| 44 | + <dl class="ml-1"> |
| 45 | + <dt>Rendering is explicit</dt> |
| 46 | + <dd>The <a href="#mizu"><code class="hljs-keyword">*mizu</code></a> attribute is required to enable <em>mizu.js</em> rendering on a subtree.</dd> |
| 47 | + <dt>Reactivity is enabled</dt> |
| 48 | + <dd>Changes performed to <a href="#concept-context">contexts</a> will trigger a re-render.</dd> |
| 49 | + </dl> |
| 50 | + </p> |
| 51 | + </section> |
| 52 | + <section> |
| 53 | + <h4 id="api-client-documentation"><a href="#api-client-documentation">Documentation</a></h4> |
| 54 | + <p> |
| 55 | + Full API documentation is available at <a href="https://jsr.io/@mizu/render/doc/client/~/Mizu">jsr.io/@mizu/render/client</a>. |
| 56 | + </p> |
| 57 | + </section> |
| 58 | + </section> |
| 59 | + <section> |
| 60 | + <h3 id="api-server"><a href="#api-server">Server-side API</a></h3> |
| 61 | + <p> |
| 62 | + To setup <em>mizu.js</em> in a server environment, you will need to install it locally. |
| 63 | + <em>mizu.js</em> packages are hosted on <a href="https://jsr.io/@mizu">jsr.io/@mizu</a>. |
| 64 | + </p> |
| 65 | + <section> |
| 66 | + <h4 id="api-server-deno"><a href="#api-server-deno">Deno</a></h4> |
| 67 | + <p> |
| 68 | + As <a href="https://deno.com/">Deno</a> supports <code>jsr:</code> specifier natively, you can import <em>mizu.js</em> directly. |
| 69 | + </p> |
| 70 | + <pre><code *code[ts]> |
| 71 | + import Mizu from "jsr:@mizu/render/server" |
| 72 | + await Mizu.render(`<div *text="foo"></div>`, { context: { foo: "🌊 Yaa, mizu!" } }) |
| 73 | + </code></pre> |
| 74 | + <p> |
| 75 | + Or you can add it to your project using the Deno CLI. |
| 76 | + </p> |
| 77 | + <pre><code *code[bash]> |
| 78 | + deno add jsr:@mizu/render |
| 79 | + </code></pre> |
| 80 | + </section> |
| 81 | + <section> |
| 82 | + <h4 id="api-server-others-runtimes"><a href="#api-server-others-runtimes">Other runtimes (NodeJS, Bun, etc.)</a></h4> |
| 83 | + <p> |
| 84 | + <em>mizu.js</em> can be added to your project using <a href="https://jsr.io/docs/npm-compatibility">JSR npm compatibility layer</a>. |
| 85 | + </p> |
| 86 | + <pre><code *code[bash]> |
| 87 | + # NodeJS |
| 88 | + npx jsr add @mizu/render |
| 89 | + </code></pre> |
| 90 | + <pre><code *code[bash]> |
| 91 | + # Bun |
| 92 | + bunx jsr add @mizu/render |
| 93 | + </code></pre> |
| 94 | + <p> |
| 95 | + Once installed, you can use it in your project. |
| 96 | + </p> |
| 97 | + <pre><code *code[ts]> |
| 98 | + import Mizu from "@mizu/render/server" |
| 99 | + await Mizu.render(`<div *text="foo"></div>`, { context: { foo: "🌊 Yaa, mizu!" } }) |
| 100 | + </code></pre> |
| 101 | + </section> |
| 102 | + <section> |
| 103 | + <h4 id="api-server-defaults"><a href="#api-server-defaults">Defaults</a></h4> |
| 104 | + <p> |
| 105 | + When using the server-side API, the following defaults are applied: |
| 106 | + <dl class="ml-1"> |
| 107 | + <dt>Rendering is implicit</dt> |
| 108 | + <dd>The <a href="#mizu"><code class="hljs-keyword">*mizu</code></a> attribute is <b>NOT</b> required to enable <em>mizu.js</em> rendering on a subtree.</dd> |
| 109 | + <dt>Reactivity is disabled</dt> |
| 110 | + <dd>Changes performed to <a href="#concept-context">contexts</a> are not tracked and will not trigger a re-render.</dd> |
| 111 | + </dl> |
| 112 | + </p> |
| 113 | + </section> |
| 114 | + <section> |
| 115 | + <h4 id="api-server-documentation"><a href="#api-server-documentation">Documentation</a></h4> |
| 116 | + <p> |
| 117 | + Full API documentation is available at <a href="https://jsr.io/@mizu/render/doc/server/~/Mizu">jsr.io/@mizu/render/server</a>. |
| 118 | + </p> |
| 119 | + </section> |
| 120 | + </section> |
| 121 | + <section> |
| 122 | + <h3 id="api-static"><a href="#api-static">Static generation API</a></h3> |
| 123 | + <p> |
| 124 | + The static generation API is an extension of the <a href="#api-server">server-side API</a> that allows you to render pages easily during your build process. |
| 125 | + </p> |
| 126 | + <section> |
| 127 | + <h4 id="api-static-documentation"><a href="#api-static-documentation">Documentation</a></h4> |
| 128 | + <p> |
| 129 | + Full API documentation is available at <a href="https://jsr.io/@mizu/render/doc/static/~/Mizu">jsr.io/@mizu/render/static</a>. |
| 130 | + </p> |
| 131 | + </section> |
| 132 | + </section> |
| 133 | +</section> |
| 134 | +<section> |
| 135 | + <h2 id="api-dev"><a href="#api-dev">Developer API</a></h2> |
| 136 | + <p> |
| 137 | + This section is targeted at developers who want to create custom <em>mizu.js</em> rendering and directives. |
| 138 | + </p> |
| 139 | + <p> |
| 140 | + If you wish to render templates, please refer to the <a href="#api-user">User API</a> section instead. |
| 141 | + </p> |
| 142 | + <div class="flash attention"> |
| 143 | + <p> |
| 144 | + This section has not been documented yet. |
| 145 | + </p> |
| 146 | + </div> |
| 147 | + <section *if="false"> |
| 148 | + <h3 id="api-directive"><a href="#api-directive">Directive API</a></h3> |
| 149 | + </section> |
| 150 | + <section *if="false"> |
| 151 | + <h3 id="api-renderer"><a href="#api-renderer">Renderer API</a></h3> |
| 152 | + </section> |
| 153 | + <section *if="false"> |
| 154 | + <h3 id="api-testing"><a href="#api-testing">Testing API</a></h3> |
| 155 | + </section> |
| 156 | +</section> |
0 commit comments