mathbox-react 0.0.4 → 0.0.5-dev

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 (54) hide show
  1. package/.eslintrc.js +3 -2
  2. package/.github/workflows/lint.yaml +3 -1
  3. package/.prettierrc +1 -0
  4. package/babel.config.js +3 -0
  5. package/build/cjs/index.js +1 -1
  6. package/build/cjs/index.js.map +1 -1
  7. package/build/cjs/types/components/Cartesian.spec.d.ts +1 -0
  8. package/build/cjs/types/components/Mathbox.d.ts +7 -5
  9. package/build/cjs/types/components/MathboxNodeContext.d.ts +4 -0
  10. package/build/cjs/types/components/components.d.ts +261 -0
  11. package/build/cjs/types/components/hooks.d.ts +4 -0
  12. package/build/cjs/types/components/index.d.ts +2 -0
  13. package/build/cjs/types/components/types.d.ts +7 -0
  14. package/build/cjs/types/index.d.ts +1 -2
  15. package/build/cjs/types/stories/utils.d.ts +5 -0
  16. package/build/cjs/types/testSetup.d.ts +1 -0
  17. package/build/cjs/types/testUtils.d.ts +1 -0
  18. package/build/esm/index.js +15 -1
  19. package/build/esm/index.js.map +1 -1
  20. package/build/esm/types/components/Cartesian.spec.d.ts +1 -0
  21. package/build/esm/types/components/Mathbox.d.ts +7 -5
  22. package/build/esm/types/components/MathboxNodeContext.d.ts +4 -0
  23. package/build/esm/types/components/components.d.ts +261 -0
  24. package/build/esm/types/components/hooks.d.ts +4 -0
  25. package/build/esm/types/components/index.d.ts +2 -0
  26. package/build/esm/types/components/types.d.ts +7 -0
  27. package/build/esm/types/index.d.ts +1 -2
  28. package/build/esm/types/stories/utils.d.ts +5 -0
  29. package/build/esm/types/testSetup.d.ts +1 -0
  30. package/build/esm/types/testUtils.d.ts +1 -0
  31. package/build/index.d.ts +271 -5
  32. package/jest.config.js +12 -0
  33. package/mathbox-react-0.0.4.tgz +0 -0
  34. package/package.json +15 -6
  35. package/scratch.js +149 -0
  36. package/src/components/Cartesian.spec.tsx +101 -0
  37. package/src/components/Mathbox.tsx +50 -33
  38. package/src/components/MathboxNodeContext.ts +6 -0
  39. package/src/components/components.tsx +361 -0
  40. package/src/components/hooks.ts +51 -0
  41. package/src/components/index.ts +2 -0
  42. package/src/components/types.ts +9 -0
  43. package/src/index.ts +1 -3
  44. package/src/stories/Cartesian.stories.tsx +36 -0
  45. package/src/stories/Grid.stories.tsx +38 -0
  46. package/src/stories/Mathbox.stories.tsx +16 -0
  47. package/src/stories/Point.stories.tsx +68 -0
  48. package/src/stories/utils.tsx +31 -0
  49. package/src/testSetup.ts +3 -0
  50. package/src/testUtils.ts +46 -0
  51. package/tsconfig.base.json +0 -1
  52. package/tsconfig.json +1 -0
  53. package/src/components/Mathbox.stories.tsx +0 -28
  54. package/src/types.d.ts +0 -4
package/build/index.d.ts CHANGED
@@ -1,6 +1,272 @@
1
- declare type Props = {
2
- element: HTMLElement;
3
- };
4
- declare const Mathbox: (props: Props) => null;
1
+ import React, { ReactNode } from 'react';
2
+ import { NodeType, Props, MathboxSelection } from 'mathbox';
5
3
 
