figureone 1.4.1 → 1.5.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/index.js CHANGED
@@ -20257,6 +20257,32 @@ var GoToFormAnimationStep = /*#__PURE__*/function (_TriggerAnimationStep2) {
20257
20257
  * * {@link GoToFormAnimationStep}
20258
20258
  * * {@link NextFormAnimationStep}
20259
20259
  *
20260
+ * In addition to the notifications published by {@link FigureElement}, an
20261
+ * Equation publishes a `formChanged` notification whenever the displayed form
20262
+ * may have changed. The payload is an object
20263
+ * `{ phase, form, fromForm?, progress? }` where `phase` is one of:
20264
+ * - `'showForm'`: a form was set via `showForm`. Callers can suppress this
20265
+ * event by passing `notify: false` to `showForm`; internal `showForm`
20266
+ * calls made by `goToForm` do this so the `goToForm*` event stream is
20267
+ * not interleaved with stray `showForm` events.
20268
+ * - `'goToFormStart'`: a `goToForm` call has just begun
20269
+ * - `'goToFormStep'`: published on every animation frame during a `goToForm`
20270
+ * animation; `progress` is the percentage (0-1) through the animation. A
20271
+ * final `goToFormStep` with `progress: 1` is always published immediately
20272
+ * before `goToFormEnd`
20273
+ * - `'goToFormEnd'`: a `goToForm` call has finished
20274
+ *
20275
+ * * `fromForm` is only included on the `goToForm*` phases (it carries the
20276
+ * `fromWhere` option from `goToForm`); it is absent on `showForm`. `progress`
20277
+ * is only included on `goToFormStep`. The event order for a `goToForm` call
20278
+ * is always: `goToFormStart` → zero-or-more `goToFormStep` → `goToFormStep`
20279
+ * with `progress: 1` → `goToFormEnd`.
20280
+ *
20281
+ * A user-initiated `showForm` made while a `goToForm` animation is running
20282
+ * will publish its `showForm` event interleaved with the ongoing
20283
+ * `goToFormStep` stream — listeners that drive UI from "the current
20284
+ * transition" should account for this. Pass `notify: false` to suppress.
20285
+ *
20260
20286
  * @extends FigureElementCollection
20261
20287
  *
20262
20288
  * @see To test examples, append them to the
@@ -21442,6 +21468,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21442
21468
  this.stopAnimating(how, '_Equation', true);
21443
21469
  this.stopAnimating(how, '_EquationColor', true);
21444
21470
  this.stopAnimating(how, '_EquationAnimateColor', true);
21471
+ this.stopAnimating(how, '_EquationFormStep', true);
21445
21472
  this.stopPulsing(how);
21446
21473
  }
21447
21474
  }, {
@@ -21634,13 +21661,26 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21634
21661
  /**
21635
21662
  * Show equation form
21636
21663
  */
21664
+ /**
21665
+ * Show equation form.
21666
+ *
21667
+ * @param formOrName the form, or its name, to show
21668
+ * @param animationStop if `true`, stops any in-progress element animations
21669
+ * before rendering the form (default `true`)
21670
+ * @param notify if `true`, publish a `formChanged` notification with
21671
+ * `phase: 'showForm'` (default `true`). Pass `false` to suppress the
21672
+ * event — useful for bulk updates or when this `showForm` is part of a
21673
+ * larger transition the caller is broadcasting separately. The internal
21674
+ * `showForm` calls made by `goToForm` use `false` so the `goToForm*`
21675
+ * event stream is not interleaved with stray `showForm` events.
21676
+ */
21637
21677
  }, {
21638
21678
  key: "showForm",
21639
21679
  value: function showForm() {
21640
21680
  var formOrName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : this.eqn.currentForm;
21641
21681
  var animationStop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
21682
+ var notify = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
21642
21683
  _superPropGet(Equation, "show", this, 3)([]);
21643
- // this.custom.settingForm = true;
21644
21684
  var form = formOrName;
21645
21685
  if (typeof formOrName === 'string') {
21646
21686
  form = this.getForm(formOrName);
@@ -21651,6 +21691,12 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21651
21691
  this.render(animationStop);
21652
21692
  this.fnMap.exec(form.onTransition);
21653
21693
  this.fnMap.exec(form.onShow);
21694
+ if (notify) {
21695
+ this.notifications.publish('formChanged', {
21696
+ phase: 'showForm',
21697
+ form: form
21698
+ });
21699
+ }
21654
21700
  }
21655
21701
  }
21656
21702
  }, {
@@ -21729,7 +21775,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21729
21775
  // this.stopEquationAnimating('complete');
21730
21776
  var currentForm = this.getCurrentForm();
21731
21777
  if (currentForm != null) {
21732
- this.showForm(currentForm);
21778
+ this.showForm(currentForm, true, false);
21733
21779
  }
21734
21780
  } else {
21735
21781
  // this.stopEquationAnimating('cancel');
@@ -21813,20 +21859,65 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21813
21859
  }
