expressive-charts 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -1
- package/README.md +6 -6
- package/dist/define-DeZLs1h7.js +95 -0
- package/dist/define-DeZLs1h7.js.map +1 -0
- package/dist/drawing-Dz_IvJPB.d.cts +208 -0
- package/dist/drawing-Dz_IvJPB.d.ts +208 -0
- package/dist/effect-CdH5449m.d.ts +232 -0
- package/dist/effect-uYC8Vs6_.d.cts +232 -0
- package/dist/expressive-charts.css +2 -0
- package/dist/expressive-charts.css.d.cts +1 -2
- package/dist/expressive-charts.css.d.ts +1 -2
- package/dist/expressive-charts.global.js +45 -47
- package/dist/expressive-charts.global.js.map +1 -1
- package/dist/icons/sport.cjs +211 -156
- package/dist/icons/sport.cjs.map +1 -1
- package/dist/icons/sport.d.cts +5 -7
- package/dist/icons/sport.d.ts +5 -7
- package/dist/icons/sport.js +122 -71
- package/dist/icons/sport.js.map +1 -1
- package/dist/index.cjs +12632 -9979
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +913 -871
- package/dist/index.d.ts +913 -871
- package/dist/index.js +10444 -8232
- package/dist/index.js.map +1 -1
- package/dist/path-data-DnEckjY8.js +123 -0
- package/dist/path-data-DnEckjY8.js.map +1 -0
- package/dist/testing.cjs +2030 -1252
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +135 -139
- package/dist/testing.d.ts +135 -139
- package/dist/testing.js +696 -499
- package/dist/testing.js.map +1 -1
- package/dist/transition-DSRt2DH3.js +2053 -0
- package/dist/transition-DSRt2DH3.js.map +1 -0
- package/package.json +6 -6
- package/dist/chunk-7A7LXXT4.js +0 -70
- package/dist/chunk-7A7LXXT4.js.map +0 -1
- package/dist/chunk-CJUQHEX6.js +0 -618
- package/dist/chunk-CJUQHEX6.js.map +0 -1
- package/dist/chunk-N2BLUETM.js +0 -1194
- package/dist/chunk-N2BLUETM.js.map +0 -1
- package/dist/drawing-CdTgixMY.d.cts +0 -206
- package/dist/drawing-CdTgixMY.d.ts +0 -206
- package/dist/effect-Bu3MHHeg.d.ts +0 -247
- package/dist/effect-D4vmdYP4.d.cts +0 -247
package/dist/testing.js
CHANGED
|
@@ -1,570 +1,767 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createMotion,
|
|
3
|
-
describeValue,
|
|
4
|
-
isMarkEffect,
|
|
5
|
-
isTransitionEffect,
|
|
6
|
-
manualClock,
|
|
7
|
-
mergeFields,
|
|
8
|
-
runScope
|
|
9
|
-
} from "./chunk-N2BLUETM.js";
|
|
10
|
-
import {
|
|
11
|
-
describe
|
|
12
|
-
} from "./chunk-CJUQHEX6.js";
|
|
13
|
-
|
|
1
|
+
import { C as createMotion, P as manualClock, a as mergeFields, c as describeValue, d as describe, i as runScope, l as isMarkEffect, t as isTransitionEffect } from "./transition-DSRt2DH3.js";
|
|
14
2
|
// src/core/testing/recording.ts
|
|
15
3
|
function recordingLayer() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
4
|
+
const drawn = /* @__PURE__ */ new Map();
|
|
5
|
+
const calls = [];
|
|
6
|
+
let nextId = 1;
|
|
7
|
+
const replace = (id, next) => {
|
|
8
|
+
const current = drawn.get(id);
|
|
9
|
+
if (current) drawn.set(id, next(current));
|
|
10
|
+
};
|
|
11
|
+
const remove = (id) => {
|
|
12
|
+
calls.push({
|
|
13
|
+
op: "remove",
|
|
14
|
+
id
|
|
15
|
+
});
|
|
16
|
+
drawn.delete(id);
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
get drawn() {
|
|
20
|
+
return [...drawn.values()];
|
|
21
|
+
},
|
|
22
|
+
get calls() {
|
|
23
|
+
return calls;
|
|
24
|
+
},
|
|
25
|
+
icon(icon, options) {
|
|
26
|
+
const id = nextId++;
|
|
27
|
+
const size = options?.size;
|
|
28
|
+
calls.push({
|
|
29
|
+
op: "icon",
|
|
30
|
+
id,
|
|
31
|
+
icon: icon.name,
|
|
32
|
+
size
|
|
33
|
+
});
|
|
34
|
+
drawn.set(id, {
|
|
35
|
+
kind: "icon",
|
|
36
|
+
id,
|
|
37
|
+
icon,
|
|
38
|
+
size,
|
|
39
|
+
transform: void 0
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
place(transform) {
|
|
43
|
+
calls.push({
|
|
44
|
+
op: "place",
|
|
45
|
+
id,
|
|
46
|
+
transform
|
|
47
|
+
});
|
|
48
|
+
replace(id, (current) => ({
|
|
49
|
+
...current,
|
|
50
|
+
transform
|
|
51
|
+
}));
|
|
52
|
+
},
|
|
53
|
+
remove: () => remove(id)
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
path(d, paint) {
|
|
57
|
+
const id = nextId++;
|
|
58
|
+
calls.push({
|
|
59
|
+
op: "path",
|
|
60
|
+
id,
|
|
61
|
+
d,
|
|
62
|
+
paint
|
|
63
|
+
});
|
|
64
|
+
drawn.set(id, {
|
|
65
|
+
kind: "path",
|
|
66
|
+
id,
|
|
67
|
+
d,
|
|
68
|
+
paint: { ...paint }
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
update(nextD, nextPaint) {
|
|
72
|
+
calls.push({
|
|
73
|
+
op: "update-path",
|
|
74
|
+
id,
|
|
75
|
+
d: nextD,
|
|
76
|
+
paint: nextPaint
|
|
77
|
+
});
|
|
78
|
+
replace(id, (current) => {
|
|
79
|
+
const path = current;
|
|
80
|
+
return {
|
|
81
|
+
...path,
|
|
82
|
+
d: nextD,
|
|
83
|
+
paint: mergeFields(path.paint, nextPaint)
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
},
|
|
87
|
+
remove: () => remove(id)
|
|
88
|
+
};
|
|
89
|
+
},
|
|
90
|
+
text(content, style) {
|
|
91
|
+
const id = nextId++;
|
|
92
|
+
calls.push({
|
|
93
|
+
op: "text",
|
|
94
|
+
id,
|
|
95
|
+
content,
|
|
96
|
+
style
|
|
97
|
+
});
|
|
98
|
+
drawn.set(id, {
|
|
99
|
+
kind: "text",
|
|
100
|
+
id,
|
|
101
|
+
content,
|
|
102
|
+
style: { ...style }
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
update(nextStyle, nextContent) {
|
|
106
|
+
calls.push({
|
|
107
|
+
op: "update-text",
|
|
108
|
+
id,
|
|
109
|
+
style: nextStyle,
|
|
110
|
+
content: nextContent
|
|
111
|
+
});
|
|
112
|
+
replace(id, (current) => {
|
|
113
|
+
const text = current;
|
|
114
|
+
return {
|
|
115
|
+
...text,
|
|
116
|
+
style: mergeFields(text.style, nextStyle),
|
|
117
|
+
content: nextContent ?? text.content
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
remove: () => remove(id)
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
picture(decimals = 3) {
|
|
125
|
+
const round = rounder(decimals);
|
|
126
|
+
return [...drawn.values()].map((item) => {
|
|
127
|
+
switch (item.kind) {
|
|
128
|
+
case "icon": return {
|
|
129
|
+
kind: "icon",
|
|
130
|
+
icon: item.icon.name,
|
|
131
|
+
size: item.size,
|
|
132
|
+
transform: item.transform?.map(round)
|
|
133
|
+
};
|
|
134
|
+
case "path": return {
|
|
135
|
+
kind: "path",
|
|
136
|
+
d: item.d,
|
|
137
|
+
paint: roundFields(item.paint, round)
|
|
138
|
+
};
|
|
139
|
+
case "text": return {
|
|
140
|
+
kind: "text",
|
|
141
|
+
content: item.content,
|
|
142
|
+
style: {
|
|
143
|
+
...roundFields(item.style, round),
|
|
144
|
+
at: {
|
|
145
|
+
x: round(item.style.at.x),
|
|
146
|
+
y: round(item.style.at.y)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
clear() {
|
|
154
|
+
calls.push({ op: "clear" });
|
|
155
|
+
drawn.clear();
|
|
156
|
+
}
|
|
157
|
+
};
|
|
98
158
|
}
|
|
99
159
|
function recordingMark() {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
160
|
+
let style = {};
|
|
161
|
+
const calls = [];
|
|
162
|
+
return {
|
|
163
|
+
get style() {
|
|
164
|
+
return style;
|
|
165
|
+
},
|
|
166
|
+
get calls() {
|
|
167
|
+
return calls;
|
|
168
|
+
},
|
|
169
|
+
set(next) {
|
|
170
|
+
calls.push({
|
|
171
|
+
op: "set",
|
|
172
|
+
style: next
|
|
173
|
+
});
|
|
174
|
+
style = mergeFields(style, next);
|
|
175
|
+
},
|
|
176
|
+
reset() {
|
|
177
|
+
calls.push({ op: "reset" });
|
|
178
|
+
style = {};
|
|
179
|
+
}
|
|
180
|
+
};
|
|
118
181
|
}
|
|
119
182
|
function rounder(decimals) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
183
|
+
const factor = 10 ** decimals;
|
|
184
|
+
return (value) => {
|
|
185
|
+
const rounded = Math.round(value * factor) / factor;
|
|
186
|
+
return rounded === 0 ? 0 : rounded;
|
|
187
|
+
};
|
|
125
188
|
}
|
|
126
189
|
function roundFields(fields, round) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
190
|
+
const result = {};
|
|
191
|
+
for (const [field, value] of Object.entries(fields)) result[field] = typeof value === "number" ? round(value) : value;
|
|
192
|
+
return result;
|
|
130
193
|
}
|
|
131
|
-
|
|
132
194
|
// src/core/testing/context.ts
|
|
133
195
|
function testContext(options = {}) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
196
|
+
const clock = manualClock();
|
|
197
|
+
const motion = createMotion({
|
|
198
|
+
mode: options.mode ?? "presentation",
|
|
199
|
+
...options.scaling ? { scaling: options.scaling } : {},
|
|
200
|
+
reducedMotion: {
|
|
201
|
+
matches: false,
|
|
202
|
+
subscribe: () => () => {}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
const layer = recordingLayer();
|
|
206
|
+
const mark = recordingMark();
|
|
207
|
+
const icons = new Map((options.icons ?? []).map((icon) => [icon.name, icon]));
|
|
208
|
+
const scope = runScope({
|
|
209
|
+
clock,
|
|
210
|
+
motion,
|
|
211
|
+
layer,
|
|
212
|
+
mark,
|
|
213
|
+
icons: { get: (name) => icons.get(name) },
|
|
214
|
+
batch: options.batch ?? {
|
|
215
|
+
index: 0,
|
|
216
|
+
count: 1
|
|
217
|
+
},
|
|
218
|
+
previous: options.previous
|
|
219
|
+
});
|
|
220
|
+
return {
|
|
221
|
+
...scope.context,
|
|
222
|
+
motion,
|
|
223
|
+
clock,
|
|
224
|
+
layer,
|
|
225
|
+
mark,
|
|
226
|
+
abort: scope.abort,
|
|
227
|
+
clear: scope.clear,
|
|
228
|
+
change: scope.change
|
|
229
|
+
};
|
|
163
230
|
}
|
|
164
|
-
|
|
165
231
|
// src/core/testing/play.ts
|
|
166
232
|
async function play(clock, running, options = {}) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
await flush();
|
|
181
|
-
}
|
|
182
|
-
return elapsed;
|
|
233
|
+
const frame = options.frame ?? 16;
|
|
234
|
+
const limit = options.limit ?? 1e4;
|
|
235
|
+
let settled = false;
|
|
236
|
+
running.then(() => settled = true, () => settled = true);
|
|
237
|
+
let elapsed = 0;
|
|
238
|
+
await flush();
|
|
239
|
+
while (!settled) {
|
|
240
|
+
if (elapsed >= limit) throw new Error(`play: still running after ${limit} ms.`);
|
|
241
|
+
clock.advance(frame);
|
|
242
|
+
elapsed += frame;
|
|
243
|
+
await flush();
|
|
244
|
+
}
|
|
245
|
+
return elapsed;
|
|
183
246
|
}
|
|
184
247
|
async function flush() {
|
|
185
|
-
|
|
248
|
+
for (let i = 0; i < 20; i++) await Promise.resolve();
|
|
186
249
|
}
|
|
187
|
-
|
|
188
250
|
// src/testing/fixtures.ts
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
251
|
+
const fixtures = /* @__PURE__ */ makeFixtures(false);
|
|
252
|
+
const movedFixtures = /* @__PURE__ */ makeFixtures(true);
|
|
253
|
+
const fixturePairs = /* @__PURE__ */ Object.freeze({
|
|
254
|
+
"slice and column": [fixtures.slice, fixtures.column],
|
|
255
|
+
"bar and column": [fixtures.bar, fixtures.column],
|
|
256
|
+
"two slices": [fixtures.slice, movedFixtures.slice],
|
|
257
|
+
"two lines": [fixtures.line, movedFixtures.line],
|
|
258
|
+
"two points": [fixtures.point, movedFixtures.point]
|
|
197
259
|
});
|
|
198
260
|
function makeFixtures(moved) {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
261
|
+
const y = moved ? 30 : 0;
|
|
262
|
+
const bar = (width, more = {}) => describe.bar({
|
|
263
|
+
key: "Okafor",
|
|
264
|
+
series: "goals",
|
|
265
|
+
x: 0,
|
|
266
|
+
y,
|
|
267
|
+
width,
|
|
268
|
+
height: 20,
|
|
269
|
+
baseline: "left",
|
|
270
|
+
...more
|
|
271
|
+
});
|
|
272
|
+
const [goals, assists] = moved ? [120, 82] : [160, 62];
|
|
273
|
+
const points = moved ? [
|
|
274
|
+
{
|
|
275
|
+
x: 0,
|
|
276
|
+
y: 90
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
x: 64,
|
|
280
|
+
y: 58
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
x: 128,
|
|
284
|
+
y: 82
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
x: 192,
|
|
288
|
+
y: 26
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
x: 256,
|
|
292
|
+
y: 40
|
|
293
|
+
}
|
|
294
|
+
] : [
|
|
295
|
+
{
|
|
296
|
+
x: 0,
|
|
297
|
+
y: 100
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
x: 80,
|
|
301
|
+
y: 60
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
x: 160,
|
|
305
|
+
y: 90
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
x: 240,
|
|
309
|
+
y: 20
|
|
310
|
+
}
|
|
311
|
+
];
|
|
312
|
+
return Object.freeze({
|
|
313
|
+
bar: bar(moved ? 160 : 200, { radius: 4 }),
|
|
314
|
+
"negative bar": describe.bar({
|
|
315
|
+
key: "n",
|
|
316
|
+
series: "goals",
|
|
317
|
+
x: moved ? 30 : 0,
|
|
318
|
+
y,
|
|
319
|
+
width: moved ? 90 : 120,
|
|
320
|
+
height: 20,
|
|
321
|
+
baseline: "right"
|
|
322
|
+
}),
|
|
323
|
+
column: describe.bar({
|
|
324
|
+
key: "c",
|
|
325
|
+
series: "goals",
|
|
326
|
+
x: moved ? 30 : 0,
|
|
327
|
+
y: moved ? 40 : 0,
|
|
328
|
+
width: 20,
|
|
329
|
+
height: moved ? 110 : 150,
|
|
330
|
+
baseline: "bottom"
|
|
331
|
+
}),
|
|
332
|
+
stacked: bar(goals + assists, {
|
|
333
|
+
series: void 0,
|
|
334
|
+
gap: 2,
|
|
335
|
+
segments: [{
|
|
336
|
+
series: "goals",
|
|
337
|
+
size: goals
|
|
338
|
+
}, {
|
|
339
|
+
series: "assists",
|
|
340
|
+
size: assists
|
|
341
|
+
}]
|
|
342
|
+
}),
|
|
343
|
+
"short bar": bar(moved ? 4 : 6),
|
|
344
|
+
slice: moved ? describe.arc({
|
|
345
|
+
key: "Saved",
|
|
346
|
+
cx: 140,
|
|
347
|
+
cy: 130,
|
|
348
|
+
inner: 60,
|
|
349
|
+
outer: 100,
|
|
350
|
+
start: .5,
|
|
351
|
+
end: 2
|
|
352
|
+
}) : describe.arc({
|
|
353
|
+
key: "Saved",
|
|
354
|
+
cx: 150,
|
|
355
|
+
cy: 150,
|
|
356
|
+
inner: 70,
|
|
357
|
+
outer: 116,
|
|
358
|
+
start: .3,
|
|
359
|
+
end: 2.4
|
|
360
|
+
}),
|
|
361
|
+
line: describe.line({
|
|
362
|
+
key: "goals",
|
|
363
|
+
series: "goals",
|
|
364
|
+
points,
|
|
365
|
+
width: 2
|
|
366
|
+
}),
|
|
367
|
+
"gapped line": describe.line({
|
|
368
|
+
key: "goals",
|
|
369
|
+
series: "goals",
|
|
370
|
+
points,
|
|
371
|
+
breaks: [2],
|
|
372
|
+
width: 2
|
|
373
|
+
}),
|
|
374
|
+
point: describe.point({
|
|
375
|
+
key: "p",
|
|
376
|
+
x: moved ? 40 : 10,
|
|
377
|
+
y: moved ? 25 : 10,
|
|
378
|
+
r: 3
|
|
379
|
+
})
|
|
380
|
+
});
|
|
215
381
|
}
|
|
216
|
-
|
|
217
382
|
// src/testing/check.ts
|
|
218
383
|
async function checkEffect(effect, options = {}) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
${list(failures)}`);
|
|
384
|
+
if (!isMarkEffect(effect)) {
|
|
385
|
+
const hint = isTransitionEffect(effect) ? "; check it with checkTransition" : "";
|
|
386
|
+
throw new TypeError(`checkEffect needs a mark effect (kind "geometry" or "data"), got ${describeValue(effect)}${hint}.`);
|
|
387
|
+
}
|
|
388
|
+
const name = options.name ?? "the effect";
|
|
389
|
+
const related = effect.kind === "data" ? effect.needs?.related ?? [] : [];
|
|
390
|
+
if (related.length > 0 && !options.data) throw new TypeError(`checkEffect: ${name} needs the related series ${related.map((s) => `"${s}"`).join(", ")}, so pass data(mark) with them: the default data has no related series.`);
|
|
391
|
+
const marks = named(options.marks ?? fixtures);
|
|
392
|
+
if (marks.length === 0) throw new TypeError("checkEffect: there are no marks to check on.");
|
|
393
|
+
const dataOf = (mark) => effect.kind === "data" ? (options.data ?? defaultData)(mark) : void 0;
|
|
394
|
+
const failures = [];
|
|
395
|
+
for (const [markName, mark] of marks) {
|
|
396
|
+
let data;
|
|
397
|
+
try {
|
|
398
|
+
data = dataOf(mark);
|
|
399
|
+
} catch (error) {
|
|
400
|
+
failures.push(`on ${markName}: data(mark) threw ${describeError(error)}`);
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
let moved;
|
|
404
|
+
try {
|
|
405
|
+
moved = movedSubject(effect, (options.moved ?? movedFixture)(mark), dataOf);
|
|
406
|
+
} catch (error) {
|
|
407
|
+
failures.push(`on ${markName}: the moved mark, or its data, threw ${describeError(error)}`);
|
|
408
|
+
}
|
|
409
|
+
const subject = {
|
|
410
|
+
context: (more = {}) => testContext({
|
|
411
|
+
icons: options.icons,
|
|
412
|
+
batch: options.batch,
|
|
413
|
+
...more
|
|
414
|
+
}),
|
|
415
|
+
run: (ctx) => promised(effect.kind === "data" ? effect.run(mark, data, ctx) : effect.run(mark, ctx)),
|
|
416
|
+
end: (ctx) => effect.kind === "data" ? effect.end(mark, data, ctx) : effect.end(mark, ctx),
|
|
417
|
+
clear: (ctx) => effect.clear(ctx),
|
|
418
|
+
moved
|
|
419
|
+
};
|
|
420
|
+
for (const check of CHECKS) {
|
|
421
|
+
const problem = await attempt(check, subject);
|
|
422
|
+
if (problem) failures.push(`on ${markName}, ${check.title}: ${problem}`);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (failures.length > 0) throw new Error(`checkEffect found ${problems(failures)} with ${name}:\n${list(failures)}`);
|
|
262
426
|
}
|
|
263
|
-
|
|
427
|
+
const RETRACE_AT = [
|
|
428
|
+
.25,
|
|
429
|
+
.5,
|
|
430
|
+
.75
|
|
431
|
+
];
|
|
264
432
|
async function checkTransition(effect, options = {}) {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
433
|
+
if (!isTransitionEffect(effect)) {
|
|
434
|
+
const hint = isMarkEffect(effect) ? "; check it with checkEffect" : "";
|
|
435
|
+
throw new TypeError(`checkTransition needs a transition effect (kind "transition" with run, end and clear), got ${describeTransition(effect)}${hint}.`);
|
|
436
|
+
}
|
|
437
|
+
const name = options.name ?? "the effect";
|
|
438
|
+
const pairs = namedPairs(options.pairs ?? fixturePairs);
|
|
439
|
+
if (pairs.length === 0) throw new TypeError("checkTransition: there are no pairs to check on.");
|
|
440
|
+
const failures = [];
|
|
441
|
+
for (const [pairName, [a, b]] of pairs) {
|
|
442
|
+
for (const [way, from, to] of [[
|
|
443
|
+
"a to b",
|
|
444
|
+
a,
|
|
445
|
+
b
|
|
446
|
+
], [
|
|
447
|
+
"b to a",
|
|
448
|
+
b,
|
|
449
|
+
a
|
|
450
|
+
]]) {
|
|
451
|
+
for (const check of COMMON) {
|
|
452
|
+
const problem = await attempt(check, transitionSubject(effect, from, to, 0, options.icons));
|
|
453
|
+
if (problem) failures.push(`on ${pairName}, ${way}, ${check.title}: ${problem}`);
|
|
454
|
+
}
|
|
455
|
+
const problem = await attempt(FULL_RUN, transitionSubject(effect, from, to, .5, options.icons));
|
|
456
|
+
if (problem) failures.push(`on ${pairName}, ${way}, a run from start: 0.5 should end with the same picture as end(): ${problem}`);
|
|
457
|
+
}
|
|
458
|
+
let problem;
|
|
459
|
+
try {
|
|
460
|
+
problem = await retraces(effect, a, b, options.icons);
|
|
461
|
+
} catch (error) {
|
|
462
|
+
problem = `it threw ${describeError(error)}`;
|
|
463
|
+
}
|
|
464
|
+
if (problem) failures.push(`on ${pairName}, a run back should retrace the run forward: ${problem}`);
|
|
465
|
+
}
|
|
466
|
+
if (failures.length > 0) throw new Error(`checkTransition found ${problems(failures)} with ${name}:\n${list(failures)}`);
|
|
292
467
|
}
|
|
293
468
|
function transitionContext(start, options) {
|
|
294
|
-
|
|
469
|
+
return {
|
|
470
|
+
...testContext(options),
|
|
471
|
+
start
|
|
472
|
+
};
|
|
295
473
|
}
|
|
296
474
|
function transitionSubject(effect, from, to, start, icons) {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
475
|
+
return {
|
|
476
|
+
context: (more = {}) => transitionContext(start, {
|
|
477
|
+
icons,
|
|
478
|
+
...more
|
|
479
|
+
}),
|
|
480
|
+
run: (ctx) => promised(effect.run(from, to, ctx)),
|
|
481
|
+
end: (ctx) => effect.end(from, to, ctx),
|
|
482
|
+
clear: (ctx) => effect.clear(ctx),
|
|
483
|
+
moved: void 0
|
|
484
|
+
};
|
|
304
485
|
}
|
|
305
486
|
async function opening(effect, from, to, start, icons) {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
487
|
+
const ctx = transitionContext(start, { icons });
|
|
488
|
+
const run = track(promised(effect.run(from, to, ctx)));
|
|
489
|
+
await flush();
|
|
490
|
+
const picture = ctx.layer.picture();
|
|
491
|
+
ctx.abort();
|
|
492
|
+
await settle(run);
|
|
493
|
+
effect.clear(ctx);
|
|
494
|
+
ctx.clear();
|
|
495
|
+
if (run.failed) throw run.error;
|
|
496
|
+
return picture;
|
|
316
497
|
}
|
|
317
498
|
async function retraces(effect, a, b, icons) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return void 0;
|
|
499
|
+
for (const p of RETRACE_AT) {
|
|
500
|
+
const forward = await opening(effect, a, b, p, icons);
|
|
501
|
+
const back = await opening(effect, b, a, 1 - p, icons);
|
|
502
|
+
if (same(back, forward)) continue;
|
|
503
|
+
const index = back.findIndex((item, i) => !same(item, forward[i]));
|
|
504
|
+
const what = back.length !== forward.length ? `${back.length} ${back.length === 1 ? "item" : "items"} (${show(back)}) where the run from a to b from start: ${p} begins with ${forward.length} (${show(forward)})` : `item ${index + 1} unlike the run from a to b from start: ${p}: ${difference(back[index], forward[index])}`;
|
|
505
|
+
return `the run from b to a from start: ${1 - p} begins with ${what}`;
|
|
506
|
+
}
|
|
327
507
|
}
|
|
328
508
|
function difference(actual, expected) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
509
|
+
if (typeof actual !== "object" || typeof expected !== "object" || actual === null || expected === null) return `${show(actual)}, not ${show(expected)}`;
|
|
510
|
+
const a = actual;
|
|
511
|
+
const b = expected;
|
|
512
|
+
for (const field of /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])) {
|
|
513
|
+
const x = a[field];
|
|
514
|
+
const y = b[field];
|
|
515
|
+
if (same(x, y)) continue;
|
|
516
|
+
if (typeof x !== "string" || typeof y !== "string") return `its ${field} is ${show(x)}, not ${show(y)}`;
|
|
517
|
+
let at = 0;
|
|
518
|
+
while (at < x.length && x[at] === y[at]) at++;
|
|
519
|
+
const from = Math.max(0, at - 24);
|
|
520
|
+
const part = (text) => `${from > 0 ? "…" : ""}${text.slice(from, at + 24)}${at + 24 < text.length ? "…" : ""}`;
|
|
521
|
+
return `its ${field} parts at character ${at + 1}: ${JSON.stringify(part(x))}, not ${JSON.stringify(part(y))}`;
|
|
522
|
+
}
|
|
523
|
+
return `${show(actual)}, not ${show(expected)}`;
|
|
344
524
|
}
|
|
345
525
|
function namedPairs(pairs) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
526
|
+
if (!Array.isArray(pairs)) return Object.entries(pairs).map(([name, pair]) => [`the ${name}`, pair]);
|
|
527
|
+
return pairs.map((pair, i) => {
|
|
528
|
+
const [a, b] = pair;
|
|
529
|
+
const keys = a?.key === b?.key ? `"${String(a?.key)}"` : `"${String(a?.key)}" and "${String(b?.key)}"`;
|
|
530
|
+
return [`pair ${i + 1} (${keys})`, pair];
|
|
531
|
+
});
|
|
352
532
|
}
|
|
353
533
|
function describeTransition(value) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
534
|
+
if (typeof value !== "object" || value === null) return value === null ? "null" : typeof value;
|
|
535
|
+
const kind = value.kind;
|
|
536
|
+
if (kind === "geometry" || kind === "data") return `a ${kind} effect, which plays on one mark`;
|
|
537
|
+
if (kind === "transition") return "a transition effect without run(), end() and clear()";
|
|
538
|
+
return kind === void 0 ? "an object with no kind" : `an effect of kind ${JSON.stringify(kind)}`;
|
|
359
539
|
}
|
|
360
540
|
async function attempt(check, subject) {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
541
|
+
try {
|
|
542
|
+
return await check.test(subject);
|
|
543
|
+
} catch (error) {
|
|
544
|
+
return `it threw ${describeError(error)}`;
|
|
545
|
+
}
|
|
366
546
|
}
|
|
367
547
|
function promised(running) {
|
|
368
|
-
|
|
369
|
-
|
|
548
|
+
if (typeof running?.then !== "function") throw new TypeError(`run() must return a promise, got ${describeValue(running)}.`);
|
|
549
|
+
return running;
|
|
370
550
|
}
|
|
371
|
-
|
|
372
|
-
|
|
551
|
+
const problems = (failures) => failures.length === 1 ? "1 problem" : `${failures.length} problems`;
|
|
552
|
+
const list = (failures) => failures.map((failure) => `- ${failure}`).join("\n");
|
|
373
553
|
function movedFixture(mark) {
|
|
374
|
-
|
|
375
|
-
|
|
554
|
+
const name = Object.keys(fixtures).find((fixture) => fixtures[fixture] === mark);
|
|
555
|
+
return name === void 0 ? void 0 : movedFixtures[name];
|
|
376
556
|
}
|
|
377
557
|
function movedSubject(effect, mark, dataOf) {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
558
|
+
if (mark === void 0) return void 0;
|
|
559
|
+
const data = dataOf(mark);
|
|
560
|
+
return {
|
|
561
|
+
change: (ctx) => ctx.change(mark, data),
|
|
562
|
+
end: (ctx) => effect.kind === "data" ? effect.end(mark, data, ctx) : effect.end(mark, ctx)
|
|
563
|
+
};
|
|
384
564
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
565
|
+
const FULL_RUN = {
|
|
566
|
+
title: "a full run should end with the same picture and mark style as end()",
|
|
567
|
+
async test(subject) {
|
|
568
|
+
const ran = subject.context();
|
|
569
|
+
const run = track(subject.run(ran));
|
|
570
|
+
await play(ran.clock, run.done);
|
|
571
|
+
if (run.failed) return `run() rejected with ${describeError(run.error)}`;
|
|
572
|
+
const ended = subject.context();
|
|
573
|
+
subject.end(ended);
|
|
574
|
+
return compare(ran, ended, "after the run");
|
|
575
|
+
}
|
|
396
576
|
};
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
];
|
|
444
|
-
var CHECKS = [
|
|
445
|
-
...COMMON,
|
|
446
|
-
{
|
|
447
|
-
title: "a change() to the moved mark should leave what end() draws on it",
|
|
448
|
-
async test(subject) {
|
|
449
|
-
const { moved } = subject;
|
|
450
|
-
if (!moved) return void 0;
|
|
451
|
-
const problems2 = [];
|
|
452
|
-
const ran = subject.context();
|
|
453
|
-
const run = track(subject.run(ran));
|
|
454
|
-
await play(ran.clock, run.done);
|
|
455
|
-
if (run.failed) return `run() rejected with ${describeError(run.error)}`;
|
|
456
|
-
moved.change(ran);
|
|
457
|
-
if (!await finish(ran)) return "it was still animating 10 s after the change()";
|
|
458
|
-
const ended = subject.context();
|
|
459
|
-
moved.end(ended);
|
|
460
|
-
const afterRun = compare(ran, ended, "after a full run and a change()");
|
|
461
|
-
if (afterRun) problems2.push(afterRun);
|
|
462
|
-
const still = subject.context({ mode: "off" });
|
|
463
|
-
subject.end(still);
|
|
464
|
-
moved.change(still);
|
|
465
|
-
await flush();
|
|
466
|
-
const endedOff = subject.context({ mode: "off" });
|
|
467
|
-
moved.end(endedOff);
|
|
468
|
-
const afterEnd = compare(still, endedOff, "after end() and a change()");
|
|
469
|
-
if (afterEnd) problems2.push(afterEnd);
|
|
470
|
-
return problems2.length > 0 ? problems2.join("; ") : void 0;
|
|
471
|
-
}
|
|
472
|
-
}
|
|
577
|
+
const COMMON = [
|
|
578
|
+
FULL_RUN,
|
|
579
|
+
{
|
|
580
|
+
title: "clearing should leave nothing behind",
|
|
581
|
+
async test(subject) {
|
|
582
|
+
const ctx = subject.context();
|
|
583
|
+
const run = track(subject.run(ctx));
|
|
584
|
+
await play(ctx.clock, run.done);
|
|
585
|
+
subject.clear(ctx);
|
|
586
|
+
ctx.clear();
|
|
587
|
+
ctx.clock.advance(48);
|
|
588
|
+
await flush();
|
|
589
|
+
return leftovers(ctx);
|
|
590
|
+
}
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
title: "an abort mid-run should settle the run and clear to nothing",
|
|
594
|
+
async test(subject) {
|
|
595
|
+
const ctx = subject.context();
|
|
596
|
+
const run = track(subject.run(ctx));
|
|
597
|
+
ctx.clock.advance(16);
|
|
598
|
+
ctx.clock.advance(16);
|
|
599
|
+
ctx.abort();
|
|
600
|
+
await settle(run);
|
|
601
|
+
if (!run.settled) return "run() was still running after the abort; it should resolve once ctx.signal aborts, without more frames";
|
|
602
|
+
if (run.failed) return `run() rejected with ${describeError(run.error)} (it should resolve, aborted or not)`;
|
|
603
|
+
subject.clear(ctx);
|
|
604
|
+
ctx.clear();
|
|
605
|
+
return leftovers(ctx);
|
|
606
|
+
}
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
title: "with motion off, no frames should run and the end state should be drawn",
|
|
610
|
+
async test(subject) {
|
|
611
|
+
const ctx = subject.context({ mode: "off" });
|
|
612
|
+
const run = track(subject.run(ctx));
|
|
613
|
+
const framesAtStart = !ctx.clock.idle;
|
|
614
|
+
await settle(run);
|
|
615
|
+
if (!run.settled) return "run() didn't finish; with motion off ctx.tween() ends at once, so wait only through it, never on a timer";
|
|
616
|
+
if (run.failed) return `run() rejected with ${describeError(run.error)}`;
|
|
617
|
+
if (framesAtStart || !ctx.clock.idle) return "it asked for animation frames";
|
|
618
|
+
const ended = subject.context({ mode: "off" });
|
|
619
|
+
subject.end(ended);
|
|
620
|
+
return compare(ctx, ended, "after the run with motion off");
|
|
621
|
+
}
|
|
622
|
+
}
|
|
473
623
|
];
|
|
624
|
+
const CHECKS = [...COMMON, {
|
|
625
|
+
title: "a change() to the moved mark should leave what end() draws on it",
|
|
626
|
+
async test(subject) {
|
|
627
|
+
const { moved } = subject;
|
|
628
|
+
if (!moved) return void 0;
|
|
629
|
+
const problems = [];
|
|
630
|
+
const ran = subject.context();
|
|
631
|
+
const run = track(subject.run(ran));
|
|
632
|
+
await play(ran.clock, run.done);
|
|
633
|
+
if (run.failed) return `run() rejected with ${describeError(run.error)}`;
|
|
634
|
+
moved.change(ran);
|
|
635
|
+
if (!await finish(ran)) return "it was still animating 10 s after the change()";
|
|
636
|
+
const ended = subject.context();
|
|
637
|
+
moved.end(ended);
|
|
638
|
+
const afterRun = compare(ran, ended, "after a full run and a change()");
|
|
639
|
+
if (afterRun) problems.push(afterRun);
|
|
640
|
+
const still = subject.context({ mode: "off" });
|
|
641
|
+
subject.end(still);
|
|
642
|
+
moved.change(still);
|
|
643
|
+
await flush();
|
|
644
|
+
const endedOff = subject.context({ mode: "off" });
|
|
645
|
+
moved.end(endedOff);
|
|
646
|
+
const afterEnd = compare(still, endedOff, "after end() and a change()");
|
|
647
|
+
if (afterEnd) problems.push(afterEnd);
|
|
648
|
+
return problems.length > 0 ? problems.join("; ") : void 0;
|
|
649
|
+
}
|
|
650
|
+
}];
|
|
474
651
|
async function finish(ctx) {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
652
|
+
await flush();
|
|
653
|
+
for (let elapsed = 0; !ctx.clock.idle; elapsed += 16) {
|
|
654
|
+
if (elapsed >= 1e4) return false;
|
|
655
|
+
ctx.clock.advance(16);
|
|
656
|
+
await flush();
|
|
657
|
+
}
|
|
658
|
+
return true;
|
|
482
659
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
660
|
+
const defaultData = (mark) => {
|
|
661
|
+
const samples = [{
|
|
662
|
+
t: 0,
|
|
663
|
+
value: 0
|
|
664
|
+
}];
|
|
665
|
+
const add = (t, gapBefore) => {
|
|
666
|
+
const last = samples[samples.length - 1];
|
|
667
|
+
if (t === last.t) samples[samples.length - 1] = gapBefore ? {
|
|
668
|
+
...last,
|
|
669
|
+
gapBefore
|
|
670
|
+
} : last;
|
|
671
|
+
else samples.push(gapBefore ? {
|
|
672
|
+
t,
|
|
673
|
+
value: t,
|
|
674
|
+
gapBefore
|
|
675
|
+
} : {
|
|
676
|
+
t,
|
|
677
|
+
value: t
|
|
678
|
+
});
|
|
679
|
+
};
|
|
680
|
+
for (const [from, to] of mark.gaps ?? []) {
|
|
681
|
+
add(from, false);
|
|
682
|
+
add(to, true);
|
|
683
|
+
}
|
|
684
|
+
add(1, false);
|
|
685
|
+
return {
|
|
686
|
+
datum: void 0,
|
|
687
|
+
samples,
|
|
688
|
+
related: () => void 0
|
|
689
|
+
};
|
|
690
|
+
};
|
|
491
691
|
function named(marks) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
692
|
+
if (!Array.isArray(marks)) return Object.entries(marks).map(([name, mark]) => [`the ${name}`, mark]);
|
|
693
|
+
const seen = /* @__PURE__ */ new Map();
|
|
694
|
+
return marks.map((mark) => {
|
|
695
|
+
const count = (seen.get(mark.key) ?? 0) + 1;
|
|
696
|
+
seen.set(mark.key, count);
|
|
697
|
+
return [`mark "${mark.key}"${count > 1 ? ` (${count})` : ""}`, mark];
|
|
698
|
+
});
|
|
499
699
|
}
|
|
500
700
|
function track(running) {
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
701
|
+
const state = {
|
|
702
|
+
settled: false,
|
|
703
|
+
failed: false,
|
|
704
|
+
error: void 0
|
|
705
|
+
};
|
|
706
|
+
const done = running.then(() => {
|
|
707
|
+
state.settled = true;
|
|
708
|
+
}, (error) => {
|
|
709
|
+
Object.assign(state, {
|
|
710
|
+
settled: true,
|
|
711
|
+
failed: true,
|
|
712
|
+
error
|
|
713
|
+
});
|
|
714
|
+
});
|
|
715
|
+
return Object.assign(state, { done });
|
|
511
716
|
}
|
|
512
717
|
async function settle(run) {
|
|
513
|
-
|
|
718
|
+
for (let i = 0; i < 10 && !run.settled; i++) await flush();
|
|
514
719
|
}
|
|
515
720
|
function compare(actual, expected, when) {
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
if (!same(style, wantedStyle)) problems2.push(`the mark's style ${when} is ${show(style)} but end() leaves ${show(wantedStyle)}`);
|
|
528
|
-
return problems2.length > 0 ? problems2.join("; ") : void 0;
|
|
721
|
+
const problems = [];
|
|
722
|
+
const drawn = actual.layer.picture();
|
|
723
|
+
const wanted = expected.layer.picture();
|
|
724
|
+
if (!same(drawn, wanted)) {
|
|
725
|
+
const index = drawn.findIndex((item, i) => !same(item, wanted[i]));
|
|
726
|
+
problems.push(drawn.length !== wanted.length ? `${drawn.length} ${drawn.length === 1 ? "item is" : "items are"} drawn ${when} but end() draws ${wanted.length} (${show(drawn)} vs ${show(wanted)})` : `item ${index + 1} drawn ${when} is ${show(drawn[index])} but end() draws ${show(wanted[index])}`);
|
|
727
|
+
}
|
|
728
|
+
const style = rounded(actual.mark.style);
|
|
729
|
+
const wantedStyle = rounded(expected.mark.style);
|
|
730
|
+
if (!same(style, wantedStyle)) problems.push(`the mark's style ${when} is ${show(style)} but end() leaves ${show(wantedStyle)}`);
|
|
731
|
+
return problems.length > 0 ? problems.join("; ") : void 0;
|
|
529
732
|
}
|
|
530
733
|
function leftovers(ctx) {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
734
|
+
const problems = [];
|
|
735
|
+
if (ctx.layer.drawn.length > 0) problems.push(`${show(ctx.layer.picture())} is still drawn`);
|
|
736
|
+
if (Object.keys(ctx.mark.style).length > 0) problems.push(`the mark's style is still ${show(ctx.mark.style)}`);
|
|
737
|
+
if (!ctx.clock.idle) problems.push("animation frames are still running");
|
|
738
|
+
return problems.length > 0 ? problems.join("; ") : void 0;
|
|
536
739
|
}
|
|
537
740
|
function same(a, b) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
741
|
+
if (a === b || Number.isNaN(a) && Number.isNaN(b)) return true;
|
|
742
|
+
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
|
|
743
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
744
|
+
const keysA = Object.keys(a).filter((key) => a[key] !== void 0);
|
|
745
|
+
const keysB = Object.keys(b).filter((key) => b[key] !== void 0);
|
|
746
|
+
return keysA.length === keysB.length && keysA.every((key) => same(a[key], b[key]));
|
|
544
747
|
}
|
|
545
748
|
function rounded(value) {
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
749
|
+
if (typeof value === "number") {
|
|
750
|
+
const round = Math.round(value * 1e3) / 1e3;
|
|
751
|
+
return round === 0 ? 0 : round;
|
|
752
|
+
}
|
|
753
|
+
if (Array.isArray(value)) return value.map(rounded);
|
|
754
|
+
if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, field]) => [key, rounded(field)]));
|
|
755
|
+
return value;
|
|
553
756
|
}
|
|
554
|
-
|
|
757
|
+
const LONGEST = 240;
|
|
555
758
|
function show(value) {
|
|
556
|
-
|
|
557
|
-
|
|
759
|
+
const text = JSON.stringify(value) ?? String(value);
|
|
760
|
+
return text.length > LONGEST ? `${text.slice(0, 239)}…` : text;
|
|
558
761
|
}
|
|
559
762
|
function describeError(error) {
|
|
560
|
-
|
|
763
|
+
return error instanceof Error ? `${error.name}: ${error.message}` : show(error);
|
|
561
764
|
}
|
|
562
|
-
export {
|
|
563
|
-
|
|
564
|
-
checkTransition,
|
|
565
|
-
fixturePairs,
|
|
566
|
-
fixtures,
|
|
567
|
-
play,
|
|
568
|
-
testContext
|
|
569
|
-
};
|
|
765
|
+
export { checkEffect, checkTransition, fixturePairs, fixtures, play, testContext };
|
|
766
|
+
|
|
570
767
|
//# sourceMappingURL=testing.js.map
|