6
- export { Mathbox };
4
+ declare type WithChildren<T> = {
5
+ children?: ReactNode | ReactNode[];
6
+ } & T;
7
+
8
+ declare type MathboxComponent<T extends NodeType> = React.ForwardRefExoticComponent<WithChildren<Props[T]> & React.RefAttributes<MathboxSelection<T>>>;
9
+ /**
10
+ * Component wrapper for mathbox [`area`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#dataarea).
11
+ */
12
+ declare const Area: MathboxComponent<"area">;
13
+ /**
14
+ * Component wrapper for mathbox [`array`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#dataarray).
15
+ */
16
+ declare const MBArray: MathboxComponent<"array">;
17
+
18
+ /**
19
+ * Component wrapper for mathbox [`axis`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawaxis).
20
+ */
21
+ declare const Axis: MathboxComponent<"axis">;
22
+ /**
23
+ * Component wrapper for mathbox [`camera`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#cameracamera).
24
+ */
25
+ declare const Camera: MathboxComponent<"camera">;
26
+ /**
27
+ * Component wrapper for mathbox [`cartesian`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewcartesian).
28
+ */
29
+ declare const Cartesian: MathboxComponent<"cartesian">;
30
+ /**
31
+ * Component wrapper for mathbox [`cartesian4`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewcartesian4).
32
+ */
33
+ declare const Cartesian4: MathboxComponent<"cartesian4">;
34
+ /**
35
+ * Component wrapper for mathbox [`clamp`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorclamp).
36
+ */
37
+ declare const Clamp: MathboxComponent<"clamp">;
38
+ /**
39
+ * Component wrapper for mathbox [`clock`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#timeclock).
40
+ */
41
+ declare const Clock: MathboxComponent<"clock">;
42
+ /**
43
+ * Component wrapper for mathbox [`compose`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#rttcompose).
44
+ */
45
+ declare const Compose: MathboxComponent<"compose">;
46
+ /**
47
+ * Component wrapper for mathbox [`dom`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#overlaydom).
48
+ */
49
+ declare const Dom: MathboxComponent<"dom">;
50
+ /**
51
+ * Component wrapper for mathbox [`face`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawface).
52
+ */
53
+ declare const Face: MathboxComponent<"face">;
54
+ /**
55
+ * Component wrapper for mathbox [`format`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#textformat).
56
+ */
57
+ declare const Format: MathboxComponent<"format">;
58
+ /**
59
+ * Component wrapper for mathbox [`fragment`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformfragment).
60
+ */
61
+ declare const Fragment: MathboxComponent<"fragment">;
62
+ /**
63
+ * Component wrapper for mathbox [`grid`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawgrid).
64
+ */
65
+ declare const Grid: MathboxComponent<"grid">;
66
+ /**
67
+ * Component wrapper for mathbox [`group`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#basegroup).
68
+ */
69
+ declare const Group: MathboxComponent<"group">;
70
+ /**
71
+ * Component wrapper for mathbox [`grow`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorgrow).
72
+ */
73
+ declare const Grow: MathboxComponent<"grow">;
74
+ /**
75
+ * Component wrapper for mathbox [`html`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#overlayhtml).
76
+ */
77
+ declare const Html: MathboxComponent<"html">;
78
+ /**
79
+ * Component wrapper for mathbox [`inherit`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#baseinherit).
80
+ */
81
+ declare const Inherit: MathboxComponent<"inherit">;
82
+ /**
83
+ * Component wrapper for mathbox [`interval`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#datainterval).
84
+ */
85
+ declare const Interval: MathboxComponent<"interval">;
86
+ /**
87
+ * Component wrapper for mathbox [`join`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorjoin).
88
+ */
89
+ declare const Join: MathboxComponent<"join">;
90
+ /**
91
+ * Component wrapper for mathbox [`label`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#textlabel).
92
+ */
93
+ declare const Label: MathboxComponent<"label">;
94
+ /**
95
+ * Component wrapper for mathbox [`layer`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformlayer).
96
+ */
97
+ declare const Layer: MathboxComponent<"layer">;
98
+ /**
99
+ * Component wrapper for mathbox [`lerp`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorlerp).
100
+ */
101
+ declare const Lerp: MathboxComponent<"lerp">;
102
+ /**
103
+ * Component wrapper for mathbox [`line`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawline).
104
+ */
105
+ declare const Line: MathboxComponent<"line">;
106
+ /**
107
+ * Component wrapper for mathbox [`mask`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformmask).
108
+ */
109
+ declare const Mask: MathboxComponent<"mask">;
110
+ /**
111
+ * Component wrapper for mathbox [`matrix`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#datamatrix).
112
+ */
113
+ declare const Matrix: MathboxComponent<"matrix">;
114
+ /**
115
+ * Component wrapper for mathbox [`memo`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatormemo).
116
+ */
117
+ declare const Memo: MathboxComponent<"memo">;
118
+ /**
119
+ * Component wrapper for mathbox [`move`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentmove).
120
+ */
121
+ declare const Move: MathboxComponent<"move">;
122
+ /**
123
+ * Component wrapper for mathbox [`now`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#timenow).
124
+ */
125
+ declare const Now: MathboxComponent<"now">;
126
+ /**
127
+ * Component wrapper for mathbox [`play`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentplay).
128
+ */
129
+ declare const Play: MathboxComponent<"play">;
130
+ /**
131
+ * Component wrapper for mathbox [`point`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawpoint).
132
+ */
133
+ declare const Point: MathboxComponent<"point">;
134
+ /**
135
+ * Component wrapper for mathbox [`polar`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewpolar).
136
+ */
137
+ declare const Polar: MathboxComponent<"polar">;
138
+ /**
139
+ * Component wrapper for mathbox [`present`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentpresent).
140
+ */
141
+ declare const Present: MathboxComponent<"present">;
142
+ /**
143
+ * Component wrapper for mathbox [`readback`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorreadback).
144
+ */
145
+ declare const Readback: MathboxComponent<"readback">;
146
+ /**
147
+ * Component wrapper for mathbox [`repeat`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorrepeat).
148
+ */
149
+ declare const Repeat: MathboxComponent<"repeat">;
150
+ /**
151
+ * Component wrapper for mathbox [`resample`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorresample).
152
+ */
153
+ declare const Resample: MathboxComponent<"resample">;
154
+ /**
155
+ * Component wrapper for mathbox [`retext`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#textretext).
156
+ */
157
+ declare const Retext: MathboxComponent<"retext">;
158
+ /**
159
+ * Component wrapper for mathbox [`reveal`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentreveal).
160
+ */
161
+ declare const Reveal: MathboxComponent<"reveal">;
162
+ /**
163
+ * Component wrapper for mathbox [`rtt`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#rttrtt).
164
+ */
165
+ declare const Rtt: MathboxComponent<"rtt">;
166
+ /**
167
+ * Component wrapper for mathbox [`scale`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#datascale).
168
+ */
169
+ declare const Scale: MathboxComponent<"scale">;
170
+ /**
171
+ * Component wrapper for mathbox [`shader`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#shadershader).
172
+ */
173
+ declare const Shader: MathboxComponent<"shader">;
174
+ /**
175
+ * Component wrapper for mathbox [`slice`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorslice).
176
+ */
177
+ declare const Slice: MathboxComponent<"slice">;
178
+ /**
179
+ * Component wrapper for mathbox [`slide`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentslide).
180
+ */
181
+ declare const Slide: MathboxComponent<"slide">;
182
+ /**
183
+ * Component wrapper for mathbox [`spherical`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewspherical).
184
+ */
185
+ declare const Spherical: MathboxComponent<"spherical">;
186
+ /**
187
+ * Component wrapper for mathbox [`split`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorsplit).
188
+ */
189
+ declare const Split: MathboxComponent<"split">;
190
+ /**
191
+ * Component wrapper for mathbox [`spread`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorspread).
192
+ */
193
+ declare const Spread: MathboxComponent<"spread">;
194
+ /**
195
+ * Component wrapper for mathbox [`step`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#presentstep).
196
+ */
197
+ declare const Step: MathboxComponent<"step">;
198
+ /**
199
+ * Component wrapper for mathbox [`stereographic`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewstereographic).
200
+ */
201
+ declare const Stereographic: MathboxComponent<"stereographic">;
202
+ /**
203
+ * Component wrapper for mathbox [`stereographic4`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewstereographic4).
204
+ */
205
+ declare const Stereographic4: MathboxComponent<"stereographic4">;
206
+ /**
207
+ * Component wrapper for mathbox [`strip`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawstrip).
208
+ */
209
+ declare const Strip: MathboxComponent<"strip">;
210
+ /**
211
+ * Component wrapper for mathbox [`subdivide`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorsubdivide).
212
+ */
213
+ declare const Subdivide: MathboxComponent<"subdivide">;
214
+ /**
215
+ * Component wrapper for mathbox [`surface`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawsurface).
216
+ */
217
+ declare const Surface: MathboxComponent<"surface">;
218
+ /**
219
+ * Component wrapper for mathbox [`swizzle`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatorswizzle).
220
+ */
221
+ declare const Swizzle: MathboxComponent<"swizzle">;
222
+ /**
223
+ * Component wrapper for mathbox [`text`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#texttext).
224
+ */
225
+ declare const Text: MathboxComponent<"text">;
226
+ /**
227
+ * Component wrapper for mathbox [`ticks`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawticks).
228
+ */
229
+ declare const Ticks: MathboxComponent<"ticks">;
230
+ /**
231
+ * Component wrapper for mathbox [`transform`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformtransform).
232
+ */
233
+ declare const Transform: MathboxComponent<"transform">;
234
+ /**
235
+ * Component wrapper for mathbox [`transform4`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformtransform4).
236
+ */
237
+ declare const Transform4: MathboxComponent<"transform4">;
238
+ /**
239
+ * Component wrapper for mathbox [`transpose`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#operatortranspose).
240
+ */
241
+ declare const Transpose: MathboxComponent<"transpose">;
242
+ /**
243
+ * Component wrapper for mathbox [`unit`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#baseunit).
244
+ */
245
+ declare const Unit: MathboxComponent<"unit">;
246
+ /**
247
+ * Component wrapper for mathbox [`vector`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#drawvector).
248
+ */
249
+ declare const Vector: MathboxComponent<"vector">;
250
+ /**
251
+ * Component wrapper for mathbox [`vertex`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#transformvertex).
252
+ */
253
+ declare const Vertex: MathboxComponent<"vertex">;
254
+ /**
255
+ * Component wrapper for mathbox [`view`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#viewview).
256
+ */
257
+ declare const View: MathboxComponent<"view">;
258
+ /**
259
+ * Component wrapper for mathbox [`volume`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#datavolume).
260
+ */
261
+ declare const Volume: MathboxComponent<"volume">;
262
+ /**
263
+ * Component wrapper for mathbox [`voxel`](https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#datavoxel).
264
+ */
265
+ declare const Voxel: MathboxComponent<"voxel">;
266
+
267
+ declare const _default: React.ForwardRefExoticComponent<Pick<{
268
+ options?: any;
269
+ initialCameraPosition?: number[] | undefined;
270
+ } & React.HTMLProps<HTMLDivElement>, "label" | "step" | "value" | "children" | "data" | "width" | "height" | "type" | "id" | "style" | "color" | "span" | "size" | "start" | "loop" | "target" | "sizes" | "shape" | "cite" | "form" | "slot" | "summary" | "title" | "pattern" | "options" | "initialCameraPosition" | "list" | "accept" | "acceptCharset" | "action" | "allowFullScreen" | "allowTransparency" | "alt" | "as" | "async" | "autoComplete" | "autoFocus" | "autoPlay" | "capture" | "cellPadding" | "cellSpacing" | "charSet" | "challenge" | "checked" | "classID" | "cols" | "colSpan" | "content" | "controls" | "coords" | "crossOrigin" | "dateTime" | "default" | "defer" | "disabled" | "download" | "encType" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "frameBorder" | "headers" | "high" | "href" | "hrefLang" | "htmlFor" | "httpEquiv" | "integrity" | "keyParams" | "keyType" | "kind" | "low" | "manifest" | "marginHeight" | "marginWidth" | "max" | "maxLength" | "media" | "mediaGroup" | "method" | "min" | "minLength" | "multiple" | "muted" | "name" | "nonce" | "noValidate" | "open" | "optimum" | "placeholder" | "playsInline" | "poster" | "preload" | "readOnly" | "rel" | "required" | "reversed" | "rows" | "rowSpan" | "sandbox" | "scope" | "scoped" | "scrolling" | "seamless" | "selected" | "src" | "srcDoc" | "srcLang" | "srcSet" | "useMap" | "wmode" | "wrap" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "lang" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "key"> & React.RefAttributes<MathboxSelection<"root">>>;
271
+
272
+ export { Area, MBArray as Array, Axis, Camera, Cartesian, Cartesian4, Clamp, Clock, Compose, Dom, Face, Format, Fragment, Grid, Group, Grow, Html, Inherit, Interval, Join, Label, Layer, Lerp, Line, Mask, _default as Mathbox, Matrix, Memo, Move, Now, Play, Point, Polar, Present, Readback, Repeat, Resample, Retext, Reveal, Rtt, Scale, Shader, Slice, Slide, Spherical, Split, Spread, Step, Stereographic, Stereographic4, Strip, Subdivide, Surface, Swizzle, Text, Ticks, Transform, Transform4, Transpose, Unit, Vector, Vertex, View, Volume, Voxel };
package/jest.config.js ADDED
@@ -0,0 +1,12 @@
1
+ module.exports = {
2
+ preset: "ts-jest",
3
+ transform: {
4
+ "^.+\\.(ts|tsx)?$": "ts-jest",
5
+ "^.+\\.(js|jsx)$": "babel-jest",
6
+ },
7
+ transformIgnorePatterns: [
8
+ "node_modules/(?!(mathbox|threestrap|three|shadergraph)/)",
9
+ ],
10
+ testEnvironment: "jsdom",
11
+ setupFiles: ["./src/testSetup.ts"],
12
+ }
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mathbox-react",
3
- "version": "0.0.4",
3
+ "version": "0.0.5-dev",
4
4
  "description": "React wrapper for Mathbox",
