figureone 0.15.10 → 1.0.1

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 (160) hide show
  1. package/figureone.min.js +1 -1
  2. package/index.js +79170 -0
  3. package/llms.txt +548 -0
  4. package/package.json +16 -1
  5. package/types/index.d.ts +128 -0
  6. package/types/js/figure/Animation/Animation.d.ts +36 -0
  7. package/types/js/figure/Animation/AnimationBuilder.d.ts +173 -0
  8. package/types/js/figure/Animation/AnimationManager.d.ts +392 -0
  9. package/types/js/figure/Animation/AnimationStep/CustomStep.d.ts +99 -0
  10. package/types/js/figure/Animation/AnimationStep/DelayStep.d.ts +24 -0
  11. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ColorAnimationStep.d.ts +203 -0
  12. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/OpacityAnimationStep.d.ts +220 -0
  13. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PositionAnimationStep.d.ts +124 -0
  14. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseAnimationStep.d.ts +137 -0
  15. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/PulseTransformAnimationStep.d.ts +52 -0
  16. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/RotationAnimationStep.d.ts +119 -0
  17. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScaleAnimationStep.d.ts +93 -0
  18. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/ScenarioAnimationStep.d.ts +204 -0
  19. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep/TransformAnimationStep.d.ts +163 -0
  20. package/types/js/figure/Animation/AnimationStep/ElementAnimationStep.d.ts +56 -0
  21. package/types/js/figure/Animation/AnimationStep/ParallelAnimationStep.d.ts +70 -0
  22. package/types/js/figure/Animation/AnimationStep/SerialAnimationStep.d.ts +84 -0
  23. package/types/js/figure/Animation/AnimationStep/TriggerStep.d.ts +106 -0
  24. package/types/js/figure/Animation/AnimationStep.d.ts +110 -0
  25. package/types/js/figure/DrawContext2D.d.ts +9 -0
  26. package/types/js/figure/DrawingObjects/DrawingObject.d.ts +45 -0
  27. package/types/js/figure/DrawingObjects/GLObject/GLObject.d.ts +146 -0
  28. package/types/js/figure/DrawingObjects/HTMLObject/HTMLObject.d.ts +29 -0
  29. package/types/js/figure/DrawingObjects/TextObject/TextObject.d.ts +94 -0
  30. package/types/js/figure/DrawingObjects/TextObject/glyphMeasures.d.ts +7 -0
  31. package/types/js/figure/DrawingObjects/VertexObject/VertexGeneric.d.ts +21 -0
  32. package/types/js/figure/DrawingObjects/VertexObject/VertexObject.d.ts +0 -0
  33. package/types/js/figure/DrawingObjects/VertexObject/VertexText.d.ts +34 -0
  34. package/types/js/figure/Element.d.ts +1212 -0
  35. package/types/js/figure/Equation/Elements/BaseAnnotationFunction.d.ts +118 -0
  36. package/types/js/figure/Equation/Elements/BaseEquationFunction.d.ts +20 -0
  37. package/types/js/figure/Equation/Elements/Bounds.d.ts +49 -0
  38. package/types/js/figure/Equation/Elements/Color.d.ts +7 -0
  39. package/types/js/figure/Equation/Elements/Container.d.ts +5 -0
  40. package/types/js/figure/Equation/Elements/Element.d.ts +95 -0
  41. package/types/js/figure/Equation/Elements/Fraction.d.ts +5 -0
  42. package/types/js/figure/Equation/Elements/Lines.d.ts +5 -0
  43. package/types/js/figure/Equation/Elements/Matrix.d.ts +5 -0
  44. package/types/js/figure/Equation/Elements/Offset.d.ts +5 -0
  45. package/types/js/figure/Equation/Elements/Scale.d.ts +5 -0
  46. package/types/js/figure/Equation/Equation.d.ts +984 -0
  47. package/types/js/figure/Equation/EquationForm.d.ts +139 -0
  48. package/types/js/figure/Equation/EquationFunctions.d.ts +3367 -0
  49. package/types/js/figure/Equation/EquationSymbols.d.ts +1646 -0
  50. package/types/js/figure/Equation/HTMLEquation.d.ts +56 -0
  51. package/types/js/figure/Equation/Symbols/AngleBracket.d.ts +6 -0
  52. package/types/js/figure/Equation/Symbols/Arrow.d.ts +17 -0
  53. package/types/js/figure/Equation/Symbols/Bar.d.ts +6 -0
  54. package/types/js/figure/Equation/Symbols/Box.d.ts +11 -0
  55. package/types/js/figure/Equation/Symbols/Brace.d.ts +6 -0
  56. package/types/js/figure/Equation/Symbols/Bracket.d.ts +8 -0
  57. package/types/js/figure/Equation/Symbols/Division.d.ts +8 -0
  58. package/types/js/figure/Equation/Symbols/Integral.d.ts +7 -0
  59. package/types/js/figure/Equation/Symbols/Line.d.ts +5 -0
  60. package/types/js/figure/Equation/Symbols/Product.d.ts +6 -0
  61. package/types/js/figure/Equation/Symbols/Radical.d.ts +9 -0
  62. package/types/js/figure/Equation/Symbols/SquareBracket.d.ts +6 -0
  63. package/types/js/figure/Equation/Symbols/Strike.d.ts +8 -0
  64. package/types/js/figure/Equation/Symbols/Sum.d.ts +6 -0
  65. package/types/js/figure/Equation/Symbols/SymbolNew.d.ts +15 -0
  66. package/types/js/figure/Equation/Symbols/Vinculum.d.ts +6 -0
  67. package/types/js/figure/Figure.d.ts +711 -0
  68. package/types/js/figure/FigureCollections/Angle.d.ts +766 -0
  69. package/types/js/figure/FigureCollections/Axis.d.ts +517 -0
  70. package/types/js/figure/FigureCollections/Axis3.d.ts +118 -0
  71. package/types/js/figure/FigureCollections/Button.d.ts +195 -0
  72. package/types/js/figure/FigureCollections/EquationLabel.d.ts +77 -0
  73. package/types/js/figure/FigureCollections/FigureCollections.d.ts +122 -0
  74. package/types/js/figure/FigureCollections/Legend.d.ts +270 -0
  75. package/types/js/figure/FigureCollections/Line.d.ts +587 -0
  76. package/types/js/figure/FigureCollections/Plot.d.ts +558 -0
  77. package/types/js/figure/FigureCollections/PolyLine.d.ts +487 -0
  78. package/types/js/figure/FigureCollections/Rectangle.d.ts +235 -0
  79. package/types/js/figure/FigureCollections/SlideNavigator.d.ts +255 -0
  80. package/types/js/figure/FigureCollections/Slider.d.ts +155 -0
  81. package/types/js/figure/FigureCollections/Text.d.ts +307 -0
  82. package/types/js/figure/FigureCollections/Toggle.d.ts +185 -0
  83. package/types/js/figure/FigureCollections/Trace.d.ts +237 -0
  84. package/types/js/figure/FigurePrimitives/FigureElementPrimitive2DText.d.ts +119 -0
  85. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGLText.d.ts +94 -0
  86. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveGesture.d.ts +536 -0
  87. package/types/js/figure/FigurePrimitives/FigureElementPrimitiveMorph.d.ts +175 -0
  88. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes.d.ts +788 -0
  89. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes2D.d.ts +1324 -0
  90. package/types/js/figure/FigurePrimitives/FigurePrimitiveTypes3D.d.ts +1105 -0
  91. package/types/js/figure/FigurePrimitives/FigurePrimitives.d.ts +173 -0
  92. package/types/js/figure/FigurePrimitives/Generic.d.ts +5 -0
  93. package/types/js/figure/FigurePrimitives/Text.d.ts +17 -0
  94. package/types/js/figure/FontManager.d.ts +113 -0
  95. package/types/js/figure/Gesture.d.ts +39 -0
  96. package/types/js/figure/Recorder/Recorder.d.ts +291 -0
  97. package/types/js/figure/Recorder/parseState.d.ts +3 -0
  98. package/types/js/figure/Recorder/recorder.worker.d.ts +1 -0
  99. package/types/js/figure/Recorder/state.d.ts +7 -0
  100. package/types/js/figure/SlideNavigator.d.ts +606 -0
  101. package/types/js/figure/TimeKeeper.d.ts +174 -0
  102. package/types/js/figure/geometries/arc.d.ts +18 -0
  103. package/types/js/figure/geometries/arrow.d.ts +215 -0
  104. package/types/js/figure/geometries/buffer.d.ts +4 -0
  105. package/types/js/figure/geometries/copy/copy.d.ts +178 -0
  106. package/types/js/figure/geometries/ellipse.d.ts +17 -0
  107. package/types/js/figure/geometries/line.d.ts +13 -0
  108. package/types/js/figure/geometries/lines/corners.d.ts +7 -0
  109. package/types/js/figure/geometries/lines/dashes.d.ts +23 -0
  110. package/types/js/figure/geometries/lines/lines.d.ts +31 -0
  111. package/types/js/figure/geometries/polygon/polygon.d.ts +12 -0
  112. package/types/js/figure/geometries/rectangle.d.ts +19 -0
  113. package/types/js/figure/geometries/triangle.d.ts +27 -0
  114. package/types/js/figure/webgl/Atlas.d.ts +42 -0
  115. package/types/js/figure/webgl/shaders.d.ts +143 -0
  116. package/types/js/figure/webgl/target.d.ts +9 -0
  117. package/types/js/figure/webgl/webgl.d.ts +54 -0
  118. package/types/js/tools/FunctionMap.d.ts +69 -0
  119. package/types/js/tools/color.d.ts +11 -0
  120. package/types/js/tools/colorNames.d.ts +2 -0
  121. package/types/js/tools/d2/polygon.d.ts +60 -0
  122. package/types/js/tools/d2/triangles.d.ts +0 -0
  123. package/types/js/tools/d3/cone.d.ts +57 -0
  124. package/types/js/tools/d3/cube.d.ts +26 -0
  125. package/types/js/tools/d3/cylinder.d.ts +45 -0
  126. package/types/js/tools/d3/line3.d.ts +55 -0
  127. package/types/js/tools/d3/prism.d.ts +49 -0
  128. package/types/js/tools/d3/revolve.d.ts +87 -0
  129. package/types/js/tools/d3/sphere.d.ts +33 -0
  130. package/types/js/tools/d3/surface.d.ts +47 -0
  131. package/types/js/tools/g2.d.ts +242 -0
  132. package/types/js/tools/geometry/Bounds.d.ts +446 -0
  133. package/types/js/tools/geometry/Line.d.ts +314 -0
  134. package/types/js/tools/geometry/Path.d.ts +67 -0
  135. package/types/js/tools/geometry/Plane.d.ts +201 -0
  136. package/types/js/tools/geometry/Point.d.ts +359 -0
  137. package/types/js/tools/geometry/Rect.d.ts +115 -0
  138. package/types/js/tools/geometry/Transform.d.ts +623 -0
  139. package/types/js/tools/geometry/angle.d.ts +105 -0
  140. package/types/js/tools/geometry/common.d.ts +9 -0
  141. package/types/js/tools/geometry/coordinates.d.ts +30 -0
  142. package/types/js/tools/geometry/deceleration.d.ts +13 -0
  143. package/types/js/tools/geometry/polygon.d.ts +4 -0
  144. package/types/js/tools/geometry/quaternion.d.ts +15 -0
  145. package/types/js/tools/geometry/scene.d.ts +282 -0
  146. package/types/js/tools/geometry/tools.d.ts +8 -0
  147. package/types/js/tools/geometry/types.d.ts +2 -0
  148. package/types/js/tools/getCssColors.d.ts +1 -0
  149. package/types/js/tools/getCssVariables.d.ts +4 -0
  150. package/types/js/tools/getImageData.d.ts +1 -0
  151. package/types/js/tools/getScssColors.d.ts +2 -0
  152. package/types/js/tools/htmlGenerator.d.ts +85 -0
  153. package/types/js/tools/m2.d.ts +24 -0
  154. package/types/js/tools/m3.d.ts +71 -0
  155. package/types/js/tools/math.d.ts +112 -0
  156. package/types/js/tools/morph.d.ts +651 -0
  157. package/types/js/tools/styleSheets.d.ts +3 -0
  158. package/types/js/tools/tools.d.ts +281 -0
  159. package/types/js/tools/types.d.ts +305 -0
  160. package/figureone.worker.js +0 -1
