expressive-charts 0.2.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +69 -1
  2. package/README.md +10 -10
  3. package/dist/define-DeZLs1h7.js +95 -0
  4. package/dist/define-DeZLs1h7.js.map +1 -0
  5. package/dist/drawing-Dz_IvJPB.d.cts +208 -0
  6. package/dist/drawing-Dz_IvJPB.d.ts +208 -0
  7. package/dist/effect-CdH5449m.d.ts +232 -0
  8. package/dist/effect-uYC8Vs6_.d.cts +232 -0
  9. package/dist/expressive-charts.css +8 -1
  10. package/dist/expressive-charts.css.d.cts +1 -0
  11. package/dist/expressive-charts.css.d.ts +1 -0
  12. package/dist/expressive-charts.global.js +50 -47
  13. package/dist/expressive-charts.global.js.map +1 -1
  14. package/dist/icons/sport.cjs +211 -152
  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 +12647 -9513
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +929 -859
  23. package/dist/index.d.ts +929 -859
  24. package/dist/index.js +10452 -7822
  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 +2034 -1222
  29. package/dist/testing.cjs.map +1 -1
  30. package/dist/testing.d.cts +137 -141
  31. package/dist/testing.d.ts +137 -141
  32. package/dist/testing.js +696 -501
  33. package/dist/testing.js.map +1 -1
  34. package/dist/transition-DSRt2DH3.js +2053 -0
  35. package/dist/transition-DSRt2DH3.js.map +1 -0
  36. package/package.json +18 -6
  37. package/dist/chunk-CVXP2L2J.js +0 -1182
  38. package/dist/chunk-CVXP2L2J.js.map +0 -1
  39. package/dist/chunk-N5IF2RO2.js +0 -66
  40. package/dist/chunk-N5IF2RO2.js.map +0 -1
  41. package/dist/chunk-V5IUTXRW.js +0 -571
  42. package/dist/chunk-V5IUTXRW.js.map +0 -1
  43. package/dist/drawing-DWZIXIeR.d.cts +0 -194
  44. package/dist/drawing-DWZIXIeR.d.ts +0 -194
  45. package/dist/effect-CZUckY0l.d.ts +0 -245
  46. package/dist/effect-CcGdU41j.d.cts +0 -245
package/dist/testing.js CHANGED
@@ -1,572 +1,767 @@
1
- import {
2
- createMotion,
3
- describeValue,
4
- isMarkEffect,
5
- isTransitionEffect,
6
- manualClock,
7
- mergeFields,
8
- runScope
9
- } from "./chunk-CVXP2L2J.js";
10
- import {
11
- describe
12
- } from "./chunk-V5IUTXRW.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
- 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
- return Object.freeze({
203
- bar: bar(moved ? 160 : 200, { radius: 4 }),
204
- "negative bar": describe.bar({ key: "n", series: "goals", x: moved ? 30 : 0, y, width: moved ? 90 : 120, height: 20, baseline: "right" }),
205
- column: describe.bar({ key: "c", series: "goals", x: moved ? 30 : 0, y: moved ? 40 : 0, width: 20, height: moved ? 110 : 150, baseline: "bottom" }),
206
- stacked: bar(goals + assists, { series: void 0, gap: 2, segments: [{ series: "goals", size: goals }, { series: "assists", size: assists }] }),
207
- "short bar": bar(moved ? 4 : 6),
208
- 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 }),
209
- line: describe.line({
210
- key: "goals",
211
- series: "goals",
212
- 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 }],
213
- width: 2
214
- }),
215
- point: describe.point({ key: "p", x: moved ? 40 : 10, y: moved ? 25 : 10, r: 3 })
216
- });
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
+ });
217
381
  }
218
-
219
382
  // src/testing/check.ts
