ranuts 0.1.0-alpha.9 → 1.0.0-beta-1

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.
Files changed (179) hide show
  1. package/CLAUDE.md +164 -0
  2. package/README.md +116 -0
  3. package/{readme.md → README.zh-CN.md} +43 -12
  4. package/dist/bin/generate-api-docs.d.ts +1 -0
  5. package/dist/build/build.es.d.ts +2 -0
  6. package/dist/build/build.umd.d.ts +2 -0
  7. package/dist/build/build.umd.node.d.ts +2 -0
  8. package/dist/build/build.umd.utils.d.ts +2 -0
  9. package/dist/color-CRdlaDqQ.js +1 -0
  10. package/dist/examples/clone-deep-example.d.ts +1 -0
  11. package/dist/examples/is-equal-example.d.ts +1 -0
  12. package/dist/index.d.ts +5 -21
  13. package/dist/index.js +1 -2484
  14. package/dist/plugins/vite-plugins-banner.d.ts +2 -0
  15. package/dist/rolldown-runtime-I3TIJKkN.js +1 -0
  16. package/dist/src/node/appendFile.d.ts +7 -0
  17. package/dist/src/node/body.d.ts +9 -0
  18. package/dist/src/node/color.d.ts +7 -0
  19. package/dist/src/node/command.d.ts +8 -0
  20. package/dist/src/node/ctx2req.d.ts +5 -0
  21. package/dist/src/node/fileInfo.d.ts +7 -0
  22. package/dist/src/node/fs.d.ts +7 -0
  23. package/dist/src/node/get.d.ts +10 -0
  24. package/dist/src/node/getIPAdress.d.ts +1 -0
  25. package/dist/src/node/index.d.ts +25 -0
  26. package/dist/src/node/index.js +1 -0
  27. package/dist/src/node/isColorSupported.d.ts +2 -0
  28. package/dist/src/node/paresUrl.d.ts +19 -0
  29. package/dist/src/node/readDir.d.ts +6 -0
  30. package/dist/src/node/readFile.d.ts +9 -0
  31. package/dist/src/node/router.d.ts +42 -0
  32. package/dist/src/node/send.d.ts +7 -0
  33. package/dist/src/node/server.d.ts +18 -0
  34. package/dist/src/node/startTask.d.ts +2 -0
  35. package/dist/src/node/stream.d.ts +15 -0
  36. package/dist/src/node/taskEnd.d.ts +2 -0
  37. package/dist/src/node/traverse.d.ts +17 -0
  38. package/dist/src/node/watchFile.d.ts +8 -0
  39. package/dist/src/node/writeFile.d.ts +8 -0
  40. package/dist/src/node/ws.d.ts +8 -0
  41. package/dist/src/utils/audioRecorder.d.ts +16 -0
  42. package/dist/src/utils/behavior.d.ts +15 -0
  43. package/dist/src/utils/bom.d.ts +294 -0
  44. package/dist/src/utils/color.d.ts +71 -0
  45. package/dist/src/utils/compose.d.ts +10 -0
  46. package/dist/src/utils/console.d.ts +1 -0
  47. package/dist/src/utils/debounce.d.ts +7 -0
  48. package/dist/src/utils/device.d.ts +25 -0
  49. package/dist/src/utils/dom.d.ts +105 -0
  50. package/dist/src/utils/error.d.ts +1 -0
  51. package/dist/src/utils/func.d.ts +1 -0
  52. package/dist/src/utils/img.d.ts +16 -0
  53. package/dist/src/utils/index.d.ts +35 -0
  54. package/dist/src/utils/index.js +1 -0
  55. package/dist/src/utils/memoize.d.ts +7 -0
  56. package/dist/src/utils/mimeType.d.ts +9 -0
  57. package/dist/src/utils/monitor.d.ts +38 -0
  58. package/dist/src/utils/network.d.ts +39 -0
  59. package/dist/src/utils/noop.d.ts +2 -0
  60. package/dist/src/utils/number.d.ts +45 -0
  61. package/dist/src/utils/obj.d.ts +83 -0
  62. package/dist/src/utils/performance.d.ts +21 -0
  63. package/dist/src/utils/queue.d.ts +33 -0
  64. package/dist/src/utils/report.d.ts +8 -0
  65. package/dist/src/utils/request.d.ts +17 -0
  66. package/dist/src/utils/script.d.ts +7 -0
  67. package/dist/src/utils/signal.d.ts +6 -0
  68. package/dist/src/utils/storage.d.ts +2 -0
  69. package/dist/src/utils/str.d.ts +212 -0
  70. package/dist/src/utils/subscribe.d.ts +46 -0
  71. package/dist/src/utils/throttle.d.ts +15 -0
  72. package/dist/src/utils/time.d.ts +20 -0
  73. package/dist/src/utils/totp/sha/common.d.ts +151 -0
  74. package/dist/src/utils/totp/sha/converters.d.ts +88 -0
  75. package/dist/src/utils/totp/sha/custom_types.d.ts +60 -0
  76. package/dist/src/utils/totp/sha/primitives_32.d.ts +98 -0
  77. package/dist/src/utils/totp/sha/primitives_64.d.ts +116 -0
  78. package/dist/src/utils/totp/sha/sha.d.ts +103 -0
  79. package/dist/src/utils/totp/sha/sha1.d.ts +18 -0
  80. package/dist/src/utils/totp/sha/sha256.d.ts +20 -0
  81. package/dist/src/utils/totp/sha/sha3.d.ts +53 -0
  82. package/dist/src/utils/totp/sha/sha512.d.ts +21 -0
  83. package/dist/src/utils/totp/totp.d.ts +23 -0
  84. package/dist/src/utils/visual/application.d.ts +27 -0
  85. package/dist/src/utils/visual/enums.d.ts +27 -0
  86. package/dist/src/utils/visual/event/boundary.d.ts +22 -0
  87. package/dist/src/utils/visual/event/event.d.ts +14 -0
  88. package/dist/src/utils/visual/event/index.d.ts +6 -0
  89. package/dist/src/utils/visual/event/types.d.ts +32 -0
  90. package/dist/src/utils/visual/graphics/graphics.d.ts +81 -0
  91. package/dist/src/utils/visual/graphics/graphicsData.d.ts +13 -0
  92. package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +35 -0
  93. package/dist/src/utils/visual/graphics/index.d.ts +4 -0
  94. package/dist/src/utils/visual/index.d.ts +7 -0
  95. package/dist/src/utils/visual/index.js +1 -0
  96. package/dist/src/utils/visual/math/bezier.d.ts +2 -0
  97. package/dist/src/utils/visual/math/enums.d.ts +3 -0
  98. package/dist/src/utils/visual/math/index.d.ts +5 -0
  99. package/dist/src/utils/visual/math/matrix.d.ts +113 -0
  100. package/dist/src/utils/visual/math/transform.d.ts +29 -0
  101. package/dist/src/utils/visual/render/batchRenderer.d.ts +78 -0
  102. package/dist/src/utils/visual/render/canvasRenderer.d.ts +10 -0
  103. package/dist/src/utils/visual/render/index.d.ts +3 -0
  104. package/dist/src/utils/visual/render/render.d.ts +11 -0
  105. package/dist/src/utils/visual/render/utils/batch/index.d.ts +90 -0
  106. package/dist/src/utils/visual/render/utils/batch/index.test.d.ts +1 -0
  107. package/dist/src/utils/visual/render/utils/float.d.ts +63 -0
  108. package/dist/src/utils/visual/render/utils/index.d.ts +3 -0
  109. package/dist/src/utils/visual/render/utils/index.test.d.ts +1 -0
  110. package/dist/src/utils/visual/render/utils/verticy.d.ts +13 -0
  111. package/dist/src/utils/visual/render/utils/webgl/initShader.d.ts +7 -0
  112. package/dist/src/utils/visual/render/utils/webgl/shaders.d.ts +2 -0
  113. package/dist/src/utils/visual/render/utils/webgpu/shaders.d.ts +8 -0
  114. package/dist/src/utils/visual/render/webGPURenderer.d.ts +49 -0
  115. package/dist/src/utils/visual/render/webGlRenderer.d.ts +14 -0
  116. package/dist/src/utils/visual/shape/circle.d.ts +11 -0
  117. package/dist/src/utils/visual/shape/ellipse.d.ts +12 -0
  118. package/dist/src/utils/visual/shape/index.d.ts +7 -0
  119. package/dist/src/utils/visual/shape/polygon.d.ts +11 -0
  120. package/dist/src/utils/visual/shape/rectangle.d.ts +12 -0
  121. package/dist/src/utils/visual/shape/roundedRectangle.d.ts +13 -0
  122. package/dist/src/utils/visual/shape/shape.d.ts +6 -0
  123. package/dist/src/utils/visual/style/fill.d.ts +8 -0
  124. package/dist/src/utils/visual/style/index.d.ts +3 -0
  125. package/dist/src/utils/visual/style/line.d.ts +10 -0
  126. package/dist/src/utils/visual/types.d.ts +18 -0
  127. package/dist/src/utils/visual/vertex/container.d.ts +74 -0
  128. package/dist/src/utils/visual/vertex/point.d.ts +18 -0
  129. package/dist/src/utils/visual/vertex/vertex.d.ts +36 -0
  130. package/dist/src/vnode/chainDom.d.ts +47 -0
  131. package/dist/src/vnode/h.d.ts +6 -0
  132. package/dist/src/vnode/hooks.d.ts +23 -0
  133. package/dist/src/vnode/htmlDomApi.d.ts +33 -0
  134. package/dist/src/vnode/index.d.ts +18 -0
  135. package/dist/src/vnode/index.js +1 -0
  136. package/dist/src/vnode/init.d.ts +2 -0
  137. package/dist/src/vnode/is.d.ts +5 -0
  138. package/dist/src/vnode/modules/attributes.d.ts +8 -0
  139. package/dist/src/vnode/modules/class.d.ts +8 -0
  140. package/dist/src/vnode/modules/index.d.ts +3 -0
  141. package/dist/src/vnode/modules/listeners.d.ts +12 -0
  142. package/dist/src/vnode/modules/props.d.ts +8 -0
  143. package/dist/src/vnode/modules/style.d.ts +14 -0
  144. package/dist/src/vnode/vnode.d.ts +31 -0
  145. package/dist/subscribe-CINWsor3.js +1 -0
  146. package/dist/test/bridge.test.d.ts +1 -0
  147. package/dist/test/clearBr.test.d.ts +1 -0
  148. package/dist/test/cloneDeep.test.d.ts +1 -0
  149. package/dist/test/command.test.d.ts +1 -0
  150. package/dist/test/encodeUrl.test.d.ts +1 -0
  151. package/dist/test/escapeHtml.test.d.ts +1 -0
  152. package/dist/test/is-equal.test.d.ts +1 -0
  153. package/dist/test/mimeType.test.d.ts +1 -0
  154. package/dist/test/package-exports.test.d.ts +1 -0
  155. package/dist/test/server.test.d.ts +1 -0
  156. package/dist/test/status.test.d.ts +1 -0
  157. package/dist/test/totp.test.d.ts +1 -0
  158. package/dist/test/utils/compose.test.d.ts +1 -0
  159. package/dist/test/utils/mergeObj.test.d.ts +1 -0
  160. package/dist/test/visual/math.test.d.ts +1 -0
  161. package/dist/test/visual-application.test.d.ts +1 -0
  162. package/dist/test/visual-batch.test.d.ts +1 -0
  163. package/dist/test/visual-math.test.d.ts +1 -0
  164. package/dist/test/vnode/index.d.ts +1 -0
  165. package/dist/test/vnode/server.d.ts +2 -0
  166. package/dist/test/vnode/vnode.d.ts +1 -0
  167. package/dist/test/vnode.test.d.ts +1 -0
  168. package/dist/test/websocket.test.d.ts +1 -0
  169. package/dist/test/writeFile.test.d.ts +1 -0
  170. package/dist/umd/index.umd.cjs +1 -0
  171. package/dist/umd/node/node.umd.cjs +1 -0
  172. package/dist/umd/utils/utils.umd.cjs +1 -0
  173. package/dist/utils-_OxsVZmz.js +1 -0
  174. package/dist/vite.config.d.ts +8 -0
  175. package/dist/vitest.config.d.ts +2 -0
  176. package/docs/API.md +309 -0
  177. package/package.json +49 -12
  178. package/typings.d.ts +28 -0
  179. package/dist/index.umd.cjs +0 -1
