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,788 @@
1
+ import type { TypeParsablePoint, TypeParsableTransform, TypeParsableBorder, Rect, Point, TypeParsableBuffer } from '../../tools/g2';
2
+ import type { FigureElement, OBJ_Scenarios, OBJ_ElementMove } from '../Element';
3
+ import type { TypeGLUniform, TypeGLBufferType, TypeGLBufferUsage } from '../DrawingObjects/GLObject/GLObject';
4
+ import type { TypeColor, TypeDash, OBJ_Font } from '../../tools/types';
5
+ import type Scene from '../../tools/geometry/scene';
6
+ import type { OBJ_Scene } from '../../tools/geometry/scene';
7
+ import type { TypeVertexShader, TypeFragmentShader } from '../webgl/shaders';
8
+ /**
9
+ * GL primitive type that describes the shapes the vertices are creating.
10
+ * Analagous to WebGL [drawing primitives](https://webglfundamentals.org/webgl/lessons/webgl-points-lines-triangles.html)
11
+ * where the mapping between the two are:
12
+ * - `'TRIANGLES'`: TRIANGLES
13
+ * - `'STRIP'`: TRIANGLE_STRIP
14
+ * - `'FAN'`: TRIANGLE_FAN
15
+ * - `'LINES'`: LINES
16
+ * - `'POINTS'`: LINES
17
+ *
18
+ * `'TRIANGLES' | 'POINTS' | 'FAN' | 'STRIP' | 'LINES'`
19
+ * @group Shaders
20
+ */
21
+ export type TypeGLPrimitive = 'TRIANGLES' | 'POINTS' | 'FAN' | 'STRIP' | 'LINES';
22
+ /**
23
+ * Line style definition object.
24
+ * @property {'mid' | 'outside' | 'inside' | 'positive' | 'negative' | number} [widthIs]
25
+ * defines how the width is grown from the polyline's points. When using
26
+ * `number`, 0 is the equivalent of 'inside' and 1 is the equivalent of
27
+ * 'outside'.
28
+ * @property {number} [width] line width
29
+ * @property {TypeDash} [dash] select solid or dashed line
30
+ * @property {TypeColor} [color] line color
31
+ * @interface
32
+ * @group Misc Shapes
33
+ */
34
+ export type OBJ_LineStyleSimple = {
35
+ widthIs?: 'mid' | 'outside' | 'inside' | 'positive' | 'negative' | number;
36
+ width?: number;
37
+ dash?: TypeDash;
38
+ color?: TypeColor;
39
+ };
40
+ export type OBJ_LineStyleSimple_Defined = {
41
+ widthIs: 'mid' | 'outside' | 'inside' | 'positive' | 'negative' | number;
42
+ width: number;
43
+ dash?: TypeDash;
44
+ color?: TypeColor;
45
+ };
46
+ /**
47
+ * {@link FigureElementCollection} options object.
48
+ *
49
+ * <p class="inline_gif"><img src="./apiassets/collection.gif" class="inline_gif_image"></p>
50
+ *
51
+ * A collection is a group of other {@link FigureElement}s that will all
52
+ * inherit the parent collections transform.
53
+ *
54
+ * @property {TypeParsableTransform} [transform]
55
+ * @property {TypeParsablePoint} [position] if defined, will overwrite first
56
+ * translation of `transform`
57
+ * @property {TypeColor} [color] default color
58
+ * @property {FigureElement | null} [parent] parent of collection
59
+ * @property {TypeParsableBuffer | TypeParsableBorder | 'children' | 'rect'} [border]
60
+ * defines border of collection. Use `children` to use the borders of
61
+ * the children. Use `'rect'` for the bounding rectangle of the borders
62
+ * of the children. Use `TypeParsableBuffer` for the bounding rectangle of the
63
+ * borders of the children with some buffer. Use `TypeParsableBorder` for
64
+ * a custom border. (`'children'`)
65
+ * @property {TypeParsableBuffer | TypeParsableBorder | 'border' | 'rect'} [touchBorder]
66
+ * defines the touch border of the collection. Use `'border'` to use the same
67
+ * as the border of the collection. Use `children` to use the touch borders of
68
+ * the children. Use `'rect'` for the bounding rectangle of the touch borders
69
+ * of the children. Use `TypeParsableBuffer` for the bounding rectangle of the
70
+ * touch borders of the children with some buffer. Use `TypeParsableBorder` for
71
+ * a custom touch border. (`'children'`)
72
+ *
73
+ * @example
74
+ * figure.add(
75
+ * {
76
+ * name: 'c',
77
+ * make: 'collection',
78
+ * elements: [ // add two elements to the collection
79
+ * {
80
+ * name: 'hex',
81
+ * make: 'polygon',
82
+ * sides: 6,
83
+ * radius: 0.5,
84
+ * },
85
+ * {
86
+ * name: 'text',
87
+ * make: 'text',
88
+ * text: 'hexagon',
89
+ * position: [0, -0.8],
90
+ * xAlign: 'center',
91
+ * font: { size: 0.3 },
92
+ * },
93
+ * ],
94
+ * },
95
+ * );
96
+ *
97
+ * // When a collection rotates, then so does all its elements
98
+ * figure.getElement('c').animations.new()
99
+ * .rotation({ target: Math.PI * 1.999, direction: 1, duration: 5 })
100
+ * .start();
101
+ *
102
+ * @example
103
+ * // Collections and primitives can also be created from `figure.collections`
104
+ * // and `figure.primitives`.
105
+ * const c = figure.collections.collection();
106
+ * const hex = figure.primitives.polygon({
107
+ * sides: 6,
108
+ * radius: 0.5,
109
+ * });
110
+ * const text = figure.primitives.text({
111
+ * text: 'hexagon',
112
+ * position: [0, -0.8],
113
+ * xAlign: 'center',
114
+ * font: { size: 0.3 },
115
+ * });
116
+ * c.add('hex', hex);
117
+ * c.add('text', text);
118
+ * figure.add('c', c);
119
+ *
120
+ * // When a collection rotates, then so does all its elements
121
+ * c.animations.new()
122
+ * .delay(1)
123
+ * .rotation({ target: Math.PI * 1.999, direction: 1, duration: 5 })
124
+ * .start();
125
+ * @interface
126
+ * @group 2D Shape Collections
127
+ */
128
+ export type OBJ_Collection = {
129
+ transform?: TypeParsableTransform;
130
+ position?: TypeParsablePoint;
131
+ color?: TypeColor;
132
+ parent?: FigureElement | null;
133
+ border?: TypeParsableBuffer | TypeParsableBorder | 'children' | 'rect' | number;
134
+ touchBorder?: TypeParsableBuffer | TypeParsableBorder | 'border' | 'children' | number | 'rect';
135
+ };
136
+ /**
137
+ * Texture definition object
138
+ *
139
+ * A texture file is an image file like a jpg, or png.
140
+ *
141
+ * Textures can be used instead of colors to fill a shape in WebGL.
142
+ *
143
+ * Each vertex in a shape is mapped to a color in the texture. A texture
144
+ * coordinate is used to define where to sample the color in the texture.
145
+ * Texture coodinates (x, y) are between 0 and 1 where the bottom left corner of
146
+ * the texture is (0, 0) and the top right corner is (1, 1). Note, even if the
147
+ * texture is being mapped onto a 3D surface, the texture coordinates are
148
+ * always two dimensional as the texture is two dimensional.
149
+ *
150
+ * Texture colors can be mapped to vertices of the shape with either:
151
+ * - `coords` - directly define the texture coordinates for each vertex
152
+ * - `mapFrom`, `mapTo` - automatically map texture coordinates to the (x, y)
153
+ * draw space components of the shape's vertices. This is only useful for 2D
154
+ * shapes (3D shapes should use `coords`).
155
+ *
156
+ * To automatically map the texture to a shapes vertices, a rectangular window
157
+ * in the texture (`mapFrom`) and a rectangular window in draw space (`mapTo`)
158
+ * is defined. The texture is then offset and scaled such that its window
159
+ * aligns with the draw space window.
160
+ *
161
+ * Therefore, to make a 1000 x 500 image fill a 2 x 1 rectangle in draw space
162
+ * centered at (0, 0) you would define:
163
+ *
164
+ * ```
165
+ * mapFrom: new Rect(0, 0, 1, 1)
166
+ * mapTo: new Rect(-1, -0.5, 2, 1)
167
+ * ```
168
+ *
169
+ * If instead you wanted to zoom the image in the same rectange by a factor of 2
170
+ * you could either:
171
+ *
172
+ * ```
173
+ * mapFrom: new Rect(0.25, 0.25, 0.5, 0.5)
174
+ * mapTo: new Rect(-1, -0.5, 2, 1)
175
+ * ```
176
+ *
177
+ * or
178
+ *
179
+ * ```
180
+ * mapFrom: new Rect(0, 0, 1, 1)
181
+ * mapTo: new Rect(-2, -1, 4, 2)
182
+ * ```
183
+ *
184
+ * Two ways of doing this are provided as sometimes it is more convenient to
185
+ * think about the window on the image, and other times the window in draw
186
+ * space.
187
+ *
188
+ * If the shape has fill outside the texture boundaries then either the
189
+ * texture can be repeated, or a pixel from the border (edge) of the image is
190
+ * used (called clamping to edge).
191
+ * WebGL only allows images that are square with a side length that is a
192
+ * power of 2 (such as 16, 32, 64, 128 etc) to be repeated. All other images
193
+ * can only be clamped to their edge.
194
+ *
195
+ * To repeat all other image resolutions, a texture can be mapped to a rectangle
196
+ * and then the rectangle repeated throughout the figure.
197
+ *
198
+ * @property {string} src The url or location of the image
199
+ * @property {Array<number>} [coords] texture coordinates to map to each vertex
200
+ * in shape. If empty, then the texture coorindates will be automatically
201
+ * generated using `mapTo` and `mapFrom`. (`[]`)
202
+ * @property {TypeParsableRect} [mapFrom] image space window (`new Rect(0, 0, 1, 1)`)
203
+ * @property {TypeParsableRect} [mapTo] draw space window (`new TypeParsableRect(-1, -1, 2, 2)`)
204
+ * @property {TypeParsableRect} [mapToAttribute] attribute name of the vertex
205
+ * definitions to map the texture to (`a_vertex`)
206
+ * @property {boolean} [repeat] `true` will tile the image. Only works with
207
+ * images that are square whose number of side pixels is a power of 2 (`false`)
208
+ * @property {TypeColor} [loadColor] color to display while texture is loading.
209
+ * Use an alpha of 0 if no color is desired. (`[0, 0, 1, 0.5]`)
210
+ * @property {() => void} [onLoad] textures are loaded asynchronously, so this
211
+ * callback can be used to execute code after the texture is loaded. At a
212
+ * minimum, any custom function here should include a call to animate the next
213
+ * frame (`figure.animateNextFrame`)
214
+ * @interface
215
+ * @group Misc Shapes
216
+ */
217
+ export type OBJ_Texture = {
218
+ src?: string;
219
+ mapFrom?: Rect;
220
+ mapTo?: Rect;
221
+ mapToAttribute?: string;
222
+ coords?: Array<number>;
223
+ loadColor?: TypeColor;
224
+ repeat?: boolean;
225
+ onLoad?: () => void;
226
+ };
227
+ /**
228
+ * Pulse options object
229
+ *
230
+ * @property {number} [scale] scale to pulse
231
+ * @property {number} [duration] duration to pulse
232
+ * @property {number} [frequency] frequency to pulse where 0
233
+ * @interface
234
+ * @group Misc Shapes
235
+ */
236
+ export type OBJ_PulseScale = {
237
+ duration?: number;
238
+ scale?: number;
239
+ frequency?: number;
240
+ };
241
+ /**
242
+ * GL buffer.
243
+ *
244
+ * @property {string} name name of attribute in shader
245
+ * @property {Array<number>} data array of values
246
+ * @property {number} [size] number of values per attribute (`2`)
247
+ * @property {TypeGLBufferType} [type] (`'FLOAT'`)
248
+ * @property {boolean} [normalize] (`false`)
249
+ * @property {number} [stride] (`0`)
250
+ * @property {number} [offset] (`0`)
251
+ * @property {TypeGLBufferUsage} [usage] (`'STATIC'`)
252
+ * @interface
253
+ * @group Shaders
254
+ */
255
+ export type OBJ_GLAttribute = {
256
+ name: string;
257
+ data: Array<number>;
258
+ size?: number;
259
+ type?: TypeGLBufferType;
260
+ normalize?: boolean;
261
+ stride?: number;
262
+ offset?: number;
263
+ usage?: TypeGLBufferUsage;
264
+ };
265
+ /**
266
+ * GL vertex - associated with attribute 'a_vertex' in shader.
267
+ *
268
+ * Assumes buffer parameters of:
269
+ * - name: 'a_vertex'
270
+ * - size: 2
271
+ * - type: 'FLOAT'
272
+ * - normalize: false
273
+ * - stride: 0
274
+ * - offset: 0
275
+ *
276
+ * @property {Array<number>} data array of values
277
+ * @property {TypeGLBufferUsage} [usage] (`'STATIC'`)
278
+ * @interface
279
+ * @group Shaders
280
+ */
281
+ export type OBJ_GLVertexBuffer = {
282
+ data: Array<number>;
283
+ usage: TypeGLBufferUsage;
284
+ };
285
+ /**
286
+ * GL Uniform
287
+ * @property {string} name name of uniform in shader
288
+ * @property {1 | 2 | 3 | 4} length
289
+ * @property {TypeGLUniform} type
290
+ * @interface
291
+ * @group Shaders
292
+ */
293
+ export type OBJ_GLUniform = {
294
+ name: string;
295
+ length: 1 | 2 | 3 | 4;
296
+ type: TypeGLUniform;
297
+ };
298
+ /**
299
+ * Touch options for a FigureElement.
300
+ *
301
+ * @property {boolean} [enable] `true` to enable touch (`true`)
302
+ * @property {string | ((Point, FigureElement) => void)} [onClick] function to
303
+ * execute when element is touched. If string, then a function from the
304
+ * FunctionMap is used.
305
+ * @property {string} [colorSeed] use a unique string to reset color generation
306
+ * of unique colors used for touch determination (debug only) (`'default'`)
307
+ * @interface
308
+ * @group Interactivity
309
+ */
310
+ export type OBJ_Touch = {
311
+ onClick?: string | ((p: Point, el: FigureElement) => void);
312
+ colorSeed?: string;
313
+ enable?: boolean;
314
+ };
315
+ /**
316
+ * Options object for any {@link FigureElementPrimitive}.
317
+ *
318
+ * These properties are available when defining any FigureElementPrimitive.
319
+ *
320
+ * @property {string} [name] name of figure element
321
+ * @property {TypeParsablePoint} [position] position overrides `transform` translation
322
+ * @property {TypeParsableTransform} [transform] transform to apply to element
323
+ * @property {TypeColor} [color] color to apply to element (is passed as the
324
+ * 'u_color' uniform to the fragment shader)
325
+ * @property {boolean | OBJ_Touch} [touch] `true`, `number` or
326
+ * `TypeParsablePoint` will set the element as touchable. If `number`, then
327
+ * element touch volume is the scaled actual volume in x, y, and z. For
328
+ * example, if `2`, then the touchable volume is twice the actual volume. If
329
+ * `TypeParsablePoint` then the x, y, and z scales can be set independantly
330
+ * (`false`)
331
+ * @property {boolean | OBJ_ElementMove} [move] setting this to anything but
332
+ * `false` will set the element as movable. Use `OBJ_ElementMove` to customize
333
+ * the movement options
334
+ * @property {TypeColor} [dimColor] RGBA is used when vertex colors are from a
335
+ * uniform, otherwise just the alpha channel is used.
336
+ * @property {TypeColor} [defaultColor]
337
+ * @property {OBJ_Scenarios} [scenarios] Define
338
+ * position/transform/rotation/scale/color scenarios tied to the element
339
+ * @property {Scene} [scene] Give the element a custom scene that is independant
340
+ * of the figure scene. For example, use this to create a 3D object in a 2D
341
+ * figure.
342
+ * @interface
343
+ * @group 2D Shape Primitives
344
+ */
345
+ export type OBJ_FigurePrimitive = {
346
+ name?: string;
347
+ position?: TypeParsablePoint;
348
+ transform?: TypeParsableTransform;
349
+ color?: TypeColor;
350
+ touch?: boolean | OBJ_Touch;
351
+ move?: boolean | OBJ_ElementMove;
352
+ dimColor?: TypeColor;
353
+ defaultColor?: TypeColor;
354
+ scenarios?: OBJ_Scenarios;
355
+ scene?: Scene | OBJ_Scene;
356
+ };
357
+ /**
358
+ * Color definition for a gl primitive.
359
+ * @property {Array<number>} data color data
360
+ * @property {boolean} [normalize] if `true`, then color data values are between
361
+ * 0 and 255 (`false`)
362
+ * @property {3 | 4} [size] if `3`, then color data is RGB, if `4` then color
363
+ * data is RGBA
364
+ * @interface
365
+ * @group Shaders
366
+ */
367
+ export type OBJ_GLColorData = {
368
+ data: Array<number>;
369
+ normalize?: boolean;
370
+ size?: 3 | 4;
371
+ };
372
+ /**
373
+ * `TypeText = 'gl' | '2d'`
374
+ *
375
+ * `'gl'`: bitmapped text drawn in webgl from a autogenerated atlas. Use when
376
+ * text size changes rarely, or text needs to be behind other shapes.
377
+ *
378
+ * '2d': text drawn on a '2d' html canvas. Text will always be ontop of the
379
+ * webgl canvas. Use when text must be displayed a large dynamic range of
380
+ * scales, or text needs to be always on top.
381
+ * @group Misc Text
382
+ */
383
+ export type TypeText = 'gl' | '2d';
384
+ /**
385
+ * DiagramElementPrimitive with low level WegGL drawing object.
386
+ *
387
+ * A number of WebGL specific properties can be defined.
388
+ *
389
+ * WebGL specific properties are `glPrimitive`, `vertexShader`, `fragmentShader`
390
+ * `attributes`, `uniforms` and an optional `texture`. The
391
+ * nomencalture for these properties is directly from WebGL.
392
+ *
393
+ * Properties `vertices`, `colors`, `dimension`, `light` and `normals` provide
394
+ * shortcuts for defining the shaders, attributes and uniforms when shaders are
395
+ * not customized.
396
+ *
397
+ * Shaders are programs that run in the GPU and are written in a C-like
398
+ * language. Shaders operate on each vertex of a shape in parallel. The vertex
399
+ * shader transforms each vertex to some specific position, and performs color
400
+ * and lighting related calculations for scenarios when color and/or lighting
401
+ * are vertex specific. The fragment shader computes the final color of each
402
+ * pixel (fragment) between the vertices that make up a `glPrimitive`.
403
+ *
404
+ * Data can be passed from the CPU (JavaScript) to the GPU with attributes and
405
+ * uniforms.
406
+ *
407
+ * Attributes are arrays of numbers that represent data specific for
408
+ * each vertex in a shape. At a minimum, an attribute that defines the (x, y)
409
+ * or (x, y, z) coordinates of each vertex is needed. Other attributes might be
410
+ * color if all verticies do not have the same color, texture coordinates to
411
+ * map vertex color to a 2D image texture, and normal vectors for defining how
412
+ * light reflects from and thus brightens a surface. Each attribute must define
413
+ * data for every vertex in a shape. Attributes are typically defined and loaded
414
+ * into GPU buffers once. On each animation frame, the GPU will pass the
415
+ * buffered attributes to the shaders. Attributes are only passed to the vertex
416
+ * shader.
417
+ *
418
+ * Uniforms are small amounts of data (vectors or square matrices with a maximum
419
+ * dimension/rank of 4) that are passed from the CPU to the GPU on each frame.
420
+ * A uniform value can be passed to both the vertex and fragment shader and is
421
+ * thus available to all vertices and fragments. A uniform is like a
422
+ * global variable whose value can change on each animation frame. Example
423
+ * uniforms are:
424
+ * - transform matrix that transforms all vertices in space the same way
425
+ * - color value that colors all vertices the same (instead of having to define
426
+ * a color for each vertex)
427
+ * - light source properties like position, direction, and amplitude
428
+ *
429
+ * Data can be passed from the vertex shader to the fragment shader in variables
430
+ * called *varyings*. Example varyings include color attributes (color that is
431
+ * defined for each vertex) and lighting information if the lighting is vertex
432
+ * dependent.
433
+ *
434
+ * Shaders source code can be defined as a string, or composed automatically
435
+ * from options including `dimension`, `color` and `light`. Shader source code
436
+ * contains attribute and uniform variables, and these attributes and uniforms
437
+ * need to be defined with `attributes` and `uniforms`.
438
+ *
439
+ * If using automated shader composition, then only attributes need to be
440
+ * defined. The uniforms will be passed to the shader from the information in
441
+ * the `color` property of the FigureElementPrimitive and the `scene` used to
442
+ * draw the primitive. See {@link OBJ_VertexShader} and
443
+ * {@link OBJ_FragmentShader} for names of attributes and uniforms used in the
444
+ * shaders, and when they are used.
445
+ *
446
+ * @property {TypeGLPrimitive} [glPrimitive]
447
+ * @property {TypeVertexShader} [vertexShader]
448
+ * @property {TypeFragmentShader} [fragmentShader]
449
+ * @property {Array<OBJ_GLAttribute>} [attributes]
450
+ * @property {Array<OBJ_GLUniform>} [uniforms]
451
+ * @property {OBJ_Texture} [texture]
452
+ * @property {2 | 3} [dimension] default value for `dimension in vertex shader
453
+ * if vertex shader is undefined (`2`)
454
+ * @property {'point' | 'directional' | null} [light] default value for `light`
455
+ * in vertex and fragment shader if shaders are not otherwise defined (`null`)
456
+ * @property {Array<number> | OBJ_GLColorData} [colors] default value for
457
+ * `light` in vertex and fragment shader if shaders are not otherwise defined
458
+ * (`uniform`)
459
+ * @property {OBJ_GLVertexBuffer} [vertices] create a `a_vertex` attribute for
460
+ * vertex coordinates
461
+ * @property {OBJ_GLVertexBuffer} [normals] create a `a_normal` attribute
462
+ *
463
+ * @example
464
+ * // Default options are 2D, uniform color, TRIANGLES.
465
+ * // Create two red triangles (6 vertices, 12 values)
466
+ * figure.add({
467
+ * make: 'gl',
468
+ * vertices: [0, 0, 0.5, 0, 0, 0.5, 0.5, 0, 1, 0, 0.5, 0.5],
469
+ * color: [1, 0, 0, 1],
470
+ * });
471
+ *
472
+ * @example
473
+ * // Simple rotatable element with a custom position
474
+ * figure.add({
475
+ * make: 'gl',
476
+ * vertices: [0, 0, 0.5, 0, 0, 0.5, 0.5, 0, 1, 0, 0.5, 0.5],
477
+ * color: [1, 0, 0, 1],
478
+ * position: [-0.4, -0.4, 0],
479
+ * move: { type: 'rotation' },
480
+ * });
481
+ *
482
+ * @example
483
+ * // Assign a color to each vertex
484
+ * figure.add({
485
+ * make: 'gl',
486
+ * vertices: [0, 0, 0.5, 0, 0, 0.5, 0.5, 0, 1, 0, 0.5, 0.5],
487
+ * colors: [
488
+ * 0, 0, 1, 1,
489
+ * 1, 0, 0, 1,
490
+ * 0, 0, 1, 1,
491
+ * 1, 0, 0, 1,
492
+ * 0, 0, 1, 1,
493
+ * 1, 0, 0, 1,
494
+ * ],
495
+ * });
496
+ *
497
+ * @example
498
+ * // Assign a color to each vertex, using just 3 numbers per color (no alpha)
499
+ * figure.add({
500
+ * make: 'gl',
501
+ * vertices: [0, 0, 0.5, 0, 0, 0.5, 0.5, 0, 1, 0, 0.5, 0.5],
502
+ * colors: {
503
+ * data: [
504
+ * 0, 0, 1,
505
+ * 1, 0, 0,
506
+ * 0, 0, 1,
507
+ * 1, 0, 0,
508
+ * 0, 0, 1,
509
+ * 1, 0, 0,
510
+ * ],
511
+ * size: 3,
512
+ * },
513
+ * });
514
+ *
515
+ * @example
516
+ * // Texture filled square
517
+ * figure.add({
518
+ * make: 'gl',
519
+ * vertices: [-0.5, -0.5, 0.5, -0.5, -0.5, 0.5, 0.5, -0.5, 0.5, 0.5, -0.5, 0.5],
520
+ * numVertices: 6,
521
+ * texture: {
522
+ * src: './flower.jpeg',
523
+ * coords: [0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1],
524
+ * loadColor: [0, 0, 0, 0],
525
+ * },
526
+ * });
527
+ *
528
+ * @example
529
+ * // Make a 3D cube using composed shaders
530
+ * const { toNumbers } = Fig;
531
+ * const [cubeVertices, cubeNormals] = Fig.cube({ side: 0.5 });
532
+ * figure.scene.setProjection({ style: 'orthographic' });
533
+ * figure.scene.setCamera({ position: [2, 1, 2] });
534
+ * figure.scene.setLight({ directional: [0.7, 0.5, 1] });
535
+ *
536
+ * figure.add({
537
+ * make: 'gl',
538
+ * light: 'directional',
539
+ * dimension: 3,
540
+ * vertices: toNumbers(cubeVertices),
541
+ * normals: toNumbers(cubeNormals),
542
+ * color: [1, 0, 0, 1],
543
+ * });
544
+ *
545
+ * @example
546
+ * // Custom shaders
547
+ * // Make a shader with a custom attribute aVertex and custom uniform uColor,
548
+ * // which are then defined in the options.
549
+ * // Note, the `u_worldViewProjectionMatrix` uniform does not need to be defined
550
+ * // as this will be passed by FigureOne using the Scene information of the
551
+ * // figure (or element if an element has a custom scene attached to it).
552
+ * figure.add({
553
+ * make: 'gl',
554
+ * vertexShader: {
555
+ * src: `
556
+ * uniform mat4 u_worldViewProjectionMatrix;
557
+ * attribute vec4 aVertex;
558
+ * void main() {
559
+ * gl_Position = u_worldViewProjectionMatrix * aVertex;
560
+ * }`,
561
+ * vars: ['aVertex', 'u_worldViewProjectionMatrix'],
562
+ * },
563
+ * fragmentShader: {
564
+ * src: `
565
+ * precision mediump float;
566
+ * uniform vec4 uColor;
567
+ * void main() {
568
+ * gl_FragColor = uColor;
569
+ * gl_FragColor.rgb *= gl_FragColor.a;
570
+ * }`,
571
+ * vars: ['uColor'],
572
+ * },
573
+ * attributes: [
574
+ * {
575
+ * name: 'aVertex',
576
+ * size: 3,
577
+ * data: [0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0.5, 0, 0, 1, 0, 0, 0.5, 0.5, 0],
578
+ * },
579
+ * ],
580
+ * uniforms: [
581
+ * {
582
+ * name: 'uColor',
583
+ * length: 4,
584
+ * value: [1, 0, 0, 1],
585
+ * },
586
+ * ],
587
+ * });
588
+ * @interface
589
+ * @group Shaders
590
+ */
591
+ export type OBJ_GenericGL = {
592
+ glPrimitive?: 'TRIANGLES' | 'POINTS' | 'FAN' | 'STRIP' | 'LINES';
593
+ vertexShader?: TypeVertexShader;
594
+ fragmentShader?: TypeFragmentShader;
595
+ attributes?: Array<OBJ_GLAttribute>;
596
+ uniforms?: Array<OBJ_GLUniform>;
597
+ texture?: OBJ_Texture;
598
+ dimension?: 2 | 3;
599
+ light?: 'directional' | 'point' | null;
600
+ vertices?: OBJ_GLVertexBuffer;
601
+ colors?: Array<number> | OBJ_GLColorData;
602
+ normals?: OBJ_GLVertexBuffer;
603
+ } & OBJ_FigurePrimitive;
604
+ /**
605
+ * {@link morph} options object.
606
+ *
607
+ * @property {string} name primitive name
608
+ * @property {Array<Array<number>>} pointArrays point arrays to morph between.
609
+ * Each point array is an array of consecutive x, y values of points. For
610
+ * example: [x1, y1, x2, y2, x3, y3, ...].
611
+ * @property {TypeColor | Array<TypeColor | Array<TypeColor>>} color colors to
612
+ * be assigned to the points
613
+ * @property {Array<String>} names optional names for each point array. Names
614
+ * can be used when using the morph animation step instead of point array
615
+ * indeces.
616
+ * @property {'TRIANGLES' | 'POINTS' | 'FAN' | 'STRIP' | 'LINES'} [glPrimitive]
617
+ * glPrimitive is the same for all point arrays (`'TRIANGLES'`)
618
+ * @interface
619
+ * @group Morphing
620
+ */
621
+ export type OBJ_Morph = {
622
+ name?: string;
623
+ pointArrays: Array<Array<number>>;
624
+ color: TypeColor | Array<TypeColor | Array<TypeColor>>;
625
+ names: Array<string>;
626
+ glPrimitive: 'TRIANGLES' | 'POINTS' | 'FAN' | 'STRIP' | 'LINES';
627
+ };
628
+ /**
629
+ * Define the width, descent or ascent of a text element. This can be used if
630
+ * the estimated width, descent or ascent is not what is desired.
631
+ * @property {number} [width]
632
+ * @property {number} [descent]
633
+ * @property {number} [ascent]
634
+ * @interface
635
+ * @group Misc Text
636
+ */
637
+ export type OBJ_TextAdjustments = {
638
+ width?: number;
639
+ descent?: number;
640
+ ascent?: number;
641
+ };
642
+ /**
643
+ * Text options object that extends {@link OBJ_FigurePrimitive}.
644
+ *
645
+ * ![](./apiassets/text1.png)
646
+ *
647
+ * ![](./apiassets/text2.png)
648
+ *
649
+ * ![](./apiassets/text3.png)
650
+ *
651
+ * ![](./apiassets/text4.png)
652
+ *
653
+ * ![](./apiassets/text5.png)
654
+ *
655
+ * ![](./apiassets/text6.png)
656
+ *
657
+ * A text element can either be defined as a single string, or an array of
658
+ * strings combined with an array of locations.
659
+ *
660
+ * The `adjustments` property allows customization of the borders around the
661
+ * text. This may be needed when the browser or FigureOne does not accurately
662
+ * calculate the size of the text (usually for non-standard fonts, and
663
+ * sometimes italized fonts).
664
+ *
665
+ * Atlernately `border` and `touchBorder` can also be used for complete
666
+ * customization.
667
+ *
668
+ * All text in this element will use the same font, x and y alignment, and
669
+ * adjustments.
670
+ *
671
+ * Note - Text can be rendered to either the WebGL canvas or the 2D canvas
672
+ * using the `render` property in `font`. For more information, see
673
+ * {@link OBJ_Font}.
674
+ *
675
+ * @property {string | Array<string>} [text] string or array of strings to
676
+ * render
677
+ * @property {TypeParsablePoint | Array<TypeParsablePoint>} [location] draw
678
+ * space location of each string (`[0, 0]`)
679
+ * @property {OBJ_Font} [font] defaults to default Figure font
680
+ * @property {'left' | 'center' | 'right'} [xAlign] (`'left'`)
681
+ * @property {'top' | 'bottom' | 'middle' | 'alphabetic' | 'baseline'} [yAlign]
682
+ * (`'baseline'`)
683
+ * @property {OBJ_TextAdjustments} [adjustments]
684
+ * @property {TypeParsableBuffer | TypeParsableBorder | 'buffer' | 'draw' | 'rect'} [border]
685
+ * @property {TypeParsableBuffer | TypeParsableBorder | 'rect' | 'border' | 'buffer' | 'draw'} [touchBorder]
686
+ *
687
+ * @extends OBJ_FigurePrimitive
688
+ *
689
+ * @see To test examples, append them to the
690
+ * <a href="#drawing-boilerplate">boilerplate</a>
691
+ *
692
+ * @example
693
+ * // Simple text
694
+ * figure.add({
695
+ * make: 'text',
696
+ * text: 'Hello World',
697
+ * });
698
+ *
699
+ * @example
700
+ * // Custom Font
701
+ * figure.add({
702
+ * make: 'text',
703
+ * text: 'Hello World',
704
+ * font: { family: 'Times New Roman', style: 'italic', underline: true },
705
+ * });
706
+ *
707
+ * @example
708
+ * // Aligned text
709
+ * figure.add({
710
+ * make: 'text',
711
+ * text: 'Aligned Text',
712
+ * xAlign: 'center',
713
+ * yAlign: 'top',
714
+ * color: [0, 0, 1, 1],
715
+ * });
716
+ *
717
+ * @example
718
+ * // Multi Text
719
+ * figure.add({
720
+ * make: 'text',
721
+ * text: ['0', '1', '2'],
722
+ * location: [[-0.5, -0.5], [0, 0.5], [0.5, -0.5]],
723
+ * });
724
+ *
725
+ * @example
726
+ * // Change Text
727
+ * t = figure.add({
728
+ * make: 'text',
729
+ * text: 'Hello World',
730
+ * });
731
+ * t.setText('Changed Text')
732
+ *
733
+ * @example
734
+ * // Change text and options
735
+ * t = figure.add({
736
+ * make: 'text',
737
+ * text: 'Hello World',
738
+ * });
739
+ * t.setText({
740
+ * text: 'Changed Text',
741
+ * xAlign: 'center',
742
+ * font: { family: 'Times New Roman' },
743
+ * });
744
+ */
745
+ export type OBJ_Text = {
746
+ text?: string | Array<string>;
747
+ location?: TypeParsablePoint | Array<TypeParsablePoint>;
748
+ font?: OBJ_Font;
749
+ xAlign?: 'left' | 'center' | 'right';
750
+ yAlign?: 'top' | 'bottom' | 'middle' | 'alphabetic' | 'baseline';
751
+ adjustments?: OBJ_TextAdjustments;
752
+ border?: TypeParsableBuffer | TypeParsableBorder | 'buffer' | 'draw' | 'rect';
753
+ touchBorder?: TypeParsableBuffer | TypeParsableBorder | 'rect' | 'border' | 'buffer' | 'draw';
754
+ } & OBJ_FigurePrimitive;
755
+ export type OBJ_Text_Fixed = {
756
+ text: Array<string>;
757
+ location: Array<Point>;
758
+ font: OBJ_Font;
759
+ xAlign: 'left' | 'center' | 'right';
760
+ yAlign: 'top' | 'bottom' | 'middle' | 'alphabetic' | 'baseline';
761
+ adjustments: OBJ_TextAdjustments;
762
+ };
763
+ /**
764
+ * Options object for setting new text in
765
+ * {@link FigureElementPrimitiveGLText} and
766
+ * {@link FigureElementPrimitive2DText} elements.
767
+ *
768
+ * @property {string} [text] new text to use
769
+ * @property {OBJ_Font} [font] define if font needs to be changed
770
+ * @property {'left' | 'center' | 'right'} [xAlign] xAlignment of text
771
+ * @property {'top' | 'bottom' | 'middle' | 'alphabetic' | 'baseline'} [yAlign]
772
+ * y alignment of text
773
+ * @property {OBJ_TextAdjustments} [adjustments] adjustments to the calculated
774
+ * borders of the text
775
+ * @property {TypeColor} [color] text color (will be overriden by a font color
776
+ * if it is specified)
777
+ * @interface
778
+ * @group Misc Text
779
+ */
780
+ export type OBJ_SetText = {
781
+ text?: string | Array<string>;
782
+ location?: TypeParsablePoint | Array<TypeParsablePoint>;
783
+ font?: OBJ_Font;
784
+ xAlign?: 'left' | 'center' | 'right';
785
+ yAlign?: 'top' | 'bottom' | 'middle' | 'alphabetic' | 'baseline';
786
+ adjustments?: OBJ_TextAdjustments;
787
+ color?: TypeColor;
788
+ };