package/llms.txt ADDED
@@ -0,0 +1,548 @@
1
+ # FigureOne
2
+
3
+ FigureOne is a JavaScript library for drawing, animating, and interacting with shapes, text, plots, and equations in a browser using WebGL. Users create a `Figure`, add elements via declarative objects with a `make` property, and control them with animations, interactivity, and slide navigation.
4
+
5
+ ## Quick Start
6
+
7
+ ```html
8
+ <!doctype html>
9
+ <html>
10
+ <body>
11
+ <div id="figureOneContainer" style="width: 500px; height: 500px; background-color: black;"></div>
12
+ <script src="https://cdn.jsdelivr.net/npm/figureone@latest/figureone.min.js"></script>
13
+ <script src="./index.js"></script>
14
+ </body>
15
+ </html>
16
+ ```
17
+
18
+ ```js
19
+ const figure = new Fig.Figure();
20
+ figure.add({ make: 'triangle', width: 0.5, height: 0.5, color: [1, 0, 0, 1] });
21
+ ```
22
+
23
+ `Fig` is the global entry point. `new Fig.Figure()` attaches to a div with id `figureOneContainer` by default. Use `{ htmlId: 'customId' }` to override.
24
+
25
+ Colors are `[r, g, b, a]` with values 0-1. Coordinates default to a scene of `[-1, -1, 2, 2]` (x, y, width, height). Override with `new Fig.Figure({ scene: [-2, -2, 4, 4] })`.
26
+
27
+ ## Core Concepts
28
+
29
+ - **Figure** — top-level container that manages all elements and rendering
30
+ - **FigureElement** — base class for all drawable objects (primitives and collections)
31
+ - **FigureElementPrimitive** — a single drawable shape (polygon, text, line, etc.)
32
+ - **FigureElementCollection** — a group of elements that transform together
33
+ - **Transform** — position, rotation, and scale applied to elements
34
+ - `figure.add(definition)` returns the created element; `figure.add([...])` returns an array
35
+ - Access child elements: `figure.elements._childName`
36
+
37
+ ## Shape Primitives (`make:` types)
38
+
39
+ | Type | Description |
40
+ |------|-------------|
41
+ | `polygon` | Regular polygon (use `sides: 100` for circles) |
42
+ | `rectangle` | Rectangle with optional rounded corners |
43
+ | `triangle` | Triangle by width/height or custom points |
44
+ | `ellipse` | Ellipse shape |
45
+ | `arc` | Arc or partial circle |
46
+ | `line` | Straight line between two points |
47
+ | `arrow` | Arrow shape |
48
+ | `star` | Star shape |
49
+ | `polyline` | Connected line segments |
50
+ | `grid` | 2D grid of lines |
51
+ | `text` | WebGL-rendered text |
52
+ | `generic` | Custom 2D vertex geometry |
53
+ | `gl` | Raw WebGL with custom shaders |
54
+ | `html` | HTML element overlay |
55
+ | `collection` | Group of child elements |
56
+ | `cube` | 3D cube (requires orthographic scene) |
57
+ | `sphere` | 3D sphere |
58
+ | `surface` | 3D surface from point grid |
59
+ | `cone` | 3D cone |
60
+ | `cylinder` | 3D cylinder |
61
+ | `prism` | 3D prism |
62
+ | `revolve` | 3D surface of revolution |
63
+ | `cameraControl` | Enables 3D camera rotation via drag |
64
+
65
+ Shorthand `make: 'polygon'` is equivalent to `make: 'primitives.polygon'`.
66
+
67
+ ### Common Shape Examples
68
+
69
+ ```js
70
+ // Circle (polygon with many sides)
71
+ figure.add({
72
+ make: 'polygon', sides: 100, radius: 0.3, color: [0, 0, 1, 1],
73
+ });
74
+
75
+ // Rectangle with rounded corners
76
+ figure.add({
77
+ make: 'rectangle', width: 0.8, height: 0.4,
78
+ corner: { radius: 0.05, sides: 10 }, color: [0, 1, 0, 1],
79
+ });
80
+
81
+ // Line
82
+ figure.add({
83
+ make: 'line', p1: [-0.5, 0], p2: [0.5, 0],
84
+ width: 0.02, color: [1, 1, 0, 1],
85
+ });
86
+
87
+ // Text
88
+ figure.add({
89
+ make: 'text', text: 'Hello', position: [0, 0],
90
+ xAlign: 'center', font: { size: 0.2, color: [1, 1, 1, 1] },
91
+ });
92
+
93
+ // Textured rectangle
94
+ figure.add({
95
+ make: 'rectangle', width: 1.8, height: 1.2,
96
+ texture: { src: 'image.jpg', mapTo: [-0.9, -0.6, 1.8, 1.2] },
97
+ });
98
+ ```
99
+
100
+ ### Element Properties
101
+
102
+ All elements accept these common options alongside shape-specific ones:
103
+
104
+ - `name` — element name for later access via `figure.elements._name`
105
+ - `color` — `[r, g, b, a]`
106
+ - `position` — `[x, y]` shorthand for translation
107
+ - `rotation` — rotation in radians
108
+
109
+ When `options` is used, shape-specific properties go inside it:
110
+
111
+ ```js
112
+ figure.add({
113
+ name: 'sq', make: 'primitives.rectangle',
114
+ options: { width: 0.4, height: 0.4, position: [-0.5, 0.5] },
115
+ });
116
+ ```
117
+
118
+ Otherwise, shape options can be at the top level alongside `make`:
119
+
120
+ ```js
121
+ figure.add({ make: 'rectangle', width: 0.4, height: 0.4, position: [-0.5, 0.5] });
122
+ ```
123
+
124
+ ## Collections (`make: 'collections.*'`)
125
+
126
+ | Type | Description |
127
+ |------|-------------|
128
+ | `collections.plot` | XY plot with traces, axes, legend |
129
+ | `collections.line` | Labelled line with optional arrows |
130
+ | `collections.polyline` | Labelled polyline with side/angle labels |
131
+ | `collections.angle` | Angle marker with label |
132
+ | `collections.axis` | Single axis with ticks and labels |
133
+ | `collections.axis3` | 3D axis |
134
+ | `collections.rectangle` | Rectangle collection with labels |
135
+ | `collections.slideNavigator` | Slide navigation controls |
136
+ | `collections.slider` | Draggable slider |
137
+ | `collections.toggle` | Toggle button |
138
+ | `collections.button` | Button |
139
+
140
+ Also available as direct shortcuts: `make: 'equation'`, `make: 'ftext'`, `make: 'angle'`, `make: 'oline'`, `make: 'opolyline'`.
141
+
142
+ ## Animation
143
+
144
+ Animations use a builder chain pattern on `element.animations`:
145
+
146
+ ```js
147
+ element.animations.new()
148
+ .dissolveIn() // fade in
149
+ .rotation({ target: Math.PI / 4, duration: 1 }) // rotate
150
+ .position({ target: [0.5, 0], duration: 2 }) // move
151
+ .start();
152
+ ```
153
+
154
+ ### Animation Steps
155
+
156
+ | Step | Description |
157
+ |------|-------------|
158
+ | `.position(target_or_options)` | Animate position |
159
+ | `.rotation(target_or_options)` | Animate rotation |
160
+ | `.scale(target_or_options)` | Animate scale |
161
+ | `.transform(target_or_options)` | Animate full transform |
162
+ | `.color(target_or_options)` | Animate color |
163
+ | `.opacity(options)` | Animate opacity |
164
+ | `.dissolveIn(duration?)` | Fade in (show + opacity 0→1) |
165
+ | `.dissolveOut(duration?)` | Fade out (opacity 1→0 + hide) |
166
+ | `.dim(options?)` | Dim to 0.3 opacity |
167
+ | `.undim(options?)` | Restore full opacity |
168
+ | `.pulse(scale_or_options)` | Pulse (scale up and back) |
169
+ | `.scenario(options)` | Animate to a named scenario |
170
+ | `.scenarios(options)` | Animate all children to a scenario |
171
+ | `.delay(duration)` | Wait before next step |
172
+ | `.trigger(callback_or_options)` | Run a callback mid-chain |
173
+ | `.whenFinished(callback)` | Run callback when chain completes |
174
+
175
+ Steps run in **sequence** by default. Use `.inParallel([...])` for simultaneous steps:
176
+
177
+ ```js
178
+ const [s1, s2] = figure.add([
179
+ { make: 'polygon', sides: 4, radius: 0.2, position: [-0.4, 0], color: [1, 0, 0, 1] },
180
+ { make: 'polygon', sides: 4, radius: 0.3, position: [0.4, 0], color: [0, 0, 1, 0.5] },
181
+ ]);
182
+
183
+ // Sequential: dissolve in, then rotate and move simultaneously
184
+ s2.animations.new()
185
+ .dissolveIn()
186
+ .inParallel([
187
+ s2.animations.position({ target: [0, 0], duration: 3 }),
188
+ s2.animations.rotation({ target: Math.PI / 4, duration: 3 }),
189
+ ])
190
+ .start();
191
+ ```
192
+
193
+ ### Cross-Element Animations
194
+
195
+ Animate other elements from one animation chain using the `element` property:
196
+
197
+ ```js
198
+ figure.elements.animations.new()
199
+ .scenarios({ target: 'center', duration: 1 }) // all children to 'center'
200
+ .scenario({ element: s1, target: 'right', duration: 1 }) // just s1
201
+ .dissolveIn({ element: s2, duration: 0.5 })
202
+ .start();
203
+ ```
204
+
205
+ ## Equations
206
+
207
+ Create equations with `make: 'equation'`. Define `elements` (terms and symbols) and `forms` (layouts).
208
+
209
+ ```js
210
+ const eqn = figure.add({
211
+ make: 'equation',
212
+ elements: {
213
+ v: { symbol: 'vinculum' },
214
+ equals: ' = ',
215
+ },
216
+ forms: {
217
+ 1: ['a', 'equals', { frac: ['b', 'v', 'c'] }],
218
+ },
219
+ });
220
+ ```
221
+
222
+ Elements not defined in `elements` are auto-created from form strings. Use `_` prefix for non-displayed spacing strings: `'_ + '` renders as ` + ` but the element name starts with `_`.
223
+
224
+ Duplicate elements: append `_N` to create copies — `'b_1'`, `'b_2'` display as `b`.
225
+
226
+ ### Layout Functions
227
+
228
+ | Function | Syntax | Description |
229
+ |----------|--------|-------------|
230
+ | `frac` | `{ frac: [num, vinculum, denom] }` | Fraction |
231
+ | `sup` | `{ sup: [base, superscript] }` | Superscript |
232
+ | `sub` | `{ sub: [base, subscript] }` | Subscript |
233
+ | `supSub` | `{ supSub: [base, superscript, subscript] }` | Both super and subscript |
234
+ | `brac` | `{ brac: { left, content, right } }` | Brackets around content |
235
+ | `root` | `{ root: [radical_symbol, content] }` | Square root |
236
+ | `annotate` | `{ annotate: { content, annotation: {...} } }` | Annotation relative to content |
237
+ | `topComment` | `{ topComment: [content, comment, symbol] }` | Comment above with symbol |
238
+ | `bottomComment` | `{ bottomComment: { content, comment, symbol } }` | Comment below |
239
+ | `strike` | `{ strike: [content, strike_symbol] }` | Strikethrough |
240
+ | `topStrike` | `{ topStrike: [content, symbol, comment] }` | Strike with top comment |
241
+ | `bottomStrike` | `{ bottomStrike: [content, symbol, comment] }` | Strike with bottom comment |
242
+ | `box` | `{ box: [content, box_symbol, inSize] }` | Box around content |
243
+ | `bar` | `{ bar: [content, bar_symbol] }` | Bar over/under content |
244
+ | `topBar` | `{ topBar: { content, symbol } }` | Bar above content |
245
+ | `bottomBar` | `{ bottomBar: { content, symbol } }` | Bar below content |
246
+ | `matrix` | `{ matrix: { content: [[...], [...]], left, right } }` | Matrix with brackets |
247
+ | `int` | `{ int: { symbol, content, from, to } }` | Integral |
248
+ | `sumOf` | `{ sumOf: { symbol, content, from, to } }` | Summation |
249
+ | `prodOf` | `{ prodOf: { symbol, content, from, to } }` | Product |
250
+ | `scale` | `{ scale: [content, scale_factor] }` | Scale content |
251
+ | `color` | `{ color: [content, [r,g,b,a]] }` | Color content |
252
+ | `container` | `{ container: { content, width, ... } }` | Fixed-size container |
253
+ | `lines` | `{ lines: { content: [...], justify } }` | Multi-line layout |
254
+
255
+ ### Symbols
256
+
257
+ Define symbols in `elements` with `{ symbol: 'type' }`:
258
+
259
+ | Symbol | Description |
260
+ |--------|-------------|
261
+ | `vinculum` | Horizontal line for fractions |
262
+ | `bracket` | Round bracket (set `side: 'left'` or `'right'`) |
263
+ | `squareBracket` | Square bracket |
264
+ | `angleBracket` | Angle bracket |
265
+ | `brace` | Curly brace (use with `side: 'top'`, `'bottom'`, `'left'`, `'right'`) |
266
+ | `bar` | Bar line (use with `side`) |
267
+ | `radical` | Square root symbol |
268
+ | `strike` | Strikethrough (`style: 'cross'`, `'forward'`, `'back'`, `'horizontal'`) |
269
+ | `box` | Box outline |
270
+ | `int` | Integral symbol (use `num` for double/triple integrals) |
271
+ | `sum` | Sigma summation |
272
+ | `prod` | Pi product |
273
+ | `arrow` | Arrow (`direction: 'right'`, `'left'`, `'up'`, `'down'`) |
274
+ | `line` | Decorative line |
275
+
276
+ ### Forms and Animation
277
+
278
+ ```js
279
+ const eqn = figure.add({
280
+ make: 'equation',
281
+ elements: {
282
+ v: { symbol: 'vinculum' },
283
+ equals: ' = ',
284
+ times: ' \u00D7 ',
285
+ c: { color: [0, 0, 1, 1] },
286
+ },
287
+ formDefaults: { alignment: { fixTo: 'equals' } },
288
+ forms: {
289
+ 1: ['a', 'equals', { frac: ['b', 'v', 'c'] }],
290
+ 2: {
291
+ content: ['c', 'times', 'a', 'equals', 'b'],
292
+ translation: { c: { style: 'curved', direction: 'down', mag: 0.5 } },
293
+ },
294
+ },
295
+ });
296
+
297
+ eqn.showForm('1');
298
+ eqn.goToForm({ form: '2', delay: 1, duration: 1.5, animate: 'move' });
299
+ ```
300
+
301
+ Use `formSeries` to define an ordered list of forms, then navigate with `eqn.nextForm()` and `eqn.prevForm()`.
302
+
303
+ Use `phrases` to define reusable sub-expressions:
304
+
305
+ ```js
306
+ {
307
+ make: 'equation',
308
+ phrases: { Csq: { sup: ['C', '2'] } },
309
+ forms: { 1: ['a', '_ = ', 'Csq'] },
310
+ }
311
+ ```
312
+
313
+ ## Interactivity
314
+
315
+ ### Making Elements Movable
316
+
317
+ ```js
318
+ figure.add({
319
+ make: 'polygon', sides: 100, radius: 0.2,
320
+ move: {
321
+ bounds: { left: -0.8, bottom: -0.8, right: 0.8, top: 0.8 },
322
+ freely: { deceleration: 0.5 },
323
+ },
324
+ });
325
+ ```
326
+
327
+ ### Touch and Click
328
+
329
+ ```js
330
+ element.setTouchable();
331
+ element.onClick = () => { /* handle click */ };
332
+ // or
333
+ figure.add({
334
+ make: 'polygon', radius: 0.3, sides: 4,
335
+ mods: { isTouchable: true, touchBorder: 0.1 },
336
+ });
337
+ ```
338
+
339
+ ### Notifications
340
+
341
+ Elements publish events you can subscribe to:
342
+
343
+ ```js
344
+ ball.notifications.add('setTransform', () => {
345
+ const p = ball.getPosition().round(1);
346
+ text.setText({ text: `(${p.x.toFixed(1)}, ${p.y.toFixed(1)})` });
347
+ });
348
+ eqn.notifications.add('onClick', () => nav.nextSlide());
349
+ ```
350
+
351
+ Common notifications: `setTransform`, `onClick`, `animationsFinished`, `setFigure`.
352
+
353
+ ## Scenarios
354
+
355
+ Scenarios are named presets for position, rotation, scale, and color:
356
+
357
+ ```js
358
+ figure.add({
359
+ name: 'shape', make: 'polygon', sides: 4, radius: 0.3,
360
+ mods: {
361
+ scenarios: {
362
+ center: { position: [0, 0], scale: [1, 1], color: [1, 0, 0, 1] },
363
+ right: { position: [1, 0], scale: [2, 1], color: [0, 0, 1, 1] },
364
+ },
365
+ },
366
+ });
367
+
368
+ // Set instantly
369
+ figure.elements._shape.setScenario('center');
370
+
371
+ // Animate to scenario
372
+ figure.elements._shape.animations.new()
373
+ .scenario({ target: 'right', duration: 1 })
374
+ .start();
375
+
376
+ // Set all children to a scenario
377
+ figure.elements.setScenarios('center');
378
+ ```
379
+
380
+ ## SlideNavigator
381
+
382
+ SlideNavigator manages sequential presentation states with animated transitions.
383
+
384
+ ### Verbose Syntax
385
+
386
+ ```js
387
+ const slides = [
388
+ {
389
+ show: [eqn, description],
390
+ steadyState: () => { eqn.showForm('0'); description.setText({ text: 'Step 1' }); },
391
+ },
392
+ {
393
+ show: [eqn, description],
394
+ enterState: () => { eqn.showForm('0'); description.setText({ text: 'Step 1' }); },
395
+ transition: (done) => {
396
+ eqn.animations.new()
397
+ .goToForm({ target: '1', animate: 'move' })
398
+ .whenFinished(done)
399
+ .start();
400
+ },
401
+ steadyState: () => { eqn.showForm('1'); },
402
+ },
403
+ ];
404
+
405
+ const nav = new Fig.SlideNavigator({ collection: figure.elements, slides });
406
+ nav.goToSlide(0);
407
+ ```
408
+
409
+ Slide lifecycle: `enterState` → `transition(done)` → `steadyState`. Each slide should fully define its state (not depend on previous slides).
410
+
411
+ ### Succinct Equation Syntax
412
+
413
+ When using equations and text, use shorthand `form` and `text` properties:
414
+
415
+ ```js
416
+ const nav = new Fig.SlideNavigator({
417
+ collection: figure.elements, equation: eqn, text: description,
418
+ slides: [
419
+ { form: '0', text: 'Goal: Rearrange for |a|' },
420
+ { text: 'Subtract |b| from both sides' },
421
+ { form: '1' },
422
+ { text: '|b| cancels on left side' },
423
+ { form: '2' },
424
+ ],
425
+ });
426
+ ```
427
+
428
+ If `form` or `text` is the same as the previous slide, it only needs to be defined once.
429
+
430
+ ### Shortcut Animation Syntax
431
+
432
+ ```js
433
+ const nav = figure.addSlideNavigator();
434
+ nav.loadSlides([
435
+ {
436
+ showCommon: 'sq1',
437
+ enterStateCommon: () => { sq1.setPosition([-0.5, 0.5]); },
438
+ },
439
+ { transition: { in: 'sq2' } }, // dissolve in
440
+ { transition: { position: 'sq2', target: [0.3, 0.5], duration: 1 } }, // move
441
+ {
442
+ transition: [ // sequence
443
+ { position: 'sq1', target: [-0.3, 0.5], duration: 1 },
444
+ { rotation: 'sq1', target: Math.PI / 4, duration: 1 },
445
+ ],
446
+ },
447
+ {
448
+ transition: [ // parallel (nested array)
449
+ [
450
+ { rotation: 'sq1', target: 0, duration: 1 },
451
+ { rotation: 'sq2', target: 0, duration: 1 },
452
+ ],
453
+ { out: ['sq1', 'sq2'] }, // dissolve out
454
+ ],
455
+ },
456
+ ]);
457
+ ```
458
+
459
+ ## Plots
460
+
461
+ ```js
462
+ // Simple plot
463
+ figure.add({
464
+ make: 'collections.plot',
465
+ trace: Fig.range(0, 10, 0.05).map(x => [x, x ** 2]),
466
+ });
467
+
468
+ // Customized plot with multiple traces and legend
469
+ figure.add({
470
+ make: 'collections.plot',
471
+ width: 1, height: 1, position: [-0.5, -0.5],
472
+ title: { text: 'Distance', offset: [0, 0.1] },
473
+ x: { title: 'time (s)' },
474
+ y: { start: 0, stop: 100, title: 'distance (m)' },
475
+ trace: [
476
+ { points: data1, name: 'Linear' },
477
+ { points: data2, name: 'Quadratic', markers: { sides: 4, radius: 0.02 } },
478
+ {
479
+ points: data3, name: 'Cubic',
480
+ markers: { radius: 0.02, sides: 10, line: { width: 0.005 } },
481
+ line: { dash: [0.04, 0.01] },
482
+ },
483
+ ],
484
+ legend: { font: { size: 0.05 } },
485
+ });
486
+ ```
487
+
488
+ Trace `points` can be `[[x, y], ...]` arrays or `Fig.Point` arrays.
489
+
490
+ ## 3D
491
+
492
+ Use an orthographic scene for 3D:
493
+
494
+ ```js
495
+ const figure = new Fig.Figure({ scene: { style: 'orthographic' } });
496
+
497
+ figure.add([
498
+ { make: 'collections.axis3', start: -0.8, length: 1.6, arrow: { ends: 'all' }, width: 0.01 },
499
+ { make: 'cube', side: 0.3, color: [1, 0, 0, 1] },
500
+ { make: 'cameraControl' },
501
+ ]);
502
+ ```
503
+
504
+ For surfaces, use `Fig.surfaceGrid()` to generate point grids:
505
+
506
+ ```js
507
+ const points = Fig.surfaceGrid({
508
+ x: [-0.8, 0.8, 0.02], y: [-0.8, 0.8, 0.02],
509
+ z: (x, y) => Math.sin(Math.sqrt(x*x + y*y) * 4) * 0.3,
510
+ });
511
+ figure.add({ make: 'surface', points, color: [1, 0, 0, 1], normals: 'curve' });
512
+ ```
513
+
514
+ ## Utilities
515
+
516
+ ```js
517
+ Fig.range(start, stop, step) // Array of numbers: [start, start+step, ..., stop]
518
+ new Fig.Point(x, y) // 2D/3D point; has .add(), .sub(), .scale(), .round()
519
+ new Fig.Transform() // Transform builder
520
+ .translate(x, y)
521
+ .rotate(angle)
522
+ .scale(sx, sy)
523
+ Fig.round(value, precision) // Round to N decimal places
524
+
525
+ // Color format: [r, g, b, a] with values 0 to 1
526
+ // [1, 0, 0, 1] = red, [0, 0, 1, 0.5] = semi-transparent blue
527
+ ```
528
+
529
+ ## Element Methods Reference
530
+
531
+ ```js
532
+ element.show() // Make visible
533
+ element.hide() // Make invisible
534
+ element.setPosition([x, y]) // Set position
535
+ element.getPosition() // Get position (returns Point)
536
+ element.setRotation(angle) // Set rotation in radians
537
+ element.getRotation() // Get rotation
538
+ element.setScale(x, y) // Set scale
539
+ element.setColor([r, g, b, a]) // Set color
540
+ element.setOpacity(value) // Set opacity (0-1)
541
+ element.dim() // Dim to 0.3 opacity
542
+ element.undim() // Restore full opacity
543
+ element.setScenario('name') // Jump to named scenario
544
+ element.setTouchable() // Enable touch
545
+ element.setMovable() // Enable dragging
546
+ element.pulse({ scale: 1.5 }) // Pulse animation
547
+ element.setText({ text: '...' }) // Update text content (text elements)
548
+ ```
package/package.json CHANGED
@@ -1,8 +1,23 @@
1
1
  {
2
2
  "name": "figureone",
3
- "version": "0.15.10",
3
+ "version": "1.0.1",
4
4
  "description": "Draw, animate and interact with shapes, text, plots and equations in Javascript. Create interactive slide shows, and interactive videos.",
5
5
  "main": "index.js",
6
+ "types": "types/index.d.ts",
7
+ "unpkg": "figureone.min.js",
8
+ "jsdelivr": "figureone.min.js",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./types/index.d.ts",
12
+ "default": "./index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "index.js",
17
+ "figureone.min.js",
18
+ "types/",
19
+ "llms.txt"
20
+ ],
6
21
  "repository": {
7
22
  "type": "git",
8
23
  "url": "git+https://github.com/airladon/figureone.git"
@@ -0,0 +1,128 @@
1
+ import * as g2 from './js/tools/g2';
2
+ import * as math from './js/tools/math';
3
+ import * as m2 from './js/tools/m2';
4
+ import * as m3 from './js/tools/m3';
5
+ import * as morph from './js/tools/morph';
6
+ import Figure from './js/figure/Figure';
7
+ import TimeKeeper from './js/figure/TimeKeeper';
8
+ import { Recorder } from './js/figure/Recorder/Recorder';
9
+ import { FunctionMap, GlobalFunctionMap } from './js/tools/FunctionMap';
10
+ import * as color from './js/tools/color';
11
+ import * as html from './js/tools/htmlGenerator';
12
+ import * as misc from './js/tools/tools';
13
+ import * as css from './js/tools/styleSheets';
14
+ import * as lines from './js/figure/geometries/lines/lines';
15
+ import { FigureElement, FigureElementPrimitive, FigureElementCollection } from './js/figure/Element';
16
+ import Scene from './js/tools/geometry/scene';
17
+ import DrawContext2D from './js/figure/DrawContext2D';
18
+ import WebGLInstance from './js/figure/webgl/webgl';
19
+ import DrawingObject from './js/figure/DrawingObjects/DrawingObject';
20
+ import VertexGeneric from './js/figure/DrawingObjects/VertexObject/VertexGeneric';
21
+ import { FigureFont } from './js/figure/DrawingObjects/TextObject/TextObject';
22
+ import HTMLObject from './js/figure/DrawingObjects/HTMLObject/HTMLObject';
23
+ import HTMLEquation from './js/figure/Equation/HTMLEquation';
24
+ import CollectionsAngle from './js/figure/FigureCollections/Angle';
25
+ import CollectionsLine from './js/figure/FigureCollections/Line';
26
+ import CollectionsPolyline from './js/figure/FigureCollections/PolyLine';
27
+ import EquationLabel from './js/figure/FigureCollections/EquationLabel';
28
+ import { Equation } from './js/figure/Equation/Equation';
29
+ import EquationForm from './js/figure/Equation/EquationForm';
30
+ import SlideNavigator from './js/figure/SlideNavigator';
31
+ import type { TypeRotationDirection, TypeParsablePoint } from './js/tools/g2';
32
+ import type { COL_Line, OBJ_LineLabel, TypeLabelledLine } from './js/figure/FigureCollections/Line';
33
+ import type { TypeLabelLocation, TypeLabelSubLocation, TypeLabelOrientation } from './js/figure/FigureCollections/EquationLabel';
34
+ import type { COL_Angle, TypeAngleLabelOptions, TypeLabelledAngle } from './js/figure/FigureCollections/Angle';
35
+ import type { OBJ_Figure } from './js/figure/Figure';
36
+ import type { COL_Polyline, OBJ_PolylinePad } from './js/figure/FigureCollections/PolyLine';
37
+ import * as anim from './js/figure/Animation/Animation';
38
+ export type { TypeRotationDirection, TypeLabelLocation, TypeLabelSubLocation, TypeLabelOrientation, COL_Line, COL_Angle, OBJ_Figure, OBJ_LineLabel, TypeAngleLabelOptions, COL_Polyline, OBJ_PolylinePad, TypeParsablePoint, TypeLabelledAngle, TypeLabelledLine, };
39
+ declare const Fig: {
40
+ version: string;
41
+ gitHash: string;
42
+ tools: {
43
+ math: typeof math;
44
+ g2: typeof g2;
45
+ m3: typeof m3;
46
+ color: typeof color;
47
+ css: typeof css;
48
+ html: typeof html;
49
+ misc: typeof misc;
50
+ lines: typeof lines;
51
+ m2: typeof m2;
52
+ morph: typeof morph;
53
+ };
54
+ Figure: typeof Figure;
55
+ Recorder: typeof Recorder;
56
+ FunctionMap: typeof FunctionMap;
57
+ GlobalFunctionMap: typeof GlobalFunctionMap;
58
+ SlideNavigator: typeof SlideNavigator;
59
+ FigureElement: typeof FigureElement;
60
+ FigureElementCollection: typeof FigureElementCollection;
61
+ FigureElementPrimitive: typeof FigureElementPrimitive;
62
+ DrawContext2D: typeof DrawContext2D;
63
+ WebGLInstance: typeof WebGLInstance;
64
+ DrawingObject: typeof DrawingObject;
65
+ VertexGeneric: typeof VertexGeneric;
66
+ FigureFont: typeof FigureFont;
67
+ HTMLObject: typeof HTMLObject;
68
+ CollectionsAngle: typeof CollectionsAngle;
69
+ CollectionsLine: typeof CollectionsLine;
70
+ CollectionsPolyline: typeof CollectionsPolyline;
71
+ EquationLabel: typeof EquationLabel;
72
+ EquationForm: typeof EquationForm;
73
+ Equation: typeof Equation;
74
+ HTMLEquation: typeof HTMLEquation;
75
+ Animation: typeof anim;
76
+ Scene: typeof Scene;
77
+ Point: typeof g2.Point;
78
+ Plane: typeof g2.Plane;
79
+ Line: typeof g2.Line;
80
+ Rect: typeof g2.Rect;
81
+ Transform: typeof g2.Transform;
82
+ parsePoint: typeof g2.getPoint;
83
+ LineBounds: typeof g2.LineBounds;
84
+ RectBounds: typeof g2.RectBounds;
85
+ RangeBounds: typeof g2.RangeBounds;
86
+ minAngleDiff: typeof g2.minAngleDiff;
87
+ getTriangleCenter: typeof g2.getTriangleCenter;
88
+ polarToRect: typeof g2.polarToRect;
89
+ rectToPolar: typeof g2.rectToPolar;
90
+ threePointAngle: typeof g2.threePointAngle;
91
+ threePointAngleMin: typeof g2.threePointAngleMin;
92
+ clipAngle: typeof g2.clipAngle;
93
+ getPoint: typeof g2.getPoint;
94
+ getPoints: typeof g2.getPoints;
95
+ getScale: typeof g2.getScale;
96
+ getLine: typeof g2.getLine;
97
+ getRect: typeof g2.getRect;
98
+ getPlane: typeof g2.getPlane;
99
+ getTransform: typeof g2.getTransform;
100
+ surfaceGrid: typeof g2.surfaceGrid;
101
+ cube: typeof g2.cube;
102
+ sphere: typeof g2.sphere;
103
+ polygon: typeof g2.polygon;
104
+ revolve: typeof g2.revolve;
105
+ surface: typeof g2.surface;
106
+ cone: typeof g2.cone;
107
+ cylinder: typeof g2.cylinder;
108
+ line3: typeof g2.line3;
109
+ getMaxTimeFromVelocity: typeof g2.getMaxTimeFromVelocity;
110
+ toNumbers: typeof g2.toNumbers;
111
+ pointsToNumbers: typeof g2.pointsToNumbers;
112
+ joinObjects: typeof misc.joinObjects;
113
+ m3: typeof m3;
114
+ morph: typeof morph;
115
+ misc: typeof misc;
116
+ round: typeof math.round;
117
+ roundNum: (value: number, precision?: number) => number;
118
+ range: typeof math.range;
119
+ randSign: typeof math.randSign;
120
+ randBool: typeof math.randBool;
121
+ randInt: typeof math.randInt;
122
+ rand: typeof math.rand;
123
+ randElement: typeof math.randElement;
124
+ randElements: typeof math.randElements;
125
+ removeRandElement: typeof math.removeRandElement;
126
+ TimeKeeper: typeof TimeKeeper;
127
+ };
128
+ export default Fig;