5
5
  "license": "ISC",
6
6
  "author": "Chris Chudzicki",
@@ -11,11 +11,15 @@
11
11
  "build": "rm -rf build && rollup -c",
12
12
  "build-storybook": "build-storybook",
13
13
  "storybook": "start-storybook -p 6006",
14
- "lint": "eslint \"src/**/*.{ts,tsx}\" --fix --max-warnings=0",
15
- "prepublishOnly": "npm run lint && npm run build"
14
+ "lint": "eslint \"src/**/*.{ts,tsx}\" --max-warnings=0",
15
+ "format": "prettier src",
16
+ "autofix": "npm run format -- --write && npm run lint -- --fix",
17
+ "prepack": "npm run build",
18
+ "test": "jest"
16
19
  },
17
20
  "devDependencies": {
18
21
  "@babel/core": "^7.17.5",
22
+ "@babel/preset-env": "^7.16.11",
19
23
  "@rollup/plugin-commonjs": "^21.0.1",
20
24
  "@rollup/plugin-node-resolve": "^13.1.3",
21
25
  "@rollup/plugin-typescript": "^8.3.0",
@@ -25,8 +29,11 @@
25
29
  "@storybook/addon-links": "^6.4.19",
26
30
  "@storybook/react": "^6.4.19",
27
31
  "@storybook/testing-library": "^0.0.9",
32
+ "@testing-library/react": "^12.1.3",
33
+ "@types/jest": "^27.4.1",
28
34
  "@types/react": "^17.0.39",
29
35
  "@types/three": "^0.137.0",
36
+ "babel-jest": "^27.5.1",
30
37
  "babel-loader": "^8.2.3",
31
38
  "eslint-config-airbnb": "^19.0.4",
32
39
  "eslint-config-airbnb-typescript": "^16.1.0",
@@ -34,7 +41,8 @@
34
41
  "eslint-config-react-app": "^7.0.0",
35
42
  "eslint-import-resolver-typescript": "^2.5.0",
36
43
  "eslint-plugin-prettier": "^4.0.0",
37
- "mathbox": "^2.1.0",
44
+ "jest": "^27.5.1",
45
+ "mathbox": "2.1.2-dev",
38
46
  "prettier": "^2.5.1",
39
47
  "react": "^17.0.2",
40
48
  "react-dom": "^17.0.2",
@@ -43,11 +51,12 @@
43
51
  "rollup-plugin-peer-deps-external": "^2.2.4",
44
52
  "rollup-plugin-terser": "^7.0.2",
45
53
  "three": "^0.137.5",
54
+ "ts-jest": "^27.1.3",
46
55
  "typescript": "^4.5.5"
47
56
  },
