@vorra/core 0.3.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/CHANGELOG.md +15 -0
- package/dist/chunk-X_3F6bsP.js +31 -0
- package/dist/di.cjs +273 -0
- package/dist/di.cjs.map +1 -0
- package/dist/di.d.ts +175 -0
- package/dist/di.d.ts.map +1 -0
- package/dist/di.js +261 -0
- package/dist/di.js.map +1 -0
- package/dist/dom.cjs +302 -0
- package/dist/dom.cjs.map +1 -0
- package/dist/dom.d.ts +136 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +285 -0
- package/dist/dom.js.map +1 -0
- package/dist/index.cjs +38 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/reactivity.cjs +232 -0
- package/dist/reactivity.cjs.map +1 -0
- package/dist/reactivity.d.ts +88 -0
- package/dist/reactivity.d.ts.map +1 -0
- package/dist/reactivity.js +226 -0
- package/dist/reactivity.js.map +1 -0
- package/package.json +63 -0
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { EffectHandle } from './reactivity.js';
|
|
2
|
+
import { Injector } from './di.js';
|
|
3
|
+
import type { Provider } from './di.js';
|
|
4
|
+
export interface ComponentContext {
|
|
5
|
+
injector: Injector;
|
|
6
|
+
effects: EffectHandle[];
|
|
7
|
+
children: ComponentContext[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Creates a DOM element with the given tag name.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const div = createElement('div');
|
|
14
|
+
*/
|
|
15
|
+
export declare function createElement(tag: string): Element;
|
|
16
|
+
/**
|
|
17
|
+
* Sets a static attribute on an element.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* setAttr(el, 'class', 'container');
|
|
21
|
+
*/
|
|
22
|
+
export declare function setAttr(el: Element, name: string, value: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Sets a DOM property directly (e.g. value, checked, disabled).
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* setProp(input, 'value', 'hello');
|
|
28
|
+
*/
|
|
29
|
+
export declare function setProp(el: Element, name: string, value: unknown): void;
|
|
30
|
+
/**
|
|
31
|
+
* Attaches an event listener and returns an EffectHandle to remove it.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const handle = listen(btn, 'click', () => count.update(n => n + 1));
|
|
35
|
+
* handle.destroy(); // removes listener
|
|
36
|
+
*/
|
|
37
|
+
export declare function listen(el: Element, event: string, handler: EventListener): EffectHandle;
|
|
38
|
+
/**
|
|
39
|
+
* Inserts a child node into a parent, optionally before an anchor node.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* insert(container, textNode);
|
|
43
|
+
* insert(list, item, anchor); // insert before anchor
|
|
44
|
+
*/
|
|
45
|
+
export declare function insert(parent: Node, child: Node, anchor?: Node | null): void;
|
|
46
|
+
/**
|
|
47
|
+
* Removes a node from the DOM.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* remove(el);
|
|
51
|
+
*/
|
|
52
|
+
export declare function remove(node: Node): void;
|
|
53
|
+
/**
|
|
54
|
+
* Binds a getter to a Text node's content. The text updates surgically
|
|
55
|
+
* whenever the getter's signal dependencies change.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* const t = document.createTextNode('');
|
|
59
|
+
* bindText(t, () => String(count()));
|
|
60
|
+
*/
|
|
61
|
+
export declare function bindText(node: Text, getter: () => string): EffectHandle;
|
|
62
|
+
/**
|
|
63
|
+
* Binds a getter to an element attribute. When the getter returns `null`,
|
|
64
|
+
* the attribute is removed.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* bindAttr(el, 'disabled', () => isDisabled() ? '' : null);
|
|
68
|
+
*/
|
|
69
|
+
export declare function bindAttr(el: Element, name: string, getter: () => string | null): EffectHandle;
|
|
70
|
+
/**
|
|
71
|
+
* Binds a getter to a DOM property. Updates the property directly whenever
|
|
72
|
+
* the getter's signal dependencies change.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* bindProp(input, 'value', () => name());
|
|
76
|
+
*/
|
|
77
|
+
export declare function bindProp(el: Element, name: string, getter: () => unknown): EffectHandle;
|
|
78
|
+
/**
|
|
79
|
+
* Binds a getter to element visibility. When the getter returns `false`,
|
|
80
|
+
* `display: none` is applied; otherwise the inline style is cleared.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* bindShow(el, () => isVisible());
|
|
84
|
+
*/
|
|
85
|
+
export declare function bindShow(el: Element, getter: () => boolean): EffectHandle;
|
|
86
|
+
/**
|
|
87
|
+
* Binds a getter to a set of CSS classes. Each key in the record is a class
|
|
88
|
+
* name; when the value is `true` the class is added, when `false` it is
|
|
89
|
+
* removed. Classes not in the record are left untouched.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* bindClass(el, () => ({ active: isActive(), disabled: isDisabled() }));
|
|
93
|
+
*/
|
|
94
|
+
export declare function bindClass(el: Element, getter: () => Record<string, boolean>): EffectHandle;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a ComponentContext scoped to a child injector derived from
|
|
97
|
+
* `parentInjector`. The context owns all EffectHandles created during
|
|
98
|
+
* the component's lifetime.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* const ctx = createComponent(app, [{ provide: MY_TOKEN, useValue: 42 }]);
|
|
102
|
+
*/
|
|
103
|
+
export declare function createComponent(parentInjector: Injector, providers?: Provider[]): ComponentContext;
|
|
104
|
+
/**
|
|
105
|
+
* Tears down a ComponentContext: destroys all child contexts recursively,
|
|
106
|
+
* then destroys all owned effects, then destroys the injector.
|
|
107
|
+
*
|
|
108
|
+
* @example
|
|
109
|
+
* destroyComponent(ctx);
|
|
110
|
+
*/
|
|
111
|
+
export declare function destroyComponent(ctx: ComponentContext): void;
|
|
112
|
+
/**
|
|
113
|
+
* Mounts a compiled component factory into a container element. The factory
|
|
114
|
+
* receives the ComponentContext, builds the DOM subtree, and returns the
|
|
115
|
+
* root node which is then appended to the container.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* mountComponent(counterFactory, document.getElementById('app')!, ctx);
|
|
119
|
+
*/
|
|
120
|
+
export declare function mountComponent(factory: (ctx: ComponentContext, props?: Record<string, () => unknown>) => Node, container: Element, ctx: ComponentContext): void;
|
|
121
|
+
/**
|
|
122
|
+
* Instantiates a child component inside a parent's template. Creates a child
|
|
123
|
+
* ComponentContext scoped under the parent, registers it for lifecycle
|
|
124
|
+
* tracking, invokes the factory with the given props, and returns the root
|
|
125
|
+
* DOM node so the caller can insert it into the tree.
|
|
126
|
+
*
|
|
127
|
+
* Props are always passed as getter functions so both static and reactive
|
|
128
|
+
* values share a uniform call-site API: `props['label']()`.
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* // In a compiled parent template:
|
|
132
|
+
* const _e1 = mountChild(MyButton, ctx, { label: () => 'Click me' });
|
|
133
|
+
* insert(_e0, _e1);
|
|
134
|
+
*/
|
|
135
|
+
export declare function mountChild(factory: (ctx: ComponentContext, props: Record<string, () => unknown>) => Node, parentCtx: ComponentContext, props?: Record<string, () => unknown>): Node;
|
|
136
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../src/dom.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAMxC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,OAAO,EAAE,YAAY,EAAE,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AED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,EAAE,EAAE,OAAO,EACX,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC,YAAY,CAwBd;AAMD;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,cAAc,EAAE,QAAQ,EACxB,SAAS,CAAC,EAAE,QAAQ,EAAE,GACrB,gBAAgB,CAOlB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,CAe5D;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,OAAO,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,KAAK,IAAI,EAC/E,SAAS,EAAE,OAAO,EAClB,GAAG,EAAE,gBAAgB,GACpB,IAAI,CAGN;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,CAAC,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,KAAK,IAAI,EAC9E,SAAS,EAAE,gBAAgB,EAC3B,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAM,GACxC,IAAI,CAIN"}
|
package/dist/dom.js
ADDED
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import { effect } from "./reactivity.js";
|
|
2
|
+
//#region src/dom.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates a DOM element with the given tag name.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* const div = createElement('div');
|
|
8
|
+
*/
|
|
9
|
+
function createElement(tag) {
|
|
10
|
+
return document.createElement(tag);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Sets a static attribute on an element.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* setAttr(el, 'class', 'container');
|
|
17
|
+
*/
|
|
18
|
+
function setAttr(el, name, value) {
|
|
19
|
+
el.setAttribute(name, value);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Sets a DOM property directly (e.g. value, checked, disabled).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* setProp(input, 'value', 'hello');
|
|
26
|
+
*/
|
|
27
|
+
function setProp(el, name, value) {
|
|
28
|
+
el[name] = value;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Attaches an event listener and returns an EffectHandle to remove it.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* const handle = listen(btn, 'click', () => count.update(n => n + 1));
|
|
35
|
+
* handle.destroy(); // removes listener
|
|
36
|
+
*/
|
|
37
|
+
function listen(el, event, handler) {
|
|
38
|
+
el.addEventListener(event, handler);
|
|
39
|
+
return { destroy() {
|
|
40
|
+
el.removeEventListener(event, handler);
|
|
41
|
+
} };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Inserts a child node into a parent, optionally before an anchor node.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* insert(container, textNode);
|
|
48
|
+
* insert(list, item, anchor); // insert before anchor
|
|
49
|
+
*/
|
|
50
|
+
function insert(parent, child, anchor) {
|
|
51
|
+
parent.insertBefore(child, anchor ?? null);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Removes a node from the DOM.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* remove(el);
|
|
58
|
+
*/
|
|
59
|
+
function remove(node) {
|
|
60
|
+
node.parentNode?.removeChild(node);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Binds a getter to a Text node's content. The text updates surgically
|
|
64
|
+
* whenever the getter's signal dependencies change.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* const t = document.createTextNode('');
|
|
68
|
+
* bindText(t, () => String(count()));
|
|
69
|
+
*/
|
|
70
|
+
function bindText(node, getter) {
|
|
71
|
+
return effect(() => {
|
|
72
|
+
node.nodeValue = getter();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Binds a getter to an element attribute. When the getter returns `null`,
|
|
77
|
+
* the attribute is removed.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* bindAttr(el, 'disabled', () => isDisabled() ? '' : null);
|
|
81
|
+
*/
|
|
82
|
+
function bindAttr(el, name, getter) {
|
|
83
|
+
return effect(() => {
|
|
84
|
+
const value = getter();
|
|
85
|
+
if (value === null) el.removeAttribute(name);
|
|
86
|
+
else el.setAttribute(name, value);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Binds a getter to a DOM property. Updates the property directly whenever
|
|
91
|
+
* the getter's signal dependencies change.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* bindProp(input, 'value', () => name());
|
|
95
|
+
*/
|
|
96
|
+
function bindProp(el, name, getter) {
|
|
97
|
+
return effect(() => {
|
|
98
|
+
el[name] = getter();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Binds a getter to element visibility. When the getter returns `false`,
|
|
103
|
+
* `display: none` is applied; otherwise the inline style is cleared.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* bindShow(el, () => isVisible());
|
|
107
|
+
*/
|
|
108
|
+
function bindShow(el, getter) {
|
|
109
|
+
return effect(() => {
|
|
110
|
+
el.style.display = getter() ? "" : "none";
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Binds a getter to a set of CSS classes. Each key in the record is a class
|
|
115
|
+
* name; when the value is `true` the class is added, when `false` it is
|
|
116
|
+
* removed. Classes not in the record are left untouched.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* bindClass(el, () => ({ active: isActive(), disabled: isDisabled() }));
|
|
120
|
+
*/
|
|
121
|
+
function bindClass(el, getter) {
|
|
122
|
+
let prevClasses = {};
|
|
123
|
+
return effect(() => {
|
|
124
|
+
const next = getter();
|
|
125
|
+
for (const name of Object.keys(prevClasses)) if (prevClasses[name] === true && !next[name]) el.classList.remove(name);
|
|
126
|
+
for (const [name, active] of Object.entries(next)) if (active) el.classList.add(name);
|
|
127
|
+
else el.classList.remove(name);
|
|
128
|
+
prevClasses = next;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Reactively renders a list of items before an anchor comment node.
|
|
133
|
+
* Each item receives its own `ComponentContext` scoped under `parentCtx`
|
|
134
|
+
* so that bindings created inside the item template are properly cleaned
|
|
135
|
+
* up whenever the list re-renders.
|
|
136
|
+
*
|
|
137
|
+
* This is the runtime backing for the `@for` template directive.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* // Generated by: <li @for={item of items()}>…</li>
|
|
141
|
+
* const anchor = document.createComment('for');
|
|
142
|
+
* insert(container, anchor);
|
|
143
|
+
* ctx.effects.push(bindList(anchor, ctx, () => items(), (item, i, itemCtx) => {
|
|
144
|
+
* const li = createElement('li');
|
|
145
|
+
* const t = document.createTextNode('');
|
|
146
|
+
* itemCtx.effects.push(bindText(t, () => item.name));
|
|
147
|
+
* insert(li, t);
|
|
148
|
+
* return li;
|
|
149
|
+
* }));
|
|
150
|
+
*/
|
|
151
|
+
function bindList(anchor, parentCtx, getter, itemFactory) {
|
|
152
|
+
let activeItems = [];
|
|
153
|
+
return effect(() => {
|
|
154
|
+
const list = getter();
|
|
155
|
+
const parent = anchor.parentNode;
|
|
156
|
+
if (!parent) return;
|
|
157
|
+
for (const { node, ctx } of activeItems) {
|
|
158
|
+
parent.removeChild(node);
|
|
159
|
+
const idx = parentCtx.children.indexOf(ctx);
|
|
160
|
+
if (idx >= 0) parentCtx.children.splice(idx, 1);
|
|
161
|
+
destroyComponent(ctx);
|
|
162
|
+
}
|
|
163
|
+
activeItems = [];
|
|
164
|
+
for (let i = 0; i < list.length; i++) {
|
|
165
|
+
const itemCtx = createComponent(parentCtx.injector);
|
|
166
|
+
parentCtx.children.push(itemCtx);
|
|
167
|
+
const node = itemFactory(list[i], i, itemCtx);
|
|
168
|
+
parent.insertBefore(node, anchor);
|
|
169
|
+
activeItems.push({
|
|
170
|
+
node,
|
|
171
|
+
ctx: itemCtx
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Creates a ComponentContext scoped to a child injector derived from
|
|
178
|
+
* `parentInjector`. The context owns all EffectHandles created during
|
|
179
|
+
* the component's lifetime.
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* const ctx = createComponent(app, [{ provide: MY_TOKEN, useValue: 42 }]);
|
|
183
|
+
*/
|
|
184
|
+
function createComponent(parentInjector, providers) {
|
|
185
|
+
return {
|
|
186
|
+
injector: parentInjector.createChild(providers ?? []),
|
|
187
|
+
effects: [],
|
|
188
|
+
children: []
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Tears down a ComponentContext: destroys all child contexts recursively,
|
|
193
|
+
* then destroys all owned effects, then destroys the injector.
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* destroyComponent(ctx);
|
|
197
|
+
*/
|
|
198
|
+
function destroyComponent(ctx) {
|
|
199
|
+
for (const child of ctx.children) destroyComponent(child);
|
|
200
|
+
ctx.children.length = 0;
|
|
201
|
+
for (const handle of ctx.effects) handle.destroy();
|
|
202
|
+
ctx.effects.length = 0;
|
|
203
|
+
ctx.injector.destroy();
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Mounts a compiled component factory into a container element. The factory
|
|
207
|
+
* receives the ComponentContext, builds the DOM subtree, and returns the
|
|
208
|
+
* root node which is then appended to the container.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* mountComponent(counterFactory, document.getElementById('app')!, ctx);
|
|
212
|
+
*/
|
|
213
|
+
function mountComponent(factory, container, ctx) {
|
|
214
|
+
const node = factory(ctx);
|
|
215
|
+
container.appendChild(node);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Instantiates a child component inside a parent's template. Creates a child
|
|
219
|
+
* ComponentContext scoped under the parent, registers it for lifecycle
|
|
220
|
+
* tracking, invokes the factory with the given props, and returns the root
|
|
221
|
+
* DOM node so the caller can insert it into the tree.
|
|
222
|
+
*
|
|
223
|
+
* Props are always passed as getter functions so both static and reactive
|
|
224
|
+
* values share a uniform call-site API: `props['label']()`.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* // In a compiled parent template:
|
|
228
|
+
* const _e1 = mountChild(MyButton, ctx, { label: () => 'Click me' });
|
|
229
|
+
* insert(_e0, _e1);
|
|
230
|
+
*/
|
|
231
|
+
function mountChild(factory, parentCtx, props = {}) {
|
|
232
|
+
const childCtx = createComponent(parentCtx.injector);
|
|
233
|
+
parentCtx.children.push(childCtx);
|
|
234
|
+
const node = factory(childCtx, props);
|
|
235
|
+
const hmrId = factory["__hmrId"];
|
|
236
|
+
if (hmrId) {
|
|
237
|
+
const hmr = (typeof window !== "undefined" ? window : null)?.["__vorra_hmr"];
|
|
238
|
+
if (hmr?.instances) {
|
|
239
|
+
const list = hmr.instances.get(hmrId) ?? [];
|
|
240
|
+
list.push({
|
|
241
|
+
node,
|
|
242
|
+
ctx: childCtx,
|
|
243
|
+
props,
|
|
244
|
+
parentCtx
|
|
245
|
+
});
|
|
246
|
+
hmr.instances.set(hmrId, list);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return node;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Replaces all mounted instances of the component identified by `id` with
|
|
253
|
+
* the output of `newFactory`. Called by the HMR client when a `.vorra` chunk
|
|
254
|
+
* is hot-updated. Not intended for use in application code.
|
|
255
|
+
*/
|
|
256
|
+
function hmrAccept(id, newFactory) {
|
|
257
|
+
const hmr = (typeof window !== "undefined" ? window : null)?.["__vorra_hmr"];
|
|
258
|
+
if (!hmr?.instances) return;
|
|
259
|
+
const instances = hmr.instances.get(id) ?? [];
|
|
260
|
+
for (const inst of instances) {
|
|
261
|
+
const parent = inst.node.parentNode;
|
|
262
|
+
if (!parent) continue;
|
|
263
|
+
const nextSibling = inst.node.nextSibling;
|
|
264
|
+
destroyComponent(inst.ctx);
|
|
265
|
+
parent.removeChild(inst.node);
|
|
266
|
+
const newCtx = createComponent(inst.parentCtx.injector);
|
|
267
|
+
const idx = inst.parentCtx.children.indexOf(inst.ctx);
|
|
268
|
+
if (idx >= 0) inst.parentCtx.children[idx] = newCtx;
|
|
269
|
+
const newNode = newFactory(newCtx, inst.props);
|
|
270
|
+
parent.insertBefore(newNode, nextSibling);
|
|
271
|
+
inst.node = newNode;
|
|
272
|
+
inst.ctx = newCtx;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (typeof __vorra_dev !== "undefined" && __vorra_dev && typeof window !== "undefined") {
|
|
276
|
+
const w = window;
|
|
277
|
+
if (!w["__vorra_hmr"]) w["__vorra_hmr"] = {};
|
|
278
|
+
const hmr = w["__vorra_hmr"];
|
|
279
|
+
if (!hmr["instances"]) hmr["instances"] = /* @__PURE__ */ new Map();
|
|
280
|
+
hmr["accept"] = hmrAccept;
|
|
281
|
+
}
|
|
282
|
+
//#endregion
|
|
283
|
+
export { bindAttr, bindClass, bindList, bindProp, bindShow, bindText, createComponent, createElement, destroyComponent, hmrAccept, insert, listen, mountChild, mountComponent, remove, setAttr, setProp };
|
|
284
|
+
|
|
285
|
+
//# sourceMappingURL=dom.js.map
|
package/dist/dom.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.js","names":[],"sources":["../src/dom.ts"],"sourcesContent":["// =============================================================================\r\n// Vorra Runtime DOM Layer\r\n// Direct DOM operations + reactive bindings that compiled templates call into.\r\n// =============================================================================\r\n\r\nimport { effect } from './reactivity.js';\r\nimport type { EffectHandle } from './reactivity.js';\r\nimport { Injector } from './di.js';\r\nimport type { Provider } from './di.js';\r\n\r\n// ---------------------------------------------------------------------------\r\n// Types\r\n// ---------------------------------------------------------------------------\r\n\r\nexport interface ComponentContext {\r\n injector: Injector;\r\n effects: EffectHandle[];\r\n children: ComponentContext[];\r\n}\r\n\r\n// Injected as a compile-time constant by Rolldown `define` in dev mode.\r\n// `typeof` check is intentional — the variable may not be defined at runtime.\r\ndeclare const __vorra_dev: boolean | undefined;\r\n\r\n/** Internal record of a mounted component instance, used by HMR swapping. */\r\ninterface HMRInstance {\r\n node: Node;\r\n ctx: ComponentContext;\r\n props: Record<string, () => unknown>;\r\n parentCtx: ComponentContext;\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// 5.1 Element creation & patching\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Creates a DOM element with the given tag name.\r\n *\r\n * @example\r\n * const div = createElement('div');\r\n */\r\nexport function createElement(tag: string): Element {\r\n return document.createElement(tag);\r\n}\r\n\r\n/**\r\n * Sets a static attribute on an element.\r\n *\r\n * @example\r\n * setAttr(el, 'class', 'container');\r\n */\r\nexport function setAttr(el: Element, name: string, value: string): void {\r\n el.setAttribute(name, value);\r\n}\r\n\r\n/**\r\n * Sets a DOM property directly (e.g. value, checked, disabled).\r\n *\r\n * @example\r\n * setProp(input, 'value', 'hello');\r\n */\r\nexport function setProp(el: Element, name: string, value: unknown): void {\r\n (el as unknown as Record<string, unknown>)[name] = value;\r\n}\r\n\r\n/**\r\n * Attaches an event listener and returns an EffectHandle to remove it.\r\n *\r\n * @example\r\n * const handle = listen(btn, 'click', () => count.update(n => n + 1));\r\n * handle.destroy(); // removes listener\r\n */\r\nexport function listen(\r\n el: Element,\r\n event: string,\r\n handler: EventListener\r\n): EffectHandle {\r\n el.addEventListener(event, handler);\r\n return {\r\n destroy() {\r\n el.removeEventListener(event, handler);\r\n },\r\n };\r\n}\r\n\r\n/**\r\n * Inserts a child node into a parent, optionally before an anchor node.\r\n *\r\n * @example\r\n * insert(container, textNode);\r\n * insert(list, item, anchor); // insert before anchor\r\n */\r\nexport function insert(parent: Node, child: Node, anchor?: Node | null): void {\r\n parent.insertBefore(child, anchor ?? null);\r\n}\r\n\r\n/**\r\n * Removes a node from the DOM.\r\n *\r\n * @example\r\n * remove(el);\r\n */\r\nexport function remove(node: Node): void {\r\n node.parentNode?.removeChild(node);\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// 5.2 Reactive bindings\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Binds a getter to a Text node's content. The text updates surgically\r\n * whenever the getter's signal dependencies change.\r\n *\r\n * @example\r\n * const t = document.createTextNode('');\r\n * bindText(t, () => String(count()));\r\n */\r\nexport function bindText(node: Text, getter: () => string): EffectHandle {\r\n return effect(() => {\r\n node.nodeValue = getter();\r\n });\r\n}\r\n\r\n/**\r\n * Binds a getter to an element attribute. When the getter returns `null`,\r\n * the attribute is removed.\r\n *\r\n * @example\r\n * bindAttr(el, 'disabled', () => isDisabled() ? '' : null);\r\n */\r\nexport function bindAttr(\r\n el: Element,\r\n name: string,\r\n getter: () => string | null\r\n): EffectHandle {\r\n return effect(() => {\r\n const value = getter();\r\n if (value === null) {\r\n el.removeAttribute(name);\r\n } else {\r\n el.setAttribute(name, value);\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * Binds a getter to a DOM property. Updates the property directly whenever\r\n * the getter's signal dependencies change.\r\n *\r\n * @example\r\n * bindProp(input, 'value', () => name());\r\n */\r\nexport function bindProp(\r\n el: Element,\r\n name: string,\r\n getter: () => unknown\r\n): EffectHandle {\r\n return effect(() => {\r\n (el as unknown as Record<string, unknown>)[name] = getter();\r\n });\r\n}\r\n\r\n/**\r\n * Binds a getter to element visibility. When the getter returns `false`,\r\n * `display: none` is applied; otherwise the inline style is cleared.\r\n *\r\n * @example\r\n * bindShow(el, () => isVisible());\r\n */\r\nexport function bindShow(el: Element, getter: () => boolean): EffectHandle {\r\n return effect(() => {\r\n (el as HTMLElement).style.display = getter() ? '' : 'none';\r\n });\r\n}\r\n\r\n/**\r\n * Binds a getter to a set of CSS classes. Each key in the record is a class\r\n * name; when the value is `true` the class is added, when `false` it is\r\n * removed. Classes not in the record are left untouched.\r\n *\r\n * @example\r\n * bindClass(el, () => ({ active: isActive(), disabled: isDisabled() }));\r\n */\r\nexport function bindClass(\r\n el: Element,\r\n getter: () => Record<string, boolean>\r\n): EffectHandle {\r\n let prevClasses: Record<string, boolean> = {};\r\n\r\n return effect(() => {\r\n const next = getter();\r\n\r\n // Remove classes that were previously active but are no longer present or are now false.\r\n for (const name of Object.keys(prevClasses)) {\r\n if (prevClasses[name] === true && !next[name]) {\r\n el.classList.remove(name);\r\n }\r\n }\r\n\r\n // Add/remove based on current values.\r\n for (const [name, active] of Object.entries(next)) {\r\n if (active) {\r\n el.classList.add(name);\r\n } else {\r\n el.classList.remove(name);\r\n }\r\n }\r\n\r\n prevClasses = next;\r\n });\r\n}\r\n\r\n/**\r\n * Reactively renders a list of items before an anchor comment node.\r\n * Each item receives its own `ComponentContext` scoped under `parentCtx`\r\n * so that bindings created inside the item template are properly cleaned\r\n * up whenever the list re-renders.\r\n *\r\n * This is the runtime backing for the `@for` template directive.\r\n *\r\n * @example\r\n * // Generated by: <li @for={item of items()}>…</li>\r\n * const anchor = document.createComment('for');\r\n * insert(container, anchor);\r\n * ctx.effects.push(bindList(anchor, ctx, () => items(), (item, i, itemCtx) => {\r\n * const li = createElement('li');\r\n * const t = document.createTextNode('');\r\n * itemCtx.effects.push(bindText(t, () => item.name));\r\n * insert(li, t);\r\n * return li;\r\n * }));\r\n */\r\nexport function bindList<T>(\r\n anchor: Comment,\r\n parentCtx: ComponentContext,\r\n getter: () => T[],\r\n itemFactory: (item: T, index: number, ctx: ComponentContext) => Node,\r\n): EffectHandle {\r\n let activeItems: Array<{ node: Node; ctx: ComponentContext }> = [];\r\n\r\n return effect(() => {\r\n const list = getter();\r\n const parent = anchor.parentNode;\r\n if (!parent) return;\r\n\r\n // Tear down previous iteration: remove DOM nodes and destroy child contexts.\r\n for (const { node, ctx } of activeItems) {\r\n parent.removeChild(node);\r\n const idx = parentCtx.children.indexOf(ctx);\r\n if (idx >= 0) parentCtx.children.splice(idx, 1);\r\n destroyComponent(ctx);\r\n }\r\n activeItems = [];\r\n\r\n // Render each new item and insert it before the anchor.\r\n for (let i = 0; i < list.length; i++) {\r\n const itemCtx = createComponent(parentCtx.injector);\r\n parentCtx.children.push(itemCtx);\r\n const node = itemFactory(list[i]!, i, itemCtx);\r\n parent.insertBefore(node, anchor);\r\n activeItems.push({ node, ctx: itemCtx });\r\n }\r\n });\r\n}\r\n\r\n// ---------------------------------------------------------------------------\r\n// 5.3 Component lifecycle\r\n// ---------------------------------------------------------------------------\r\n\r\n/**\r\n * Creates a ComponentContext scoped to a child injector derived from\r\n * `parentInjector`. The context owns all EffectHandles created during\r\n * the component's lifetime.\r\n *\r\n * @example\r\n * const ctx = createComponent(app, [{ provide: MY_TOKEN, useValue: 42 }]);\r\n */\r\nexport function createComponent(\r\n parentInjector: Injector,\r\n providers?: Provider[]\r\n): ComponentContext {\r\n const injector = parentInjector.createChild(providers ?? []);\r\n return {\r\n injector,\r\n effects: [],\r\n children: [],\r\n };\r\n}\r\n\r\n/**\r\n * Tears down a ComponentContext: destroys all child contexts recursively,\r\n * then destroys all owned effects, then destroys the injector.\r\n *\r\n * @example\r\n * destroyComponent(ctx);\r\n */\r\nexport function destroyComponent(ctx: ComponentContext): void {\r\n // Recursively destroy children first.\r\n for (const child of ctx.children) {\r\n destroyComponent(child);\r\n }\r\n ctx.children.length = 0;\r\n\r\n // Destroy all owned effect handles.\r\n for (const handle of ctx.effects) {\r\n handle.destroy();\r\n }\r\n ctx.effects.length = 0;\r\n\r\n // Tear down the scoped injector.\r\n ctx.injector.destroy();\r\n}\r\n\r\n/**\r\n * Mounts a compiled component factory into a container element. The factory\r\n * receives the ComponentContext, builds the DOM subtree, and returns the\r\n * root node which is then appended to the container.\r\n *\r\n * @example\r\n * mountComponent(counterFactory, document.getElementById('app')!, ctx);\r\n */\r\nexport function mountComponent(\r\n factory: (ctx: ComponentContext, props?: Record<string, () => unknown>) => Node,\r\n container: Element,\r\n ctx: ComponentContext\r\n): void {\r\n const node = factory(ctx);\r\n container.appendChild(node);\r\n}\r\n\r\n/**\r\n * Instantiates a child component inside a parent's template. Creates a child\r\n * ComponentContext scoped under the parent, registers it for lifecycle\r\n * tracking, invokes the factory with the given props, and returns the root\r\n * DOM node so the caller can insert it into the tree.\r\n *\r\n * Props are always passed as getter functions so both static and reactive\r\n * values share a uniform call-site API: `props['label']()`.\r\n *\r\n * @example\r\n * // In a compiled parent template:\r\n * const _e1 = mountChild(MyButton, ctx, { label: () => 'Click me' });\r\n * insert(_e0, _e1);\r\n */\r\nexport function mountChild(\r\n factory: (ctx: ComponentContext, props: Record<string, () => unknown>) => Node,\r\n parentCtx: ComponentContext,\r\n props: Record<string, () => unknown> = {},\r\n): Node {\r\n const childCtx = createComponent(parentCtx.injector);\r\n parentCtx.children.push(childCtx);\r\n const node = factory(childCtx, props);\r\n\r\n // Register the instance for HMR swapping when the runtime is active.\r\n const hmrId = (factory as unknown as Record<string, unknown>)['__hmrId'] as string | undefined;\r\n if (hmrId) {\r\n const w = typeof window !== 'undefined' ? (window as unknown as Record<string, unknown>) : null;\r\n const hmr = w?.['__vorra_hmr'] as { instances?: Map<string, HMRInstance[]> } | undefined;\r\n if (hmr?.instances) {\r\n const list = hmr.instances.get(hmrId) ?? [];\r\n list.push({ node, ctx: childCtx, props, parentCtx });\r\n hmr.instances.set(hmrId, list);\r\n }\r\n }\r\n\r\n return node;\r\n}\r\n\r\n/**\r\n * Replaces all mounted instances of the component identified by `id` with\r\n * the output of `newFactory`. Called by the HMR client when a `.vorra` chunk\r\n * is hot-updated. Not intended for use in application code.\r\n */\r\nexport function hmrAccept(\r\n id: string,\r\n newFactory: (ctx: ComponentContext, props: Record<string, () => unknown>) => Node,\r\n): void {\r\n const w = typeof window !== 'undefined' ? (window as unknown as Record<string, unknown>) : null;\r\n const hmr = w?.['__vorra_hmr'] as { instances?: Map<string, HMRInstance[]> } | undefined;\r\n if (!hmr?.instances) return;\r\n\r\n const instances = hmr.instances.get(id) ?? [];\r\n for (const inst of instances) {\r\n const parent = inst.node.parentNode;\r\n if (!parent) continue; // component was unmounted — skip\r\n\r\n const nextSibling = inst.node.nextSibling;\r\n\r\n // Tear down old component subtree.\r\n destroyComponent(inst.ctx);\r\n parent.removeChild(inst.node);\r\n\r\n // Mount the new factory in its place.\r\n const newCtx = createComponent(inst.parentCtx.injector);\r\n const idx = inst.parentCtx.children.indexOf(inst.ctx);\r\n if (idx >= 0) inst.parentCtx.children[idx] = newCtx;\r\n\r\n const newNode = newFactory(newCtx, inst.props);\r\n parent.insertBefore(newNode, nextSibling);\r\n\r\n // Update the instance record for future HMR swaps.\r\n inst.node = newNode;\r\n inst.ctx = newCtx;\r\n }\r\n}\r\n\r\n// Wire up the HMR runtime on the global `window.__vorra_hmr` object so that\r\n// dynamically-imported component chunks can call `window.__vorra_hmr.accept`.\r\n// This block is compiled away in production builds (Rolldown replaces\r\n// `__vorra_dev` with `false` and tree-shakes the dead code).\r\nif (typeof __vorra_dev !== 'undefined' && __vorra_dev && typeof window !== 'undefined') {\r\n const w = window as unknown as Record<string, unknown>;\r\n if (!w['__vorra_hmr']) w['__vorra_hmr'] = {};\r\n const hmr = w['__vorra_hmr'] as Record<string, unknown>;\r\n if (!hmr['instances']) hmr['instances'] = new Map<string, HMRInstance[]>();\r\n hmr['accept'] = hmrAccept;\r\n}\r\n"],"mappings":";;;;;;;;AA0CA,SAAgB,cAAc,KAAsB;AAClD,QAAO,SAAS,cAAc,IAAI;;;;;;;;AASpC,SAAgB,QAAQ,IAAa,MAAc,OAAqB;AACtE,IAAG,aAAa,MAAM,MAAM;;;;;;;;AAS9B,SAAgB,QAAQ,IAAa,MAAc,OAAsB;AACtE,IAA0C,QAAQ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AM,OADI,OAAO,WAAW,cAAe,SAAgD,QAC3E;AAChB,MAAI,KAAK,WAAW;GAClB,MAAM,OAAO,IAAI,UAAU,IAAI,MAAM,IAAI,EAAE;AAC3C,QAAK,KAAK;IAAE;IAAM,KAAK;IAAU;IAAO;IAAW,CAAC;AACpD,OAAI,UAAU,IAAI,OAAO,KAAK;;;AAIlC,QAAO;;;;;;;AAQT,SAAgB,UACd,IACA,YACM;CAEN,MAAM,OADI,OAAO,WAAW,cAAe,SAAgD,QAC3E;AAChB,KAAI,CAAC,KAAK,UAAW;CAErB,MAAM,YAAY,IAAI,UAAU,IAAI,GAAG,IAAI,EAAE;AAC7C,MAAK,MAAM,QAAQ,WAAW;EAC5B,MAAM,SAAS,KAAK,KAAK;AACzB,MAAI,CAAC,OAAQ;EAEb,MAAM,cAAc,KAAK,KAAK;AAG9B,mBAAiB,KAAK,IAAI;AAC1B,SAAO,YAAY,KAAK,KAAK;EAG7B,MAAM,SAAS,gBAAgB,KAAK,UAAU,SAAS;EACvD,MAAM,MAAM,KAAK,UAAU,SAAS,QAAQ,KAAK,IAAI;AACrD,MAAI,OAAO,EAAG,MAAK,UAAU,SAAS,OAAO;EAE7C,MAAM,UAAU,WAAW,QAAQ,KAAK,MAAM;AAC9C,SAAO,aAAa,SAAS,YAAY;AAGzC,OAAK,OAAO;AACZ,OAAK,MAAM;;;AAQf,IAAI,OAAO,gBAAgB,eAAe,eAAe,OAAO,WAAW,aAAa;CACtF,MAAM,IAAI;AACV,KAAI,CAAC,EAAE,eAAgB,GAAE,iBAAiB,EAAE;CAC5C,MAAM,MAAM,EAAE;AACd,KAAI,CAAC,IAAI,aAAc,KAAI,+BAAe,IAAI,KAA4B;AAC1E,KAAI,YAAY"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_reactivity = require("./reactivity.cjs");
|
|
3
|
+
const require_di = require("./di.cjs");
|
|
4
|
+
const require_dom = require("./dom.cjs");
|
|
5
|
+
exports.Inject = require_di.Inject;
|
|
6
|
+
exports.Injectable = require_di.Injectable;
|
|
7
|
+
exports.InjectionToken = require_di.InjectionToken;
|
|
8
|
+
exports.Injector = require_di.Injector;
|
|
9
|
+
exports.batch = require_reactivity.batch;
|
|
10
|
+
exports.bindAttr = require_dom.bindAttr;
|
|
11
|
+
exports.bindClass = require_dom.bindClass;
|
|
12
|
+
exports.bindList = require_dom.bindList;
|
|
13
|
+
exports.bindProp = require_dom.bindProp;
|
|
14
|
+
exports.bindShow = require_dom.bindShow;
|
|
15
|
+
exports.bindText = require_dom.bindText;
|
|
16
|
+
exports.bootstrapApp = require_di.bootstrapApp;
|
|
17
|
+
exports.computed = require_reactivity.computed;
|
|
18
|
+
exports.createComponent = require_dom.createComponent;
|
|
19
|
+
exports.createElement = require_dom.createElement;
|
|
20
|
+
exports.destroyComponent = require_dom.destroyComponent;
|
|
21
|
+
exports.effect = require_reactivity.effect;
|
|
22
|
+
exports.getActiveInjector = require_di.getActiveInjector;
|
|
23
|
+
exports.getRootInjector = require_di.getRootInjector;
|
|
24
|
+
exports.inject = require_di.inject;
|
|
25
|
+
exports.insert = require_dom.insert;
|
|
26
|
+
exports.isSignal = require_reactivity.isSignal;
|
|
27
|
+
exports.listen = require_dom.listen;
|
|
28
|
+
exports.mountChild = require_dom.mountChild;
|
|
29
|
+
exports.mountComponent = require_dom.mountComponent;
|
|
30
|
+
exports.onDestroy = require_di.onDestroy;
|
|
31
|
+
exports.remove = require_dom.remove;
|
|
32
|
+
exports.resetRootInjector = require_di.resetRootInjector;
|
|
33
|
+
exports.runDestroyCallbacks = require_di.runDestroyCallbacks;
|
|
34
|
+
exports.runInContext = require_di.runInContext;
|
|
35
|
+
exports.setAttr = require_dom.setAttr;
|
|
36
|
+
exports.setProp = require_dom.setProp;
|
|
37
|
+
exports.signal = require_reactivity.signal;
|
|
38
|
+
exports.untrack = require_reactivity.untrack;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { signal, computed, effect, batch, untrack, isSignal, } from './reactivity.js';
|
|
2
|
+
export type { WritableSignal, ReadonlySignal, ComputedSignal, EffectHandle, Signal, SignalGetter, SignalSetter, } from './reactivity.js';
|
|
3
|
+
export { Injectable, Inject, InjectionToken, Injector, inject, runInContext, bootstrapApp, resetRootInjector, getRootInjector, getActiveInjector, onDestroy, runDestroyCallbacks, } from './di.js';
|
|
4
|
+
export type { Provider, ClassProvider, ValueProvider, FactoryProvider, ExistingProvider, Token, ProvidedIn, InjectableOptions, } from './di.js';
|
|
5
|
+
export { createElement, setAttr, setProp, listen, insert, remove, bindText, bindAttr, bindProp, bindShow, bindClass, createComponent, destroyComponent, mountComponent, mountChild, } from './dom.js';
|
|
6
|
+
export type { ComponentContext } from './dom.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,MAAM,EACN,QAAQ,EACR,MAAM,EACN,KAAK,EACL,OAAO,EACP,QAAQ,GACT,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EACV,cAAc,EACd,cAAc,EACd,cAAc,EACd,YAAY,EACZ,MAAM,EACN,YAAY,EACZ,YAAY,GACb,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,UAAU,EACV,MAAM,EACN,cAAc,EACd,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,SAAS,EACT,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAEjB,YAAY,EACV,QAAQ,EACR,aAAa,EACb,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,KAAK,EACL,UAAU,EACV,iBAAiB,GAClB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,aAAa,EACb,OAAO,EACP,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,UAAU,GACX,MAAM,UAAU,CAAC;AAElB,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { batch, computed, effect, isSignal, signal, untrack } from "./reactivity.js";
|
|
2
|
+
import { Inject, Injectable, InjectionToken, Injector, bootstrapApp, getActiveInjector, getRootInjector, inject, onDestroy, resetRootInjector, runDestroyCallbacks, runInContext } from "./di.js";
|
|
3
|
+
import { bindAttr, bindClass, bindList, bindProp, bindShow, bindText, createComponent, createElement, destroyComponent, insert, listen, mountChild, mountComponent, remove, setAttr, setProp } from "./dom.js";
|
|
4
|
+
export { Inject, Injectable, InjectionToken, Injector, batch, bindAttr, bindClass, bindList, bindProp, bindShow, bindText, bootstrapApp, computed, createComponent, createElement, destroyComponent, effect, getActiveInjector, getRootInjector, inject, insert, isSignal, listen, mountChild, mountComponent, onDestroy, remove, resetRootInjector, runDestroyCallbacks, runInContext, setAttr, setProp, signal, untrack };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,2BAA2B;AAC3B,gFAAgF;AAEhF,wBAAwB;AACxB,OAAO,EACL,MAAM,EACN,QAAQ,EACR,MAAM,EACN,KAAK,EACL,OAAO,EACP,QAAQ,GACT,MAAM,iBAAiB,CAAC;AAYzB,uBAAuB;AACvB,OAAO,EACL,UAAU,EACV,MAAM,EACN,cAAc,EACd,QAAQ,EACR,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,SAAS,EACT,mBAAmB,GACpB,MAAM,SAAS,CAAC;AAajB,cAAc;AACd,OAAO,EACL,aAAa,EACb,OAAO,EACP,OAAO,EACP,MAAM,EACN,MAAM,EACN,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,cAAc,EACd,UAAU,GACX,MAAM,UAAU,CAAC"}
|