220
383
  async function checkEffect(effect, options = {}) {
221
- if (!isMarkEffect(effect)) {
222
- const hint = isTransitionEffect(effect) ? "; check it with checkTransition" : "";
223
- throw new TypeError(`checkEffect needs a mark effect (kind "geometry" or "data"), got ${describeValue(effect)}${hint}.`);
224
- }
225
- const name = options.name ?? "the effect";
226
- const related = effect.kind === "data" ? effect.needs?.related ?? [] : [];
227
- if (related.length > 0 && !options.data) {
228
- throw new TypeError(
229
- `checkEffect: ${name} needs the related series ${related.map((s) => `"${s}"`).join(", ")}, so pass data(mark) with them: the default data has no related series.`
230
- );
231
- }
232
- const marks = named(options.marks ?? fixtures);
233
- if (marks.length === 0) throw new TypeError("checkEffect: there are no marks to check on.");
234
- const dataOf = (mark) => effect.kind === "data" ? (options.data ?? defaultData)(mark) : void 0;
235
- const failures = [];
236
- for (const [markName, mark] of marks) {
237
- let data;
238
- try {
239
- data = dataOf(mark);
240
- } catch (error) {
241
- failures.push(`on ${markName}: data(mark) threw ${describeError(error)}`);
242
- continue;
243
- }
244
- let moved;
245
- try {
246
- moved = movedSubject(effect, (options.moved ?? movedFixture)(mark), dataOf);
247
- } catch (error) {
248
- failures.push(`on ${markName}: the moved mark, or its data, threw ${describeError(error)}`);
249
- }
250
- const subject = {
251
- context: (more = {}) => testContext({ icons: options.icons, batch: options.batch, ...more }),
252
- run: (ctx) => promised(effect.kind === "data" ? effect.run(mark, data, ctx) : effect.run(mark, ctx)),
253
- end: (ctx) => effect.kind === "data" ? effect.end(mark, data, ctx) : effect.end(mark, ctx),
254
- clear: (ctx) => effect.clear(ctx),
255
- moved
256
- };
257
- for (const check of CHECKS) {
258
- const problem = await attempt(check, subject);
259
- if (problem) failures.push(`on ${markName}, ${check.title}: ${problem}`);
260
- }
261
- }
262
- if (failures.length > 0) throw new Error(`checkEffect found ${problems(failures)} with ${name}:
263
- ${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)}`);
264
426
  }
265
- var RETRACE_AT = [0.25, 0.5, 0.75];
427
+ const RETRACE_AT = [
428
+ .25,
429
+ .5,
430
+ .75
431
+ ];
266
432
  async function checkTransition(effect, options = {}) {
267
- if (!isTransitionEffect(effect)) {
268
- const hint = isMarkEffect(effect) ? "; check it with checkEffect" : "";
269
- throw new TypeError(`checkTransition needs a transition effect (kind "transition" with run, end and clear), got ${describeTransition(effect)}${hint}.`);
270
- }
271
- const name = options.name ?? "the effect";
272
- const pairs = namedPairs(options.pairs ?? fixturePairs);
273
- if (pairs.length === 0) throw new TypeError("checkTransition: there are no pairs to check on.");
274
- const failures = [];
275
- for (const [pairName, [a, b]] of pairs) {
276
- for (const [way, from, to] of [["a to b", a, b], ["b to a", b, a]]) {
277
- for (const check of COMMON) {
278
- const problem3 = await attempt(check, transitionSubject(effect, from, to, 0, options.icons));
279
- if (problem3) failures.push(`on ${pairName}, ${way}, ${check.title}: ${problem3}`);
280
- }
281
- const problem2 = await attempt(FULL_RUN, transitionSubject(effect, from, to, 0.5, options.icons));
282
- if (problem2) failures.push(`on ${pairName}, ${way}, a run from start: 0.5 should end with the same picture as end(): ${problem2}`);
283
- }
284
- let problem;
285
- try {
286
- problem = await retraces(effect, a, b, options.icons);
287
- } catch (error) {
288
- problem = `it threw ${describeError(error)}`;
289
- }
290
- if (problem) failures.push(`on ${pairName}, a run back should retrace the run forward: ${problem}`);
291
- }
292
- if (failures.length > 0) throw new Error(`checkTransition found ${problems(failures)} with ${name}:
293
- ${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)}`);
294
467
  }
295
468
  function transitionContext(start, options) {
296
- return { ...testContext(options), start };
469
+ return {
470
+ ...testContext(options),
471
+ start
472
+ };
297
473
  }
