expressive-charts 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/testing.cjs CHANGED
@@ -258,6 +258,22 @@ function mergeFields(current, next) {
258
258
  else result[field] = value;
259
259
  return result;
260
260
  }
261
+ // src/core/text-box.ts
262
+ const TEXT_SIZE = 12.5;
263
+ const AVERAGE_WIDTH = .6;
264
+ const ASCENT = 1.05;
265
+ const SIDE = .16;
266
+ function boxAround(at, anchor, width, size) {
267
+ return {
268
+ x: (anchor === "end" ? at.x - width : anchor === "middle" ? at.x - width / 2 : at.x) - SIDE * size,
269
+ y: at.y - ASCENT * size,
270
+ width: width + 2 * SIDE * size,
271
+ height: 1.3 * size
272
+ };
273
+ }
274
+ function estimatedBox(content, style) {
275
+ return boxAround(style.at, style.anchor, content.length * TEXT_SIZE * AVERAGE_WIDTH, TEXT_SIZE);
276
+ }
261
277
  // src/core/easing.ts
262
278
  const easeInOutCubic = (t) => t < .5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
263
279
  // src/core/tween.ts
@@ -345,6 +361,7 @@ function runScope(options) {
345
361
  icons: options.icons,
346
362
  batch: options.batch,
347
363
  ...options.previous ? { previous: options.previous } : {},
364
+ ...options.texts ? { texts: options.texts } : {},
348
365
  tween(tweenOptions) {
349
366
  const own = tweenOptions.signal;
350
367
  const running = tween({
@@ -584,6 +601,18 @@ function testContext(options = {}) {
584
601
  const layer = recordingLayer();
585
602
  const mark = recordingMark();
586
603
  const icons = new Map((options.icons ?? []).map((icon) => [icon.name, icon]));
604
+ const held = [...options.held ?? []];
605
+ let holding;
606
+ const texts = {
607
+ box: estimatedBox,
608
+ held: () => held,
609
+ hold(box) {
610
+ holding = box;
611
+ },
612
+ get holding() {
613
+ return holding;
614
+ }
615
+ };
587
616
  const scope = runScope({
588
617
  clock,
589
618
  motion,
@@ -594,7 +623,8 @@ function testContext(options = {}) {
594
623
  index: 0,
595
624
  count: 1
596
625
  },
597
- previous: options.previous
626
+ previous: options.previous,
627
+ texts
598
628
  });
599
629
  return {
600
630
  ...scope.context,
@@ -602,8 +632,12 @@ function testContext(options = {}) {
602
632
  clock,
603
633
  layer,
604
634
  mark,
635
+ texts,
605
636
  abort: scope.abort,
606
- clear: scope.clear,
637
+ clear() {
638
+ scope.clear();
639
+ holding = void 0;
640
+ },
607
641
  change: scope.change
608
642
  };
609
643
  }