three-render-objects 1.35.0 → 1.36.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.
package/README.md CHANGED
@@ -80,9 +80,9 @@ new ThreeRenderObjects(<domElement>, { configOptions })
80
80
 
81
81
  | Method | Description | Default |
82
82
  | --- | --- | :--: |
83
- | <b>onClick</b>(<i>fn</i>) | Callback function for object clicks with left mouse button. The object (or `null` if there's no object under the mouse line of sight), the event object and the coordinates of the intersecting point in the object's surface are included as arguments `onClick(object, event, { x, y, z })`. | - |
84
- | <b>onRightClick</b>(<i>fn</i>) | Callback function for object right-clicks. The object (or `null` if there's no object under the mouse line of sight), the event object and the coordinates of the intersecting point in the object's surface are included as arguments `onRightClick(object, event, { x, y, z })`. | - |
85
- | <b>onHover</b>(<i>fn</i>) | Callback function for object mouse over events. The object (or `null` if there's no object under the mouse line of sight) is included as the first argument, and the previous hovered object (or `null`) as second argument: `onHover(obj, prevObj)`. | - |
83
+ | <b>onClick</b>(<i>fn</i>) | Callback function for object clicks with left mouse button. The object (or `null` if there's no object under the mouse line of sight), the event object and the intersection object are included as arguments `onClick(object, event, intersection)`. | - |
84
+ | <b>onRightClick</b>(<i>fn</i>) | Callback function for object right-clicks. The object (or `null` if there's no object under the mouse line of sight), the event object and the intersection object are included as arguments `onRightClick(object, event, intersection)`. | - |
85
+ | <b>onHover</b>(<i>fn</i>) | Callback function for object mouse over events. The object (or `null` if there's no object under the mouse line of sight), the previous hovered object (or `null`) and the intersection object are included as arguments: `onHover(obj, prevObj, intersection)`. | - |
86
86
  | <b>hoverOrderComparator</b>([<i>fn</i>]) | Getter/setter for the comparator function to use when hovering over multiple objects under the same line of sight. This function can be used to prioritize hovering some objects over others. | By default, hovering priority is based solely on camera proximity (closest object wins). |
87
87
  | <b>hoverFilter</b>([<i>fn</i>]) | Getter/setter for the filter function that defines whether an object is eligible for hovering and other interactions. This function receives an object as sole argument and should return a `boolean` value | `() => true` |
88
88
  | <b>lineHoverPrecision</b>([<i>int</i>]) | Getter/setter for the precision to use when detecting hover events over [Line](https://threejs.org/docs/#api/objects/Line) objects. | 1 |
@@ -59,9 +59,9 @@ declare class ThreeRenderObjectsGeneric<ChainableInstance> {
59
59
  controls(): TrackballControls | OrbitControls | FlyControls;
60
60
 
61
61
  // Interaction
62
- onClick(callback: (obj: object | null, event: MouseEvent, intersectionPoint: { x: number, y: number, z: number }) => void): ChainableInstance;
63
- onRightClick(callback: (obj: object | null, event: MouseEvent, intersectionPoint: { x: number, y: number, z: number }) => void): ChainableInstance;
64
- onHover(callback: (obj: object | null, previousObj: object | null) => void): ChainableInstance;
62
+ onClick(callback: (obj: object | null, event: MouseEvent, intersection: Intersection) => void): ChainableInstance;
63
+ onRightClick(callback: (obj: object | null, event: MouseEvent, intersection: Intersection) => void): ChainableInstance;
64
+ onHover(callback: (obj: object | null, previousObj: object | null, intersection: Intersection | null) => void): ChainableInstance;
65
65
  hoverOrderComparator(): Obj3DCompFn;
66
66
  hoverOrderComparator(compFn: Obj3DCompFn): ChainableInstance;
67
67
  hoverFilter(): (obj: Object3D) => boolean;
@@ -1,4 +1,4 @@
1
- // Version 1.35.0 three-render-objects - https://github.com/vasturiano/three-render-objects
1
+ // Version 1.36.0 three-render-objects - https://github.com/vasturiano/three-render-objects
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('three')) :
4
4
  typeof define === 'function' && define.amd ? define(['three'], factory) :
@@ -77547,7 +77547,8 @@ var<${access}> ${name} : ${structName};`;
77547
77547
  return t(G(o));
77548
77548
  };
77549
77549
  var render = function render(jsx, domEl) {
77550
- return D(_reactElement2VNode(jsx), domEl);
77550
+ delete domEl.__k; // Wipe traces of previous preact renders
77551
+ D(_reactElement2VNode(jsx), domEl);
77551
77552
  };
77552
77553
 
77553
77554
  function styleInject(css, ref) {
@@ -77582,7 +77583,14 @@ var<${access}> ${name} : ${structName};`;
77582
77583
  props: {
77583
77584
  content: {
77584
77585
  "default": false
77585
- }
77586
+ },
77587
+ offsetX: {
77588
+ triggerUpdate: false
77589
+ },
77590
+ // null or number
77591
+ offsetY: {
77592
+ triggerUpdate: false
77593
+ } // null or number
77586
77594
  },
77587
77595
  init: function init(domNode, state) {
77588
77596
  var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
@@ -77602,24 +77610,27 @@ var<${access}> ${name} : ${structName};`;
77602
77610
  });
77603
77611
  state.tooltipEl // start off-screen
77604
77612
  .style('left', '-10000px').style('display', 'none');
77613
+ var evSuffix = "tooltip-".concat(Math.round(Math.random() * 1e12));
77605
77614
  state.mouseInside = false;
77606
- el.on('mousemove.tooltip', function (ev) {
77615
+ el.on("mousemove.".concat(evSuffix), function (ev) {
77607
77616
  state.mouseInside = true;
77608
77617
  var mousePos = pointer(ev);
77609
77618
  var domNode = el.node();
77610
77619
  var canvasWidth = domNode.offsetWidth;
77611
77620
  var canvasHeight = domNode.offsetHeight;
77612
- state.tooltipEl.style('left', mousePos[0] + 'px').style('top', mousePos[1] + 'px')
77613
- // adjust horizontal position to not exceed canvas boundaries
77614
- .style('transform', "translate(-".concat(mousePos[0] / canvasWidth * 100, "%, ").concat(
77615
- // flip to above if near bottom
77616
- canvasHeight > 130 && canvasHeight - mousePos[1] < 100 ? 'calc(-100% - 6px)' : '21px', ")"));
77621
+ var translate = [state.offsetX === null || state.offsetX === undefined
77622
+ // auto: adjust horizontal position to not exceed canvas boundaries
77623
+ ? "-".concat(mousePos[0] / canvasWidth * 100, "%") : typeof state.offsetX === 'number' ? "calc(-50% + ".concat(state.offsetX, "px)") : state.offsetX, state.offsetY === null || state.offsetY === undefined
77624
+ // auto: flip to above if near bottom
77625
+ ? canvasHeight > 130 && canvasHeight - mousePos[1] < 100 ? 'calc(-100% - 6px)' : '21px' : typeof state.offsetY === 'number' ? state.offsetY < 0 ? "calc(-100% - ".concat(Math.abs(state.offsetY), "px)") : "".concat(state.offsetY, "px") : state.offsetY];
77626
+ state.tooltipEl.style('left', mousePos[0] + 'px').style('top', mousePos[1] + 'px').style('transform', "translate(".concat(translate.join(','), ")"));
77627
+ state.content && state.tooltipEl.style('display', 'inline');
77617
77628
  });
77618
- el.on('mouseover.tooltip', function () {
77629
+ el.on("mouseover.".concat(evSuffix), function () {
77619
77630
  state.mouseInside = true;
77620
77631
  state.content && state.tooltipEl.style('display', 'inline');
77621
77632
  });
77622
- el.on('mouseout.tooltip', function () {
77633
+ el.on("mouseout.".concat(evSuffix), function () {
77623
77634
  state.mouseInside = false;
77624
77635
  state.tooltipEl.style('display', 'none');
77625
77636
  });
@@ -77769,10 +77780,10 @@ var<${access}> ${name} : ${structName};`;
77769
77780
  });
77770
77781
  var topIntersect = intersects.length ? intersects[0] : null;
77771
77782
  topObject = topIntersect ? topIntersect.object : null;
77772
- state.intersectionPoint = topIntersect ? topIntersect.point : null;
77783
+ state.intersection = topIntersect || null;
77773
77784
  }
77774
77785
  if (topObject !== state.hoverObj) {
77775
- state.onHover(topObject, state.hoverObj);
77786
+ state.onHover(topObject, state.hoverObj, state.intersection);
77776
77787
  state.tooltip.content(topObject ? index$2(state.tooltipContent)(topObject) || null : null);
77777
77788
  state.hoverObj = topObject;
77778
77789
  }
@@ -78025,11 +78036,11 @@ var<${access}> ${name} : ${structName};`;
78025
78036
  // trigger click events asynchronously, to allow hoverObj to be set (on frame)
78026
78037
  if (ev.button === 0) {
78027
78038
  // left-click
78028
- state.onClick(state.hoverObj || null, ev, state.intersectionPoint); // trigger background clicks with null
78039
+ state.onClick(state.hoverObj || null, ev, state.intersection); // trigger background clicks with null
78029
78040
  }
78030
78041
  if (ev.button === 2 && state.onRightClick) {
78031
78042
  // right-click
78032
- state.onRightClick(state.hoverObj || null, ev, state.intersectionPoint);
78043
+ state.onRightClick(state.hoverObj || null, ev, state.intersection);
78033
78044
  }
78034
78045
  });
78035
78046
  }, {