48
57
  "peerDependencies": {
49
- "mathbox": "^2.1.0",
58
+ "mathbox": "2.1.2-dev",
50
59
  "react": "^17.0.2",
51
- "three": "^0.137.5"
60
+ "three": ">=0.118.0"
52
61
  }
53
62
  }
package/scratch.js ADDED
@@ -0,0 +1,149 @@
1
+ const classDescriptions = {
2
+ axis: ["draw", "Draw an axis", {}, { end: "true", zBias: "-1" }],
3
+ face: ["draw", "Draw polygon faces"],
4
+ grid: ["draw", "Draw a 2D line grid", {}, { width: "1", zBias: "-2" }],
5
+ line: ["draw", "Draw lines"],
6
+ point: ["draw", "Draw points"],
7
+ strip: ["draw", "Draw triangle strips"],
8
+ surface: ["draw", "Draw surfaces", {}, { lineX: "false", lineY: "false" }],
9
+ ticks: ["draw", "Draw ticks"],
10
+ vector: ["draw", "Draw vectors"],
11
+
12
+ view: ["view", "Adjust view range"],
13
+ cartesian: ["view", "Apply cartesian view"],
14
+ cartesian4: ["view", "Apply 4D cartesian view"],
15
+ polar: ["view", "Apply polar view"],
16
+ spherical: ["view", "Apply spherical view"],
17
+ stereographic: ["view", "Apply stereographic projection"],
18
+ stereographic4: ["view", "Apply 4D stereographic projection"],
19
+
20
+ transform: ["transform", "Transform geometry in 3D"],
21
+ transform4: ["transform", "Transform geometry in 4D"],
22
+ vertex: ["transform", "Apply custom vertex shader pass"],
23
+ fragment: ["transform", "Apply custom fragment shader pass"],
24
+ layer: ["transform", "Independent 2D layer/overlay"],
25
+ mask: ["transform", "Apply custom mask pass"],
26
+
27
+ array: [
28
+ "data",
29
+ "1D array",
30
+ { expr: "function (emit, i, time, delta) { ... }" },
31
+ ],
32
+ interval: [
33
+ "data",
34
+ "1D sampled array",
35
+ { expr: "function (emit, x, i, time, delta) { ... }" },
36
+ ],
37
+ matrix: [
38
+ "data",
39
+ "2D matrix",
40
+ { expr: "function (emit, i, j, time, delta) { ... }" },
41
+ ],
42
+ area: [
43
+ "data",
44
+ "2D sampled matrix",
45
+ { expr: "function (emit, x, y, i, j, time, delta) { ... }" },
46
+ ],
47
+ voxel: [
48
+ "data",
49
+ "3D voxels",
50
+ { expr: "function (emit, i, j, k, time, delta) { ... }" },
51
+ ],
52
+ volume: [
53
+ "data",
54
+ "3D sampled voxels",
55
+ { expr: "function (emit, x, y, z, i, j, k, time, delta) { ... }" },
56
+ ],
57
+ scale: ["data", "Human-friendly divisions on an axis, subdivided as needed"],
58
+
59
+ html: ["overlay", "HTML element source"],
60
+ dom: ["overlay", "HTML DOM injector"],
61
+
62
+ text: [
63
+ "text",
64
+ "GL text source",
65
+ {},
66
+ { minFilter: '"linear"', magFilter: '"linear"' },
67
+ ],
68
+ format: [
69
+ "text",
70
+ "Text formatter",
71
+ { expr: "function (x, y, z, w, i, j, k, l, time, delta) { ... }" },
72
+ { minFilter: '"linear"', magFilter: '"linear"' },
73
+ ],
74
+ retext: ["text", "Text atlas resampler"],
75
+ label: ["text", "Draw GL labels"],
76
+
77
+ clamp: ["operator", "Clamp out-of-bounds samples to the nearest data point"],
78
+ grow: ["operator", "Scale data relative to reference data point"],
79
+ join: [
80
+ "operator",
81
+ "Join two array dimensions into one by concatenating rows/columns/stacks",
82
+ ],
83
+ lerp: ["operator", "Linear interpolation of data"],
84
+ memo: ["operator", "Memoize data to an array/texture"],
85
+ readback: [
86
+ "operator",
87
+ "Read data back to a binary JavaScript array",
88
+ { expr: "function (x, y, z, w, i, j, k, l) { ... }" },
89
+ ],
90
+ resample: ["operator", "Resample data to new dimensions with a shader"],
91
+ repeat: ["operator", "Repeat data in one or more dimensions"],
92
+ swizzle: ["operator", "Swizzle data values"],
93
+ spread: ["operator", "Spread data values according to array indices"],
94
+ split: [
95
+ "operator",
96
+ "Split one array dimension into two by splitting rows/columns/etc",
97
+ ],
98
+ slice: ["operator", "Select one or more rows/columns/stacks"],
99
+ subdivide: ["operator", "Subdivide data points evenly or with a bevel"],
100
+ transpose: ["operator", "Transpose array dimensions"],
101
+
102
+ group: ["base", "Group elements for visibility and activity"],
103
+ inherit: ["base", "Inherit and inject a trait from another element"],
104
+ root: ["base", "Tree root"],
105
+ unit: ["base", "Change unit sizing for drawing ops"],
106
+
107
+ shader: ["shader", "Custom shader snippet"],
108
+
109
+ camera: ["camera", "Camera instance or proxy"],
110
+
111
+ rtt: [
112
+ "rtt",
113
+ "Render objects to a texture",
114
+ {},
115
+ { minFilter: '"linear"', magFilter: '"linear"', type: '"unsignedByte"' },
116
+ ],
117
+ compose: [
118
+ "rtt",
119
+ "Full-screen render pass",
120
+ {},
121
+ { zWrite: "false", zTest: "false", color: '"white"' },
122
+ ],
123
+
124
+ clock: ["time", "Relative clock that starts from zero."],
125
+ now: ["time", "Absolute UNIX time in seconds since 01/01/1970"],
126
+
127
+ move: ["present", "Move elements in/out on transition"],
128
+ play: ["present", "Play a sequenced animation"],
129
+ present: ["present", "Present a tree of slides"],
130
+ reveal: ["present", "Reveal/hide elements on transition"],
131
+ slide: ["present", "Presentation slide"],
132
+ step: ["present", "Step through a sequenced animation"],
133
+ }
134
+
135
+ const capitalize = (s) => `${s[0].toUpperCase()}${s.slice(1)}`
136
+
137
+ const makeDef = (name) => {
138
+ const [group] = classDescriptions[name]
139
+ const Name = capitalize(name)
140
+ const dest = `https://gitgud.io/unconed/mathbox/-/blob/master/docs/primitives.md#${group}${name}`
141
+ const def = `
142
+ /**
143
+ * Component wrapper for mathbox [\`${name}\`](${dest}).
144
+ */
145
+ export const ${Name} = mathboxComponentFactory('${name}');`
146
+ console.log(def)
147
+ }
148
+
149
+ Object.keys(classDescriptions).sort().forEach(makeDef)
@@ -0,0 +1,101 @@
1
+ import React from "react"
2
+ import { render } from "@testing-library/react"
3
+ import Mathbox from "./Mathbox"
4
+ import { Cartesian, Grid } from "./components"
5
+ import { MathboxRef } from "./types"
6
+
7
+ function assertNotUndefined<T>(value: T | undefined): asserts value is T {
8
+ if (value === undefined) {
9
+ throw new Error("Unexpected undefined value")
10
+ }
11
+ }
12
+
13
+ describe("Cartesian", () => {
14
+ it("exposes Mathbox instance via ref", () => {
15
+ const mbRef: MathboxRef<"root"> = { current: null }
16
+ const cartesianRef: MathboxRef<"cartesian"> = { current: null }
17
+ render(
18
+ <Mathbox ref={mbRef}>
19
+ <Cartesian ref={cartesianRef} />
20
+ </Mathbox>
21
+ )
22
+
23
+ expect(mbRef.current?.[0].type).toBe("root")
24
+ expect(cartesianRef.current?.[0].type).toBe("cartesian")
25
+ })
26
+
27
+ it("creates a cartesian instance as child of root", () => {
28
+ const mbRef: MathboxRef<"root"> = { current: null }
29
+ render(
30
+ <Mathbox ref={mbRef}>
31
+ <Cartesian />
32
+ </Mathbox>
33
+ )
34
+ expect(mbRef.current?.select("cartesian").length).toBe(1)
35
+ })
36
+
37
+ it("creates mathbox children as children of itself", () => {
38
+ const mbRef: MathboxRef<"root"> = { current: null }
39
+ render(
40
+ <Mathbox ref={mbRef}>
41
+ <Cartesian>
42
+ <Grid />
43
+ <Grid />
44
+ </Cartesian>
45
+ </Mathbox>
46
+ )
47
+ mbRef.current?.print()
48
+ expect(mbRef.current?.select("cartesian").length).toBe(1)
49
+ expect(mbRef.current?.select("cartesian grid").length).toBe(2)
50
+ })
51
+
52
+ it("removes its mathbox instance when unmounted", () => {
53
+ const mbRef: MathboxRef<"root"> = { current: null }
54
+ const { rerender } = render(
55
+ <Mathbox ref={mbRef}>
56
+ <Cartesian />
57
+ </Mathbox>
58
+ )
59
+ expect(mbRef.current?.select("cartesian").length).toBe(1)
60
+ rerender(<Mathbox ref={mbRef} />)
61
+ expect(mbRef.current?.select("cartesian").length).toBe(0)
62
+ })
63
+
64
+ it.each([
65
+ { props: { visible: true, scale: [3, 2, 1] } },
66
+ { props: { visible: false, scale: [1, 2, 3] } },
67
+ ])("passes appropriate props to its mathbox instance", ({ props }) => {
68
+ const mbRef: MathboxRef<"root"> = { current: null }
69
+ render(
70
+ <Mathbox ref={mbRef}>
71
+ <Cartesian {...props} />
72
+ </Mathbox>
73
+ )
74
+ const cartesian = mbRef.current?.select<"cartesian">("cartesian")
75
+
76
+ assertNotUndefined(cartesian)
77
+
78
+ expect(cartesian.get("visible")).toBe(props.visible)
79
+ // Mathbox converts scale to a ThreeJS Vec3
80
+ expect(cartesian.get("scale").toArray()).toStrictEqual(props.scale)
81
+ })
82
+
83
+ it("updates props on its mathbox instance when rerendered", () => {
84
+ const mbRef: MathboxRef<"root"> = { current: null }
85
+ const { rerender } = render(
86
+ <Mathbox ref={mbRef}>
87
+ <Cartesian />
88
+ </Mathbox>
89
+ )
90
+ const cartesian = mbRef.current?.select<"cartesian">("cartesian")
91
+ assertNotUndefined(cartesian)
92
+
93
+ expect(cartesian.get("visible")).toBe(true)
94
+ rerender(
95
+ <Mathbox ref={mbRef}>
96
+ <Cartesian visible={false} />
97
+ </Mathbox>
98
+ )
99
+ expect(cartesian.get("visible")).toBe(false)
100
+ })
101
+ })