cruzo 0.9.0
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/LICENSE +21 -0
- package/README.md +268 -0
- package/assets/cruzo.png +0 -0
- package/dist/component-CH-TJ5VF.js +1850 -0
- package/dist/component-CH-TJ5VF.js.map +1 -0
- package/dist/component.d.ts +62 -0
- package/dist/component.d.ts.map +1 -0
- package/dist/components-registry.service.d.ts +21 -0
- package/dist/components-registry.service.d.ts.map +1 -0
- package/dist/http.d.ts +54 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +355 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces.d.ts +39 -0
- package/dist/interfaces.d.ts.map +1 -0
- package/dist/lib/component.d.ts +62 -0
- package/dist/lib/component.d.ts.map +1 -0
- package/dist/lib/components-registry.service.d.ts +21 -0
- package/dist/lib/components-registry.service.d.ts.map +1 -0
- package/dist/lib/http.d.ts +54 -0
- package/dist/lib/http.d.ts.map +1 -0
- package/dist/lib/index.d.ts +14 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/interfaces.d.ts +39 -0
- package/dist/lib/interfaces.d.ts.map +1 -0
- package/dist/lib/router.service.d.ts +84 -0
- package/dist/lib/router.service.d.ts.map +1 -0
- package/dist/lib/rx-scope.d.ts +76 -0
- package/dist/lib/rx-scope.d.ts.map +1 -0
- package/dist/lib/rx.d.ts +21 -0
- package/dist/lib/rx.d.ts.map +1 -0
- package/dist/lib/service.d.ts +10 -0
- package/dist/lib/service.d.ts.map +1 -0
- package/dist/lib/template.d.ts +141 -0
- package/dist/lib/template.d.ts.map +1 -0
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/vm.d.ts +118 -0
- package/dist/lib/vm.d.ts.map +1 -0
- package/dist/router.service-CYzZn3L6.js +231 -0
- package/dist/router.service-CYzZn3L6.js.map +1 -0
- package/dist/router.service.d.ts +84 -0
- package/dist/router.service.d.ts.map +1 -0
- package/dist/rx-scope.d.ts +76 -0
- package/dist/rx-scope.d.ts.map +1 -0
- package/dist/rx.d.ts +21 -0
- package/dist/rx.d.ts.map +1 -0
- package/dist/service.d.ts +10 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/template.d.ts +141 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/ui-components/button-group/button-group.component.d.ts +17 -0
- package/dist/ui-components/button-group/button-group.component.d.ts.map +1 -0
- package/dist/ui-components/button-group.css +38 -0
- package/dist/ui-components/button-group.js +35 -0
- package/dist/ui-components/button-group.js.map +1 -0
- package/dist/ui-components/input/input.component.d.ts +41 -0
- package/dist/ui-components/input/input.component.d.ts.map +1 -0
- package/dist/ui-components/input.css +13 -0
- package/dist/ui-components/input.js +104 -0
- package/dist/ui-components/input.js.map +1 -0
- package/dist/ui-components/modal/modal.component.d.ts +32 -0
- package/dist/ui-components/modal/modal.component.d.ts.map +1 -0
- package/dist/ui-components/modal.css +35 -0
- package/dist/ui-components/modal.js +45 -0
- package/dist/ui-components/modal.js.map +1 -0
- package/dist/ui-components/router-link/router-link.d.ts +29 -0
- package/dist/ui-components/router-link/router-link.d.ts.map +1 -0
- package/dist/ui-components/router-link.js +46 -0
- package/dist/ui-components/router-link.js.map +1 -0
- package/dist/ui-components/select/select.component.d.ts +30 -0
- package/dist/ui-components/select/select.component.d.ts.map +1 -0
- package/dist/ui-components/select.css +111 -0
- package/dist/ui-components/select.js +77 -0
- package/dist/ui-components/select.js.map +1 -0
- package/dist/ui-components/spinner/spinner.component.d.ts +30 -0
- package/dist/ui-components/spinner/spinner.component.d.ts.map +1 -0
- package/dist/ui-components/spinner.css +106 -0
- package/dist/ui-components/spinner.js +83 -0
- package/dist/ui-components/spinner.js.map +1 -0
- package/dist/ui-components/upload/upload.component.d.ts +17 -0
- package/dist/ui-components/upload/upload.component.d.ts.map +1 -0
- package/dist/ui-components/upload.css +31 -0
- package/dist/ui-components/upload.js +34 -0
- package/dist/ui-components/upload.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +26 -0
- package/dist/utils.js.map +1 -0
- package/dist/vm.d.ts +118 -0
- package/dist/vm.d.ts.map +1 -0
- package/package.json +74 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Cruzo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# C R U Z O
|
|
2
|
+
|
|
3
|
+
<img src="./assets/cruzo.png" alt="cruzo" width="100" height="100" />
|
|
4
|
+
|
|
5
|
+
> zero-dependency reactive framework + expression VM
|
|
6
|
+
> no vdom. no magic build step. just html + rx + bytecode.
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/cruzo)
|
|
9
|
+
[](./LICENSE)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## // What Is This
|
|
14
|
+
|
|
15
|
+
`cruzo` is a tiny UI framework with:
|
|
16
|
+
|
|
17
|
+
- reactive primitives (`newRx`, `newRxFunc`) inside components
|
|
18
|
+
- template engine with `{{ }}` expressions compiled to bytecode VM
|
|
19
|
+
- scoped data bus via `RxScope`
|
|
20
|
+
- built-in router (`RouteUrlBucket`, `routerService`)
|
|
21
|
+
- built-in HTTP client (`HttpClient`) with interceptors, cache, abort
|
|
22
|
+
- optional UI components as separate entrypoints
|
|
23
|
+
|
|
24
|
+
If you want full control over DOM and a small runtime footprint, this is your lane.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## // Install
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm i cruzo
|
|
32
|
+
```
|
|
33
|
+
- Starter repo: [cruzo-starter](https://maratbektemirov.github.io/cruzo-starter/)
|
|
34
|
+
- VSCode extension (syntax): [cruzo-syntax](https://marketplace.visualstudio.com/items?itemName=cruzo.cruzo-syntax)
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## // Public API (current)
|
|
39
|
+
|
|
40
|
+
Root import:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import {
|
|
44
|
+
Template,
|
|
45
|
+
AbstractComponent,
|
|
46
|
+
AbstractService,
|
|
47
|
+
RxScope,
|
|
48
|
+
componentsRegistryService,
|
|
49
|
+
routerService,
|
|
50
|
+
RouteUrlBucket,
|
|
51
|
+
HttpClient,
|
|
52
|
+
HttpError,
|
|
53
|
+
delay,
|
|
54
|
+
debounce,
|
|
55
|
+
arrayToHash,
|
|
56
|
+
} from "cruzo";
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Also available via dedicated subpath:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { delay, debounce, arrayToHash } from "cruzo/utils";
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Also exported types:
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import type {
|
|
69
|
+
HttpRequestOptions,
|
|
70
|
+
Interceptors,
|
|
71
|
+
AbstractComponentConstructor,
|
|
72
|
+
ComponentDescriptor,
|
|
73
|
+
ComponentConnectedParams,
|
|
74
|
+
ScopeEvent,
|
|
75
|
+
Rx,
|
|
76
|
+
RxFunc,
|
|
77
|
+
} from "cruzo";
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## // Fast Start
|
|
83
|
+
|
|
84
|
+
```ts
|
|
85
|
+
import { AbstractComponent, componentsRegistryService } from "cruzo";
|
|
86
|
+
|
|
87
|
+
class CounterComponent extends AbstractComponent {
|
|
88
|
+
static selector = "counter-component";
|
|
89
|
+
|
|
90
|
+
count$ = this.newRx(0);
|
|
91
|
+
|
|
92
|
+
getHTML() {
|
|
93
|
+
return `
|
|
94
|
+
<button onclick="{{root.count$.update(root.count$::rx + 1)}}">
|
|
95
|
+
ping: {{root.count$::rx}}
|
|
96
|
+
</button>
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
componentsRegistryService.define(CounterComponent);
|
|
102
|
+
componentsRegistryService.initApp();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Place `<counter-component></counter-component>` in HTML and it works.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## // Template Syntax Cheatsheet
|
|
110
|
+
|
|
111
|
+
Supported in templates:
|
|
112
|
+
|
|
113
|
+
- text interpolation: `{{ expr }}`
|
|
114
|
+
- events: `onclick="{{ root.doStuff() }}"`
|
|
115
|
+
- reactive read: `rxValue$::rx`
|
|
116
|
+
- one-time evaluation: `once::expr`
|
|
117
|
+
- loop: `repeat="{{ root.list$::rx }}"`
|
|
118
|
+
- conditional mount: `attached="{{ root.flag$::rx }}"`
|
|
119
|
+
- lexical vars: `let-item="{{ this::rx }}"`
|
|
120
|
+
- raw html: `inner-html="{{ root.html$::rx }}"`
|
|
121
|
+
|
|
122
|
+
Example:
|
|
123
|
+
|
|
124
|
+
```html
|
|
125
|
+
<div repeat="{{root.items$::rx}}" let-name="{{this::rx.name}}">
|
|
126
|
+
<button onclick="{{root.select(this::rx.id)}}">{{name}}</button>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<section attached="{{root.open$::rx}}">
|
|
130
|
+
selected: {{root.selected$::rx ?? "none"}}
|
|
131
|
+
</section>
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## // RxScope: shared config/state/value/events
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { AbstractComponent, RxScope } from "cruzo";
|
|
140
|
+
|
|
141
|
+
type ScopeShape = {
|
|
142
|
+
input: { config: { placeholder: string } };
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
class DemoScopeComponent extends AbstractComponent {
|
|
146
|
+
static selector = "demo-scope-component";
|
|
147
|
+
|
|
148
|
+
innerScope = new RxScope<ScopeShape>({
|
|
149
|
+
input: { config: { placeholder: "your alias" } },
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
inputValue$ = this.newRxValueFromScope(this.innerScope, "input");
|
|
153
|
+
|
|
154
|
+
getHTML() {
|
|
155
|
+
return `
|
|
156
|
+
<input-component component-id="input" scope-id="${this.innerScope.id}"></input-component>
|
|
157
|
+
<pre>{{root.inputValue$::rx}}</pre>
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Use `scope-id` + `component-id` to route descriptor/config/value into components.
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## // Router
|
|
168
|
+
|
|
169
|
+
```ts
|
|
170
|
+
import { RouteUrlBucket } from "cruzo";
|
|
171
|
+
|
|
172
|
+
const routes = new RouteUrlBucket({
|
|
173
|
+
home: {
|
|
174
|
+
url: "/",
|
|
175
|
+
componentSelectorUnbox: () => "home-page",
|
|
176
|
+
routeSelectorUnbox: () => "#app",
|
|
177
|
+
},
|
|
178
|
+
docs: {
|
|
179
|
+
url: "/docs/:slug",
|
|
180
|
+
componentSelectorUnbox: () => "docs-page",
|
|
181
|
+
routeSelectorUnbox: () => "#app",
|
|
182
|
+
},
|
|
183
|
+
oldDocs: {
|
|
184
|
+
url: "/guide/*rest",
|
|
185
|
+
redirectTo: "/docs/intro",
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
routes.buildUrl("docs", { slug: "template-vm" }); // /docs/template-vm
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
`routerService` also provides:
|
|
193
|
+
|
|
194
|
+
- `pushHistory(href)`
|
|
195
|
+
- `pushHistoryLink(event, href)`
|
|
196
|
+
- `hrefIsActive(href, { startsWith, ignoreSearch, ignoreHash })`
|
|
197
|
+
- reactive URL streams: `pathname$`, `search$`, `hash$`
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
## // HTTP
|
|
202
|
+
|
|
203
|
+
```ts
|
|
204
|
+
import { HttpClient } from "cruzo";
|
|
205
|
+
|
|
206
|
+
const api = new HttpClient("https://api.example.com", {
|
|
207
|
+
params: async (_method, _url, options) => {
|
|
208
|
+
options.headers ??= {};
|
|
209
|
+
options.headers.Authorization = "Bearer " + token();
|
|
210
|
+
},
|
|
211
|
+
error: async (_method, _url, _options, status) => {
|
|
212
|
+
if (status === 401) logout();
|
|
213
|
+
},
|
|
214
|
+
}, false, 30_000);
|
|
215
|
+
|
|
216
|
+
const me = await api.get("/me", { useCache: true });
|
|
217
|
+
await api.clearCache("GET", "/me");
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
Features:
|
|
221
|
+
|
|
222
|
+
- auto `content-type` inference
|
|
223
|
+
- JSON/text/form-urlencoded body normalization
|
|
224
|
+
- AbortSignal support (`factory(signal)`)
|
|
225
|
+
- in-memory request cache (`cacheTime` + `useCache`)
|
|
226
|
+
|
|
227
|
+
---
|
|
228
|
+
|
|
229
|
+
## // UI Components (separate imports)
|
|
230
|
+
|
|
231
|
+
`cruzo` now exposes UI components via dedicated subpaths:
|
|
232
|
+
|
|
233
|
+
```ts
|
|
234
|
+
import { InputComponent, InputConfig } from "cruzo/ui-components/input";
|
|
235
|
+
import { ButtonGroupComponent, ButtonGroupConfig } from "cruzo/ui-components/button-group";
|
|
236
|
+
import { SelectComponent, SelectConfig } from "cruzo/ui-components/select";
|
|
237
|
+
import { RouterLinkComponent, RouterLinkConfig } from "cruzo/ui-components/router-link";
|
|
238
|
+
import { SpinnerComponent, SpinnerConfig, SpinnerValue } from "cruzo/ui-components/spinner";
|
|
239
|
+
import { UploadComponent, UploadConfig } from "cruzo/ui-components/upload";
|
|
240
|
+
import { ModalComponent, ModalConfig } from "cruzo/ui-components/modal";
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
CSS is also per-component:
|
|
244
|
+
|
|
245
|
+
```ts
|
|
246
|
+
import "cruzo/ui-components/input.css";
|
|
247
|
+
import "cruzo/ui-components/button-group.css";
|
|
248
|
+
import "cruzo/ui-components/select.css";
|
|
249
|
+
import "cruzo/ui-components/spinner.css";
|
|
250
|
+
import "cruzo/ui-components/modal.css";
|
|
251
|
+
import "cruzo/ui-components/upload.css";
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## // Notes For Night Shift
|
|
257
|
+
|
|
258
|
+
- no default export
|
|
259
|
+
- no runtime deps
|
|
260
|
+
- no global css reset bundled
|
|
261
|
+
- UI components are opt-in by import path
|
|
262
|
+
- template expressions run in Cruzo VM (not eval)
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## License
|
|
267
|
+
|
|
268
|
+
MIT
|
package/assets/cruzo.png
ADDED
|
Binary file
|