@vertexvis/viewer 0.18.1 → 0.18.2-testing.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 (226) hide show
  1. package/dist/components/_commonjsHelpers.js +41 -0
  2. package/dist/components/_commonjsHelpers.js.map +1 -0
  3. package/dist/components/browser.esm.js +3173 -0
  4. package/dist/components/browser.esm.js.map +1 -0
  5. package/dist/components/bundle.esm.js +2250 -0
  6. package/dist/components/bundle.esm.js.map +1 -0
  7. package/dist/components/bundle.esm2.js +39740 -0
  8. package/dist/components/bundle.esm2.js.map +1 -0
  9. package/dist/components/config.js +81 -0
  10. package/dist/components/config.js.map +1 -0
  11. package/dist/components/controller.js +7627 -0
  12. package/dist/components/controller.js.map +1 -0
  13. package/dist/components/controller2.js +124 -0
  14. package/dist/components/controller2.js.map +1 -0
  15. package/dist/components/controller3.js +111 -0
  16. package/dist/components/controller3.js.map +1 -0
  17. package/dist/components/cursors.js +110 -0
  18. package/dist/components/cursors.js.map +1 -0
  19. package/dist/components/dom.js +43 -0
  20. package/dist/components/dom.js.map +1 -0
  21. package/dist/components/dom2.js +10 -0
  22. package/dist/components/dom2.js.map +1 -0
  23. package/dist/components/elementRectObserver.js +25 -0
  24. package/dist/components/elementRectObserver.js.map +1 -0
  25. package/dist/components/entities.js +179 -0
  26. package/dist/components/entities.js.map +1 -0
  27. package/dist/components/errors.js +80 -0
  28. package/dist/components/errors.js.map +1 -0
  29. package/dist/components/events.js +11 -0
  30. package/dist/components/events.js.map +1 -0
  31. package/dist/components/index.d.ts +26 -0
  32. package/dist/components/index.js +365 -0
  33. package/dist/components/index.js.map +1 -0
  34. package/dist/components/index2.js +63 -0
  35. package/dist/components/index2.js.map +1 -0
  36. package/dist/components/interactions.js +236 -0
  37. package/dist/components/interactions.js.map +1 -0
  38. package/dist/components/mapper.js +9811 -0
  39. package/dist/components/mapper.js.map +1 -0
  40. package/dist/components/markup.js +33 -0
  41. package/dist/components/markup.js.map +1 -0
  42. package/dist/components/model.js +134 -0
  43. package/dist/components/model.js.map +1 -0
  44. package/dist/components/model2.js +157 -0
  45. package/dist/components/model2.js.map +1 -0
  46. package/dist/components/overlays.js +76 -0
  47. package/dist/components/overlays.js.map +1 -0
  48. package/dist/components/png-decoder.js +2405 -0
  49. package/dist/components/png-decoder.js.map +1 -0
  50. package/dist/components/regl-component.js +12582 -0
  51. package/dist/components/regl-component.js.map +1 -0
  52. package/dist/components/results.js +24 -0
  53. package/dist/components/results.js.map +1 -0
  54. package/dist/components/row.js +32 -0
  55. package/dist/components/row.js.map +1 -0
  56. package/dist/components/scene-tree-search.js +146 -0
  57. package/dist/components/scene-tree-search.js.map +1 -0
  58. package/dist/components/scene-tree-table-layout.js +928 -0
  59. package/dist/components/scene-tree-table-layout.js.map +1 -0
  60. package/dist/components/scene-tree-toolbar.js +35 -0
  61. package/dist/components/scene-tree-toolbar.js.map +1 -0
  62. package/dist/components/scene.js +1508 -0
  63. package/dist/components/scene.js.map +1 -0
  64. package/dist/components/stencil.js +25 -0
  65. package/dist/components/stencil.js.map +1 -0
  66. package/dist/components/streamAttributes.js +40833 -0
  67. package/dist/components/streamAttributes.js.map +1 -0
  68. package/dist/components/templates.js +36 -0
  69. package/dist/components/templates.js.map +1 -0
  70. package/dist/components/tslib.es6.js +125 -0
  71. package/dist/components/tslib.es6.js.map +1 -0
  72. package/dist/components/vertex-scene-tree-search.d.ts +11 -0
  73. package/dist/components/vertex-scene-tree-search.js +11 -0
  74. package/dist/components/vertex-scene-tree-search.js.map +1 -0
  75. package/dist/components/vertex-scene-tree-table-cell.d.ts +11 -0
  76. package/dist/components/vertex-scene-tree-table-cell.js +209 -0
  77. package/dist/components/vertex-scene-tree-table-cell.js.map +1 -0
  78. package/dist/components/vertex-scene-tree-table-column.d.ts +11 -0
  79. package/dist/components/vertex-scene-tree-table-column.js +42 -0
  80. package/dist/components/vertex-scene-tree-table-column.js.map +1 -0
  81. package/dist/components/vertex-scene-tree-table-header.d.ts +11 -0
  82. package/dist/components/vertex-scene-tree-table-header.js +38 -0
  83. package/dist/components/vertex-scene-tree-table-header.js.map +1 -0
  84. package/dist/components/vertex-scene-tree-table-layout.d.ts +11 -0
  85. package/dist/components/vertex-scene-tree-table-layout.js +11 -0
  86. package/dist/components/vertex-scene-tree-table-layout.js.map +1 -0
  87. package/dist/components/vertex-scene-tree-table-resize-divider.d.ts +11 -0
  88. package/dist/components/vertex-scene-tree-table-resize-divider.js +57 -0
  89. package/dist/components/vertex-scene-tree-table-resize-divider.js.map +1 -0
  90. package/dist/components/vertex-scene-tree-toolbar-group.d.ts +11 -0
  91. package/dist/components/vertex-scene-tree-toolbar-group.js +38 -0
  92. package/dist/components/vertex-scene-tree-toolbar-group.js.map +1 -0
  93. package/dist/components/vertex-scene-tree-toolbar.d.ts +11 -0
  94. package/dist/components/vertex-scene-tree-toolbar.js +11 -0
  95. package/dist/components/vertex-scene-tree-toolbar.js.map +1 -0
  96. package/dist/components/vertex-scene-tree.d.ts +11 -0
  97. package/dist/components/vertex-scene-tree.js +803 -0
  98. package/dist/components/vertex-scene-tree.js.map +1 -0
  99. package/dist/components/vertex-viewer-box-query-tool.d.ts +11 -0
  100. package/dist/components/vertex-viewer-box-query-tool.js +352 -0
  101. package/dist/components/vertex-viewer-box-query-tool.js.map +1 -0
  102. package/dist/components/vertex-viewer-button.d.ts +11 -0
  103. package/dist/components/vertex-viewer-button.js +11 -0
  104. package/dist/components/vertex-viewer-button.js.map +1 -0
  105. package/dist/components/vertex-viewer-default-toolbar.d.ts +11 -0
  106. package/dist/components/vertex-viewer-default-toolbar.js +99 -0
  107. package/dist/components/vertex-viewer-default-toolbar.js.map +1 -0
  108. package/dist/components/vertex-viewer-dom-element.d.ts +11 -0
  109. package/dist/components/vertex-viewer-dom-element.js +11 -0
  110. package/dist/components/vertex-viewer-dom-element.js.map +1 -0
  111. package/dist/components/vertex-viewer-dom-group.d.ts +11 -0
  112. package/dist/components/vertex-viewer-dom-group.js +11 -0
  113. package/dist/components/vertex-viewer-dom-group.js.map +1 -0
  114. package/dist/components/vertex-viewer-dom-renderer.d.ts +11 -0
  115. package/dist/components/vertex-viewer-dom-renderer.js +11 -0
  116. package/dist/components/vertex-viewer-dom-renderer.js.map +1 -0
  117. package/dist/components/vertex-viewer-hit-result-indicator.d.ts +11 -0
  118. package/dist/components/vertex-viewer-hit-result-indicator.js +335 -0
  119. package/dist/components/vertex-viewer-hit-result-indicator.js.map +1 -0
  120. package/dist/components/vertex-viewer-icon.d.ts +11 -0
  121. package/dist/components/vertex-viewer-icon.js +11 -0
  122. package/dist/components/vertex-viewer-icon.js.map +1 -0
  123. package/dist/components/vertex-viewer-layer.d.ts +11 -0
  124. package/dist/components/vertex-viewer-layer.js +11 -0
  125. package/dist/components/vertex-viewer-layer.js.map +1 -0
  126. package/dist/components/vertex-viewer-markup-arrow.d.ts +11 -0
  127. package/dist/components/vertex-viewer-markup-arrow.js +11 -0
  128. package/dist/components/vertex-viewer-markup-arrow.js.map +1 -0
  129. package/dist/components/vertex-viewer-markup-circle.d.ts +11 -0
  130. package/dist/components/vertex-viewer-markup-circle.js +11 -0
  131. package/dist/components/vertex-viewer-markup-circle.js.map +1 -0
  132. package/dist/components/vertex-viewer-markup-freeform.d.ts +11 -0
  133. package/dist/components/vertex-viewer-markup-freeform.js +11 -0
  134. package/dist/components/vertex-viewer-markup-freeform.js.map +1 -0
  135. package/dist/components/vertex-viewer-markup-tool.d.ts +11 -0
  136. package/dist/components/vertex-viewer-markup-tool.js +257 -0
  137. package/dist/components/vertex-viewer-markup-tool.js.map +1 -0
  138. package/dist/components/vertex-viewer-markup.d.ts +11 -0
  139. package/dist/components/vertex-viewer-markup.js +362 -0
  140. package/dist/components/vertex-viewer-markup.js.map +1 -0
  141. package/dist/components/vertex-viewer-measurement-details.d.ts +11 -0
  142. package/dist/components/vertex-viewer-measurement-details.js +307 -0
  143. package/dist/components/vertex-viewer-measurement-details.js.map +1 -0
  144. package/dist/components/vertex-viewer-measurement-distance.d.ts +11 -0
  145. package/dist/components/vertex-viewer-measurement-distance.js +1067 -0
  146. package/dist/components/vertex-viewer-measurement-distance.js.map +1 -0
  147. package/dist/components/vertex-viewer-measurement-line.d.ts +11 -0
  148. package/dist/components/vertex-viewer-measurement-line.js +11 -0
  149. package/dist/components/vertex-viewer-measurement-line.js.map +1 -0
  150. package/dist/components/vertex-viewer-measurement-overlays.d.ts +11 -0
  151. package/dist/components/vertex-viewer-measurement-overlays.js +11 -0
  152. package/dist/components/vertex-viewer-measurement-overlays.js.map +1 -0
  153. package/dist/components/vertex-viewer-measurement-precise.d.ts +11 -0
  154. package/dist/components/vertex-viewer-measurement-precise.js +362 -0
  155. package/dist/components/vertex-viewer-measurement-precise.js.map +1 -0
  156. package/dist/components/vertex-viewer-pin-group.d.ts +11 -0
  157. package/dist/components/vertex-viewer-pin-group.js +11 -0
  158. package/dist/components/vertex-viewer-pin-group.js.map +1 -0
  159. package/dist/components/vertex-viewer-pin-label-line.d.ts +11 -0
  160. package/dist/components/vertex-viewer-pin-label-line.js +11 -0
  161. package/dist/components/vertex-viewer-pin-label-line.js.map +1 -0
  162. package/dist/components/vertex-viewer-pin-label.d.ts +11 -0
  163. package/dist/components/vertex-viewer-pin-label.js +11 -0
  164. package/dist/components/vertex-viewer-pin-label.js.map +1 -0
  165. package/dist/components/vertex-viewer-pin-tool.d.ts +11 -0
  166. package/dist/components/vertex-viewer-pin-tool.js +430 -0
  167. package/dist/components/vertex-viewer-pin-tool.js.map +1 -0
  168. package/dist/components/vertex-viewer-spinner.d.ts +11 -0
  169. package/dist/components/vertex-viewer-spinner.js +11 -0
  170. package/dist/components/vertex-viewer-spinner.js.map +1 -0
  171. package/dist/components/vertex-viewer-toolbar-group.d.ts +11 -0
  172. package/dist/components/vertex-viewer-toolbar-group.js +11 -0
  173. package/dist/components/vertex-viewer-toolbar-group.js.map +1 -0
  174. package/dist/components/vertex-viewer-toolbar.d.ts +11 -0
  175. package/dist/components/vertex-viewer-toolbar.js +11 -0
  176. package/dist/components/vertex-viewer-toolbar.js.map +1 -0
  177. package/dist/components/vertex-viewer-transform-widget.d.ts +11 -0
  178. package/dist/components/vertex-viewer-transform-widget.js +838 -0
  179. package/dist/components/vertex-viewer-transform-widget.js.map +1 -0
  180. package/dist/components/vertex-viewer-view-cube.d.ts +11 -0
  181. package/dist/components/vertex-viewer-view-cube.js +270 -0
  182. package/dist/components/vertex-viewer-view-cube.js.map +1 -0
  183. package/dist/components/vertex-viewer.d.ts +11 -0
  184. package/dist/components/vertex-viewer.js +3543 -0
  185. package/dist/components/vertex-viewer.js.map +1 -0
  186. package/dist/components/viewer-button.js +35 -0
  187. package/dist/components/viewer-button.js.map +1 -0
  188. package/dist/components/viewer-dom-element.js +250 -0
  189. package/dist/components/viewer-dom-element.js.map +1 -0
  190. package/dist/components/viewer-dom-group.js +214 -0
  191. package/dist/components/viewer-dom-group.js.map +1 -0
  192. package/dist/components/viewer-dom-renderer.js +295 -0
  193. package/dist/components/viewer-dom-renderer.js.map +1 -0
  194. package/dist/components/viewer-icon.js +87 -0
  195. package/dist/components/viewer-icon.js.map +1 -0
  196. package/dist/components/viewer-layer.js +46 -0
  197. package/dist/components/viewer-layer.js.map +1 -0
  198. package/dist/components/viewer-markup-arrow.js +235 -0
  199. package/dist/components/viewer-markup-arrow.js.map +1 -0
  200. package/dist/components/viewer-markup-circle-components.js +42 -0
  201. package/dist/components/viewer-markup-circle-components.js.map +1 -0
  202. package/dist/components/viewer-markup-circle.js +201 -0
  203. package/dist/components/viewer-markup-circle.js.map +1 -0
  204. package/dist/components/viewer-markup-freeform.js +251 -0
  205. package/dist/components/viewer-markup-freeform.js.map +1 -0
  206. package/dist/components/viewer-measurement-line.js +77 -0
  207. package/dist/components/viewer-measurement-line.js.map +1 -0
  208. package/dist/components/viewer-measurement-overlays.js +184 -0
  209. package/dist/components/viewer-measurement-overlays.js.map +1 -0
  210. package/dist/components/viewer-pin-group.js +207 -0
  211. package/dist/components/viewer-pin-group.js.map +1 -0
  212. package/dist/components/viewer-pin-label-line.js +43 -0
  213. package/dist/components/viewer-pin-label-line.js.map +1 -0
  214. package/dist/components/viewer-pin-label.js +427 -0
  215. package/dist/components/viewer-pin-label.js.map +1 -0
  216. package/dist/components/viewer-spinner.js +53 -0
  217. package/dist/components/viewer-spinner.js.map +1 -0
  218. package/dist/components/viewer-toolbar-group.js +42 -0
  219. package/dist/components/viewer-toolbar-group.js.map +1 -0
  220. package/dist/components/viewer-toolbar.js +61 -0
  221. package/dist/components/viewer-toolbar.js.map +1 -0
  222. package/dist/components/viewport.js +188 -0
  223. package/dist/components/viewport.js.map +1 -0
  224. package/dist/components/wrappers_pb.js +1926 -0
  225. package/dist/components/wrappers_pb.js.map +1 -0
  226. package/package.json +7 -7
