figureone 0.15.10 → 1.0.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.
Files changed (159) hide show
  1. package/figureone.min.js +1 -1
  2. package/index.js +79167 -0
  3. package/package.json +15 -1
  4. package/types/index.d.ts +132 -0
  5. package/types/js/figure/Animation/Animation.d.ts +36 -0
  6. package/types/js/figure/Animation/AnimationBuilder.d.ts +173 -0
  7. package/types/js/figure/Animation/AnimationManager.d.ts +392 -0
  8. package/types/js/figure/Animation/AnimationStep/CustomStep.d.ts +99 -0
  9. package/types/js/figure/Animation/AnimationStep/DelayStep.d.ts +24 -0
  10. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ColorAnimationStep.d.ts +203 -0
  11. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/OpacityAnimationStep.d.ts +220 -0
  12. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PositionAnimationStep.d.ts +124 -0
  13. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseAnimationStep.d.ts +137 -0
  14. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseTransformAnimationStep.d.ts +52 -0
  15. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/RotationAnimationStep.d.ts +119 -0
  16. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScaleAnimationStep.d.ts +93 -0
  17. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScenarioAnimationStep.d.ts +204 -0
  18. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/TransformAnimationStep.d.ts +163 -0
  19. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep.d.ts +56 -0
  20. package/types/js/figure/Animation/AnimationStep/ParallelAnimationStep.d.ts +70 -0
  21. package/types/js/figure/Animation/AnimationStep/SerialAnimationStep.d.ts +84 -0
  22. package/types/js/figure/Animation/AnimationStep/TriggerStep.d.ts +106 -0
  23. package/types/js/figure/Animation/AnimationStep.d.ts +110 -0
  24. package/types/js/figure/DrawContext2D.d.ts +9 -0
  25. package/types/js/figure/DrawingObjects/DrawingObject.d.ts +45 -0
  26. package/types/js/figure/DrawingObjects/GLObject/GLObject.d.ts +146 -0
  27. package/types/js/figure/DrawingObjects/HTMLObject/HTMLObject.d.ts +29 -0
  28. package/types/js/figure/DrawingObjects/TextObject/TextObject.d.ts +94 -0
  29. package/types/js/figure/DrawingObjects/TextObject/glyphMeasures.d.ts +7 -0
  30. package/types/js/figure/DrawingObjects/VertexObject/VertexGeneric.d.ts +21 -0
  31. package/types/js/figure/DrawingObjects/VertexObject/VertexObject.d.ts +0 -0
  32. package/types/js/figure/DrawingObjects/VertexObject/VertexText.d.ts +34 -0
  33. package/types/js/figure/Element.d.ts +1212 -0
  34. package/types/js/figure/Equation/Elements/BaseAnnotationFunction.d.ts +118 -0
  35. package/types/js/figure/Equation/Elements/BaseEquationFunction.d.ts +20 -0
  36. package/types/js/figure/Equation/Elements/Bounds.d.ts +49 -0
  37. package/types/js/figure/Equation/Elements/Color.d.ts +7 -0
  38. package/types/js/figure/Equation/Elements/Container.d.ts +5 -0
  39. package/types/js/figure/Equation/Elements/Element.d.ts +95 -0
  40. package/types/js/figure/Equation/Elements/Fraction.d.ts +5 -0
  41. package/types/js/figure/Equation/Elements/Lines.d.ts +5 -0
  42. package/types/js/figure/Equation/Elements/Matrix.d.ts +5 -0
  43. package/types/js/figure/Equation/Elements/Offset.d.ts +5 -0
  44. package/types/js/figure/Equation/Elements/Scale.d.ts +5 -0
  45. package/types/js/figure/Equation/Equation.d.ts +984 -0
  46. package/types/js/figure/Equation/EquationForm.d.ts +139 -0
  47. package/types/js/figure/Equation/EquationFunctions.d.ts +3367 -0
  48. package/types/js/figure/Equation/EquationSymbols.d.ts +1646 -0
  49. package/types/js/figure/Equation/HTMLEquation.d.ts +56 -0
  50. package/types/js/figure/Equation/Symbols/AngleBracket.d.ts +6 -0
  51. package/types/js/figure/Equation/Symbols/Arrow.d.ts +17 -0
  52. package/types/js/figure/Equation/Symbols/Bar.d.ts +6 -0
  53. package/types/js/figure/Equation/Symbols/Box.d.ts +11 -0
  54. package/types/js/figure/Equation/Symbols/Brace.d.ts +6 -0
  55. package/types/js/figure/Equation/Symbols/Bracket.d.ts +8 -0
  56. package/types/js/figure/Equation/Symbols/Division.d.ts +8 -0
  57. package/types/js/figure/Equation/Symbols/Integral.d.ts +7 -0
  58. package/types/js/figure/Equation/Symbols/Line.d.ts +5 -0
  59. package/types/js/figure/Equation/Symbols/Product.d.ts +6 -0
  60. package/types/js/figure/Equation/Symbols/Radical.d.ts +9 -0
  61. package/types/js/figure/Equation/Symbols/SquareBracket.d.ts +6 -0
  62. package/types/js/figure/Equation/Symbols/Strike.d.ts +8 -0
  63. package/types/js/figure/Equation/Symbols/Sum.d.ts +6 -0
  64. package/types/js/figure/Equation/Symbols/SymbolNew.d.ts +15 -0
  65. package/types/js/figure/Equation/Symbols/Vinculum.d.ts +6 -0
  66. package/types/js/figure/Figure.d.ts +711 -0
  67. package/types/js/figure/FigureCollections/Angle.d.ts +766 -0
  68. package/types/js/figure/FigureCollections/Axis.d.ts +517 -0
  69. package/types/js/figure/FigureCollections/Axis3.d.ts +118 -0
  70. package/types/js/figure/FigureCollections/Button.d.ts +195 -0
  71. package/types/js/figure/FigureCollections/EquationLabel.d.ts +77 -0
  72. package/types/js/figure/FigureCollections/FigureCollections.d.ts +122 -0
  73. package/types/js/figure/FigureCollections/Legend.d.ts +270 -0
  74. package/types/js/figure/FigureCollections/Line.d.ts +587 -0
  75. package/types/js/figure/FigureCollections/Plot.d.ts +558 -0
  76. package/types/js/figure/FigureCollections/PolyLine.d.ts +487 -0
  77. package/types/js/figure/FigureCollections/Rectangle.d.ts +235 -0
  78. package/types/js/figure/FigureCollections/SlideNavigator.d.ts +255 -0
  79. package/types/js/figure/FigureCollections/Slider.d.ts +155 -0
  80. package/types/js/figure/FigureCollections/Text.d.ts +307 -0
  81. package/types/js/figure/FigureCollections/Toggle.d.ts +185 -0
  82. package/types/js/figure/FigureCollections/Trace.d.ts +237 -0
  83. package/types/js/figure/FigurePrimitives/FigureElementPrimitive2DText.d.ts +119 -0
  84. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGLText.d.ts +94 -0
  85. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGesture.d.ts +536 -0
  86. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveMorph.d.ts +175 -0
  87. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes.d.ts +788 -0
  88. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes2D.d.ts +1324 -0
  89. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes3D.d.ts +1105 -0
  90. package/types/js/figure/FigurePrimitives/FigurePrimitives.d.ts +173 -0
  91. package/types/js/figure/FigurePrimitives/Generic.d.ts +5 -0
  92. package/types/js/figure/FigurePrimitives/Text.d.ts +17 -0
  93. package/types/js/figure/FontManager.d.ts +113 -0
  94. package/types/js/figure/Gesture.d.ts +39 -0
  95. package/types/js/figure/Recorder/Recorder.d.ts +291 -0
  96. package/types/js/figure/Recorder/parseState.d.ts +3 -0
  97. package/types/js/figure/Recorder/recorder.worker.d.ts +1 -0
  98. package/types/js/figure/Recorder/state.d.ts +7 -0
  99. package/types/js/figure/SlideNavigator.d.ts +606 -0
  100. package/types/js/figure/TimeKeeper.d.ts +174 -0
  101. package/types/js/figure/geometries/arc.d.ts +18 -0
  102. package/types/js/figure/geometries/arrow.d.ts +215 -0
  103. package/types/js/figure/geometries/buffer.d.ts +4 -0
  104. package/types/js/figure/geometries/copy/copy.d.ts +178 -0
  105. package/types/js/figure/geometries/ellipse.d.ts +17 -0
  106. package/types/js/figure/geometries/line.d.ts +13 -0
  107. package/types/js/figure/geometries/lines/corners.d.ts +7 -0
  108. package/types/js/figure/geometries/lines/dashes.d.ts +23 -0
  109. package/types/js/figure/geometries/lines/lines.d.ts +31 -0
  110. package/types/js/figure/geometries/polygon/polygon.d.ts +12 -0
  111. package/types/js/figure/geometries/rectangle.d.ts +19 -0
  112. package/types/js/figure/geometries/triangle.d.ts +27 -0
  113. package/types/js/figure/webgl/Atlas.d.ts +42 -0
  114. package/types/js/figure/webgl/shaders.d.ts +143 -0
  115. package/types/js/figure/webgl/target.d.ts +9 -0
  116. package/types/js/figure/webgl/webgl.d.ts +54 -0
  117. package/types/js/tools/FunctionMap.d.ts +69 -0
  118. package/types/js/tools/color.d.ts +11 -0
  119. package/types/js/tools/colorNames.d.ts +2 -0
  120. package/types/js/tools/d2/polygon.d.ts +60 -0
  121. package/types/js/tools/d2/triangles.d.ts +0 -0
  122. package/types/js/tools/d3/cone.d.ts +57 -0
  123. package/types/js/tools/d3/cube.d.ts +26 -0
  124. package/types/js/tools/d3/cylinder.d.ts +45 -0
  125. package/types/js/tools/d3/line3.d.ts +55 -0
  126. package/types/js/tools/d3/prism.d.ts +49 -0
  127. package/types/js/tools/d3/revolve.d.ts +87 -0
  128. package/types/js/tools/d3/sphere.d.ts +33 -0
  129. package/types/js/tools/d3/surface.d.ts +47 -0
  130. package/types/js/tools/g2.d.ts +242 -0
  131. package/types/js/tools/geometry/Bounds.d.ts +446 -0
  132. package/types/js/tools/geometry/Line.d.ts +314 -0
  133. package/types/js/tools/geometry/Path.d.ts +67 -0
  134. package/types/js/tools/geometry/Plane.d.ts +201 -0
  135. package/types/js/tools/geometry/Point.d.ts +359 -0
  136. package/types/js/tools/geometry/Rect.d.ts +115 -0
  137. package/types/js/tools/geometry/Transform.d.ts +623 -0
  138. package/types/js/tools/geometry/angle.d.ts +105 -0
  139. package/types/js/tools/geometry/common.d.ts +9 -0
  140. package/types/js/tools/geometry/coordinates.d.ts +30 -0
  141. package/types/js/tools/geometry/deceleration.d.ts +13 -0
  142. package/types/js/tools/geometry/polygon.d.ts +4 -0
  143. package/types/js/tools/geometry/quaternion.d.ts +15 -0
  144. package/types/js/tools/geometry/scene.d.ts +282 -0
  145. package/types/js/tools/geometry/tools.d.ts +8 -0
  146. package/types/js/tools/geometry/types.d.ts +2 -0
  147. package/types/js/tools/getCssColors.d.ts +1 -0
  148. package/types/js/tools/getCssVariables.d.ts +4 -0
  149. package/types/js/tools/getImageData.d.ts +1 -0
  150. package/types/js/tools/getScssColors.d.ts +2 -0
  151. package/types/js/tools/htmlGenerator.d.ts +85 -0
  152. package/types/js/tools/m2.d.ts +24 -0
  153. package/types/js/tools/m3.d.ts +71 -0
  154. package/types/js/tools/math.d.ts +112 -0
  155. package/types/js/tools/morph.d.ts +651 -0
  156. package/types/js/tools/styleSheets.d.ts +3 -0
  157. package/types/js/tools/tools.d.ts +281 -0
  158. package/types/js/tools/types.d.ts +305 -0
  159. package/figureone.worker.js +0 -1
