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 +23 -12
- package/dist/{color-Dohr9BXX.js → color-Bh_QUad2.js} +1 -1
- package/dist/i18n-D1p8_7wC.js +1 -0
- package/dist/index.js +1 -1
- package/dist/src/node/index.js +1 -1
- package/dist/src/sw/index.d.ts +109 -0
- package/dist/src/sw/index.js +1 -0
- package/dist/src/utils/dom.d.ts +23 -0
- package/dist/src/utils/file.d.ts +7 -2
- package/dist/src/utils/i18n/index.js +1 -1
- package/dist/src/utils/i18n.d.ts +64 -14
- package/dist/src/utils/idb.d.ts +40 -0
- package/dist/src/utils/index.d.ts +15 -10
- package/dist/src/utils/index.js +1 -1
- package/dist/src/utils/paginate.d.ts +73 -0
- package/dist/src/utils/speech.d.ts +86 -0
- package/dist/src/utils/str.d.ts +35 -0
- package/dist/src/utils/time.d.ts +73 -3
- package/dist/src/utils/worker.d.ts +49 -0
- package/dist/test/sw.test.d.ts +1 -0
- package/dist/test/utils/autosize.test.d.ts +1 -0
- package/dist/test/utils/i18n.test.d.ts +1 -0
- package/dist/test/utils/idb-collection.test.d.ts +1 -0
- package/dist/test/utils/paginate.test.d.ts +1 -0
- package/dist/test/utils/speech.test.d.ts +1 -0
- package/dist/test/utils/time.test.d.ts +1 -0
- package/dist/test/utils/truncate.test.d.ts +1 -0
- package/dist/test/utils/worker-serve.test.d.ts +1 -0
- package/dist/umd/index.umd.cjs +1 -1
- package/dist/umd/utils/utils.umd.cjs +1 -1
- package/dist/utils-vTF6lLZZ.js +1 -0
- package/docs/API.md +65 -13
- package/package.json +5 -1
- package/dist/i18n-Cf5TtRb4.js +0 -1
- package/dist/utils-BDtXHcK8.js +0 -1
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/
|
|
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
|
|
163
|
-
global or register a listener. **All of them
|
|
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
|