@threekit-tools/treble 0.0.87 → 0.0.89-next-001

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 (145) hide show
  1. package/dist/Treble/Treble.d.ts +2 -5
  2. package/dist/Treble/Treble.js +1 -7
  3. package/dist/components/AttributeValue/index.js +2 -0
  4. package/dist/components/Wishlist/index.d.ts +1 -1
  5. package/dist/components/Zoom/index.d.ts +1 -1
  6. package/dist/components/containers/formInputContainer.d.ts +1 -1
  7. package/dist/connection.d.ts +4 -0
  8. package/dist/connection.js +3 -0
  9. package/dist/hooks/useProductCache/index.d.ts +2 -1
  10. package/dist/hooks/useProductCache/index.js +43 -1
  11. package/dist/hooks/useResetProduct/index.d.ts +3 -0
  12. package/dist/hooks/useResetProduct/index.js +55 -0
  13. package/dist/hooks/useRoomBuilder/RoomBuilderState.d.ts +93 -0
  14. package/dist/hooks/useRoomBuilder/RoomBuilderState.js +1207 -0
  15. package/dist/hooks/useRoomBuilder/constants.d.ts +33 -0
  16. package/dist/hooks/useRoomBuilder/constants.js +40 -0
  17. package/dist/hooks/useRoomBuilder/dataHandlers.d.ts +15 -0
  18. package/dist/hooks/useRoomBuilder/dataHandlers.js +177 -0
  19. package/dist/hooks/useRoomBuilder/draw.d.ts +55 -0
  20. package/dist/hooks/useRoomBuilder/draw.js +551 -0
  21. package/dist/hooks/useRoomBuilder/geometry.d.ts +43 -0
  22. package/dist/hooks/useRoomBuilder/geometry.js +462 -0
  23. package/dist/hooks/useRoomBuilder/index.d.ts +40 -0
  24. package/dist/hooks/useRoomBuilder/index.js +299 -0
  25. package/dist/hooks/useRoomBuilder/messaging.d.ts +8 -0
  26. package/dist/hooks/useRoomBuilder/messaging.js +13 -0
  27. package/dist/hooks/useRoomBuilder/themes.d.ts +12 -0
  28. package/dist/hooks/useRoomBuilder/themes.js +270 -0
  29. package/dist/hooks/useRoomBuilder/types.d.ts +232 -0
  30. package/dist/hooks/useRoomBuilder/types.js +36 -0
  31. package/dist/hooks/useRoomBuilder/validators.d.ts +36 -0
  32. package/dist/hooks/useRoomBuilder/validators.js +362 -0
  33. package/dist/http/request.js +4 -1
  34. package/dist/icons/Add.d.ts +1 -1
  35. package/dist/icons/Add.js +3 -3
  36. package/dist/icons/Angle.d.ts +3 -0
  37. package/dist/icons/Angle.js +21 -0
  38. package/dist/icons/ArrowLeft.d.ts +1 -1
  39. package/dist/icons/ArrowLeft.js +3 -3
  40. package/dist/icons/ArrowRight.d.ts +1 -1
  41. package/dist/icons/ArrowRight.js +3 -3
  42. package/dist/icons/Camera.d.ts +1 -1
  43. package/dist/icons/Camera.js +3 -3
  44. package/dist/icons/CaretDown.d.ts +1 -1
  45. package/dist/icons/CaretDown.js +3 -3
  46. package/dist/icons/CaretLeft.d.ts +1 -1
  47. package/dist/icons/CaretLeft.js +3 -3
  48. package/dist/icons/CaretRight.d.ts +1 -1
  49. package/dist/icons/CaretRight.js +3 -3
  50. package/dist/icons/CaretUp.d.ts +1 -1
  51. package/dist/icons/CaretUp.js +3 -3
  52. package/dist/icons/Cart.d.ts +1 -1
  53. package/dist/icons/Cart.js +3 -3
  54. package/dist/icons/Checkmate.d.ts +1 -1
  55. package/dist/icons/Checkmate.js +3 -3
  56. package/dist/icons/Clipboard.d.ts +1 -1
  57. package/dist/icons/Clipboard.js +3 -3
  58. package/dist/icons/ColorPicker.d.ts +1 -1
  59. package/dist/icons/ColorPicker.js +3 -3
  60. package/dist/icons/Copy.d.ts +1 -1
  61. package/dist/icons/Copy.js +3 -3
  62. package/dist/icons/Cursor.d.ts +3 -0
  63. package/dist/icons/Cursor.js +21 -0
  64. package/dist/icons/Delete.d.ts +1 -1
  65. package/dist/icons/Delete.js +3 -3
  66. package/dist/icons/Door.d.ts +3 -0
  67. package/dist/icons/Door.js +22 -0
  68. package/dist/icons/DoubleCaretLeft.d.ts +1 -1
  69. package/dist/icons/DoubleCaretLeft.js +3 -3
  70. package/dist/icons/DoubleCaretRight.d.ts +1 -1
  71. package/dist/icons/DoubleCaretRight.js +3 -3
  72. package/dist/icons/Download.d.ts +1 -1
  73. package/dist/icons/Download.js +3 -3
  74. package/dist/icons/Drag.d.ts +1 -1
  75. package/dist/icons/Drag.js +3 -3
  76. package/dist/icons/Draggable.d.ts +1 -1
  77. package/dist/icons/Draggable.js +3 -3
  78. package/dist/icons/Edit.d.ts +1 -1
  79. package/dist/icons/Edit.js +3 -3
  80. package/dist/icons/Heart.d.ts +1 -1
  81. package/dist/icons/Heart.js +3 -3
  82. package/dist/icons/Image.d.ts +1 -1
  83. package/dist/icons/Image.js +3 -3
  84. package/dist/icons/Info.d.ts +1 -1
  85. package/dist/icons/Info.js +3 -3
  86. package/dist/icons/Layout.d.ts +3 -0
  87. package/dist/icons/Layout.js +21 -0
  88. package/dist/icons/Mail.d.ts +1 -1
  89. package/dist/icons/Mail.js +3 -3
  90. package/dist/icons/Menu.d.ts +1 -1
  91. package/dist/icons/Menu.js +3 -3
  92. package/dist/icons/More.d.ts +1 -1
  93. package/dist/icons/More.js +3 -3
  94. package/dist/icons/NewWindow.d.ts +1 -1
  95. package/dist/icons/NewWindow.js +3 -3
  96. package/dist/icons/Opening.d.ts +3 -0
  97. package/dist/icons/Opening.js +21 -0
  98. package/dist/icons/Pause.d.ts +1 -1
  99. package/dist/icons/Pause.js +3 -3
  100. package/dist/icons/Play.d.ts +1 -1
  101. package/dist/icons/Play.js +3 -3
  102. package/dist/icons/Redo.d.ts +1 -1
  103. package/dist/icons/Redo.js +3 -3
  104. package/dist/icons/Remove.d.ts +1 -1
  105. package/dist/icons/Remove.js +3 -3
  106. package/dist/icons/Ruler.d.ts +1 -1
  107. package/dist/icons/Ruler.js +3 -3
  108. package/dist/icons/Search.d.ts +1 -1
  109. package/dist/icons/Search.js +3 -3
  110. package/dist/icons/Settings.d.ts +1 -1
  111. package/dist/icons/Settings.js +3 -3
  112. package/dist/icons/Share.d.ts +1 -1
  113. package/dist/icons/Share.js +3 -3
  114. package/dist/icons/Switch.d.ts +1 -1
  115. package/dist/icons/Switch.js +3 -3
  116. package/dist/icons/Tag.d.ts +1 -1
  117. package/dist/icons/Tag.js +3 -3
  118. package/dist/icons/TrashCan.d.ts +3 -0
  119. package/dist/icons/TrashCan.js +21 -0
  120. package/dist/icons/TrashCanAlt.d.ts +3 -0
  121. package/dist/icons/TrashCanAlt.js +21 -0
  122. package/dist/icons/Undo.d.ts +1 -1
  123. package/dist/icons/Undo.js +3 -3
  124. package/dist/icons/Wall.d.ts +3 -0
  125. package/dist/icons/Wall.js +21 -0
  126. package/dist/icons/Window.d.ts +3 -0
  127. package/dist/icons/Window.js +22 -0
  128. package/dist/icons/Wishlist.d.ts +1 -1
  129. package/dist/icons/Wishlist.js +3 -3
  130. package/dist/icons/ZoomIn.d.ts +1 -1
  131. package/dist/icons/ZoomIn.js +3 -3
  132. package/dist/icons/ZoomOut.d.ts +1 -1
  133. package/dist/icons/ZoomOut.js +3 -3
  134. package/dist/icons/index.d.ts +2 -6
  135. package/dist/icons/index.js +18 -0
  136. package/dist/icons/types.d.ts +7 -0
  137. package/dist/icons/types.js +2 -0
  138. package/dist/index.d.ts +11 -1
  139. package/dist/index.js +23 -2
  140. package/dist/store/product.d.ts +5 -4
  141. package/dist/store/product.js +43 -26
  142. package/dist/store/treble.js +6 -3
  143. package/dist/types.d.ts +47 -7
  144. package/dist/types.js +1 -0
  145. package/package.json +1 -1