21814
21860
  }
21815
21861
  if (duration === 0) {
21816
- this.showForm(form);
21862
+ this.notifications.publish('formChanged', {
21863
+ phase: 'goToFormStart',
21864
+ form: form,
21865
+ fromForm: options.fromWhere
21866
+ });
21867
+ this.showForm(form, true, false);
21817
21868
  this.fnMap.exec(options.callback);
21869
+ this.notifications.publish('formChanged', {
21870
+ phase: 'goToFormStep',
21871
+ form: form,
21872
+ fromForm: options.fromWhere,
21873
+ progress: 1
21874
+ });
21875
+ this.notifications.publish('formChanged', {
21876
+ phase: 'goToFormEnd',
21877
+ form: form,
21878
+ fromForm: options.fromWhere
21879
+ });
21818
21880
  } else {
21819
21881
  this.eqn.isAnimating = true;
21820
21882
  this.fnMap.exec(onTransition);
21883
+ // Set the current form before publishing goToFormStart so listeners
21884
+ // that call getCurrentForm() see the target form, matching the payload.
21885
+ this.setCurrentForm(form);
21886
+ this.notifications.publish('formChanged', {
21887
+ phase: 'goToFormStart',
21888
+ form: form,
21889
+ fromForm: options.fromWhere
21890
+ });
21891
+ var stepStarted = false;
21821
21892
  var end = function end() {
21822
21893
  _this1.fnMap.exec(form.onShow);
21823
21894
  _this1.eqn.isAnimating = false;
21824
21895
  _this1.fnMap.exec(options.callback);
21896
+ // Cancelling the step ticker stops any further frame callbacks
21897
+ // after end(). It cannot retract a step(p:1) the ticker may have
21898
+ // already published earlier in this frame, so the ticker callback
21899
+ // also skips p===1 — the manual publish below is the single
21900
+ // canonical terminal step event.
21901
+ if (stepStarted) {
21902
+ _this1.stopAnimating('cancel', '_EquationFormStep', true);
21903
+ }
21904
+ _this1.notifications.publish('formChanged', {
21905
+ phase: 'goToFormStep',
21906
+ form: form,
21907
+ fromForm: options.fromWhere,
21908
+ progress: 1
21909
+ });
21910
+ _this1.notifications.publish('formChanged', {
21911
+ phase: 'goToFormEnd',
21912
+ form: form,
21913
+ fromForm: options.fromWhere
21914
+ });
21825
21915
  };
21916
+ var totalTime = 0;
21826
21917
  if (options.animate === 'move') {
21827
- form.animatePositionsTo(options.delay, options.dissolveOutTime, duration, options.dissolveInTime, end, options.fromWhere, false);
21918
+ totalTime = form.animatePositionsTo(options.delay, options.dissolveOutTime, duration, options.dissolveInTime, end, options.fromWhere, false);
21828
21919
  } else if (options.animate === 'dissolveInThenMove') {
21829
- form.animatePositionsTo(options.delay, options.dissolveOutTime, duration, options.dissolveInTime, end, options.fromWhere, true);
21920
+ totalTime = form.animatePositionsTo(options.delay, options.dissolveOutTime, duration, options.dissolveInTime, end, options.fromWhere, true);
21830
21921
  } else if (options.animate === 'moveFrom' && this.eqn.formRestart != null && this.eqn.formRestart.moveFrom != null) {
21831
21922
  var moveFrom = this.eqn.formRestart.moveFrom;
21832
21923
  var target = this.getPosition();
@@ -21840,7 +21931,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21840
21931
  start = (0,_tools_g2__WEBPACK_IMPORTED_MODULE_0__.getPoint)(this.eqn.formRestart.moveFrom);
21841
21932
  }
21842
21933
  var showFormCallback = function showFormCallback() {
21843
- _this1.showForm(form.name, false);
21934
+ _this1.showForm(form.name, false, false);
21844
21935
  };
21845
21936
  this.fnMap.add('_equationShowFormCallback', showFormCallback);
21846
21937
  this.animations["new"]('_Equation').dissolveOut({
@@ -21855,6 +21946,14 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21855
21946
  target: target,
21856
21947
  duration: duration
21857
21948
  }).whenFinished(end).start();
21949
+ if (duration != null) {
21950
+ totalTime = options.delay + options.dissolveOutTime + 0.01 + duration;
21951
+ } else {
21952
+ // duration is null — the position step computes a velocity-based
21953
+ // move time internally. Read it back from the chain we just
21954
+ // started so the step ticker still covers the full animation.
21955
+ totalTime = this.animations.getRemainingTime('_Equation');
21956
+ }
21858
21957
  } else if (options.animate === 'pulse' && this.eqn.formRestart != null && this.eqn.formRestart.pulse != null) {
21859
21958
  var pulse = this.eqn.formRestart.pulse;
21860
21959
  var newEnd = function newEnd() {
@@ -21871,11 +21970,30 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21871
21970
  });
