tutuca 0.9.91 → 0.9.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tutuca",
3
- "version": "0.9.91",
3
+ "version": "0.9.92",
4
4
  "type": "module",
5
5
  "description": "Zero-dependency SPA framework with immutable state and virtual DOM",
6
6
  "main": "./dist/tutuca.js",
@@ -21,7 +21,8 @@ When authoring tutuca code, also load these if available:
21
21
  values.
22
22
  - **margaui** — the Tailwind v4 / daisyUI-compatible class library.
23
23
  Reach for it when the project uses MargaUI / Tailwind class lists in
24
- `class=` / `:class=`.
24
+ `class=` / `:class=`. See [margaui.md](./margaui.md) to set it up in a
25
+ project and wire it into tutuca.
25
26
 
26
27
  ## Routing
27
28
 
@@ -32,7 +33,8 @@ When authoring tutuca code, also load these if available:
32
33
  | CLI commands, flags, exit codes, full linter rule list | [cli.md](./cli.md) |
33
34
  | Authoring `*.dev.js` story modules, `getExamples()` sections, per-example request mocking, running `tutuca storybook` | [storybook.md](./storybook.md) |
34
35
  | `bubble` / `send`-`receive` / async `request`-`response` channels, `$unknown`, request-handler registration | [request-response.md](./request-response.md) |
35
- | Drag & drop, dynamic bindings (`*x`), pseudo-`x`, custom seq types, Tailwind/MargaUI | [advanced.md](./advanced.md) |
36
+ | Drag & drop, dynamic bindings (`*x`), pseudo-`x`, custom seq types | [advanced.md](./advanced.md) |
37
+ | Setting up MargaUI styling — install (CDN / npm / vendoring), theme CSS, and the `compileClassesToStyleText` wiring | [margaui.md](./margaui.md) |
36
38
  | Runtime semantics — path steps, transaction lifecycle, dyn-var teleporting, async key pinning (`livePath`) | [semantics.md](./semantics.md) |
37
39
  | Authoring tests — `getTests` shape, calling methods/input/receive/bubble/response/alter handlers, designing handlers for testability | [testing.md](./testing.md) |
38
40
  | Task-oriented recipes — iteration, filtering, conditional content, conditional attributes, dynamic vars, composition, events | [patterns/README.md](./patterns/README.md) |
@@ -2,9 +2,9 @@
2
2
 
3
3
  Reach this file only when the task touches drag & drop, context-style
4
4
  "dynamic bindings", pseudo-`x` (the `<x>`-stripping workaround inside
5
- `<select>`/`<table>`/`<tr>`), registering a custom seq type, or
6
- compiling Tailwind / MargaUI classes. For everything else, `core.md`
7
- is the right place.
5
+ `<select>`/`<table>`/`<tr>`), or registering a custom seq type. For
6
+ compiling Tailwind / MargaUI classes see [margaui.md](./margaui.md); for
7
+ everything else, `core.md` is the right place.
8
8
 
9
9
  ## Drag and Drop
10
10
 
@@ -190,37 +190,6 @@ whose entries resolve `@key` in event handlers.
190
190
 
191
191
  ## Tailwind / MargaUI Class Compilation (extra build)
192
192
 
193
- ```js
194
- import { compileClassesToStyleText, injectCss, tutuca } from "tutuca/extra";
195
- import { compile } from "https://cdn.jsdelivr.net/npm/margaui/+esm";
196
-
197
- const app = tutuca("#app");
198
- app.registerComponents([Comp]);
199
- const css = await compileClassesToStyleText(app, compile);
200
- injectCss("myapp", css);
201
- app.start();
202
- ```
203
-
204
- `compileClassesToStyleText` walks every registered component's templates,
205
- collects the `class=` and `:class=` literals, hands them to a `compile`
206
- function (any margaui-compatible signature), and returns CSS text. Pair
207
- with `injectCss(scopeName, css)` to install the result before `start()`.
208
-
209
- If a margaui skill is available, load it alongside this one when
210
- authoring class lists — it lists the available components and their
211
- canonical class strings, which is what the `compile` step expects.
212
-
213
- **Pitfall: `@if.class` payloads are invisible to the scanner.** Classes
214
- inside `@then` / `@else` (e.g. `@if.class=".active" @then="'btn-success'"
215
- @else="'btn-ghost'"`) are not literals in `class=` / `:class=`, so
216
- `compileClassesToStyleText` skips them and the margaui CSS for those
217
- classes is never emitted — the conditional class renders unstyled.
218
- Workaround: add a hidden "decoy" view on the component that lists every
219
- conditional class as a real literal, so the walker picks them up:
220
-
221
- ```js
222
- _margauiClasses: html`<p class="btn-success btn-ghost on off"></p>`,
223
- ```
224
-
225
- The view does not need to be rendered anywhere — registration is enough
226
- for the template walker to find it.
193
+ Moved to [margaui.md](./margaui.md) — installing margaui (CDN / npm /
194
+ vendoring), the theme CSS, the `compileClassesToStyleText` + `injectCss`
195
+ wiring, and the `@if.class` decoy-view pitfall.
@@ -11,8 +11,9 @@ the `tutuca` CLI.
11
11
  > `request`/`response`, the `$unknown` fallback, and request-handler