@@ -0,0 +1,606 @@
1
+ import { NotificationManager } from '../tools/tools';
2
+ import { FigureElementCollection } from './Element';
3
+ import type { FigureElement, TypeElementPath } from './Element';
4
+ import type { OBJ_Collection } from './FigurePrimitives/FigurePrimitiveTypes';
5
+ import type { OBJ_TextModifiersDefinition } from './FigurePrimitives/FigurePrimitiveTypes2D';
6
+ import type Figure from './Figure';
7
+ import { Equation } from './Equation/Equation';
8
+ import type AnimationStep from './Animation/AnimationStep';
9
+ import type CollectionsText from './FigureCollections/Text';
10
+ import type { OBJ_FormattedText } from './FigureCollections/Text';
11
+ /**
12
+ * Last slide shown
13
+ *
14
+ * `'next'` | `'prev'` | number
15
+ * @group Slide Navigator
16
+ */
17
+ export type TypeSlideFrom = 'next' | 'prev' | number;
18
+ /**
19
+ * `(currentIndex: number, nextIndex: number) => void`
20
+ *
21
+ * When using {@link Recorder}, a string from a {@link FunctionMap} can be
22
+ * used, as long as the function the string maps to allows for the same
23
+ * parameters as above.
24
+ * @group Slide Navigator
25
+ */
26
+ export type TypeSlideLeaveStateCallback = string | ((currentIndex: number, nextIndex: number) => void);
27
+ /**
28
+ * `(currentIndex: number, from: `{@link TypeSlideFrom}`) => void`
29
+ *
30
+ * When using {@link Recorder}, a string from a {@link FunctionMap} can be
31
+ * used, as long as the function the string maps to allows for the same
32
+ * parameters as above.
33
+ * @group Slide Navigator
34
+ */
35
+ export type TypeSlideStateCallback = string | ((from: TypeSlideFrom, index: number) => void);
36
+ /**
37
+ * Callback definition for slide transition.
38
+ *
39
+ * `(done: () => void, currentIndex: number, from: `{@link TypeSlideFrom}`) => void`
40
+ *
41
+ * When using {@link Recorder}, a string from a {@link FunctionMap} can be
42
+ * used, as long as the function the string maps to allows for the same
43
+ * parameters as above.
44
+ *
45
+ * Important note: the `done` parameter MUST be called at the end of the
46
+ * transition to allow the slide to progress to steady state.
47
+ * @group Slide Navigator
48
+ */
49
+ export type TypeSlideTransitionCallback = string | ((done: () => void, index: number, from: TypeSlideFrom) => void);
50
+ /**
51
+ * An animation definition object defines an animation in a json like
52
+ * object.
53
+ *
54
+ * One key of the object defines the animation to use, while the remaining
55
+ * keys are the properties of the animation.
56
+ *
57
+ * The value of the key (with the exception of the `delay` key) that defines
58
+ * the animation is a {@link TypeElementPath} defining which elements to apply
59
+ * the animation to. When using `delay`, the value will be a number in seconds.
60
+ *
61
+ * The remaining keys in the object then come from the definition objects of
62
+ * the associated animation.
63
+ *
64
+ * The possible key names that define animations are:
65
+ *
66
+ * - `delay`: delay where value is `number` in seconds
67
+ * - `in`: dissolve in with {@link OBJ_ElementAnimationStep} options where
68
+ * duration is dissolve in time
69
+ * - `out`: dissolve out with {@link OBJ_ElementAnimationStep} options where
70
+ * duration is dissolve out time
71
+ * - `rotation`: {@link OBJ_RotationAnimationStep}
72
+ * - `position`: {@link OBJ_PositionAnimationStep}
73
+ * - `scale`: {@link OBJ_ScaleAnimationStep}
74
+ * - `scenario`: {@link OBJ_ScenarioAnimationStep}
75
+ * - `scenarios`: {@link OBJ_ScenariosAnimationStep}
76
+ * - `pulseWidth`: {@link OBJ_PulseWidthAnimationStep}
77
+ * - `length`: {@link OBJ_LengthAnimationStep}
78
+ * - `pulseAngle`: {@link OBJ_PulseAngleAnimationStep}
79
+ * - `pulse`: {@link OBJ_PulseAnimationStep}
80
+ * - `dim`: dim animation step with {@link OBJ_ElementAnimationStep} options
81
+ * where
82
+ * duration is dim duration
83
+ * - `undim`: dim animation step with {@link OBJ_ElementAnimationStep} options
84
+ * where duration is undim duration
85
+ * - `trigger`: {@link OBJ_TriggerAnimationStep}
86
+ * - `goToForm`: {@link OBJ_TriggerAnimationStep}
87
+ *
88
+ *
89
+ * Several animation steps will automatically set their final targets just
90
+ * before `steadyStateCommon` is set. This means, if the slide is navigated to
91
+ * from a slide that doesn't trigger the transition, then these targets will
92
+ * still be set. In many cases, this reduces doubling up desired steady state
93
+ * targets when defining a slide. However, if the target should not be
94
+ * automatically set, then use `final: false` in the animation steps's options
95
+ * to disable this behavor. The animations that automatically set targets are:
96
+ *
97
+ * - `in`
98
+ * - `out`
99
+ * - `scenario`
100
+ * - `dim`
101
+ * - `undim`
102
+ * - `rotation`
103
+ * - `position`
104
+ * - `scale`
105
+ *
106
+ *
107
+ * If a transition definition contains `in` or `out` animation steps, then
108
+ * before the transition starts, the elements that will dissolve in are
109
+ * automatically hidden, and the elements that will dissolve out are
110
+ * automatically shown. If this behavior is not wanted, then for `out` steps
111
+ * use `show: false` in the animation step definition, and for `in` steps use
112
+ * `show: true`.
113
+ *
114
+ * @interface
115
+ * @group Misc SlideNavigator
116
+ */
117
+ export type OBJ_AnimationDefinition = Record<string, any>;
118
+ /**
119
+ * Transition Definition
120
+ *
121
+ * {@link TypeSlideTransitionCallback} | {@link OBJ_AnimationDefinition} | Array<{@link OBJ_AnimationDefinition} | Array<{@link OBJ_AnimationDefinition}>>
122
+ *
123
+ * For complete control in creating a transition animation, and/or setting
124
+ * necessary transition state within an application, use a function definition
125
+ * {@link TypeSlideTransitionCallback}.
126
+ *
127
+ * Many transitions will be simple animations, dissolving in elements,
128
+ * dissolving out elements, or animating between positions. For these, a short
129
+ * hand way of defining animations can be used.
130
+ *
131
+ * {@link OBJ_AnimationDefinition} is a json like object that defines the
132
+ * animation. When used in an array, multiple animations will be executed in
133
+ * series.
134
+ *
135
+ * If an array of {@link OBJ_AnimationDefinition} objects has an element that
136
+ * itself is an array of {@link OBJ_AnimationDefinition} objects, then the
137
+ * the animations within the nested array will be executed in parallel.
138
+ *
139
+ * <p class="inline_gif"><img src="./apiassets/slidetransition.gif" class="inline_gif_image"></p>
140
+ *
141
+ * @see To test examples, append them to the
142
+ * <a href="#animation-boilerplate">boilerplate</a>
143
+ *
144
+ * @example
145
+ * // Figure has two rectangles and a slide navigator. Slides will dissolve in,
146
+ * // dissolve out, move and rotate rectangles
147
+ * const [rect1, rect2] = figure.add([
148
+ * {
149
+ * name: 'rect1',
150
+ * make: 'primitives.rectangle',
151
+ * width: 0.4,
152
+ * height: 0.4,
153
+ * position: [-0.5, 0.5],
154
+ * },
155
+ * {
156
+ * name: 'rect2',
157
+ * make: 'primitives.rectangle',
158
+ * width: 0.4,
159
+ * height: 0.4,
160
+ * position: [0.5, 0.5],
161
+ * },
162
+ * {
163
+ * name: 'nav',
164
+ * make: 'collections.slideNavigator',
165
+ * },
166
+ * ]);
167
+ *
168
+ * const setPositionAndRotation = (r1Pos, r1Rot, r2Pos, r2Rot) => {
169
+ * rect1.setPosition(r1Pos);
170
+ * rect1.setRotation(r1Rot);
171
+ * rect2.setPosition(r2Pos);
172
+ * rect2.setRotation(r2Rot);
173
+ * };
174
+ *
175
+ * // Add slides to the navigator
176
+ * figure.getElement('nav').loadSlides([
177
+ * // Slide 1
178
+ * {
179
+ * showCommon: 'rect1',
180
+ * enterStateCommon: () => setPositionAndRotation([-0.5, 0.5], 0, [0.5, 0.5], 0),
181
+ * },
182
+ *
183
+ * // Slide 2
184
+ * {
185
+ * transition: (done) => {
186
+ * rect2.animations.new()
187
+ * .dissolveIn({ duration: 1 })
188
+ * .whenFinished(done) // Make sure to process done when finished
189
+ * .start();
190
+ * },
191
+ * // When using a transition function, any changes during the transition
192
+ * // need to be explicitly set at steady state
193
+ * steadyState: () => {
194
+ * rect2.show();
195
+ * },
196
+ * },
197
+ *
198
+ * // Slide 3
199
+ * // When using animation objects, the targets of animations will be
200
+ * // automatically set at steady state, so user does not need to set them
201
+ * {
202
+ * showCommon: ['rect1', 'rect2'],
203
+ * transition: { position: 'rect2', target: [0.3, 0.5], duration: 1 },
204
+ * },
205
+ *
206
+ * // Slide 4
207
+ * // Use an array of animation object definitions to create a sequence of steps
208
+ * {
209
+ * enterState: () => setPositionAndRotation([-0.5, 0.5], 0, [0.3, 0.5], 0),
210
+ * transition: [
211
+ * { position: 'rect1', target: [-0.3, 0.5], duration: 1 },
212
+ * { rotation: 'rect1', target: Math.PI / 4, duration: 1 },
213
+ * { rotation: 'rect2', target: Math.PI / 4, duration: 1 },
214
+ * ],
215
+ * },
216
+ *
217
+ * // Slide 5
218
+ * // Use an array within an array to create parallel steps
219
+ * {
220
+ * enterState: () => setPositionAndRotation([-0.3, 0.5], Math.PI / 4, [0.3, 0.5], Math.PI / 4),
221
+ * transition: [
222
+ * [
223
+ * { rotation: 'rect1', target: 0, duration: 1 },
224
+ * { rotation: 'rect2', target: 0, duration: 1 },
225
+ * ],
226
+ * [
227
+ * { position: 'rect1', target: [-0.5, 0.5], duration: 1 },
228
+ * { position: 'rect2', target: [0.5, 0.5], duration: 1 },
229
+ * ],
230
+ * { out: ['rect1', 'rect2'] },
231
+ * ],
232
+ * },
233
+ * ]);
234
+ * @group Slide Navigator
235
+ */
236
+ export type TypeTransitionDefinition = TypeSlideTransitionCallback | OBJ_AnimationDefinition | Array<OBJ_AnimationDefinition | Array<OBJ_AnimationDefinition>>;
237
+ /**
238
+ * Recorder time format.
239
+ *
240
+ * `number | string`
241
+ *
242
+ * Use `number` for number of seconds, or use string with format 'm:s.s' (for
243
+ * example, '1:23.5' would define 1 minute, 23.5 seconds)
244
+ * @group Interactive Video
245
+ */
246
+ export type TypeRecorderTime = string | number;
247
+ /**
248
+ *
249
+ *
250
+ * Slide definition options object.
251
+ *
252
+ * This object defines the state the figure should be set to when this slide
253
+ * is navigated to.
254
+ *
255
+ * A slide definition has several callback properties that can be used to set
256
+ * figure state including:
257
+ * - enterState: set an initial state
258
+ * - transition: define an animation for when moving to this slide
259
+ * - steadyState: set steady state, then wait for next navigation event
260
+ * - leaveState: set leave state when moving to another another slide
261
+ *
262
+ * It is good practice to try and make each slide's state independant of other
263
+ * slides. If a square is shown on slides 4 and 5, then it should be explicitly
264
+ * shown on both slides. If it is only shown on slide 4, then it will be fine
265
+ * when the user navigates from slide 4 to 5, but will not be shown if the user
266
+ * is navigating from slide 6 to 5. Allowing users to go to specific slides out
267
+ * of order makes slide dependencies even more difficult.
268
+ *
269
+ * Therefore, the enter, steady and leave states above should be used to fully
270
+ * define the figure's state on each slide.
271
+ *
272
+ * However, while this approach will yield a good user experience, developing
273
+ * many slides, complex figures or numerous equation forms can make slide
274
+ * definition verbose. Even though each slide is different, many slides may
275
+ * share largely the same state, all of which needs to be explicitly defined
276
+ * for each slide.
277
+ *
278
+ * The SlideNavigator tries to manage this by providing the fundamental state
279
+ * callbacks above, as well as properties that can be defined once, and shared
280
+ * between slides. Slides with shared, or common properties make copies of all
281
+ * the properties so each slide is independant, but require the developer to
282
+ * define them just once. If a slide doesn't define a common property, then it
283
+ * will use the definition in the last slide that defined it.
284
+ *
285
+ * For example, the `enterStateCommon` property is a common property. If it is
286
+ * defined in slides 4 and 7, then slides 0-3 will not have the property, slides
287
+ * 4-6 will use the slide 4 definition, and slides 7 and after will all use
288
+ * slide 7's definition.
289
+ *
290
+ * Common state properties include:
291
+ * - enterStateCommon
292
+ * - steadyStateCommon
293
+ * - leaveStateCommon
294
+ *
295
+ * The reason some states have both a common and slide specific property
296
+ * (such as steadyState and steadyStateCommon) is so the common property can
297
+ * be best leveraged. If all properties were common, then they would need to be
298
+ * redefined every time a small change was made. Having both common and slide
299
+ * specific properties allows a balance of defining some state for a group of
300
+ * slides once, while allowing specific changes to that state where needed.
301
+ *
302
+ * In addition to the above state properties, there are a number of short-cut
303
+ * properties, that make it easy to set state for common figure elements. When
304
+ * a SlideNavigator is instantiated, a text figure element, a figure collection
305
+ * and one or more equation elements can be associated with it.
306
+ *
307
+ * The `text`, `modifier` and `modifierCommon` properties can be used to set
308
+ * the text of the text figure element associated with the SlideNavigator.
309
+ * `text` and `modifierCommon` are common properties.
310
+ *
311
+ * The `form` property is also common and can be used to automatically set the
312
+ * form of the associated equation elements. A SlideNavigator can be associated
313
+ * with one or more equations. The `form` property defines the form each of the
314
+ * equations should be set to on this slide. If there is just one equation, then
315
+ * the form property can be a string that is the form name. For two or more
316
+ * equations, the form property should be an array of strings where each element
317
+ * is the form name for the corresponding equation. The order of equations
318
+ * passed into the SlideNavigator, needs to be the same as the order of strings
319
+ * in the `form` array. To hide an equation, use a `null` instead of a string.
320
+ * If the `form` property has less forms than equations, then all remaining
321
+ * equations will be hidden.
322
+ *
323
+ * The `form` property is a short cut with several consequences:
324
+ * - All equations with `null` forms will be hidden prior to `enterState`.
325
+ * - If the slide doesn't have a `transition` defined, and if an equation form
326
+ * is changed, then a transition will be added that animates the equation form
327
+ * change. If `transition` is defined, and equation animation is required,
328
+ * then it needs to be defined in the `transition` property explicity.
329
+ * - Each equation with a defined form will have `showForm` called on that form
330
+ * prior to `steadyState`.
331
+ *
332
+ * The life cycle of a slide change is:
333
+ * - `leaveStateCommon` (for current slide)
334
+ * - `leaveState` (for current slide)
335
+ * - stop all animations
336
+ * - Update associated text element with `text` property
337
+ * - Hide all figure elements in associated collection
338
+ * - `showCommon`
339
+ * - `show`
340
+ * - show navigator buttons and navigator text element
341
+ * - `hideCommon`
342
+ * - `hide`
343
+ * - show `fromForm`
344
+ * - show all elements that dissolveIn or dissolveOut in an auto transition
345
+ * - `scenarioCommon`
346
+ * - `scenario`
347
+ * - `enterStateCommon` (for new slide)
348
+ * - `enterState`
349
+ * - `addReference`
350
+ * - show all elements that dissolveOut and hide all elements that dissolveIn
351
+ * in an auto transition
352
+ * - publish `beforeTransition` notification
353
+ * - transition
354
+ * - show `form`
355
+ * - set targets from auto transition
356
+ * - `steadyStateCommon`
357
+ * - `steadyState`
358
+ * - update slide navigator buttons
359
+ * - publish `steady` notification
360
+ *
361
+ * @property {OBJ_TextLines} [text] common property - With `modifiersCommon` and
362
+ * `modifiers` define the text for the text element associated with the
363
+ * SlideNavigator
364
+ * @property {OBJ_TextModifiersDefinition} [modifiersCommon] common property
365
+ * @property {OBJ_TextModifiersDefinition} [modifiers] common property - will
366
+ * overwrite any keys from `modifiersCommon` with the same name
367
+ * @property {TypeElementPath} [showCommon] common property
368
+ * @property {TypeElementPath} [show]
369
+ * @property {TypeElementPath} [hideCommon] common property
370
+ * @property {TypeElementPath} [hide]
371
+ * @property {TypeSlideStateCallback} [enterStateCommon] common property
372
+ * @property {TypeSlideStateCallback} [enterState]
373
+ * @property {TypeTransitionDefinition} [transition] transititions are
374
+ * only called when moving between adjacent slides in the forward direction.
375
+ * Progressing backwards, or skipping around with `goToSlide` will not call
376
+ * `transition`. A transition is a callback where animations can be defined. A
377
+ * `done` function is passed to the callback and must be called at the end of
378
+ * the animation to allow slide steadyStates to be set.
379
+ * @property {TypeSlideStateCallback} [steadyStateCommon] common property
380
+ * @property {TypeSlideStateCallback} [steadyState]
381
+ * @property {TypeSlideLeaveStateCallback} [leaveStateCommon] common property
382
+ * @property {TypeSlideLeaveStateCallback} [leaveState]
383
+ * @property {string | Array<string | null> | null | Object} [form] common property
384
+ * @property {string | Array<string | null> | null | Object} [fromForm]
385
+ * @property {string | Array<string>} [scenarioCommon] common property
386
+ * @property {string | Array<string>} [scenario]
387
+ * @property {'move' | 'dissolve' | 'moveFrom' | 'pulse' |
388
+ * 'dissolveInThenMove'} [animate] override default animation option for
389
+ * automatic form animation using the 'form' property
390
+ * @property {boolean} [clear] `true` does not use any prior common properties (`false`)
391
+ * @property {TypeRecorderTime} [time] recorder only - absolute time to
392
+ * transition to slide.
393
+ * @property {number} [delta] recorder only - time delta in seconds from last
394
+ * slide transition to transition to this slide
395
+ * @property {Array<[TypeRecorderTime, string]> | [TypeRecorderTime, string]} [exec]
396
+ * recorder only - times to execute functions.
397
+ * @property {Array<[number | string, string]> | [number | string, string]} [execDelta]
398
+ * recorder only - time deltas to execute functions from the slide transition
399
+ * start.
400
+ * @property {boolean} addReference recorder only `true` will add a new
401
+ * reference state based on the current state
402
+ * @interface
403
+ * @group Slide Navigator
404
+ */
405
+ export type OBJ_SlideNavigatorSlide = {
406
+ text?: OBJ_FormattedText;
407
+ modifiersCommon?: OBJ_TextModifiersDefinition;
408
+ modifiers?: OBJ_TextModifiersDefinition;
409
+ showCommon?: TypeElementPath;
410
+ show?: TypeElementPath;
411
+ hideCommon?: TypeElementPath;
412
+ hide?: TypeElementPath;
413
+ enterStateCommon?: TypeSlideStateCallback;
414
+ enterState?: TypeSlideStateCallback;
415
+ transition?: TypeTransitionDefinition;
416
+ steadyStateCommon?: TypeSlideStateCallback;
417
+ steadyState?: TypeSlideStateCallback;
418
+ leaveStateCommon?: TypeSlideLeaveStateCallback;
419
+ leaveState?: TypeSlideLeaveStateCallback;
420
+ fromForm?: string | Array<string | null> | null;
421
+ form?: string | Array<string | null> | null;
422
+ scenarioCommon?: string | Array<string>;
423
+ scenario?: string | Array<string>;
424
+ clear?: boolean;
425
+ time?: TypeRecorderTime;
426
+ delta?: number;
427
+ exec?: Array<[TypeRecorderTime, string]> | [TypeRecorderTime, string];
428
+ execDelta?: Array<[number, string]> | [number, string];
429
+ addReference?: boolean;
430
+ };
431
+ /**
432
+ * Default equation animation properties.
433
+ * @interface
434
+ * @group Slide Navigator
435
+ */
436
+ export type OBJ_EquationDefaults = {
437
+ duration?: number;
438
+ animate?: "move" | "dissolve" | "moveFrom" | "pulse" | "dissolveInThenMove";
439
+ };
440
+ /**
441
+ * SlideNavigator options object
442
+ *
443
+ * The options here associate a number of {@link FigureElement}s with the
444
+ * {@link SlideNavigator}, which will be ustilized by the slide definitions in
445
+ * {@link OBJ_SlideNavigatorSlide}.
446
+ *
447
+ * The `collection` property associates a {@link FigureElementCollection}. If a
448
+ * {@link Figure} is passed in, then the root level collection will be
449
+ * used. All animations in slide `transitions` should be attached to
450
+ * this collection or its children as this is the collection that will be
451
+ * stopped when skipping slides. All string definitions of other elements
452
+ * will be relative to this collection, and therefore must be children of
453
+ * this collection. A collection must be passed in.
454
+ *
455
+ * `prevButton` and `nextButton` are buttons that can be used to progress
456
+ * backwards and forwards through the slides. The SlideNavigator will
457
+ * disable `prevButton` on the first slide and update `nextButton` label
458
+ * (if it exists) with `'restart'` when at the last slide.
459
+ *
460
+ * `text` is a {@link OBJ_TextLines} figure element that will be updated
461
+ * with the `text` property in {@link OBJ_SlideNavigatorSlide}
462
+ *
463
+ * `equation` is one or more {@link Equation} elements to associate with the
464
+ * SlideNavigator. Each associated equation will be operated on by the `form`
465
+ * property in {@link OBJ_SlideNavigatorSlide}. Use `OBJ_EquationDefaults` to
466
+ * set default equation animation properties when `form` creates slide
467
+ * transitions.
468
+ *
469
+ * @property {Figure | FigureElementCollection} collection
470
+ * @property {Array<OBJ_SlideNavigatorSlide>} [slides]
471
+ * @property {null | FigureElement | string} [prevButton]
472
+ * @property {null | FigureElement | string} [nextButton]
473
+ * @property {null | string | FigureElementCollection} [text]
474
+ * @property {Equation | string | Array<string | Equation>} [equation]
475
+ * @property {OBJ_EquationDefaults} [equationDefaults]
476
+ * @interface
477
+ * @group Slide Navigator
478
+ */
479
+ export type OBJ_SlideNavigator = {
480
+ collection: Figure | FigureElementCollection;
481
+ slides?: Array<OBJ_SlideNavigatorSlide>;
482
+ prevButton?: FigureElement | null | undefined | string;
483
+ nextButton?: FigureElement | null | undefined | string;
484
+ text?: string | FigureElementCollection;
485
+ equation?: Equation | string | Array<string | Equation>;
486
+ equationDefaults?: OBJ_EquationDefaults;
487
+ } & OBJ_Collection;
488
+ /**
489
+ * Slide Navigator
490
+ *
491
+ * It is sometimes useful to break down a visualization into easier to consume
492
+ * parts.
493
+ *
494
+ * For example, a complex figure or concept can be made easier if built up
495
+ * from a simple begining. Each step along the way might change the elements
496
+ * within the figure, or the form of an equation, and be accompanied by a
497
+ * corresponding description giving context, reasoning or next steps.
498
+ *
499
+ * An analogy to this is a story or presentation, where each step along the way
500
+ * is a presentation slide.
501
+ *
502
+ * This class is a simple slide navigator, providing a convenient way to define
503
+ * slides and step through them.
504
+ *
505
+ * {@link CollectionsSlideNavigator} creates the navigation buttons, and
506
+ * `textElement` automatically, and will usually be more convenient than
507
+ * manually creating them (unless custom buttons are needed).
508
+ *
509
+ * Notifications - The notification manager property `notifications` will
510
+ * publish the following events:
511
+ * - `goToSlide`: published when slide changes - will pass slide index to
512
+ * subscriber
513
+ * - `steady`: steady state reached (slide transition complete)
514
+ *
515
+ * @property {NotificationManager} notifications notification manager for
516
+ * element
517
+ * @property {number} currentSlideIndex index of slide current shown
518
+ * @property {boolean} inTransition `true` if slide current transitioning
519
+ *
520
+ * @see {@link CollectionsSlideNavigator} for examples.
521
+ * @group Slide Navigator
522
+ */
523
+ export default class SlideNavigator {
524
+ currentSlideIndex: number;
525
+ slides: Array<OBJ_SlideNavigatorSlide>;
526
+ prevButton: FigureElement | null | undefined;
527
+ nextButton: FigureElement | null | undefined;
528
+ textElement: CollectionsText | null | undefined;
529
+ inTransition: boolean;
530
+ equationsOrder: Array<FigureElement>;
531
+ equations: {
532
+ [key: string]: FigureElement;
533
+ };
534
+ collection: FigureElementCollection;
535
+ notifications: NotificationManager;
536
+ from: 'prev' | 'next' | number;
537
+ slideTransitionDoneName: string;
538
+ doneCount: number;
539
+ equationDefaults: {
540
+ duration: number;
541
+ animate: "move" | "dissolve" | "moveFrom" | "pulse" | "dissolveInThenMove";
542
+ };
543
+ disableButtonOpacity: number;
544
+ fromAutoSlide: boolean;
545
+ /**
546
+ * @param {OBJ_SlideNavigator | null} options use `null` to load options later
547
+ * with the `load` method. Options should only be loaded when an instantiated
548
+ * {@link FigureElementCollection} is available for the `collections`
549
+ * property.
550
+ */
551
+ constructor(options?: OBJ_SlideNavigator | null);
552
+ /**
553
+ * Load options after object instantiation. Usefull for if the
554
+ * `collection`, `prevButton`, `nextButton`, `equation` and/or `text` figure
555
+ * elements are not available at instantiation.
556
+ *
557
+ * @param {OBJ_SlideNavigator} options
558
+ */
559
+ load(options: OBJ_SlideNavigator): void;
560
+ syncDone: () => void;
561
+ convertTime(timeIn: string | number): number;
562
+ loadRecorder(): void;
563
+ /**
564
+ * Load slides into navigator
565
+ */
566
+ loadSlides(slides: Array<OBJ_SlideNavigatorSlide>): void;
567
+ setEquations(equationsIn: Array<string | Equation>): void;
568
+ getProperty(property: string, indexIn: number, defaultValue?: any): any;
569
+ getText(index: number): any;
570
+ getForm(index: number): any;
571
+ getFormGeneric(formType: 'form' | 'fromForm', index: number): any;
572
+ getFromForm(index: number): any;
573
+ showForms(formsToShow: Record<string, any>): void;
574
+ setSteadyState(from: 'next' | 'prev' | number): void;
575
+ transitionDone(cancelled?: boolean, force?: 'freeze' | 'complete' | null): void;
576
+ setFinalFromAutoTransition(stepsIn: Array<OBJ_AnimationDefinition | Array<OBJ_AnimationDefinition>>): void;
577
+ processAutoTransitionAnim(step: Record<string, any>, key: string, animName: string | undefined, animSteps: Array<AnimationStep>, defaultOptions?: Record<string, any>): void;
578
+ processAutoTransitionSet(step: Record<string, any>, key: string, setName: string, setKey?: string): void;
579
+ showAutoTransitionDissolve(index: number, showAll?: boolean): void;
580
+ autoTransition(stepsIn: Array<Array<Record<string, any>>> | Array<Record<string, any>>): void;
581
+ transition(from: 'next' | 'prev' | number): any;
582
+ setText(index: number): void;
583
+ showElements(index: number): void;
584
+ hideElements(index: number): void;
585
+ /**
586
+ * @param {number} index slide index to go to
587
+ * @param {'next' | 'prev' | number} from this should generally not be used
588
+ * and will be set automatically
589
+ */
590
+ goToSlide(slideIndex: number, from?: 'next' | 'prev' | number | null): void;
591
+ /**
592
+ * Progress to next slide.
593
+ *
594
+ * @param {boolean} ignoreTransition when `false`, if the slide is still in
595
+ * a transition when nextSlide is called, then the transition will skip
596
+ * through to the end, without moving to the next slide - effectively skipping
597
+ * through to the steady state of the current slide. If `true`, then the
598
+ * transition will instantly complete, setState and leaveStates called and the
599
+ * next slide will be progressed to.
600
+ */
601
+ nextSlide(ignoreTransition?: boolean): void;
602
+ /**
603
+ * Progress to the previous slide.
604
+ */
605
+ prevSlide(): void;
606
+ }