298
474
  function transitionSubject(effect, from, to, start, icons) {
299
- return {
300
- context: (more = {}) => transitionContext(start, { icons, ...more }),
301
- run: (ctx) => promised(effect.run(from, to, ctx)),
302
- end: (ctx) => effect.end(from, to, ctx),
303
- clear: (ctx) => effect.clear(ctx),
304
- moved: void 0
305
- };
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
+ };
306
485
  }
307
486
  async function opening(effect, from, to, start, icons) {
308
- const ctx = transitionContext(start, { icons });
309
- const run = track(promised(effect.run(from, to, ctx)));
310
- await flush();
311
- const picture = ctx.layer.picture();
312
- ctx.abort();
313
- await settle(run);
314
- effect.clear(ctx);
315
- ctx.clear();
316
- if (run.failed) throw run.error;
317
- 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;
318
497
  }
319
498
  async function retraces(effect, a, b, icons) {
320
- for (const p of RETRACE_AT) {
321
- const forward = await opening(effect, a, b, p, icons);
322
- const back = await opening(effect, b, a, 1 - p, icons);
323
- if (same(back, forward)) continue;
324
- const index = back.findIndex((item, i) => !same(item, forward[i]));
325
- 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])}`;
326
- return `the run from b to a from start: ${1 - p} begins with ${what}`;
327
- }
328
- 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
+ }
329
507
  }
330
508
  function difference(actual, expected) {
331
- if (typeof actual !== "object" || typeof expected !== "object" || actual === null || expected === null) return `${show(actual)}, not ${show(expected)}`;
332
- const a = actual;
333
- const b = expected;
334
- for (const field of /* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])) {
335
- const x = a[field];
336
- const y = b[field];
337
- if (same(x, y)) continue;
338
- if (typeof x !== "string" || typeof y !== "string") return `its ${field} is ${show(x)}, not ${show(y)}`;
339
- let at = 0;
340
- while (at < x.length && x[at] === y[at]) at++;
341
- const from = Math.max(0, at - 24);
342
- const part = (text) => `${from > 0 ? "\u2026" : ""}${text.slice(from, at + 24)}${at + 24 < text.length ? "\u2026" : ""}`;
343
- return `its ${field} parts at character ${at + 1}: ${JSON.stringify(part(x))}, not ${JSON.stringify(part(y))}`;
344
- }
345
- 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)}`;
346
524
  }
347
525
  function namedPairs(pairs) {
348
- if (!Array.isArray(pairs)) return Object.entries(pairs).map(([name, pair]) => [`the ${name}`, pair]);
349
- return pairs.map((pair, i) => {
350
- const [a, b] = pair;
351
- const keys = a?.key === b?.key ? `"${String(a?.key)}"` : `"${String(a?.key)}" and "${String(b?.key)}"`;
352
- return [`pair ${i + 1} (${keys})`, pair];
353
- });
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
+ });
354
532
  }
