cajoa 0.6.0 → 0.8.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.
Files changed (3) hide show
  1. package/LICENSE +201 -201
  2. package/README.md +273 -223
  3. package/package.json +85 -40
package/LICENSE CHANGED
@@ -1,201 +1,201 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,223 +1,273 @@
1
- # Cajoa
2
-
3
- A small, beginner-friendly frontend framework built on **signals** and **JSX**.
4
- No virtual DOM, no hooks rules, no re-rendering components.
5
-
6
- > ⚠️ **v0.6 (early stage).** The API may still change. Not production-ready yet.
7
-
8
- ## Why Cajoa?
9
-
10
- - **Components run once.** A component is just a function that builds DOM. Only the parts that depend on a signal update.
11
- - **Plain JSX.** Write `<button onClick={...}>`, no special syntax to learn.
12
- - **Tiny and readable.** The whole core is small enough to read in one sitting.
13
- - **TypeScript-first**, ESM + CommonJS, zero runtime dependencies.
14
-
15
- ## Install
16
-
17
- ```bash
18
- npm create cajoa@latest my-app
19
- ```
20
-
21
- ## Setup (JSX)
22
-
23
- In your `tsconfig.json`:
24
-
25
- ```json
26
- {
27
- "compilerOptions": {
28
- "jsx": "react-jsx",
29
- "jsxImportSource": "cajoa"
30
- }
31
- }
32
- ```
33
-
34
- If you use Vite and your JSX is not transformed, also set it in `vite.config.ts`
35
- (`oxc: { jsx: { runtime: "automatic", importSource: "cajoa" } }` on newer Vite,
36
- or `esbuild: { jsx: "automatic", jsxImportSource: "cajoa" }` on older ones).
37
-
38
- ## Quick start
39
-
40
- ```tsx
41
- import { createSignal, render } from "cajoa";
42
-
43
- function Counter() {
44
- const [count, setCount] = createSignal(0);
45
-
46
- return (
47
- <button onClick={() => setCount((c) => c + 1)}>
48
- Clicked {count} times
49
- </button>
50
- );
51
- }
52
-
53
- render(Counter, document.getElementById("app")!);
54
- ```
55
-
56
- ## Two rules to remember
57
-
58
- Cajoa has no compiler, so JSX expressions run exactly once. That gives two rules:
59
-
60
- 1. **Pass the signal, don't call it.**
61
- `{count}` is reactive. `{count()}` is read once and never updates.
62
- For computed values, pass a function: `{() => count() * 2}`.
63
- 2. **`Show` children are a function.**
64
- `<Show when={on}>{() => <p>Hello</p>}</Show>`
65
- Otherwise the element is created even when it is hidden.
66
-
67
- ## Lists and conditions
68
-
69
- ```tsx
70
- import { createSignal, Show, For } from "cajoa";
71
-
72
- const [todos, setTodos] = createSignal([{ id: 1, text: "Learn Cajoa" }]);
73
-
74
- <Show when={() => todos().length > 0} fallback={() => <p>Nothing to do.</p>}>
75
- {() => (
76
- <ul>
77
- <For each={todos}>{(todo) => <li>{todo.text}</li>}</For>
78
- </ul>
79
- )}
80
- </Show>;
81
- ```
82
-
83
- ## Routing
84
-
85
- ```tsx
86
- import { render, Router, Route, Link, useParams } from "cajoa";
87
-
88
- const User = () => <h1>User {useParams().id}</h1>;
89
-
90
- render(
91
- () => (
92
- <div>
93
- <nav>
94
- <Link href="/">Home</Link> <Link href="/users/7">User 7</Link>
95
- </nav>
96
- <Router>
97
- <Route path="/" component={() => <h1>Home</h1>} />
98
- <Route path="/users/:id" component={User} />
99
- <Route path="*" component={() => <h1>Not found</h1>} />
100
- </Router>
101
- </div>
102
- ),
103
- document.getElementById("app")!,
104
- );
105
- ```
106
-
107
- Routes are matched in order, so put `path="*"` last.
108
-
109
- ## API
110
-
111
- ### Reactivity
112
-
113
- | Function | What it does |
114
- | --------------------- | ---------------------------------------------------------------------------------------------------------------------- |
115
- | `createSignal(value)` | Returns `[get, set]`. Reading `get()` inside an effect subscribes to it. `set` accepts a value or an updater function. |
116
- | `createEffect(fn)` | Runs `fn` now and again whenever a signal it read changes. |
117
- | `createMemo(fn)` | Cached computed value. Only notifies when the result changes. |
118
- | `batch(fn)` | Groups several `set` calls into one update. |
119
-
120
- ### Components
121
-
122
- | Component | What it does |
123
- | ---------------------- | ---------------------------------------------------------------------------------------------------- |
124
- | `<Show when fallback>` | Conditional rendering. `children` and `fallback` are functions. |
125
- | `<For each key?>` | List rendering. Reuses DOM nodes for unchanged items. The child is a function that returns a `Node`. |
126
-
127
- ### Rendering
128
-
129
- | Function | What it does |
130
- | ------------------------------ | ------------------------------------------------- |
131
- | `render(component, container)` | Mounts a component. Returns a `dispose` function. |
132
- | `h(tag, props, ...children)` | Low-level element creator. JSX compiles to this. |
133
-
134
- ### Lifecycle
135
-
136
- | Function | What it does |
137
- | ---------------- | ----------------------------------------------------------------- |
138
- | `onMount(fn)` | Runs `fn` after the component is rendered. |
139
- | `onCleanup(fn)` | Runs `fn` before an effect re-runs or when its owner is disposed. |
140
- | `createRoot(fn)` | Creates a top-level owner you can dispose manually. |
141
-
142
- ### Context
143
-
144
- | Function | What it does |
145
- | ------------------------- | ------------------------------------------------------ |
146
- | `createContext(default)` | Creates a context with a default value. |
147
- | `provide(ctx, value, fn)` | Runs `fn`; everything created inside can read `value`. |
148
- | `useContext(ctx)` | Reads the nearest provided value (or the default). |
149
-
150
- ### Router
151
-
152
- | Function | What it does |
153
- | ---------------------------- | ---------------------------------------------------------- |
154
- | `<Router>` | Renders the first `<Route>` that matches the current path. |
155
- | `<Route path component>` | Maps a path (`/users/:id`, `*`) to a component. |
156
- | `<Link href>` | An `<a>` that navigates without reloading the page. |
157
- | `navigate(to, { replace? })` | Navigates programmatically. |
158
- | `useParams()` | Reads the route params (`{ id: "7" }`). |
159
- | `usePath()` | Returns a signal getter for the current pathname. |
160
- | `untrack(fn)` | Runs `fn` without subscribing to signals. |
161
-
162
- ### Renderer
163
-
164
- | Function | What it does |
165
- | ----------------------- | ------------------------------------------------------------------ |
166
- | `setRenderer(renderer)` | Swaps the renderer (default: DOM). Used to target other platforms. |
167
- | `getRenderer()` | Returns the current renderer. |
168
- | `domRenderer` | The built-in DOM renderer. |
169
-
170
- ## Packages
171
-
172
- | Package | What it is |
173
- | ------------- | -------------------------------------------------------------------- |
174
- | `cajoa` | The package most apps install (core + DOM) |
175
- | `@cajoa/core` | Renderer-agnostic core: signals, JSX runtime, `Show`, `For`, context |
176
- | `@cajoa/dom` | DOM renderer and router |
177
-
178
- ## Good to know
179
-
180
- - `For` uses the item itself as the key by default. If you pass `key`, items with the same key are **not** re-rendered when their data changes, so keys must be unique and the item should hold its own signals if it needs to update.
181
- - `useContext` only works while a component is being created (or inside `onMount` / effects). Read it at the top of your component and use the value later in handlers.
182
- - Updating an object in place will not trigger effects. Set a new object instead.
183
- - Fragments (`<>...</>`) work anywhere, but inside `<For>` the child must be a single element, because `For` reuses that node.
184
-
185
- ## Known limitations
186
-
187
- - No SSR.
188
- - Router: pathname only (no query/hash handling), no nested routes, no `base` path.
189
- - `<Show>` and `<Router>` return a function, so they must sit inside an element, not be the root returned by `render`.
190
- - Single-page apps need a server fallback to `index.html` for unknown paths.
191
- - `createMemo` can show a brief inconsistent state when memos depend on each other.
192
- - `set` calls are not batched automatically inside event handlers. Wrap them in `batch()`.
193
- - The Router and event names (`onClick`) are still web-specific for now.
194
-
195
- ## Roadmap
196
-
197
- - [x] Signals and effects
198
- - [x] DOM bindings and `render`
199
- - [x] `Show`, `For` (keyed)
200
- - [x] Lifecycle and disposal
201
- - [x] `createMemo`, `batch`
202
- - [x] Context
203
- - [x] JSX support
204
- - [x] Fragments
205
- - [x] Router
206
- - [x] Renderer abstraction (core no longer depends on DOM)
207
- - [ ] Split into packages ('@cajoa/core', '@cajoa/dom')
208
- - [ ] Vite plugin (removes the two rules above)
209
- - [ ] Native renderer (mobile, desktop)
210
- - [ ] SSR
211
-
212
- ## Development
213
-
214
- ```bash
215
- npm install
216
- npm test # run tests
217
- npm run dev # open the playground
218
- npm run build # build to dist/
219
- ```
220
-
221
- ## License
222
-
223
- [Apache-2.0](./LICENSE)
1
+ # Cajoa
2
+
3
+ A small, beginner-friendly frontend framework built on **signals** and **JSX**.
4
+ No virtual DOM, no hooks rules, no re-rendering components.
5
+
6
+ > ⚠️ **Early stage.** The API may still change before 1.0.
7
+
8
+ ## Why Cajoa?
9
+
10
+ - **Components run once.** A component is just a function that builds DOM. Only the parts that depend on a signal update.
11
+ - **Plain JSX.** Write `<button onClick={...}>`, no special syntax to learn.
12
+ - **Tiny and readable.** The core is small enough to read in one sitting.
13
+ - **Renderer-agnostic core.** `@cajoa/core` has no DOM dependency, so other targets (native, SSR) can plug in their own renderer.
14
+ - **TypeScript-first**, ESM + CommonJS, zero runtime dependencies.
15
+
16
+ ## Get started
17
+
18
+ The fastest way is the starter:
19
+
20
+ ```bash
21
+ npm create cajoa@latest my-app
22
+ cd my-app
23
+ npm install
24
+ npm run dev
25
+ ```
26
+
27
+ Or add Cajoa to an existing project:
28
+
29
+ ```bash
30
+ npm install cajoa
31
+ ```
32
+
33
+ ### Manual JSX setup
34
+
35
+ In your `tsconfig.json`:
36
+
37
+ ```json
38
+ {
39
+ "compilerOptions": {
40
+ "jsx": "react-jsx",
41
+ "jsxImportSource": "cajoa"
42
+ }
43
+ }
44
+ ```
45
+
46
+ With Vite, also set it in `vite.config.ts`
47
+ (`oxc: { jsx: { runtime: "automatic", importSource: "cajoa" } }` on newer Vite,
48
+ or `esbuild: { jsx: "automatic", jsxImportSource: "cajoa" }` on older ones).
49
+
50
+ ## Quick start
51
+
52
+ ```tsx
53
+ import { createSignal, render } from "cajoa";
54
+
55
+ function Counter() {
56
+ const [count, setCount] = createSignal(0);
57
+
58
+ return (
59
+ <button onClick={() => setCount((c) => c + 1)}>
60
+ Clicked {count} times
61
+ </button>
62
+ );
63
+ }
64
+
65
+ render(Counter, document.getElementById("app")!);
66
+ ```
67
+
68
+ ## Two rules to remember
69
+
70
+ Cajoa has no compiler yet, so JSX expressions run exactly once. That gives two rules:
71
+
72
+ 1. **Pass the signal, don't call it.**
73
+ `{count}` is reactive. `{count()}` is read once and never updates.
74
+ For computed values, pass a function: `{() => count() * 2}`.
75
+ 2. **`Show` children are a function.**
76
+ `<Show when={on}>{() => <p>Hello</p>}</Show>`
77
+ Otherwise the element is created even when it is hidden.
78
+
79
+ ## Lists and conditions
80
+
81
+ ```tsx
82
+ import { createSignal, Show, For } from "cajoa";
83
+
84
+ const [todos, setTodos] = createSignal([{ id: 1, text: "Learn Cajoa" }]);
85
+
86
+ <Show when={() => todos().length > 0} fallback={() => <p>Nothing to do.</p>}>
87
+ {() => (
88
+ <ul>
89
+ <For each={todos}>{(todo) => <li>{todo.text}</li>}</For>
90
+ </ul>
91
+ )}
92
+ </Show>;
93
+ ```
94
+
95
+ ## Routing
96
+
97
+ ## Forms, styles and events
98
+
99
+ ```tsx
100
+ const [name, setName] = createSignal("");
101
+ const [agree, setAgree] = createSignal(false);
102
+
103
+ <form>
104
+ <input
105
+ placeholder="Name"
106
+ value={name}
107
+ onInput={(e) => setName(e.target.value)}
108
+ />
109
+ <label>
110
+ <input
111
+ type="checkbox"
112
+ checked={agree}
113
+ onChange={(e) => setAgree(e.target.checked)}
114
+ />
115
+ I agree
116
+ </label>
117
+ <p style={() => ({ color: agree() ? "green" : "gray", fontSize: "18px" })}>
118
+ Hello, {() => name() || "stranger"}!
119
+ </p>
120
+ </form>;
121
+ ```
122
+
123
+ - `value`, `checked` and `selected` are set as DOM properties, so they stay in sync even after the user typed. Write `value` after `type`, `min` and `max`.
124
+ - `style` takes a string or an object (camelCase keys, kebab-case keys, or custom properties like `--accent`). Numbers are not converted to `px`, so write `"12px"`. For a reactive style, pass a function: `style={() => ({ color: color() })}`. An object with signals inside, like `style={{ color: color() }}`, is read once.
125
+ - Events are native DOM events. `onChange` fires when a field loses focus, so use `onInput` for every keystroke. `onDoubleClick` listens to `dblclick`.
126
+ - `className` and `htmlFor` work. Inline string handlers like `onclick="..."` are ignored.
127
+
128
+ ```tsx
129
+ import { render, Router, Route, Link, useParams } from "cajoa";
130
+
131
+ const User = () => <h1>User {useParams().id}</h1>;
132
+
133
+ render(
134
+ () => (
135
+ <div>
136
+ <nav>
137
+ <Link href="/">Home</Link> <Link href="/users/7">User 7</Link>
138
+ </nav>
139
+ <Router>
140
+ <Route path="/" component={() => <h1>Home</h1>} />
141
+ <Route path="/users/:id" component={User} />
142
+ <Route path="*" component={() => <h1>Not found</h1>} />
143
+ </Router>
144
+ </div>
145
+ ),
146
+ document.getElementById("app")!,
147
+ );
148
+ ```
149
+
150
+ Routes are matched in order, so put `path="*"` last.
151
+
152
+ ## Packages
153
+
154
+ | Package | What it is |
155
+ | -------------- | ------------------------------------------------------------------------------------------ |
156
+ | `cajoa` | The package most apps install (core + DOM) |
157
+ | `@cajoa/core` | Renderer-agnostic core: signals, JSX runtime, `Show`, `For`, context, `Renderer` interface |
158
+ | `@cajoa/dom` | DOM renderer and router |
159
+ | `create-cajoa` | Project starter (`npm create cajoa@latest`) |
160
+
161
+ ## API
162
+
163
+ ### Reactivity
164
+
165
+ | Function | What it does |
166
+ | --------------------- | ---------------------------------------------------------------------------------------------------------------------- |
167
+ | `createSignal(value)` | Returns `[get, set]`. Reading `get()` inside an effect subscribes to it. `set` accepts a value or an updater function. |
168
+ | `createEffect(fn)` | Runs `fn` now and again whenever a signal it read changes. |
169
+ | `createMemo(fn)` | Cached computed value. Only notifies when the result changes. |
170
+ | `batch(fn)` | Groups several `set` calls into one update. |
171
+ | `untrack(fn)` | Runs `fn` without subscribing to signals. |
172
+
173
+ ### Components
174
+
175
+ | Component | What it does |
176
+ | ---------------------- | --------------------------------------------------------------------------------------------------------- |
177
+ | `<Show when fallback>` | Conditional rendering. `children` and `fallback` are functions. |
178
+ | `<For each key?>` | List rendering. Reuses DOM nodes for unchanged items. The child is a function that returns a single node. |
179
+ | `<>...</>` (Fragment) | Groups siblings without a wrapper element. |
180
+
181
+ ### Rendering
182
+
183
+ | Function | What it does |
184
+ | ------------------------------ | ------------------------------------------------- |
185
+ | `render(component, container)` | Mounts a component. Returns a `dispose` function. |
186
+ | `h(tag, props, ...children)` | Low-level element creator. JSX compiles to this. |
187
+
188
+ ### Lifecycle
189
+
190
+ | Function | What it does |
191
+ | ---------------- | ----------------------------------------------------------------- |
192
+ | `onMount(fn)` | Runs `fn` after the component is rendered. |
193
+ | `onCleanup(fn)` | Runs `fn` before an effect re-runs or when its owner is disposed. |
194
+ | `createRoot(fn)` | Creates a top-level owner you can dispose manually. |
195
+
196
+ ### Context
197
+
198
+ | Function | What it does |
199
+ | ------------------------- | ------------------------------------------------------ |
200
+ | `createContext(default)` | Creates a context with a default value. |
201
+ | `provide(ctx, value, fn)` | Runs `fn`; everything created inside can read `value`. |
202
+ | `useContext(ctx)` | Reads the nearest provided value (or the default). |
203
+
204
+ ### Router
205
+
206
+ | Function | What it does |
207
+ | ---------------------------- | ---------------------------------------------------------- |
208
+ | `<Router>` | Renders the first `<Route>` that matches the current path. |
209
+ | `<Route path component>` | Maps a path (`/users/:id`, `*`) to a component. |
210
+ | `<Link href>` | An `<a>` that navigates without reloading the page. |
211
+ | `navigate(to, { replace? })` | Navigates programmatically. |
212
+ | `useParams()` | Reads the route params (`{ id: "7" }`). |
213
+ | `usePath()` | Returns a signal getter for the current pathname. |
214
+
215
+ ### Renderer
216
+
217
+ | Function | What it does |
218
+ | ----------------------- | ------------------------------------------------------------------ |
219
+ | `setRenderer(renderer)` | Swaps the renderer (default: DOM). Used to target other platforms. |
220
+ | `getRenderer()` | Returns the current renderer. |
221
+ | `domRenderer` | The built-in DOM renderer. |
222
+
223
+ ## Good to know
224
+
225
+ - `For` uses the item itself as the key by default. If you pass `key`, items with the same key are **not** re-rendered when their data changes, so keys must be unique and the item should hold its own signals if it needs to update.
226
+ - Inside `<For>`, return a single element (not a fragment), because `For` reuses that node.
227
+ - `useContext` and `useParams` only work while a component is being created (or inside `onMount` / effects). Read them at the top of your component and use the value later in handlers.
228
+ - Updating an object in place will not trigger effects. Set a new object instead.
229
+
230
+ ## Known limitations
231
+
232
+ - No SSR.
233
+ - Router: pathname only (no query/hash handling), no nested routes, no `base` path.
234
+ - `<Show>` and `<Router>` return a function, so they must sit inside an element, not be the root returned by `render`.
235
+ - Single-page apps need a server fallback to `index.html` for unknown paths.
236
+ - SVG is not supported yet: `<svg>` is created as an HTML element, so it does not render.
237
+ - No `ref` prop yet.
238
+ - `<select value>` works only when the `<option>` elements are direct children of the `<select>`.
239
+ - `createMemo` can show a brief inconsistent state when memos depend on each other.
240
+ - `set` calls are not batched automatically inside event handlers. Wrap them in `batch()`.
241
+ - Types in the core use a loose `HostNode` type for now.
242
+
243
+ ## Roadmap
244
+
245
+ - [x] Signals, effects, memo, batch
246
+ - [x] DOM bindings, `Show`, keyed `For`, Fragments
247
+ - [x] Lifecycle, context
248
+ - [x] JSX support
249
+ - [x] Router
250
+ - [x] Renderer abstraction, split into packages
251
+ - [x] Automated releases
252
+ - [x] Form, style and event handling in the DOM renderer
253
+ - [ ] SVG and `ref` support
254
+ - [ ] Vite plugin (removes the two rules above)
255
+ - [ ] Better form and style handling in the DOM renderer
256
+ - [ ] Native renderers (mobile, desktop)
257
+ - [ ] SSR
258
+ - [ ] Docs site
259
+
260
+ ## Development
261
+
262
+ ```bash
263
+ npm install
264
+ npm test # run tests
265
+ npm run dev # open the playground
266
+ npm run verify # typecheck, tests, build, sync and package checks
267
+ ```
268
+
269
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for the release flow.
270
+
271
+ ## License
272
+
273
+ [Apache-2.0](./LICENSE)
package/package.json CHANGED
@@ -1,40 +1,85 @@
1
- {
2
- "name": "cajoa",
3
- "version": "0.6.0",
4
- "description": "A small, beginner-friendly frontend framework built on signals and JSX.",
5
- "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
12
- "require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
13
- },
14
- "./jsx-runtime": {
15
- "import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
16
- "require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
17
- },
18
- "./jsx-dev-runtime": {
19
- "import": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
20
- "require": { "types": "./dist/index.d.cts", "default": "./dist/index.cjs" }
21
- }
22
- },
23
- "files": ["dist"],
24
- "sideEffects": true,
25
- "dependencies": {
26
- "@cajoa/core": "^0.6.0",
27
- "@cajoa/dom": "^0.6.0"
28
- },
29
- "scripts": { "build": "tsup src/index.ts --format esm,cjs --dts --clean" },
30
- "repository": {
31
- "type": "git",
32
- "url": "git+https://github.com/CajoaTS/Cajoa.git",
33
- "directory": "packages/cajoa"
34
- },
35
- "keywords": ["frontend", "framework", "signals", "reactive", "ui", "cajoa"],
36
- "author": "cjmgrc",
37
- "license": "Apache-2.0",
38
- "bugs": { "url": "https://github.com/CajoaTS/Cajoa/issues" },
39
- "homepage": "https://github.com/CajoaTS/Cajoa#readme"
40
- }
1
+ {
2
+ "name": "cajoa",
3
+ "version": "0.8.0",
4
+ "description": "A small, beginner-friendly frontend framework built on signals and JSX.",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ },
20
+ "./jsx-runtime": {
21
+ "import": {
22
+ "types": "./dist/index.d.ts",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/index.d.cts",
27
+ "default": "./dist/index.cjs"
28
+ }
29
+ },
30
+ "./jsx-dev-runtime": {
31
+ "import": {
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "require": {
36
+ "types": "./dist/index.d.cts",
37
+ "default": "./dist/index.cjs"
38
+ }
39
+ }
40
+ },
41
+ "typesVersions": {
42
+ "*": {
43
+ "jsx-runtime": [
44
+ "./dist/index.d.ts"
45
+ ],
46
+ "jsx-dev-runtime": [
47
+ "./dist/index.d.ts"
48
+ ]
49
+ }
50
+ },
51
+ "engines": {
52
+ "node": ">=18"
53
+ },
54
+ "files": [
55
+ "dist"
56
+ ],
57
+ "sideEffects": true,
58
+ "dependencies": {
59
+ "@cajoa/core": "^0.8.0",
60
+ "@cajoa/dom": "^0.8.0"
61
+ },
62
+ "scripts": {
63
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean",
64
+ "check:package": "publint && attw --pack ."
65
+ },
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "git+https://github.com/CajoaTS/Cajoa.git",
69
+ "directory": "packages/cajoa"
70
+ },
71
+ "keywords": [
72
+ "frontend",
73
+ "framework",
74
+ "signals",
75
+ "reactive",
76
+ "ui",
77
+ "cajoa"
78
+ ],
79
+ "author": "cjmgrc",
80
+ "license": "Apache-2.0",
81
+ "bugs": {
82
+ "url": "https://github.com/CajoaTS/Cajoa/issues"
83
+ },
84
+ "homepage": "https://github.com/CajoaTS/Cajoa#readme"
85
+ }