package/CLAUDE.md ADDED
@@ -0,0 +1,164 @@
1
+ # ranuts — Utility Library Reference
2
+
3
+ Experimental TypeScript utility library. A broad, learning-oriented collection: DOM/BOM
4
+ helpers, string/object/number utilities, algorithms, a 2D rendering engine, a virtual DOM,
5
+ and Node server tooling. Multi-entry, tree-shakeable, ships ESM + UMD.
6
+
7
+ > ⚠️ **Experimental** (`1.0.0-beta-1`). APIs may change; primarily for learning. No
8
+ > framework runtime — these are standalone functions and classes.
9
+
10
+ ---
11
+
12
+ ## Start here
13
+
14
+ - **[docs/API.md](docs/API.md)** — ⭐ generated, authoritative list of **every exported
15
+ symbol** with its signature + one-line description, grouped by entry point. Regenerate
16
+ with `npm run doc:api` after changing any public API. Read this to find what exists.
17
+ - **This file** — orientation: which entry to import, runtime constraints, conventions,
18
+ and gotchas. Read this to decide _where_ things go and _how_ to add them.
19
+
20
+ When asked to "use ranuts" for a task: open `docs/API.md`, find the symbol, and import it
21
+ from the **subpath that owns it** (below) — not from a deep source path.
22
+
23
+ ---
24
+
25
+ ## Entry points (import map)
26
+
27
+ Each subpath is an independent, tree-shakeable barrel. Import from the subpath, never from
28
+ `ranuts/dist/...` or `@/...` (that alias is internal to the source).
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/vnode` | `src/vnode/index.ts` | Snabbdom-style virtual DOM (`h`, `init`, modules) | browser |
37
+
38
+ \* `ranuts/utils` is broad: most functions are browser-oriented (touch `window`/`document`),
39
+ but pure helpers (`str`, `obj`, `number`, `compose`, `cloneDeep`, …) run anywhere. Functions
40
+ that read browser globals generally guard with `typeof window/document !== 'undefined'`; do
41
+ the same for any new code. **Do not import `ranuts/node` in browser code** — it pulls in
42
+ `fs`/`http`/`child_process` (these are marked external in the build).
43
+
44
+ ---
45
+
46
+ ## Project layout
47
+
48
+ ```
49
+ packages/ranuts/
50
+ ├── index.ts # Root barrel (re-exports utils + visual + selected)
51
+ ├── src/
52
+ │ ├── utils/ # ranuts/utils — the largest surface (~13.8k LOC)
53
+ │ │ ├── str.ts obj.ts number.ts color.ts bom.ts dom.ts time.ts …
54
+ │ │ ├── visual/ # ranuts/visual — 2D rendering engine (see below)
55
+ │ │ └── totp/ # TOTP + hand-rolled SHA
56
+ │ ├── node/ # ranuts/node — mini HTTP framework
57
+ │ └── vnode/ # ranuts/vnode — virtual DOM
58
+ ├── bin/
59
+ │ ├── build.sh # build (tsc types + vite es/umd)
60
+ │ └── generate-api-docs.ts # ⭐ doc:api — emits docs/API.md from source + JSDoc
61
+ ├── docs/API.md # ⭐ generated API reference (do not hand-edit)
62
+ ├── CLAUDE.md # this file
63
+ ├── vite.config.ts # multi-entry es + umd build
64
+ ├── vitest.config.ts # tests (node env, '@' alias)
65
+ └── package.json # "exports" map ↔ entry points above
66
+ ```
67
+
68
+ ---
69
+
70
+ ## The `visual/` rendering engine
71
+
72
+ A PixiJS-style 2D engine. The non-obvious parts, so you don't have to re-derive them:
73
+
74
+ - **Layering**: `Application` (lifecycle/RAF) → `Renderer` (abstract backend) → scene graph
75
+ of `Container` (a "group") → `Graphics` (drawable). Add nodes to `app.stage`.
76
+ - **Async init**: use `await Application.create({ view, prefer })`, not `new Application()` —
77
+ the WebGPU backend initializes its device asynchronously and must finish before the first
78
+ render. Canvas/WebGL `init()` resolve immediately, so the factory is safe for all backends.
79
+ - **Three backends** (`RENDERER_TYPE`): `CANVAS` draws directly via Canvas2D API; `WEB_GL`
80
+ and `WEB_GPU` share one `BatchRenderer` pipeline (triangulate → pack a single interleaved
81
+ vertex buffer → one draw call). Backend chosen by `prefer`, default Canvas.
82
+ - **Dirty tracking**: the scene-graph root carries a `structureVersion`. Structural changes
83
+ (add/remove child, redraw, clear) bubble to the root and bump it; the batch renderer
84
+ rebuilds the big array only when the version changed, otherwise it just re-transforms
85
+ vertices. Version-compare (not a boolean flag) so multiple renderers can share a scene.
86
+ - **Color**: all backends accept any CSS color. Geometry/background colors flow through
87
+ `getRgb` (in `render/utils/index.ts`) which fast-paths `#rgb`/`#rrggbb` and falls back to
88
+ the browser's own parser for named/`rgb()`/`hsl()` colors — keeping the three backends
89
+ aligned. GPU vertex colors are premultiplied + packed little-endian into one u32.
90
+ - **Inherent backend difference**: stroke/join geometry is native `ctx.stroke()` on Canvas
91
+ vs. custom triangulation (`render/utils/verticy.ts`) on GPU — not pixel-identical by design.
92
+
93
+ Tests for the color pipeline and batch packing live next to the source as `*.test.ts`.
94
+
95
+ ---
96
+
97
+ ## Conventions
98
+
99
+ ### Adding a function to an existing module
100
+
101
+ 1. Write it in the right `src/<module>/*.ts` file with a JSDoc block. This codebase uses the
102
+ `@description:` tag (often Chinese) for the summary — the generator reads it:
103
+ ```ts
104
+ /**
105
+ * @description: 防抖
106
+ * @param fn 要执行的函数
107
+ * @return 包装后的函数
108
+ */
109
+ export const debounce = (fn, ms = 300) => { … };
110
+ ```
111
+ 2. Re-export it from that module's `index.ts` barrel (named export; types via `export type`).
112
+ 3. Run `npm run doc:api` to refresh `docs/API.md`.
113
+
114
+ ### Adding a whole new entry point (subpath)
115
+
116
+ Wire it in **three** places (mirror an existing one):
117
+
118
+ 1. **`package.json` → `exports`** — add `"./foo": { types, import, require }`.
119
+ 2. **`vite.config.ts` → `es.lib.entry`** (and a `umd*` block if a UMD build is wanted) — add
120
+ `foo: resolve(__dirname, 'src/foo/index.ts')`.
121
+ 3. **`bin/generate-api-docs.ts` → `ENTRIES`** — add the subpath so it shows up in `docs/API.md`.
122
+
123
+ Then `npm run doc:api`.
124
+
125
+ ### Runtime safety
126
+
127
+ - Guard every `window`/`document`/`localStorage`/`navigator` access with `typeof … !== 'undefined'`
128
+ in code reachable from `ranuts/utils` (it's imported in node too).
129
+ - Keep `ranuts/node` server-only; never import it from browser-facing modules.
130
+
131
+ ---
132
+
133
+ ## Build, test, docs
134
+
135
+ ```bash
136
+ npm run build # tsc types + vite (es + umd) → dist/
137
+ npm run tsc # type-check only (tsc --noEmit)
138
+ npm run test # vitest run (node env)
139
+ npm run test:coverage
140
+ npm run doc:api # regenerate docs/API.md from source + JSDoc
141
+ ```
142
+
143
+ - **Tests**: Vitest, **node environment** (no jsdom) — `vitest.config.ts` has no `environment`
144
+ set. Co-locate as `*.test.ts` next to source; alias `@ → src`. Pure logic and anything that
145
+ degrades gracefully without DOM is testable here; DOM/GPU-dependent paths are not (e.g.
146
+ `getRgb`'s CSS fallback returns black without `document`).
147
+ - **`onConsoleLog` throws**: the test config fails any test that logs to console — don't leave
148
+ stray `console.*` in code under test.
149
+
150
+ ---
151
+
152
+ ## Gotchas
153
+
154
+ | Pitfall | Fix |
155
+ | ------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- |
156
+ | Importing from a deep source path or `@/…` | Import from the public subpath (`ranuts/utils`, `ranuts/visual`, …). `@/…` is build-internal only. |
157
+ | Importing `ranuts/node` in browser code | It externalizes `fs`/`http`/`child_process` — server-only. Use `ranuts/utils` for browser helpers. |
158
+ | `new Application()` then `render()` with WebGPU | Device init is async — use `await Application.create(...)`, then `app.start()`. |
159
+ | Hand-editing `docs/API.md` | It's generated. Edit the source JSDoc and run `npm run doc:api`. |
160
+ | Adding an export but it's missing from `docs/API.md` | Re-export it from the module's `index.ts` barrel, then `npm run doc:api`. |
161
+ | New entry point not importable as `ranuts/foo` | Wire all three: `package.json` exports + `vite.config.ts` es entry + generator `ENTRIES`. |
162
+ | `console.log` left in a function that a test calls | `vitest.config.ts` `onConsoleLog` throws — remove it or the test fails. |
163
+ | Assuming a GPU/Canvas test can run in CI | Test env is node (no DOM/GPU). Test pure logic; gate visual checks behind a browser demo. |
164
+ | Passing a non-`#rrggbb` color to the GPU backend and expecting it to fail | It won't — `getRgb` resolves any CSS color via the browser parser, matching the Canvas backend. |
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # ranuts
2
+
3
+ Experimental utility library with commonly used functions and tools
4
+
5
+ ---
6
+
7
+ <a href="https://github.com/chaxus/ran"><img src="https://img.shields.io/github/actions/workflow/status/chaxus/ran/ci.yml" alt="Build Status"></a>
8
+ <a href="https://github.com/chaxus/ran"><img src="https://img.shields.io/npm/v/ranuts.svg" alt="npm-v"></a>
9
+ <a href="https://github.com/chaxus/ran"><img src="https://img.shields.io/npm/dt/ranuts.svg" alt="npm-d"></a>
10
+ <a href="https://github.com/chaxus/ran"><img src="https://img.badgesize.io/https:/unpkg.com/ranuts/dist/index.js?label=brotli&compression=brotli" alt="brotli"></a>
11
+ <a href="https://github.com/chaxus/ran"><img src="https://img.shields.io/badge/module%20formats-umd%2C%20esm-green.svg" alt="module formats: umd, esm"></a>
12
+
13
+ ---
14
+
15
+ ## ⚠️ Important Notice
16
+
17
+ This is an **experimental utility library** in early development. While functional, it's primarily designed for learning and experimentation.
18
+
19
+ **Key points:**
20
+
21
+ - 🚧 **Early Development**: Features are still being developed and refined
22
+ - 🧪 **Experimental**: APIs may change frequently
23
+ - 📚 **Learning Focus**: Primarily for learning JavaScript/TypeScript utilities
24
+
25
+ ## Install
26
+
27
+ Using npm:
28
+
29
+ ```console
30
+ npm install ranuts@latest --save
31
+ ```
32
+
33
+ ## Document
34
+
35
+ [Some commonly used functions and tools](https://chaxus.github.io/ran/src/ranuts/)
36
+
37
+ **For AI agents / LLMs:** start from [CLAUDE.md](./CLAUDE.md) (orientation: entry points,
38
+ runtime constraints, conventions) and [docs/API.md](./docs/API.md) (generated reference of
39
+ every exported symbol with signatures + descriptions, run `npm run doc:api` to refresh).
40
+
41
+ Or install the ready-made **Claude Code skill** from the `ran` plugin marketplace — it
42
+ gives assistants the import map, `ranuts/utils` inventory, usage examples, and conventions,
43
+ and points to the API reference shipped in the package:
44
+
45
+ ```bash
46
+ /plugin marketplace add chaxus/ran
47
+ /plugin install ranuts@ran
48
+ ```
49
+
50
+ Claude then uses it automatically (or invoke it as `/ranuts:ranuts`).
51
+
52
+ ## Usage
53
+
54
+ Import as required. You can select:
55
+
56
+ - ranuts/utils
57
+ - ranuts/node
58
+ - ranuts/react
59
+
60
+ ```js
61
+ import { str2Xml } from 'ranuts/utils';
62
+ import { readFile } from 'ranuts/node';
63
+ import { reactify } from 'ranuts/react';
64
+ ```
65
+
66
+ Full import,(Full import will introduce many unnecessary modules. You are advised to import them on demand)
67
+
68
+ - ESM
69
+
70
+ ```js
71
+ import { str2Xml } from 'ranuts';
72
+
73
+ const data = `
74
+ <svg t="1688378016663" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2608" width="128" height="128"><path d="M568 515.008l254.016-255.008q12-11.008 12-27.488t-11.488-28-28-11.488-27.488 12l-255.008 254.016-255.008-254.016q-11.008-12-27.488-12t-28 11.488-11.488 28 12 27.488l254.016 255.008-254.016 255.008q-12 11.008-12 27.488t11.488 28 28 11.488 27.488-12l255.008-255.008 255.008 255.008q11.008 12 27.488 12t28-11.488 11.488-28-12-27.488z" p-id="2609" ></path></svg>
75
+ `;
76
+
77
+ const html = str2Xml(data, 'image/svg+xml');
78
+
79
+ document.body.appendChild(html);
80
+ ```
81
+
82
+ - UMD, IIFE, CJS
83
+
84
+ ```html
85
+ <script src="./ranuts/dist/umd/index.umd.cjs"></script>
86
+
87
+ <script>
88
+ const { str2Xml } = require('ranuts')
89
+ const data = `
90
+ <svg t="1688378016663" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2608" width="128" height="128"><path d="M568 515.008l254.016-255.008q12-11.008 12-27.488t-11.488-28-28-11.488-27.488 12l-255.008 254.016-255.008-254.016q-11.008-12-27.488-12t-28 11.488-11.488 28 12 27.488l254.016 255.008-254.016 255.008q-12 11.008-12 27.488t11.488 28 28 11.488 27.488-12l255.008-255.008 255.008 255.008q11.008 12 27.488 12t28-11.488 11.488-28-12-27.488z" p-id="2609" ></path></svg>
91
+ `
92
+
93
+ const html = str2Xml(data, 'image/svg+xml');
94
+
95
+ document.body.appendChild(html);
96
+
97
+ <script>
98
+ ```
99
+
100
+ ## Contributing
101
+
102
+ We welcome contributions from learners and developers! This is an experimental project, so please be patient with the development process.
103
+
104
+ ## Contributors
105
+
106
+ <a href="https://github.com/chaxus/ran/graphs/contributors">
107
+ <img src="https://contrib.rocks/image?repo=chaxus/ran" />
108
+ </a>
109
+
110
+ ## Visitors
111
+
112
+ ![](http://profile-counter.glitch.me/chaxus-ranuts/count.svg)
113
+
114
+ ## Meta
115
+
116
+ [LICENSE (MIT)](/LICENSE)
@@ -1,33 +1,56 @@
1
1
  # ranuts
2
2
 
3
- Some commonly used functions and tools
3
+ 实验性工具函数库,包含常用的函数和工具
4
4
 
5
5
  ---
6
6
 
7
7
  <a href="https://github.com/chaxus/ran"><img src="https://img.shields.io/github/actions/workflow/status/chaxus/ran/ci.yml" alt="Build Status"></a>
8
8
  <a href="https://github.com/chaxus/ran"><img src="https://img.shields.io/npm/v/ranuts.svg" alt="npm-v"></a>
9
9
  <a href="https://github.com/chaxus/ran"><img src="https://img.shields.io/npm/dt/ranuts.svg" alt="npm-d"></a>
10
- <a href="https://github.com/chaxus/ran"><img src="https://img.badgesize.io/https:/unpkg.com/ranuts/dist/index.umd.cjs?label=brotli&compression=brotli" alt="brotli"></a>
10
+ <a href="https://github.com/chaxus/ran"><img src="https://img.badgesize.io/https:/unpkg.com/ranuts/dist/index.js?label=brotli&compression=brotli" alt="brotli"></a>
11
11
  <a href="https://github.com/chaxus/ran"><img src="https://img.shields.io/badge/module%20formats-umd%2C%20esm-green.svg" alt="module formats: umd, esm"></a>
12
12
 
13
+ **中文** | [English](./README.md)
14
+
13
15
  ---
14
16
 
17
+ ## ⚠️ 重要说明
18
+
19
+ 这是一个**实验性工具函数库**,处于早期开发阶段。虽然功能可用,但主要用于学习和实验。
20
+
21
+ **关键要点:**
22
+
23
+ - 🚧 **早期开发**: 功能仍在开发和完善中
24
+ - 🧪 **实验性**: API 可能会频繁变化
25
+ - 📚 **学习导向**: 主要用于学习 JavaScript/TypeScript 工具函数
15
26
 
16
- ## Install
27
+ ## 安装
17
28
 
18
- Using npm:
29
+ 使用 npm:
19
30
 
20
31
  ```console
21
- npm install ranuts --save
32
+ npm install ranuts@latest --save
22
33
  ```
23
34
 
24
- ## Document
35
+ ## 文档
25
36
 
26
- [Some commonly used functions and tools](https://chaxus.github.io/ran/src/ranuts/)
37
+ [一些常用的函数和工具](https://chaxus.github.io/ran/cn/src/ranuts/)
27
38
 
39
+ ## 使用方式
28
40
 
41
+ 按需导入。您可以选择:
29
42
 
30
- ## Usage
43
+ - ranuts/utils
44
+ - ranuts/node
45
+ - ranuts/react
46
+
47
+ ```js
48
+ import { str2Xml } from 'ranuts/utils';
49
+ import { readFile } from 'ranuts/node';
50
+ import { reactify } from 'ranuts/react';
51
+ ```
52
+
53
+ 全量导入(全量导入会引入许多不必要的模块,建议按需导入)
31
54
 
32
55
  - ESM
33
56
 
@@ -36,7 +59,7 @@ import { str2Xml } from 'ranuts';
36
59
 
37
60
  const data = `
38
61
  <svg t="1688378016663" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2608" width="128" height="128"><path d="M568 515.008l254.016-255.008q12-11.008 12-27.488t-11.488-28-28-11.488-27.488 12l-255.008 254.016-255.008-254.016q-11.008-12-27.488-12t-28 11.488-11.488 28 12 27.488l254.016 255.008-254.016 255.008q-12 11.008-12 27.488t11.488 28 28 11.488 27.488-12l255.008-255.008 255.008 255.008q11.008 12 27.488 12t28-11.488 11.488-28-12-27.488z" p-id="2609" ></path></svg>
39
- `
62
+ `;
40
63
 
41
64
  const html = str2Xml(data, 'image/svg+xml');
42
65
 
@@ -46,7 +69,7 @@ document.body.appendChild(html);
46
69
  - UMD, IIFE, CJS
47
70
 
48
71
  ```html
49
- <script src="./ranuts/dist/index.umd.cjs"></script>
72
+ <script src="./ranuts/dist/umd/index.umd.cjs"></script>
50
73
 
51
74
  <script>
52
75
  const { str2Xml } = require('ranuts')
@@ -61,12 +84,20 @@ document.body.appendChild(html);
61
84
  <script>
62
85
  ```
63
86
 
64
- ## Contributors
87
+ ## 贡献
88
+
89
+ 我们欢迎学习者和开发者的贡献!这是一个实验性项目,请对开发过程保持耐心。
90
+
91
+ ## 贡献者
65
92
 
66
93
  <a href="https://github.com/chaxus/ran/graphs/contributors">
67
94
  <img src="https://contrib.rocks/image?repo=chaxus/ran" />
68
95
  </a>
69
96
 
97
+ ## 访问统计
98
+
99
+ ![](http://profile-counter.glitch.me/chaxus-ranuts/count.svg)
100
+
70
101
  ## Meta
71
102
 
72
- [LICENSE (MIT)](/LICENSE)
103
+ [LICENSE (MIT)](/LICENSE)
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("vite").UserConfig;
2
+ export default _default;