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,536 @@
1
+ import type { OBJ_FigureForElement } from '../Figure';
2
+ import { FigureElementPrimitive } from '../Element';
3
+ import { Point } from '../../tools/g2';
4
+ import type { FigureElement } from '../Element';
5
+ import type { TypeParsablePoint, Transform } from '../../tools/g2';
6
+ import Scene from '../../tools/geometry/scene';
7
+ import type { OBJ_Scene } from '../../tools/geometry/scene';
8
+ import type { OBJ_Generic } from './FigurePrimitiveTypes2D';
9
+ import type TimeKeeper from '../TimeKeeper';
10
+ import type DrawingObject from '../DrawingObjects/DrawingObject';
11
+ import type { TypeColor } from '../../tools/types';
12
+ /**
13
+ * Zoom options.
14
+ *
15
+ * @property {null | number} [max] maximum zoom if value defined, no
16
+ * maximum if `null` (`null`)
17
+ * @property {null | number} [min] minimum zoom if value defined, no
18
+ * minimum if `null` (`null`)
19
+ * @property {number} [pinchSensitivity] pinch zoom sensitivity where values
20
+ * greater than 1 are more sensitive resulting in faster zoom changes (`1`)
21
+ * @property {number} [wheelSensitivity] mouse wheel zoom sensitivity where
22
+ * values greater than 1 are more sensitive resulting in faster zoom changes
23
+ * (`1`)
24
+ * @property {null | TypeParsablePoint} [position] zoom around a fixed point (instead of the
25
+ * mouse of pinch location) - leave undefined or use `null` to instead zoom
26
+ * around mouse or pinch location (`null`)
27
+ * @interface
28
+ * @group Misc Shapes
29
+ */
30
+ export type OBJ_ZoomOptions = {
31
+ min?: null | number;
32
+ max?: null | number;
33
+ wheelSensitivity?: number;
34
+ pinchSensitivity?: number;
35
+ position?: null | TypeParsablePoint;
36
+ };
37
+ /**
38
+ * Manual zoom setting.
39
+ *
40
+ * @property {number} mag zoom magnification (`last zoom`)
41
+ * @property {TypeParsablePoint} position zoom around this position (`[0, 0]`)
42
+ * @property {TypeParsablePoint} offset use this pan offset
43
+ * @interface
44
+ * @group Misc Shapes
45
+ */
46
+ export type OBJ_ManualZoom = {
47
+ mag?: number;
48
+ position?: TypeParsablePoint;
49
+ offset?: TypeParsablePoint;
50
+ };
51
+ /**
52
+ * Zoom values
53
+ *
54
+ * @property {number} mag zoom magnification
55
+ * @property {Point} position zoom position
56
+ * @property {number} distance distance between pinch touches (in pixels)
57
+ * @property {number} angle delta angle from original pinch angle
58
+ * @interface
59
+ * @group Misc Shapes
60
+ */
61
+ export type OBJ_ZoomValues = {
62
+ mag: number;
63
+ position: Point;
64
+ distance: number;
65
+ angle: number;
66
+ };
67
+ /**
68
+ * Current zoom values
69
+ *
70
+ * @property {number} mag zoom magnification
71
+ * @property {Point} offset pan offset
72
+ * @property {OBJ_ZoomValues} last last zoom values
73
+ * @property {OBJ_ZoomValues} current current zoom values
74
+ * @interface
75
+ * @group Misc Shapes
76
+ */
77
+ export type OBJ_CurrentZoom = {
78
+ delta: number;
79
+ mag: number;
80
+ offset: Point;
81
+ last: OBJ_ZoomValues;
82
+ current: OBJ_ZoomValues;
83
+ };
84
+ export type OBJ_CurrentPan = {
85
+ offset: number;
86
+ delta: number;
87
+ };
88
+ /**
89
+ * Pan options.
90
+ *
91
+ * @property {null | number} [left] maximum left pan allowed, or `null` for no
92
+ * limit (`null`)
93
+ * @property {null | number} [right] maximum right pan allowed, or `null` for no
94
+ * limit (`null`)
95
+ * @property {null | number} [bottom] maximum bottom pan allowed, or `null` for
96
+ * no limit (`null`)
97
+ * @property {null | number} [top] maximum top pan allowed, or `null` for no
98
+ * limit (`null`)
99
+ * @property {number} [wheelSensitivity] mouse wheel pan sensitivity for mouse
100
+ * wheel panning where values greater than 1 are more sensitive resulting in
101
+ * faster panning (`1`)
102
+ * @property {boolean} [wheel] enable mouse wheel panning - only possible if
103
+ * zoom gesture is disabled.
104
+ * @property {boolean} [momentum] enable pan momentum for drag panning. NB,
105
+ * mouse wheel panning mamemntum cannot be controlled and will be browser
106
+ * dependent. (`true`)
107
+ * @interface
108
+ * @group Misc Shapes
109
+ */
110
+ export type OBJ_PanOptions = {
111
+ left?: null | number;
112
+ right?: null | number;
113
+ bottom?: null | number;
114
+ top?: null | number;
115
+ wheelSensitivity?: number;
116
+ wheel?: boolean;
117
+ momentum?: boolean;
118
+ maxVelocity?: number;
119
+ };
120
+ /**
121
+ * Instantaneous zoom metrics.
122
+ * @property {number} [mag] zoom magnification
123
+ * @property {Point} [position] position around which zoom is happening
124
+ * @property {Point} [normPosition] position around which zoom is happening
125
+ * normalized to the gesture rectangle where (0, 0) is the bottom left corner
126
+ * and (1, 1) is the top right corner
127
+ * @property {number} [angle] (pinch zoom only) pinch angle delta to start of
128
+ * pinch
129
+ * @property {number} [distance] (pinch zoom only) distance between pinch points
130
+ * @interface
131
+ * @group Misc Shapes
132
+ */
133
+ export type OBJ_ZoomInstant = {
134
+ mag: number;
135
+ position: Point;
136
+ normPosition: Point;
137
+ angle: number;
138
+ distance: number;
139
+ };
140
+ /**
141
+ * Current zoom.
142
+ *
143
+ @property {OBJ_ZoomInstant} last last zoom metrics
144
+ @property {OBJ_ZoomInstant} current current zoom metrics
145
+ @property {number} mag current zoom magnification
146
+ @property {number} offset pan offset needed to keep the zoom position at a
147
+ * fixed location
148
+ * @interface
149
+ * @group Misc Shapes
150
+ */
151
+ export type OBJ_Zoom = {
152
+ last: OBJ_ZoomInstant;
153
+ current: OBJ_ZoomInstant;
154
+ mag: number;
155
+ offset: Point;
156
+ };
157
+ /**
158
+ * @property {OBJ_ZoomOptions | boolean} [zoom] zoom options - if not `false`
159
+ * then zoom will be enabled (`false`)
160
+ * @property {OBJ_PanOptions | boolean} [pan] pan options - if not `false` then
161
+ * pan will be enabled (`false`)
162
+ * @property {boolean} [onlyWhenTouched] (mouse wheel zoom/pan and pinch zoom)
163
+ * only notify when element gesture rectangle is being touched (`true`)
164
+ * @property {boolean} [back] if `true` 3D shape interactivity will be
165
+ * prioritized (`true`)
166
+ * @property {number} [width] width of rectangle - defaults to full scene width
167
+ * @property {number} [height] height of rectangle - defaults to full scene
168
+ * height
169
+ * @property {OBJ_Scene | Scene} [scene] define if gesture should be an
170
+ * independeant scene (like if the gestures are being used to change the
171
+ * default figure scene) - defaults to Figure scene
172
+ * @property {OBJ_Scene} [changeScene] if defined, this scene will be
173
+ * automatically updated with any pan and zoom events
174
+ * @property {'left' | 'center' | 'right' | number} [xAlign] x alignment of
175
+ * rectangle (`'center'`)
176
+ * @property {'bottom' | 'middle' | 'top' | number} [yAlign] y alignment of
177
+ * rectangle (`'middle'`)
178
+ *
179
+ * @extends OBJ_Generic
180
+ * @interface
181
+ * @group Interactivity
182
+ */
183
+ export type OBJ_Gesture = {
184
+ zoom?: OBJ_ZoomOptions | boolean;
185
+ pan?: OBJ_PanOptions | boolean;
186
+ onlyWhenTouched?: boolean;
187
+ back?: boolean;
188
+ width?: number;
189
+ height?: number;
190
+ scene?: OBJ_Scene | Scene;
191
+ changeScene?: Scene;
192
+ xAlign?: 'left' | 'center' | 'right' | number;
193
+ yAlign?: 'bottom' | 'middle' | 'top' | number;
194
+ } & OBJ_Generic;
195
+ /**
196
+ * Gesture rectangle.
197
+ *
198
+ * ![](./apiassets/gesture1.gif)
199
+ *
200
+ * ![](./apiassets/gesture2.gif)
201
+ *
202
+ * This primitive creates a rectangle within which pan and zoom gestures can be
203
+ * captured (from mouse and touch events) and transformed into pan and zoom
204
+ * values. The pan and zoom values can be used to change {@link Scene} objects
205
+ * directly, or used for some custom purpose.
206
+ *
207
+ * The pan and zoom values are relative to the gesture rectangle and the
208
+ * {@link Scene} it is drawn with.
209
+ *
210
+ * Performing a drag gesture over half the width of the rectangle, will create
211
+ * a pan value that is half the width of the rectangle.
212
+ *
213
+ * Performing a 2x zoom gesture at a point within the rectangle will create a
214
+ * pan value that is the delta between the original rectangle center and the
215
+ * center of the new zoomed rectangle, and a magnification value of 2.
216
+ *
217
+ * Any combination of zoom and pan can be expressed as a pan value, that offsets
218
+ * the original rectangle such that when it is then zoomed, the zoom position
219
+ * will be at the same relative position of the original and zoomed rectangle.
220
+ *
221
+ * Whenever a gesture changes the pan or zoom, then `'pan'` or `'zoom'`
222
+ * notifications will be published by the primitive's {@link NotificationManger}
223
+ * (`element.notifications`).
224
+ *
225
+ * The handled gestures are:
226
+ * - Mouse wheel change (often used for zooming and panning with a mouse)
227
+ * - Drag (often used for panning with touch devices or a mouse)
228
+ * - Pinching (often used for zooming and panning on touch devices)
229
+ *
230
+ * ### Pan
231
+ *
232
+ * A pan is an offset in xy.
233
+ *
234
+ * The gestures that can generate pan events are:
235
+ * - Mouse click then drag
236
+ * - Finger touch then drag (touch devices)
237
+ * - Mouse wheel change
238
+ *
239
+ * For the mouse click and drag, and finger touch and drag gestures, the pan
240
+ * value tracks the change in position of the mouse/finger in the gesture
241
+ * primitive rectangle. For example, if the rectangle has a width of 2, and the
242
+ * mouse or touch moves across half the width of the rectangle, then the pan
243
+ * offset will be 1.
244
+ *
245
+ * For the mouse wheel change, a `wheelSensitivity` value is used to speed up or
246
+ * slow down the pan.
247
+ *
248
+ * When a pan event happens, a `'pan'` notification is published. The parameter
249
+ * passed to any subscribers is the pan offset value, but if more information
250
+ * is needed (like the pan delta from the last pan) then `getPan()` can be
251
+ * called.
252
+ *
253
+ * ### Zoom
254
+ *
255
+ * A zoom is a magnification at a point in the rectangle. The zoom point will
256
+ * stay stationary, while the other points around it spread out (when zooming
257
+ * in) or compress in (when zooming out). The zoom event thus includes a pan
258
+ * offset to ensure the zoom point stays stationary, as well as a magnification
259
+ * value.
260
+ *
261
+ * The gestures that can generate zoom events are:
262
+ * - Mouse wheel vertical change
263
+ * - Finger touch pinch
264
+ *
265
+ * A `wheelSensitivity` or `pinchSenstivity` value is used to speed up or slow down zooming.
266
+ *
267
+ * When a zoom event happens, a `'zoom'` notification is published. The
268
+ * parameters passed to any subscribers are the zoom magnification value and
269
+ * pan offset, but if more information is needed (like the zoom position)
270
+ * then `getZoom()` can be called.
271
+ *
272
+ * Zoom and pan events can be used in many ways. One of the most common ways
273
+ * will be to change a {@link Scene} that contains one or more
274
+ * {@link FigureElement}s allowing a user to pan or zoom through the scene.
275
+ *
276
+ * In such cases, the `zoomScene()` and `panScene()` methods can be used to do
277
+ * this directly.
278
+ *
279
+ * Alternately, a `changeScene` can be defined which will be automatically
280
+ * panned and zoomed by this primitive.
281
+ *
282
+ * In general the scene that is being used to draw the gesture primitive should
283
+ * not be panned or zoomed by the gesture primitive, as this will produce
284
+ * unexpected results (especially when panning). If the gesture primitive is
285
+ * setup to change the same scene as it uses itself, then it will assign itself
286
+ * a duplicate scene.
287
+ *
288
+ * @example
289
+ * // Gesture primitive pans and zooms a figure scene
290
+ * const figure = new Fig.Figure({ color: [1, 0, 0, 1] });
291
+ *
292
+ * // Elements within the figure to zoom and pan
293
+ * figure.add([
294
+ * { make: 'rectangle', width: 0.2, height: 0.2, position: [-0.3, 0] },
295
+ * { make: 'triangle', width: 0.2, height: 0.2, position: [0.02, -0.025] },
296
+ * { make: 'ellipse', width: 0.2, height: 0.2, position: [0.3, 0] },
297
+ * ])
298
+ *
299
+ * // Gesture Primitive
300
+ * figure.add({
301
+ * make: 'gesture',
302
+ * changeScene: figure.scene,
303
+ * pan: true,
304
+ * zoom: true,
305
+ * });
306
+ *
307
+ * @example
308
+ * // Using zoom and pan notifications when the gestures are confied
309
+ * // to a green rectangle
310
+ * const figure = new Fig.Figure({ color: [1, 0, 0, 1] });
311
+ *
312
+ * const gesture = figure.add({
313
+ * make: 'gesture',
314
+ * color: [0, 1, 0, 0.3],
315
+ * width: 0.5,
316
+ * height: 1,
317
+ * pan: true,
318
+ * zoom: true,
319
+ * });
320
+ *
321
+ * gesture.notifications.add(
322
+ * 'pan', offset => console.log('Pan: ', offset.x, offset.y),
323
+ * );
324
+ * gesture.notifications.add(
325
+ * 'zoom', (mag, offset) => console.log('Zoom: ', mag, offset.x, offset.y),
326
+ * );
327
+ * @group Interactivity
328
+ */
329
+ export default class FigureElementPrimitiveGesture extends FigureElementPrimitive {
330
+ zoom: {
331
+ last: {
332
+ mag: number;
333
+ normPosition: Point;
334
+ position: Point;
335
+ angle: number;
336
+ distance: number;
337
+ };
338
+ current: {
339
+ position: Point;
340
+ normPosition: Point;
341
+ angle: number;
342
+ distance: number;
343
+ };
344
+ min: null | number;
345
+ max: null | number;
346
+ wheelSensitivity: number;
347
+ pinchSensitivity: number;
348
+ mag: number;
349
+ cumAngle: number;
350
+ pinching: boolean;
351
+ enabled: boolean;
352
+ position: Point | null;
353
+ };
354
+ pan: {
355
+ enabled: boolean;
356
+ offset: Point;
357
+ left: null | number;
358
+ right: null | number;
359
+ bottom: null | number;
360
+ top: null | number;
361
+ delta: Point;
362
+ wheelSensitivity: number;
363
+ wheel: boolean;
364
+ momentum: boolean;
365
+ maxVelocity: number;
366
+ };
367
+ justMoved: boolean;
368
+ originalPosition: Point;
369
+ mousePixelPosition: Point;
370
+ onlyWhenTouched: boolean;
371
+ relativeScene: null | Scene;
372
+ notificationIDs: Array<number>;
373
+ changeScene: Scene;
374
+ constructor(drawingObject: DrawingObject, transform: Transform, color: TypeColor, parent: FigureElement | null, name: string, timeKeeper: TimeKeeper);
375
+ _getStateProperties(options: {
376
+ ignoreShown?: boolean;
377
+ }): string[];
378
+ setup(options: OBJ_Gesture): void;
379
+ /**
380
+ * Reset zoom and pan.
381
+ */
382
+ reset(exceptDistance?: boolean): void;
383
+ /**
384
+ * Associate this gesture rectangle with a new scene. Zoom and pan will be
385
+ * reset.
386
+ */
387
+ setScene(scene: Scene | OBJ_Scene): void;
388
+ /**
389
+ * Set a scene to automatically zoom and pan.
390
+ */
391
+ setChangeScene(scene: Scene): void;
392
+ setupMove(): void;
393
+ dragPan(): void;
394
+ mousePosition(pixelPoint: Point): void;
395
+ pixelToZoomedScene(pixelPoint: Point): Point;
396
+ glToZoomedScene(glPoint: Point): Point;
397
+ zoomedSceneToNorm(p: Point): Point;
398
+ wheelHandler(delta: Point): void;
399
+ /**
400
+ * Change the position and scale of an element to simulate it zooming.
401
+ *
402
+ * Note, the element will stay in the same space it was previously, and
403
+ * therefore moving it will be moving it in the same space.
404
+ *
405
+ * Often a better way to zoom an element (especially if more than one and
406
+ * interactivity is being used) is to zoom the scene the element(s) belong
407
+ * to.
408
+ *
409
+ * @param {FigureElement} element element to zoom
410
+ */
411
+ zoomElement(element: FigureElement, originalPosition: TypeParsablePoint, scale?: boolean): void;
412
+ /**
413
+ * Changes a 2D scene to simulate zooming in and out
414
+ */
415
+ zoomScene(scene: Scene): void;
416
+ panTransform(scene: Scene): Point;
417
+ /**
418
+ * Pan a scene with the current pan.
419
+ * @param {Scene} scene
420
+ */
421
+ panScene(scene: Scene): void;
422
+ updateZoom(mag: number, zoomPosition: Point, distance?: number, angle?: number): void;
423
+ startPinchZoom(touch1PixelPos: Point, touch2PixelPos: Point, beingTouchedElement: null | FigureElement): void;
424
+ pinchZoom(touch1PixelPos: Point, touch2PixelPos: Point, beingTouchedElement: null | FigureElement): void;
425
+ endPinchZoom(): void;
426
+ enableZoom(): void;
427
+ disableZoom(): void;
428
+ /**
429
+ * Set zoom gesture options.
430
+ *
431
+ * @param {OBJ_ZoomOptions} options
432
+ */
433
+ setZoomOptions(options: OBJ_ZoomOptions): void;
434
+ /**
435
+ * Set pan gesture options.
436
+ *
437
+ * @param {OBJ_ZoomOptions} options
438
+ */
439
+ setPanOptions(options: OBJ_PanOptions): void;
440
+ /**
441
+ * Set zoom manually.
442
+ *
443
+ * Zoom magnitude can be set with zoom position or pan offset. Either a
444
+ * position or pan should be used (not both).
445
+ *
446
+ * NB: if manually creating positions or offsets, the position (p) to offset
447
+ * (o) for some zoom (z) conversion is:
448
+ *
449
+ * o = -(p / z - p)
450
+ *
451
+ * p = -o / (1/z - 1)
452
+ *
453
+ * @param {OBJ_ManualZoom} zoom
454
+ * @param {boolean} notify `true` to send `'zoom'` notification after set
455
+ * (`true`)
456
+ */
457
+ setZoom(zoom: {
458
+ mag: number;
459
+ position?: TypeParsablePoint;
460
+ offset?: TypeParsablePoint;
461
+ }, notify?: boolean): void;
462
+ zoomChanged(notify?: boolean): void;
463
+ panChanged(notify?: boolean): void;
464
+ _setZoomPan(mag: number, offset: Point, position?: Point, angle?: number, distance?: number, pinching?: boolean): void;
465
+ /**
466
+ * Set pan offset manually.
467
+ * @param {TypeParsablePoint} offset
468
+ * @param {boolean} notify `true` to send `'zoom'` notification after set (`true`)
469
+ */
470
+ setPan(offset: TypeParsablePoint, notify?: boolean): void;
471
+ /**
472
+ * @return {OBJ_CurrentZoom}
473
+ */
474
+ getZoom(): {
475
+ mag: number;
476
+ offset: Point;
477
+ last: {
478
+ mag: number;
479
+ normPosition: Point;
480
+ position: Point;
481
+ angle: number;
482
+ distance: number;
483
+ };
484
+ current: {
485
+ position: Point;
486
+ normPosition: Point;
487
+ angle: number;
488
+ distance: number;
489
+ };
490
+ };
491
+ /**
492
+ * @return {OBJ_CurrentPan}
493
+ */
494
+ getPan(): {
495
+ offset: Point;
496
+ delta: Point;
497
+ };
498
+ setZoomMag(mag: number): void;
499
+ setPanOffset(offset: Point): void;
500
+ setFigure(figure: OBJ_FigureForElement): void;
501
+ cleanupIDs(): void;
502
+ }
503
+ /**
504
+ A zoom pan can be defined as:
505
+ 1) what coordinate is in the middle of the screen (C)
506
+ 2) what the zoom factor is
507
+
508
+ A pan zoom in a scene then:
509
+ - Pans camera so C is in middle of screen
510
+ - Zooms
511
+
512
+ If a point is zoomed on, then it stays in its relative position in the zoomed
513
+ scene space, meaning C keeps changing.
514
+
515
+ Therefore to find C:
516
+ - Find relative position of point in scene
517
+ - using the zoom factor find the center point in the zoomed scene
518
+ */
519
+ /**
520
+ A gesture primitive is a rectangle within an associated scene.
521
+
522
+ The rectangle has a center point.
523
+
524
+ To define a zoomed area of the rectangle, two points are needed:
525
+ - point of the rectangle that will be the new center point of the screen
526
+ - zoom magnification
527
+
528
+
529
+ A gesture primitive has an associated scene.
530
+
531
+ The gesture rectangle covers a portion of space within the scene
532
+ Any zoom and pan combination in a scene can be represented by:
533
+ * center position
534
+ * zoom magnification
535
+
536
+ */
@@ -0,0 +1,175 @@
1
+ import { FigureElementPrimitive } from '../Element';
2
+ import { CustomAnimationStep } from '../Animation/AnimationStep/CustomStep';
3
+ import AnimationManager from '../Animation/AnimationManager';
4
+ import type { OBJ_AnimationStep } from '../Animation/AnimationStep';
5
+ /**
6
+ * {@link FigureElementPrimitive} that can efficiently translate large numbers
7
+ * of points.
8
+ *
9
+ * ![](./apiassets/morph.gif)
10
+ *
11
+ * ![](./apiassets/morph2.gif)
12
+ *
13
+ * The morph primitive is optimized to animate hundreds of thousands of
14
+ * points with minimal performance impact.
15
+ *
16
+ * Multiple arrays of points can be defined, and the translation of
17
+ * corresponding points in two arrays can be animated.
18
+ *
19
+ * Being able to accomodate so many points means this primitive can be used to
20
+ * efficiently morph shapes.
21
+ *
22
+ * All points in all point arrays can be assigned an individual color if
23
+ * desired. Use `color: TypeColor` to assign all points in all arrays the same
24
+ * color, `color: Array<TypeColor>` to assign all points in each array a
25
+ * specific color, `color: Array<Array<TypeColor>>` to assign each point in
26
+ * each array a specific color, and
27
+ * `color: Array<TypeColor | Array<TypeColor>` to assign some point arrays
28
+ * with one color, and others with a specific color per point.
29
+ *
30
+ * A point array is an array of numbers representing consecutive x, y points.
31
+ * For example, [x1, y1, x2, y2, ...].
32
+ *
33
+ * A color array is an array of numbers representing the color of each points.
34
+ * For example, [r1, g1, b1, a1, r2, g2, b2, a2, ...].
35
+ *
36
+ * If `color` is an array of colors and/or color arrays, then the its length
37
+ * must be equal to the number of point Arrays. The colors in the array will
38
+ * be matched up with the corresponding point arrays in `points`.
39
+ *
40
+ * This element's specialty is creating a visual effect, and so does not
41
+ * automatically calculate touch borders, and doesn't allow for color changes
42
+ * (with the `setColor`, `dim`, and `undim` methods). If touch borders are
43
+ * desired then either setup touch borders manually, or use a different
44
+ * element as a touch pad.
45
+ *
46
+ * This element comes with two specialized methods and an animation step:
47
+ * - `setPoints` - sets points to a specific point array
48
+ * - `setPointsBetween` - sets points to a position between two point arrays
49
+ * - `animations.morph` - morph between `start` and `target`
50
+ *
51
+ * Note, while animation is efficient, loading or generating hundreds of
52
+ * thousands of points when first instantiated can be slow on lower
53
+ * end systems, and may need to be accounted for (like letting the user know
54
+ * that loading is ongoing).
55
+ *
56
+ * @example
57
+ * const { polylineToShapes, getPolygonCorners } = Fig.morph;
58
+ * const { range } = Fig;
59
+ *
60
+ * // Number of shapes that make up the lines
61
+ * const n = 300;
62
+ *
63
+ * // Generate a line of points along a sinc function
64
+ * const sinc = (xIn, a, b) => {
65
+ * const x = xIn === 0 ? 0.00001 : xIn;
66
+ * return a * Math.sin(b * x) / (b * x);
67
+ * };
68
+ *
69
+ * // Generate line of shapes along a sinc function
70
+ * const xValues = range(-0.8, 0.8, 0.01);
71
+ * const [sincPoints] = polylineToShapes({
72
+ * points: xValues.map(x => [x, sinc(x, 0.6, 20)]),
73
+ * num: n,
74
+ * size: 0.04,
75
+ * shape: 15,
76
+ * });
77
+ *
78
+ * // Generate a line of shapes along a square
79
+ * const [squarePoints] = polylineToShapes({
80
+ * points: [[0.5, 0.5], [-0.5, 0.5], [-0.5, -0.5], [0.5, -0.5]],
81
+ * num: n,
82
+ * size: 0.04,
83
+ * close: true,
84
+ * shape: 15,
85
+ * });
86
+ *
87
+ * // Generate a line of shapes along a circle
88
+ * const [circlePoints] = polylineToShapes({
89
+ * points: getPolygonCorners({ radius: 0.5, sides: 50, rotation: Math.PI / 4 }),
90
+ * num: n,
91
+ * size: 0.04,
92
+ * close: true,
93
+ * shape: 15,
94
+ * });
95
+ *
96
+ * const morpher = figure.add({
97
+ * make: 'morph',
98
+ * names: ['sinc', 'square', 'circle'],
99
+ * points: [sincPoints, squarePoints, circlePoints],
100
+ * color: [1, 0, 0, 1],
101
+ * });
102
+ *
103
+ * // Animate morph
104
+ * morpher.animations.new()
105
+ * .delay(1)
106
+ * .morph({ start: 'sinc', target: 'square', duration: 2 })
107
+ * .morph({ start: 'square', target: 'circle', duration: 2 })
108
+ * .morph({ start: 'circle', target: 'sinc', duration: 2 })
109
+ * .start();
110
+ *
111
+ * @example
112
+ * const { imageToShapes, circleCloudShapes, polylineToShapes } = Fig.morph;
113
+ * const { range } = Fig;
114
+ *
115
+ * const image = new Image();
116
+ * image.src = './logocolored.png';
117
+ * image.onload = () => {
118
+ * const [logo, logoColors] = imageToShapes({
119
+ * image,
120
+ * width: 2,
121
+ * height: 2,
122
+ * dither: 0.003,
123
+ * });
124
+ *
125
+ * const n = logo.length / 2 / 6;
126
+ * const cloud = circleCloudShapes({
127
+ * radius: 3,
128
+ * num: n,
129
+ * size: 0.005,
130
+ * });
131
+ *
132
+ * const xValues = range(-0.8, 0.8, 0.001);
133
+ * const [sine] = polylineToShapes({
134
+ * points: xValues.map(x => [x, 0.3 * Math.sin(x * 2 * Math.PI / 0.4)]),
135
+ * num: n,
136
+ * size: 0.01,
137
+ * });
138
+ *
139
+ * const m = figure.add({
140
+ * make: 'morph',
141
+ * points: [cloud, logo, sine],
142
+ * names: ['cloud', 'logo', 'sine'],
143
+ * color: [logoColors, logoColors, [0, 0, 1, 1]],
144
+ * });
145
+ *
146
+ * m.setPoints('sine');
147
+ * m.animations.new()
148
+ * .delay(1)
149
+ * .morph({ start: 'sine', target: 'cloud', duration: 2 })
150
+ * .morph({ start: 'cloud', target: 'logo', duration: 2 })
151
+ * .start();
152
+ * };
153
+ * @group Morphing
154
+ */
155
+ export default class FigureElementPrimitiveMorph extends FigureElementPrimitive {
156
+ shapeNameMap: {
157
+ [name: string]: number;
158
+ };
159
+ animations: {
160
+ morph: (options: OBJ_AnimationStep) => CustomAnimationStep;
161
+ } & AnimationManager;
162
+ /**
163
+ * Set points position to be between two points arrays
164
+ * @param {string | number} from name or index of point array to morph from
165
+ * @param {string | number} to name or index of point array to morph to
166
+ * @param {number} percent percent of morph between from and to
167
+ */
168
+ setPointsBetween(from: string | number, to: string | number, percent: number): void;
169
+ /**
170
+ * Set points to equal a point array
171
+ * @param {string | number} points point array name or index to set
172
+ */
173
+ setPoints(points: string | number): void;
174
+ getIndex: (shapeNameOrIndex: string | number) => number;
175
+ }