@motifx/core 1.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-2026 Ekrem Erşahin
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,136 @@
1
+ # @motifx/core
2
+
3
+ A UI framework for JavaScript and TypeScript: components written as classes, functions or options objects, fine-grained reactivity without a virtual DOM, routing and dependency injection in one package.
4
+
5
+ - **No render loop.** Components are bound directly to real DOM nodes; a state change updates only the node or attribute that depends on it.
6
+ - **Compiled JSX.** The [`@motifx/compiler`](https://www.npmjs.com/package/@motifx/compiler) compiler lowers JSX into direct reactive bindings at build time.
7
+ - **Batteries included.** Router, dependency injection, lifecycle hooks, transitions, list virtualization and resource disposal ship with the core.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ npm install @motifx/core
13
+ npm install -D @motifx/compiler vite typescript
14
+ ```
15
+
16
+ ## Setup
17
+
18
+ `vite.config.ts`:
19
+
20
+ ```ts
21
+ import { defineConfig } from 'vite';
22
+ import compiler from '@motifx/compiler';
23
+
24
+ export default defineConfig({
25
+ plugins: [compiler()],
26
+ esbuild: { jsx: 'preserve' },
27
+ });
28
+ ```
29
+
30
+ `tsconfig.json`:
31
+
32
+ ```json
33
+ {
34
+ "compilerOptions": {
35
+ "target": "ES2021",
36
+ "module": "esnext",
37
+ "moduleResolution": "bundler",
38
+ "strict": true,
39
+ "jsx": "preserve",
40
+ "useDefineForClassFields": true,
41
+ "lib": ["ESNext", "DOM", "DOM.Iterable"]
42
+ }
43
+ }
44
+ ```
45
+
46
+ `jsx: "preserve"` is required in both places: the JSX is compiled by `@motifx/compiler`, not by esbuild or TypeScript.
47
+
48
+ ## A first component
49
+
50
+ ```tsx
51
+ import { Application, Component, reactive } from '@motifx/core';
52
+
53
+ class Counter extends Component {
54
+ state = reactive({ value: 0 });
55
+
56
+ view() {
57
+ return (
58
+ <div>
59
+ <button type="button" onclick={() => this.state.value--}>−</button>
60
+ <output>{this.state.value}</output>
61
+ <button type="button" onclick={() => this.state.value++}>+</button>
62
+ </div>
63
+ );
64
+ }
65
+ }
66
+
67
+ const app = Application.CreateBuilder().build();
68
+ app.run('#app', new Counter());
69
+ ```
70
+
71
+ With a router, pass no root component and MotifJS mounts a `RouterView` for you:
72
+
73
+ ```ts
74
+ import { Application } from '@motifx/core';
75
+ import { routes } from './routes';
76
+
77
+ const app = Application.CreateBuilder().build();
78
+ app.useRouter({ routes, mode: 'history' });
79
+ app.run('#app');
80
+ ```
81
+
82
+ ## Using a CDN
83
+
84
+ A UMD build is published for use without a build step. It exposes the global `motif`:
85
+
86
+ ```html
87
+ <div id="app"></div>
88
+ <script src="https://cdn.jsdelivr.net/npm/@motifx/core@1/dist/index.umd.min.js"></script>
89
+ <script>
90
+ const { Application, Component, reactive } = motif;
91
+ const state = reactive({ count: 0 });
92
+
93
+ class Counter extends Component {
94
+ constructor() { super('button'); }
95
+ onConfig() {
96
+ this.bindings.add('textContent', state, 'count');
97
+ this.motif.on('click', () => state.count++);
98
+ }
99
+ }
100
+
101
+ Application.CreateBuilder().build().run('#app', new Counter());
102
+ </script>
103
+ ```
104
+
105
+ JSX needs the `@motifx/compiler` compiler, so CDN usage relies on the binding API directly.
106
+
107
+ ## Package contents
108
+
109
+ | File | Format |
110
+ | --- | --- |
111
+ | `dist/index.esm.js` | ES module (`import`) |
112
+ | `dist/index.cjs` | CommonJS (`require`) |
113
+ | `dist/index.umd.js`, `dist/index.umd.min.js` | UMD for `<script>` tags, global `motif` |
114
+ | `dist/index.esm.min.js` | Single-file ES module for `<script type="module">` |
115
+
116
+ Every build ships with a source map that points into the included `src/` folder.
117
+
118
+ ## Diagnostics
119
+
120
+ Reactivity inspection helpers live in a separate entry point so they stay out of the main API:
121
+
122
+ ```ts
123
+ import { debugGetDeps } from '@motifx/core/devtools';
124
+
125
+ const deps = debugGetDeps(state);
126
+ ```
127
+
128
+ `debugGetDeps(target)` returns the effects subscribed to each key of a reactive object; `debugGetDepMap()` returns the whole dependency map. They share the runtime instance with `@motifx/core`.
129
+
130
+ ## Documentation
131
+
132
+ Guides and API reference: [motifjs.com](https://motifjs.com/)
133
+
134
+ ## License
135
+
136
+ [MIT](./LICENSE)