@wardic/test 0.0.0-stage → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +13 -2
- package/THIRD_PARTY_NOTICES.md +145 -0
- package/dist/clock.d.ts +55 -0
- package/dist/clock.d.ts.map +1 -0
- package/dist/clock.js +119 -0
- package/dist/clock.js.map +1 -0
- package/dist/feeds.d.ts +25 -0
- package/dist/feeds.d.ts.map +1 -0
- package/dist/feeds.js +32 -0
- package/dist/feeds.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/input.d.ts +60 -0
- package/dist/input.d.ts.map +1 -0
- package/dist/input.js +90 -0
- package/dist/input.js.map +1 -0
- package/dist/layer.d.ts +27 -0
- package/dist/layer.d.ts.map +1 -0
- package/dist/layer.js +43 -0
- package/dist/layer.js.map +1 -0
- package/dist/probe.d.ts +46 -0
- package/dist/probe.d.ts.map +1 -0
- package/dist/probe.js +60 -0
- package/dist/probe.js.map +1 -0
- package/dist/renderer.d.ts +32 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +43 -0
- package/dist/renderer.js.map +1 -0
- package/package.json +54 -4
- package/src/clock.ts +136 -0
- package/src/feeds.ts +46 -0
- package/src/index.ts +17 -0
- package/src/input.ts +104 -0
- package/src/layer.ts +78 -0
- package/src/probe.ts +87 -0
- package/src/renderer.ts +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 the Wardic 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
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @wardic/test
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Headless testing Layers for [Wardic](https://wardic.dev)'s core and for a new Environment: animation code runs with no page at all.
|
|
4
|
+
|
|
5
|
+
- `TestClock`: a clock that replays the frames you give it, so every frame's values can be read in turn;
|
|
6
|
+
- `TestRenderer`: a renderer that records what it's asked to draw (`TestRenderer.make()`);
|
|
7
|
+
- `TestInput`: pointer, keyboard and focus input you push;
|
|
8
|
+
- `TestProbe`: the page as you script it: its boxes, viewport, scroll and what's in view.
|
|
9
|
+
|
|
10
|
+
`TestLive` (or `testLayer(frames)`) is all four together. It draws nothing on a page, and its clock moves only through the frames it's given, so an element rendered under it stays at its starting style. To test an app's components, render them with `DomLive` in jsdom or happy-dom, under your test runner's fake timers: see https://wardic.dev/guides/testing.
|
|
11
|
+
|
|
12
|
+
- Docs: https://wardic.dev
|
|
13
|
+
- Source: https://github.com/wardiclabs/wardic/tree/main/packages/test
|
|
14
|
+
- Licence: MIT
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
Wardic follows the API of [Motion](https://motion.dev) for React, and parts of its source are ported from Motion's: rewritten in Wardic's own style, keeping Motion's algorithms, formulas and constants so the results match. Motion is MIT licensed, and its notice follows.
|
|
4
|
+
|
|
5
|
+
## Motion
|
|
6
|
+
|
|
7
|
+
https://github.com/motiondivision/motion
|
|
8
|
+
|
|
9
|
+
Ported from Motion's source:
|
|
10
|
+
|
|
11
|
+
- `@wardic/core`:
|
|
12
|
+
- `Box` and `Projection`: the projection geometry (`motion-dom`'s `projection/geometry`: `models`, `delta-calc`, `delta-apply`, `applyTreeDeltas`);
|
|
13
|
+
- `Spring`: the solver for a spring's stiffness and damping from its duration and bounce (`findSpring`);
|
|
14
|
+
- `Velocity`: a gesture's velocity from its points (`getVelocity`);
|
|
15
|
+
- `Reorder`: moving an item, and the axis a list runs on (`moveItem`, `detectAxis`);
|
|
16
|
+
- `AutoScroll`: scrolling a container while an item is dragged near its edge (`autoScrollIfNeeded`).
|
|
17
|
+
- `@wardic/dom`:
|
|
18
|
+
- the projection transform (`buildProjectionTransform`);
|
|
19
|
+
- the scroll offsets (`render/dom/scroll/offsets`).
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
The MIT License (MIT)
|
|
23
|
+
|
|
24
|
+
Copyright (c) 2024 [Motion](https://motion.dev) B.V.
|
|
25
|
+
|
|
26
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
27
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
28
|
+
in the Software without restriction, including without limitation the rights
|
|
29
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
30
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
31
|
+
furnished to do so, subject to the following conditions:
|
|
32
|
+
|
|
33
|
+
The above copyright notice and this permission notice shall be included in all
|
|
34
|
+
copies or substantial portions of the Software.
|
|
35
|
+
|
|
36
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
37
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
38
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
39
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
40
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
41
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
42
|
+
SOFTWARE.
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Manrope
|
|
46
|
+
|
|
47
|
+
https://github.com/googlefonts/manrope
|
|
48
|
+
|
|
49
|
+
The docs site serves Manrope for its headings (`site/public/fonts/manrope-latin.woff2`, its variable weights 600 to 800, Latin only, with its licence beside it as `OFL.txt`), and Wardic's wordmark is "wardic" set in Manrope ExtraBold and outlined (`brand/`, and the docs header's logo, `site/src/components/logo-paths.ts`). Manrope is licensed under the SIL Open Font License, Version 1.1.
|
|
50
|
+
|
|
51
|
+
```
|
|
52
|
+
Copyright 2018 The Manrope Project Authors (https://github.com/googlefonts/manrope)
|
|
53
|
+
|
|
54
|
+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
|
|
55
|
+
This license is copied below, and is also available with a FAQ at:
|
|
56
|
+
http://scripts.sil.org/OFL
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
-----------------------------------------------------------
|
|
60
|
+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
|
|
61
|
+
-----------------------------------------------------------
|
|
62
|
+
|
|
63
|
+
PREAMBLE
|
|
64
|
+
The goals of the Open Font License (OFL) are to stimulate worldwide
|
|
65
|
+
development of collaborative font projects, to support the font creation
|
|
66
|
+
efforts of academic and linguistic communities, and to provide a free and
|
|
67
|
+
open framework in which fonts may be shared and improved in partnership
|
|
68
|
+
with others.
|
|
69
|
+
|
|
70
|
+
The OFL allows the licensed fonts to be used, studied, modified and
|
|
71
|
+
redistributed freely as long as they are not sold by themselves. The
|
|
72
|
+
fonts, including any derivative works, can be bundled, embedded,
|
|
73
|
+
redistributed and/or sold with any software provided that any reserved
|
|
74
|
+
names are not used by derivative works. The fonts and derivatives,
|
|
75
|
+
however, cannot be released under any other type of license. The
|
|
76
|
+
requirement for fonts to remain under this license does not apply
|
|
77
|
+
to any document created using the fonts or their derivatives.
|
|
78
|
+
|
|
79
|
+
DEFINITIONS
|
|
80
|
+
"Font Software" refers to the set of files released by the Copyright
|
|
81
|
+
Holder(s) under this license and clearly marked as such. This may
|
|
82
|
+
include source files, build scripts and documentation.
|
|
83
|
+
|
|
84
|
+
"Reserved Font Name" refers to any names specified as such after the
|
|
85
|
+
copyright statement(s).
|
|
86
|
+
|
|
87
|
+
"Original Version" refers to the collection of Font Software components as
|
|
88
|
+
distributed by the Copyright Holder(s).
|
|
89
|
+
|
|
90
|
+
"Modified Version" refers to any derivative made by adding to, deleting,
|
|
91
|
+
or substituting -- in part or in whole -- any of the components of the
|
|
92
|
+
Original Version, by changing formats or by porting the Font Software to a
|
|
93
|
+
new environment.
|
|
94
|
+
|
|
95
|
+
"Author" refers to any designer, engineer, programmer, technical
|
|
96
|
+
writer or other person who contributed to the Font Software.
|
|
97
|
+
|
|
98
|
+
PERMISSION & CONDITIONS
|
|
99
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
100
|
+
a copy of the Font Software, to use, study, copy, merge, embed, modify,
|
|
101
|
+
redistribute, and sell modified and unmodified copies of the Font
|
|
102
|
+
Software, subject to the following conditions:
|
|
103
|
+
|
|
104
|
+
1) Neither the Font Software nor any of its individual components,
|
|
105
|
+
in Original or Modified Versions, may be sold by itself.
|
|
106
|
+
|
|
107
|
+
2) Original or Modified Versions of the Font Software may be bundled,
|
|
108
|
+
redistributed and/or sold with any software, provided that each copy
|
|
109
|
+
contains the above copyright notice and this license. These can be
|
|
110
|
+
included either as stand-alone text files, human-readable headers or
|
|
111
|
+
in the appropriate machine-readable metadata fields within text or
|
|
112
|
+
binary files as long as those fields can be easily viewed by the user.
|
|
113
|
+
|
|
114
|
+
3) No Modified Version of the Font Software may use the Reserved Font
|
|
115
|
+
Name(s) unless explicit written permission is granted by the corresponding
|
|
116
|
+
Copyright Holder. This restriction only applies to the primary font name as
|
|
117
|
+
presented to the users.
|
|
118
|
+
|
|
119
|
+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
|
|
120
|
+
Software shall not be used to promote, endorse or advertise any
|
|
121
|
+
Modified Version, except to acknowledge the contribution(s) of the
|
|
122
|
+
Copyright Holder(s) and the Author(s) or with their explicit written
|
|
123
|
+
permission.
|
|
124
|
+
|
|
125
|
+
5) The Font Software, modified or unmodified, in part or in whole,
|
|
126
|
+
must be distributed entirely under this license, and must not be
|
|
127
|
+
distributed under any other license. The requirement for fonts to
|
|
128
|
+
remain under this license does not apply to any document created
|
|
129
|
+
using the Font Software.
|
|
130
|
+
|
|
131
|
+
TERMINATION
|
|
132
|
+
This license becomes null and void if any of the above conditions are
|
|
133
|
+
not met.
|
|
134
|
+
|
|
135
|
+
DISCLAIMER
|
|
136
|
+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
137
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
|
|
138
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
|
|
139
|
+
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
|
|
140
|
+
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
141
|
+
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|
142
|
+
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
143
|
+
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
|
|
144
|
+
OTHER DEALINGS IN THE FONT SOFTWARE.
|
|
145
|
+
```
|
package/dist/clock.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as Clock from "@wardic/core/Clock";
|
|
2
|
+
import * as RefreshFrameSource from "@wardic/core/RefreshFrameSource";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Layer from "effect/Layer";
|
|
5
|
+
/**
|
|
6
|
+
* A deterministic Clock for frame-level tests. `ticks` replays the supplied `dt`
|
|
7
|
+
* sequence (in seconds) exactly once, so a primitive's per-frame output can be
|
|
8
|
+
* collected with `Stream.runCollect` and asserted. Its `now` is the time those
|
|
9
|
+
* ticks have reached, in ms, from 0: the furthest any subscriber has
|
|
10
|
+
* reached, so two subscribers replaying the same frames don't run it twice as
|
|
11
|
+
* fast. A live Clock (rAF-driven) is `@wardic/dom`'s.
|
|
12
|
+
*/
|
|
13
|
+
export declare const make: (frames?: ReadonlyArray<number>) => Clock.Clock["Service"];
|
|
14
|
+
/** Clock Layer that emits `frames` (dt values, seconds) then completes. */
|
|
15
|
+
export declare const layer: (frames?: ReadonlyArray<number>) => Layer.Layer<Clock.Clock>;
|
|
16
|
+
/**
|
|
17
|
+
* Convenience: `n` frames of a fixed `dt` (default 1/60s) — e.g. `frames(30)`
|
|
18
|
+
* for half a second at 60fps.
|
|
19
|
+
*/
|
|
20
|
+
export declare const frames: (count: number, dt?: number) => ReadonlyArray<number>;
|
|
21
|
+
/**
|
|
22
|
+
* A push-based Clock for tests that need to advance frames *on demand* —
|
|
23
|
+
* interleaved with pointer input — rather than replaying a fixed sequence. The
|
|
24
|
+
* static {@link layer} drains its whole `ticks` stream as fast as the consumer
|
|
25
|
+
* pulls, which makes it impossible to assert "advance a few frames, do
|
|
26
|
+
* something, advance more". This form lets the test `advance` one dt at a time.
|
|
27
|
+
*
|
|
28
|
+
* Backed by a `PubSub` (broadcast, no replay) so a consumer only sees ticks
|
|
29
|
+
* pushed *after* it subscribes — matching a live rAF clock where motion starts
|
|
30
|
+
* from the moment you subscribe. It has no Cold start: its ticks are the advances.
|
|
31
|
+
*
|
|
32
|
+
* Its `layer` also provides the Environment's `RefreshFrameSource`, and one `advance`
|
|
33
|
+
* is one Refresh frame in the web's order: it runs the frames requested so far (a flush gate's
|
|
34
|
+
* flush of a write made outside a tick), in request order, then publishes `dt` (the Clock's
|
|
35
|
+
* tick, at whose end a Frame loop over this Clock calls its `afterTick` hooks: the gate's
|
|
36
|
+
* flush). A frame requested during that `advance` waits for the next one. The frames'
|
|
37
|
+
* timestamps start at 0 and advance by `dt`, and the Clock's `now` is the last one's: a test's
|
|
38
|
+
* advances drive velocities too.
|
|
39
|
+
*
|
|
40
|
+
* It doesn't yield: a subscriber waiting on the ticks handles the tick inside the
|
|
41
|
+
* publish, as every subscriber does inside a real Refresh frame's callback, so a consumer that
|
|
42
|
+
* hops through Effect's scheduler on its way to its sink hasn't got there when `advance`
|
|
43
|
+
* returns, and its test sees it.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* const clock = yield* TestClock.pushable()
|
|
47
|
+
* // … fork a stream that consumes Clock.ticks, providing clock.layer …
|
|
48
|
+
* yield* clock.advance() // one 1/60s frame
|
|
49
|
+
* yield* clock.advance(1 / 30) // a custom dt
|
|
50
|
+
*/
|
|
51
|
+
export declare const pushable: () => Effect.Effect<{
|
|
52
|
+
readonly layer: Layer.Layer<Clock.Clock | RefreshFrameSource.RefreshFrameSource>;
|
|
53
|
+
readonly advance: (dt?: number) => Effect.Effect<void>;
|
|
54
|
+
}>;
|
|
55
|
+
//# sourceMappingURL=clock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../src/clock.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,kBAAkB,MAAM,iCAAiC,CAAA;AAErE,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAOrC;;;;;;;GAOG;AAEH,eAAO,MAAM,IAAI,YAAY,aAAa,CAAC,MAAM,CAAC,KAAQ,KAAK,CAAC,KAAK,CAAC,SAAS,CAa9E,CAAA;AAED,2EAA2E;AAC3E,eAAO,MAAM,KAAK,YAAY,aAAa,CAAC,MAAM,CAAC,KAAQ,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAErC,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,MAAM,UAAW,MAAM,kBAAgB,aAAa,CAAC,MAAM,CAC/B,CAAA;AAkCzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,eAAO,MAAM,QAAQ,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,CAAA;IAChF,QAAQ,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CACvD,CAoBG,CAAA"}
|
package/dist/clock.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as Clock from "@wardic/core/Clock";
|
|
2
|
+
import * as RefreshFrameSource from "@wardic/core/RefreshFrameSource";
|
|
3
|
+
import * as Arr from "effect/Array";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import { constVoid } from "effect/Function";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
import * as MutableRef from "effect/MutableRef";
|
|
8
|
+
import * as Predicate from "effect/Predicate";
|
|
9
|
+
import * as PubSub from "effect/PubSub";
|
|
10
|
+
import * as Stream from "effect/Stream";
|
|
11
|
+
import * as UndefinedOr from "effect/UndefinedOr";
|
|
12
|
+
/**
|
|
13
|
+
* A deterministic Clock for frame-level tests. `ticks` replays the supplied `dt`
|
|
14
|
+
* sequence (in seconds) exactly once, so a primitive's per-frame output can be
|
|
15
|
+
* collected with `Stream.runCollect` and asserted. Its `now` is the time those
|
|
16
|
+
* ticks have reached, in ms, from 0: the furthest any subscriber has
|
|
17
|
+
* reached, so two subscribers replaying the same frames don't run it twice as
|
|
18
|
+
* fast. A live Clock (rAF-driven) is `@wardic/dom`'s.
|
|
19
|
+
*/
|
|
20
|
+
// `now`: #460.
|
|
21
|
+
export const make = (frames = []) => {
|
|
22
|
+
const time = MutableRef.make(0);
|
|
23
|
+
// Each frame with the time it reaches, in ms from 0 (#618, decision 7: each subscriber added its
|
|
24
|
+
// frames to one sum).
|
|
25
|
+
const reached = Arr.zip(frames, Arr.drop(Arr.scan(frames, 0, (at, dt) => at + dt * 1000), 1));
|
|
26
|
+
return {
|
|
27
|
+
ticks: Stream.map(Stream.fromIterable(reached), ([dt, at]) => {
|
|
28
|
+
MutableRef.update(time, (t) => Math.max(t, at));
|
|
29
|
+
return dt;
|
|
30
|
+
}),
|
|
31
|
+
tick: (_t) => Effect.sync(() => { }),
|
|
32
|
+
now: () => MutableRef.get(time),
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
/** Clock Layer that emits `frames` (dt values, seconds) then completes. */
|
|
36
|
+
export const layer = (frames = []) =>
|
|
37
|
+
// A Clock per build: one Layer built twice shares no time (#618).
|
|
38
|
+
Layer.sync(Clock.Clock, () => make(frames));
|
|
39
|
+
/**
|
|
40
|
+
* Convenience: `n` frames of a fixed `dt` (default 1/60s) — e.g. `frames(30)`
|
|
41
|
+
* for half a second at 60fps.
|
|
42
|
+
*/
|
|
43
|
+
export const frames = (count, dt = 1 / 60) => Array.from({ length: count }, () => dt);
|
|
44
|
+
/**
|
|
45
|
+
* The Refresh frames `pushable`'s `advance` fires: a `RefreshFrameSource` that keeps the
|
|
46
|
+
* contract's order rules, as `requestAnimationFrame` does (ADR-0031, decision 4). `fire` runs the
|
|
47
|
+
* callbacks requested before it, in request order. One requested while they run waits for the
|
|
48
|
+
* next `fire`, and one cancelled before its turn never runs.
|
|
49
|
+
*/
|
|
50
|
+
const makeFrames = () => {
|
|
51
|
+
const pending = new Map();
|
|
52
|
+
const nextHandle = MutableRef.make(1);
|
|
53
|
+
const source = {
|
|
54
|
+
requestFrame: (callback) => {
|
|
55
|
+
const handle = MutableRef.getAndIncrement(nextHandle);
|
|
56
|
+
pending.set(handle, callback);
|
|
57
|
+
return handle;
|
|
58
|
+
},
|
|
59
|
+
cancelFrame: (handle) => {
|
|
60
|
+
if (Predicate.isNumber(handle))
|
|
61
|
+
pending.delete(handle);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
/** Run the callbacks requested so far at timestamp `t` (ms). */
|
|
65
|
+
const fire = (t) => Arr.forEach(Arr.fromIterable(pending.keys()), (handle) => UndefinedOr.match(pending.get(handle), {
|
|
66
|
+
onUndefined: constVoid,
|
|
67
|
+
onDefined: (callback) => {
|
|
68
|
+
pending.delete(handle);
|
|
69
|
+
callback(t);
|
|
70
|
+
},
|
|
71
|
+
}));
|
|
72
|
+
return { source, fire };
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* A push-based Clock for tests that need to advance frames *on demand* —
|
|
76
|
+
* interleaved with pointer input — rather than replaying a fixed sequence. The
|
|
77
|
+
* static {@link layer} drains its whole `ticks` stream as fast as the consumer
|
|
78
|
+
* pulls, which makes it impossible to assert "advance a few frames, do
|
|
79
|
+
* something, advance more". This form lets the test `advance` one dt at a time.
|
|
80
|
+
*
|
|
81
|
+
* Backed by a `PubSub` (broadcast, no replay) so a consumer only sees ticks
|
|
82
|
+
* pushed *after* it subscribes — matching a live rAF clock where motion starts
|
|
83
|
+
* from the moment you subscribe. It has no Cold start: its ticks are the advances.
|
|
84
|
+
*
|
|
85
|
+
* Its `layer` also provides the Environment's `RefreshFrameSource`, and one `advance`
|
|
86
|
+
* is one Refresh frame in the web's order: it runs the frames requested so far (a flush gate's
|
|
87
|
+
* flush of a write made outside a tick), in request order, then publishes `dt` (the Clock's
|
|
88
|
+
* tick, at whose end a Frame loop over this Clock calls its `afterTick` hooks: the gate's
|
|
89
|
+
* flush). A frame requested during that `advance` waits for the next one. The frames'
|
|
90
|
+
* timestamps start at 0 and advance by `dt`, and the Clock's `now` is the last one's: a test's
|
|
91
|
+
* advances drive velocities too.
|
|
92
|
+
*
|
|
93
|
+
* It doesn't yield: a subscriber waiting on the ticks handles the tick inside the
|
|
94
|
+
* publish, as every subscriber does inside a real Refresh frame's callback, so a consumer that
|
|
95
|
+
* hops through Effect's scheduler on its way to its sink hasn't got there when `advance`
|
|
96
|
+
* returns, and its test sees it.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* const clock = yield* TestClock.pushable()
|
|
100
|
+
* // … fork a stream that consumes Clock.ticks, providing clock.layer …
|
|
101
|
+
* yield* clock.advance() // one 1/60s frame
|
|
102
|
+
* yield* clock.advance(1 / 30) // a custom dt
|
|
103
|
+
*/
|
|
104
|
+
// The RefreshFrameSource: ADR-0031. The gate's flush at the tick's end: ADR-0033. `now`: #460. No
|
|
105
|
+
// yield: ADR-0032.
|
|
106
|
+
export const pushable = Effect.fnUntraced(function* () {
|
|
107
|
+
const pubsub = yield* PubSub.unbounded();
|
|
108
|
+
const frames = makeFrames();
|
|
109
|
+
const time = MutableRef.make(0);
|
|
110
|
+
return {
|
|
111
|
+
layer: Layer.merge(Layer.succeed(Clock.Clock, {
|
|
112
|
+
ticks: Stream.fromPubSub(pubsub),
|
|
113
|
+
tick: (_t) => Effect.sync(() => { }),
|
|
114
|
+
now: () => MutableRef.get(time),
|
|
115
|
+
}), RefreshFrameSource.layer(frames.source)),
|
|
116
|
+
advance: (dt = 1 / 60) => Effect.sync(() => frames.fire(MutableRef.updateAndGet(time, (t) => t + dt * 1000))).pipe(Effect.andThen(PubSub.publish(pubsub, dt)), Effect.asVoid),
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.js","sourceRoot":"","sources":["../src/clock.ts"],"names":[],"mappings":"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"}
|
package/dist/feeds.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Test Environment's **Input feeds** (#318): a script replayed to each subscriber, and a hub a
|
|
3
|
+
* test pushes into.
|
|
4
|
+
*/
|
|
5
|
+
import type * as InputFeed from "@wardic/core/InputFeed";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
/**
|
|
8
|
+
* A fixed script as a feed: each subscriber hears every event as it subscribes, then the end. A
|
|
9
|
+
* Stream over it (`InputFeed.toStream`) emits the script and ends, as `Stream.fromIterable` did; an
|
|
10
|
+
* empty one ends at once. Not shared: each subscriber gets the whole script (tests address one
|
|
11
|
+
* surface, and a consumer may read it twice).
|
|
12
|
+
*/
|
|
13
|
+
export declare const script: <A>(events: ReadonlyArray<A>) => InputFeed.InputFeed<A>;
|
|
14
|
+
/** A live feed a test pushes into, and the push. */
|
|
15
|
+
export interface Hub<A> {
|
|
16
|
+
readonly feed: InputFeed.InputFeed<A>;
|
|
17
|
+
readonly push: (event: A) => Effect.Effect<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* A live feed: every subscriber hears each event pushed after it subscribed, in the order they
|
|
21
|
+
* subscribed. `push` doesn't yield (ADR-0032): a subscriber handles the event inside the push, as an
|
|
22
|
+
* Environment's consumers handle a real event inside its dispatch.
|
|
23
|
+
*/
|
|
24
|
+
export declare const hub: <A>() => Hub<A>;
|
|
25
|
+
//# sourceMappingURL=feeds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feeds.d.ts","sourceRoot":"","sources":["../src/feeds.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,KAAK,SAAS,MAAM,wBAAwB,CAAA;AAExD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAGvC;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAChB,CAAC,UAAU,aAAa,CAAC,CAAC,CAAC,KAAG,SAAS,CAAC,SAAS,CAAC,CAAC,CAKnD,CAAA;AAEH,oDAAoD;AACpD,MAAM,WAAW,GAAG,CAAC,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;IACrC,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CACjD;AAED;;;;GAIG;AACH,eAAO,MAAM,GAAG,GAAI,CAAC,OAAK,GAAG,CAAC,CAAC,CAW9B,CAAA"}
|
package/dist/feeds.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as Arr from "effect/Array";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import { constVoid } from "effect/Function";
|
|
4
|
+
/**
|
|
5
|
+
* A fixed script as a feed: each subscriber hears every event as it subscribes, then the end. A
|
|
6
|
+
* Stream over it (`InputFeed.toStream`) emits the script and ends, as `Stream.fromIterable` did; an
|
|
7
|
+
* empty one ends at once. Not shared: each subscriber gets the whole script (tests address one
|
|
8
|
+
* surface, and a consumer may read it twice).
|
|
9
|
+
*/
|
|
10
|
+
export const script = (events) => (emit, end) => {
|
|
11
|
+
Arr.forEach(events, emit);
|
|
12
|
+
end();
|
|
13
|
+
return constVoid;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A live feed: every subscriber hears each event pushed after it subscribed, in the order they
|
|
17
|
+
* subscribed. `push` doesn't yield (ADR-0032): a subscriber handles the event inside the push, as an
|
|
18
|
+
* Environment's consumers handle a real event inside its dispatch.
|
|
19
|
+
*/
|
|
20
|
+
export const hub = () => {
|
|
21
|
+
let subscribers = [];
|
|
22
|
+
return {
|
|
23
|
+
feed: (emit) => {
|
|
24
|
+
subscribers = Arr.append(subscribers, emit);
|
|
25
|
+
return () => {
|
|
26
|
+
subscribers = Arr.filter(subscribers, (s) => s !== emit);
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
push: (event) => Effect.sync(() => Arr.forEach(subscribers, (emit) => emit(event))),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=feeds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feeds.js","sourceRoot":"","sources":["../src/feeds.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,MAAM,GACjB,CAAI,MAAwB,EAA0B,EAAE,CACxD,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;IACZ,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IACzB,GAAG,EAAE,CAAA;IACL,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA;AAQH;;;;GAIG;AACH,MAAM,CAAC,MAAM,GAAG,GAAG,GAAc,EAAE;IACjC,IAAI,WAAW,GAAsC,EAAE,CAAA;IACvD,OAAO;QACL,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;YACb,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAA;YAC3C,OAAO,GAAG,EAAE;gBACV,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAA;YAC1D,CAAC,CAAA;QACH,CAAC;QACD,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;KACpF,CAAA;AACH,CAAC,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wardic/test — headless testing Layers.
|
|
3
|
+
*
|
|
4
|
+
* Provide `TestLive` (or `testLayer(frames)`) in place of `@wardic/dom`'s
|
|
5
|
+
* `DomLive` to run animation code without a page. The Clock is deterministic
|
|
6
|
+
* (replays a `dt` sequence), so primitive output is collectable frame-by-frame.
|
|
7
|
+
* Nothing is drawn on a page: an app's components are tested with `DomLive`
|
|
8
|
+
* under the test runner's fake timers, as https://wardic.dev/guides/testing shows.
|
|
9
|
+
*/
|
|
10
|
+
export declare const VERSION = "0.1.0-alpha.0";
|
|
11
|
+
export * as TestClock from "./clock.ts";
|
|
12
|
+
export * as TestRenderer from "./renderer.ts";
|
|
13
|
+
export * as TestProbe from "./probe.ts";
|
|
14
|
+
export * as TestInput from "./input.ts";
|
|
15
|
+
export { testLayer, TestLive } from "./layer.ts";
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,eAAO,MAAM,OAAO,kBAAkB,CAAA;AAEtC,OAAO,KAAK,SAAS,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,YAAY,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,SAAS,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @wardic/test — headless testing Layers.
|
|
3
|
+
*
|
|
4
|
+
* Provide `TestLive` (or `testLayer(frames)`) in place of `@wardic/dom`'s
|
|
5
|
+
* `DomLive` to run animation code without a page. The Clock is deterministic
|
|
6
|
+
* (replays a `dt` sequence), so primitive output is collectable frame-by-frame.
|
|
7
|
+
* Nothing is drawn on a page: an app's components are tested with `DomLive`
|
|
8
|
+
* under the test runner's fake timers, as https://wardic.dev/guides/testing shows.
|
|
9
|
+
*/
|
|
10
|
+
// The testing guide: #558.
|
|
11
|
+
export const VERSION = "0.1.0-alpha.0";
|
|
12
|
+
export * as TestClock from "./clock.js";
|
|
13
|
+
export * as TestRenderer from "./renderer.js";
|
|
14
|
+
export * as TestProbe from "./probe.js";
|
|
15
|
+
export * as TestInput from "./input.js";
|
|
16
|
+
export { testLayer, TestLive } from "./layer.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,2BAA2B;AAC3B,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAA;AAEtC,OAAO,KAAK,SAAS,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,YAAY,MAAM,eAAe,CAAA;AAC7C,OAAO,KAAK,SAAS,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/input.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import * as InputSource from "@wardic/core/InputSource";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
/**
|
|
5
|
+
* An InputSource that replays fixed scripts of events, as **Input feeds** that end after their
|
|
6
|
+
* script: a Stream over one ends too. `pointer(target)` replays the same `pointerEvents`,
|
|
7
|
+
* `focus(target)` the same `focusEvents` and `keyboard(target)` the same `keyEvents` to each
|
|
8
|
+
* subscriber (each ignores `target` — tests address a single surface). The first positional arg is
|
|
9
|
+
* pointer events for back-compat; focus and key events are optional, defaulting to empty so existing
|
|
10
|
+
* call sites emit nothing on them. Each script plays whole when its feed is subscribed, so scripts of
|
|
11
|
+
* two kinds don't interleave: a test that needs them to pushes them ({@link pushable}). Called with no
|
|
12
|
+
* args it yields an InputSource that emits nothing — for tests that don't exercise gestures. It adopts
|
|
13
|
+
* no pointer: `adoptPointer` delivers nothing.
|
|
14
|
+
*/
|
|
15
|
+
export declare const layer: (pointerEvents?: ReadonlyArray<InputSource.PointerLikeEvent>, focusEvents?: ReadonlyArray<InputSource.FocusLikeEvent>, keyEvents?: ReadonlyArray<InputSource.KeyboardLikeEvent>) => Layer.Layer<InputSource.InputSource>;
|
|
16
|
+
/**
|
|
17
|
+
* A push-based InputSource for tests that need to interleave pointer events with
|
|
18
|
+
* other effects (e.g. advancing the Clock between a release and a re-grab). Unlike
|
|
19
|
+
* {@link layer} — which replays a fixed script that drains immediately — this
|
|
20
|
+
* form lets the test `push` events one at a time, on its own schedule.
|
|
21
|
+
*
|
|
22
|
+
* Backed by a hub (`feeds.ts`) so that every subscription to `pointer(target)`
|
|
23
|
+
* hears every event: a consumer may subscribe to `input.pointer(target)` more than once
|
|
24
|
+
* (a binding's drag track reads the drag fold and the grabs). There is no replay buffer,
|
|
25
|
+
* so only events pushed *after* a subscription is live reach it.
|
|
26
|
+
*
|
|
27
|
+
* `push` doesn't yield: a subscriber handles the event inside the push, as an
|
|
28
|
+
* Environment's consumers handle a real event inside its dispatch, so a pipeline that hops
|
|
29
|
+
* through Effect's scheduler on its way to its sink hasn't got there when `push` returns,
|
|
30
|
+
* and its test sees it.
|
|
31
|
+
*
|
|
32
|
+
* Returns `{ layer, push }`. Resolve it inside an `Effect.gen`, provide `layer`,
|
|
33
|
+
* and drive the surface with `push`:
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const input = yield* TestInput.pushable()
|
|
37
|
+
* yield* Stream.runForEach(drag(undefined), …).pipe(Effect.fork…) // subscribe
|
|
38
|
+
* yield* input.push(ev("down", 0, 0, 0))
|
|
39
|
+
*
|
|
40
|
+
* Returns `pushFocus` and `pushKey` alongside `push` so focus/blur transitions and keys can be
|
|
41
|
+
* driven on the same schedule; `focus(target)` and `keyboard(target)` mirror `pointer(target)`, each
|
|
42
|
+
* with its own hub.
|
|
43
|
+
*
|
|
44
|
+
* `adoptPointer(target, raw)` takes a pointer event as its `raw`: a pressed one is pushed on
|
|
45
|
+
* the pointer hub as an adopted down, inside the call, as the DOM's is. The hub holds no pointer, so
|
|
46
|
+
* the test pushes that pointer's later events itself.
|
|
47
|
+
*
|
|
48
|
+
* `options.focusWithin` is the source's `focusWithin`, for a test of a **Keyboard press** that
|
|
49
|
+
* holds its keys only while focus is within its target. Without it the source says nothing of focus,
|
|
50
|
+
* and a press hears every key pushed.
|
|
51
|
+
*/
|
|
52
|
+
export declare const pushable: (options?: {
|
|
53
|
+
readonly focusWithin?: ((target: unknown) => boolean) | undefined;
|
|
54
|
+
}) => Effect.Effect<{
|
|
55
|
+
readonly layer: Layer.Layer<InputSource.InputSource>;
|
|
56
|
+
readonly push: (event: InputSource.PointerLikeEvent) => Effect.Effect<void>;
|
|
57
|
+
readonly pushFocus: (event: InputSource.FocusLikeEvent) => Effect.Effect<void>;
|
|
58
|
+
readonly pushKey: (event: InputSource.KeyboardLikeEvent) => Effect.Effect<void>;
|
|
59
|
+
}>;
|
|
60
|
+
//# sourceMappingURL=input.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input.d.ts","sourceRoot":"","sources":["../src/input.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,0BAA0B,CAAA;AAEvD,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAKrC;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,KAAK,mBACD,aAAa,CAAC,WAAW,CAAC,gBAAgB,CAAC,gBAC7C,aAAa,CAAC,WAAW,CAAC,cAAc,CAAC,cAC3C,aAAa,CAAC,WAAW,CAAC,iBAAiB,CAAC,KACtD,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAMlC,CAAA;AAEJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,eAAO,MAAM,QAAQ,aAAc;IAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC,GAAG,SAAS,CAAA;CAAE,KAAG,MAAM,CAAC,MAAM,CAAC;IACvH,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,CAAA;IACpD,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,gBAAgB,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC3E,QAAQ,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC9E,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,iBAAiB,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CAChF,CAwBG,CAAA"}
|
package/dist/input.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import * as InputSource from "@wardic/core/InputSource";
|
|
2
|
+
import * as Bool from "effect/Boolean";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import * as Predicate from "effect/Predicate";
|
|
5
|
+
import * as Layer from "effect/Layer";
|
|
6
|
+
import * as UndefinedOr from "effect/UndefinedOr";
|
|
7
|
+
import * as Option from "effect/Option";
|
|
8
|
+
import * as Feeds from "./feeds.js";
|
|
9
|
+
/**
|
|
10
|
+
* An InputSource that replays fixed scripts of events, as **Input feeds** that end after their
|
|
11
|
+
* script: a Stream over one ends too. `pointer(target)` replays the same `pointerEvents`,
|
|
12
|
+
* `focus(target)` the same `focusEvents` and `keyboard(target)` the same `keyEvents` to each
|
|
13
|
+
* subscriber (each ignores `target` — tests address a single surface). The first positional arg is
|
|
14
|
+
* pointer events for back-compat; focus and key events are optional, defaulting to empty so existing
|
|
15
|
+
* call sites emit nothing on them. Each script plays whole when its feed is subscribed, so scripts of
|
|
16
|
+
* two kinds don't interleave: a test that needs them to pushes them ({@link pushable}). Called with no
|
|
17
|
+
* args it yields an InputSource that emits nothing — for tests that don't exercise gestures. It adopts
|
|
18
|
+
* no pointer: `adoptPointer` delivers nothing.
|
|
19
|
+
*/
|
|
20
|
+
// Input feeds: #318. adoptPointer: #431.
|
|
21
|
+
export const layer = (pointerEvents = [], focusEvents = [], keyEvents = []) => Layer.succeed(InputSource.InputSource, {
|
|
22
|
+
pointer: () => Feeds.script(pointerEvents),
|
|
23
|
+
keyboard: () => Feeds.script(keyEvents),
|
|
24
|
+
focus: () => Feeds.script(focusEvents),
|
|
25
|
+
adoptPointer: () => Option.none(),
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* A push-based InputSource for tests that need to interleave pointer events with
|
|
29
|
+
* other effects (e.g. advancing the Clock between a release and a re-grab). Unlike
|
|
30
|
+
* {@link layer} — which replays a fixed script that drains immediately — this
|
|
31
|
+
* form lets the test `push` events one at a time, on its own schedule.
|
|
32
|
+
*
|
|
33
|
+
* Backed by a hub (`feeds.ts`) so that every subscription to `pointer(target)`
|
|
34
|
+
* hears every event: a consumer may subscribe to `input.pointer(target)` more than once
|
|
35
|
+
* (a binding's drag track reads the drag fold and the grabs). There is no replay buffer,
|
|
36
|
+
* so only events pushed *after* a subscription is live reach it.
|
|
37
|
+
*
|
|
38
|
+
* `push` doesn't yield: a subscriber handles the event inside the push, as an
|
|
39
|
+
* Environment's consumers handle a real event inside its dispatch, so a pipeline that hops
|
|
40
|
+
* through Effect's scheduler on its way to its sink hasn't got there when `push` returns,
|
|
41
|
+
* and its test sees it.
|
|
42
|
+
*
|
|
43
|
+
* Returns `{ layer, push }`. Resolve it inside an `Effect.gen`, provide `layer`,
|
|
44
|
+
* and drive the surface with `push`:
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const input = yield* TestInput.pushable()
|
|
48
|
+
* yield* Stream.runForEach(drag(undefined), …).pipe(Effect.fork…) // subscribe
|
|
49
|
+
* yield* input.push(ev("down", 0, 0, 0))
|
|
50
|
+
*
|
|
51
|
+
* Returns `pushFocus` and `pushKey` alongside `push` so focus/blur transitions and keys can be
|
|
52
|
+
* driven on the same schedule; `focus(target)` and `keyboard(target)` mirror `pointer(target)`, each
|
|
53
|
+
* with its own hub.
|
|
54
|
+
*
|
|
55
|
+
* `adoptPointer(target, raw)` takes a pointer event as its `raw`: a pressed one is pushed on
|
|
56
|
+
* the pointer hub as an adopted down, inside the call, as the DOM's is. The hub holds no pointer, so
|
|
57
|
+
* the test pushes that pointer's later events itself.
|
|
58
|
+
*
|
|
59
|
+
* `options.focusWithin` is the source's `focusWithin`, for a test of a **Keyboard press** that
|
|
60
|
+
* holds its keys only while focus is within its target. Without it the source says nothing of focus,
|
|
61
|
+
* and a press hears every key pushed.
|
|
62
|
+
*/
|
|
63
|
+
// The hub: #318. No yield: ADR-0032. Keys: #427. adoptPointer: #431. focusWithin: #460.
|
|
64
|
+
export const pushable = (options) => Effect.sync(() => {
|
|
65
|
+
const pointer = Feeds.hub();
|
|
66
|
+
const focus = Feeds.hub();
|
|
67
|
+
const keys = Feeds.hub();
|
|
68
|
+
return {
|
|
69
|
+
layer: Layer.succeed(InputSource.InputSource, {
|
|
70
|
+
pointer: () => pointer.feed,
|
|
71
|
+
keyboard: () => keys.feed,
|
|
72
|
+
focus: () => focus.feed,
|
|
73
|
+
focusWithin: UndefinedOr.map(options, (o) => o.focusWithin),
|
|
74
|
+
adoptPointer: (_target, raw) => {
|
|
75
|
+
if (isPressedPointer(raw)) {
|
|
76
|
+
const down = { ...raw, type: "down", adopted: true };
|
|
77
|
+
Effect.runSync(pointer.push(down));
|
|
78
|
+
return Option.some(down);
|
|
79
|
+
}
|
|
80
|
+
return Option.none();
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
push: pointer.push,
|
|
84
|
+
pushFocus: focus.push,
|
|
85
|
+
pushKey: keys.push,
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
/** Whether `raw` is a pointer event with a button pressed: one the pushable InputSource adopts (#431). */
|
|
89
|
+
const isPressedPointer = (raw) => Bool.and(Predicate.hasProperty(raw, "pointerId"), Predicate.hasProperty(raw, "pressed")) && raw.pressed;
|
|
90
|
+
//# sourceMappingURL=input.js.map
|