21872
21971
  }
21873
21972
  };
21874
- form.allHideShow(options.delay, options.dissolveOutTime, options.blankTime, options.dissolveInTime, newEnd);
21973
+ var hideShowTime = form.allHideShow(options.delay, options.dissolveOutTime, options.blankTime, options.dissolveInTime, newEnd);
21974
+ totalTime = hideShowTime + (pulse.duration != null ? pulse.duration : 0);
21875
21975
  } else {
21876
- form.allHideShow(options.delay, options.dissolveOutTime, options.blankTime, options.dissolveInTime, end);
21976
+ totalTime = form.allHideShow(options.delay, options.dissolveOutTime, options.blankTime, options.dissolveInTime, end);
21977
+ }
21978
+ if (totalTime > 0) {
21979
+ this.animations["new"]('_EquationFormStep').custom({
21980
+ callback: function callback(p) {
21981
+ // Skip the terminal tick — end() publishes the canonical
21982
+ // step(p:1) so the ticker would otherwise duplicate it (and
21983
+ // CustomAnimationStep can land on p=1 twice via
21984
+ // nextFrame + finish()).
21985
+ if (p >= 1) return;
21986
+ _this1.notifications.publish('formChanged', {
21987
+ phase: 'goToFormStep',
21988
+ form: form,
21989
+ fromForm: options.fromWhere,
21990
+ progress: p
21991
+ });
21992
+ },
21993
+ duration: totalTime
21994
+ }).start();
21995
+ stepStarted = true;
21877
21996
  }
21878
- this.setCurrentForm(form);
21879
21997
  }
21880
21998
  }
21881
21999
  }, {
@@ -21986,7 +22104,7 @@ var Equation = /*#__PURE__*/function (_FigureElementCollect) {
21986
22104
  this.eqn.isAnimating = false;
21987
22105
  var currentForm = this.getCurrentForm();
21988
22106
  if (currentForm != null) {
21989
- this.showForm(currentForm);
22107
+ this.showForm(currentForm, true, false);
21990
22108
  }
21991
22109
  return;
21992
22110
  }
@@ -22542,8 +22660,8 @@ var EquationForm = /*#__PURE__*/function (_Elements) {
22542
22660
  if (elementsToShow.length === 0 && elementsShown.length === 0) {
22543
22661
  if (callback != null) {
22544
22662
  callback(false);
22545
- return;
22546
22663
  }
22664
+ return 0;
22547
22665
  }
22548
22666
  var dissolveOutCallback = function dissolveOutCallback() {
22549
22667
  _this3.setPositions();
@@ -22587,6 +22705,13 @@ var EquationForm = /*#__PURE__*/function (_Elements) {
22587
22705
  delay: blankTime
22588
22706
  }).start();
22589
22707
  });
22708
+ if (elementsToShow.length > 0) {
22709
+ cumTime += blankTime + showTime;
22710
+ }
22711
+ // Upper bound on the total animation time: when elementsToDelayShowing
22712
+ // finish their dissolveIn. elementsToShowAfterDissolve are scheduled with
22713
+ // `delay: blankTime` (not `cumTime + blankTime`) so they may finish earlier.
22714
+ return cumTime;
22590
22715
  }