@@ -0,0 +1,462 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.findClosedPaths = exports.getClosestPointOnCircumference = exports.getDistanceFromCircumference = exports.doLinesOverlap = exports.getAllLineIntersections = exports.doeslineSegmentIntersectQuadrilateral = exports.getTangetIntersectionAndOffset = exports.getTangentIntersection = exports.findAllIntersectionPoints = exports.orderCoordinatesOnLineSegment = exports.splitLineAtOffset = exports.splitLineAtPoints = exports.splitLineAtPoint = exports.getLineSegmentsIntersection = exports.getLineIntersection = exports.isPointInPolygon = exports.isPointInQuadrilateral = exports.arePointsWithinProximity = exports.addThicknessToLine = exports.getParallelLineSegmentAtDistance = exports.getTriangleArea = exports.getQuadrilateralArea = exports.getAngleBetweenLines = exports.closestPointOnLine = exports.getDistanceToLine = exports.getLineMidpoint = exports.getLineAtOffsetOnLineSegment = exports.getPointAtOffsetOnLineSegment = exports.getAngleOfLineSegment = exports.getMidpointOfLineSegment = exports.getLengthOfLineSegment = exports.areLinesEqual = exports.arePointsEqual = void 0;
13
+ function arePointsEqual(point1, point2) {
14
+ if (!point1 || !point2)
15
+ return false;
16
+ return point1[0] === point2[0] && point1[1] === point2[1];
17
+ }
18
+ exports.arePointsEqual = arePointsEqual;
19
+ function areLinesEqual(line1, line2) {
20
+ if (!line1 || !line2)
21
+ return false;
22
+ if ((arePointsEqual(line1[0], line2[0]) &&
23
+ arePointsEqual(line1[1], line2[1])) ||
24
+ (arePointsEqual(line1[0], line2[1]) && arePointsEqual(line1[1], line2[0]))) {
25
+ return true;
26
+ }
27
+ return false;
28
+ }
29
+ exports.areLinesEqual = areLinesEqual;
30
+ function getLengthOfLineSegment(line) {
31
+ var _a = line.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
32
+ return Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
33
+ }
34
+ exports.getLengthOfLineSegment = getLengthOfLineSegment;
35
+ function getMidpointOfLineSegment(line) {
36
+ var _a = line.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
37
+ var xMidpoint = (x1 + x2) / 2;
38
+ var yMidpoint = (y1 + y2) / 2;
39
+ return [Math.round(xMidpoint), Math.round(yMidpoint)];
40
+ }
41
+ exports.getMidpointOfLineSegment = getMidpointOfLineSegment;
42
+ function getAngleOfLineSegment(line) {
43
+ var _a = line.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
44
+ return Math.atan2(y2 - y1, x2 - x1);
45
+ }
46
+ exports.getAngleOfLineSegment = getAngleOfLineSegment;
47
+ function getPointAtOffsetOnLineSegment(line, offset) {
48
+ var _a = line.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
49
+ var d = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
50
+ var r = offset / d;
51
+ var x = x1 + r * (x2 - x1);
52
+ var y = y1 + r * (y2 - y1);
53
+ return [x, y];
54
+ }
55
+ exports.getPointAtOffsetOnLineSegment = getPointAtOffsetOnLineSegment;
56
+ function getLineAtOffsetOnLineSegment(line, offset, length) {
57
+ var _a = line.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
58
+ var d = Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
59
+ var startRatio = offset / d;
60
+ var endRatio = (offset + length) / d;
61
+ var startX = x1 + startRatio * (x2 - x1);
62
+ var startY = y1 + startRatio * (y2 - y1);
63
+ var endX = x1 + endRatio * (x2 - x1);
64
+ var endY = y1 + endRatio * (y2 - y1);
65
+ return [
66
+ [startX, startY],
67
+ [endX, endY],
68
+ ];
69
+ }
70
+ exports.getLineAtOffsetOnLineSegment = getLineAtOffsetOnLineSegment;
71
+ function getLineMidpoint(line) {
72
+ var x = (line[0][0] + line[1][0]) / 2;
73
+ var y = (line[0][1] + line[1][1]) / 2;
74
+ return [x, y];
75
+ }
76
+ exports.getLineMidpoint = getLineMidpoint;
77
+ function getDistanceToLine(pointOnLine, lineSlope, point) {
78
+ var x1 = point[0], y1 = point[1];
79
+ var x2 = pointOnLine[0], y2 = pointOnLine[1];
80
+ var lineYIntercept = y2 - lineSlope * x2;
81
+ return Math.abs((lineSlope * x1 - y1 + lineYIntercept) /
82
+ Math.sqrt(lineSlope * lineSlope + 1));
83
+ }
84
+ exports.getDistanceToLine = getDistanceToLine;
85
+ function closestPointOnLine(pointOnLine, lineSlope, point) {
86
+ var x1 = point[0], y1 = point[1];
87
+ var x2 = pointOnLine[0], y2 = pointOnLine[1];
88
+ var lineYIntercept = y2 - lineSlope * x2;
89
+ var perpendicularSlope = -1 / lineSlope;
90
+ var perpendicularYIntercept = y1 - perpendicularSlope * x1;
91
+ var intersectionX = (lineYIntercept - perpendicularYIntercept) /
92
+ (perpendicularSlope - lineSlope);
93
+ var intersectionY = lineSlope * intersectionX + lineYIntercept;
94
+ return [intersectionX, intersectionY];
95
+ }
96
+ exports.closestPointOnLine = closestPointOnLine;
97
+ function getAngleBetweenLines(line1, line2) {
98
+ var _a = line1.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
99
+ var _b = line2.flat(), x3 = _b[0], y3 = _b[1], x4 = _b[2], y4 = _b[3];
100
+ var line1Slope = (y2 - y1) / (x2 - x1);
101
+ var line2Slope = (y4 - y3) / (x4 - x3);
102
+ return Math.atan2(line1Slope - line2Slope, 1 + line1Slope * line2Slope);
103
+ }
104
+ exports.getAngleBetweenLines = getAngleBetweenLines;
105
+ function getQuadrilateralArea(quadrilateral) {
106
+ var _a = quadrilateral.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3], x3 = _a[4], y3 = _a[5], x4 = _a[6], y4 = _a[7];
107
+ var area = Math.abs((x1 * y2 +
108
+ x2 * y3 +
109
+ x3 * y4 +
110
+ x4 * y1 -
111
+ x2 * y1 -
112
+ x3 * y2 -
113
+ x4 * y3 -
114
+ x1 * y4) /
115
+ 2);
116
+ return area;
117
+ }
118
+ exports.getQuadrilateralArea = getQuadrilateralArea;
119
+ function getTriangleArea(point1, point2, point3) {
120
+ var x1 = point1[0], y1 = point1[1];
121
+ var x2 = point2[0], y2 = point2[1];
122
+ var x3 = point3[0], y3 = point3[1];
123
+ var a = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
124
+ var b = Math.sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
125
+ var c = Math.sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
126
+ var s = (a + b + c) / 2;
127
+ var area = Math.sqrt(s * (s - a) * (s - b) * (s - c));
128
+ return area;
129
+ }
130
+ exports.getTriangleArea = getTriangleArea;
131
+ function getParallelLineSegmentAtDistance(line, distance) {
132
+ var _a = line.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
133
+ var angle = Math.atan2(y2 - y1, x2 - x1);
134
+ var xOffset = (distance / 2) * Math.sin(angle);
135
+ var yOffset = (distance / 2) * Math.cos(angle);
136
+ var point1 = [x1 + xOffset, y1 - yOffset];
137
+ var point2 = [x2 + xOffset, y2 - yOffset];
138
+ return [point1, point2];
139
+ }
140
+ exports.getParallelLineSegmentAtDistance = getParallelLineSegmentAtDistance;
141
+ function addThicknessToLine(line, thickness) {
142
+ var _a = line.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
143
+ var angle = Math.atan2(y2 - y1, x2 - x1);
144
+ var xOffset = (thickness / 2) * Math.sin(angle);
145
+ var yOffset = (thickness / 2) * Math.cos(angle);
146
+ var point1 = [x1 + xOffset, y1 - yOffset];
147
+ var point2 = [x1 - xOffset, y1 + yOffset];
148
+ var point3 = [x2 - xOffset, y2 + yOffset];
149
+ var point4 = [x2 + xOffset, y2 - yOffset];
150
+ return [point1, point2, point3, point4];
151
+ }
152
+ exports.addThicknessToLine = addThicknessToLine;
153
+ function arePointsWithinProximity(point1, point2, proximity) {
154
+ var length = getLengthOfLineSegment([point1, point2]);
155
+ return length <= proximity;
156
+ }
157
+ exports.arePointsWithinProximity = arePointsWithinProximity;
158
+ function isPointInQuadrilateral(quadrilateral, point) {
159
+ var _a = quadrilateral.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3], x3 = _a[4], y3 = _a[5], x4 = _a[6], y4 = _a[7];
160
+ var pointX = point[0], pointY = point[1];
161
+ if (pointX < Math.min(x1, x2, x3, x4) ||
162
+ pointX > Math.max(x1, x2, x3, x4) ||
163
+ pointY < Math.min(y1, y2, y3, y4) ||
164
+ pointY > Math.max(y1, y2, y3, y4)) {
165
+ return false;
166
+ }
167
+ var area = getQuadrilateralArea(quadrilateral);
168
+ var area1 = getTriangleArea(point, quadrilateral[0], quadrilateral[1]);
169
+ var area2 = getTriangleArea(point, quadrilateral[1], quadrilateral[2]);
170
+ var area3 = getTriangleArea(point, quadrilateral[2], quadrilateral[3]);
171
+ var area4 = getTriangleArea(point, quadrilateral[3], quadrilateral[0]);
172
+ return (Math.abs(Math.round(area) - Math.round(area1 + area2 + area3 + area4)) < 2);
173
+ }
174
+ exports.isPointInQuadrilateral = isPointInQuadrilateral;
175
+ function isPointInPolygon(point, polygon) {
176
+ var ray = [
177
+ point,
178
+ [point[0] + Number.MAX_SAFE_INTEGER, point[1]],
179
+ ];
180
+ var intersectCount = 0;
181
+ for (var i = 0; i < polygon.length; i++) {
182
+ var polygonStart = polygon[i];
183
+ var polygonEnd = polygon[(i + 1) % polygon.length];
184
+ if (getLineSegmentsIntersection(ray, [polygonStart, polygonEnd]))
185
+ intersectCount++;
186
+ }
187
+ return intersectCount % 2 === 1;
188
+ }
189
+ exports.isPointInPolygon = isPointInPolygon;
190
+ function getLineIntersection(line1, line2) {
191
+ var _a = line1.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
192
+ var _b = line2.flat(), x3 = _b[0], y3 = _b[1], x4 = _b[2], y4 = _b[3];
193
+ var a1 = y2 - y1;
194
+ var b1 = x1 - x2;
195
+ var c1 = a1 * x1 + b1 * y1;
196
+ var a2 = y4 - y3;
197
+ var b2 = x3 - x4;
198
+ var c2 = a2 * x3 + b2 * y3;
199
+ var determinant = a1 * b2 - a2 * b1;
200
+ if (determinant === 0)
201
+ return null;
202
+ var x = (b2 * c1 - b1 * c2) / determinant;
203
+ var y = (a1 * c2 - a2 * c1) / determinant;
204
+ return [x, y];
205
+ }
206
+ exports.getLineIntersection = getLineIntersection;
207
+ function getLineSegmentsIntersection(line1, line2) {
208
+ if (arePointsEqual.apply(void 0, line1) || arePointsEqual.apply(void 0, line2))
209
+ return null;
210
+ if (arePointsEqual(line1[0], line2[0]))
211
+ return null;
212
+ if (arePointsEqual(line1[0], line2[1]))
213
+ return null;
214
+ if (arePointsEqual(line1[1], line2[0]))
215
+ return null;
216
+ if (arePointsEqual(line1[1], line2[1]))
217
+ return null;
218
+ var _a = line1.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
219
+ var _b = line2.flat(), x3 = _b[0], y3 = _b[1], x4 = _b[2], y4 = _b[3];
220
+ if ((x1 === x2 && x3 === x4) || (y1 === y2 && y3 === y4))
221
+ return null;
222
+ if (x1 === x2 || x3 === x4) {
223
+ var _c = x1 === x2 ? line1.flat() : line2.flat(), xVert = _c[0], y1Vert = _c[1], _1 = _c[2], y2Vert = _c[3];
224
+ var _d = x1 === x2 ? line2.flat() : line1.flat(), x1Line = _d[0], y1Line = _d[1], x2Line = _d[2], y2Line = _d[3];
225
+ if (Math.min(x1Line, x2Line) <= xVert &&
226
+ xVert <= Math.max(x1Line, x2Line)) {
227
+ var m = (y2Line - y1Line) / (x2Line - x1Line);
228
+ var yValue = m * xVert + y1Line - m * x1Line;
229
+ if (Math.min(y1Vert, y2Vert) <= yValue &&
230
+ yValue <= Math.max(y1Vert, y2Vert))
231
+ return [xVert, yValue];
232
+ }
233
+ return null;
234
+ }
235
+ var m1 = (y2 - y1) / (x2 - x1);
236
+ var b1 = y1 - m1 * x1;
237
+ var m2 = (y4 - y3) / (x4 - x3);
238
+ var b2 = y3 - m2 * x3;
239
+ if (m1 === m2)
240
+ return null;
241
+ var x = (b2 - b1) / (m1 - m2);
242
+ var y = m1 * x + b1;
243
+ if (x < Math.min(x1, x2) ||
244
+ x > Math.max(x1, x2) ||
245
+ x < Math.min(x3, x4) ||
246
+ x > Math.max(x3, x4))
247
+ return null;
248
+ if (y < Math.min(y1, y2) ||
249
+ y > Math.max(y1, y2) ||
250
+ y < Math.min(y3, y4) ||
251
+ y > Math.max(y3, y4))
252
+ return null;
253
+ return [x, y];
254
+ }
255
+ exports.getLineSegmentsIntersection = getLineSegmentsIntersection;
256
+ function splitLineAtPoint(line, point) {
257
+ return [
258
+ [line[0], point],
259
+ [point, line[1]],
260
+ ];
261
+ }
262
+ exports.splitLineAtPoint = splitLineAtPoint;
263
+ function splitLineAtPoints(line, points) {
264
+ if (!points.length)
265
+ return [line];
266
+ var orderedPoints = orderCoordinatesOnLineSegment(__spreadArray(__spreadArray([], line, true), points, true));
267
+ return (orderedPoints[0][0] === line[0][0] ? orderedPoints : orderedPoints.reverse()).reduce(function (output, point, i) {
268
+ if (!i)
269
+ return output;
270
+ else
271
+ output.push([orderedPoints[i - 1], point]);
272
+ return output;
273
+ }, []);
274
+ }
275
+ exports.splitLineAtPoints = splitLineAtPoints;
276
+ function splitLineAtOffset(line, offset) {
277
+ var splitPoint = getPointAtOffsetOnLineSegment(line, offset);
278
+ return splitLineAtPoint(line, splitPoint);
279
+ }
280
+ exports.splitLineAtOffset = splitLineAtOffset;
281
+ function orderCoordinatesOnLineSegment(points) {
282
+ if (!points)
283
+ return [];
284
+ if (points[0][0] === points[1][0])
285
+ return points.sort(function (a, b) { return a[1] - b[1]; });
286
+ else
287
+ return points.sort(function (a, b) { return a[0] - b[0]; });
288
+ }
289
+ exports.orderCoordinatesOnLineSegment = orderCoordinatesOnLineSegment;
290
+ function findAllIntersectionPoints(lines) {
291
+ var intersectionPoints = [];
292
+ for (var i = 0; i < lines.length - 1; i++) {
293
+ var _a = lines[i].flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
294
+ for (var j = i + 1; j < lines.length; j++) {
295
+ var _b = lines[j].flat(), x3 = _b[0], y3 = _b[1], x4 = _b[2], y4 = _b[3];
296
+ var den = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
297
+ if (den === 0) {
298
+ continue;
299
+ }
300
+ var t = ((x1 - x3) * (y3 - y4) - (y1 - y3) * (x3 - x4)) / den;
301
+ var u = -((x1 - x2) * (y1 - y3) - (y1 - y2) * (x1 - x3)) / den;
302
+ if (t >= 0 && t <= 1 && u >= 0 && u <= 1) {
303
+ var x = x1 + t * (x2 - x1);
304
+ var y = y1 + t * (y2 - y1);
305
+ intersectionPoints.push({ lines: [i, j], point: [x, y] });
306
+ }
307
+ }
308
+ }
309
+ return intersectionPoints;
310
+ }
311
+ exports.findAllIntersectionPoints = findAllIntersectionPoints;
312
+ function getTangentIntersection(line, point) {
313
+ var _a = line.flat(), x1 = _a[0], y1 = _a[1], x2 = _a[2], y2 = _a[3];
314
+ var xTest = point[0], yTest = point[1];
315
+ if (x1 === x2) {
316
+ if (Math.min(y1, y2) <= yTest && yTest <= Math.max(y1, y2))
317
+ return [x1, yTest];
318
+ return undefined;
319
+ }
320
+ if (y1 === y2) {
321
+ if (Math.min(x1, x2) <= xTest && xTest <= Math.max(x1, x2))
322
+ return [xTest, y1];
323
+ return undefined;
324
+ }
325
+ var slope = (y2 - y1) / (x2 - x1);
326
+ var yIntercept = y1 - slope * x1;
327
+ var tangentSlope = -1 / slope;
328
+ var tangentYIntercept = yTest - tangentSlope * xTest;
329
+ var intersectionX = (tangentYIntercept - yIntercept) / (slope - tangentSlope);
330
+ var intersectionY = slope * intersectionX + yIntercept;
331
+ if (intersectionX >= Math.min(x1, x2) &&
332
+ intersectionX <= Math.max(x1, x2) &&
333
+ intersectionY >= Math.min(y1, y2) &&
334
+ intersectionY <= Math.max(y1, y2)) {
335
+ return [intersectionX, intersectionY];
336
+ }
337
+ else {
338
+ return undefined;
339
+ }
340
+ }
341
+ exports.getTangentIntersection = getTangentIntersection;
342
+ function getTangetIntersectionAndOffset(line, point) {
343
+ var interceptPoint = getTangentIntersection(line, point);
344
+ if (!interceptPoint)
345
+ return undefined;
346
+ return {
347
+ point: interceptPoint,
348
+ offset: getLengthOfLineSegment([line[0], point]),
349
+ };
350
+ }
351
+ exports.getTangetIntersectionAndOffset = getTangetIntersectionAndOffset;
352
+ function doeslineSegmentIntersectQuadrilateral(line, quadrilateral) {
353
+ for (var i = 0; i < quadrilateral.length; i++) {
354
+ var quadStart = quadrilateral[i];
355
+ var quadEnd = quadrilateral[(i + 1) % quadrilateral.length];
356
+ if (getLineSegmentsIntersection(line, [quadStart, quadEnd]))
357
+ return true;
358
+ }
359
+ return false;
360
+ }
361
+ exports.doeslineSegmentIntersectQuadrilateral = doeslineSegmentIntersectQuadrilateral;
362
+ function getAllLineIntersections(line, lines) {
363
+ var lineStr = [JSON.stringify(line[0]), JSON.stringify(line[1])];
364
+ return lines.reduce(function (output, existingLine, i) {
365
+ if (existingLine === null)
366
+ return output;
367
+ var startStr = JSON.stringify(existingLine[0]);
368
+ var endStr = JSON.stringify(existingLine[1]);
369
+ if (lineStr.includes(startStr) || lineStr.includes(endStr))
370
+ return output;
371
+ var intersectionPoint = getLineSegmentsIntersection(line, existingLine);
372
+ if (!intersectionPoint)
373
+ return output;
374
+ output.push({ index: i, point: intersectionPoint });
375
+ return output;
376
+ }, []);
377
+ }
378
+ exports.getAllLineIntersections = getAllLineIntersections;
379
+ function doLinesOverlap(line1, line2) {
380
+ var start1 = line1[0];
381
+ var end1 = line1[0] + line1[1];
382
+ var start2 = line2[0];
383
+ var end2 = line2[0] + line2[1];
384
+ if (start2 < start1 && start1 < end2)
385
+ return true;
386
+ if (start2 < end1 && end1 < end2)
387
+ return true;
388
+ if (start1 < start2 && start2 < end1 && start1 < end2 && end2 < end1)
389
+ return true;
390
+ return false;
391
+ }
392
+ exports.doLinesOverlap = doLinesOverlap;
393
+ function getDistanceFromCircumference(point, circleCenter, radius) {
394
+ var x = point[0], y = point[1];
395
+ var xCircle = circleCenter[0], yCircle = circleCenter[1];
396
+ var dx = x - xCircle;
397
+ var dy = y - yCircle;
398
+ var distanceFromCenter = Math.sqrt(dx * dx + dy * dy);
399
+ return Math.abs(distanceFromCenter - radius);
400
+ }
401
+ exports.getDistanceFromCircumference = getDistanceFromCircumference;
402
+ function getClosestPointOnCircumference(point, circleCenter, radius) {
403
+ var x = point[0], y = point[1];
404
+ var xCircle = circleCenter[0], yCircle = circleCenter[1];
405
+ var dx = x - xCircle;
406
+ var dy = y - yCircle;
407
+ var angle = Math.atan2(dy, dx);
408
+ var x2 = xCircle + radius * Math.cos(angle);
409
+ var y2 = yCircle + radius * Math.sin(angle);
410
+ return [x2, y2];
411
+ }
412
+ exports.getClosestPointOnCircumference = getClosestPointOnCircumference;
413
+ function findClosedPaths(lines) {
414
+ if (!(lines === null || lines === void 0 ? void 0 : lines.length))
415
+ return [];
416
+ var vertices = lines.reduce(function (output, line, i) {
417
+ line.forEach(function (point) {
418
+ var pointStr = JSON.stringify(point);
419
+ if (output[pointStr])
420
+ output[pointStr].push(i);
421
+ else
422
+ output[pointStr] = [i];
423
+ });
424
+ return output;
425
+ }, {});
426
+ var closedLoops = [];
427
+ var linesVisted = new Set([]);
428
+ for (var i = 0; i < lines.length; i++) {
429
+ if (!linesVisted.has(i))
430
+ depthFirstSearch(i);
431
+ }
432
+ return closedLoops;
433
+ function depthFirstSearch(index, vertexPath, linesPath) {
434
+ if (vertexPath === void 0) { vertexPath = []; }
435
+ if (linesPath === void 0) { linesPath = []; }
436
+ var pointsToSearch = vertexPath.length
437
+ ? lines[index].filter(function (point) { return !arePointsEqual(vertexPath[vertexPath.length - 1], point); })
438
+ : lines[index];
439
+ pointsToSearch.forEach(function (pointToSearch) {
440
+ var vertexVisted = vertexPath.findIndex(function (point) {
441
+ return arePointsEqual(pointToSearch, point);
442
+ });
443
+ if (vertexVisted !== -1) {
444
+ var loop = linesPath.slice(vertexVisted, linesPath.length - 1);
445
+ closedLoops.push(__spreadArray([index], loop, true));
446
+ return;
447
+ }
448
+ if (linesVisted.has(index))
449
+ return;
450
+ var linesToSearch = vertices[JSON.stringify(pointToSearch)];
451
+ if (!(linesToSearch === null || linesToSearch === void 0 ? void 0 : linesToSearch.length))
452
+ return;
453
+ linesToSearch.forEach(function (lineIndex) {
454
+ if (index === lineIndex)
455
+ return;
456
+ depthFirstSearch(lineIndex, __spreadArray(__spreadArray([], vertexPath, true), [pointToSearch], false), __spreadArray(__spreadArray([], linesPath, true), [lineIndex], false));
457
+ });
458
+ });
459
+ linesVisted.add(index);
460
+ }
461
+ }
462
+ exports.findClosedPaths = findClosedPaths;
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import type { IHydratedAttributeArray } from '../../types';
3
+ import type { IElementName, IElementPublic, IRoomBuilderHookProps } from './types';
4
+ import { IModes, IUnits, IElements } from './types';
5
+ import { IThemes } from './themes';
6
+ interface IUseRoomBuilder {
7
+ canvasRef: React.RefObject<HTMLCanvasElement>;
8
+ [IElements.WALL]?: IHydratedAttributeArray;
9
+ [IElements.WINDOW]?: IHydratedAttributeArray;
10
+ [IElements.DOOR]?: IHydratedAttributeArray;
11
+ [IElements.OPENING]?: IHydratedAttributeArray;
12
+ selectedElement: IElementPublic | null;
13
+ deleteAll: () => void;
14
+ deleteElement: (type: IElementName, index: number) => void;
15
+ dimensions: {
16
+ show: boolean;
17
+ handleToggle: (val?: boolean) => void;
18
+ };
19
+ snapping: {
20
+ enabled: boolean;
21
+ handleToggle: (val?: boolean) => void;
22
+ };
23
+ mode: {
24
+ value: IModes;
25
+ options: Array<{
26
+ label: IModes;
27
+ value: IModes;
28
+ selected: boolean;
29
+ handleSelect: () => void;
30
+ }>;
31
+ handleChange: (mode: IModes) => void;
32
+ };
33
+ }
34
+ declare const useRoomBuilder: {
35
+ (props: IRoomBuilderHookProps): IUseRoomBuilder;
36
+ themes: typeof IThemes;
37
+ units: typeof IUnits;
38
+ modes: typeof IModes;
39
+ };
40
+ export default useRoomBuilder;