@smoove/core 0.1.3 → 0.1.4

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/README.md CHANGED
@@ -41,7 +41,7 @@ const comp = new Composition({
41
41
  });
42
42
 
43
43
  // A sequence covering the whole composition, like a "root" layer.
44
- const main = new Sequence({ from: 0, durationInFrames: 300 });
44
+ const main = new Sequence();
45
45
  const circle = new Circle({ x: 100, y: 300, radius: 40, fill: "tomato" });
46
46
  main.add(circle);
47
47
  comp.add(main);
@@ -1,7 +1,13 @@
1
1
  import Konva from "konva";
2
2
  export type SequenceOptions = Konva.LayerConfig & {
3
- from: number;
4
- durationInFrames: number;
3
+ /** Composition frame this sequence starts on. Defaults to `0`. */
4
+ from?: number;
5
+ /**
6
+ * How many frames the sequence spans. When omitted it defaults to the host
7
+ * composition's `durationInFrames` — i.e. a layer spanning the whole comp.
8
+ * Resolved live once added (see {@link Sequence.durationInFrames}).
9
+ */
10
+ durationInFrames?: number;
5
11
  };
6
12
  export type Updater = (localFrame: number) => void;
7
13
  /**
@@ -15,12 +21,22 @@ export type SequenceProvider = {
15
21
  };
16
22
  export declare class Sequence extends Konva.Layer {
17
23
  readonly from: number;
18
- readonly durationInFrames: number;
24
+ /** Explicit span, or `undefined` to default to the host comp's duration. */
25
+ private readonly _durationInFrames?;
19
26
  private readonly _updaters;
20
27
  private _active;
21
28
  private _media;
22
29
  private _lastLocal;
23
- constructor(opts: SequenceOptions);
30
+ constructor(opts?: SequenceOptions);
31
+ /**
32
+ * Frames this sequence spans. When constructed without an explicit
33
+ * `durationInFrames`, this resolves **live** to the host composition's
34
+ * `durationInFrames` — a layer that spans the whole comp. Before the sequence
35
+ * is added to a composition (no reachable stage) it reports `Infinity`,
36
+ * meaning "unbounded"; `_apply` is only ever driven by the comp, so by then
37
+ * the real duration is reachable.
38
+ */
39
+ get durationInFrames(): number;
24
40
  register(updater: Updater): () => void;
25
41
  /**
26
42
  * Internal — called by Composition on each frame change.
@@ -1 +1 @@
1
- {"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../../src/engine/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,GAAG;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAAE,SAAS,IAAI,QAAQ,EAAE,CAAA;CAAE,CAAC;AAQ3D,qBAAa,QAAS,SAAQ,KAAK,CAAC,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAmB;IAIjC,OAAO,CAAC,UAAU,CAAM;gBAEZ,IAAI,EAAE,eAAe;IAajC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,IAAI;IAOtC;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,IAAI;IAsC1C;;;;;OAKG;IACH,OAAO,IAAI,IAAI;CAOhB"}
1
+ {"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../../src/engine/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,GAAG;IAChD,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAAE,SAAS,IAAI,QAAQ,EAAE,CAAA;CAAE,CAAC;AAQ3D,qBAAa,QAAS,SAAQ,KAAK,CAAC,KAAK;IACvC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,4EAA4E;IAC5E,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAS;IAC5C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAmB;IAIjC,OAAO,CAAC,UAAU,CAAM;gBAEZ,IAAI,GAAE,eAAoB;IAetC;;;;;;;OAOG;IACH,IAAI,gBAAgB,IAAI,MAAM,CAK7B;IAED,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,IAAI;IAOtC;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,UAAQ,GAAG,IAAI;IAsC1C;;;;;OAKG;IACH,OAAO,IAAI,IAAI;CAOhB"}
@@ -1,9 +1,11 @@
1
1
  import Konva from "konva";
2
2
  import { isKMLayoutRoot } from "../layout/contract.js";
3
3
  import { MEDIA_MARK, TICK_MARK } from "../media/media-marker.js";
4
+ import { getComposition } from "./composition.js";
4
5
  export class Sequence extends Konva.Layer {
5
6
  from;
6
- durationInFrames;
7
+ /** Explicit span, or `undefined` to default to the host comp's duration. */
8
+ _durationInFrames;
7
9
  _updaters = new Set();
8
10
  _active = false;
9
11
  _media = [];
@@ -11,17 +13,34 @@ export class Sequence extends Konva.Layer {
11
13
  // (updaters + layout + draw) when nothing about the playhead changed. `-1` is
12
14
  // a sentinel that never equals a real local frame, so the first apply always runs.
13
15
  _lastLocal = -1;
14
- constructor(opts) {
15
- if (!Number.isInteger(opts.from) || opts.from < 0) {
16
+ constructor(opts = {}) {
17
+ const { from = 0, durationInFrames, ...layerOpts } = opts;
18
+ if (!Number.isInteger(from) || from < 0) {
16
19
  throw new Error("Sequence: from must be a non-negative integer");
17
20
  }
18
- if (!Number.isInteger(opts.durationInFrames) || opts.durationInFrames <= 0) {
21
+ // durationInFrames is optional: when omitted it resolves to the host comp's
22
+ // duration (see the getter). Only validate an explicitly provided value.
23
+ if (durationInFrames !== undefined && (!Number.isInteger(durationInFrames) || durationInFrames <= 0)) {
19
24
  throw new Error("Sequence: durationInFrames must be a positive integer");
20
25
  }
21
- const { from, durationInFrames, ...layerOpts } = opts;
22
26
  super({ ...layerOpts, visible: false });
23
27
  this.from = from;
24
- this.durationInFrames = durationInFrames;
28
+ this._durationInFrames = durationInFrames;
29
+ }
30
+ /**
31
+ * Frames this sequence spans. When constructed without an explicit
32
+ * `durationInFrames`, this resolves **live** to the host composition's
33
+ * `durationInFrames` — a layer that spans the whole comp. Before the sequence
34
+ * is added to a composition (no reachable stage) it reports `Infinity`,
35
+ * meaning "unbounded"; `_apply` is only ever driven by the comp, so by then
36
+ * the real duration is reachable.
37
+ */
38
+ get durationInFrames() {
39
+ if (this._durationInFrames !== undefined)
40
+ return this._durationInFrames;
41
+ const stage = this.getStage();
42
+ const comp = stage && getComposition(stage);
43
+ return comp ? comp.durationInFrames.get() : Number.POSITIVE_INFINITY;
25
44
  }
26
45
  register(updater) {
27
46
  this._updaters.add(updater);
@@ -1 +1 @@
1
- {"version":3,"file":"sequence.js","sourceRoot":"","sources":["../../src/engine/sequence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAuBjE,MAAM,OAAO,QAAS,SAAQ,KAAK,CAAC,KAAK;IAC9B,IAAI,CAAS;IACb,gBAAgB,CAAS;IACjB,SAAS,GAAG,IAAI,GAAG,EAAW,CAAC;IACxC,OAA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E,CAAC;;gBACzB,IAAI,CAAC,SAAS,EAAE,CAAC;QACxB,CAAC;aAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YACpB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;YACrB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM;gBAAE,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC;QACnD,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,OAAO;QACL,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YAAE,OAAO;QAC7C,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QACrB,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM;YAAE,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC;IACnD,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smoove/core",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "A timeline-driven animation engine for Konva. Runs in the browser or on the server and renders to any target.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {