expressive-charts 0.3.0 → 0.5.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +73 -1
  2. package/README.md +7 -7
  3. package/dist/define-DeZLs1h7.js +95 -0
  4. package/dist/define-DeZLs1h7.js.map +1 -0
  5. package/dist/drawing-Ypmq-2h6.d.cts +214 -0
  6. package/dist/drawing-Ypmq-2h6.d.ts +214 -0
  7. package/dist/effect-C786hGyJ.d.cts +232 -0
  8. package/dist/effect-CMo-2gPf.d.ts +232 -0
  9. package/dist/expressive-charts.css +5 -2
  10. package/dist/expressive-charts.css.d.cts +1 -2
  11. package/dist/expressive-charts.css.d.ts +1 -2
  12. package/dist/expressive-charts.global.js +47 -48
  13. package/dist/expressive-charts.global.js.map +1 -1
  14. package/dist/icons/sport.cjs +211 -156
  15. package/dist/icons/sport.cjs.map +1 -1
  16. package/dist/icons/sport.d.cts +5 -7
  17. package/dist/icons/sport.d.ts +5 -7
  18. package/dist/icons/sport.js +122 -71
  19. package/dist/icons/sport.js.map +1 -1
  20. package/dist/index.cjs +13203 -9982
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +953 -871
  23. package/dist/index.d.ts +953 -871
  24. package/dist/index.js +11000 -8234
  25. package/dist/index.js.map +1 -1
  26. package/dist/path-data-DnEckjY8.js +123 -0
  27. package/dist/path-data-DnEckjY8.js.map +1 -0
  28. package/dist/testing.cjs +2047 -1255
  29. package/dist/testing.cjs.map +1 -1
  30. package/dist/testing.d.cts +135 -139
  31. package/dist/testing.d.ts +135 -139
  32. package/dist/testing.js +696 -499
  33. package/dist/testing.js.map +1 -1
  34. package/dist/transition-Bu1NsQor.js +2067 -0
  35. package/dist/transition-Bu1NsQor.js.map +1 -0
  36. package/package.json +6 -6
  37. package/dist/chunk-7A7LXXT4.js +0 -70
  38. package/dist/chunk-7A7LXXT4.js.map +0 -1
  39. package/dist/chunk-CJUQHEX6.js +0 -618
  40. package/dist/chunk-CJUQHEX6.js.map +0 -1
  41. package/dist/chunk-N2BLUETM.js +0 -1194
  42. package/dist/chunk-N2BLUETM.js.map +0 -1
  43. package/dist/drawing-CdTgixMY.d.cts +0 -206
  44. package/dist/drawing-CdTgixMY.d.ts +0 -206
  45. package/dist/effect-Bu3MHHeg.d.ts +0 -247
  46. 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 { I as manualClock, T as createMotion, a as mergeFields, c as describeValue, d as describe, i as runScope, l as isMarkEffect, t as isTransitionEffect } from "./transition-Bu1NsQor.js";
14
2
  // src/core/testing/recording.ts
