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,307 @@
1
+ import type { TypeParsablePoint, TypeParsableBuffer, TypeParsableBorder } from '../../tools/g2';
2
+ import type { OBJ_Font, OBJ_Font_Fixed, TypeColor } from '../../tools/types';
3
+ import type FigureCollections from './FigureCollections';
4
+ import type { EQN_EquationElements, EQN_Forms } from '../Equation/Equation';
5
+ import type { TypeEquationPhrase } from '../Equation/EquationFunctions';
6
+ import { Equation } from '../Equation/Equation';
7
+ import type { OBJ_Collection } from '../FigurePrimitives/FigurePrimitiveTypes';
8
+ /**
9
+ * Formatted Text line definition object.
10
+ *
11
+ * Used to define a line of text in {@link OBJ_FormattedText}.
12
+ *
13
+ * @property {string} [text] string representing a line of text
14
+ * @property {OBJ_Font} [font] line specific default font
15
+ * @property {number} [lineSpace] line specific separation from top of
16
+ * previous line to baseline of this line
17
+ * @property {number} [baselineSpace] line specific separation from baseline of
18
+ * this previous line to baseline of this line
19
+ * @interface
20
+ * @group Misc Shapes
21
+ */
22
+ export type OBJ_TextLineDefinition = {
23
+ text: string;
24
+ font?: OBJ_Font;
25
+ lineSpace?: number;
26
+ baselineSpace?: number;
27
+ };
28
+ /**
29
+ * Text modifier definition object.
30
+ *
31
+ * Used to define the modifiers of a string within a formatted text element
32
+ * {@link OBJ_FormattedText}.
33
+ *
34
+ * @property {string} [text] text to replace `modifierId` with - if `undefined`
35
+ * then `modifierId` is used
36
+ * @property {TypeParsablePoint} [offset] text offset
37
+ * @property {OBJ_Font} [font] font changes for modified text
38
+ * @property {boolean} [inLine] `false` if modified text should not contribute
39
+ * to line layout (default: `true`)
40
+ * @property {string | function(): void} [onClick] function to execute on click
41
+ * within the `touchBorder` of the modified text
42
+ * @property {TypeParsableBuffer | boolean} [touch] use `true` to enable touch
43
+ * or a buffer to enable touch and define the touchBorder (`false`)
44
+ * buffer (`TypeParsableBuffer`) around the rectangle (default: `'0'`)
45
+ * @property {number} [space] additional space to right of text
46
+ * @property {TypeEquationPhrase} [eqn] use this to replace the text with an
47
+ * equation defined by an equation phrase - when using eqn the `font` property
48
+ * will be ignored
49
+ * @interface
50
+ * @group Misc Shapes
51
+ */
52
+ export type OBJ_TextModifiersDefinition = {
53
+ text?: string;
54
+ offset?: TypeParsablePoint;
55
+ inLine?: boolean;
56
+ font?: OBJ_Font;
57
+ touch?: boolean | TypeParsableBuffer;
58
+ onClick?: string | (() => void);
59
+ space?: number;
60
+ eqn?: TypeEquationPhrase;
61
+ };
62
+ /**
63
+ * {@link FormattedText} options object that extends {@link OBJ_Collection}
64
+ * options object (without `parent`).
65
+ *
66
+ * ![](./apiassets/ftext1.png)
67
+ *
68
+ * ![](./apiassets/ftext2.png)
69
+ *
70
+ * ![](./apiassets/ftext3.png)
71
+ *
72
+ * ![](./apiassets/ftext4.gif)
73
+ *
74
+ * ![](./apiassets/ftext5.png)
75
+ *
76
+ * ![](./apiassets/ftext6.gif)
77
+ *
78
+ * Formatted text allows:
79
+ * - Use of more than one font
80
+ * - Multi-line text
81
+ * - Embedded equations
82
+ * - Interactivity on select strings
83
+ *
84
+ * If `text` is defined as an array of strings of line definition objects, then
85
+ * each element of the array will be a new line of text.
86
+ *
87
+ * All text will be laid out with the default font (or default line font if a
88
+ * line definition object is used).
89
+ *
90
+ * To modify the font of portions of text within a line, surround the text to
91
+ * modify with '|' characters. The string surrounded by the '|' characters will
92
+ * then be a unique identifier that can be referenced in the `modifiers`
93
+ * property which will then allow for replacing that text with some other text,
94
+ * changing the font of the text, changing the touchability of the text and/or
95
+ * replacing the text with an embedded equation.
96
+ *
97
+ * If a string is surrounded by '|' characters but not defined in `modifiers`
98
+ * then that string will have the formmating of the `accent` property applied
99
+ * to it.
100
+ *
101
+ * @property {Array<string | OBJ_TextLineDefinition> | string} [text] array of
102
+ * line strings - single string is single line only.
103
+ * @property {OBJ_TextModifiersDefinition} [modifiers] modifier definitions
104
+ * @property {OBJ_Font} [font] Default font to use in lines
105
+ * @property {TypeParsableBuffer} [defaultTextTouchBorder] default buffer for
106
+ * `touch` property in {@link OBJ_TextModifiersDefinition}
107
+ * @property {EQN_EquationElements} [elements] equation elements to use within
108
+ * the equation phrases defined in `modifiers`
109
+ * @property {'left' | 'right' | 'center} [justify] justification of lines
110
+ * (`left`)
111
+ * @property {number} [lineSpace] Space between ascent of each line with
112
+ * descent of previous line (`font.size * 0.5`)
113
+ * @property {number} [baselineSpace] Space between baselines of lines. This
114
+ * will override `lineSpace` for all lines including individual line settings
115
+ * (`undefined`)
116
+ * @property {'left' | 'right' | 'center'} [xAlign] horizontal alignment of
117
+ * lines with `position` (`left`)
118
+ * @property {'bottom' | 'baseline' | 'middle' | 'top'} [yAlign] vertical
119
+ * alignment of lines with `position` (`baseline`)
120
+ * @property {TypeParsableBuffer | TypeParsableBorder | 'children' | 'rect' | number} [border]
121
+ * border used for keeping shape within limits (`'draw'`)
122
+ * @property {TypeParsableBuffer | TypeParsableBorder | 'border' | 'children' | 'rect' | number} [touchBorder]
123
+ * border used for determining shape was touched. `number` and `'rect'` use
124
+ * the the points in `'buffer'` to calculate the bounding rects (`'buffer'`).
125
+ * @property {OBJ_Font} [accent] default modifier for accented text without a
126
+ * specific modification. By default accented text will be italic.
127
+ *
128
+ * @extends OBJ_Collection
129
+ *
130
+ * @see To test examples, append them to the
131
+ * <a href="#drawing-boilerplate">boilerplate</a>
132
+ *
133
+ * // Accent a word
134
+ * figure.add({
135
+ * make: 'ftext',
136
+ * text: 'Hello |World|',
137
+ * });
138
+ *
139
+ * @example
140
+ * // Multi-line center justified
141
+ * figure.add({
142
+ * make: 'ftext',
143
+ * text: ['First line', 'Second line'],
144
+ * justify: 'center',
145
+ * });
146
+ *
147
+ * @example
148
+ * // Modifiers
149
+ * figure.add({
150
+ * make: 'ftext',
151
+ * text: ['|First| |line|', 'Second |line2|'],
152
+ * modifiers: {
153
+ * First: { font: { underline: 'true', color: [0, 0.7, 0.7, 1] } },
154
+ * line: { font: { color: [0, 0, 1, 1] } },
155
+ * line2: { text: 'line', font: { color: [0, 0.7, 0, 1], style: 'italic' } },
156
+ * },
157
+ * });
158
+ *
159
+ * @example
160
+ * // Interactive words in formatted text
161
+ * figure.add({
162
+ * make: 'ftext',
163
+ * text: 'Touch |here| or |here2|',
164
+ * modifiers: {
165
+ * here: {
166
+ * font: { underline: true, color: [0, 0, 1, 1] },
167
+ * touch: 0.1,
168
+ * onClick: () => console.log('here 1'),
169
+ * },
170
+ * here2: {
171
+ * text: 'here',
172
+ * font: { underline: true, color: [0, 0.8, 0, 1] },
173
+ * touch: 0.1,
174
+ * onClick: () => console.log('here 2'),
175
+ * },
176
+ * },
177
+ * xAlign: 'center',
178
+ * });
179
+ *
180
+ * @example
181
+ * // Embedded equation (inline form definition)
182
+ * figure.add({
183
+ * make: 'ftext',
184
+ * text: '|root2| is irrational',
185
+ * modifiers: {
186
+ * root2: { eqn: { root: ['radical', '2'] } },
187
+ * },
188
+ * xAlign: 'center',
189
+ * });
190
+ *
191
+ * @example
192
+ * // Embedded equation with defined, touchable elements
193
+ * figure.add({
194
+ * name: 't',
195
+ * make: 'ftext',
196
+ * text: ['A fraction is |fraction|', 'Touch it!'],
197
+ * modifiers: {
198
+ * fraction: {
199
+ * eqn: {
200
+ * scale: [{ frac: ['num', 'v', 'den'] }, 0.7],
201
+ * },
202
+ * offset: [0, 0.2],
203
+ * touch: 0.1,
204
+ * onClick: () => figure.get('t').pulse({
205
+ * elements: ['num', 'den', 'v'],
206
+ * centerOn: 'v',
207
+ * xAlign: 'left',
208
+ * scale: 1.3,
209
+ * }),
210
+ * space: 0.3,
211
+ * },
212
+ * },
213
+ * elements: {
214
+ * num: 'numerator',
215
+ * den: { text: 'denominator', color: [0, 0, 1, 1], style: 'italic' },
216
+ * v: { symbol: 'vinculum' },
217
+ * },
218
+ * xAlign: 'center',
219
+ * });
220
+ * @interface
221
+ * @group Text
222
+ */
223
+ export type OBJ_FormattedText = {
224
+ text?: Array<string | OBJ_TextLineDefinition> | string;
225
+ modifiers?: OBJ_TextModifiersDefinition | {
226
+ eqn?: TypeEquationPhrase;
227
+ };
228
+ elements?: EQN_EquationElements;
229
+ font?: OBJ_Font;
230
+ defaultTextTouchBorder?: TypeParsableBuffer;
231
+ justify?: 'left' | 'center' | 'right';
232
+ lineSpace?: number;
233
+ baselineSpace?: number;
234
+ xAlign?: 'left' | 'right' | 'center';
235
+ yAlign?: 'bottom' | 'baseline' | 'middle' | 'top';
236
+ border?: TypeParsableBuffer | TypeParsableBorder | 'children' | 'rect' | number;
237
+ touchBorder?: TypeParsableBuffer | TypeParsableBorder | 'border' | 'children' | 'rect' | number;
238
+ accent?: OBJ_Font;
239
+ } & OBJ_Collection;
240
+ declare class CollectionsText extends Equation {
241
+ _eqn: Equation;
242
+ font: OBJ_Font_Fixed;
243
+ accent: OBJ_Font;
244
+ justify: 'left' | 'right' | 'center';
245
+ lineSpace: number | null;
246
+ lines: Array<Record<string, any>>;
247
+ modifiers: Record<string, any>;
248
+ baselineSpace: number | null;
249
+ defaultTextTouchBorder: TypeParsableBuffer;
250
+ xAlign: 'left' | 'right' | 'center';
251
+ yAlign: 'bottom' | 'top' | 'middle' | 'baseline';
252
+ touchCounter: number;
253
+ /**
254
+ * @hideconstructor
255
+ */
256
+ constructor(collections: FigureCollections, optionsIn: Record<string, any>);
257
+ fontUpdated(): void;
258
+ setText(optionsIn: OBJ_FormattedText): void;
259
+ updateElements(elems: {
260
+ [elementName: string]: {
261
+ text: string;
262
+ font: {
263
+ size: number;
264
+ family: string;
265
+ weight: string;
266
+ style: string;
267
+ color: TypeColor;
268
+ };
269
+ touchBorder?: TypeParsableBuffer;
270
+ onClick?: string | (() => void);
271
+ };
272
+ }): boolean;
273
+ updateForms(forms: EQN_Forms, reform: boolean): boolean;
274
+ splitLines(linesIn: Array<Record<string, any> | string> | string): void;
275
+ createEquation(): {
276
+ name: string;
277
+ make: string;
278
+ color: TypeColor;
279
+ font: OBJ_Font_Fixed;
280
+ textFont: OBJ_Font_Fixed;
281
+ scale: number;
282
+ elements: Record<string, any>;
283
+ forms: {
284
+ base: {
285
+ lines: {
286
+ content: any[];
287
+ justify: "left" | "right" | "center";
288
+ lineSpace: number | null;
289
+ baselineSpace: number | null;
290
+ };
291
+ };
292
+ };
293
+ } | {
294
+ name: string;
295
+ make: string;
296
+ color: TypeColor;
297
+ font: OBJ_Font_Fixed;
298
+ textFont: OBJ_Font_Fixed;
299
+ scale: number;
300
+ elements: Record<string, any>;
301
+ forms: {
302
+ base: never[];
303
+ };
304
+ };
305
+ createLine(line: Record<string, any>, lineIndex: number): Record<string, any>[];
306
+ }
307
+ export default CollectionsText;
@@ -0,0 +1,185 @@
1
+ import type { TypeParsablePoint, Point } from '../../tools/g2';
2
+ import { FigureElementCollection, FigureElementPrimitive } from '../Element';
3
+ import type { OBJ_Collection } from '../FigurePrimitives/FigurePrimitiveTypes';
4
+ import type { TypeColor, OBJ_Font } from '../../tools/types';
5
+ import type FigureCollections from './FigureCollections';
6
+ import EquationLabel from './EquationLabel';
7
+ import type { EQN_Equation, Equation } from '../Equation/Equation';
8
+ import type { TypeLabelSubLocation } from './EquationLabel';
9
+ /**
10
+ * Collections toggle label options object.
11
+ *
12
+ * A toggle switch can be annotated with a label using the `text` property and can be:
13
+ * - text (`string`, `Array<string>`)
14
+ * - an equation (`Equation`, `EQN_Equation`)
15
+ *
16
+ * In all cases, an actual {@link Equation} is created as the label. The
17
+ * equation can have multiple forms, which can be set using the `showForm`
18
+ * method.
19
+ *
20
+ * If `text`: `string`, then an equation with a single form named `base` will
21
+ * be created with a single element being the string text.
22
+ *
23
+ * If `text`: `Array<string>`, then an equation with a form for each element
24
+ * of the array is created. Each form is named '0', '1', '2'... corresponding
25
+ * with the index of the array. Each form is has a single element, being the
26
+ * text at that index.
27
+ *
28
+ * Use `text`: `Equation` or `EQN_Equation` to create completely custom
29
+ * equations with any forms desirable.
30
+ *
31
+ *
32
+ * @see {@link COL_Toggle}
33
+ *
34
+ * @property {null | string | Array<string> | Equation | EQN_Equation } text
35
+ * @property {TypeParsablePoint} [offset] offset to default loation
36
+ * @property {TypeLabelSubLocation} [location] location of label relative to
37
+ * toggle
38
+ * @property {number} [scale] size of the label
39
+ * @property {TypeColor} [color]
40
+ * @interface
41
+ * @group Misc Shapes
42
+ */
43
+ export type OBJ_ToggleLabel = {
44
+ text: null | string | Array<string> | Equation | EQN_Equation;
45
+ offset?: TypeParsablePoint;
46
+ location?: TypeLabelSubLocation;
47
+ scale?: number;
48
+ color?: TypeColor;
49
+ };
50
+ /**
51
+ * Border of circle or bar of toggle.
52
+ *
53
+ * @property {width} [number] border width
54
+ * @property {color} [TypeColor] border color
55
+ * @see {@link OBJ_Toggle}
56
+ * @interface
57
+ * @group Misc Shapes
58
+ */
59
+ export type OBJ_ToggleBorder = {
60
+ width?: number;
61
+ color?: TypeColor;
62
+ };
63
+ /**
64
+ * {@link CollectionsToggle} options object that extends {@link OBJ_Collection}
65
+ * options object (without `parent`).
66
+ *
67
+ * @property {number} [width] toggle width
68
+ * @property {number} [height] toggle height
69
+ * @property {number} [barHeight] height of toggle bar showing on
70
+ * or off
71
+ * @property {number} [sides] number of sides in curves (`20`)
72
+ * @property {'dark' | 'light'} [theme] selects default colors for a light or
73
+ * dark switch (`dark`)
74
+ * @property {TypeColor} [colorOff] toggle off color
75
+ * @property {TypeColor} [colorOn] toggle on color (`[0, 1, 0, 1]`)
76
+ * @property {OBJ_ToggleBorder} [circleBorder] border around circle (defaults to on
77
+ * where width is half the figure's default line width)
78
+ * @property {OBJ_ToggleBorder} [barBorder] border around bar
79
+ * (defaults to off - width = 0)
80
+ * @property {OBJ_ToggleLabel} [label]
81
+
82
+ * @extends OBJ_Collection
83
+ * @interface
84
+ * @group 2D Shape Collections
85
+ */
86
+ export type COL_Toggle = {
87
+ width?: number;
88
+ height?: number;
89
+ barHeight?: number;
90
+ sides?: number;
91
+ theme?: 'dark' | 'light';
92
+ colorOff?: TypeColor;
93
+ colorOn?: TypeColor;
94
+ circleBorder?: OBJ_ToggleBorder;
95
+ barBorder?: OBJ_ToggleBorder;
96
+ label?: OBJ_ToggleLabel;
97
+ } & OBJ_Collection;
98
+ declare class ToggleLabel extends EquationLabel {
99
+ offset: Point;
100
+ location: TypeLabelSubLocation;
101
+ constructor(collections: FigureCollections, labelText: string | Equation | EQN_Equation | Array<string>, color: TypeColor, offset: TypeParsablePoint, location?: TypeLabelSubLocation, scale?: number, font?: OBJ_Font | null | undefined);
102
+ }
103
+ /**
104
+ * {@link FigureElementCollection} representing a toggle switch.
105
+ *
106
+ * ![](./apiassets/toggle.gif)
107
+ *
108
+ * The toggle switch can be turned on or off.
109
+ *
110
+ * Notifications - The notification manager property `notifications` will
111
+ * publish the following events:
112
+ * - `toggle`: switch is changed - `true` will be passed if the switch is
113
+ * changed to on, and `false` will be passed if the switch is changed to off
114
+ * - `on`: switch is changed to on
115
+ * - `off`: switch is changed to off
116
+ *
117
+ * See {@link COL_Toggle} for setup options.
118
+ *
119
+ * To test examples below, append them to the
120
+ * <a href="#drawing-boilerplate">boilerplate</a>
121
+ *
122
+ * @example
123
+ * // Simple toggle switch with notification causing a console statement
124
+ * const toggle = figure.add({
125
+ * make: 'collections.toggle',
126
+ * label: {
127
+ * text: 'Control',
128
+ * location: 'bottom',
129
+ * scale: 0.6,
130
+ * },
131
+ * });
132
+ *
133
+ * toggle.notifications.add('toggle', (state) => {
134
+ * state ? console.log('on') : console.log('off');
135
+ * });
136
+ * @group 2D Shape Collections
137
+ */
138
+ declare class CollectionsToggle extends FigureElementCollection {
139
+ _circ: FigureElementPrimitive;
140
+ _bar: FigureElementPrimitive;
141
+ _circBorder: FigureElementPrimitive | null;
142
+ _barBorder: FigureElementPrimitive | null;
143
+ label: ToggleLabel | null;
144
+ _label: FigureElementPrimitive | null;
145
+ width: number;
146
+ height: number;
147
+ colorOn: TypeColor;
148
+ colorOff: TypeColor;
149
+ /**
150
+ * @hideconstructor
151
+ */
152
+ constructor(collections: FigureCollections, optionsIn: COL_Toggle);
153
+ /**
154
+ * Turn switch on.
155
+ * @param {boolean} `true` to send `'toggle'` and `'on'` notifications
156
+ */
157
+ on(notify?: boolean): void;
158
+ /**
159
+ * Turn switch off.
160
+ * @param {boolean} `true` to send `'toggle'` and `'off'` notifications
161
+ */
162
+ off(notify?: boolean): void;
163
+ /**
164
+ * `true` if switch is on.
165
+ * @return {boolean}
166
+ */
167
+ isOn(): any;
168
+ /**
169
+ * `true` if switch is off.
170
+ * @return {boolean}
171
+ */
172
+ isOff(): boolean;
173
+ /**
174
+ * Toggle switch.
175
+ */
176
+ toggle(): void;
177
+ fontUpdated(): void;
178
+ updateLabel(): void;
179
+ /**
180
+ * Change label text.
181
+ * @param {string} text text to change to
182
+ */
183
+ setLabel(text: string): void;
184
+ }
185
+ export default CollectionsToggle;