@weasel-js/animator 1.15.0 → 1.15.2

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.
@@ -1,6 +1,6 @@
1
1
  import { isPlainObject, createEmitter } from '@weasel-js/registry';
2
+ import { wrapAngle, resolveEasing } from '@weasel-js/geom';
2
3
  import { keys } from '@msb235/blits';
3
- import { resolveEasing } from '@weasel-js/geom';
4
4
 
5
5
  // src/engine/axes.ts
6
6
  function fieldByField(keys) {
@@ -269,204 +269,6 @@ function createTarget(opts) {
269
269
  states.set(target, s);
270
270
  return target;
271
271
  }
272
-
273
- // src/engine/offsets.ts
274
- var TAU = Math.PI * 2;
275
- function axesFor(axes, value, what) {
276
- const a = axes.to(value);
277
- if (a.length !== axes.count || !a.every((x) => typeof x === "number" && !Number.isNaN(x))) {
278
- throw new Error(`animator: \`${what}\` is not the target's shape`);
279
- }
280
- return a;
281
- }
282
- function shortWay(x) {
283
- x %= TAU;
284
- if (x > Math.PI) return x - TAU;
285
- if (x <= -Math.PI) return x + TAU;
286
- return x;
287
- }
288
- function travel(axes, a, b) {
289
- const d = a.map((x, i) => x - b[i]);
290
- for (const i of axes.angles ?? []) d[i] = shortWay(d[i]);
291
- return d;
292
- }
293
- var plus = (a, b) => a.map((x, i) => x + b[i]);
294
- var minus = (a, b) => a.map((x, i) => x - b[i]);
295
- var norm = (a) => Math.hypot(...a);
296
- function bump(s, delta, sign) {
297
- for (let i = 0; i < delta.length; i++) s.adjust[i] = s.adjust[i] + sign * delta[i];
298
- stale(s);
299
- s.row?.table.mark(s.row.index);
300
- }
301
- function bumpBehind(s, b, delta, sign) {
302
- const adjust = b.adjust ??= new Array(delta.length).fill(0);
303
- for (let i = 0; i < delta.length; i++) adjust[i] = adjust[i] + sign * delta[i];
304
- stale(s);
305
- s.row?.table.mark(s.row.index);
306
- }
307
- function seat(s, holder, slot) {
308
- const was = holder.slot;
309
- if (was && was !== slot && was.refs === 0) {
310
- const n = s.axes.count;
311
- const adjust = holder.adjust ??= new Array(n).fill(0);
312
- for (let i = 0; i < n; i++) adjust[i] = adjust[i] + was.cols[was.at + i];
313
- stale(s);
314
- }
315
- holder.slot = slot;
316
- }
317
- function setBeside(s, beside) {
318
- s.beside = beside;
319
- s.row?.table.beside(s.row.index, beside);
320
- }
321
- function stale(s) {
322
- if (s.stale || !s.owner) return;
323
- s.stale = true;
324
- s.owner.adjusted(s);
325
- }
326
- function absorb(s, delta) {
327
- if (s.discard) return;
328
- s.set(s.axes.from(plus(s.axes.to(s.get()), delta)));
329
- }
330
- function shareBehind(axes, committed, to, start) {
331
- return travel(axes, committed, to).map((m, i) => start[i] === 0 ? 0 : m / start[i]);
332
- }
333
- var times = (a, b) => a.map((x, i) => x * b[i]);
334
- function goBehind(s, own, left, share2) {
335
- const b = {
336
- own,
337
- left,
338
- share: share2,
339
- kept: null,
340
- slot: null,
341
- adjust: null,
342
- move: s.row ? s.row.table.move(s.row.index, share2) : null
343
- };
344
- s.behind.push(b);
345
- return b;
346
- }
347
- var runsOn = (s, b) => b.move ? b : s;
348
- function bumpOn(s, b, delta, sign) {
349
- if (b.move) bumpBehind(s, b, delta, sign);
350
- else bump(s, delta, sign);
351
- }
352
- function comeOut(s, b, left) {
353
- const at = s.behind.indexOf(b);
354
- if (at >= 0) s.behind.splice(at, 1);
355
- b.move?.leave();
356
- if (b.kept) {
357
- s.dimmed = false;
358
- for (const other of s.behind) if (other.kept) s.dimmed = true;
359
- }
360
- return b.kept ? times(left, b.kept) : left.slice();
361
- }
362
- function commitOffset(s, own, left, shown) {
363
- const top = minus(own, left);
364
- if (s.held === 0) {
365
- keep(s, plus(shown, top));
366
- return;
367
- }
368
- if (shown.some((x) => x !== 0)) absorb(s, shown);
369
- if (top.some((x) => x !== 0)) keep(s, top);
370
- }
371
- function keep(s, delta) {
372
- if (s.discard) return;
373
- if (s.held === 0) absorb(s, delta);
374
- else setBeside(s, s.beside ? plus(s.beside, delta) : delta.slice());
375
- s.row?.table.mark(s.row.index);
376
- }
377
- function takeUp(s) {
378
- const committed = s.axes.to(s.get());
379
- const beside = s.beside;
380
- if (beside) setBeside(s, null);
381
- return beside ? plus(committed, beside) : committed;
382
- }
383
- function createTargetBook(owner) {
384
- const adjusted = [];
385
- const token = { ...owner, adjusted: (s) => {
386
- adjusted.push(s);
387
- } };
388
- const showing2 = /* @__PURE__ */ new Set();
389
- const rested = /* @__PURE__ */ new Set();
390
- const publishes = /* @__PURE__ */ new Set();
391
- const tables2 = /* @__PURE__ */ new Map();
392
- const stores = /* @__PURE__ */ new Map();
393
- const shown = (s, value) => {
394
- s.show(value);
395
- if (s.publish) publishes.add(s.publish);
396
- };
397
- const publish = () => {
398
- for (const p of publishes) p();
399
- publishes.clear();
400
- };
401
- return {
402
- attach(s) {
403
- if (s.owner && s.owner !== token) {
404
- throw new Error("animator: this target is being moved by another animator");
405
- }
406
- s.owner = token;
407
- s.live += 1;
408
- if (s.show) showing2.add(s);
409
- rested.delete(s);
410
- if (s.row) {
411
- tables2.set(s.row.table, (tables2.get(s.row.table) ?? 0) + 1);
412
- s.row.table.mark(s.row.index);
413
- }
414
- },
415
- detach(s) {
416
- s.live -= 1;
417
- if (s.row) {
418
- tables2.set(s.row.table, tables2.get(s.row.table) - 1);
419
- s.row.table.mark(s.row.index);
420
- }
421
- if (s.live > 0) return;
422
- s.owner = null;
423
- s.slot = null;
424
- if (s.beside) setBeside(s, null);
425
- for (const b of s.behind) b.move?.leave();
426
- s.behind.length = 0;
427
- s.dimmed = false;
428
- s.adjust.fill(0);
429
- s.stale = false;
430
- if (s.show && showing2.delete(s)) rested.add(s);
431
- },
432
- settle() {
433
- for (const s of adjusted) {
434
- if (!s.stale || s.owner !== token) continue;
435
- s.adjust.fill(0);
436
- for (const b of s.behind) b.adjust = null;
437
- s.stale = false;
438
- }
439
- adjusted.length = 0;
440
- for (const store of stores.keys()) store.frame();
441
- for (const t of tables2.keys()) t.settle();
442
- },
443
- holding(store, by) {
444
- const count = (stores.get(store) ?? 0) + by;
445
- if (count > 0) stores.set(store, count);
446
- else stores.delete(store);
447
- },
448
- show() {
449
- for (const s of showing2) shown(s, readTarget(s));
450
- for (const s of rested) shown(s, s.get());
451
- rested.clear();
452
- for (const [t, moving] of tables2) {
453
- t.fill(owner.columns);
454
- if (moving === 0) tables2.delete(t);
455
- }
456
- publish();
457
- },
458
- showNow(s) {
459
- if (!s.show) return;
460
- shown(s, readTarget(s));
461
- publish();
462
- },
463
- get resting() {
464
- return rested.size > 0;
465
- }
466
- };
467
- }
468
-
469
- // src/engine/holdStore.ts
470
272
  var share = (w) => w > 0 ? Math.min(w, 1) : 0;
471
273
  function wider(a, length, fill = 0) {
472
274
  const b = new a.constructor(length);
@@ -525,7 +327,7 @@ function foldRow(layers, angle, n, row, committed, at, skip, delta, total) {
525
327
  const w = holds(l, a);
526
328
  if (!(w > 0)) continue;
527
329
  const v = l.values[base + a];
528
- sum += w * (mean === null ? shortWay(v - c) : shortWay(mean - c) + shortWay(v - mean));
330
+ sum += w * (mean === null ? wrapAngle(v - c) : wrapAngle(mean - c) + wrapAngle(v - mean));
529
331
  }
530
332
  }
531
333
  total[a] = weight;
@@ -1068,6 +870,193 @@ function shownOf(slot) {
1068
870
  for (let i = 0; i < out.length; i++) out[i] = shown[at + i];
1069
871
  return out;
1070
872
  }
873
+ function axesFor(axes, value, what) {
874
+ const a = axes.to(value);
875
+ if (a.length !== axes.count || !a.every((x) => typeof x === "number" && !Number.isNaN(x))) {
876
+ throw new Error(`animator: \`${what}\` is not the target's shape`);
877
+ }
878
+ return a;
879
+ }
880
+ function travel(axes, a, b) {
881
+ const d = a.map((x, i) => x - b[i]);
882
+ for (const i of axes.angles ?? []) d[i] = wrapAngle(d[i]);
883
+ return d;
884
+ }
885
+ var plus = (a, b) => a.map((x, i) => x + b[i]);
886
+ var minus = (a, b) => a.map((x, i) => x - b[i]);
887
+ var norm = (a) => Math.hypot(...a);
888
+ function bump(s, delta, sign) {
889
+ for (let i = 0; i < delta.length; i++) s.adjust[i] = s.adjust[i] + sign * delta[i];
890
+ stale(s);
891
+ s.row?.table.mark(s.row.index);
892
+ }
893
+ function bumpBehind(s, b, delta, sign) {
894
+ const adjust = b.adjust ??= new Array(delta.length).fill(0);
895
+ for (let i = 0; i < delta.length; i++) adjust[i] = adjust[i] + sign * delta[i];
896
+ stale(s);
897
+ s.row?.table.mark(s.row.index);
898
+ }
899
+ function seat(s, holder, slot) {
900
+ const was = holder.slot;
901
+ if (was && was !== slot && was.refs === 0) {
902
+ const n = s.axes.count;
903
+ const adjust = holder.adjust ??= new Array(n).fill(0);
904
+ for (let i = 0; i < n; i++) adjust[i] = adjust[i] + was.cols[was.at + i];
905
+ stale(s);
906
+ }
907
+ holder.slot = slot;
908
+ }
909
+ function setBeside(s, beside) {
910
+ s.beside = beside;
911
+ s.row?.table.beside(s.row.index, beside);
912
+ }
913
+ function stale(s) {
914
+ if (s.stale || !s.owner) return;
915
+ s.stale = true;
916
+ s.owner.adjusted(s);
917
+ }
918
+ function absorb(s, delta) {
919
+ if (s.discard) return;
920
+ s.set(s.axes.from(plus(s.axes.to(s.get()), delta)));
921
+ }
922
+ function shareBehind(axes, committed, to, start) {
923
+ return travel(axes, committed, to).map((m, i) => start[i] === 0 ? 0 : m / start[i]);
924
+ }
925
+ var times = (a, b) => a.map((x, i) => x * b[i]);
926
+ function goBehind(s, own, left, share2) {
927
+ const b = {
928
+ own,
929
+ left,
930
+ share: share2,
931
+ kept: null,
932
+ slot: null,
933
+ adjust: null,
934
+ move: s.row ? s.row.table.move(s.row.index, share2) : null
935
+ };
936
+ s.behind.push(b);
937
+ return b;
938
+ }
939
+ var runsOn = (s, b) => b.move ? b : s;
940
+ function bumpOn(s, b, delta, sign) {
941
+ if (b.move) bumpBehind(s, b, delta, sign);
942
+ else bump(s, delta, sign);
943
+ }
944
+ function comeOut(s, b, left) {
945
+ const at = s.behind.indexOf(b);
946
+ if (at >= 0) s.behind.splice(at, 1);
947
+ b.move?.leave();
948
+ if (b.kept) {
949
+ s.dimmed = false;
950
+ for (const other of s.behind) if (other.kept) s.dimmed = true;
951
+ }
952
+ return b.kept ? times(left, b.kept) : left.slice();
953
+ }
954
+ function commitOffset(s, own, left, shown) {
955
+ const top = minus(own, left);
956
+ if (s.held === 0) {
957
+ keep(s, plus(shown, top));
958
+ return;
959
+ }
960
+ if (shown.some((x) => x !== 0)) absorb(s, shown);
961
+ if (top.some((x) => x !== 0)) keep(s, top);
962
+ }
963
+ function keep(s, delta) {
964
+ if (s.discard) return;
965
+ if (s.held === 0) absorb(s, delta);
966
+ else setBeside(s, s.beside ? plus(s.beside, delta) : delta.slice());
967
+ s.row?.table.mark(s.row.index);
968
+ }
969
+ function takeUp(s) {
970
+ const committed = s.axes.to(s.get());
971
+ const beside = s.beside;
972
+ if (beside) setBeside(s, null);
973
+ return beside ? plus(committed, beside) : committed;
974
+ }
975
+ function createTargetBook(owner) {
976
+ const adjusted = [];
977
+ const token = { ...owner, adjusted: (s) => {
978
+ adjusted.push(s);
979
+ } };
980
+ const showing2 = /* @__PURE__ */ new Set();
981
+ const rested = /* @__PURE__ */ new Set();
982
+ const publishes = /* @__PURE__ */ new Set();
983
+ const tables2 = /* @__PURE__ */ new Map();
984
+ const stores = /* @__PURE__ */ new Map();
985
+ const shown = (s, value) => {
986
+ s.show(value);
987
+ if (s.publish) publishes.add(s.publish);
988
+ };
989
+ const publish = () => {
990
+ for (const p of publishes) p();
991
+ publishes.clear();
992
+ };
993
+ return {
994
+ attach(s) {
995
+ if (s.owner && s.owner !== token) {
996
+ throw new Error("animator: this target is being moved by another animator");
997
+ }
998
+ s.owner = token;
999
+ s.live += 1;
1000
+ if (s.show) showing2.add(s);
1001
+ rested.delete(s);
1002
+ if (s.row) {
1003
+ tables2.set(s.row.table, (tables2.get(s.row.table) ?? 0) + 1);
1004
+ s.row.table.mark(s.row.index);
1005
+ }
1006
+ },
1007
+ detach(s) {
1008
+ s.live -= 1;
1009
+ if (s.row) {
1010
+ tables2.set(s.row.table, tables2.get(s.row.table) - 1);
1011
+ s.row.table.mark(s.row.index);
1012
+ }
1013
+ if (s.live > 0) return;
1014
+ s.owner = null;
1015
+ s.slot = null;
1016
+ if (s.beside) setBeside(s, null);
1017
+ for (const b of s.behind) b.move?.leave();
1018
+ s.behind.length = 0;
1019
+ s.dimmed = false;
1020
+ s.adjust.fill(0);
1021
+ s.stale = false;
1022
+ if (s.show && showing2.delete(s)) rested.add(s);
1023
+ },
1024
+ settle() {
1025
+ for (const s of adjusted) {
1026
+ if (!s.stale || s.owner !== token) continue;
1027
+ s.adjust.fill(0);
1028
+ for (const b of s.behind) b.adjust = null;
1029
+ s.stale = false;
1030
+ }
1031
+ adjusted.length = 0;
1032
+ for (const store of stores.keys()) store.frame();
1033
+ for (const t of tables2.keys()) t.settle();
1034
+ },
1035
+ holding(store, by) {
1036
+ const count = (stores.get(store) ?? 0) + by;
1037
+ if (count > 0) stores.set(store, count);
1038
+ else stores.delete(store);
1039
+ },
1040
+ show() {
1041
+ for (const s of showing2) shown(s, readTarget(s));
1042
+ for (const s of rested) shown(s, s.get());
1043
+ rested.clear();
1044
+ for (const [t, moving] of tables2) {
1045
+ t.fill(owner.columns);
1046
+ if (moving === 0) tables2.delete(t);
1047
+ }
1048
+ publish();
1049
+ },
1050
+ showNow(s) {
1051
+ if (!s.show) return;
1052
+ shown(s, readTarget(s));
1053
+ publish();
1054
+ },
1055
+ get resting() {
1056
+ return rested.size > 0;
1057
+ }
1058
+ };
1059
+ }
1071
1060
 
1072
1061
  // src/timeline/targetStops.ts
1073
1062
  function targetStops(track) {
@@ -1620,6 +1609,6 @@ function createTimeline(register, id, opts, report, hold) {
1620
1609
  };
1621
1610
  }
1622
1611
 
1623
- export { ColorOverrideRegistry, absorb, axesFor, axesOf, axisIndexes, bump, bumpOn, comeOut, commitOffset, committedInto, createHoldStore, createTarget, createTargetBook, createTargetTable, createTimeline, goBehind, isTarget, minus, norm, plus, rowTableOf, runsOn, sampleTrack, seat, setBeside, shareBehind, shortWay, stateOf, takeUp, times, travel };
1624
- //# sourceMappingURL=chunk-H7WENFPC.js.map
1625
- //# sourceMappingURL=chunk-H7WENFPC.js.map
1612
+ export { ColorOverrideRegistry, absorb, axesFor, axesOf, axisIndexes, bump, bumpOn, comeOut, commitOffset, committedInto, createHoldStore, createTarget, createTargetBook, createTargetTable, createTimeline, goBehind, isTarget, minus, norm, plus, rowTableOf, runsOn, sampleTrack, seat, setBeside, shareBehind, stateOf, takeUp, times, travel };
1613
+ //# sourceMappingURL=chunk-7TTE4JM6.js.map
1614
+ //# sourceMappingURL=chunk-7TTE4JM6.js.map