15
3
  function recordingLayer() {
16
- const drawn = /* @__PURE__ */ new Map();
17
- const calls = [];
18
- let nextId = 1;
19
- const replace = (id, next) => {
20
- const current = drawn.get(id);
21
- if (current) drawn.set(id, next(current));
22
- };
23
- const remove = (id) => {
24
- calls.push({ op: "remove", id });
25
- drawn.delete(id);
26
- };
27
- return {
28
- get drawn() {
29
- return [...drawn.values()];
30
- },
31
- get calls() {
32
- return calls;
33
- },
34
- icon(icon, options) {
35
- const id = nextId++;
36
- const size = options?.size;
37
- calls.push({ op: "icon", id, icon: icon.name, size });
38
- drawn.set(id, { kind: "icon", id, icon, size, transform: void 0 });
39
- const handle = {
40
- place(transform) {
41
- calls.push({ op: "place", id, transform });
42
- replace(id, (current) => ({ ...current, transform }));
43
- },
44
- remove: () => remove(id)
45
- };
46
- return handle;
47
- },
48
- path(d, paint) {
49
- const id = nextId++;
50
- calls.push({ op: "path", id, d, paint });
51
- drawn.set(id, { kind: "path", id, d, paint: { ...paint } });
52
- const handle = {
53
- update(nextD, nextPaint) {
54
- calls.push({ op: "update-path", id, d: nextD, paint: nextPaint });
55
- replace(id, (current) => {
56
- const path = current;
57
- return { ...path, d: nextD, paint: mergeFields(path.paint, nextPaint) };
58
- });
59
- },
60
- remove: () => remove(id)
61
- };
62
- return handle;
63
- },
64
- text(content, style) {
65
- const id = nextId++;
66
- calls.push({ op: "text", id, content, style });
67
- drawn.set(id, { kind: "text", id, content, style: { ...style } });
68
- const handle = {
69
- update(nextStyle, nextContent) {
70
- calls.push({ op: "update-text", id, style: nextStyle, content: nextContent });
71
- replace(id, (current) => {
72
- const text = current;
73
- return { ...text, style: mergeFields(text.style, nextStyle), content: nextContent ?? text.content };
74
- });
75
- },
76
- remove: () => remove(id)
77
- };
78
- return handle;
79
- },
80
- picture(decimals = 3) {
81
- const round = rounder(decimals);
82
- return [...drawn.values()].map((item) => {
83
- switch (item.kind) {
84
- case "icon":
85
- return { kind: "icon", icon: item.icon.name, size: item.size, transform: item.transform?.map(round) };
86
- case "path":
87
- return { kind: "path", d: item.d, paint: roundFields(item.paint, round) };
88
- case "text":
89
- return { kind: "text", content: item.content, style: { ...roundFields(item.style, round), at: { x: round(item.style.at.x), y: round(item.style.at.y) } } };
90
- }
91
- });
92
- },
93
- clear() {
94
- calls.push({ op: "clear" });
95
- drawn.clear();
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
- let style = {};
101
- const calls = [];
102
- return {
103
- get style() {
104
- return style;
105
- },
106
- get calls() {
107
- return calls;
108
- },
109
- set(next) {
110
- calls.push({ op: "set", style: next });
111
- style = mergeFields(style, next);
112
- },
113
- reset() {
114
- calls.push({ op: "reset" });
115
- style = {};
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
- const factor = 10 ** decimals;
121
- return (value) => {
122
- const rounded2 = Math.round(value * factor) / factor;
123
- return rounded2 === 0 ? 0 : rounded2;
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
- const result = {};
128
- for (const [field, value] of Object.entries(fields)) result[field] = typeof value === "number" ? round(value) : value;
129
- return result;
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
- const clock = manualClock();
135
- const motion = createMotion({
136
- mode: options.mode ?? "presentation",
137
- ...options.scaling ? { scaling: options.scaling } : {},
138
- reducedMotion: { matches: false, subscribe: () => () => {
139
- } }
140
- });
141
- const layer = recordingLayer();
142
- const mark = recordingMark();
143
- const icons = new Map((options.icons ?? []).map((icon) => [icon.name, icon]));
144
- const scope = runScope({
145
- clock,
146
- motion,
147
- layer,
148
- mark,
149
- icons: { get: (name) => icons.get(name) },
150
- batch: options.batch ?? { index: 0, count: 1 },
151
- previous: options.previous
152
- });
153
- return {
154
- ...scope.context,
155
- motion,
156
- clock,
157
- layer,
158
- mark,
159
- abort: scope.abort,
160
- clear: scope.clear,
161
- change: scope.change
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
- const frame = options.frame ?? 16;
168
- const limit = options.limit ?? 1e4;
169
- let settled = false;
170
- running.then(
171
- () => settled = true,
172
- () => settled = true
173
- );
174
- let elapsed = 0;
175
- await flush();
176
- while (!settled) {
177
- if (elapsed >= limit) throw new Error(`play: still running after ${limit} ms.`);
178
- clock.advance(frame);
179
- elapsed += frame;
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
- for (let i = 0; i < 20; i++) await Promise.resolve();
248
+ for (let i = 0; i < 20; i++) await Promise.resolve();
186
249
  }
187
-
188
250
  // src/testing/fixtures.ts
189
- var fixtures = /* @__PURE__ */ makeFixtures(false);
190
- var movedFixtures = /* @__PURE__ */ makeFixtures(true);
191
- var fixturePairs = /* @__PURE__ */ Object.freeze({
192
- "slice and column": [fixtures.slice, fixtures.column],
193
- "bar and column": [fixtures.bar, fixtures.column],
194
- "two slices": [fixtures.slice, movedFixtures.slice],
195
- "two lines": [fixtures.line, movedFixtures.line],
196
- "two points": [fixtures.point, movedFixtures.point]
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
- const y = moved ? 30 : 0;
200
- const bar = (width, more = {}) => describe.bar({ key: "Okafor", series: "goals", x: 0, y, width, height: 20, baseline: "left", ...more });
201
- const [goals, assists] = moved ? [120, 82] : [160, 62];
202
- const points = moved ? [{ x: 0, y: 90 }, { x: 64, y: 58 }, { x: 128, y: 82 }, { x: 192, y: 26 }, { x: 256, y: 40 }] : [{ x: 0, y: 100 }, { x: 80, y: 60 }, { x: 160, y: 90 }, { x: 240, y: 20 }];
203
- return Object.freeze({
204
- bar: bar(moved ? 160 : 200, { radius: 4 }),
205
- "negative bar": describe.bar({ key: "n", series: "goals", x: moved ? 30 : 0, y, width: moved ? 90 : 120, height: 20, baseline: "right" }),
206
- column: describe.bar({ key: "c", series: "goals", x: moved ? 30 : 0, y: moved ? 40 : 0, width: 20, height: moved ? 110 : 150, baseline: "bottom" }),
207
- stacked: bar(goals + assists, { series: void 0, gap: 2, segments: [{ series: "goals", size: goals }, { series: "assists", size: assists }] }),
208
- "short bar": bar(moved ? 4 : 6),
209
- slice: moved ? describe.arc({ key: "Saved", cx: 140, cy: 130, inner: 60, outer: 100, start: 0.5, end: 2 }) : describe.arc({ key: "Saved", cx: 150, cy: 150, inner: 70, outer: 116, start: 0.3, end: 2.4 }),
210
- line: describe.line({ key: "goals", series: "goals", points, width: 2 }),
211
- // The line broken after its second point: a run, a gap, and a run.
212
- "gapped line": describe.line({ key: "goals", series: "goals", points, breaks: [2], width: 2 }),
213
- point: describe.point({ key: "p", x: moved ? 40 : 10, y: moved ? 25 : 10, r: 3 })
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
- if (!isMarkEffect(effect)) {
220
- const hint = isTransitionEffect(effect) ? "; check it with checkTransition" : "";
221
- throw new TypeError(`checkEffect needs a mark effect (kind "geometry" or "data"), got ${describeValue(effect)}${hint}.`);
222
- }
223
- const name = options.name ?? "the effect";
224
- const related = effect.kind === "data" ? effect.needs?.related ?? [] : [];
225
- if (related.length > 0 && !options.data) {
226
- throw new TypeError(
227
- `checkEffect: ${name} needs the related series ${related.map((s) => `"${s}"`).join(", ")}, so pass data(mark) with them: the default data has no related series.`
228
- );
229
- }
230
- const marks = named(options.marks ?? fixtures);
231
- if (marks.length === 0) throw new TypeError("checkEffect: there are no marks to check on.");
232
- const dataOf = (mark) => effect.kind === "data" ? (options.data ?? defaultData)(mark) : void 0;
233
- const failures = [];
234
- for (const [markName, mark] of marks) {
235
- let data;
236
- try {
237
- data = dataOf(mark);
238
- } catch (error) {
239
- failures.push(`on ${markName}: data(mark) threw ${describeError(error)}`);
240
- continue;
241
- }
242
- let moved;
243
- try {
244
- moved = movedSubject(effect, (options.moved ?? movedFixture)(mark), dataOf);
245
- } catch (error) {
246
- failures.push(`on ${markName}: the moved mark, or its data, threw ${describeError(error)}`);
247
- }
248
- const subject = {
249
- context: (more = {}) => testContext({ icons: options.icons, batch: options.batch, ...more }),
250
- run: (ctx) => promised(effect.kind === "data" ? effect.run(mark, data, ctx) : effect.run(mark, ctx)),
251
- end: (ctx) => effect.kind === "data" ? effect.end(mark, data, ctx) : effect.end(mark, ctx),
252
- clear: (ctx) => effect.clear(ctx),
253
- moved
254
- };
255
- for (const check of CHECKS) {
256
- const problem = await attempt(check, subject);
257
- if (problem) failures.push(`on ${markName}, ${check.title}: ${problem}`);
258
- }
259
- }
260
- if (failures.length > 0) throw new Error(`checkEffect found ${problems(failures)} with ${name}:
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
- var RETRACE_AT = [0.25, 0.5, 0.75];
427
+ const RETRACE_AT = [
428
+ .25,
429
+ .5,
430
+ .75
431
+ ];
264
432
  async function checkTransition(effect, options = {}) {
265
- if (!isTransitionEffect(effect)) {
266
- const hint = isMarkEffect(effect) ? "; check it with checkEffect" : "";
267
- throw new TypeError(`checkTransition needs a transition effect (kind "transition" with run, end and clear), got ${describeTransition(effect)}${hint}.`);
268
- }
269
- const name = options.name ?? "the effect";
270
- const pairs = namedPairs(options.pairs ?? fixturePairs);
271
- if (pairs.length === 0) throw new TypeError("checkTransition: there are no pairs to check on.");
272
- const failures = [];
273
- for (const [pairName, [a, b]] of pairs) {
274
- for (const [way, from, to] of [["a to b", a, b], ["b to a", b, a]]) {
275
- for (const check of COMMON) {
276
- const problem3 = await attempt(check, transitionSubject(effect, from, to, 0, options.icons));
277
- if (problem3) failures.push(`on ${pairName}, ${way}, ${check.title}: ${problem3}`);
278
- }
279
- const problem2 = await attempt(FULL_RUN, transitionSubject(effect, from, to, 0.5, options.icons));
280
- if (problem2) failures.push(`on ${pairName}, ${way}, a run from start: 0.5 should end with the same picture as end(): ${problem2}`);
281
- }
282
- let problem;
283
- try {
284
- problem = await retraces(effect, a, b, options.icons);
285
- } catch (error) {
286
- problem = `it threw ${describeError(error)}`;
287
- }
288
- if (problem) failures.push(`on ${pairName}, a run back should retrace the run forward: ${problem}`);
289
- }
290
- if (failures.length > 0) throw new Error(`checkTransition found ${problems(failures)} with ${name}:
291
- ${list(failures)}`);
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
- return { ...testContext(options), start };
469
+ return {
470
+ ...testContext(options),
471
+ start
472
+ };
295
473
  }
296
474
  function transitionSubject(effect, from, to, start, icons) {
297
- return {
298
- context: (more = {}) => transitionContext(start, { icons, ...more }),
299
- run: (ctx) => promised(effect.run(from, to, ctx)),
300
- end: (ctx) => effect.end(from, to, ctx),
301
- clear: (ctx) => effect.clear(ctx),
302
- moved: void 0
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
- const ctx = transitionContext(start, { icons });
307
- const run = track(promised(effect.run(from, to, ctx)));
308
- await flush();
309
- const picture = ctx.layer.picture();
310
- ctx.abort();
311
- await settle(run);
312
- effect.clear(ctx);
313
- ctx.clear();
314
- if (run.failed) throw run.error;
315
- return picture;
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
- for (const p of RETRACE_AT) {
319
- const forward = await opening(effect, a, b, p, icons);
320
- const back = await opening(effect, b, a, 1 - p, icons);
321
- if (same(back, forward)) continue;
322
- const index = back.findIndex((item, i) => !same(item, forward[i]));
323
- 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])}`;
324
- return `the run from b to a from start: ${1 - p} begins with ${what}`;
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
- if (typeof actual !== "object" || typeof expected !== "object" || actual === null || expected === null) return `${show(actual)}, not ${show(expected)}`;
330
- const a = actual;
331
- const b = expected;
332
- for (const field of /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])) {
333
- const x = a[field];
334
- const y = b[field];
335
- if (same(x, y)) continue;
336
- if (typeof x !== "string" || typeof y !== "string") return `its ${field} is ${show(x)}, not ${show(y)}`;
337
- let at = 0;
338
- while (at < x.length && x[at] === y[at]) at++;
339
- const from = Math.max(0, at - 24);
340
- const part = (text) => `${from > 0 ? "\u2026" : ""}${text.slice(from, at + 24)}${at + 24 < text.length ? "\u2026" : ""}`;
341
- return `its ${field} parts at character ${at + 1}: ${JSON.stringify(part(x))}, not ${JSON.stringify(part(y))}`;
342
- }
343
- return `${show(actual)}, not ${show(expected)}`;
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
- if (!Array.isArray(pairs)) return Object.entries(pairs).map(([name, pair]) => [`the ${name}`, pair]);
347
- return pairs.map((pair, i) => {
348
- const [a, b] = pair;
349
- const keys = a?.key === b?.key ? `"${String(a?.key)}"` : `"${String(a?.key)}" and "${String(b?.key)}"`;
350
- return [`pair ${i + 1} (${keys})`, pair];
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
- if (typeof value !== "object" || value === null) return value === null ? "null" : typeof value;
355
- const kind = value.kind;
356
- if (kind === "geometry" || kind === "data") return `a ${kind} effect, which plays on one mark`;
357
- if (kind === "transition") return "a transition effect without run(), end() and clear()";
358
- return kind === void 0 ? "an object with no kind" : `an effect of kind ${JSON.stringify(kind)}`;
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
- try {
362
- return await check.test(subject);
363
- } catch (error) {
364
- return `it threw ${describeError(error)}`;
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
- if (typeof running?.then !== "function") throw new TypeError(`run() must return a promise, got ${describeValue(running)}.`);
369
- return running;
548
+ if (typeof running?.then !== "function") throw new TypeError(`run() must return a promise, got ${describeValue(running)}.`);
549
+ return running;
370
550
  }
371
- var problems = (failures) => failures.length === 1 ? "1 problem" : `${failures.length} problems`;
372
- var list = (failures) => failures.map((failure) => `- ${failure}`).join("\n");
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
- const name = Object.keys(fixtures).find((fixture) => fixtures[fixture] === mark);
375
- return name === void 0 ? void 0 : movedFixtures[name];
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
- if (mark === void 0) return void 0;
379
- const data = dataOf(mark);
380
- return {
381
- change: (ctx) => ctx.change(mark, data),
382
- end: (ctx) => effect.kind === "data" ? effect.end(mark, data, ctx) : effect.end(mark, ctx)
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
- var FULL_RUN = {
386
- title: "a full run should end with the same picture and mark style as end()",
387
- async test(subject) {
388
- const ran = subject.context();
389
- const run = track(subject.run(ran));
390
- await play(ran.clock, run.done);
391
- if (run.failed) return `run() rejected with ${describeError(run.error)}`;
392
- const ended = subject.context();
393
- subject.end(ended);
394
- return compare(ran, ended, "after the run");
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
- var COMMON = [
398
- FULL_RUN,
399
- {
400
- title: "clearing should leave nothing behind",
401
- async test(subject) {
402
- const ctx = subject.context();
403
- const run = track(subject.run(ctx));
404
- await play(ctx.clock, run.done);
405
- subject.clear(ctx);
406
- ctx.clear();
407
- ctx.clock.advance(48);
408
- await flush();
409
- return leftovers(ctx);
410
- }
411
- },
412
- {
413
- title: "an abort mid-run should settle the run and clear to nothing",
414
- async test(subject) {
415
- const ctx = subject.context();
416
- const run = track(subject.run(ctx));
417
- ctx.clock.advance(16);
418
- ctx.clock.advance(16);
419
- ctx.abort();
420
- await settle(run);
421
- if (!run.settled) return "run() was still running after the abort; it should resolve once ctx.signal aborts, without more frames";
422
- if (run.failed) return `run() rejected with ${describeError(run.error)} (it should resolve, aborted or not)`;
423
- subject.clear(ctx);
424
- ctx.clear();
425
- return leftovers(ctx);
426
- }
427
- },
428
- {
429
- title: "with motion off, no frames should run and the end state should be drawn",
430
- async test(subject) {
431
- const ctx = subject.context({ mode: "off" });
432
- const run = track(subject.run(ctx));
433
- const framesAtStart = !ctx.clock.idle;
434
- await settle(run);
435
- 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";
436
- if (run.failed) return `run() rejected with ${describeError(run.error)}`;
437
- if (framesAtStart || !ctx.clock.idle) return "it asked for animation frames";
438
- const ended = subject.context({ mode: "off" });
439
- subject.end(ended);
440
- return compare(ctx, ended, "after the run with motion off");
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
- await flush();
476
- for (let elapsed = 0; !ctx.clock.idle; elapsed += 16) {
477
- if (elapsed >= 1e4) return false;
478
- ctx.clock.advance(16);
479
- await flush();
480
- }
481
- return true;
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
- var defaultData = () => ({
484
- datum: void 0,
485
- samples: [
486
- { t: 0, value: 0 },
487
- { t: 1, value: 1 }
488
- ],
489
- related: () => void 0
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
- if (!Array.isArray(marks)) return Object.entries(marks).map(([name, mark]) => [`the ${name}`, mark]);
493
- const seen = /* @__PURE__ */ new Map();
494
- return marks.map((mark) => {
495
- const count = (seen.get(mark.key) ?? 0) + 1;
496
- seen.set(mark.key, count);
497
- return [`mark "${mark.key}"${count > 1 ? ` (${count})` : ""}`, mark];
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
- const state = { settled: false, failed: false, error: void 0 };
502
- const done = running.then(
503
- () => {
504
- state.settled = true;
505
- },
506
- (error) => {
507
- Object.assign(state, { settled: true, failed: true, error });
508
- }
509
- );
510
- return Object.assign(state, { done });
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
- for (let i = 0; i < 10 && !run.settled; i++) await flush();
718
+ for (let i = 0; i < 10 && !run.settled; i++) await flush();
514
719
  }
515
720
  function compare(actual, expected, when) {
516
- const problems2 = [];
517
- const drawn = actual.layer.picture();
518
- const wanted = expected.layer.picture();
519
- if (!same(drawn, wanted)) {
520
- const index = drawn.findIndex((item, i) => !same(item, wanted[i]));
521
- problems2.push(
522
- 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])}`
523
- );
524
- }
525
- const style = rounded(actual.mark.style);
526
- const wantedStyle = rounded(expected.mark.style);
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
- const problems2 = [];
532
- if (ctx.layer.drawn.length > 0) problems2.push(`${show(ctx.layer.picture())} is still drawn`);
533
- if (Object.keys(ctx.mark.style).length > 0) problems2.push(`the mark's style is still ${show(ctx.mark.style)}`);
534
- if (!ctx.clock.idle) problems2.push("animation frames are still running");
535
- return problems2.length > 0 ? problems2.join("; ") : void 0;
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
- if (a === b || Number.isNaN(a) && Number.isNaN(b)) return true;
539
- if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
540
- if (Array.isArray(a) !== Array.isArray(b)) return false;
541
- const keysA = Object.keys(a).filter((key) => a[key] !== void 0);
542
- const keysB = Object.keys(b).filter((key) => b[key] !== void 0);
543
- return keysA.length === keysB.length && keysA.every((key) => same(a[key], b[key]));
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
- if (typeof value === "number") {
547
- const round = Math.round(value * 1e3) / 1e3;
548
- return round === 0 ? 0 : round;
549
- }
550
- if (Array.isArray(value)) return value.map(rounded);
551
- if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, field]) => [key, rounded(field)]));
552
- return value;
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
- var LONGEST = 240;
757
+ const LONGEST = 240;
555
758
  function show(value) {
556
- const text = JSON.stringify(value) ?? String(value);
557
- return text.length > LONGEST ? `${text.slice(0, LONGEST - 1)}\u2026` : text;
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
- return error instanceof Error ? `${error.name}: ${error.message}` : show(error);
763
+ return error instanceof Error ? `${error.name}: ${error.message}` : show(error);
561
764
  }
562
- export {
563
- checkEffect,
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