355
533
  function describeTransition(value) {
356
- if (typeof value !== "object" || value === null) return value === null ? "null" : typeof value;
357
- const kind = value.kind;
358
- if (kind === "geometry" || kind === "data") return `a ${kind} effect, which plays on one mark`;
359
- if (kind === "transition") return "a transition effect without run(), end() and clear()";
360
- 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)}`;
361
539
  }
362
540
  async function attempt(check, subject) {
363
- try {
364
- return await check.test(subject);
365
- } catch (error) {
366
- return `it threw ${describeError(error)}`;
367
- }
541
+ try {
542
+ return await check.test(subject);
543
+ } catch (error) {
544
+ return `it threw ${describeError(error)}`;
545
+ }
368
546
  }
369
547
  function promised(running) {
370
- if (typeof running?.then !== "function") throw new TypeError(`run() must return a promise, got ${describeValue(running)}.`);
371
- return running;
548
+ if (typeof running?.then !== "function") throw new TypeError(`run() must return a promise, got ${describeValue(running)}.`);
549
+ return running;
372
550
  }
373
- var problems = (failures) => failures.length === 1 ? "1 problem" : `${failures.length} problems`;
374
- 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");
375
553
  function movedFixture(mark) {
376
- const name = Object.keys(fixtures).find((fixture) => fixtures[fixture] === mark);
377
- 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];
378
556
  }
379
557
  function movedSubject(effect, mark, dataOf) {
380
- if (mark === void 0) return void 0;
381
- const data = dataOf(mark);
382
- return {
383
- change: (ctx) => ctx.change(mark, data),
384
- end: (ctx) => effect.kind === "data" ? effect.end(mark, data, ctx) : effect.end(mark, ctx)
385
- };
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
+ };
386
564
  }
387
- var FULL_RUN = {
388
- title: "a full run should end with the same picture and mark style as end()",
389
- async test(subject) {
390
- const ran = subject.context();
391
- const run = track(subject.run(ran));
392
- await play(ran.clock, run.done);
393
- if (run.failed) return `run() rejected with ${describeError(run.error)}`;
394
- const ended = subject.context();
395
- subject.end(ended);
396
- return compare(ran, ended, "after the run");
397
- }
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
+ }
398
576
  };
399
- var COMMON = [
400
- FULL_RUN,
401
- {
402
- title: "clearing should leave nothing behind",
403
- async test(subject) {
404
- const ctx = subject.context();
405
- const run = track(subject.run(ctx));
406
- await play(ctx.clock, run.done);
407
- subject.clear(ctx);
408
- ctx.clear();
409
- ctx.clock.advance(48);
410
- await flush();
411
- return leftovers(ctx);
412
- }
413
- },
414
- {
415
- title: "an abort mid-run should settle the run and clear to nothing",
416
- async test(subject) {
417
- const ctx = subject.context();
418
- const run = track(subject.run(ctx));
419
- ctx.clock.advance(16);
420
- ctx.clock.advance(16);
421
- ctx.abort();
422
- await settle(run);
423
- if (!run.settled) return "run() was still running after the abort; it should resolve once ctx.signal aborts, without more frames";
424
- if (run.failed) return `run() rejected with ${describeError(run.error)} (it should resolve, aborted or not)`;
425
- subject.clear(ctx);
426
- ctx.clear();
427
- return leftovers(ctx);
428
- }
429
- },
430
- {
431
- title: "with motion off, no frames should run and the end state should be drawn",
432
- async test(subject) {
433
- const ctx = subject.context({ mode: "off" });
434
- const run = track(subject.run(ctx));
435
- const framesAtStart = !ctx.clock.idle;
436
- await settle(run);
437
- 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";
438
- if (run.failed) return `run() rejected with ${describeError(run.error)}`;
439
- if (framesAtStart || !ctx.clock.idle) return "it asked for animation frames";
440
- const ended = subject.context({ mode: "off" });
441
- subject.end(ended);
442
- return compare(ctx, ended, "after the run with motion off");
443
- }
444
- }
445
- ];
446
- var CHECKS = [
447
- ...COMMON,
448
- {
449
- title: "a change() to the moved mark should leave what end() draws on it",
450
- async test(subject) {
451
- const { moved } = subject;
452
- if (!moved) return void 0;
453
- const problems2 = [];
454
- const ran = subject.context();
455
- const run = track(subject.run(ran));
456
- await play(ran.clock, run.done);
457
- if (run.failed) return `run() rejected with ${describeError(run.error)}`;
458
- moved.change(ran);
459
- if (!await finish(ran)) return "it was still animating 10 s after the change()";
460
- const ended = subject.context();
461
- moved.end(ended);
462
- const afterRun = compare(ran, ended, "after a full run and a change()");
463
- if (afterRun) problems2.push(afterRun);
464
- const still = subject.context({ mode: "off" });
465
- subject.end(still);
466
- moved.change(still);
467
- await flush();
468
- const endedOff = subject.context({ mode: "off" });
469
- moved.end(endedOff);
470
- const afterEnd = compare(still, endedOff, "after end() and a change()");
471
- if (afterEnd) problems2.push(afterEnd);
472
- return problems2.length > 0 ? problems2.join("; ") : void 0;
473
- }
474
- }
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
+ }
475
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
+ }];
476
651
  async function finish(ctx) {
477
- await flush();
478
- for (let elapsed = 0; !ctx.clock.idle; elapsed += 16) {
479
- if (elapsed >= 1e4) return false;
480
- ctx.clock.advance(16);
481
- await flush();
482
- }
483
- 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;
484
659
  }
485
- var defaultData = () => ({
486
- datum: void 0,
487
- samples: [
488
- { t: 0, value: 0 },
489
- { t: 1, value: 1 }
490
- ],
491
- related: () => void 0
492
- });
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
+ };
493
691
  function named(marks) {
494
- if (!Array.isArray(marks)) return Object.entries(marks).map(([name, mark]) => [`the ${name}`, mark]);
495
- const seen = /* @__PURE__ */ new Map();
496
- return marks.map((mark) => {
497
- const count = (seen.get(mark.key) ?? 0) + 1;
498
- seen.set(mark.key, count);
499
- return [`mark "${mark.key}"${count > 1 ? ` (${count})` : ""}`, mark];
500
- });
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
+ });
501
699
  }
502
700
  function track(running) {
503
- const state = { settled: false, failed: false, error: void 0 };
504
- const done = running.then(
505
- () => {
506
- state.settled = true;
507
- },
508
- (error) => {
509
- Object.assign(state, { settled: true, failed: true, error });
510
- }
511
- );
512
- 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 });
513
716
  }
514
717
  async function settle(run) {
515
- for (let i = 0; i < 10 && !run.settled; i++) await flush();
718
+ for (let i = 0; i < 10 && !run.settled; i++) await flush();
516
719
  }
517
720
  function compare(actual, expected, when) {
518
- const problems2 = [];
519
- const drawn = actual.layer.picture();
520
- const wanted = expected.layer.picture();
521
- if (!same(drawn, wanted)) {
522
- const index = drawn.findIndex((item, i) => !same(item, wanted[i]));
523
- problems2.push(
524
- 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])}`
525
- );
526
- }
527
- const style = rounded(actual.mark.style);
528
- const wantedStyle = rounded(expected.mark.style);
529
- if (!same(style, wantedStyle)) problems2.push(`the mark's style ${when} is ${show(style)} but end() leaves ${show(wantedStyle)}`);
530
- 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;
531
732
  }