@@ -0,0 +1,838 @@
1
+ /*!
2
+ * Copyright (c) 2023 Vertex Software LLC. All rights reserved.
3
+ */
4
+ import { proxyCustomElement, HTMLElement, createEvent, h, Host } from '@stencil/core/internal/client';
5
+ import { p as point, v as vector3, r as ray, f as plane, q as quaternion, m as matrix4, c as angle, b as boundingBox, e as rectangle } from './bundle.esm.js';
6
+ import { c as classnames } from './index2.js';
7
+ import { w as writeDOM, r as readDOM } from './stencil.js';
8
+ import { T as TransformController } from './controller2.js';
9
+ import { E as EventDispatcher } from './browser.esm.js';
10
+ import { d as TriangleMeshPoints, T as TriangleMesh, R as ReglComponent, e as computeDrawable2dBounds, r as regl, s as shapeBuilder, x as xAxisArrowPositions, A as AxisLine, b as axisPositions, y as yAxisArrowPositions, z as zAxisArrowPositions, f as rotationAxisPositions, g as RotationLine } from './regl-component.js';
11
+
12
+ function convertPointToCanvas(point$1, bounds) {
13
+ return bounds != null
14
+ ? point.create(point$1.x - bounds.left, point$1.y - bounds.top)
15
+ : undefined;
16
+ }
17
+ function convertCanvasPointToWorld(point, frame, viewport, transform) {
18
+ const position = transform != null ? vector3.fromMatrixPosition(transform) : undefined;
19
+ if (point != null && frame != null && viewport != null && position != null) {
20
+ if (frame.scene.camera.isOrthographic()) {
21
+ const ray$1 = viewport.transformPointToOrthographicRay(point, frame.image, frame.scene.camera);
22
+ // Offset the point to past the bounding sphere of the model to
23
+ // adjust the position plane location.
24
+ const offsetPoint = ray.at(ray.create({
25
+ origin: position,
26
+ direction: frame.scene.camera.direction,
27
+ }), vector3.magnitude(frame.scene.camera.viewVector) * 2);
28
+ return ray.intersectPlane(ray$1, plane.fromNormalAndCoplanarPoint(frame.scene.camera.direction, offsetPoint));
29
+ }
30
+ else {
31
+ const ray$1 = viewport.transformPointToRay(point, frame.image, frame.scene.camera);
32
+ return ray.intersectPlane(ray$1, plane.fromNormalAndCoplanarPoint(frame.scene.camera.direction, position));
33
+ }
34
+ }
35
+ return undefined;
36
+ }
37
+ function computeUpdatedTransform(current, previous, next, viewVector, angle, identifier) {
38
+ switch (identifier) {
39
+ case 'x-translate': {
40
+ return matrix4.multiply(current, matrix4.makeTranslation(vector3.create(computeTranslation(current, previous, next, vector3.right()), 0, 0)));
41
+ }
42
+ case 'y-translate':
43
+ return matrix4.multiply(current, matrix4.makeTranslation(vector3.create(0, computeTranslation(current, previous, next, vector3.up()), 0)));
44
+ case 'z-translate':
45
+ return matrix4.multiply(current, matrix4.makeTranslation(vector3.create(0, 0, computeTranslation(current, previous, next, vector3.back()))));
46
+ case 'x-rotate': {
47
+ const rotation = quaternion.fromMatrixRotation(current);
48
+ const rotatedRight = vector3.transformMatrix(vector3.right(), matrix4.makeRotation(rotation));
49
+ const rotatedLeft = vector3.transformMatrix(vector3.left(), matrix4.makeRotation(rotation));
50
+ const rotationAxis = vector3.dot(viewVector, rotatedRight) >
51
+ vector3.dot(viewVector, rotatedLeft)
52
+ ? rotatedRight
53
+ : rotatedLeft;
54
+ return computeRotation(quaternion.fromAxisAngle(rotationAxis, angle), current);
55
+ }
56
+ case 'y-rotate': {
57
+ const rotation = quaternion.fromMatrixRotation(current);
58
+ const rotatedUp = vector3.transformMatrix(vector3.up(), matrix4.makeRotation(rotation));
59
+ const rotatedDown = vector3.transformMatrix(vector3.down(), matrix4.makeRotation(rotation));
60
+ const rotationAxis = vector3.dot(viewVector, rotatedUp) >
61
+ vector3.dot(viewVector, rotatedDown)
62
+ ? rotatedUp
63
+ : rotatedDown;
64
+ return computeRotation(quaternion.fromAxisAngle(rotationAxis, angle), current);
65
+ }
66
+ case 'z-rotate': {
67
+ const rotation = quaternion.fromMatrixRotation(current);
68
+ const rotatedForward = vector3.transformMatrix(vector3.forward(), matrix4.makeRotation(rotation));
69
+ const rotatedBack = vector3.transformMatrix(vector3.back(), matrix4.makeRotation(rotation));
70
+ const rotationAxis = vector3.dot(viewVector, rotatedForward) >
71
+ vector3.dot(viewVector, rotatedBack)
72
+ ? rotatedForward
73
+ : rotatedBack;
74
+ return computeRotation(quaternion.fromAxisAngle(rotationAxis, angle), current);
75
+ }
76
+ default:
77
+ return current;
78
+ }
79
+ }
80
+ function computeTranslation(current, previous, next, direction) {
81
+ const rotatedTranslationAxis = vector3.transformMatrix(direction, matrix4.makeRotation(quaternion.fromMatrixRotation(current)));
82
+ const rotatedDelta = vector3.multiply(rotatedTranslationAxis, vector3.subtract(next, previous));
83
+ return rotatedDelta.x + rotatedDelta.y + rotatedDelta.z;
84
+ }
85
+ /**
86
+ * Computes a rotation Matrix4 by applying the rotation at the given position,
87
+ * then translating it back to convert it to a world delta.
88
+ * @param rotation
89
+ * @param current
90
+ * @returns
91
+ */
92
+ function computeRotation(rotation, current) {
93
+ return matrix4.multiply(matrix4.multiply(matrix4.multiply(matrix4.makeTranslation(vector3.fromMatrixPosition(current)), matrix4.makeRotation(rotation)), matrix4.makeTranslation(vector3.negate(vector3.fromMatrixPosition(current)))), current);
94
+ }
95
+
96
+ function xAxisRotationPositions(widgetTransform, camera, triangleSize = 3) {
97
+ return computeRotationNdcValues(widgetTransform, camera, vector3.back(), vector3.up(), triangleSize);
98
+ }
99
+ function yAxisRotationPositions(widgetTransform, camera, triangleSize = 3) {
100
+ return computeRotationNdcValues(widgetTransform, camera, vector3.right(), vector3.back(), triangleSize);
101
+ }
102
+ function zAxisRotationPositions(widgetTransform, camera, triangleSize = 3) {
103
+ return computeRotationNdcValues(widgetTransform, camera, vector3.right(), vector3.up(), triangleSize);
104
+ }
105
+ function computeRotationNdcValues(widgetTransform, camera, xDirection, yDirection, triangleSize) {
106
+ const transformedDirection = vector3.transformMatrix(vector3.add(xDirection, yDirection), matrix4.makeRotation(quaternion.fromMatrixRotation(widgetTransform)));
107
+ const transformedX = vector3.transformMatrix(xDirection, matrix4.makeRotation(quaternion.fromMatrixRotation(widgetTransform)));
108
+ const transformedY = vector3.transformMatrix(yDirection, matrix4.makeRotation(quaternion.fromMatrixRotation(widgetTransform)));
109
+ const basePosition = vector3.fromMatrixPosition(widgetTransform);
110
+ const position = vector3.add(basePosition, vector3.scale(triangleSize * 10, transformedDirection));
111
+ const xRay = ray.create({
112
+ origin: position,
113
+ direction: transformedX,
114
+ });
115
+ const yRay = ray.create({
116
+ origin: position,
117
+ direction: transformedY,
118
+ });
119
+ const rotationAxis = vector3.cross(transformedX, transformedY);
120
+ const base = vector3.rotateAboutAxis(angle.toRadians(45), ray.at(yRay, -triangleSize), rotationAxis, position);
121
+ const right = vector3.rotateAboutAxis(angle.toRadians(45), ray.at(xRay, triangleSize), rotationAxis, position);
122
+ const up = vector3.rotateAboutAxis(angle.toRadians(45), ray.at(yRay, triangleSize), rotationAxis, position);
123
+ const left = vector3.rotateAboutAxis(angle.toRadians(45), ray.at(xRay, -triangleSize), rotationAxis, position);
124
+ return new TriangleMeshPoints(vector3.dot(transformedX, camera.direction) !== -1 &&
125
+ vector3.dot(transformedY, camera.direction) !== -1, base, left, right, up, vector3.transformMatrix(base, camera.projectionViewMatrix), vector3.transformMatrix(left, camera.projectionViewMatrix), vector3.transformMatrix(right, camera.projectionViewMatrix), vector3.transformMatrix(up, camera.projectionViewMatrix));
126
+ }
127
+
128
+ function testDrawable(drawable, frame, viewport, point) {
129
+ if (drawable instanceof TriangleMesh) {
130
+ return testTriangleMesh(drawable, frame, viewport, point);
131
+ }
132
+ return false;
133
+ }
134
+ function testTriangleMesh(mesh, frame, viewport, point) {
135
+ return (testTriangle([mesh.points.worldLeft, mesh.points.worldRight, mesh.points.worldTip], frame, viewport, point) ||
136
+ testTriangle([mesh.points.worldLeft, mesh.points.worldRight, mesh.points.worldBase], frame, viewport, point));
137
+ }
138
+ /**
139
+ * Adapted from https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm.
140
+ */
141
+ function testTriangle(points, frame, viewport, point) {
142
+ var _a;
143
+ if (points.length === 3) {
144
+ const ray = frame.scene.camera.isOrthographic()
145
+ ? viewport.transformPointToOrthographicRay(point, frame.image, frame.scene.camera)
146
+ : viewport.transformPointToRay(point, frame.image, frame.scene.camera);
147
+ const edge1 = vector3.subtract(points[1], points[0]);
148
+ const edge2 = vector3.subtract(points[2], points[0]);
149
+ const epsilon = boundingBox.epsilon((_a = boundingBox.fromVectors([ray.direction, ray.origin, edge1, edge2])) !== null && _a !== void 0 ? _a : boundingBox.create(edge1, edge2));
150
+ const p = vector3.cross(ray.direction, edge2);
151
+ const det = vector3.dot(edge1, p);
152
+ // This check causes a `det` of NaN or 0 to return false
153
+ // without needing to perform the subsequent calculations.
154
+ if (!(Math.abs(det) >= epsilon)) {
155
+ return false;
156
+ }
157
+ const t = vector3.subtract(ray.origin, points[0]);
158
+ const u = vector3.dot(t, p) / det;
159
+ if (u < 0 || u > 1) {
160
+ return false;
161
+ }
162
+ const q = vector3.cross(t, edge1);
163
+ const v = vector3.dot(ray.direction, q) / det;
164
+ if (v < 0 || u + v > 1) {
165
+ return false;
166
+ }
167
+ const r = vector3.dot(edge2, q) / det;
168
+ // Ignore the case where the computed hit position is negative
169
+ // if in orthographic to correctly return hit results when close
170
+ // to the camera.
171
+ // TODO: revisit with https://vertexvis.atlassian.net/browse/PLAT-1549
172
+ return !isNaN(r) && (r > 0 || frame.scene.camera.isOrthographic());
173
+ }
174
+ return false;
175
+ }
176
+
177
+ class TransformWidget extends ReglComponent {
178
+ constructor(canvasElement, colors = {}, initialDisabledAxes = {}) {
179
+ var _a, _b, _c, _d, _e, _f;
180
+ super(canvasElement);
181
+ this.disabledAxis = {
182
+ xTranslation: false,
183
+ yTranslation: false,
184
+ zTranslation: false,
185
+ xRotation: false,
186
+ yRotation: false,
187
+ zRotation: false,
188
+ };
189
+ this.axisLines = [];
190
+ this.rotationLines = [];
191
+ this.translationMeshes = [];
192
+ this.rotationMeshes = [];
193
+ this.hoveredChanged = new EventDispatcher();
194
+ this.xArrowFillColor = colors.xArrow;
195
+ this.yArrowFillColor = colors.yArrow;
196
+ this.zArrowFillColor = colors.zArrow;
197
+ this.hoveredArrowFillColor = colors.hovered;
198
+ this.outlineColor = colors.outline;
199
+ this.disabledAxis.xTranslation = (_a = initialDisabledAxes.xTranslation) !== null && _a !== void 0 ? _a : false;
200
+ this.disabledAxis.yTranslation = (_b = initialDisabledAxes.yTranslation) !== null && _b !== void 0 ? _b : false;
201
+ this.disabledAxis.zTranslation = (_c = initialDisabledAxes.zTranslation) !== null && _c !== void 0 ? _c : false;
202
+ this.disabledAxis.xRotation = (_d = initialDisabledAxes.xRotation) !== null && _d !== void 0 ? _d : false;
203
+ this.disabledAxis.yRotation = (_e = initialDisabledAxes.yRotation) !== null && _e !== void 0 ? _e : false;
204
+ this.disabledAxis.zRotation = (_f = initialDisabledAxes.zRotation) !== null && _f !== void 0 ? _f : false;
205
+ }
206
+ dispose() {
207
+ var _a;
208
+ (_a = this.reglFrameDisposable) === null || _a === void 0 ? void 0 : _a.cancel();
209
+ }
210
+ /**
211
+ * @internal - visible for testing
212
+ */
213
+ getDrawableElements() {
214
+ return this.drawableElements;
215
+ }
216
+ boundsContainsPoint(point) {
217
+ return (this.bounds != null &&
218
+ this.frame != null &&
219
+ rectangle.containsPoints(this.bounds, point));
220
+ }
221
+ updateDisabledAxis(axis) {
222
+ this.disabledAxis = Object.assign(Object.assign({}, this.disabledAxis), axis);
223
+ this.updateDisabledOnDrawables();
224
+ }
225
+ updateCursor(cursor) {
226
+ this.cursor = cursor;
227
+ if (cursor != null && this.frame != null) {
228
+ this.updateHovered();
229
+ }
230
+ else {
231
+ this.clearHovered();
232
+ }
233
+ }
234
+ updateTransform(transform) {
235
+ var _a;
236
+ this.transform = transform;
237
+ if (transform != null && this.frame != null) {
238
+ this.updateAndDraw();
239
+ }
240
+ else {
241
+ this.clear();
242
+ (_a = this.reglFrameDisposable) === null || _a === void 0 ? void 0 : _a.cancel();
243
+ this.reglFrameDisposable = undefined;
244
+ }
245
+ }
246
+ updateColors(colors = {}) {
247
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
248
+ this.xArrowFillColor = (_a = colors.xArrow) !== null && _a !== void 0 ? _a : this.xArrowFillColor;
249
+ this.yArrowFillColor = (_b = colors.yArrow) !== null && _b !== void 0 ? _b : this.yArrowFillColor;
250
+ this.zArrowFillColor = (_c = colors.zArrow) !== null && _c !== void 0 ? _c : this.zArrowFillColor;
251
+ this.hoveredArrowFillColor = (_d = colors.hovered) !== null && _d !== void 0 ? _d : this.hoveredArrowFillColor;
252
+ this.outlineColor = (_e = colors.outline) !== null && _e !== void 0 ? _e : this.outlineColor;
253
+ (_f = this.xArrow) === null || _f === void 0 ? void 0 : _f.updateFillColor(this.getXTranslationColor());
254
+ (_g = this.yArrow) === null || _g === void 0 ? void 0 : _g.updateFillColor(this.getYTranslationColor());
255
+ (_h = this.zArrow) === null || _h === void 0 ? void 0 : _h.updateFillColor(this.getZTranslationColor());
256
+ (_j = this.xRotation) === null || _j === void 0 ? void 0 : _j.updateFillColor(this.getXRotationColor());
257
+ (_k = this.yRotation) === null || _k === void 0 ? void 0 : _k.updateFillColor(this.getYRotationColor());
258
+ (_l = this.zRotation) === null || _l === void 0 ? void 0 : _l.updateFillColor(this.getZRotationColor());
259
+ (_m = this.hoveredElement) === null || _m === void 0 ? void 0 : _m.updateFillColor(this.hoveredArrowFillColor);
260
+ }
261
+ onHoveredChanged(listener) {
262
+ return this.hoveredChanged.on(listener);
263
+ }
264
+ updateDisabledOnDrawables() {
265
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
266
+ (_a = this.xRotation) === null || _a === void 0 ? void 0 : _a.setDisabled(this.disabledAxis.xRotation);
267
+ (_b = this.xyRotationLine) === null || _b === void 0 ? void 0 : _b.setDisabled(this.disabledAxis.xRotation);
268
+ (_c = this.xzRotationLine) === null || _c === void 0 ? void 0 : _c.setDisabled(this.disabledAxis.xRotation);
269
+ (_d = this.yRotation) === null || _d === void 0 ? void 0 : _d.setDisabled(this.disabledAxis.yRotation);
270
+ (_e = this.yzRotationLine) === null || _e === void 0 ? void 0 : _e.setDisabled(this.disabledAxis.yRotation);
271
+ (_f = this.yxRotationLine) === null || _f === void 0 ? void 0 : _f.setDisabled(this.disabledAxis.yRotation);
272
+ (_g = this.zRotation) === null || _g === void 0 ? void 0 : _g.setDisabled(this.disabledAxis.zRotation);
273
+ (_h = this.zxRotationLine) === null || _h === void 0 ? void 0 : _h.setDisabled(this.disabledAxis.zRotation);
274
+ (_j = this.zyRotationLine) === null || _j === void 0 ? void 0 : _j.setDisabled(this.disabledAxis.zRotation);
275
+ (_k = this.xArrow) === null || _k === void 0 ? void 0 : _k.setDisabled(this.disabledAxis.xTranslation);
276
+ (_l = this.yArrow) === null || _l === void 0 ? void 0 : _l.setDisabled(this.disabledAxis.yTranslation);
277
+ (_m = this.zArrow) === null || _m === void 0 ? void 0 : _m.setDisabled(this.disabledAxis.zTranslation);
278
+ this.updateColors();
279
+ }
280
+ updateHovered() {
281
+ var _a;
282
+ const previousHovered = this.hoveredElement;
283
+ const currentFrame = this.frame;
284
+ if (currentFrame != null) {
285
+ this.hoveredElement = [...this.translationMeshes, ...this.rotationMeshes]
286
+ .filter((el) => el.points.valid && !el.isDisabled())
287
+ .find((m) => this.cursor != null
288
+ ? testDrawable(m, currentFrame, this.viewport, this.cursor)
289
+ : false);
290
+ if (this.hoveredElement !== previousHovered) {
291
+ this.hoveredChanged.emit(this.hoveredElement);
292
+ (_a = this.hoveredElement) === null || _a === void 0 ? void 0 : _a.updateFillColor(this.hoveredArrowFillColor);
293
+ previousHovered === null || previousHovered === void 0 ? void 0 : previousHovered.updateFillColor(previousHovered === null || previousHovered === void 0 ? void 0 : previousHovered.initialFillColor);
294
+ }
295
+ }
296
+ }
297
+ clearHovered() {
298
+ const previousHovered = this.hoveredElement;
299
+ this.hoveredElement = undefined;
300
+ if (this.hoveredElement !== previousHovered) {
301
+ this.hoveredChanged.emit(this.hoveredElement);
302
+ previousHovered.updateFillColor(previousHovered.initialFillColor);
303
+ }
304
+ }
305
+ hasData() {
306
+ return this.transform != null;
307
+ }
308
+ createOrUpdateElements() {
309
+ if (this.transform != null && this.frame != null) {
310
+ if (this.xArrow == null || this.yArrow == null || this.zArrow == null) {
311
+ this.createElements(this.transform, this.frame);
312
+ }
313
+ else {
314
+ this.updateElements(this.transform, this.frame);
315
+ }
316
+ this.bounds = computeDrawable2dBounds(this.viewport, ...this.rotationMeshes, ...this.translationMeshes);
317
+ }
318
+ }
319
+ createElements(transform, frame) {
320
+ this.reglCommand = regl({
321
+ canvas: this.canvasElement,
322
+ extensions: 'angle_instanced_arrays',
323
+ });
324
+ const { createShape } = shapeBuilder(this.reglCommand);
325
+ const triangleSize = this.computeTriangleSize(vector3.fromMatrixPosition(transform), frame);
326
+ this.xArrow = new TriangleMesh(createShape, 'x-translate', xAxisArrowPositions(transform, frame.scene.camera, triangleSize), this.outlineColor, this.getXTranslationColor());
327
+ this.xRotation = new TriangleMesh(createShape, 'x-rotate', xAxisRotationPositions(transform, frame.scene.camera, triangleSize), this.outlineColor, this.getXRotationColor());
328
+ this.xAxis = new AxisLine(createShape, 'x-axis', axisPositions(transform, frame.scene.camera, this.xArrow), this.outlineColor, this.getXTranslationColor());
329
+ this.yArrow = new TriangleMesh(createShape, 'y-translate', yAxisArrowPositions(transform, frame.scene.camera, triangleSize), this.outlineColor, this.getYTranslationColor());
330
+ this.yRotation = new TriangleMesh(createShape, 'y-rotate', yAxisRotationPositions(transform, frame.scene.camera, triangleSize), this.outlineColor, this.getYRotationColor());
331
+ this.yAxis = new AxisLine(createShape, 'y-axis', axisPositions(transform, frame.scene.camera, this.yArrow), this.outlineColor, this.getYTranslationColor());
332
+ this.zArrow = new TriangleMesh(createShape, 'z-translate', zAxisArrowPositions(transform, frame.scene.camera, triangleSize), this.outlineColor, this.getZTranslationColor());
333
+ this.zAxis = new AxisLine(createShape, 'z-axis', axisPositions(transform, frame.scene.camera, this.zArrow), this.outlineColor, this.getZTranslationColor());
334
+ this.zRotation = new TriangleMesh(createShape, 'z-rotate', zAxisRotationPositions(transform, frame.scene.camera, triangleSize), this.outlineColor, this.getZRotationColor());
335
+ this.createRotationLines(createShape, transform, frame);
336
+ this.axisLines = [this.xAxis, this.yAxis, this.zAxis];
337
+ this.translationMeshes = [this.xArrow, this.yArrow, this.zArrow];
338
+ this.rotationMeshes = [this.xRotation, this.yRotation, this.zRotation];
339
+ this.updateDisabledOnDrawables();
340
+ this.availableElements = [
341
+ ...this.axisLines,
342
+ ...this.rotationLines,
343
+ ...this.translationMeshes,
344
+ ...this.rotationMeshes,
345
+ ];
346
+ }
347
+ getXRotationColor() {
348
+ return this.xArrowFillColor;
349
+ }
350
+ getYRotationColor() {
351
+ return this.yArrowFillColor;
352
+ }
353
+ getZRotationColor() {
354
+ return this.zArrowFillColor;
355
+ }
356
+ getXTranslationColor() {
357
+ return this.xArrowFillColor;
358
+ }
359
+ getYTranslationColor() {
360
+ return this.yArrowFillColor;
361
+ }
362
+ getZTranslationColor() {
363
+ return this.zArrowFillColor;
364
+ }
365
+ createRotationLines(createShape, transform, frame) {
366
+ var _a, _b, _c, _d, _e, _f;
367
+ const triangleSize = this.computeTriangleSize(vector3.fromMatrixPosition(transform), frame);
368
+ const xyRotationLinePoints = rotationAxisPositions(frame.scene.camera, this.xRotation, (_a = this.yArrow) === null || _a === void 0 ? void 0 : _a.points.worldTip, triangleSize);
369
+ const xzRotationLinePoints = rotationAxisPositions(frame.scene.camera, this.xRotation, (_b = this.zArrow) === null || _b === void 0 ? void 0 : _b.points.worldTip, triangleSize);
370
+ const yxRotationLinePoints = rotationAxisPositions(frame.scene.camera, this.yRotation, (_c = this.xArrow) === null || _c === void 0 ? void 0 : _c.points.worldTip, triangleSize);
371
+ const yzRotationLinePoints = rotationAxisPositions(frame.scene.camera, this.yRotation, (_d = this.zArrow) === null || _d === void 0 ? void 0 : _d.points.worldTip, triangleSize);
372
+ const zxRotationLinePoints = rotationAxisPositions(frame.scene.camera, this.zRotation, (_e = this.xArrow) === null || _e === void 0 ? void 0 : _e.points.worldTip, triangleSize);
373
+ const zyRotationLinePoints = rotationAxisPositions(frame.scene.camera, this.zRotation, (_f = this.yArrow) === null || _f === void 0 ? void 0 : _f.points.worldTip, triangleSize);
374
+ if (xyRotationLinePoints != null) {
375
+ this.xyRotationLine = new RotationLine(createShape, 'xy-rotation-line', xyRotationLinePoints, this.outlineColor);
376
+ }
377
+ if (xzRotationLinePoints != null) {
378
+ this.xzRotationLine = new RotationLine(createShape, 'xz-rotation-line', xzRotationLinePoints, this.outlineColor);
379
+ }
380
+ if (yxRotationLinePoints != null) {
381
+ this.yxRotationLine = new RotationLine(createShape, 'yx-rotation-line', yxRotationLinePoints, this.outlineColor);
382
+ }
383
+ if (yzRotationLinePoints != null) {
384
+ this.yzRotationLine = new RotationLine(createShape, 'yz-rotation-line', yzRotationLinePoints, this.outlineColor);
385
+ }
386
+ if (zxRotationLinePoints != null) {
387
+ this.zxRotationLine = new RotationLine(createShape, 'zx-rotation-line', zxRotationLinePoints, this.outlineColor);
388
+ }
389
+ if (zyRotationLinePoints != null) {
390
+ this.zyRotationLine = new RotationLine(createShape, 'zy-rotation-line', zyRotationLinePoints, this.outlineColor);
391
+ }
392
+ this.rotationLines = [
393
+ this.xyRotationLine,
394
+ this.xzRotationLine,
395
+ this.yxRotationLine,
396
+ this.yzRotationLine,
397
+ this.zxRotationLine,
398
+ this.zyRotationLine,
399
+ ].filter((l) => l != null);
400
+ }
401
+ updateElements(transform, frame) {
402
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
403
+ const triangleSize = this.computeTriangleSize(vector3.fromMatrixPosition(transform), frame);
404
+ if (this.xArrow != null) {
405
+ this.xArrow.updatePoints(xAxisArrowPositions(transform, frame.scene.camera, triangleSize));
406
+ (_a = this.xAxis) === null || _a === void 0 ? void 0 : _a.updatePoints(axisPositions(transform, frame.scene.camera, this.xArrow));
407
+ }
408
+ (_b = this.xRotation) === null || _b === void 0 ? void 0 : _b.updatePoints(xAxisRotationPositions(transform, frame.scene.camera, triangleSize));
409
+ if (this.yArrow != null) {
410
+ this.yArrow.updatePoints(yAxisArrowPositions(transform, frame.scene.camera, triangleSize));
411
+ (_c = this.yAxis) === null || _c === void 0 ? void 0 : _c.updatePoints(axisPositions(transform, frame.scene.camera, this.yArrow));
412
+ }
413
+ (_d = this.yRotation) === null || _d === void 0 ? void 0 : _d.updatePoints(yAxisRotationPositions(transform, frame.scene.camera, triangleSize));
414
+ if (this.zArrow != null) {
415
+ this.zArrow.updatePoints(zAxisArrowPositions(transform, frame.scene.camera, triangleSize));
416
+ (_e = this.zAxis) === null || _e === void 0 ? void 0 : _e.updatePoints(axisPositions(transform, frame.scene.camera, this.zArrow));
417
+ }
418
+ (_f = this.zRotation) === null || _f === void 0 ? void 0 : _f.updatePoints(zAxisRotationPositions(transform, frame.scene.camera, triangleSize));
419
+ (_g = this.xyRotationLine) === null || _g === void 0 ? void 0 : _g.updatePoints(rotationAxisPositions(frame.scene.camera, this.xRotation, (_h = this.yArrow) === null || _h === void 0 ? void 0 : _h.points.worldTip, triangleSize));
420
+ (_j = this.xzRotationLine) === null || _j === void 0 ? void 0 : _j.updatePoints(rotationAxisPositions(frame.scene.camera, this.xRotation, (_k = this.zArrow) === null || _k === void 0 ? void 0 : _k.points.worldTip, triangleSize));
421
+ (_l = this.yxRotationLine) === null || _l === void 0 ? void 0 : _l.updatePoints(rotationAxisPositions(frame.scene.camera, this.yRotation, (_m = this.xArrow) === null || _m === void 0 ? void 0 : _m.points.worldTip, triangleSize));
422
+ (_o = this.yzRotationLine) === null || _o === void 0 ? void 0 : _o.updatePoints(rotationAxisPositions(frame.scene.camera, this.yRotation, (_p = this.zArrow) === null || _p === void 0 ? void 0 : _p.points.worldTip, triangleSize));
423
+ (_q = this.zxRotationLine) === null || _q === void 0 ? void 0 : _q.updatePoints(rotationAxisPositions(frame.scene.camera, this.zRotation, (_r = this.xArrow) === null || _r === void 0 ? void 0 : _r.points.worldTip, triangleSize));
424
+ (_s = this.zyRotationLine) === null || _s === void 0 ? void 0 : _s.updatePoints(rotationAxisPositions(frame.scene.camera, this.zRotation, (_t = this.yArrow) === null || _t === void 0 ? void 0 : _t.points.worldTip, triangleSize));
425
+ }
426
+ }
427
+
428
+ const viewerTransformWidgetCss = ":host{position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;--viewer-transform-widget-x-axis-arrow-color:var(--x-axis-color);--viewer-transform-widget-y-axis-arrow-color:var(--y-axis-color);--viewer-transform-widget-z-axis-arrow-color:var(--z-axis-color);--viewer-transform-widget-hovered-arrow-color:#ffff00}.widget{position:absolute;top:0;left:0}.widget.hovered{pointer-events:auto}";
429
+
430
+ const ViewerTransformWidget = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
431
+ constructor() {
432
+ super();
433
+ this.__registerHost();
434
+ this.__attachShadow();
435
+ this.positionChanged = createEvent(this, "positionChanged", 7);
436
+ this.rotationChanged = createEvent(this, "rotationChanged", 7);
437
+ this.interactionEnded = createEvent(this, "interactionEnded", 7);
438
+ this.interactionStarted = createEvent(this, "interactionStarted", 7);
439
+ /**
440
+ * Determines whether or not the x-rotation is disabled on the widget
441
+ */
442
+ this.xRotationDisabled = false;
443
+ /**
444
+ * Determines whether or not the y-rotation is disabled on the widget
445
+ */
446
+ this.yRotationDisabled = false;
447
+ /**
448
+ * Determines whether or not the z-rotation is disabled on the widget
449
+ */
450
+ this.zRotationDisabled = false;
451
+ /**
452
+ * Determines whether or not the x-translation is disabled on the widget
453
+ */
454
+ this.xTranslationDisabled = false;
455
+ /**
456
+ * Determines whether or not the y-translation is disabled on the widget
457
+ */
458
+ this.yTranslationDisabled = false;
459
+ /**
460
+ * Determines whether or not the z-translation is disabled on the widget
461
+ */
462
+ this.zTranslationDisabled = false;
463
+ this.xArrowColor = '#ea3324';
464
+ this.yArrowColor = '#4faf32';
465
+ this.zArrowColor = '#0000ff';
466
+ this.hoveredColor = '#ffff00';
467
+ this.lastAngle = 0;
468
+ this.handleHoveredDrawableChanged = (drawable) => {
469
+ this.hovered = drawable;
470
+ };
471
+ this.handleViewerFrameDrawn = () => {
472
+ this.updatePropsFromViewer();
473
+ };
474
+ this.handleViewerDimensionsChange = () => {
475
+ writeDOM(() => {
476
+ if (this.viewer != null && this.canvasRef != null) {
477
+ this.canvasRef.width = this.viewer.viewport.width;
478
+ this.canvasRef.height = this.viewer.viewport.height;
479
+ this.updateCanvasBounds(this.canvasRef);
480
+ }
481
+ });
482
+ };
483
+ this.handleResize = () => {
484
+ if (this.canvasRef != null) {
485
+ this.updateCanvasBounds(this.canvasRef);
486
+ }
487
+ };
488
+ this.handlePointerMove = (event) => {
489
+ if (this.dragging == null) {
490
+ const canvasPoint = convertPointToCanvas(point.create(event.clientX, event.clientY), this.getCanvasBounds());
491
+ const widget = this.getTransformWidget();
492
+ if (canvasPoint != null && widget.boundsContainsPoint(canvasPoint)) {
493
+ widget.updateCursor(canvasPoint);
494
+ }
495
+ else {
496
+ widget.updateCursor(undefined);
497
+ this.hovered = undefined;
498
+ }
499
+ }
500
+ };
501
+ this.handleBeginDrag = async (event) => {
502
+ var _a, _b;
503
+ const canvasBounds = this.getCanvasBounds();
504
+ if (this.hovered != null &&
505
+ canvasBounds != null &&
506
+ this.viewer != null &&
507
+ this.position != null &&
508
+ this.viewer.frame != null) {
509
+ this.dragging = this.hovered;
510
+ const currentCanvas = convertPointToCanvas(point.create(event.clientX, event.clientY), canvasBounds);
511
+ const widgetCenter = this.viewer.viewport.transformWorldToViewport(this.position, this.viewer.frame.scene.camera.projectionViewMatrix);
512
+ this.lastAngle =
513
+ currentCanvas != null
514
+ ? angle.fromPoints(widgetCenter, currentCanvas)
515
+ : 0;
516
+ this.lastWorldPosition = convertCanvasPointToWorld(currentCanvas, (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.frame, (_b = this.viewer) === null || _b === void 0 ? void 0 : _b.viewport, this.currentTransform);
517
+ this.interactionStarted.emit();
518
+ window.removeEventListener('pointermove', this.handlePointerMove);
519
+ window.addEventListener('pointermove', this.handleDrag);
520
+ window.addEventListener('pointerup', this.handleEndTransform);
521
+ }
522
+ };
523
+ this.handleDrag = async (event) => {
524
+ var _a, _b, _c;
525
+ // Prevent selection of text and interaction with view cube while dragging the widget
526
+ event.preventDefault();
527
+ const canvasBounds = this.getCanvasBounds();
528
+ if (this.dragging != null &&
529
+ this.lastWorldPosition != null &&
530
+ canvasBounds != null &&
531
+ this.viewer != null &&
532
+ this.viewer.frame != null &&
533
+ this.position != null) {
534
+ // Begin the transform on the first `pointermove` event as opposed to the
535
+ // `pointerdown` to prevent accidental no-op transforms (identity matrix).
536
+ await ((_a = this.controller) === null || _a === void 0 ? void 0 : _a.beginTransform());
537
+ const currentCanvas = convertPointToCanvas(point.create(event.clientX, event.clientY), canvasBounds);
538
+ const widgetCenter = this.viewer.viewport.transformWorldToViewport(this.position, this.viewer.frame.scene.camera.projectionViewMatrix);
539
+ const currentWorld = convertCanvasPointToWorld(currentCanvas, (_b = this.viewer) === null || _b === void 0 ? void 0 : _b.frame, (_c = this.viewer) === null || _c === void 0 ? void 0 : _c.viewport, this.currentTransform);
540
+ if (currentWorld != null &&
541
+ currentCanvas != null &&
542
+ widgetCenter != null) {
543
+ const angle$1 = angle.fromPoints(widgetCenter, currentCanvas);
544
+ this.transform(this.lastWorldPosition, currentWorld, angle$1 - this.lastAngle);
545
+ this.lastWorldPosition = currentWorld;
546
+ this.lastAngle = angle$1;
547
+ }
548
+ }
549
+ };
550
+ this.handleEndTransform = async (event) => {
551
+ var _a, _b;
552
+ const canvasPoint = convertPointToCanvas(point.create(event.clientX, event.clientY), this.getCanvasBounds());
553
+ const widget = this.getTransformWidget();
554
+ this.dragging = undefined;
555
+ this.lastWorldPosition = undefined;
556
+ this.position =
557
+ this.currentTransform != null
558
+ ? vector3.fromMatrixPosition(this.currentTransform)
559
+ : this.position;
560
+ this.lastAngle = 0;
561
+ widget.updateCursor(canvasPoint);
562
+ widget.updateTransform(this.currentTransform);
563
+ widget.updateDisabledAxis({
564
+ xRotation: true,
565
+ yRotation: true,
566
+ zRotation: true,
567
+ xTranslation: true,
568
+ yTranslation: true,
569
+ zTranslation: true,
570
+ });
571
+ window.removeEventListener('pointermove', this.handleDrag);
572
+ window.removeEventListener('pointerup', this.handleEndTransform);
573
+ try {
574
+ const delta = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.getCurrentDelta();
575
+ await ((_b = this.controller) === null || _b === void 0 ? void 0 : _b.endTransform());
576
+ this.interactionEnded.emit(delta);
577
+ }
578
+ catch (e) {
579
+ console.error('Failed to end transform interaction', e);
580
+ }
581
+ window.addEventListener('pointermove', this.handlePointerMove);
582
+ this.getTransformWidget().updateDisabledAxis({
583
+ xRotation: this.xRotationDisabled,
584
+ yRotation: this.yRotationDisabled,
585
+ zRotation: this.zRotationDisabled,
586
+ xTranslation: this.xTranslationDisabled,
587
+ yTranslation: this.yTranslationDisabled,
588
+ zTranslation: this.zTranslationDisabled,
589
+ });
590
+ };
591
+ this.updatePropsFromViewer = () => {
592
+ const { frame } = this.viewer || {};
593
+ if (frame != null) {
594
+ const widget = this.getTransformWidget();
595
+ widget.updateFrame(frame, this.dragging == null);
596
+ }
597
+ };
598
+ this.setupTransformWidget = (canvasRef) => {
599
+ var _a, _b;
600
+ console.debug(`Initializing transform widget. [initial-position=${JSON.stringify(this.position)}, has-initial-frame=${((_a = this.viewer) === null || _a === void 0 ? void 0 : _a.frame) != null}]`);
601
+ this.widget = new TransformWidget(canvasRef, {
602
+ xArrow: this.xArrowColor,
603
+ yArrow: this.yArrowColor,
604
+ zArrow: this.zArrowColor,
605
+ hovered: this.hoveredColor,
606
+ });
607
+ if (this.rotation != null) {
608
+ this.currentTransform = this.getTransformForNewRotation(this.rotation);
609
+ this.startingTransform = this.currentTransform;
610
+ this.widget.updateTransform(this.currentTransform);
611
+ }
612
+ if (this.position != null) {
613
+ this.currentTransform = this.getTransformForNewPosition(this.position);
614
+ this.startingTransform = this.currentTransform;
615
+ this.widget.updateTransform(this.currentTransform);
616
+ }
617
+ if (((_b = this.viewer) === null || _b === void 0 ? void 0 : _b.frame) != null) {
618
+ this.widget.updateFrame(this.viewer.frame, true);
619
+ }
620
+ this.handleSettingDisabledAxis();
621
+ this.hoveredChangeDisposable = this.widget.onHoveredChanged(this.handleHoveredDrawableChanged);
622
+ return this.widget;
623
+ };
624
+ this.updateCanvasBounds = (canvasElement) => {
625
+ readDOM(() => {
626
+ this.canvasBounds = canvasElement.getBoundingClientRect();
627
+ this.getTransformWidget().updateDimensions(canvasElement);
628
+ });
629
+ };
630
+ this.getTransformForNewPosition = (newPosition) => {
631
+ if (newPosition != null) {
632
+ const c = this.currentTransform != null
633
+ ? this.currentTransform
634
+ : matrix4.makeIdentity();
635
+ const currentRotation = matrix4.makeRotation(quaternion.fromMatrixRotation(c));
636
+ const position = matrix4.makeTranslation(newPosition);
637
+ return matrix4.multiply(position, currentRotation);
638
+ }
639
+ else if (newPosition != null) {
640
+ return matrix4.makeTranslation(newPosition);
641
+ }
642
+ };
643
+ this.getTransformForNewRotation = (newRotationEuler) => {
644
+ const c = this.currentTransform != null
645
+ ? this.currentTransform
646
+ : matrix4.makeIdentity();
647
+ const oldRotation = matrix4.invert(matrix4.makeRotation(quaternion.fromMatrixRotation(c)));
648
+ const newRotation = matrix4.makeRotation(quaternion.fromEuler(newRotationEuler));
649
+ const oldTranslation = matrix4.multiply(c, oldRotation);
650
+ return matrix4.multiply(oldTranslation, newRotation);
651
+ };
652
+ this.getCanvasBounds = () => {
653
+ if (this.canvasBounds != null) {
654
+ return this.canvasBounds;
655
+ }
656
+ else if (this.canvasRef != null) {
657
+ this.updateCanvasBounds(this.canvasRef);
658
+ return this.canvasBounds;
659
+ }
660
+ };
661
+ this.getTransformWidget = () => {
662
+ if (this.widget == null && this.canvasRef != null) {
663
+ return this.setupTransformWidget(this.canvasRef);
664
+ }
665
+ else if (this.widget != null) {
666
+ return this.widget;
667
+ }
668
+ else {
669
+ throw new Error('Transform widget was not initialized. The canvas element may not have been initialized.');
670
+ }
671
+ };
672
+ }
673
+ componentDidLoad() {
674
+ window.addEventListener('pointermove', this.handlePointerMove);
675
+ this.canvasResizeObserver = new ResizeObserver(this.handleResize);
676
+ if (this.canvasRef != null) {
677
+ this.canvasResizeObserver.observe(this.canvasRef);
678
+ this.setupTransformWidget(this.canvasRef);
679
+ }
680
+ this.handleViewerChanged(this.viewer, undefined);
681
+ readDOM(() => {
682
+ const hostStyles = window.getComputedStyle(this.hostEl);
683
+ this.xArrowColor = hostStyles
684
+ .getPropertyValue('--viewer-transform-widget-x-axis-arrow-color')
685
+ .trim();
686
+ this.yArrowColor = hostStyles
687
+ .getPropertyValue('--viewer-transform-widget-y-axis-arrow-color')
688
+ .trim();
689
+ this.zArrowColor = hostStyles
690
+ .getPropertyValue('--viewer-transform-widget-z-axis-arrow-color')
691
+ .trim();
692
+ this.hoveredColor = hostStyles
693
+ .getPropertyValue('--viewer-transform-widget-hovered-arrow-color')
694
+ .trim();
695
+ });
696
+ }
697
+ disconnectedCallback() {
698
+ var _a, _b, _c;
699
+ window.removeEventListener('pointermove', this.handlePointerMove);
700
+ (_a = this.canvasResizeObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
701
+ (_b = this.hoveredChangeDisposable) === null || _b === void 0 ? void 0 : _b.dispose();
702
+ (_c = this.widget) === null || _c === void 0 ? void 0 : _c.dispose();
703
+ }
704
+ /**
705
+ * @ignore
706
+ */
707
+ handleViewerChanged(newViewer, oldViewer) {
708
+ var _a;
709
+ oldViewer === null || oldViewer === void 0 ? void 0 : oldViewer.removeEventListener('frameDrawn', this.handleViewerFrameDrawn);
710
+ oldViewer === null || oldViewer === void 0 ? void 0 : oldViewer.removeEventListener('dimensionschange', this.handleViewerDimensionsChange);
711
+ newViewer === null || newViewer === void 0 ? void 0 : newViewer.addEventListener('frameDrawn', this.handleViewerFrameDrawn);
712
+ newViewer === null || newViewer === void 0 ? void 0 : newViewer.addEventListener('dimensionschange', this.handleViewerDimensionsChange);
713
+ if ((newViewer === null || newViewer === void 0 ? void 0 : newViewer.stream) != null) {
714
+ (_a = this.controller) === null || _a === void 0 ? void 0 : _a.dispose();
715
+ this.controller = new TransformController(newViewer.stream);
716
+ }
717
+ }
718
+ /**
719
+ * @ignore
720
+ */
721
+ handleDisabledPropertyChanged() {
722
+ var _a;
723
+ (_a = this.widget) === null || _a === void 0 ? void 0 : _a.updateDisabledAxis({
724
+ xRotation: this.xRotationDisabled,
725
+ yRotation: this.yRotationDisabled,
726
+ zRotation: this.zRotationDisabled,
727
+ xTranslation: this.xTranslationDisabled,
728
+ yTranslation: this.yTranslationDisabled,
729
+ zTranslation: this.zTranslationDisabled,
730
+ });
731
+ }
732
+ /**
733
+ * @ignore
734
+ */
735
+ handleRotationChanged(newRotation, oldRotation) {
736
+ var _a;
737
+ this.currentTransform = this.getTransformForNewRotation(newRotation);
738
+ this.startingTransform = this.currentTransform;
739
+ (_a = this.widget) === null || _a === void 0 ? void 0 : _a.updateTransform(this.currentTransform);
740
+ console.debug(`Updating widget rotation [previous=${JSON.stringify(oldRotation)}, current=${JSON.stringify(newRotation)}]`);
741
+ this.rotationChanged.emit(newRotation);
742
+ }
743
+ /**
744
+ * @ignore
745
+ */
746
+ handlePositionChanged(newPosition, oldPosition) {
747
+ var _a, _b;
748
+ this.currentTransform = this.getTransformForNewPosition(newPosition);
749
+ this.startingTransform = this.currentTransform;
750
+ console.debug(`Updating widget position [previous=${JSON.stringify(oldPosition)}, current=${JSON.stringify(newPosition)}]`);
751
+ (_a = this.widget) === null || _a === void 0 ? void 0 : _a.updateTransform(this.currentTransform);
752
+ if (newPosition == null) {
753
+ (_b = this.controller) === null || _b === void 0 ? void 0 : _b.clearTransform();
754
+ }
755
+ this.positionChanged.emit(newPosition);
756
+ }
757
+ render() {
758
+ var _a, _b;
759
+ return (h(Host, null, h("canvas", { ref: (el) => {
760
+ this.canvasRef = el;
761
+ }, class: classnames('widget', {
762
+ hovered: this.hovered != null,
763
+ }), width: (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.viewport.width, height: (_b = this.viewer) === null || _b === void 0 ? void 0 : _b.viewport.height, onPointerDown: this.handleBeginDrag })));
764
+ }
765
+ transform(previous, next, angle) {
766
+ var _a, _b;
767
+ if (this.position != null &&
768
+ this.startingTransform != null &&
769
+ this.currentTransform != null &&
770
+ this.dragging != null &&
771
+ this.viewer != null &&
772
+ this.viewer.frame != null) {
773
+ this.currentTransform = computeUpdatedTransform(this.currentTransform, previous, next, (_a = this.viewer) === null || _a === void 0 ? void 0 : _a.frame.scene.camera.viewVector, angle, this.dragging.identifier);
774
+ this.getTransformWidget().updateTransform(this.currentTransform);
775
+ (_b = this.controller) === null || _b === void 0 ? void 0 : _b.updateTransform(matrix4.multiply(this.currentTransform, matrix4.invert(this.startingTransform)));
776
+ }
777
+ }
778
+ handleSettingDisabledAxis() {
779
+ if (this.widget) {
780
+ this.widget.updateDisabledAxis({
781
+ xRotation: this.xRotationDisabled,
782
+ yRotation: this.yRotationDisabled,
783
+ zRotation: this.zRotationDisabled,
784
+ xTranslation: this.xTranslationDisabled,
785
+ yTranslation: this.yTranslationDisabled,
786
+ zTranslation: this.zTranslationDisabled,
787
+ });
788
+ }
789
+ else {
790
+ console.warn('Cannot set disabled values - no widget defined');
791
+ }
792
+ }
793
+ get hostEl() { return this; }
794
+ static get watchers() { return {
795
+ "viewer": ["handleViewerChanged"],
796
+ "xTranslationDisabled": ["handleDisabledPropertyChanged"],
797
+ "yTranslationDisabled": ["handleDisabledPropertyChanged"],
798
+ "zTranslationDisabled": ["handleDisabledPropertyChanged"],
799
+ "xRotationDisabled": ["handleDisabledPropertyChanged"],
800
+ "yRotationDisabled": ["handleDisabledPropertyChanged"],
801
+ "zRotationDisabled": ["handleDisabledPropertyChanged"],
802
+ "rotation": ["handleRotationChanged"],
803
+ "position": ["handlePositionChanged"]
804
+ }; }
805
+ static get style() { return viewerTransformWidgetCss; }
806
+ }, [1, "vertex-viewer-transform-widget", {
807
+ "viewer": [16],
808
+ "position": [1040],
809
+ "rotation": [1040],
810
+ "controller": [1040],
811
+ "xRotationDisabled": [1028, "x-rotation-disabled"],
812
+ "yRotationDisabled": [1028, "y-rotation-disabled"],
813
+ "zRotationDisabled": [1028, "z-rotation-disabled"],
814
+ "xTranslationDisabled": [1028, "x-translation-disabled"],
815
+ "yTranslationDisabled": [1028, "y-translation-disabled"],
816
+ "zTranslationDisabled": [1028, "z-translation-disabled"],
817
+ "hovered": [1040]
818
+ }]);
819
+ function defineCustomElement$1() {
820
+ if (typeof customElements === "undefined") {
821
+ return;
822
+ }
823
+ const components = ["vertex-viewer-transform-widget"];
824
+ components.forEach(tagName => { switch (tagName) {
825
+ case "vertex-viewer-transform-widget":
826
+ if (!customElements.get(tagName)) {
827
+ customElements.define(tagName, ViewerTransformWidget);
828
+ }
829
+ break;
830
+ } });
831
+ }
832
+
833
+ const VertexViewerTransformWidget = ViewerTransformWidget;
834
+ const defineCustomElement = defineCustomElement$1;
835
+
836
+ export { VertexViewerTransformWidget, defineCustomElement };
837
+
838
+ //# sourceMappingURL=vertex-viewer-transform-widget.js.map