@kumikijs/runtime 0.1.0 → 0.2.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 +202 -0
- package/README.md +20 -20
- package/dist/index.d.ts +54 -3
- package/dist/index.js +266 -3
- package/package.json +9 -16
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
# @kumikijs/runtime
|
|
2
|
-
|
|
3
|
-
Kumiki DOM runtime — mounts compiled Kumiki apps, dispatches effects, and manages the signal graph. Part of [Kumiki](https://github.com/kage1020/Kumiki).
|
|
4
|
-
|
|
5
|
-
You normally do not import this directly: the compiler embeds the runtime into generated apps. It is published so generated apps and tooling can resolve it.
|
|
6
|
-
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
```sh
|
|
10
|
-
npm i @kumikijs/runtime
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Exports
|
|
14
|
-
|
|
15
|
-
- `@kumikijs/runtime` — the runtime API (`mount`, `runScenario`, `smoke`, …).
|
|
16
|
-
- `@kumikijs/runtime/bundle` — the prebuilt, self-contained runtime bundle as a single file, embedded verbatim into generated apps.
|
|
17
|
-
|
|
18
|
-
## License
|
|
19
|
-
|
|
20
|
-
Apache-2.0
|
|
1
|
+
# @kumikijs/runtime
|
|
2
|
+
|
|
3
|
+
Kumiki DOM runtime — mounts compiled Kumiki apps, dispatches effects, and manages the signal graph. Part of [Kumiki](https://github.com/kage1020/Kumiki).
|
|
4
|
+
|
|
5
|
+
You normally do not import this directly: the compiler embeds the runtime into generated apps. It is published so generated apps and tooling can resolve it.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm i @kumikijs/runtime
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Exports
|
|
14
|
+
|
|
15
|
+
- `@kumikijs/runtime` — the runtime API (`mount`, `runScenario`, `smoke`, …).
|
|
16
|
+
- `@kumikijs/runtime/bundle` — the prebuilt, self-contained runtime bundle as a single file, embedded verbatim into generated apps.
|
|
17
|
+
|
|
18
|
+
## License
|
|
19
|
+
|
|
20
|
+
Apache-2.0
|
package/dist/index.d.ts
CHANGED
|
@@ -173,7 +173,7 @@ type TileNode = {
|
|
|
173
173
|
value?: unknown;
|
|
174
174
|
selected?: boolean;
|
|
175
175
|
} | {
|
|
176
|
-
kind: "grid" | "stack" | "region" | "scroll" | "panel" | "fieldset";
|
|
176
|
+
kind: "grid" | "stack" | "region" | "scroll" | "panel" | "fieldset" | "overlay";
|
|
177
177
|
children: TileNode[];
|
|
178
178
|
props?: TileProps;
|
|
179
179
|
} | {
|
|
@@ -208,6 +208,7 @@ type ReducerSpec = {
|
|
|
208
208
|
} | {
|
|
209
209
|
kind: "timer";
|
|
210
210
|
intervalMs: number;
|
|
211
|
+
name?: string;
|
|
211
212
|
} | {
|
|
212
213
|
kind: "lifecycle";
|
|
213
214
|
name: string;
|
|
@@ -215,6 +216,7 @@ type ReducerSpec = {
|
|
|
215
216
|
apply: (slots: Record<string, unknown>, payload: Record<string, unknown>) => {
|
|
216
217
|
slots: Record<string, unknown>;
|
|
217
218
|
emits: EmitSpec[];
|
|
219
|
+
stopTimers?: string[];
|
|
218
220
|
};
|
|
219
221
|
};
|
|
220
222
|
type EmitSpec = {
|
|
@@ -280,7 +282,8 @@ type AppShape = {
|
|
|
280
282
|
timeout?: number;
|
|
281
283
|
}; /** Phase 4: registered themes by name. */
|
|
282
284
|
themes?: Record<string, Theme>; /** Phase 4: selected theme name. */
|
|
283
|
-
themeName?: string | null;
|
|
285
|
+
themeName?: string | null; /** v0.2 M5: reusable scoped animations by name (closed-grammar keyframes + timing). */
|
|
286
|
+
motions?: Record<string, unknown>;
|
|
284
287
|
root?: () => TileNode;
|
|
285
288
|
live?: Record<string, unknown>;
|
|
286
289
|
_rerender?: () => void;
|
|
@@ -288,7 +291,55 @@ type AppShape = {
|
|
|
288
291
|
declare function mount(app: AppShape, target: HTMLElement): {
|
|
289
292
|
dispose: () => void;
|
|
290
293
|
};
|
|
294
|
+
type TestResult = {
|
|
295
|
+
name: string;
|
|
296
|
+
pass: boolean;
|
|
297
|
+
expected?: string;
|
|
298
|
+
actual?: string;
|
|
299
|
+
diffAt?: string;
|
|
300
|
+
/**
|
|
301
|
+
* The scalar values at the divergence point (`diffAt`), when the runner can
|
|
302
|
+
* isolate one. Powers the §8.7.1 value arrow (`expected -> actual`) and lets
|
|
303
|
+
* `kumiki fix --auto-patch` find the responsible source literal.
|
|
304
|
+
*/
|
|
305
|
+
leaf?: {
|
|
306
|
+
expected: unknown;
|
|
307
|
+
actual: unknown;
|
|
308
|
+
};
|
|
309
|
+
};
|
|
291
310
|
declare const _stdlib: {
|
|
311
|
+
/** Reset live slot state to slot defaults, then apply the test's `given` slots. */resetLive(live: Record<string, unknown>, slots: Record<string, {
|
|
312
|
+
value: unknown;
|
|
313
|
+
}>, given: Record<string, unknown>): void; /** Compare a reducer's resulting slots + emitted effects (or a panic) to `expect`. */
|
|
314
|
+
runReducerTest(input: {
|
|
315
|
+
name: string;
|
|
316
|
+
givenSlots: Record<string, unknown>;
|
|
317
|
+
result: {
|
|
318
|
+
slots: Record<string, unknown>;
|
|
319
|
+
emits: {
|
|
320
|
+
effect: string;
|
|
321
|
+
args: unknown[];
|
|
322
|
+
}[];
|
|
323
|
+
} | null;
|
|
324
|
+
panic: string | null;
|
|
325
|
+
expect: {
|
|
326
|
+
kind: "panic";
|
|
327
|
+
message: string;
|
|
328
|
+
} | {
|
|
329
|
+
kind: "state";
|
|
330
|
+
slots: Record<string, unknown>;
|
|
331
|
+
effects: {
|
|
332
|
+
effect: string;
|
|
333
|
+
args: unknown[];
|
|
334
|
+
argsSpecified?: boolean;
|
|
335
|
+
}[];
|
|
336
|
+
};
|
|
337
|
+
}): TestResult; /** Structurally compare a rendered tile against the expected tile structure. */
|
|
338
|
+
runTileTest(input: {
|
|
339
|
+
name: string;
|
|
340
|
+
actual: unknown;
|
|
341
|
+
expected: unknown;
|
|
342
|
+
}): TestResult;
|
|
292
343
|
mapSize(m: unknown): number;
|
|
293
344
|
mapKeys(m: Record<string, unknown> | undefined | null): string[];
|
|
294
345
|
mapValues(m: Record<string, unknown> | undefined | null): unknown[];
|
|
@@ -360,4 +411,4 @@ declare const builtinEffects: {
|
|
|
360
411
|
httpFetch(method: string, input: unknown, baseUrl: string): Promise<EffectResult>;
|
|
361
412
|
};
|
|
362
413
|
//#endregion
|
|
363
|
-
export { type Action, AppShape, CapabilityRegistry, EffectResult, type EffectScript, EffectSpec, EmitSpec, EventHandler, type Expect, RedirectEntry, ReducerSpec, RefinementCheck, RouteEntry, type Scenario, type ScenarioReport, type ScenarioStep, SlotMeta, type SmokeIssue, type SmokeOptions, type SmokePhase, type SmokeReport, type StepResult, Theme, ThemeValue, TileNode, TileProps, _stdlib, builtinEffects, mount, runScenario, smoke };
|
|
414
|
+
export { type Action, AppShape, CapabilityRegistry, EffectResult, type EffectScript, EffectSpec, EmitSpec, EventHandler, type Expect, RedirectEntry, ReducerSpec, RefinementCheck, RouteEntry, type Scenario, type ScenarioReport, type ScenarioStep, SlotMeta, type SmokeIssue, type SmokeOptions, type SmokePhase, type SmokeReport, type StepResult, TestResult, Theme, ThemeValue, TileNode, TileProps, _stdlib, builtinEffects, mount, runScenario, smoke };
|
package/dist/index.js
CHANGED
|
@@ -424,12 +424,15 @@ function mount(app, target) {
|
|
|
424
424
|
for (const [k, v] of Object.entries(app.slots)) app.live[k] = v.value;
|
|
425
425
|
}
|
|
426
426
|
if (!("route" in app.live)) app.live.route = emptyRoute();
|
|
427
|
+
ensureMotionStyles(app);
|
|
427
428
|
const slotValues = app.live;
|
|
428
429
|
const dispatcher = makeEffectDispatcher(app, makeCapabilityRegistry(app.caps), (effect, outcome, value, key) => {
|
|
429
430
|
handleEffectResult(effect, outcome, value, key);
|
|
430
431
|
});
|
|
431
432
|
let currentRoot = null;
|
|
432
433
|
let disposed = false;
|
|
434
|
+
const namedTimers = /* @__PURE__ */ new Map();
|
|
435
|
+
const anonTimers = [];
|
|
433
436
|
const render = () => {
|
|
434
437
|
if (disposed) return;
|
|
435
438
|
let snap = null;
|
|
@@ -481,6 +484,13 @@ function mount(app, target) {
|
|
|
481
484
|
slotValues[k] = v;
|
|
482
485
|
}
|
|
483
486
|
for (const emit of result.emits) dispatcher.dispatch(emit);
|
|
487
|
+
for (const name of result.stopTimers ?? []) {
|
|
488
|
+
const h = namedTimers.get(name);
|
|
489
|
+
if (h !== void 0) {
|
|
490
|
+
clearInterval(h);
|
|
491
|
+
namedTimers.delete(name);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
484
494
|
render();
|
|
485
495
|
}
|
|
486
496
|
function handleEffectResult(effect, outcome, value, key) {
|
|
@@ -536,10 +546,10 @@ function mount(app, target) {
|
|
|
536
546
|
};
|
|
537
547
|
for (const emit of app.init) dispatcher.dispatch(emit);
|
|
538
548
|
for (const r of app.reducers) if (r.event.kind === "lifecycle" && r.event.name === "app.start") applyReducer(r, {});
|
|
539
|
-
const timerHandles = [];
|
|
540
549
|
for (const r of app.reducers) if (r.event.kind === "timer") {
|
|
541
550
|
const handle = setInterval(() => applyReducer(r, {}), r.event.intervalMs);
|
|
542
|
-
|
|
551
|
+
if (r.event.name !== void 0) namedTimers.set(r.event.name, handle);
|
|
552
|
+
else anonTimers.push(handle);
|
|
543
553
|
}
|
|
544
554
|
if (app.routes && app.routes.length > 0) {
|
|
545
555
|
const cur = slotValues.route;
|
|
@@ -548,7 +558,9 @@ function mount(app, target) {
|
|
|
548
558
|
render();
|
|
549
559
|
return { dispose: () => {
|
|
550
560
|
disposed = true;
|
|
551
|
-
for (const h of
|
|
561
|
+
for (const h of anonTimers) clearInterval(h);
|
|
562
|
+
for (const h of namedTimers.values()) clearInterval(h);
|
|
563
|
+
namedTimers.clear();
|
|
552
564
|
target.replaceChildren();
|
|
553
565
|
dispatcher.dispose();
|
|
554
566
|
} };
|
|
@@ -736,6 +748,11 @@ function _setPathHelper(obj, path, value) {
|
|
|
736
748
|
};
|
|
737
749
|
}
|
|
738
750
|
function renderTile(node) {
|
|
751
|
+
const el = renderTileNode(node);
|
|
752
|
+
applyMotion(el, node.props);
|
|
753
|
+
return el;
|
|
754
|
+
}
|
|
755
|
+
function renderTileNode(node) {
|
|
739
756
|
switch (node.kind) {
|
|
740
757
|
case "page":
|
|
741
758
|
case "column": {
|
|
@@ -779,6 +796,28 @@ function renderTile(node) {
|
|
|
779
796
|
for (const child of node.children) if (child != null) div.appendChild(renderTile(child));
|
|
780
797
|
return div;
|
|
781
798
|
}
|
|
799
|
+
case "overlay": {
|
|
800
|
+
const div = document.createElement("div");
|
|
801
|
+
div.dataset.kumikiTile = "overlay";
|
|
802
|
+
div.style.position = "relative";
|
|
803
|
+
applyContainerProps(div, node.props);
|
|
804
|
+
const align = typeof node.props?.align === "string" ? node.props.align : "center";
|
|
805
|
+
node.children.filter((c) => c != null).forEach((child, i) => {
|
|
806
|
+
if (i === 0) {
|
|
807
|
+
div.appendChild(renderTile(child));
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
const layer = document.createElement("div");
|
|
811
|
+
layer.dataset.kumikiTile = "overlay-layer";
|
|
812
|
+
layer.style.position = "absolute";
|
|
813
|
+
layer.style.inset = "0";
|
|
814
|
+
layer.style.display = "flex";
|
|
815
|
+
applyOverlayAlign(layer, align);
|
|
816
|
+
layer.appendChild(renderTile(child));
|
|
817
|
+
div.appendChild(layer);
|
|
818
|
+
});
|
|
819
|
+
return div;
|
|
820
|
+
}
|
|
782
821
|
case "grid": {
|
|
783
822
|
const div = document.createElement("div");
|
|
784
823
|
div.dataset.kumikiTile = "grid";
|
|
@@ -1055,6 +1094,19 @@ function applyContainerProps(el, props) {
|
|
|
1055
1094
|
applyStateStyles(el, props);
|
|
1056
1095
|
applyTransition(el, props);
|
|
1057
1096
|
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Place an overlay layer inside its `position: relative` container via flexbox.
|
|
1099
|
+
* The token combines a vertical part (`top` / `bottom`, default center) and a
|
|
1100
|
+
* horizontal part (`left` / `right`, default center), e.g. `top-left`,
|
|
1101
|
+
* `bottom`, `center`. Unknown parts fall back to center (consistent with how
|
|
1102
|
+
* other style-prop tokens pass through without compile-time validation).
|
|
1103
|
+
*/
|
|
1104
|
+
function applyOverlayAlign(layer, align) {
|
|
1105
|
+
const parts = align.split("-");
|
|
1106
|
+
const has = (k) => parts.includes(k);
|
|
1107
|
+
layer.style.alignItems = has("top") ? "flex-start" : has("bottom") ? "flex-end" : "center";
|
|
1108
|
+
layer.style.justifyContent = has("left") ? "flex-start" : has("right") ? "flex-end" : "center";
|
|
1109
|
+
}
|
|
1058
1110
|
/** Apply a value that may be a literal or a responsive `{base, sm, md, lg, xl}` map. */
|
|
1059
1111
|
function applyResponsive(_el, raw, set) {
|
|
1060
1112
|
if (raw === void 0 || raw === null) return;
|
|
@@ -1104,6 +1156,58 @@ function applyTransition(el, props) {
|
|
|
1104
1156
|
const d = props["transition-duration"];
|
|
1105
1157
|
if (typeof d === "string") el.classList.add(`kumiki-anim-${d}`);
|
|
1106
1158
|
}
|
|
1159
|
+
/** Map a duration token (or a raw ms number) to a CSS duration. */
|
|
1160
|
+
function motionDuration(d) {
|
|
1161
|
+
if (typeof d === "number") return `${d}ms`;
|
|
1162
|
+
if (d === "fast") return "150ms";
|
|
1163
|
+
if (d === "slow") return "600ms";
|
|
1164
|
+
return "300ms";
|
|
1165
|
+
}
|
|
1166
|
+
/** Build the CSS declarations for one keyframe stop from the closed prop set. */
|
|
1167
|
+
function motionStopCss(stop) {
|
|
1168
|
+
const s = stop ?? {};
|
|
1169
|
+
const decls = [];
|
|
1170
|
+
const transform = [];
|
|
1171
|
+
if (typeof s.opacity === "number") decls.push(`opacity: ${s.opacity}`);
|
|
1172
|
+
if (typeof s["translate-x"] === "number") transform.push(`translateX(${s["translate-x"]}px)`);
|
|
1173
|
+
if (typeof s["translate-y"] === "number") transform.push(`translateY(${s["translate-y"]}px)`);
|
|
1174
|
+
if (typeof s.scale === "number") transform.push(`scale(${s.scale})`);
|
|
1175
|
+
if (typeof s.rotate === "number") transform.push(`rotate(${s.rotate}deg)`);
|
|
1176
|
+
if (transform.length > 0) decls.push(`transform: ${transform.join(" ")}`);
|
|
1177
|
+
return decls.join("; ");
|
|
1178
|
+
}
|
|
1179
|
+
/** Build the `@keyframes` + class CSS for one motion definition. */
|
|
1180
|
+
function motionCss(name, spec) {
|
|
1181
|
+
const s = spec ?? {};
|
|
1182
|
+
const kf = s.keyframes ?? {};
|
|
1183
|
+
const from = motionStopCss(kf.from);
|
|
1184
|
+
const to = motionStopCss(kf.to);
|
|
1185
|
+
const easing = typeof s.easing === "string" ? s.easing : "ease";
|
|
1186
|
+
const iteration = s.iteration === "infinite" ? "infinite" : typeof s.iteration === "number" ? String(s.iteration) : "1";
|
|
1187
|
+
const direction = typeof s.direction === "string" ? s.direction : "normal";
|
|
1188
|
+
const cls = `kumiki-motion-${name}`;
|
|
1189
|
+
return [`@keyframes ${cls} { from { ${from} } to { ${to} } }`, `.${cls} { animation-name: ${cls}; animation-duration: ${motionDuration(s.duration)}; animation-timing-function: ${easing}; animation-iteration-count: ${iteration}; animation-direction: ${direction}; animation-fill-mode: both; }`].join("\n");
|
|
1190
|
+
}
|
|
1191
|
+
/** Inject the app's motion keyframes + a `prefers-reduced-motion` guard at mount. */
|
|
1192
|
+
function ensureMotionStyles(app) {
|
|
1193
|
+
const motions = app.motions ?? {};
|
|
1194
|
+
const rules = Object.entries(motions).map(([name, spec]) => motionCss(name, spec));
|
|
1195
|
+
rules.push(`@media (prefers-reduced-motion: reduce) { .kumiki-motion, .kumiki-anim { animation: none !important } }`);
|
|
1196
|
+
let style = document.getElementById("kumiki-motions");
|
|
1197
|
+
if (!style) {
|
|
1198
|
+
style = document.createElement("style");
|
|
1199
|
+
style.id = "kumiki-motions";
|
|
1200
|
+
document.head.appendChild(style);
|
|
1201
|
+
}
|
|
1202
|
+
style.textContent = rules.join("\n");
|
|
1203
|
+
}
|
|
1204
|
+
/** Add the generated motion class to a tile that carries a `motion: "Name"` prop. */
|
|
1205
|
+
function applyMotion(el, props) {
|
|
1206
|
+
if (!props) return;
|
|
1207
|
+
const m = props.motion;
|
|
1208
|
+
if (typeof m !== "string") return;
|
|
1209
|
+
el.classList.add("kumiki-motion", `kumiki-motion-${m}`);
|
|
1210
|
+
}
|
|
1107
1211
|
let stateStyleSeq = 0;
|
|
1108
1212
|
let stateStylesEl = null;
|
|
1109
1213
|
function applyStateStyles(el, props) {
|
|
@@ -1307,7 +1411,166 @@ function mapSize(s) {
|
|
|
1307
1411
|
default: return s;
|
|
1308
1412
|
}
|
|
1309
1413
|
}
|
|
1414
|
+
function _jsonStr(v) {
|
|
1415
|
+
try {
|
|
1416
|
+
return JSON.stringify(v);
|
|
1417
|
+
} catch {
|
|
1418
|
+
return String(v);
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
/** Deep structural equality for slot values (records / lists / primitives). */
|
|
1422
|
+
function deepEqualValue(a, b) {
|
|
1423
|
+
if (a === b) return true;
|
|
1424
|
+
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") return false;
|
|
1425
|
+
const aArr = Array.isArray(a);
|
|
1426
|
+
const bArr = Array.isArray(b);
|
|
1427
|
+
if (aArr || bArr) {
|
|
1428
|
+
if (!aArr || !bArr || a.length !== b.length) return false;
|
|
1429
|
+
return a.every((x, i) => deepEqualValue(x, b[i]));
|
|
1430
|
+
}
|
|
1431
|
+
const ao = a;
|
|
1432
|
+
const bo = b;
|
|
1433
|
+
const ak = Object.keys(ao);
|
|
1434
|
+
if (ak.length !== Object.keys(bo).length) return false;
|
|
1435
|
+
return ak.every((k) => Object.hasOwn(bo, k) && deepEqualValue(ao[k], bo[k]));
|
|
1436
|
+
}
|
|
1437
|
+
function tileField(node, k) {
|
|
1438
|
+
return node?.[k];
|
|
1439
|
+
}
|
|
1440
|
+
function tileChildren(node) {
|
|
1441
|
+
const c = tileField(node, "children");
|
|
1442
|
+
return Array.isArray(c) ? c.filter((x) => x != null) : [];
|
|
1443
|
+
}
|
|
1444
|
+
/**
|
|
1445
|
+
* Structural tile comparison for tile-tests: compares `kind`, `text`, and
|
|
1446
|
+
* `children` recursively. Props (styles, onClick handlers, …) are out of scope,
|
|
1447
|
+
* per spec §8.4. Returns the first differing path on mismatch.
|
|
1448
|
+
*/
|
|
1449
|
+
function tileStructEqual(expected, actual, path = "") {
|
|
1450
|
+
if (expected == null || actual == null) return expected === actual ? { ok: true } : {
|
|
1451
|
+
ok: false,
|
|
1452
|
+
path: path || "(root)"
|
|
1453
|
+
};
|
|
1454
|
+
const ek = tileField(expected, "kind");
|
|
1455
|
+
const here = path || String(ek ?? "(root)");
|
|
1456
|
+
if (ek !== tileField(actual, "kind")) return {
|
|
1457
|
+
ok: false,
|
|
1458
|
+
path: `${here}.kind`
|
|
1459
|
+
};
|
|
1460
|
+
if (tileField(expected, "text") !== void 0) {
|
|
1461
|
+
const et = String(tileField(expected, "text"));
|
|
1462
|
+
const at = String(tileField(actual, "text"));
|
|
1463
|
+
if (et !== at) return {
|
|
1464
|
+
ok: false,
|
|
1465
|
+
path: `${here}.text`,
|
|
1466
|
+
expectedLeaf: et,
|
|
1467
|
+
actualLeaf: at
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
const ec = tileChildren(expected);
|
|
1471
|
+
const ac = tileChildren(actual);
|
|
1472
|
+
if (ec.length !== ac.length) return {
|
|
1473
|
+
ok: false,
|
|
1474
|
+
path: `${here}.children.length`
|
|
1475
|
+
};
|
|
1476
|
+
for (let i = 0; i < ec.length; i++) {
|
|
1477
|
+
const r = tileStructEqual(ec[i], ac[i], `${here}[${i}]`);
|
|
1478
|
+
if (!r.ok) return r;
|
|
1479
|
+
}
|
|
1480
|
+
return { ok: true };
|
|
1481
|
+
}
|
|
1482
|
+
function serializeTileNode(node) {
|
|
1483
|
+
if (node == null) return "null";
|
|
1484
|
+
const kind = String(tileField(node, "kind"));
|
|
1485
|
+
const kids = tileChildren(node);
|
|
1486
|
+
if (tileField(node, "text") !== void 0 && kids.length === 0) return `${kind}(${_jsonStr(tileField(node, "text"))})`;
|
|
1487
|
+
if (kids.length === 0) return `${kind}()`;
|
|
1488
|
+
return `${kind}(${kids.map(serializeTileNode).join(", ")})`;
|
|
1489
|
+
}
|
|
1310
1490
|
const _stdlib = {
|
|
1491
|
+
/** Reset live slot state to slot defaults, then apply the test's `given` slots. */
|
|
1492
|
+
resetLive(live, slots, given) {
|
|
1493
|
+
for (const k of Object.keys(live)) delete live[k];
|
|
1494
|
+
for (const [k, v] of Object.entries(slots)) live[k] = v.value;
|
|
1495
|
+
Object.assign(live, given);
|
|
1496
|
+
},
|
|
1497
|
+
/** Compare a reducer's resulting slots + emitted effects (or a panic) to `expect`. */
|
|
1498
|
+
runReducerTest(input) {
|
|
1499
|
+
const { name, givenSlots, result, panic, expect } = input;
|
|
1500
|
+
if (expect.kind === "panic") {
|
|
1501
|
+
const pass = panic !== null && String(panic).includes(expect.message);
|
|
1502
|
+
return {
|
|
1503
|
+
name,
|
|
1504
|
+
pass,
|
|
1505
|
+
expected: `panic: ${_jsonStr(expect.message)}`,
|
|
1506
|
+
actual: panic === null ? "(no panic)" : `panic: ${_jsonStr(panic)}`,
|
|
1507
|
+
...pass ? {} : { diffAt: "(panic)" }
|
|
1508
|
+
};
|
|
1509
|
+
}
|
|
1510
|
+
if (panic !== null) return {
|
|
1511
|
+
name,
|
|
1512
|
+
pass: false,
|
|
1513
|
+
expected: _jsonStr(expect.slots),
|
|
1514
|
+
actual: `panic: ${_jsonStr(panic)}`,
|
|
1515
|
+
diffAt: "(unexpected panic)"
|
|
1516
|
+
};
|
|
1517
|
+
const finalSlots = {
|
|
1518
|
+
...givenSlots,
|
|
1519
|
+
...result?.slots ?? {}
|
|
1520
|
+
};
|
|
1521
|
+
let diffAt;
|
|
1522
|
+
let leaf;
|
|
1523
|
+
for (const k of Object.keys(expect.slots)) if (!deepEqualValue(finalSlots[k], expect.slots[k])) {
|
|
1524
|
+
diffAt = `slots.${k}`;
|
|
1525
|
+
leaf = {
|
|
1526
|
+
expected: expect.slots[k],
|
|
1527
|
+
actual: finalSlots[k]
|
|
1528
|
+
};
|
|
1529
|
+
break;
|
|
1530
|
+
}
|
|
1531
|
+
const emits = result?.emits ?? [];
|
|
1532
|
+
if (diffAt === void 0) if (emits.length !== expect.effects.length) diffAt = "effects.length";
|
|
1533
|
+
else for (let i = 0; i < expect.effects.length; i++) {
|
|
1534
|
+
const ex = expect.effects[i];
|
|
1535
|
+
const ac = emits[i];
|
|
1536
|
+
if (!ex || !ac || ex.effect !== ac.effect) {
|
|
1537
|
+
diffAt = `effects[${i}].effect`;
|
|
1538
|
+
break;
|
|
1539
|
+
}
|
|
1540
|
+
if (ex.argsSpecified && !deepEqualValue(ac.args, ex.args)) {
|
|
1541
|
+
diffAt = `effects[${i}].args`;
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
}
|
|
1545
|
+
const pickExpected = (s) => {
|
|
1546
|
+
const o = {};
|
|
1547
|
+
for (const k of Object.keys(expect.slots)) o[k] = s[k];
|
|
1548
|
+
return o;
|
|
1549
|
+
};
|
|
1550
|
+
return {
|
|
1551
|
+
name,
|
|
1552
|
+
pass: diffAt === void 0,
|
|
1553
|
+
expected: `slots=${_jsonStr(expect.slots)} effects=${_jsonStr(expect.effects.map((e) => e.effect))}`,
|
|
1554
|
+
actual: `slots=${_jsonStr(pickExpected(finalSlots))} effects=${_jsonStr(emits.map((e) => e.effect))}`,
|
|
1555
|
+
...diffAt ? { diffAt } : {},
|
|
1556
|
+
...leaf ? { leaf } : {}
|
|
1557
|
+
};
|
|
1558
|
+
},
|
|
1559
|
+
/** Structurally compare a rendered tile against the expected tile structure. */
|
|
1560
|
+
runTileTest(input) {
|
|
1561
|
+
const cmp = tileStructEqual(input.expected, input.actual);
|
|
1562
|
+
return {
|
|
1563
|
+
name: input.name,
|
|
1564
|
+
pass: cmp.ok,
|
|
1565
|
+
expected: serializeTileNode(input.expected),
|
|
1566
|
+
actual: serializeTileNode(input.actual),
|
|
1567
|
+
...cmp.path ? { diffAt: cmp.path } : {},
|
|
1568
|
+
...cmp.expectedLeaf !== void 0 || cmp.actualLeaf !== void 0 ? { leaf: {
|
|
1569
|
+
expected: cmp.expectedLeaf,
|
|
1570
|
+
actual: cmp.actualLeaf
|
|
1571
|
+
} } : {}
|
|
1572
|
+
};
|
|
1573
|
+
},
|
|
1311
1574
|
mapSize(m) {
|
|
1312
1575
|
if (m instanceof Map) return m.size;
|
|
1313
1576
|
if (m && typeof m === "object") return Object.keys(m).length;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kumikijs/runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Kumiki DOM runtime — mounts compiled Kumiki apps, dispatches effects, manages the signal graph.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"exports": {
|
|
27
27
|
".": {
|
|
28
28
|
"types": "./dist/index.d.ts",
|
|
29
|
-
"
|
|
29
|
+
"import": "./dist/index.js"
|
|
30
30
|
},
|
|
31
31
|
"./bundle": "./dist/index.js"
|
|
32
32
|
},
|
|
@@ -35,24 +35,17 @@
|
|
|
35
35
|
],
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public",
|
|
38
|
-
"provenance": true
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"./bundle": "./dist/index.js"
|
|
45
|
-
}
|
|
38
|
+
"provenance": true
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"jsdom": "^29.1.1",
|
|
42
|
+
"typescript": "^6.0.3",
|
|
43
|
+
"vitest": "^4.1.7"
|
|
46
44
|
},
|
|
47
45
|
"scripts": {
|
|
48
46
|
"build": "tsdown",
|
|
49
47
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
50
48
|
"test": "vitest run",
|
|
51
49
|
"lint": "biome check src test"
|
|
52
|
-
},
|
|
53
|
-
"devDependencies": {
|
|
54
|
-
"jsdom": "catalog:",
|
|
55
|
-
"typescript": "catalog:",
|
|
56
|
-
"vitest": "catalog:"
|
|
57
50
|
}
|
|
58
|
-
}
|
|
51
|
+
}
|