@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,114 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.performanceEnd = performanceEnd;
7
+ exports.performanceLog = performanceLog;
8
+ exports.performanceStart = performanceStart;
9
+ // performance.tsx
10
+
11
+ /**
12
+ * Performance Check Timers
13
+ * Aggregates timers that execute multiple times with the same name.
14
+ * Handles multiple concurrent timers with different names.
15
+ * Cannot aggregate multiple concurrent timers with the same name.
16
+ *
17
+ * Usage:
18
+ * - Place performanceStart("timer name") at the beginning.
19
+ * - Place performanceEnd("timer name") at the end.
20
+ * - For multiple timers, names must be unique.
21
+ * - stopwatchMode allows for printing total performance time
22
+ * at each occurence of performanceEnd without having to
23
+ * create new performanceStart's. Default is false.
24
+ * - Place performanceLog("timer name") after recording with
25
+ * performanceStart and performanceEnd to print results.
26
+ */
27
+
28
+ var timers = {};
29
+ function performanceStart() {
30
+ var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "no name";
31
+ var stopwatchMode = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
32
+ // Timer Already Exists
33
+ if (timers[name]) {
34
+ var timer = timers[name];
35
+
36
+ // Timer Already Running
37
+ if (timer.running) {
38
+ console.warn("".concat(name, " is already running! Cannot start another timer with the same name."));
39
+ return;
40
+ }
41
+
42
+ // Start Timer
43
+ timer.running = true;
44
+ timer.start = performance.now();
45
+ return;
46
+ }
47
+
48
+ // New Timer
49
+ timers[name] = {
50
+ start: 0,
51
+ count: 0,
52
+ total: 0,
53
+ average: 0,
54
+ running: true,
55
+ stopwatchMode: stopwatchMode
56
+ };
57
+ timers[name].start = performance.now();
58
+ }
59
+ function performanceEnd() {
60
+ var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "no name";
61
+ var end = performance.now();
62
+
63
+ // Timer Never Started
64
+ if (timers[name] == null) {
65
+ console.warn("Timer ".concat(name, " does not exist. Make sure to place performanceStart(\"timer name\") before performanceEnd(\"timer name\")!"));
66
+ return;
67
+ }
68
+ var timer = timers[name];
69
+ if (!timer.running) {
70
+ console.warn("Timer ".concat(name, " not running. Make sure to place performanceStart(\"timer name\") before performanceEnd(\"timer name\")!"));
71
+ return;
72
+ }
73
+
74
+ // End Timer
75
+ var time = end - timer.start;
76
+ timer.count++;
77
+ timer.total += time;
78
+ timer.average = timer.total / timer.count;
79
+
80
+ // Stopwatch Mode
81
+ if (timer.stopwatchMode) {
82
+ /* eslint-disable-next-line no-console */
83
+ console.log("".concat(name, ": total ").concat(timer.total, ", average ").concat(timer.average, ", runs ").concat(timer.count));
84
+ timer.start = performance.now();
85
+ } else {
86
+ timer.running = false;
87
+ }
88
+ }
89
+ function performanceLog() {
90
+ var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "no name";
91
+ var print = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
92
+ // Timer Never Recorded
93
+ if (timers[name] == null) {
94
+ console.warn("Timer ".concat(name, " never recorded. Make sure to place performanceStart(\"timer name\") and performanceEnd(\"timer name\") before performanceLog(\"timer name\")!"));
95
+ return {
96
+ average: 0,
97
+ total: 0,
98
+ count: 0
99
+ };
100
+ }
101
+ var _timers$name = timers[name],
102
+ count = _timers$name.count,
103
+ total = _timers$name.total,
104
+ average = _timers$name.average;
105
+ if (print) {
106
+ /* eslint-disable-next-line no-console */
107
+ console.log("\x1B[36m ".concat(name, "\t \x1B[33m average: ").concat(average, "\t \x1B[31m total: ").concat(total, "\t \x1B[92m count: ").concat(count));
108
+ }
109
+ return {
110
+ average: average,
111
+ total: total,
112
+ count: count
113
+ };
114
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DEFAULT_HIGHLIGHT_COLOR = exports.DEFAULT_COLOR = void 0;
7
+ // styles.js
8
+
9
+ var DEFAULT_COLOR = exports.DEFAULT_COLOR = "gray";
10
+ var DEFAULT_HIGHLIGHT_COLOR = exports.DEFAULT_HIGHLIGHT_COLOR = "yellow";
@@ -0,0 +1,76 @@
1
+ import * as THREE from 'three';
2
+ /**
3
+ * getAlignmentOffset
4
+ *
5
+ * Given an old anchor position and new anchor position as strings,
6
+ * for example, oldAnchor: "right" and newAnchor: "center",
7
+ * and also optional current position, diagonal, and scale,
8
+ * getAlignmentOffset will provide the new position.
9
+ *
10
+ * diagonal is the displacement between the boundingBox.min
11
+ * and boundingBox.max or any other displacement between
12
+ * the min and max corners. This is necessary for Labels and Text,
13
+ * where the fundamental geometry is not to unit scale of [1, 1, 1].
14
+ *
15
+ * In general, it is better to apply getAlignmentOffset on
16
+ * unit geometry before scaling.
17
+ */
18
+ export declare function getAlignmentOffset(oldAnchor: string, newAnchor: string, diagonal?: Array<number>): Array<number>;
19
+ /**
20
+ * reconcileSynonymousProps
21
+ *
22
+ * Given the correct type, synonymous prop key value pairs are removed.
23
+ * If correctly named prop does not exist, value is extracted from
24
+ * synonymous props and assigned to the correctly named prop, then
25
+ * synonymous props are removed.
26
+ *
27
+ * This functions mutates props!
28
+ */
29
+ export declare function reconcileSynonymousProps(props: any, synonymousProps: Record<string, string>[], correctType: string, opposite?: boolean): void;
30
+ export declare function areArraysEqual(array1: any, array2: any): boolean;
31
+ /**
32
+ * FPS
33
+ */
34
+ export declare const FPS: import("react").NamedExoticComponent<object>;
35
+ /**
36
+ * RGBStringToNumber
37
+ */
38
+ export declare function RGBStringToNumber(rgbString: any): {
39
+ r: number;
40
+ g: number;
41
+ b: number;
42
+ };
43
+ /**
44
+ * numberToRGBString
45
+ */
46
+ export declare function numberToRGBString(r: any, g: any, b: any): string;
47
+ /**
48
+ * objectToArray
49
+ * returns obj if already an array
50
+ * default is [0, 0, 0]
51
+ * default is array of all zeros for custom order with more than 3 components
52
+ */
53
+ export declare function objectToArray(obj: any, order?: string): Array<number>;
54
+ /**
55
+ * arrayToObject
56
+ * returns array if already an object with fields x, y, and z
57
+ * default is { x: 0, y: 0, z: 0 }
58
+ * default is an object with all zero value components for custom order
59
+ */
60
+ export declare function arrayToObject(array: any, order?: string): any;
61
+ /**
62
+ * arrayToQuaternion
63
+ * return THREE.Quaternion if already THREE.Quaternion
64
+ */
65
+ export declare function toQuaternion(obj: any, order?: string): THREE.Quaternion;
66
+ /**
67
+ * filterArrayLength
68
+ */
69
+ export declare function filterArrayLength(array: any, length?: number, defaultArray?: number[]): Array<number> | undefined;
70
+ /**
71
+ * billboard
72
+ */
73
+ export declare function billboard({ mesh, camera }: {
74
+ mesh: any;
75
+ camera: any;
76
+ }): void;
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.FPS = void 0;
7
+ exports.RGBStringToNumber = RGBStringToNumber;
8
+ exports.areArraysEqual = areArraysEqual;
9
+ exports.arrayToObject = arrayToObject;
10
+ exports.billboard = billboard;
11
+ exports.filterArrayLength = filterArrayLength;
12
+ exports.getAlignmentOffset = getAlignmentOffset;
13
+ exports.numberToRGBString = numberToRGBString;
14
+ exports.objectToArray = objectToArray;
15
+ exports.reconcileSynonymousProps = reconcileSynonymousProps;
16
+ exports.toQuaternion = toQuaternion;
17
+ var THREE = _interopRequireWildcard(require("three"));
18
+ var _react = require("react");
19
+ var _drei = require("@react-three/drei");
20
+ var _constants = require("./constants");
21
+ 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); }
22
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
23
+ 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."); }
24
+ 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; } }
25
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
26
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
27
+ 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); }
28
+ function _construct(t, e, r) { if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments); var o = [null]; o.push.apply(o, e); var p = new (t.bind.apply(t, o))(); return r && _setPrototypeOf(p, r.prototype), p; }
29
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
30
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
31
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
32
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
33
+ 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; } }
34
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
35
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
36
+ 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; } // util.ts
37
+ /**
38
+ * getAlignmentOffset
39
+ *
40
+ * Given an old anchor position and new anchor position as strings,
41
+ * for example, oldAnchor: "right" and newAnchor: "center",
42
+ * and also optional current position, diagonal, and scale,
43
+ * getAlignmentOffset will provide the new position.
44
+ *
45
+ * diagonal is the displacement between the boundingBox.min
46
+ * and boundingBox.max or any other displacement between
47
+ * the min and max corners. This is necessary for Labels and Text,
48
+ * where the fundamental geometry is not to unit scale of [1, 1, 1].
49
+ *
50
+ * In general, it is better to apply getAlignmentOffset on
51
+ * unit geometry before scaling.
52
+ */
53
+ function getAlignmentOffset(oldAnchor, newAnchor) {
54
+ var diagonal = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [1, 1, 1];
55
+ var posVec = new THREE.Vector3();
56
+ diagonal.map(function (val, index) {
57
+ /* eslint-disable-next-line no-param-reassign */
58
+ diagonal[index] = Math.abs(val);
59
+ return null;
60
+ });
61
+ var diagonalVec = _construct(THREE.Vector3, _toConsumableArray(diagonal));
62
+ var oldAnchorVec = _constants.ANCHORS[_constants.ANCHOR_SYNONYMS[oldAnchor]];
63
+ var newAnchorVec = _constants.ANCHORS[_constants.ANCHOR_SYNONYMS[newAnchor]];
64
+ var offset = oldAnchorVec.clone().sub(newAnchorVec);
65
+ posVec.add(offset.multiply(diagonalVec));
66
+ return [posVec.x, posVec.y, posVec.z];
67
+ }
68
+
69
+ /**
70
+ * reconcileSynonymousProps
71
+ *
72
+ * Given the correct type, synonymous prop key value pairs are removed.
73
+ * If correctly named prop does not exist, value is extracted from
74
+ * synonymous props and assigned to the correctly named prop, then
75
+ * synonymous props are removed.
76
+ *
77
+ * This functions mutates props!
78
+ */
79
+ function reconcileSynonymousProps(/* eslint-disable @typescript-eslint/no-explicit-any */
80
+ props, synonymousProps, /* eslint-enable @typescript-eslint/no-explicit-any */
81
+ correctType) {
82
+ var opposite = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
83
+ // Ensure props is an object
84
+ if (!props || _typeof(props) !== 'object') {
85
+ return;
86
+ }
87
+ synonymousProps.map(function (propNames) {
88
+ var correctName = propNames[correctType];
89
+ var synnonyms = Object.values(propNames).filter(function (name) {
90
+ return name !== correctName;
91
+ });
92
+
93
+ // Assign Synnonymous Prop
94
+ if (props[correctName] == null) {
95
+ /* eslint-disable no-restricted-syntax */
96
+ // loop
97
+ var _iterator = _createForOfIteratorHelper(synnonyms),
98
+ _step;
99
+ try {
100
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
101
+ var synnonym = _step.value;
102
+ if (props[synnonym] != null) {
103
+ /* eslint-disable-next-line no-param-reassign */
104
+ props[correctName] = opposite ? !props[synnonym] : props[synnonym];
105
+ break;
106
+ }
107
+ }
108
+ /* eslint-enable no-restricted-syntax */
109
+ } catch (err) {
110
+ _iterator.e(err);
111
+ } finally {
112
+ _iterator.f();
113
+ }
114
+ }
115
+ // Delete Synnonymous Props
116
+ /* eslint-disable no-restricted-syntax */
117
+ var _iterator2 = _createForOfIteratorHelper(synnonyms),
118
+ _step2;
119
+ try {
120
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
121
+ var _synnonym = _step2.value;
122
+ /* eslint-disable-next-line no-param-reassign */
123
+ delete props[_synnonym];
124
+ }
125
+ /* eslint-enable no-restricted-syntax */
126
+ } catch (err) {
127
+ _iterator2.e(err);
128
+ } finally {
129
+ _iterator2.f();
130
+ }
131
+ return null;
132
+ });
133
+ }
134
+ function areArraysEqual(array1, array2) {
135
+ return Array.isArray(array1) && Array.isArray(array2) && array1.length === array2.length && array1[0] === array2[0] && array1[1] === array2[1] && array1[2] === array2[2];
136
+ }
137
+
138
+ /**
139
+ * FPS
140
+ */
141
+ var FPS = exports.FPS = /*#__PURE__*/(0, _react.memo)(function FPS() {
142
+ return /*#__PURE__*/React.createElement(_drei.Stats, {
143
+ showPanel: 0,
144
+ className: "fps-stats"
145
+ });
146
+ });
147
+ FPS.displayName = 'FPS';
148
+
149
+ /**
150
+ * RGBStringToNumber
151
+ */
152
+ function RGBStringToNumber(rgbString) {
153
+ var _rgbString$split = rgbString.split(/[,()]/),
154
+ _rgbString$split2 = _slicedToArray(_rgbString$split, 4),
155
+ r = _rgbString$split2[1],
156
+ g = _rgbString$split2[2],
157
+ b = _rgbString$split2[3];
158
+ r = parseInt(r, 10);
159
+ g = parseInt(g, 10);
160
+ b = parseInt(b, 10);
161
+ return {
162
+ r: r,
163
+ g: g,
164
+ b: b
165
+ };
166
+ }
167
+
168
+ /**
169
+ * numberToRGBString
170
+ */
171
+ function numberToRGBString(r, g, b) {
172
+ return "RGB(".concat(r, ", ").concat(g, ", ").concat(b, ")");
173
+ }
174
+
175
+ /**
176
+ * objectToArray
177
+ * returns obj if already an array
178
+ * default is [0, 0, 0]
179
+ * default is array of all zeros for custom order with more than 3 components
180
+ */
181
+ function objectToArray(obj) {
182
+ var order = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'xyz';
183
+ // Object is an Array
184
+ if (Array.isArray(obj)) {
185
+ return obj;
186
+ }
187
+
188
+ // Convert object to array of numbers
189
+ var array = [];
190
+ /* eslint-disable no-restricted-syntax */
191
+ var _iterator3 = _createForOfIteratorHelper(order.split('')),
192
+ _step3;
193
+ try {
194
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
195
+ var component = _step3.value;
196
+ // Object with any missing components yields default
197
+ if (Number.isNaN(obj[component])) {
198
+ return Array(order.length).fill(0);
199
+ }
200
+ array.push(obj[component]);
201
+ }
202
+ /* eslint-enable no-restricted-syntax */
203
+ } catch (err) {
204
+ _iterator3.e(err);
205
+ } finally {
206
+ _iterator3.f();
207
+ }
208
+ return array;
209
+ }
210
+
211
+ /**
212
+ * arrayToObject
213
+ * returns array if already an object with fields x, y, and z
214
+ * default is { x: 0, y: 0, z: 0 }
215
+ * default is an object with all zero value components for custom order
216
+ */
217
+ /* eslint-disable @typescript-eslint/no-explicit-any */
218
+ function arrayToObject(array) {
219
+ var order = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'xyz';
220
+ var obj = {};
221
+ /* eslint-enable @typescript-eslint/no-explicit-any */
222
+
223
+ // Not an Array or does not have enough elements
224
+ if (!Array.isArray(array) || array.length < order.length) {
225
+ order.split('').map(function (component) {
226
+ obj[component] = 0;
227
+ return null;
228
+ });
229
+ return obj;
230
+ }
231
+
232
+ // Convert array to object
233
+ order.split('').map(function (component, index) {
234
+ obj[component] = array[index];
235
+ return null;
236
+ });
237
+ return obj;
238
+ }
239
+
240
+ /**
241
+ * arrayToQuaternion
242
+ * return THREE.Quaternion if already THREE.Quaternion
243
+ */
244
+ function toQuaternion(obj) {
245
+ var order = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'xyzw';
246
+ var quaternion = {
247
+ x: 0,
248
+ y: 0,
249
+ z: 0,
250
+ w: 1
251
+ };
252
+ if (Array.isArray(obj) && obj.length === 4) {
253
+ // Array
254
+ order.split('').map(function (component, i) {
255
+ quaternion[component] = obj[i];
256
+ return null;
257
+ });
258
+ } else {
259
+ // Object
260
+ order.split('').map(function (component) {
261
+ if (obj[component] == null) {
262
+ console.warn("[toQuaternion] argument does not have component: ".concat(component, ". Default Quaternion(0, 0, 0, 1) returned."));
263
+ return new THREE.Quaternion();
264
+ }
265
+ quaternion[component] = obj[component];
266
+ return null;
267
+ });
268
+ }
269
+ return new THREE.Quaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
270
+ }
271
+
272
+ /**
273
+ * filterArrayLength
274
+ */
275
+ function filterArrayLength(array) {
276
+ var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3;
277
+ var defaultArray = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [0, 0, 0];
278
+ return Array.isArray(array) && array.length === length ? array : defaultArray;
279
+ }
280
+
281
+ /**
282
+ * billboard
283
+ */
284
+ function billboard(_ref) {
285
+ var mesh = _ref.mesh,
286
+ camera = _ref.camera;
287
+ mesh.current.lookAt(camera.position);
288
+ /* eslint-disable-next-line no-param-reassign */
289
+ mesh.current.up = camera.up;
290
+ }
@@ -0,0 +1,23 @@
1
+ import * as React from "react";
2
+ /**
3
+ * GeneraterContextListeners
4
+ *
5
+ * Create a ContextListener for each context in the given contexts array.
6
+ * Each ContextListener must be a outside the @react-three/fiber's Canvas
7
+ * component to detect the context values ContextListener and changes
8
+ * the value in the values array.
9
+ * the useContext hook in each ContextListener.
10
+ * This allows the context changes to be captured and passed into the
11
+ * ContextBridge.
12
+ */
13
+ export declare function GenerateContextListeners(contexts: Array<React.Context<any>>, values: Array<any>): Array<React.ReactNode>;
14
+ type ContextBridgeProps = {
15
+ contexts?: Array<React.Context<any>>;
16
+ values?: Array<any>;
17
+ children?: any;
18
+ };
19
+ /**
20
+ * ContextBridge
21
+ */
22
+ export declare const ContextBridge: React.NamedExoticComponent<ContextBridgeProps>;
23
+ export {};
@@ -0,0 +1,98 @@
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.ContextBridge = void 0;
8
+ exports.GenerateContextListeners = GenerateContextListeners;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _fiber = require("@react-three/fiber");
11
+ 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); }
12
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
13
+ 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."); }
14
+ 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; } }
15
+ 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; }
16
+ 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; } }
17
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } // ContextBridge.tsx
18
+ var useState = React.useState,
19
+ useContext = React.useContext,
20
+ memo = React.memo;
21
+ /**
22
+ * ContextListener
23
+ */
24
+ function ContextListener(_ref) {
25
+ var context = _ref.context,
26
+ values = _ref.values,
27
+ index = _ref.index;
28
+ // Safety checks
29
+ if (!context || !values || !Array.isArray(values) || typeof index !== 'number') {
30
+ return null;
31
+ }
32
+
33
+ /* eslint-disable no-param-reassign */
34
+ values[index] = useContext(context);
35
+ /* eslint-enable no-param-reassign */
36
+ return null;
37
+ }
38
+
39
+ /**
40
+ * GeneraterContextListeners
41
+ *
42
+ * Create a ContextListener for each context in the given contexts array.
43
+ * Each ContextListener must be a outside the @react-three/fiber's Canvas
44
+ * component to detect the context values ContextListener and changes
45
+ * the value in the values array.
46
+ * the useContext hook in each ContextListener.
47
+ * This allows the context changes to be captured and passed into the
48
+ * ContextBridge.
49
+ */
50
+ function GenerateContextListeners(/* eslint-disable @typescript-eslint/no-explicit-any */
51
+ contexts, values) {
52
+ // Safety checks
53
+ if (!contexts || !Array.isArray(contexts) || !values || !Array.isArray(values)) {
54
+ return [];
55
+ }
56
+
57
+ /* eslint-disable react/no-array-index-key */
58
+ var contextListeners = contexts.map(/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
59
+ function (context, index) {
60
+ return /*#__PURE__*/React.createElement(ContextListener, {
61
+ context: context,
62
+ values: values,
63
+ index: index,
64
+ key: index
65
+ });
66
+ });
67
+ /* eslint-enable react/no-array-index-key */
68
+ return contextListeners;
69
+ }
70
+ /**
71
+ * ContextBridge
72
+ */
73
+ var ContextBridge = exports.ContextBridge = memo(function ContextBridge(_ref2) {
74
+ var contexts = _ref2.contexts,
75
+ values = _ref2.values,
76
+ children = _ref2.children;
77
+ var _useState = useState(0),
78
+ _useState2 = _slicedToArray(_useState, 2),
79
+ update = _useState2[1];
80
+ // Context Updater
81
+ // Always trigger a rerender here and trust that
82
+ // Context.Provider will only rerender when value
83
+ // has changed
84
+ (0, _fiber.useFrame)(function () {
85
+ return update(function (prev) {
86
+ return prev + 1;
87
+ });
88
+ });
89
+ if (!contexts || !values) {
90
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
91
+ }
92
+ return contexts.reduce(function (child, Context, index) {
93
+ return /*#__PURE__*/React.createElement(Context.Provider, {
94
+ value: values[index]
95
+ }, child);
96
+ }, children);
97
+ });
98
+ ContextBridge.displayName = "ContextBridge";
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ interface SceneCameraProps {
3
+ camera?: any;
4
+ orthographic?: boolean;
5
+ }
6
+ declare const SceneCameraMemo: React.NamedExoticComponent<SceneCameraProps>;
7
+ export default SceneCameraMemo;
@@ -0,0 +1,52 @@
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 _drei = require("@react-three/drei");
10
+ 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); }
11
+ 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); } // SetControls.tsx
12
+ var useEffect = React.useEffect,
13
+ useState = React.useState,
14
+ useMemo = React.useMemo,
15
+ memo = React.memo;
16
+ /**
17
+ * SceneCamera
18
+ *
19
+ * @param {SceneCameraProps} props
20
+ */
21
+ var SceneCamera = function SceneCamera(_ref) {
22
+ var camera = _ref.camera,
23
+ orthographic = _ref.orthographic;
24
+ var useCustomCamera = useMemo(function updateUpdateDefaultCamera() {
25
+ // No Camera Props
26
+ if (camera == null) {
27
+ return true;
28
+ }
29
+ if (camera.updateDefaultCamera != null) {
30
+ return camera.updateDefaultCamera;
31
+ } else if (
32
+ // Fixed orthographic left, right, top, bottom
33
+ orthographic && (camera.left != null || camera.right != null || camera.top != null || camera.bottom != null)) {
34
+ return false;
35
+ } else if (!orthographic && camera.aspect != null) {
36
+ // Fixed aspect
37
+ return false;
38
+ } else {
39
+ return true;
40
+ }
41
+ }, [camera, orthographic]);
42
+ return /*#__PURE__*/React.createElement(React.Fragment, null, useCustomCamera && orthographic ? /*#__PURE__*/React.createElement(React.Fragment, null, "Orthographics", /*#__PURE__*/React.createElement(_drei.OrthographicCamera, _extends({
43
+ makeDefault: true,
44
+ position: camera.position
45
+ }, camera))) : /*#__PURE__*/React.createElement(React.Fragment, null, "Perspective", /*#__PURE__*/React.createElement(_drei.PerspectiveCamera, _extends({
46
+ makeDefault: true,
47
+ position: camera.position
48
+ }, camera))));
49
+ };
50
+ var SceneCameraMemo = memo(SceneCamera);
51
+ SceneCameraMemo.displayName = 'SceneCamera';
52
+ var _default = exports["default"] = SceneCameraMemo;