ranuts 0.3.0-alpha.1 → 0.4.0-alpha.2

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/CLAUDE.md CHANGED
@@ -27,14 +27,15 @@ from the **subpath that owns it** (below) — not from a deep source path.
27
27
  Each subpath is an independent, tree-shakeable barrel. Import from the subpath, never from
28
28
  `ranuts/dist/...` or `@/...` (that alias is internal to the source).
29
29
 
30
- | Import from | Source | What | Runtime |
31
- | --------------- | --------------------------- | --------------------------------------------------- | ---------------- |
32
- | `ranuts` | `index.ts` | Root barrel — re-exports the utils + visual surface | browser + node |
33
- | `ranuts/utils` | `src/utils/index.ts` | DOM/BOM, string, object, number, color, time, etc. | browser + node\* |
34
- | `ranuts/node` | `src/node/index.ts` | HTTP server, router, ws, fs, streams, middleware | **node only** |
35
- | `ranuts/visual` | `src/utils/visual/index.ts` | 2D rendering engine (Canvas / WebGL / WebGPU) | **browser only** |
36
- | `ranuts/i18n` | `src/utils/i18n.ts` | `I18nCore` / `createI18n` / `useI18n` — DOM-free | browser + node |
37
- | `ranuts/vnode` | `src/vnode/index.ts` | Snabbdom-style virtual DOM (`h`, `init`, modules) | browser |
30
+ | Import from | Source | What | Runtime |
31
+ | --------------- | --------------------------- | --------------------------------------------------- | ------------------ |
32
+ | `ranuts` | `index.ts` | Root barrel — re-exports the utils + visual surface | browser + node |
33
+ | `ranuts/utils` | `src/utils/index.ts` | DOM/BOM, string, object, number, color, time, etc. | browser + node\* |
34
+ | `ranuts/node` | `src/node/index.ts` | HTTP server, router, ws, fs, streams, middleware | **node only** |
35
+ | `ranuts/visual` | `src/utils/visual/index.ts` | 2D rendering engine (Canvas / WebGL / WebGPU) | **browser only** |
36
+ | `ranuts/i18n` | `src/utils/i18n.ts` | `I18nCore` / `createI18n` / `useI18n` — DOM-free | browser + node |
37
+ | `ranuts/sw` | `src/sw/index.ts` | Cache strategies + the precache protocol's SW half | **service worker** |
38
+ | `ranuts/vnode` | `src/vnode/index.ts` | Snabbdom-style virtual DOM (`h`, `init`, modules) | browser |
38
39
 
39
40
  \* `ranuts/utils` is broad: most functions are browser-oriented (touch `window`/`document`),
40
41
  but pure helpers (`str`, `obj`, `number`, `compose`, `cloneDeep`, …) run anywhere. Functions
@@ -153,15 +154,25 @@ Then `npm run doc:api`.
153
154
  - Never call `window.setTimeout` / `window.setInterval`. The bare globals work in Node, Web
154
155
  Workers and the browser alike; the `window.`-prefixed ones throw `ReferenceError` outside a
155
156
  document. (This is what made `throttle` unusable in SSR before 0.3.)
156
- - Keep `ranuts/node` server-only; never import it from browser-facing modules.
157
+ - Keep `ranuts/node` server-only; never import it from browser-facing modules. Same for
158
+ `ranuts/sw`: it runs in a `ServiceWorkerGlobalScope` with no `window`/`document`, which is
159
+ why it is its own entry rather than part of the utils barrel.
160
+
161
+ ### Ship both halves of a protocol, or neither
162
+
163
+ `WorkerClient` without `serveWorker` meant every worker re-implemented the same id echo and
164
+ error envelope — and each got to invent its own bug (a sync throw escaping the handler, a
165
+ rejection with no id so the caller waits forever). Same for `prefetchUrls({ serviceWorkerMessage })`
166
+ without `servePrecache`. When a helper defines a message shape, the counterpart that answers
167
+ it belongs in the library too; a JSDoc block saying "just echo the id back" is not a substitute.
157
168
 
158
169
  ### Anything that installs something must return how to uninstall it
159
170
 
160
171
  `debounce`, `throttle`, `watchMediaQuery`, `whenIdle`, `WorkerClient`, `QuestQueue` hand back
161
172
  something holding a timer, a listener or a worker. `replaceOld`, `handleConsole`,
162
- `handleFetchHook`, `handleXhrHook`, `handleError`, `handleClick` and `Monitor.start()` patch a
163
- global or register a listener. **All of them return a teardown function**, and callers are
164
- expected to use it.
173
+ `handleFetchHook`, `handleXhrHook`, `handleError`, `handleClick`, `serveWorker`,
174
+ `servePrecache` and `Monitor.start()` patch a global or register a listener. **All of them
175
+ return a teardown function**, and callers are expected to use it.
165
176
 
166
177
  A utility of this shape without a teardown path is incomplete. The failure modes are concrete:
167
178
  a pending timer firing into a destroyed component; a hot reload re-patching an already-patched