@streetui/runtime 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/index.cjs +173 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +116 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.js +144 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 StreetUI contributors
|
|
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,26 @@
|
|
|
1
|
+
# @streetui/runtime
|
|
2
|
+
|
|
3
|
+
StreetUI runtime — application mounting, lifecycle, node instances, state/event integration
|
|
4
|
+
|
|
5
|
+
Part of [StreetUI](https://github.com/streetui/streetui) — a semantic,
|
|
6
|
+
signal-based UI framework with its own reactivity and keyed DOM reconciler
|
|
7
|
+
(no virtual DOM).
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install @streetui/runtime
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import * as pkg from '@streetui/runtime';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Both ESM (`import`) and CommonJS (`require`) entry points are shipped, with
|
|
22
|
+
matching TypeScript declarations.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
MIT
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Runtime: () => Runtime,
|
|
24
|
+
RuntimeNodeInstance: () => RuntimeNodeInstance,
|
|
25
|
+
createRuntime: () => createRuntime
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(index_exports);
|
|
28
|
+
|
|
29
|
+
// src/node-instance.ts
|
|
30
|
+
var import_core = require("@streetui/core");
|
|
31
|
+
var RuntimeNodeInstance = class {
|
|
32
|
+
graphNode;
|
|
33
|
+
domNode;
|
|
34
|
+
children = [];
|
|
35
|
+
cleanup = new import_core.CleanupRegistry();
|
|
36
|
+
_mounted = false;
|
|
37
|
+
constructor(options) {
|
|
38
|
+
this.graphNode = options.graphNode;
|
|
39
|
+
this.domNode = options.domNode;
|
|
40
|
+
}
|
|
41
|
+
get isMounted() {
|
|
42
|
+
return this._mounted;
|
|
43
|
+
}
|
|
44
|
+
mount() {
|
|
45
|
+
this._mounted = true;
|
|
46
|
+
}
|
|
47
|
+
unmount() {
|
|
48
|
+
if (!this._mounted) return;
|
|
49
|
+
this._mounted = false;
|
|
50
|
+
for (const child of this.children) {
|
|
51
|
+
child.unmount();
|
|
52
|
+
}
|
|
53
|
+
this.cleanup.run();
|
|
54
|
+
}
|
|
55
|
+
addChild(instance) {
|
|
56
|
+
this.children.push(instance);
|
|
57
|
+
}
|
|
58
|
+
/** Subscribe to a signal and register the unsubscribe for cleanup. */
|
|
59
|
+
trackSignal(signal, handler) {
|
|
60
|
+
const unsub = signal.subscribe(handler);
|
|
61
|
+
this.cleanup.add(unsub);
|
|
62
|
+
}
|
|
63
|
+
/** Register an arbitrary cleanup function (e.g. DOM event removal). */
|
|
64
|
+
trackCleanup(fn) {
|
|
65
|
+
this.cleanup.add(fn);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/runtime.ts
|
|
70
|
+
var import_core2 = require("@streetui/core");
|
|
71
|
+
var import_scheduler = require("@streetui/scheduler");
|
|
72
|
+
var Runtime = class {
|
|
73
|
+
_renderer;
|
|
74
|
+
_scheduler;
|
|
75
|
+
_cleanup = new import_core2.CleanupRegistry();
|
|
76
|
+
_renderHandle = null;
|
|
77
|
+
_mounted = false;
|
|
78
|
+
constructor(options) {
|
|
79
|
+
this._renderer = options.renderer;
|
|
80
|
+
this._scheduler = options.scheduler ?? new import_scheduler.Scheduler();
|
|
81
|
+
}
|
|
82
|
+
get isMounted() {
|
|
83
|
+
return this._mounted;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Mount the compiled application into the given DOM container.
|
|
87
|
+
*/
|
|
88
|
+
mount(compiled, container) {
|
|
89
|
+
if (this._mounted) {
|
|
90
|
+
throw new Error("[Runtime] Already mounted. Call unmount() first.");
|
|
91
|
+
}
|
|
92
|
+
this._renderHandle = this._renderer.mount(compiled, container);
|
|
93
|
+
this._mounted = true;
|
|
94
|
+
this._bindSignals(compiled.graph);
|
|
95
|
+
const self = this;
|
|
96
|
+
return {
|
|
97
|
+
renderHandle: this._renderHandle,
|
|
98
|
+
runtime: this,
|
|
99
|
+
unmount() {
|
|
100
|
+
self.unmount();
|
|
101
|
+
},
|
|
102
|
+
flush() {
|
|
103
|
+
self._scheduler.flush();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
unmount() {
|
|
108
|
+
if (!this._mounted) return;
|
|
109
|
+
this._mounted = false;
|
|
110
|
+
this._renderHandle?.unmount();
|
|
111
|
+
this._renderHandle = null;
|
|
112
|
+
this._cleanup.run();
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Hydrate a container that already holds server-rendered HTML for this
|
|
116
|
+
* application. Delegates to the renderer's `hydrate` (adopting the existing
|
|
117
|
+
* DOM instead of recreating it) and falls back to `mount` for renderers that
|
|
118
|
+
* cannot hydrate. Signal binding is identical to `mount`, so the live client
|
|
119
|
+
* lifecycle is established the same way.
|
|
120
|
+
*/
|
|
121
|
+
hydrate(compiled, container) {
|
|
122
|
+
if (this._mounted) {
|
|
123
|
+
throw new Error("[Runtime] Already mounted. Call unmount() first.");
|
|
124
|
+
}
|
|
125
|
+
this._renderHandle = this._renderer.hydrate !== void 0 ? this._renderer.hydrate(compiled, container) : this._renderer.mount(compiled, container);
|
|
126
|
+
this._mounted = true;
|
|
127
|
+
this._bindSignals(compiled.graph);
|
|
128
|
+
const self = this;
|
|
129
|
+
return {
|
|
130
|
+
renderHandle: this._renderHandle,
|
|
131
|
+
runtime: this,
|
|
132
|
+
unmount() {
|
|
133
|
+
self.unmount();
|
|
134
|
+
},
|
|
135
|
+
flush() {
|
|
136
|
+
self._scheduler.flush();
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Walk the graph and subscribe to all signal-bound nodes.
|
|
142
|
+
* When a signal changes, schedule a renderer update for that node.
|
|
143
|
+
*/
|
|
144
|
+
_bindSignals(graph) {
|
|
145
|
+
graph.walk((node) => {
|
|
146
|
+
for (const stateRef of node.stateRefs) {
|
|
147
|
+
const signalKey = `__signal__${stateRef.signalId}`;
|
|
148
|
+
const maybeSignal = graph.getHandler(signalKey);
|
|
149
|
+
if (maybeSignal === void 0 || typeof maybeSignal.subscribe !== "function") continue;
|
|
150
|
+
const unsub = maybeSignal.subscribe(() => {
|
|
151
|
+
this._scheduler.schedule({
|
|
152
|
+
key: `update:${node.id}:${stateRef.propKey}`,
|
|
153
|
+
priority: "normal",
|
|
154
|
+
fn: () => {
|
|
155
|
+
this._renderHandle?.flush();
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
this._cleanup.add(unsub);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
function createRuntime(options) {
|
|
165
|
+
return new Runtime(options);
|
|
166
|
+
}
|
|
167
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
+
0 && (module.exports = {
|
|
169
|
+
Runtime,
|
|
170
|
+
RuntimeNodeInstance,
|
|
171
|
+
createRuntime
|
|
172
|
+
});
|
|
173
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/node-instance.ts","../src/runtime.ts"],"sourcesContent":["export * from './node-instance.js';\nexport * from './renderer-interface.js';\nexport * from './runtime.js';\n","/**\n * RuntimeNodeInstance — the runtime's live representation of a GraphNode.\n *\n * Each GraphNode in the compiled application gets a corresponding\n * RuntimeNodeInstance during mounting. The instance owns:\n * - the DOM node(s) produced for this graph node\n * - all signal subscriptions that drive updates\n * - all DOM event listeners\n * - child instances\n */\n\nimport { CleanupRegistry } from '@streetui/core';\nimport type { GraphNode } from '@streetui/graph';\nimport type { Signal, ReadonlySignal } from '@streetui/state';\n\nexport interface NodeInstanceOptions {\n readonly graphNode: GraphNode;\n readonly domNode: Node;\n}\n\nexport class RuntimeNodeInstance {\n readonly graphNode: GraphNode;\n domNode: Node;\n readonly children: RuntimeNodeInstance[] = [];\n readonly cleanup: CleanupRegistry = new CleanupRegistry();\n private _mounted = false;\n\n constructor(options: NodeInstanceOptions) {\n this.graphNode = options.graphNode;\n this.domNode = options.domNode;\n }\n\n get isMounted(): boolean {\n return this._mounted;\n }\n\n mount(): void {\n this._mounted = true;\n }\n\n unmount(): void {\n if (!this._mounted) return;\n this._mounted = false;\n for (const child of this.children) {\n child.unmount();\n }\n this.cleanup.run();\n }\n\n addChild(instance: RuntimeNodeInstance): void {\n this.children.push(instance);\n }\n\n /** Subscribe to a signal and register the unsubscribe for cleanup. */\n trackSignal<T>(\n signal: Signal<T> | ReadonlySignal<T>,\n handler: (value: T) => void,\n ): void {\n const unsub = signal.subscribe(handler);\n this.cleanup.add(unsub);\n }\n\n /** Register an arbitrary cleanup function (e.g. DOM event removal). */\n trackCleanup(fn: () => void): void {\n this.cleanup.add(fn);\n }\n}\n","/**\n * StreetUI Runtime.\n *\n * Owns:\n * - Signal binding — wires signal subscriptions to renderer update calls\n * - Event dispatch — calls registered handlers from graph events\n * - Lifecycle — orchestrates mount, update cycles, unmount\n *\n * The runtime does NOT create DOM nodes. It calls into StreetRenderer\n * for all DOM operations.\n */\n\nimport { CleanupRegistry } from '@streetui/core';\nimport type { GraphNode, ApplicationGraph } from '@streetui/graph';\nimport type { Signal, ReadonlySignal } from '@streetui/state';\nimport { Scheduler } from '@streetui/scheduler';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport type { StreetRenderer, RenderHandle } from './renderer-interface.js';\n\nexport interface RuntimeOptions {\n readonly renderer: StreetRenderer;\n readonly scheduler?: Scheduler;\n}\n\nexport interface MountedApplication {\n readonly renderHandle: RenderHandle;\n readonly runtime: Runtime;\n unmount(): void;\n flush(): void;\n}\n\nexport class Runtime {\n private readonly _renderer: StreetRenderer;\n private readonly _scheduler: Scheduler;\n private readonly _cleanup: CleanupRegistry = new CleanupRegistry();\n private _renderHandle: RenderHandle | null = null;\n private _mounted = false;\n\n constructor(options: RuntimeOptions) {\n this._renderer = options.renderer;\n this._scheduler = options.scheduler ?? new Scheduler();\n }\n\n get isMounted(): boolean {\n return this._mounted;\n }\n\n /**\n * Mount the compiled application into the given DOM container.\n */\n mount(compiled: CompiledApplication, container: Element): MountedApplication {\n if (this._mounted) {\n throw new Error('[Runtime] Already mounted. Call unmount() first.');\n }\n\n // Hand off to renderer — it creates all DOM nodes\n this._renderHandle = this._renderer.mount(compiled, container);\n this._mounted = true;\n\n // Wire signal subscriptions from the graph\n this._bindSignals(compiled.graph);\n\n const self = this;\n return {\n renderHandle: this._renderHandle,\n runtime: this,\n unmount() { self.unmount(); },\n flush() { self._scheduler.flush(); },\n };\n }\n\n unmount(): void {\n if (!this._mounted) return;\n this._mounted = false;\n this._renderHandle?.unmount();\n this._renderHandle = null;\n this._cleanup.run();\n }\n\n /**\n * Hydrate a container that already holds server-rendered HTML for this\n * application. Delegates to the renderer's `hydrate` (adopting the existing\n * DOM instead of recreating it) and falls back to `mount` for renderers that\n * cannot hydrate. Signal binding is identical to `mount`, so the live client\n * lifecycle is established the same way.\n */\n hydrate(compiled: CompiledApplication, container: Element): MountedApplication {\n if (this._mounted) {\n throw new Error('[Runtime] Already mounted. Call unmount() first.');\n }\n\n this._renderHandle = this._renderer.hydrate !== undefined\n ? this._renderer.hydrate(compiled, container)\n : this._renderer.mount(compiled, container);\n this._mounted = true;\n\n this._bindSignals(compiled.graph);\n\n const self = this;\n return {\n renderHandle: this._renderHandle,\n runtime: this,\n unmount() { self.unmount(); },\n flush() { self._scheduler.flush(); },\n };\n }\n\n /**\n * Walk the graph and subscribe to all signal-bound nodes.\n * When a signal changes, schedule a renderer update for that node.\n */\n private _bindSignals(graph: ApplicationGraph): void {\n graph.walk((node) => {\n for (const stateRef of node.stateRefs) {\n const signalKey = `__signal__${stateRef.signalId}`;\n const maybeSignal = graph.getHandler(signalKey) as\n | (Signal<unknown> & ReadonlySignal<unknown>)\n | undefined;\n\n if (maybeSignal === undefined || typeof maybeSignal.subscribe !== 'function') continue;\n\n const unsub = maybeSignal.subscribe(() => {\n // Schedule a re-render update keyed to this node+prop\n this._scheduler.schedule({\n key: `update:${node.id}:${stateRef.propKey}`,\n priority: 'normal',\n fn: () => {\n // The renderer handles the actual DOM update\n this._renderHandle?.flush();\n },\n });\n });\n this._cleanup.add(unsub);\n }\n });\n }\n}\n\n/**\n * Convenience factory — create a runtime, mount, and return the handle.\n */\nexport function createRuntime(options: RuntimeOptions): Runtime {\n return new Runtime(options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWA,kBAAgC;AASzB,IAAM,sBAAN,MAA0B;AAAA,EACtB;AAAA,EACT;AAAA,EACS,WAAkC,CAAC;AAAA,EACnC,UAA2B,IAAI,4BAAgB;AAAA,EAChD,WAAW;AAAA,EAEnB,YAAY,SAA8B;AACxC,SAAK,YAAY,QAAQ;AACzB,SAAK,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,IACF,CAAC;AAAA,EACH;AACF;AAKO,SAAS,cAAc,SAAkC;AAC9D,SAAO,IAAI,QAAQ,OAAO;AAC5B;","names":["import_core"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { CleanupRegistry } from '@streetui/core';
|
|
2
|
+
import { GraphNode } from '@streetui/graph';
|
|
3
|
+
import { Signal, ReadonlySignal } from '@streetui/state';
|
|
4
|
+
import { CompiledApplication } from '@streetui/compiler';
|
|
5
|
+
import { Scheduler } from '@streetui/scheduler';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* RuntimeNodeInstance — the runtime's live representation of a GraphNode.
|
|
9
|
+
*
|
|
10
|
+
* Each GraphNode in the compiled application gets a corresponding
|
|
11
|
+
* RuntimeNodeInstance during mounting. The instance owns:
|
|
12
|
+
* - the DOM node(s) produced for this graph node
|
|
13
|
+
* - all signal subscriptions that drive updates
|
|
14
|
+
* - all DOM event listeners
|
|
15
|
+
* - child instances
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
interface NodeInstanceOptions {
|
|
19
|
+
readonly graphNode: GraphNode;
|
|
20
|
+
readonly domNode: Node;
|
|
21
|
+
}
|
|
22
|
+
declare class RuntimeNodeInstance {
|
|
23
|
+
readonly graphNode: GraphNode;
|
|
24
|
+
domNode: Node;
|
|
25
|
+
readonly children: RuntimeNodeInstance[];
|
|
26
|
+
readonly cleanup: CleanupRegistry;
|
|
27
|
+
private _mounted;
|
|
28
|
+
constructor(options: NodeInstanceOptions);
|
|
29
|
+
get isMounted(): boolean;
|
|
30
|
+
mount(): void;
|
|
31
|
+
unmount(): void;
|
|
32
|
+
addChild(instance: RuntimeNodeInstance): void;
|
|
33
|
+
/** Subscribe to a signal and register the unsubscribe for cleanup. */
|
|
34
|
+
trackSignal<T>(signal: Signal<T> | ReadonlySignal<T>, handler: (value: T) => void): void;
|
|
35
|
+
/** Register an arbitrary cleanup function (e.g. DOM event removal). */
|
|
36
|
+
trackCleanup(fn: () => void): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The interface the runtime uses to communicate with the renderer.
|
|
41
|
+
*
|
|
42
|
+
* The runtime never knows how DOM nodes are created — it delegates to this
|
|
43
|
+
* interface. This keeps the runtime/renderer boundary clean.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
interface RenderHandle {
|
|
47
|
+
/** Force a synchronous flush of pending updates. */
|
|
48
|
+
flush(): void;
|
|
49
|
+
/** Unmount and dispose all resources. */
|
|
50
|
+
unmount(): void;
|
|
51
|
+
}
|
|
52
|
+
interface StreetRenderer {
|
|
53
|
+
mount(application: CompiledApplication, container: Element): RenderHandle;
|
|
54
|
+
/**
|
|
55
|
+
* Optional: attach behavior to server-rendered HTML already present in
|
|
56
|
+
* `container` instead of recreating it. Renderers that cannot hydrate may
|
|
57
|
+
* omit this; callers fall back to `mount`.
|
|
58
|
+
*/
|
|
59
|
+
hydrate?(application: CompiledApplication, container: Element): RenderHandle;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* StreetUI Runtime.
|
|
64
|
+
*
|
|
65
|
+
* Owns:
|
|
66
|
+
* - Signal binding — wires signal subscriptions to renderer update calls
|
|
67
|
+
* - Event dispatch — calls registered handlers from graph events
|
|
68
|
+
* - Lifecycle — orchestrates mount, update cycles, unmount
|
|
69
|
+
*
|
|
70
|
+
* The runtime does NOT create DOM nodes. It calls into StreetRenderer
|
|
71
|
+
* for all DOM operations.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
interface RuntimeOptions {
|
|
75
|
+
readonly renderer: StreetRenderer;
|
|
76
|
+
readonly scheduler?: Scheduler;
|
|
77
|
+
}
|
|
78
|
+
interface MountedApplication {
|
|
79
|
+
readonly renderHandle: RenderHandle;
|
|
80
|
+
readonly runtime: Runtime;
|
|
81
|
+
unmount(): void;
|
|
82
|
+
flush(): void;
|
|
83
|
+
}
|
|
84
|
+
declare class Runtime {
|
|
85
|
+
private readonly _renderer;
|
|
86
|
+
private readonly _scheduler;
|
|
87
|
+
private readonly _cleanup;
|
|
88
|
+
private _renderHandle;
|
|
89
|
+
private _mounted;
|
|
90
|
+
constructor(options: RuntimeOptions);
|
|
91
|
+
get isMounted(): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Mount the compiled application into the given DOM container.
|
|
94
|
+
*/
|
|
95
|
+
mount(compiled: CompiledApplication, container: Element): MountedApplication;
|
|
96
|
+
unmount(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Hydrate a container that already holds server-rendered HTML for this
|
|
99
|
+
* application. Delegates to the renderer's `hydrate` (adopting the existing
|
|
100
|
+
* DOM instead of recreating it) and falls back to `mount` for renderers that
|
|
101
|
+
* cannot hydrate. Signal binding is identical to `mount`, so the live client
|
|
102
|
+
* lifecycle is established the same way.
|
|
103
|
+
*/
|
|
104
|
+
hydrate(compiled: CompiledApplication, container: Element): MountedApplication;
|
|
105
|
+
/**
|
|
106
|
+
* Walk the graph and subscribe to all signal-bound nodes.
|
|
107
|
+
* When a signal changes, schedule a renderer update for that node.
|
|
108
|
+
*/
|
|
109
|
+
private _bindSignals;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Convenience factory — create a runtime, mount, and return the handle.
|
|
113
|
+
*/
|
|
114
|
+
declare function createRuntime(options: RuntimeOptions): Runtime;
|
|
115
|
+
|
|
116
|
+
export { type MountedApplication, type NodeInstanceOptions, type RenderHandle, Runtime, RuntimeNodeInstance, type RuntimeOptions, type StreetRenderer, createRuntime };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { CleanupRegistry } from '@streetui/core';
|
|
2
|
+
import { GraphNode } from '@streetui/graph';
|
|
3
|
+
import { Signal, ReadonlySignal } from '@streetui/state';
|
|
4
|
+
import { CompiledApplication } from '@streetui/compiler';
|
|
5
|
+
import { Scheduler } from '@streetui/scheduler';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* RuntimeNodeInstance — the runtime's live representation of a GraphNode.
|
|
9
|
+
*
|
|
10
|
+
* Each GraphNode in the compiled application gets a corresponding
|
|
11
|
+
* RuntimeNodeInstance during mounting. The instance owns:
|
|
12
|
+
* - the DOM node(s) produced for this graph node
|
|
13
|
+
* - all signal subscriptions that drive updates
|
|
14
|
+
* - all DOM event listeners
|
|
15
|
+
* - child instances
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
interface NodeInstanceOptions {
|
|
19
|
+
readonly graphNode: GraphNode;
|
|
20
|
+
readonly domNode: Node;
|
|
21
|
+
}
|
|
22
|
+
declare class RuntimeNodeInstance {
|
|
23
|
+
readonly graphNode: GraphNode;
|
|
24
|
+
domNode: Node;
|
|
25
|
+
readonly children: RuntimeNodeInstance[];
|
|
26
|
+
readonly cleanup: CleanupRegistry;
|
|
27
|
+
private _mounted;
|
|
28
|
+
constructor(options: NodeInstanceOptions);
|
|
29
|
+
get isMounted(): boolean;
|
|
30
|
+
mount(): void;
|
|
31
|
+
unmount(): void;
|
|
32
|
+
addChild(instance: RuntimeNodeInstance): void;
|
|
33
|
+
/** Subscribe to a signal and register the unsubscribe for cleanup. */
|
|
34
|
+
trackSignal<T>(signal: Signal<T> | ReadonlySignal<T>, handler: (value: T) => void): void;
|
|
35
|
+
/** Register an arbitrary cleanup function (e.g. DOM event removal). */
|
|
36
|
+
trackCleanup(fn: () => void): void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The interface the runtime uses to communicate with the renderer.
|
|
41
|
+
*
|
|
42
|
+
* The runtime never knows how DOM nodes are created — it delegates to this
|
|
43
|
+
* interface. This keeps the runtime/renderer boundary clean.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
interface RenderHandle {
|
|
47
|
+
/** Force a synchronous flush of pending updates. */
|
|
48
|
+
flush(): void;
|
|
49
|
+
/** Unmount and dispose all resources. */
|
|
50
|
+
unmount(): void;
|
|
51
|
+
}
|
|
52
|
+
interface StreetRenderer {
|
|
53
|
+
mount(application: CompiledApplication, container: Element): RenderHandle;
|
|
54
|
+
/**
|
|
55
|
+
* Optional: attach behavior to server-rendered HTML already present in
|
|
56
|
+
* `container` instead of recreating it. Renderers that cannot hydrate may
|
|
57
|
+
* omit this; callers fall back to `mount`.
|
|
58
|
+
*/
|
|
59
|
+
hydrate?(application: CompiledApplication, container: Element): RenderHandle;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* StreetUI Runtime.
|
|
64
|
+
*
|
|
65
|
+
* Owns:
|
|
66
|
+
* - Signal binding — wires signal subscriptions to renderer update calls
|
|
67
|
+
* - Event dispatch — calls registered handlers from graph events
|
|
68
|
+
* - Lifecycle — orchestrates mount, update cycles, unmount
|
|
69
|
+
*
|
|
70
|
+
* The runtime does NOT create DOM nodes. It calls into StreetRenderer
|
|
71
|
+
* for all DOM operations.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
interface RuntimeOptions {
|
|
75
|
+
readonly renderer: StreetRenderer;
|
|
76
|
+
readonly scheduler?: Scheduler;
|
|
77
|
+
}
|
|
78
|
+
interface MountedApplication {
|
|
79
|
+
readonly renderHandle: RenderHandle;
|
|
80
|
+
readonly runtime: Runtime;
|
|
81
|
+
unmount(): void;
|
|
82
|
+
flush(): void;
|
|
83
|
+
}
|
|
84
|
+
declare class Runtime {
|
|
85
|
+
private readonly _renderer;
|
|
86
|
+
private readonly _scheduler;
|
|
87
|
+
private readonly _cleanup;
|
|
88
|
+
private _renderHandle;
|
|
89
|
+
private _mounted;
|
|
90
|
+
constructor(options: RuntimeOptions);
|
|
91
|
+
get isMounted(): boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Mount the compiled application into the given DOM container.
|
|
94
|
+
*/
|
|
95
|
+
mount(compiled: CompiledApplication, container: Element): MountedApplication;
|
|
96
|
+
unmount(): void;
|
|
97
|
+
/**
|
|
98
|
+
* Hydrate a container that already holds server-rendered HTML for this
|
|
99
|
+
* application. Delegates to the renderer's `hydrate` (adopting the existing
|
|
100
|
+
* DOM instead of recreating it) and falls back to `mount` for renderers that
|
|
101
|
+
* cannot hydrate. Signal binding is identical to `mount`, so the live client
|
|
102
|
+
* lifecycle is established the same way.
|
|
103
|
+
*/
|
|
104
|
+
hydrate(compiled: CompiledApplication, container: Element): MountedApplication;
|
|
105
|
+
/**
|
|
106
|
+
* Walk the graph and subscribe to all signal-bound nodes.
|
|
107
|
+
* When a signal changes, schedule a renderer update for that node.
|
|
108
|
+
*/
|
|
109
|
+
private _bindSignals;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Convenience factory — create a runtime, mount, and return the handle.
|
|
113
|
+
*/
|
|
114
|
+
declare function createRuntime(options: RuntimeOptions): Runtime;
|
|
115
|
+
|
|
116
|
+
export { type MountedApplication, type NodeInstanceOptions, type RenderHandle, Runtime, RuntimeNodeInstance, type RuntimeOptions, type StreetRenderer, createRuntime };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// src/node-instance.ts
|
|
2
|
+
import { CleanupRegistry } from "@streetui/core";
|
|
3
|
+
var RuntimeNodeInstance = class {
|
|
4
|
+
graphNode;
|
|
5
|
+
domNode;
|
|
6
|
+
children = [];
|
|
7
|
+
cleanup = new CleanupRegistry();
|
|
8
|
+
_mounted = false;
|
|
9
|
+
constructor(options) {
|
|
10
|
+
this.graphNode = options.graphNode;
|
|
11
|
+
this.domNode = options.domNode;
|
|
12
|
+
}
|
|
13
|
+
get isMounted() {
|
|
14
|
+
return this._mounted;
|
|
15
|
+
}
|
|
16
|
+
mount() {
|
|
17
|
+
this._mounted = true;
|
|
18
|
+
}
|
|
19
|
+
unmount() {
|
|
20
|
+
if (!this._mounted) return;
|
|
21
|
+
this._mounted = false;
|
|
22
|
+
for (const child of this.children) {
|
|
23
|
+
child.unmount();
|
|
24
|
+
}
|
|
25
|
+
this.cleanup.run();
|
|
26
|
+
}
|
|
27
|
+
addChild(instance) {
|
|
28
|
+
this.children.push(instance);
|
|
29
|
+
}
|
|
30
|
+
/** Subscribe to a signal and register the unsubscribe for cleanup. */
|
|
31
|
+
trackSignal(signal, handler) {
|
|
32
|
+
const unsub = signal.subscribe(handler);
|
|
33
|
+
this.cleanup.add(unsub);
|
|
34
|
+
}
|
|
35
|
+
/** Register an arbitrary cleanup function (e.g. DOM event removal). */
|
|
36
|
+
trackCleanup(fn) {
|
|
37
|
+
this.cleanup.add(fn);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/runtime.ts
|
|
42
|
+
import { CleanupRegistry as CleanupRegistry2 } from "@streetui/core";
|
|
43
|
+
import { Scheduler } from "@streetui/scheduler";
|
|
44
|
+
var Runtime = class {
|
|
45
|
+
_renderer;
|
|
46
|
+
_scheduler;
|
|
47
|
+
_cleanup = new CleanupRegistry2();
|
|
48
|
+
_renderHandle = null;
|
|
49
|
+
_mounted = false;
|
|
50
|
+
constructor(options) {
|
|
51
|
+
this._renderer = options.renderer;
|
|
52
|
+
this._scheduler = options.scheduler ?? new Scheduler();
|
|
53
|
+
}
|
|
54
|
+
get isMounted() {
|
|
55
|
+
return this._mounted;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Mount the compiled application into the given DOM container.
|
|
59
|
+
*/
|
|
60
|
+
mount(compiled, container) {
|
|
61
|
+
if (this._mounted) {
|
|
62
|
+
throw new Error("[Runtime] Already mounted. Call unmount() first.");
|
|
63
|
+
}
|
|
64
|
+
this._renderHandle = this._renderer.mount(compiled, container);
|
|
65
|
+
this._mounted = true;
|
|
66
|
+
this._bindSignals(compiled.graph);
|
|
67
|
+
const self = this;
|
|
68
|
+
return {
|
|
69
|
+
renderHandle: this._renderHandle,
|
|
70
|
+
runtime: this,
|
|
71
|
+
unmount() {
|
|
72
|
+
self.unmount();
|
|
73
|
+
},
|
|
74
|
+
flush() {
|
|
75
|
+
self._scheduler.flush();
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
unmount() {
|
|
80
|
+
if (!this._mounted) return;
|
|
81
|
+
this._mounted = false;
|
|
82
|
+
this._renderHandle?.unmount();
|
|
83
|
+
this._renderHandle = null;
|
|
84
|
+
this._cleanup.run();
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Hydrate a container that already holds server-rendered HTML for this
|
|
88
|
+
* application. Delegates to the renderer's `hydrate` (adopting the existing
|
|
89
|
+
* DOM instead of recreating it) and falls back to `mount` for renderers that
|
|
90
|
+
* cannot hydrate. Signal binding is identical to `mount`, so the live client
|
|
91
|
+
* lifecycle is established the same way.
|
|
92
|
+
*/
|
|
93
|
+
hydrate(compiled, container) {
|
|
94
|
+
if (this._mounted) {
|
|
95
|
+
throw new Error("[Runtime] Already mounted. Call unmount() first.");
|
|
96
|
+
}
|
|
97
|
+
this._renderHandle = this._renderer.hydrate !== void 0 ? this._renderer.hydrate(compiled, container) : this._renderer.mount(compiled, container);
|
|
98
|
+
this._mounted = true;
|
|
99
|
+
this._bindSignals(compiled.graph);
|
|
100
|
+
const self = this;
|
|
101
|
+
return {
|
|
102
|
+
renderHandle: this._renderHandle,
|
|
103
|
+
runtime: this,
|
|
104
|
+
unmount() {
|
|
105
|
+
self.unmount();
|
|
106
|
+
},
|
|
107
|
+
flush() {
|
|
108
|
+
self._scheduler.flush();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Walk the graph and subscribe to all signal-bound nodes.
|
|
114
|
+
* When a signal changes, schedule a renderer update for that node.
|
|
115
|
+
*/
|
|
116
|
+
_bindSignals(graph) {
|
|
117
|
+
graph.walk((node) => {
|
|
118
|
+
for (const stateRef of node.stateRefs) {
|
|
119
|
+
const signalKey = `__signal__${stateRef.signalId}`;
|
|
120
|
+
const maybeSignal = graph.getHandler(signalKey);
|
|
121
|
+
if (maybeSignal === void 0 || typeof maybeSignal.subscribe !== "function") continue;
|
|
122
|
+
const unsub = maybeSignal.subscribe(() => {
|
|
123
|
+
this._scheduler.schedule({
|
|
124
|
+
key: `update:${node.id}:${stateRef.propKey}`,
|
|
125
|
+
priority: "normal",
|
|
126
|
+
fn: () => {
|
|
127
|
+
this._renderHandle?.flush();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
this._cleanup.add(unsub);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
function createRuntime(options) {
|
|
137
|
+
return new Runtime(options);
|
|
138
|
+
}
|
|
139
|
+
export {
|
|
140
|
+
Runtime,
|
|
141
|
+
RuntimeNodeInstance,
|
|
142
|
+
createRuntime
|
|
143
|
+
};
|
|
144
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/node-instance.ts","../src/runtime.ts"],"sourcesContent":["/**\n * RuntimeNodeInstance — the runtime's live representation of a GraphNode.\n *\n * Each GraphNode in the compiled application gets a corresponding\n * RuntimeNodeInstance during mounting. The instance owns:\n * - the DOM node(s) produced for this graph node\n * - all signal subscriptions that drive updates\n * - all DOM event listeners\n * - child instances\n */\n\nimport { CleanupRegistry } from '@streetui/core';\nimport type { GraphNode } from '@streetui/graph';\nimport type { Signal, ReadonlySignal } from '@streetui/state';\n\nexport interface NodeInstanceOptions {\n readonly graphNode: GraphNode;\n readonly domNode: Node;\n}\n\nexport class RuntimeNodeInstance {\n readonly graphNode: GraphNode;\n domNode: Node;\n readonly children: RuntimeNodeInstance[] = [];\n readonly cleanup: CleanupRegistry = new CleanupRegistry();\n private _mounted = false;\n\n constructor(options: NodeInstanceOptions) {\n this.graphNode = options.graphNode;\n this.domNode = options.domNode;\n }\n\n get isMounted(): boolean {\n return this._mounted;\n }\n\n mount(): void {\n this._mounted = true;\n }\n\n unmount(): void {\n if (!this._mounted) return;\n this._mounted = false;\n for (const child of this.children) {\n child.unmount();\n }\n this.cleanup.run();\n }\n\n addChild(instance: RuntimeNodeInstance): void {\n this.children.push(instance);\n }\n\n /** Subscribe to a signal and register the unsubscribe for cleanup. */\n trackSignal<T>(\n signal: Signal<T> | ReadonlySignal<T>,\n handler: (value: T) => void,\n ): void {\n const unsub = signal.subscribe(handler);\n this.cleanup.add(unsub);\n }\n\n /** Register an arbitrary cleanup function (e.g. DOM event removal). */\n trackCleanup(fn: () => void): void {\n this.cleanup.add(fn);\n }\n}\n","/**\n * StreetUI Runtime.\n *\n * Owns:\n * - Signal binding — wires signal subscriptions to renderer update calls\n * - Event dispatch — calls registered handlers from graph events\n * - Lifecycle — orchestrates mount, update cycles, unmount\n *\n * The runtime does NOT create DOM nodes. It calls into StreetRenderer\n * for all DOM operations.\n */\n\nimport { CleanupRegistry } from '@streetui/core';\nimport type { GraphNode, ApplicationGraph } from '@streetui/graph';\nimport type { Signal, ReadonlySignal } from '@streetui/state';\nimport { Scheduler } from '@streetui/scheduler';\nimport type { CompiledApplication } from '@streetui/compiler';\nimport type { StreetRenderer, RenderHandle } from './renderer-interface.js';\n\nexport interface RuntimeOptions {\n readonly renderer: StreetRenderer;\n readonly scheduler?: Scheduler;\n}\n\nexport interface MountedApplication {\n readonly renderHandle: RenderHandle;\n readonly runtime: Runtime;\n unmount(): void;\n flush(): void;\n}\n\nexport class Runtime {\n private readonly _renderer: StreetRenderer;\n private readonly _scheduler: Scheduler;\n private readonly _cleanup: CleanupRegistry = new CleanupRegistry();\n private _renderHandle: RenderHandle | null = null;\n private _mounted = false;\n\n constructor(options: RuntimeOptions) {\n this._renderer = options.renderer;\n this._scheduler = options.scheduler ?? new Scheduler();\n }\n\n get isMounted(): boolean {\n return this._mounted;\n }\n\n /**\n * Mount the compiled application into the given DOM container.\n */\n mount(compiled: CompiledApplication, container: Element): MountedApplication {\n if (this._mounted) {\n throw new Error('[Runtime] Already mounted. Call unmount() first.');\n }\n\n // Hand off to renderer — it creates all DOM nodes\n this._renderHandle = this._renderer.mount(compiled, container);\n this._mounted = true;\n\n // Wire signal subscriptions from the graph\n this._bindSignals(compiled.graph);\n\n const self = this;\n return {\n renderHandle: this._renderHandle,\n runtime: this,\n unmount() { self.unmount(); },\n flush() { self._scheduler.flush(); },\n };\n }\n\n unmount(): void {\n if (!this._mounted) return;\n this._mounted = false;\n this._renderHandle?.unmount();\n this._renderHandle = null;\n this._cleanup.run();\n }\n\n /**\n * Hydrate a container that already holds server-rendered HTML for this\n * application. Delegates to the renderer's `hydrate` (adopting the existing\n * DOM instead of recreating it) and falls back to `mount` for renderers that\n * cannot hydrate. Signal binding is identical to `mount`, so the live client\n * lifecycle is established the same way.\n */\n hydrate(compiled: CompiledApplication, container: Element): MountedApplication {\n if (this._mounted) {\n throw new Error('[Runtime] Already mounted. Call unmount() first.');\n }\n\n this._renderHandle = this._renderer.hydrate !== undefined\n ? this._renderer.hydrate(compiled, container)\n : this._renderer.mount(compiled, container);\n this._mounted = true;\n\n this._bindSignals(compiled.graph);\n\n const self = this;\n return {\n renderHandle: this._renderHandle,\n runtime: this,\n unmount() { self.unmount(); },\n flush() { self._scheduler.flush(); },\n };\n }\n\n /**\n * Walk the graph and subscribe to all signal-bound nodes.\n * When a signal changes, schedule a renderer update for that node.\n */\n private _bindSignals(graph: ApplicationGraph): void {\n graph.walk((node) => {\n for (const stateRef of node.stateRefs) {\n const signalKey = `__signal__${stateRef.signalId}`;\n const maybeSignal = graph.getHandler(signalKey) as\n | (Signal<unknown> & ReadonlySignal<unknown>)\n | undefined;\n\n if (maybeSignal === undefined || typeof maybeSignal.subscribe !== 'function') continue;\n\n const unsub = maybeSignal.subscribe(() => {\n // Schedule a re-render update keyed to this node+prop\n this._scheduler.schedule({\n key: `update:${node.id}:${stateRef.propKey}`,\n priority: 'normal',\n fn: () => {\n // The renderer handles the actual DOM update\n this._renderHandle?.flush();\n },\n });\n });\n this._cleanup.add(unsub);\n }\n });\n }\n}\n\n/**\n * Convenience factory — create a runtime, mount, and return the handle.\n */\nexport function createRuntime(options: RuntimeOptions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AQ,YAAY,UAAU,MAAM;AAExC,eAAK,WAAW,SAAS;AAAA,YACvB,KAAK,UAAU,KAAK,EAAE,IAAI,SAAS,OAAO;AAAA,YAC1C,UAAU;AAAA,YACV,IAAI,MAAM;AAER,mBAAK,eAAe,MAAM;AAAA,YAC5B;AAAA,UACF,CAAC;AAAA,QACH,CAAC;AACD,aAAK,SAAS,IAAI,KAAK;AAAA,MACzB;AAAA,IACF,CAAC;AAAA,EACH;AACF;AAKO,SAAS,cAAc,SAAkC;AAC9D,SAAO,IAAI,QAAQ,OAAO;AAC5B;","names":["CleanupRegistry"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@streetui/runtime",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "StreetUI runtime — application mounting, lifecycle, node instances, state/event integration",
|
|
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
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"clean": "rm -rf dist"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@streetui/core": "1.0.0",
|
|
29
|
+
"@streetui/graph": "1.0.0",
|
|
30
|
+
"@streetui/state": "1.0.0",
|
|
31
|
+
"@streetui/events": "1.0.0",
|
|
32
|
+
"@streetui/scheduler": "1.0.0",
|
|
33
|
+
"@streetui/compiler": "1.0.0",
|
|
34
|
+
"@streetui/dsl": "1.0.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"typescript": "*",
|
|
38
|
+
"tsup": "*",
|
|
39
|
+
"vitest": "*"
|
|
40
|
+
},
|
|
41
|
+
"license": "MIT",
|
|
42
|
+
"sideEffects": false,
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"README.md",
|
|
49
|
+
"LICENSE"
|
|
50
|
+
]
|
|
51
|
+
}
|