@weasel-js/animator 1.15.1 → 1.16.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/{chunk-H7WENFPC.js → chunk-TXKTFZIW.js} +326 -212
- package/dist/chunk-TXKTFZIW.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +8 -18
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +10 -6
- package/dist/react.js.map +1 -1
- package/dist/{types-TZO301HJ.d.ts → types-Bjk4RrcB.d.ts} +67 -2
- package/package.json +6 -6
- package/dist/chunk-H7WENFPC.js.map +0 -1
|
@@ -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 ?
|
|
330
|
+
sum += w * (mean === null ? wrapAngle(v - c) : wrapAngle(mean - c) + wrapAngle(v - mean));
|
|
529
331
|
}
|
|
530
332
|
}
|
|
531
333
|
total[a] = weight;
|
|
@@ -920,12 +722,11 @@ function createTargetTable(opts) {
|
|
|
920
722
|
tables.set(table, rows);
|
|
921
723
|
return table;
|
|
922
724
|
}
|
|
923
|
-
|
|
924
|
-
// src/colorRegistry.ts
|
|
925
725
|
var ColorOverrideRegistry = class {
|
|
926
726
|
map = /* @__PURE__ */ new Map();
|
|
927
727
|
slots = /* @__PURE__ */ new Map();
|
|
928
728
|
tables = /* @__PURE__ */ new Map();
|
|
729
|
+
listeners = createEmitter();
|
|
929
730
|
_version = 0;
|
|
930
731
|
set(id, channel, override) {
|
|
931
732
|
let entry = this.map.get(id);
|
|
@@ -934,7 +735,7 @@ var ColorOverrideRegistry = class {
|
|
|
934
735
|
this.map.set(id, entry);
|
|
935
736
|
}
|
|
936
737
|
entry[channel] = override;
|
|
937
|
-
this.
|
|
738
|
+
this.changed();
|
|
938
739
|
}
|
|
939
740
|
/** Drops `id`'s override on `channel`, and the colors a finished or canceled animation on its
|
|
940
741
|
* {@link target} left painted. An animation still running goes on. */
|
|
@@ -945,7 +746,7 @@ var ColorOverrideRegistry = class {
|
|
|
945
746
|
if (!(channel in entry)) return;
|
|
946
747
|
delete entry[channel];
|
|
947
748
|
if (!entry.fill && !entry.stroke) this.map.delete(id);
|
|
948
|
-
this.
|
|
749
|
+
this.changed();
|
|
949
750
|
}
|
|
950
751
|
clearAll() {
|
|
951
752
|
for (const [id, node] of this.slots) {
|
|
@@ -953,7 +754,7 @@ var ColorOverrideRegistry = class {
|
|
|
953
754
|
}
|
|
954
755
|
if (this.map.size === 0) return;
|
|
955
756
|
this.map.clear();
|
|
956
|
-
this.
|
|
757
|
+
this.changed();
|
|
957
758
|
}
|
|
958
759
|
/** What `set` stored for `id`'s `channel`; failing that, the colors its {@link target} paints. */
|
|
959
760
|
get(id, channel) {
|
|
@@ -962,9 +763,12 @@ var ColorOverrideRegistry = class {
|
|
|
962
763
|
const slot = this.slots.get(id)?.[channel];
|
|
963
764
|
return slot?.painted ? shownOf(slot) : void 0;
|
|
964
765
|
}
|
|
965
|
-
/** Whether anything
|
|
766
|
+
/** Whether anything paints over `id`, on either channel: an override from `set`, or a target
|
|
767
|
+
* an animation has committed. A target asked for and never moved does not count. */
|
|
966
768
|
has(id) {
|
|
967
|
-
|
|
769
|
+
if (this.map.has(id)) return true;
|
|
770
|
+
const node = this.slots.get(id);
|
|
771
|
+
return node !== void 0 && (node.fill?.painted === true || node.stroke?.painted === true);
|
|
968
772
|
}
|
|
969
773
|
/**
|
|
970
774
|
* The {@link Target} for `id`'s colors on `channel`: `length` numbers, flat RGBA per anchor.
|
|
@@ -1009,7 +813,8 @@ var ColorOverrideRegistry = class {
|
|
|
1009
813
|
set: (row) => {
|
|
1010
814
|
const slot = rows[row];
|
|
1011
815
|
if (slot) slot.painted = true;
|
|
1012
|
-
this._version++;
|
|
816
|
+
if (table.target(row).active) this._version++;
|
|
817
|
+
else this.changed();
|
|
1013
818
|
},
|
|
1014
819
|
show: () => {
|
|
1015
820
|
this._version++;
|
|
@@ -1034,7 +839,7 @@ var ColorOverrideRegistry = class {
|
|
|
1034
839
|
delete node[channel];
|
|
1035
840
|
if (!node.fill && !node.stroke) this.slots.delete(id);
|
|
1036
841
|
this.drop(slot);
|
|
1037
|
-
if (slot.painted) this.
|
|
842
|
+
if (slot.painted) this.changed();
|
|
1038
843
|
}
|
|
1039
844
|
/**
|
|
1040
845
|
* The colors to paint on `id`'s `channel`, given the colors the painter would
|
|
@@ -1057,9 +862,18 @@ var ColorOverrideRegistry = class {
|
|
|
1057
862
|
const result = override(base, tMs);
|
|
1058
863
|
return result.length === base.length ? result : base;
|
|
1059
864
|
}
|
|
865
|
+
/** Calls `listener` after a `set`, `clear`, or release changes what paints; an animation's
|
|
866
|
+
* frames reach a painter through `animator.onTick` instead. Returns an unsubscribe. */
|
|
867
|
+
subscribe(listener) {
|
|
868
|
+
return this.listeners.subscribe(listener);
|
|
869
|
+
}
|
|
1060
870
|
version() {
|
|
1061
871
|
return this._version;
|
|
1062
872
|
}
|
|
873
|
+
changed() {
|
|
874
|
+
this._version++;
|
|
875
|
+
this.listeners.emit();
|
|
876
|
+
}
|
|
1063
877
|
};
|
|
1064
878
|
function shownOf(slot) {
|
|
1065
879
|
const { shown } = slot.table;
|
|
@@ -1068,6 +882,306 @@ function shownOf(slot) {
|
|
|
1068
882
|
for (let i = 0; i < out.length; i++) out[i] = shown[at + i];
|
|
1069
883
|
return out;
|
|
1070
884
|
}
|
|
885
|
+
var EDGES = ["start", "end"];
|
|
886
|
+
var TrimOverrideRegistry = class {
|
|
887
|
+
map = /* @__PURE__ */ new Map();
|
|
888
|
+
slots = /* @__PURE__ */ new Map();
|
|
889
|
+
listeners = createEmitter();
|
|
890
|
+
_version = 0;
|
|
891
|
+
set(id, override) {
|
|
892
|
+
this.map.set(id, { ...override });
|
|
893
|
+
this.changed();
|
|
894
|
+
}
|
|
895
|
+
/** Drops `id`'s override, and the edges a finished or canceled animation on its
|
|
896
|
+
* {@link target}s left painted. An animation still running goes on. */
|
|
897
|
+
clear(id) {
|
|
898
|
+
for (const edge of EDGES) this.release(id, edge);
|
|
899
|
+
if (this.map.delete(id)) this.changed();
|
|
900
|
+
}
|
|
901
|
+
clearAll() {
|
|
902
|
+
for (const [id, node] of [...this.slots]) {
|
|
903
|
+
for (const edge of Object.keys(node)) this.release(id, edge);
|
|
904
|
+
}
|
|
905
|
+
if (this.map.size === 0) return;
|
|
906
|
+
this.map.clear();
|
|
907
|
+
this.changed();
|
|
908
|
+
}
|
|
909
|
+
/** What paints on `id`'s edges now: see {@link resolve}. */
|
|
910
|
+
get(id) {
|
|
911
|
+
return this.resolve(id);
|
|
912
|
+
}
|
|
913
|
+
/** Whether anything paints over `id`'s trim: an override from `set`, or a target an
|
|
914
|
+
* animation has committed. A target asked for and never moved does not count. */
|
|
915
|
+
has(id) {
|
|
916
|
+
if (this.map.has(id)) return true;
|
|
917
|
+
const node = this.slots.get(id);
|
|
918
|
+
return node !== void 0 && (node.start?.painted === true || node.end?.painted === true);
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
* The {@link Target} for `id`'s `edge`, committed at the whole stroke's (`start` 0, `end` 1)
|
|
922
|
+
* until something moves it. Every caller for one node and edge gets the same one, so their
|
|
923
|
+
* animations add. The registry holds its committed value and nothing writes the scene.
|
|
924
|
+
*
|
|
925
|
+
* What it paints, on its own edge only: with no override from `set` on that edge, its value in
|
|
926
|
+
* place of the stroke's own; over one, only what its animations have left to travel, added on
|
|
927
|
+
* top. Ask again for each animation rather than keeping it: {@link release} and {@link clear}
|
|
928
|
+
* drop a resting one, and the target it had throws from then on.
|
|
929
|
+
*/
|
|
930
|
+
target(id, edge) {
|
|
931
|
+
let node = this.slots.get(id);
|
|
932
|
+
const held = node?.[edge];
|
|
933
|
+
if (held) return held.target;
|
|
934
|
+
const state = { value: edge === "start" ? 0 : 1, painted: false, released: false };
|
|
935
|
+
const target = createTarget({
|
|
936
|
+
get: () => state.value,
|
|
937
|
+
set: (value) => {
|
|
938
|
+
if (state.released) throw new Error(`trim overrides: ${id}'s ${edge} target was released`);
|
|
939
|
+
state.value = value;
|
|
940
|
+
state.painted = true;
|
|
941
|
+
if (target.active) this._version++;
|
|
942
|
+
else this.changed();
|
|
943
|
+
},
|
|
944
|
+
show: () => {
|
|
945
|
+
this._version++;
|
|
946
|
+
}
|
|
947
|
+
});
|
|
948
|
+
if (!node) {
|
|
949
|
+
node = {};
|
|
950
|
+
this.slots.set(id, node);
|
|
951
|
+
}
|
|
952
|
+
node[edge] = Object.assign(state, { target });
|
|
953
|
+
return target;
|
|
954
|
+
}
|
|
955
|
+
/** Drops the value `id`'s {@link target} on `edge` left painted, unless an animation is still
|
|
956
|
+
* moving it. An override from `set` stays. */
|
|
957
|
+
release(id, edge) {
|
|
958
|
+
const node = this.slots.get(id);
|
|
959
|
+
const slot = node?.[edge];
|
|
960
|
+
if (!node || !slot || slot.target.active) return;
|
|
961
|
+
delete node[edge];
|
|
962
|
+
if (!node.start && !node.end) this.slots.delete(id);
|
|
963
|
+
slot.released = true;
|
|
964
|
+
if (slot.painted) this.changed();
|
|
965
|
+
}
|
|
966
|
+
/**
|
|
967
|
+
* The edges to paint on `id`'s stroke, each on its own: the override from `set` for that
|
|
968
|
+
* edge plus what its {@link target} has left to travel; failing a `set` value, the target's
|
|
969
|
+
* value once an animation has committed it. An edge with neither is left out, so the stroke's
|
|
970
|
+
* own stands. `undefined` when neither edge is overridden.
|
|
971
|
+
*/
|
|
972
|
+
resolve(id) {
|
|
973
|
+
const override = this.map.get(id);
|
|
974
|
+
const node = this.slots.get(id);
|
|
975
|
+
const start = edgeOf(override?.start, node?.start);
|
|
976
|
+
const end = edgeOf(override?.end, node?.end);
|
|
977
|
+
if (start === void 0 && end === void 0) return void 0;
|
|
978
|
+
return { ...start !== void 0 ? { start } : {}, ...end !== void 0 ? { end } : {} };
|
|
979
|
+
}
|
|
980
|
+
/** Calls `listener` after a `set`, `clear`, or release changes what paints; an animation's
|
|
981
|
+
* frames reach a painter through `animator.onTick` instead. Returns an unsubscribe. */
|
|
982
|
+
subscribe(listener) {
|
|
983
|
+
return this.listeners.subscribe(listener);
|
|
984
|
+
}
|
|
985
|
+
version() {
|
|
986
|
+
return this._version;
|
|
987
|
+
}
|
|
988
|
+
changed() {
|
|
989
|
+
this._version++;
|
|
990
|
+
this.listeners.emit();
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
function edgeOf(set, slot) {
|
|
994
|
+
const painted = slot?.painted === true;
|
|
995
|
+
if (set === void 0) return painted ? slot.target.read() : void 0;
|
|
996
|
+
return painted && slot.target.active ? set + slot.target.read() - slot.value : set;
|
|
997
|
+
}
|
|
998
|
+
function axesFor(axes, value, what) {
|
|
999
|
+
const a = axes.to(value);
|
|
1000
|
+
if (a.length !== axes.count || !a.every((x) => typeof x === "number" && !Number.isNaN(x))) {
|
|
1001
|
+
throw new Error(`animator: \`${what}\` is not the target's shape`);
|
|
1002
|
+
}
|
|
1003
|
+
return a;
|
|
1004
|
+
}
|
|
1005
|
+
function travel(axes, a, b) {
|
|
1006
|
+
const d = a.map((x, i) => x - b[i]);
|
|
1007
|
+
for (const i of axes.angles ?? []) d[i] = wrapAngle(d[i]);
|
|
1008
|
+
return d;
|
|
1009
|
+
}
|
|
1010
|
+
var plus = (a, b) => a.map((x, i) => x + b[i]);
|
|
1011
|
+
var minus = (a, b) => a.map((x, i) => x - b[i]);
|
|
1012
|
+
var norm = (a) => Math.hypot(...a);
|
|
1013
|
+
function bump(s, delta, sign) {
|
|
1014
|
+
for (let i = 0; i < delta.length; i++) s.adjust[i] = s.adjust[i] + sign * delta[i];
|
|
1015
|
+
stale(s);
|
|
1016
|
+
s.row?.table.mark(s.row.index);
|
|
1017
|
+
}
|
|
1018
|
+
function bumpBehind(s, b, delta, sign) {
|
|
1019
|
+
const adjust = b.adjust ??= new Array(delta.length).fill(0);
|
|
1020
|
+
for (let i = 0; i < delta.length; i++) adjust[i] = adjust[i] + sign * delta[i];
|
|
1021
|
+
stale(s);
|
|
1022
|
+
s.row?.table.mark(s.row.index);
|
|
1023
|
+
}
|
|
1024
|
+
function seat(s, holder, slot) {
|
|
1025
|
+
const was = holder.slot;
|
|
1026
|
+
if (was && was !== slot && was.refs === 0) {
|
|
1027
|
+
const n = s.axes.count;
|
|
1028
|
+
const adjust = holder.adjust ??= new Array(n).fill(0);
|
|
1029
|
+
for (let i = 0; i < n; i++) adjust[i] = adjust[i] + was.cols[was.at + i];
|
|
1030
|
+
stale(s);
|
|
1031
|
+
}
|
|
1032
|
+
holder.slot = slot;
|
|
1033
|
+
}
|
|
1034
|
+
function setBeside(s, beside) {
|
|
1035
|
+
s.beside = beside;
|
|
1036
|
+
s.row?.table.beside(s.row.index, beside);
|
|
1037
|
+
}
|
|
1038
|
+
function stale(s) {
|
|
1039
|
+
if (s.stale || !s.owner) return;
|
|
1040
|
+
s.stale = true;
|
|
1041
|
+
s.owner.adjusted(s);
|
|
1042
|
+
}
|
|
1043
|
+
function absorb(s, delta) {
|
|
1044
|
+
if (s.discard) return;
|
|
1045
|
+
s.set(s.axes.from(plus(s.axes.to(s.get()), delta)));
|
|
1046
|
+
}
|
|
1047
|
+
function shareBehind(axes, committed, to, start) {
|
|
1048
|
+
return travel(axes, committed, to).map((m, i) => start[i] === 0 ? 0 : m / start[i]);
|
|
1049
|
+
}
|
|
1050
|
+
var times = (a, b) => a.map((x, i) => x * b[i]);
|
|
1051
|
+
function goBehind(s, own, left, share2) {
|
|
1052
|
+
const b = {
|
|
1053
|
+
own,
|
|
1054
|
+
left,
|
|
1055
|
+
share: share2,
|
|
1056
|
+
kept: null,
|
|
1057
|
+
slot: null,
|
|
1058
|
+
adjust: null,
|
|
1059
|
+
move: s.row ? s.row.table.move(s.row.index, share2) : null
|
|
1060
|
+
};
|
|
1061
|
+
s.behind.push(b);
|
|
1062
|
+
return b;
|
|
1063
|
+
}
|
|
1064
|
+
var runsOn = (s, b) => b.move ? b : s;
|
|
1065
|
+
function bumpOn(s, b, delta, sign) {
|
|
1066
|
+
if (b.move) bumpBehind(s, b, delta, sign);
|
|
1067
|
+
else bump(s, delta, sign);
|
|
1068
|
+
}
|
|
1069
|
+
function comeOut(s, b, left) {
|
|
1070
|
+
const at = s.behind.indexOf(b);
|
|
1071
|
+
if (at >= 0) s.behind.splice(at, 1);
|
|
1072
|
+
b.move?.leave();
|
|
1073
|
+
if (b.kept) {
|
|
1074
|
+
s.dimmed = false;
|
|
1075
|
+
for (const other of s.behind) if (other.kept) s.dimmed = true;
|
|
1076
|
+
}
|
|
1077
|
+
return b.kept ? times(left, b.kept) : left.slice();
|
|
1078
|
+
}
|
|
1079
|
+
function commitOffset(s, own, left, shown) {
|
|
1080
|
+
const top = minus(own, left);
|
|
1081
|
+
if (s.held === 0) {
|
|
1082
|
+
keep(s, plus(shown, top));
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
if (shown.some((x) => x !== 0)) absorb(s, shown);
|
|
1086
|
+
if (top.some((x) => x !== 0)) keep(s, top);
|
|
1087
|
+
}
|
|
1088
|
+
function keep(s, delta) {
|
|
1089
|
+
if (s.discard) return;
|
|
1090
|
+
if (s.held === 0) absorb(s, delta);
|
|
1091
|
+
else setBeside(s, s.beside ? plus(s.beside, delta) : delta.slice());
|
|
1092
|
+
s.row?.table.mark(s.row.index);
|
|
1093
|
+
}
|
|
1094
|
+
function takeUp(s) {
|
|
1095
|
+
const committed = s.axes.to(s.get());
|
|
1096
|
+
const beside = s.beside;
|
|
1097
|
+
if (beside) setBeside(s, null);
|
|
1098
|
+
return beside ? plus(committed, beside) : committed;
|
|
1099
|
+
}
|
|
1100
|
+
function createTargetBook(owner) {
|
|
1101
|
+
const adjusted = [];
|
|
1102
|
+
const token = { ...owner, adjusted: (s) => {
|
|
1103
|
+
adjusted.push(s);
|
|
1104
|
+
} };
|
|
1105
|
+
const showing2 = /* @__PURE__ */ new Set();
|
|
1106
|
+
const rested = /* @__PURE__ */ new Set();
|
|
1107
|
+
const publishes = /* @__PURE__ */ new Set();
|
|
1108
|
+
const tables2 = /* @__PURE__ */ new Map();
|
|
1109
|
+
const stores = /* @__PURE__ */ new Map();
|
|
1110
|
+
const shown = (s, value) => {
|
|
1111
|
+
s.show(value);
|
|
1112
|
+
if (s.publish) publishes.add(s.publish);
|
|
1113
|
+
};
|
|
1114
|
+
const publish = () => {
|
|
1115
|
+
for (const p of publishes) p();
|
|
1116
|
+
publishes.clear();
|
|
1117
|
+
};
|
|
1118
|
+
return {
|
|
1119
|
+
attach(s) {
|
|
1120
|
+
if (s.owner && s.owner !== token) {
|
|
1121
|
+
throw new Error("animator: this target is being moved by another animator");
|
|
1122
|
+
}
|
|
1123
|
+
s.owner = token;
|
|
1124
|
+
s.live += 1;
|
|
1125
|
+
if (s.show) showing2.add(s);
|
|
1126
|
+
rested.delete(s);
|
|
1127
|
+
if (s.row) {
|
|
1128
|
+
tables2.set(s.row.table, (tables2.get(s.row.table) ?? 0) + 1);
|
|
1129
|
+
s.row.table.mark(s.row.index);
|
|
1130
|
+
}
|
|
1131
|
+
},
|
|
1132
|
+
detach(s) {
|
|
1133
|
+
s.live -= 1;
|
|
1134
|
+
if (s.row) {
|
|
1135
|
+
tables2.set(s.row.table, tables2.get(s.row.table) - 1);
|
|
1136
|
+
s.row.table.mark(s.row.index);
|
|
1137
|
+
}
|
|
1138
|
+
if (s.live > 0) return;
|
|
1139
|
+
s.owner = null;
|
|
1140
|
+
s.slot = null;
|
|
1141
|
+
if (s.beside) setBeside(s, null);
|
|
1142
|
+
for (const b of s.behind) b.move?.leave();
|
|
1143
|
+
s.behind.length = 0;
|
|
1144
|
+
s.dimmed = false;
|
|
1145
|
+
s.adjust.fill(0);
|
|
1146
|
+
s.stale = false;
|
|
1147
|
+
if (s.show && showing2.delete(s)) rested.add(s);
|
|
1148
|
+
},
|
|
1149
|
+
settle() {
|
|
1150
|
+
for (const s of adjusted) {
|
|
1151
|
+
if (!s.stale || s.owner !== token) continue;
|
|
1152
|
+
s.adjust.fill(0);
|
|
1153
|
+
for (const b of s.behind) b.adjust = null;
|
|
1154
|
+
s.stale = false;
|
|
1155
|
+
}
|
|
1156
|
+
adjusted.length = 0;
|
|
1157
|
+
for (const store of stores.keys()) store.frame();
|
|
1158
|
+
for (const t of tables2.keys()) t.settle();
|
|
1159
|
+
},
|
|
1160
|
+
holding(store, by) {
|
|
1161
|
+
const count = (stores.get(store) ?? 0) + by;
|
|
1162
|
+
if (count > 0) stores.set(store, count);
|
|
1163
|
+
else stores.delete(store);
|
|
1164
|
+
},
|
|
1165
|
+
show() {
|
|
1166
|
+
for (const s of showing2) shown(s, readTarget(s));
|
|
1167
|
+
for (const s of rested) shown(s, s.get());
|
|
1168
|
+
rested.clear();
|
|
1169
|
+
for (const [t, moving] of tables2) {
|
|
1170
|
+
t.fill(owner.columns);
|
|
1171
|
+
if (moving === 0) tables2.delete(t);
|
|
1172
|
+
}
|
|
1173
|
+
publish();
|
|
1174
|
+
},
|
|
1175
|
+
showNow(s) {
|
|
1176
|
+
if (!s.show) return;
|
|
1177
|
+
shown(s, readTarget(s));
|
|
1178
|
+
publish();
|
|
1179
|
+
},
|
|
1180
|
+
get resting() {
|
|
1181
|
+
return rested.size > 0;
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1071
1185
|
|
|
1072
1186
|
// src/timeline/targetStops.ts
|
|
1073
1187
|
function targetStops(track) {
|
|
@@ -1620,6 +1734,6 @@ function createTimeline(register, id, opts, report, hold) {
|
|
|
1620
1734
|
};
|
|
1621
1735
|
}
|
|
1622
1736
|
|
|
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,
|
|
1624
|
-
//# sourceMappingURL=chunk-
|
|
1625
|
-
//# sourceMappingURL=chunk-
|
|
1737
|
+
export { ColorOverrideRegistry, TrimOverrideRegistry, 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 };
|
|
1738
|
+
//# sourceMappingURL=chunk-TXKTFZIW.js.map
|
|
1739
|
+
//# sourceMappingURL=chunk-TXKTFZIW.js.map
|