532
733
  function leftovers(ctx) {
533
- const problems2 = [];
534
- if (ctx.layer.drawn.length > 0) problems2.push(`${show(ctx.layer.picture())} is still drawn`);
535
- if (Object.keys(ctx.mark.style).length > 0) problems2.push(`the mark's style is still ${show(ctx.mark.style)}`);
536
- if (!ctx.clock.idle) problems2.push("animation frames are still running");
537
- 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;
538
739
  }
539
740
  function same(a, b) {
540
- if (a === b || Number.isNaN(a) && Number.isNaN(b)) return true;
541
- if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
542
- if (Array.isArray(a) !== Array.isArray(b)) return false;
543
- const keysA = Object.keys(a).filter((key) => a[key] !== void 0);
544
- const keysB = Object.keys(b).filter((key) => b[key] !== void 0);
545
- 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]));
546
747
  }
547
748
  function rounded(value) {
548
- if (typeof value === "number") {
549
- const round = Math.round(value * 1e3) / 1e3;
550
- return round === 0 ? 0 : round;
551
- }
552
- if (Array.isArray(value)) return value.map(rounded);
553
- if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, field]) => [key, rounded(field)]));
554
- 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;
555
756
  }
556
- var LONGEST = 240;
757
+ const LONGEST = 240;
557
758
  function show(value) {
558
- const text = JSON.stringify(value) ?? String(value);
559
- 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;
560
761
  }
561
762
  function describeError(error) {
562
- return error instanceof Error ? `${error.name}: ${error.message}` : show(error);
763
+ return error instanceof Error ? `${error.name}: ${error.message}` : show(error);
563
764
  }
564
- export {
565
- checkEffect,
566
- checkTransition,
567
- fixturePairs,
568
- fixtures,
569
- play,
570
- testContext
571
- };
765
+ export { checkEffect, checkTransition, fixturePairs, fixtures, play, testContext };
766
+
572
767
  //# sourceMappingURL=testing.js.map