12
12
  > registration: see [request-response.md](./request-response.md).
13
13
  > Advanced topics (drag & drop, dynamic bindings `*x`, pseudo-`x` for
14
- > `<select>`/`<table>`/`<tr>`, custom seq types, Tailwind/MargaUI
15
- > compilation): see [advanced.md](./advanced.md). CLI commands, flags,
14
+ > `<select>`/`<table>`/`<tr>`, custom seq types): see
15
+ > [advanced.md](./advanced.md). Setting up Tailwind/MargaUI styling: see
16
+ > [margaui.md](./margaui.md). CLI commands, flags,
16
17
  > exit codes, and full linter rule list: see [cli.md](./cli.md).
17
18
  > Authoring tests — `getTests` shape, calling methods/input/receive/
18
19
  > bubble/response/alter handlers, designing for testability: see
@@ -827,6 +828,9 @@ component({
827
828
  Tagged templates `html` and `css` are just `String.raw` (editor hinting
828
829
  only). Plain strings work too.
829
830
 
831
+ For Tailwind / MargaUI utility classes (compiling `class=` literals into
832
+ CSS via the extra build), see [margaui.md](./margaui.md).
833
+
830
834
  ## Triggers and Handlers
831
835
 
832
836
  Tutuca has four orchestration channels. Each one pairs a trigger with
@@ -1056,8 +1060,9 @@ consumed by the shipped `tutuca/storybook` library (`mountStorybook`,
1056
1060
  `request`-`response` channels, the `ctx.at` `PathBuilder`, `$unknown`, and
1057
1061
  request-handler registration.
1058
1062
  - [advanced.md](./advanced.md) — dynamic bindings (`*x`), pseudo-`@x` for
1059
- `<select>` / `<table>` / `<tr>`, drag & drop, custom seq types, Tailwind /
1060
- MargaUI compilation.
1063
+ `<select>` / `<table>` / `<tr>`, drag & drop, custom seq types.
1064
+ - [margaui.md](./margaui.md) — setting up MargaUI styling: install
1065
+ (CDN / npm / vendoring), theme CSS, and `compileClassesToStyleText`.
1061
1066
  - [semantics.md](./semantics.md) — runtime semantics: path steps, the
1062
1067
  transaction lifecycle, dyn-var teleporting, and async key pinning
1063
1068
  (`livePath`).
@@ -0,0 +1,124 @@
1
+ # Tutuca — MargaUI Styling
2
+
3
+ Reach this file to add **MargaUI** (the Tailwind v4 / daisyUI-compatible
4
+ class library) styling to a tutuca app: get margaui into the project,
5
+ link its theme, and let tutuca's extra build compile the utility classes
6
+ it finds in your views into CSS. If you only need scoped/global component
7
+ CSS, the `## Styles` section in [core.md](./core.md) is enough.
8
+
9
+ ## Get margaui
10
+
11
+ margaui ships two pieces: a `compile` function (class names → CSS text)
12
+ and a `theme.css` stylesheet. Pick one of three ways to obtain them.
13
+
14
+ ### CDN (no install)
15
+
16
+ Nothing to install — import from jsDelivr and link the theme. tutuca's
17
+ extra build is on the CDN too:
18
+
19
+ ```html
20
+ <link
21
+ rel="stylesheet"
22
+ href="https://marianoguerra.github.io/margaui/themes/theme.css"
23
+ />
24
+ <script type="module">
25
+ import { compile } from "https://cdn.jsdelivr.net/npm/margaui/+esm";
26
+ import {
27
+ compileClassesToStyleText,
28
+ injectCss,
29
+ tutuca,
30
+ } from "https://cdn.jsdelivr.net/npm/tutuca/dist/tutuca-extra.js/+esm";
31
+ // …wire it up (see below)
32
+ </script>
33
+ ```
34
+
35
+ See `docs/examples/getting-started-margaui.html` for a complete runnable page.
36
+
37
+ ### npm
38
+
39
+ Install both as dev dependencies and import via bare specifiers:
40
+
41
+ ```sh
42
+ npm i --save-dev tutuca margaui
43
+ ```
44
+
45
+ ```js
46
+ import { compileClassesToStyleText, injectCss, tutuca } from "tutuca/extra";
47
+ import { compile } from "margaui";
48
+ ```
49
+
50
+ Serve or copy the theme from `node_modules/margaui` into your build, or
51
+ keep linking the GitHub Pages `theme.css` shown above.
52
+
53
+ ### Vendoring
54
+
55
+ Copy a prebuilt `margaui.min.js` and a `theme.css` into the project and
56
+ import from the local path — useful for offline builds or pinning an
57
+ exact version (this repo vendors `docs/deps/margaui.min.js` for exactly
58
+ that reason):
59
+
60
+ ```html
61
+ <link rel="stylesheet" href="./vendor/theme.css" />
62
+ <script type="module">
63
+ import { compile } from "./vendor/margaui.min.js";
64
+ // …
65
+ </script>
66
+ ```
67
+
68
+ Trade-off: no runtime network dependency and a frozen version, at the
69
+ cost of updating the vendored files by hand.
70
+
71
+ ## Wire it into tutuca
72
+
73
+ However you obtained `compile`, the integration is the same: register
74
+ your components, compile the classes their views reference, inject the
75
+ resulting CSS, then start.
76
+
77
+ ```js
78
+ import { compileClassesToStyleText, injectCss, tutuca } from "tutuca/extra";
79
+ import { compile } from "margaui"; // or the CDN / vendored path
80
+
81
+ const app = tutuca("#app");
82
+ app.registerComponents([Comp]);
83
+ const css = await compileClassesToStyleText(app, compile);
84
+ injectCss("myapp", css);
85
+ app.start();
86
+ ```
87
+
88
+ `compileClassesToStyleText` walks every registered component's templates,
89
+ collects the `class=` and `:class=` literals, hands them to a `compile`
90
+ function (any margaui-compatible signature), and returns CSS text. Pair
91
+ with `injectCss(scopeName, css)` to install the result before `start()`.
92
+
93
+ When authoring class lists, load the margaui skill alongside this one if
94
+ available (`npx tutuca install-skill --margaui-skill`) — it lists the
95
+ available components and their canonical class strings, which is what the
96
+ `compile` step expects.
97
+
98
+ ## Pitfall: @if.class is invisible to the scanner
99
+
100
+ Classes inside `@then` / `@else` (e.g.
101
+ `@if.class=".active" @then="'btn-success'" @else="'btn-ghost'"`) are not
102
+ literals in `class=` / `:class=`, so `compileClassesToStyleText` skips
103
+ them and the margaui CSS for those classes is never emitted — the
104
+ conditional class renders unstyled. Workaround: add a hidden "decoy" view
105
+ on the component that lists every conditional class as a real literal, so
106
+ the walker picks them up:
107
+
108
+ ```js
109
+ _margauiClasses: html`<p class="btn-success btn-ghost on off"></p>`,
110
+ ```
111
+
112
+ The view does not need to be rendered anywhere — registration is enough
113
+ for the template walker to find it. (This is the same rule
114
+ [component-design.md](./component-design.md) gives for runtime-assembled
115
+ margaui classes.)
116
+
117
+ ## See also
118
+
119
+ - [core.md](./core.md) — `## Styles` for scoped/global component CSS.
120
+ - [advanced.md](./advanced.md) — dynamic bindings, drag & drop, custom
121
+ seq types, and other advanced view features.
122
+ - [cli.md](./cli.md) — `tutuca storybook` wires margaui by default
123
+ (`--no-margaui` to skip); `install-skill --margaui-skill` installs the
124
+ margaui skill.