22591
22716
  }, {
22592
22717
  key: "applyElementMods",
@@ -80795,8 +80920,8 @@ var tools = {
80795
80920
  */
80796
80921
 
80797
80922
  var Fig = {
80798
- version: "1.4.1",
80799
- gitHash: "2fa15b061",
80923
+ version: "1.5.0",
80924
+ gitHash: "2390662f6",
80800
80925
  tools: tools,
80801
80926
  Figure: _js_figure_Figure__WEBPACK_IMPORTED_MODULE_5__["default"],
80802
80927
  Recorder: _js_figure_Recorder_Recorder__WEBPACK_IMPORTED_MODULE_7__.Recorder,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "figureone",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "Draw, animate and interact with shapes, text, plots and equations in Javascript. Create interactive slide shows, and interactive videos.",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -726,6 +726,32 @@ type EQN_EquationGoToForm = {
726
726
  * * {@link GoToFormAnimationStep}
727
727
  * * {@link NextFormAnimationStep}
728
728
  *
729
+ * In addition to the notifications published by {@link FigureElement}, an
730
+ * Equation publishes a `formChanged` notification whenever the displayed form
731
+ * may have changed. The payload is an object
732
+ * `{ phase, form, fromForm?, progress? }` where `phase` is one of:
733
+ * - `'showForm'`: a form was set via `showForm`. Callers can suppress this
734
+ * event by passing `notify: false` to `showForm`; internal `showForm`
735
+ * calls made by `goToForm` do this so the `goToForm*` event stream is
736
+ * not interleaved with stray `showForm` events.
737
+ * - `'goToFormStart'`: a `goToForm` call has just begun
738
+ * - `'goToFormStep'`: published on every animation frame during a `goToForm`
739
+ * animation; `progress` is the percentage (0-1) through the animation. A
740
+ * final `goToFormStep` with `progress: 1` is always published immediately
741
+ * before `goToFormEnd`
742
+ * - `'goToFormEnd'`: a `goToForm` call has finished
743
+ *
744
+ * * `fromForm` is only included on the `goToForm*` phases (it carries the
745
+ * `fromWhere` option from `goToForm`); it is absent on `showForm`. `progress`
746
+ * is only included on `goToFormStep`. The event order for a `goToForm` call
747
+ * is always: `goToFormStart` → zero-or-more `goToFormStep` → `goToFormStep`
748
+ * with `progress: 1` → `goToFormEnd`.
749
+ *
750
+ * A user-initiated `showForm` made while a `goToForm` animation is running
751
+ * will publish its `showForm` event interleaved with the ongoing
752
+ * `goToFormStep` stream — listeners that drive UI from "the current
753
+ * transition" should account for this. Pass `notify: false` to suppress.
754
+ *
729
755
  * @extends FigureElementCollection
730
756
  *
731
757
  * @see To test examples, append them to the
@@ -979,7 +1005,20 @@ export declare class Equation extends FigureElementCollection {
979
1005
  /**
980
1006
  * Show equation form
981
1007
  */
982
- showForm(formOrName?: EquationForm | string, animationStop?: boolean): void;
1008
+ /**
1009
+ * Show equation form.
1010
+ *
1011
+ * @param formOrName the form, or its name, to show
1012
+ * @param animationStop if `true`, stops any in-progress element animations
1013
+ * before rendering the form (default `true`)
1014
+ * @param notify if `true`, publish a `formChanged` notification with
1015
+ * `phase: 'showForm'` (default `true`). Pass `false` to suppress the
1016
+ * event — useful for bulk updates or when this `showForm` is part of a
1017
+ * larger transition the caller is broadcasting separately. The internal
1018
+ * `showForm` calls made by `goToForm` use `false` so the `goToForm*`
1019
+ * event stream is not interleaved with stray `showForm` events.
1020
+ */
1021
+ showForm(formOrName?: EquationForm | string, animationStop?: boolean, notify?: boolean): void;
983
1022
  showAll(): void;
984
1023
  cleanup(): void;
985
1024
  cleanupForms(): void;
@@ -133,7 +133,7 @@ export default class EquationForm extends Elements {
133
133
  render(): void;
134
134
  showHide(showTime?: number, hideTime?: number, callback?: ((arg?: any) => void) | null, animationStop?: boolean): void;
135
135
  hideShow(showTime?: number, hideTime?: number, callback?: ((arg?: any) => void) | null, animationStop?: boolean): void;
136
- allHideShow(delay?: number, hideTime?: number, blankTime?: number, showTime?: number, callback?: ((cancelled: boolean) => void) | null): void;
136
+ allHideShow(delay?: number, hideTime?: number, blankTime?: number, showTime?: number, callback?: ((cancelled: boolean) => void) | null): number;
137
137
  applyElementMods(fromWhere?: null | string): void;
138
138
  animatePositionsTo(delay: number, dissolveOutTime: number, moveTime: number | null, dissolveInTime: number, callback?: (string | ((arg?: any) => void)) | null, fromWhere?: string | null | undefined, dissolveInBeforeMove?: boolean): number;
139
139
  }