@ifiwas/standard-view 2.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 (134) hide show
  1. package/.prettierignore +67 -0
  2. package/.prettierrc +12 -0
  3. package/CHANGELOG.md +42 -0
  4. package/LICENSE +8 -0
  5. package/README.md +199 -0
  6. package/debug-storybook.log +179 -0
  7. package/declarations.d.ts +17 -0
  8. package/dist/standard-view.es.js +9522 -0
  9. package/dist/standard-view.es.js.map +1 -0
  10. package/dist/standard-view.umd.js +41 -0
  11. package/dist/standard-view.umd.js.map +1 -0
  12. package/fonts/gentilis.bold.typeface.json +1 -0
  13. package/fonts/gentilis.typeface.json +1 -0
  14. package/fonts/helvetiker.bold.typeface.json +1 -0
  15. package/fonts/helvetiker.typeface.json +1 -0
  16. package/fonts/optimer.bold.typeface.json +1 -0
  17. package/fonts/optimer.typeface.json +1 -0
  18. package/images.d.ts +7 -0
  19. package/index.js +10 -0
  20. package/lib/controls/OrbitControls.d.ts +9 -0
  21. package/lib/controls/OrbitControls.js +761 -0
  22. package/lib/controls/index.d.ts +1 -0
  23. package/lib/controls/index.js +18 -0
  24. package/lib/groups/Arrow.d.ts +19 -0
  25. package/lib/groups/Arrow.js +134 -0
  26. package/lib/groups/Axis.d.ts +20 -0
  27. package/lib/groups/Axis.js +147 -0
  28. package/lib/groups/BoundingBox.d.ts +9 -0
  29. package/lib/groups/BoundingBox.js +143 -0
  30. package/lib/groups/Camera.d.ts +32 -0
  31. package/lib/groups/Camera.js +477 -0
  32. package/lib/groups/Capsule.d.ts +9 -0
  33. package/lib/groups/Capsule.js +112 -0
  34. package/lib/groups/FBX.d.ts +9 -0
  35. package/lib/groups/FBX.js +213 -0
  36. package/lib/groups/GLTF.d.ts +9 -0
  37. package/lib/groups/GLTF.js +198 -0
  38. package/lib/groups/Group.d.ts +63 -0
  39. package/lib/groups/Group.js +426 -0
  40. package/lib/groups/OBJ.d.ts +11 -0
  41. package/lib/groups/OBJ.js +252 -0
  42. package/lib/groups/PCD.d.ts +9 -0
  43. package/lib/groups/PCD.js +82 -0
  44. package/lib/groups/Path.d.ts +19 -0
  45. package/lib/groups/Path.js +160 -0
  46. package/lib/groups/index.d.ts +11 -0
  47. package/lib/groups/index.js +91 -0
  48. package/lib/index.d.ts +6 -0
  49. package/lib/index.js +298 -0
  50. package/lib/lights/AmbientLight.d.ts +8 -0
  51. package/lib/lights/AmbientLight.js +37 -0
  52. package/lib/lights/DirectionalLight.d.ts +8 -0
  53. package/lib/lights/DirectionalLight.js +43 -0
  54. package/lib/lights/HemisphereLight.d.ts +13 -0
  55. package/lib/lights/HemisphereLight.js +108 -0
  56. package/lib/lights/LightWithShadows.d.ts +24 -0
  57. package/lib/lights/LightWithShadows.js +188 -0
  58. package/lib/lights/PointLight.d.ts +9 -0
  59. package/lib/lights/PointLight.js +47 -0
  60. package/lib/lights/RectAreaLight.d.ts +13 -0
  61. package/lib/lights/RectAreaLight.js +177 -0
  62. package/lib/lights/SpotLight.d.ts +10 -0
  63. package/lib/lights/SpotLight.js +49 -0
  64. package/lib/lights/index.d.ts +6 -0
  65. package/lib/lights/index.js +48 -0
  66. package/lib/primitives/Box.d.ts +6 -0
  67. package/lib/primitives/Box.js +43 -0
  68. package/lib/primitives/Circle.d.ts +10 -0
  69. package/lib/primitives/Circle.js +85 -0
  70. package/lib/primitives/Cylinder.d.ts +15 -0
  71. package/lib/primitives/Cylinder.js +180 -0
  72. package/lib/primitives/Label.d.ts +18 -0
  73. package/lib/primitives/Label.js +189 -0
  74. package/lib/primitives/Line.d.ts +19 -0
  75. package/lib/primitives/Line.js +173 -0
  76. package/lib/primitives/Mesh.d.ts +72 -0
  77. package/lib/primitives/Mesh.js +642 -0
  78. package/lib/primitives/Plane.d.ts +7 -0
  79. package/lib/primitives/Plane.js +47 -0
  80. package/lib/primitives/Polygon.d.ts +8 -0
  81. package/lib/primitives/Polygon.js +75 -0
  82. package/lib/primitives/Quad.d.ts +9 -0
  83. package/lib/primitives/Quad.js +110 -0
  84. package/lib/primitives/Sphere.d.ts +14 -0
  85. package/lib/primitives/Sphere.js +92 -0
  86. package/lib/primitives/Text.d.ts +20 -0
  87. package/lib/primitives/Text.js +285 -0
  88. package/lib/primitives/Triangle.d.ts +8 -0
  89. package/lib/primitives/Triangle.js +83 -0
  90. package/lib/primitives/index.d.ts +12 -0
  91. package/lib/primitives/index.js +90 -0
  92. package/lib/shaders/index.d.ts +0 -0
  93. package/lib/shaders/index.js +2 -0
  94. package/lib/types/three-jsx.d.js +5 -0
  95. package/lib/utils/constants.js +181 -0
  96. package/lib/utils/events.d.ts +22 -0
  97. package/lib/utils/events.js +98 -0
  98. package/lib/utils/hooks.d.ts +8 -0
  99. package/lib/utils/hooks.js +96 -0
  100. package/lib/utils/index.d.ts +3 -0
  101. package/lib/utils/index.js +110 -0
  102. package/lib/utils/interfaces.d.ts +9 -0
  103. package/lib/utils/interfaces.js +5 -0
  104. package/lib/utils/math.d.ts +12 -0
  105. package/lib/utils/math.js +31 -0
  106. package/lib/utils/performance.d.ts +7 -0
  107. package/lib/utils/performance.js +114 -0
  108. package/lib/utils/styles.js +10 -0
  109. package/lib/utils/util.d.ts +76 -0
  110. package/lib/utils/util.js +290 -0
  111. package/lib/views/ContextBridge.d.ts +23 -0
  112. package/lib/views/ContextBridge.js +98 -0
  113. package/lib/views/SceneCamera.d.ts +7 -0
  114. package/lib/views/SceneCamera.js +52 -0
  115. package/lib/views/SetBackground.d.ts +9 -0
  116. package/lib/views/SetBackground.js +90 -0
  117. package/lib/views/SetControls.d.ts +19 -0
  118. package/lib/views/SetControls.js +173 -0
  119. package/lib/views/SetRenderer.d.ts +25 -0
  120. package/lib/views/SetRenderer.js +66 -0
  121. package/lib/views/SetShadows.d.ts +7 -0
  122. package/lib/views/SetShadows.js +48 -0
  123. package/lib/views/View3D.d.ts +21 -0
  124. package/lib/views/View3D.js +289 -0
  125. package/lib/views/ViewContext.d.ts +23 -0
  126. package/lib/views/ViewContext.js +55 -0
  127. package/lib/views/index.d.ts +2 -0
  128. package/lib/views/index.js +20 -0
  129. package/netlify.toml +15 -0
  130. package/package.json +110 -0
  131. package/tsconfig.json +42 -0
  132. package/tsconfig.prod.json +3 -0
  133. package/tsconfig.test.json +6 -0
  134. package/vite.config.ts +37 -0
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ var _fiber = require("@react-three/fiber");
10
+ var _SetRenderer = _interopRequireDefault(require("./SetRenderer"));
11
+ var _SetBackground = _interopRequireDefault(require("./SetBackground"));
12
+ var _SetShadows = _interopRequireDefault(require("./SetShadows"));
13
+ var _SetControls = _interopRequireWildcard(require("./SetControls"));
14
+ var _ContextBridge = require("./ContextBridge");
15
+ var _ViewContext = require("./ViewContext");
16
+ var _util = require("../utils/util");
17
+ var _constants = require("../utils/constants");
18
+ var _package = require("../../package.json");
19
+ var _excluded = ["trackballControls", "orbitControls", "mapControls", "backgroundColor", "backgroundTextureURL", "backgroundEquirectangularTextureURL", "backgroundEquirectangularRGBEURL", "shadowMapEnabled", "shadowType", "camera", "controls", "gl", "orthographic", "contexts", "children"],
20
+ _excluded2 = ["position", "target", "up", "rotation", "roll"],
21
+ _excluded3 = ["polarAngle", "azimuthAngle"]; // View3D.tsx
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
23
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
24
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
25
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
26
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
27
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
28
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
29
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
30
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
31
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
32
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
33
+ var useRef = React.useRef,
34
+ useEffect = React.useEffect,
35
+ useMemo = React.useMemo,
36
+ memo = React.memo;
37
+ /**
38
+ * View3D
39
+ *
40
+ * In Standard View, View3D creates the @react-three/fiber Canvas
41
+ * and also applies some extra features, such as setting the
42
+ * background color/texture/equirectangular texture.
43
+ * For @react-three/fiber, this is not possible since the background
44
+ * color or texture is not a THREE.WebGLRenderer parameter with a setter.
45
+ * Since @react-three/fiber does not provide an easy way to call methods
46
+ * of three.js objects, View3D provides the settings for the Canvas
47
+ * that @react-three/fiber does not.
48
+ *
49
+ * All other @react-three/fiber functionality for its Canvas properties
50
+ * are maintained and applied, since the View3D specific properties are
51
+ * stripped out.
52
+ *
53
+ * Camera controls may be enable by passing in true for either trackballControls
54
+ * orbitControls, or mapControls. Camera controls parameters may be passed with the controls
55
+ * prop in the form of an Object, similar to camera's props.
56
+ *
57
+ * SetCanvasProps is a small component that isolates the useThree hook.
58
+ * Unfortunately, @react-three/fiber hooks incur additional renders,
59
+ * hence those hooks have been encapsulated into small components to avoid
60
+ * re-rendering larger more complicated logic. Similarly, UpdateCameraControls
61
+ * isolates the useThree hook.
62
+ *
63
+ * SetBackground, SetShadows, and SetControls contain logic encapsulated in
64
+ * components because these changes cannot be applied through @react-three/fiber
65
+ * props on Canvas. Also, this logic cannot be applied in the body of View3D
66
+ * since background, shadows, and camera controls depends on the creation of
67
+ * Canvas and ultimately mutate the Canvas Properties, namely camera, gl,
68
+ * and scene. Thus this logic must execute in components after Canvas is created
69
+ * and within the Canvas component.
70
+ *
71
+ * Any number of React contexts may be passed into View3D. Since @react-three/fiber
72
+ * provides its own render method and reconciler, contexts must be maintained via
73
+ * a context bridge. In order to permeate contexts into View3D, pass an array of
74
+ * all contexts to the contexts prop.
75
+ * Also, ViewContext will always provide Canvas Props so that all components in a
76
+ * particular View3D has access to those particular @react-three/fiber
77
+ * Canvas Props (gl, scene, camera, etc)
78
+ *
79
+ * @param {View3DProps} props
80
+ */
81
+ var View3D = function View3D(_ref) {
82
+ var trackballControls = _ref.trackballControls,
83
+ orbitControls = _ref.orbitControls,
84
+ mapControls = _ref.mapControls,
85
+ backgroundColor = _ref.backgroundColor,
86
+ backgroundTextureURL = _ref.backgroundTextureURL,
87
+ backgroundEquirectangularTextureURL = _ref.backgroundEquirectangularTextureURL,
88
+ backgroundEquirectangularRGBEURL = _ref.backgroundEquirectangularRGBEURL,
89
+ _ref$shadowMapEnabled = _ref.shadowMapEnabled,
90
+ shadowMapEnabled = _ref$shadowMapEnabled === void 0 ? false : _ref$shadowMapEnabled,
91
+ _ref$shadowType = _ref.shadowType,
92
+ shadowType = _ref$shadowType === void 0 ? 'pcfsoft' : _ref$shadowType,
93
+ camera = _ref.camera,
94
+ _ref$controls = _ref.controls,
95
+ controls = _ref$controls === void 0 ? {} : _ref$controls,
96
+ gl = _ref.gl,
97
+ orthographic = _ref.orthographic,
98
+ contexts = _ref.contexts,
99
+ children = _ref.children,
100
+ otherProps = _objectWithoutProperties(_ref, _excluded);
101
+ // Print Standard View Version
102
+ useEffect(function () {
103
+ /* eslint-disable-next-line no-console */
104
+ console.log("%cStandard View Core ".concat(_package.version), 'color: orange');
105
+ }, []);
106
+
107
+ // ----- Contexts -----//
108
+ var _contexts = useMemo(function updateContexts() {
109
+ if (contexts) {
110
+ // Handle Single Context (non Array) or Multiple Contexts (Array)
111
+ return Array.isArray(contexts) ? contexts : [contexts];
112
+ } else {
113
+ return [];
114
+ }
115
+ }, [contexts]);
116
+
117
+ // ----- Canvas Props -----//
118
+ var canvasProps = useRef(null);
119
+
120
+ // ----- gl Props -----//
121
+ var _useMemo = useMemo(function updateGLProps() {
122
+ // WebGLRenderer Parameters on Initialization
123
+ var glParameterKeys = ['context', 'precision', 'alpha', 'premultipliedAlpha', 'antialias', 'stencil', 'preserveDrawingBuffer', 'powerPreference', 'failIfMajorPerformanceCaveat', 'depth', 'logarithmicDepthBuffer'];
124
+
125
+ /* eslint-disable no-shadow */
126
+ var glParameters = {
127
+ antialias: true,
128
+ preserveDrawingBuffer: true
129
+ };
130
+ var glProps = {
131
+ antialias: true,
132
+ preserveDrawingBuffer: true
133
+ };
134
+ /* eslint-enable no-shadow */
135
+
136
+ // Extract glParams and glProps
137
+ if (gl) {
138
+ Object.entries(gl).map(function (_ref2) {
139
+ var _ref3 = _slicedToArray(_ref2, 2),
140
+ key = _ref3[0],
141
+ value = _ref3[1];
142
+ if (glParameterKeys.includes(key)) {
143
+ glParameters[key] = value;
144
+ } else {
145
+ glProps[key] = value;
146
+ }
147
+ return null;
148
+ });
149
+ }
150
+ return {
151
+ glParameters: glParameters,
152
+ glProps: glProps
153
+ };
154
+ }, [gl]),
155
+ glParameters = _useMemo.glParameters,
156
+ glProps = _useMemo.glProps;
157
+
158
+ // ----- Background -----//
159
+ var backgroundProps = useMemo(function updateBackgroundProps() {
160
+ return {
161
+ backgroundColor: backgroundColor,
162
+ backgroundTextureURL: backgroundTextureURL,
163
+ backgroundEquirectangularTextureURL: backgroundEquirectangularTextureURL,
164
+ backgroundEquirectangularRGBEURL: backgroundEquirectangularRGBEURL
165
+ };
166
+ }, [backgroundColor, backgroundTextureURL, backgroundEquirectangularTextureURL, backgroundEquirectangularRGBEURL]);
167
+
168
+ // ----- Shadows -----//
169
+ var shadowProps = useMemo(function updateShadowProps() {
170
+ return {
171
+ shadowMapEnabled: shadowMapEnabled || true,
172
+ shadowType: shadowType || 'type'
173
+ };
174
+ }, [shadowMapEnabled, shadowType]);
175
+
176
+ // ----- Camera Controls ----- //
177
+ var cameraType = useMemo(function updateCameraType() {
178
+ return orthographic ? _constants.CAMERA_TYPES.ORTHOGRAPHIC : _constants.CAMERA_TYPES.PERSPECTIVE;
179
+ }, [orthographic]);
180
+ var controlsType = useMemo(function updateControlsType() {
181
+ if (orbitControls) {
182
+ return _constants.CONTROLS_TYPES.ORBIT_CONTROLS;
183
+ } else if (trackballControls) {
184
+ return _constants.CONTROLS_TYPES.TRACKBALL_CONTROLS;
185
+ } else if (mapControls) {
186
+ return _constants.CONTROLS_TYPES.MAP_CONTROLS;
187
+ }
188
+ return 'none';
189
+ }, [orbitControls, trackballControls, mapControls]);
190
+
191
+ // ----- Camera Props -----//
192
+ var _useMemo2 = useMemo(function updateCameraProps() {
193
+ /* eslint-disable no-shadow */
194
+ var _ref4 = camera || {},
195
+ _ref4$position = _ref4.position,
196
+ position = _ref4$position === void 0 ? [0, 0, 5] : _ref4$position,
197
+ _ref4$target = _ref4.target,
198
+ target = _ref4$target === void 0 ? [0, 0, 0] : _ref4$target,
199
+ _ref4$up = _ref4.up,
200
+ up = _ref4$up === void 0 ? _constants.DEFAULT_UP : _ref4$up,
201
+ _ref4$rotation = _ref4.rotation,
202
+ rotation = _ref4$rotation === void 0 ? undefined : _ref4$rotation,
203
+ _ref4$roll = _ref4.roll,
204
+ roll = _ref4$roll === void 0 ? 0 : _ref4$roll,
205
+ cameraProps = _objectWithoutProperties(_ref4, _excluded2);
206
+ var cameraExtrinsics = {
207
+ position: position,
208
+ target: target,
209
+ up: up,
210
+ rotation: rotation,
211
+ roll: roll
212
+ };
213
+ /* eslint-enable no-shadow */
214
+
215
+ return {
216
+ cameraExtrinsics: cameraExtrinsics,
217
+ cameraProps: cameraProps
218
+ };
219
+ }, [camera]),
220
+ cameraExtrinsics = _useMemo2.cameraExtrinsics,
221
+ cameraProps = _useMemo2.cameraProps;
222
+
223
+ // ----- Controls Props ----- //
224
+ var controlsProps = useMemo(function updateControlsProps() {
225
+ // Extract Angles of Rotation
226
+ var _controls$polarAngle = controls.polarAngle,
227
+ polarAngle = _controls$polarAngle === void 0 ? 0 : _controls$polarAngle,
228
+ _controls$azimuthAngl = controls.azimuthAngle,
229
+ azimuthAngle = _controls$azimuthAngl === void 0 ? 0 : _controls$azimuthAngl,
230
+ controlsProps = _objectWithoutProperties(controls, _excluded3);
231
+ controlsProps = controlsProps || {};
232
+
233
+ // Reconcile Control Props
234
+ if (controlsType !== 'none') {
235
+ (0, _util.reconcileSynonymousProps)(controlsProps, _constants.SYNONYMOUS_CONTROLS_PROPS, controlsType);
236
+ (0, _util.reconcileSynonymousProps)(controlsProps, _constants.ANTONYMOUS_CONTROLS_PROPS, controlsType, true);
237
+ }
238
+ (0, _util.reconcileSynonymousProps)(controlsProps, _constants.SYNONYMOUS_CAMERA_PROPS, cameraType);
239
+ return {
240
+ controlsType: controlsType,
241
+ polarAngle: polarAngle,
242
+ azimuthAngle: azimuthAngle,
243
+ cameraExtrinsics: cameraExtrinsics,
244
+ controlsProps: Object.keys(controlsProps).length > 0 ? controlsProps : undefined
245
+ };
246
+ }, [controlsType, cameraType, controls, cameraExtrinsics]);
247
+ var values = useRef([]);
248
+ /* eslint-disable react-hooks/exhaustive-deps */
249
+ var contextListeners = useMemo(function generateContextListeners() {
250
+ return (0, _ContextBridge.GenerateContextListeners)(_contexts, (values === null || values === void 0 ? void 0 : values.current) || []);
251
+ }, [_contexts]);
252
+ /* eslint-enable react-hooks/exhaustive-deps */
253
+
254
+ return /*#__PURE__*/React.createElement(React.Fragment, null, contextListeners, /*#__PURE__*/React.createElement(_fiber.Canvas, _extends({
255
+ camera: cameraProps,
256
+ orthographic: orthographic
257
+ // updateDefaultCamera={updateDefaultCamera}
258
+ // @ts-ignore:TS2559 no properties in common with Partial<WebGLRenderer>
259
+ ,
260
+ gl: glParameters
261
+ }, otherProps), /*#__PURE__*/React.createElement(SetCanvasProps, {
262
+ canvasProps: canvasProps
263
+ }), /*#__PURE__*/React.createElement(_ViewContext.ViewContextProvider, {
264
+ canvasProps: canvasProps
265
+ }, /*#__PURE__*/React.createElement(_ContextBridge.ContextBridge, {
266
+ contexts: _contexts,
267
+ values: values.current
268
+ }, /*#__PURE__*/React.createElement(_SetRenderer["default"], glProps), /*#__PURE__*/React.createElement(_SetBackground["default"], backgroundProps), /*#__PURE__*/React.createElement(_SetShadows["default"], shadowProps), /*#__PURE__*/React.createElement(_SetControls["default"], controlsProps), (mapControls || trackballControls || controls && controls.autoRotate) && /*#__PURE__*/React.createElement(_SetControls.UpdateControls, null), children))));
269
+ };
270
+ var View3DMemo = memo(View3D);
271
+ View3DMemo.displayName = 'View3D';
272
+ var _default = exports["default"] = View3DMemo;
273
+ /**
274
+ * SetCanvasProps
275
+ *
276
+ * Isolates the useThree hook to avoid larger components from
277
+ * re-rendering up to 3 times--this is a bug from @react-three/fiber.
278
+ * Any @react-three/fiber hook call incurs additional renders.
279
+ */
280
+ var SetCanvasProps = memo(/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
281
+ function SetCanvasProps(_ref5) {
282
+ var canvasProps = _ref5.canvasProps;
283
+ /* eslint-disable-next-line no-param-reassign */
284
+ canvasProps.current = (0, _fiber.useThree)();
285
+ return null;
286
+ }, function () {
287
+ return true;
288
+ });
289
+ SetCanvasProps.displayName = 'SetCanvasProps';
@@ -0,0 +1,23 @@
1
+ import * as React from "react";
2
+ export declare const ViewContext: React.Context<any>;
3
+ type ViewContextProviderProps = {
4
+ canvasProps: React.MutableRefObject<any>;
5
+ children?: any;
6
+ };
7
+ /**
8
+ * ViewContextProvider
9
+ *
10
+ * Placing <ViewContext.Provider value={canvasProps.current}>
11
+ * directly into the return statement of View3D does not wait for
12
+ * canvasProps to be set by SetCanvasProps, and instead the
13
+ * context value is set to null.
14
+ *
15
+ * Encapsulating <ViewContext.Provider> in a component delays the
16
+ * creation of the provider, hence delays setting value until
17
+ * after SetCanvasProps has been created.
18
+ *
19
+ * Cannot add ViewContext to contextListeners and apply in GenerateContexts
20
+ * because canvasProps do not exist at that time.
21
+ */
22
+ export declare const ViewContextProvider: React.NamedExoticComponent<ViewContextProviderProps>;
23
+ export {};
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.ViewContextProvider = exports.ViewContext = void 0;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
14
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
16
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
18
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
19
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
20
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } // ViewContext.tsx
21
+ var useState = React.useState,
22
+ createContext = React.createContext,
23
+ memo = React.memo;
24
+ /* eslint-disable-next-line @typescript-eslint/no-explicit-any */
25
+ var ViewContext = exports.ViewContext = createContext([]);
26
+ /**
27
+ * ViewContextProvider
28
+ *
29
+ * Placing <ViewContext.Provider value={canvasProps.current}>
30
+ * directly into the return statement of View3D does not wait for
31
+ * canvasProps to be set by SetCanvasProps, and instead the
32
+ * context value is set to null.
33
+ *
34
+ * Encapsulating <ViewContext.Provider> in a component delays the
35
+ * creation of the provider, hence delays setting value until
36
+ * after SetCanvasProps has been created.
37
+ *
38
+ * Cannot add ViewContext to contextListeners and apply in GenerateContexts
39
+ * because canvasProps do not exist at that time.
40
+ */
41
+ var ViewContextProvider = exports.ViewContextProvider = memo(function ViewContextProvider(_ref) {
42
+ var canvasProps = _ref.canvasProps,
43
+ children = _ref.children;
44
+ var _useState = useState(canvasProps.current),
45
+ _useState2 = _slicedToArray(_useState, 2),
46
+ viewContextValue = _useState2[0],
47
+ setViewContextValue = _useState2[1];
48
+ var value = _objectSpread({
49
+ setViewContextValue: setViewContextValue
50
+ }, viewContextValue);
51
+ return /*#__PURE__*/React.createElement(ViewContext.Provider, {
52
+ value: value
53
+ }, children);
54
+ });
55
+ ViewContextProvider.displayName = "ViewContextProvider";
@@ -0,0 +1,2 @@
1
+ export { default as View3D } from './View3D';
2
+ export { ViewContext } from './ViewContext';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "View3D", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _View3D["default"];
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "ViewContext", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _ViewContext.ViewContext;
16
+ }
17
+ });
18
+ var _View3D = _interopRequireDefault(require("./View3D"));
19
+ var _ViewContext = require("./ViewContext");
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
package/netlify.toml ADDED
@@ -0,0 +1,15 @@
1
+ [build.environment]
2
+ NODE_OPTIONS = "--openssl-legacy-provider"
3
+
4
+ [build]
5
+ # Directory to change to before starting a build.
6
+ # This is where we will look for package.json/.nvmrc/etc.
7
+ base = ""
8
+
9
+ # Directory (relative to root of your repo) that contains the deploy-ready
10
+ # HTML files and assets generated by the build. If a base directory has
11
+ # been specified, include it in the publish directory path.
12
+ publish = "./storybook-static/"
13
+
14
+ # Default build command.
15
+ command = "yarn test && yarn build-storybook"
package/package.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "name": "@ifiwas/standard-view",
3
+ "version": "2.0.0",
4
+ "description": "3D Graphics Library for React Apps",
5
+ "repository": "ifiwas/standard-view",
6
+ "license": "MIT",
7
+ "contributors": [
8
+ "If I Was (https://ifiwaslabs.com/)",
9
+ "Wasif Islam"
10
+ ],
11
+ "main": "./index.js",
12
+ "scripts": {
13
+ "build": "vite build && yarn build-babel && yarn build-tsc",
14
+ "build-dev": "vite build --mode development",
15
+ "dev": "vite",
16
+ "build-babel": "babel --extensions '.ts,.tsx,.js,.jsx' src/ -d lib/ --copy-files",
17
+ "build-storybook": "storybook build",
18
+ "build-tsc": "tsc",
19
+ "build-flow": "flow-copy-source src lib",
20
+ "flow": "flow",
21
+ "lint": "eslint --cache --format codeframe --ext ts,tsx,mjs,jsx,js src stories",
22
+ "lint-fix": "eslint --cache --format codeframe --ext mjs,jsx,js src stories --fix",
23
+ "format": "prettier --write \"src/**/*.{ts,tsx,js,jsx,json}\" \"stories/**/*.{ts,tsx,js,jsx,json}\"",
24
+ "format-check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,json}\" \"stories/**/*.{ts,tsx,js,jsx,json}\"",
25
+ "test": "jest",
26
+ "prepublish": "yarn build",
27
+ "storybook": "storybook dev -p 5001"
28
+ },
29
+ "keywords": [
30
+ "ifiwas",
31
+ "ifiwaslabs",
32
+ "ifiwas-standard-view",
33
+ "standard-view",
34
+ "standard-view-core",
35
+ "standard",
36
+ "view",
37
+ "core",
38
+ "@react-three/fiber",
39
+ "three",
40
+ "three.js",
41
+ "visualization",
42
+ "tool",
43
+ "package",
44
+ "3D",
45
+ "graphics"
46
+ ],
47
+ "devDependencies": {
48
+ "@babel/cli": "^7.5.5",
49
+ "@babel/core": "^7.5.5",
50
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
51
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
52
+ "@babel/plugin-transform-runtime": "^7.0.0",
53
+ "@babel/polyfill": "^7.4.4",
54
+ "@babel/preset-env": "^7.5.5",
55
+ "@babel/preset-react": "^7.0.0",
56
+ "@babel/preset-typescript": "^7.3.3",
57
+ "@emotion/core": "^11.0.0",
58
+ "@emotion/react": "^11.14.0",
59
+ "@emotion/styled": "^11.14.1",
60
+ "@react-three/drei": "^10.5.1",
61
+ "@react-three/fiber": "^9.2.0",
62
+ "@storybook/addon-docs": "9.0.16",
63
+ "@storybook/addon-links": "9.0.16",
64
+ "@storybook/cli": "^9.0.16",
65
+ "@storybook/react-vite": "9.0.16",
66
+ "@storybook/testing-library": "^0.2.2",
67
+ "@testing-library/jest-dom": "^6.0.0",
68
+ "@testing-library/react": "^16.3.0",
69
+ "@types/jest": "^30.0.0",
70
+ "@types/node": "^24.0.13",
71
+ "@types/react": "^19",
72
+ "@types/react-dom": "^19",
73
+ "@types/three": "^0.178.0",
74
+ "@typescript-eslint/eslint-plugin": "^8.37.0",
75
+ "@typescript-eslint/parser": "^8.37.0",
76
+ "@vitejs/plugin-react": "^4.0.0",
77
+ "assert": "^2.0.0",
78
+ "babel-eslint": "^10.0.1",
79
+ "babel-loader": "^10.0.0",
80
+ "eslint": "^9.31.0",
81
+ "eslint-config-airbnb": "^19.0.0",
82
+ "eslint-config-airbnb-typescript": "^18.0.0",
83
+ "eslint-config-prettier": "^10.1.5",
84
+ "eslint-import-resolver-typescript": "^4.4.4",
85
+ "eslint-plugin-import": "^2.29.0",
86
+ "eslint-plugin-jsx-a11y": "^6.8.0",
87
+ "eslint-plugin-prettier": "^5.0.0",
88
+ "eslint-plugin-react": "^7.33.0",
89
+ "eslint-plugin-react-hooks": "^5.2.0",
90
+ "eslint-plugin-storybook": "9.0.16",
91
+ "jest": "^30.0.4",
92
+ "jest-environment-jsdom": "^30.0.4",
93
+ "mousetrap": "^1.6.3",
94
+ "prettier": "^3.6.2",
95
+ "react": "^19.1.0",
96
+ "react-dom": "^19.1.0",
97
+ "storybook": "^9.0.16",
98
+ "three": "^0.178.0",
99
+ "ts-jest": "^29.0.0",
100
+ "tslib": "^2.6.0",
101
+ "typescript": "^5",
102
+ "vite": "^7.0.4",
103
+ "webpack": "^5.100.1"
104
+ },
105
+ "peerDependencies": {
106
+ "react": "^19",
107
+ "three": "^0.178.0"
108
+ },
109
+ "dependencies": {}
110
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowSyntheticDefaultImports": true,
4
+ "baseUrl": "src",
5
+ "paths": {},
6
+ "outDir": "lib",
7
+ "module": "esnext",
8
+ "target": "es5",
9
+ "lib": ["es6", "dom"],
10
+ "sourceMap": false,
11
+ // "allowJs": true,
12
+ "declaration": true,
13
+ "emitDeclarationOnly": true,
14
+ "moduleResolution": "node",
15
+ // "noEmit": true,
16
+ "strict": true,
17
+ // "isolatedModules": true,
18
+ "esModuleInterop": true,
19
+ "resolveJsonModule": true,
20
+ "rootDir": "src",
21
+ "forceConsistentCasingInFileNames": true,
22
+ "noImplicitReturns": true,
23
+ "noImplicitThis": false,
24
+ "noImplicitAny": false,
25
+ "importHelpers": true,
26
+ "strictNullChecks": true,
27
+ "noUnusedLocals": false,
28
+ "skipLibCheck": true,
29
+ "jsx": "react-jsx",
30
+
31
+ },
32
+ "include": ["src", "src/types"],
33
+ "exclude": [
34
+ "node_modules",
35
+ "build",
36
+ "scripts",
37
+ "acceptance-tests",
38
+ "webpack",
39
+ "jest",
40
+ "src/setupTests.ts"
41
+ ]
42
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "extends": "./tsconfig.json"
3
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "commonjs"
5
+ }
6
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,37 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import { resolve } from 'path';
4
+
5
+ export default defineConfig({
6
+ plugins: [react()],
7
+ build: {
8
+ lib: {
9
+ entry: resolve(__dirname, 'src/index.tsx'),
10
+ name: 'StandardView',
11
+ formats: ['es', 'umd'],
12
+ fileName: (format) => `standard-view.${format}.js`,
13
+ },
14
+ rollupOptions: {
15
+ external: ['react', 'react-dom', 'three', '@react-three/fiber'],
16
+ output: {
17
+ globals: {
18
+ react: 'React',
19
+ 'react-dom': 'ReactDOM',
20
+ three: 'THREE',
21
+ '@react-three/fiber': 'ReactThreeFiber',
22
+ },
23
+ },
24
+ },
25
+ sourcemap: true,
26
+ outDir: 'dist',
27
+ },
28
+ resolve: {
29
+ alias: {
30
+ '@': resolve(__dirname, 'src'),
31
+ },
32
+ },
33
+ server: {
34
+ port: 3000,
35
+ open: true,
36
+ },
37
+ });