@needle-tools/engine 4.12.1-next.d0e7ab9 → 4.12.2

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.
@@ -224,7 +224,7 @@ export class NeedleEngineWebComponent extends HTMLElement {
224
224
  <canvas></canvas>
225
225
  </div>
226
226
  <div class="content">
227
- <slot class="overlay-content"></slot>
227
+ <slot class="overlay-content" style="display: contents;"></slot>
228
228
  </div>
229
229
  `;
230
230
  // #endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/engine",
3
- "version": "4.12.1-next.d0e7ab9",
3
+ "version": "4.12.2",
4
4
  "description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.",
5
5
  "main": "dist/needle-engine.min.js",
6
6
  "exports": {
@@ -176,4 +176,4 @@
176
176
  "module": "lib/needle-engine.js",
177
177
  "typings": "lib/needle-engine.d.ts",
178
178
  "types": "lib/needle-engine.d.ts"
179
- }
179
+ }
@@ -110,7 +110,11 @@ function onParseError(args: Array<any>) {
110
110
  export function addLog(type: LogType, message: string | any[], _file?: string | null, _line?: number | null) {
111
111
  if (hide) return;
112
112
  const context = ContextRegistry.Current;
113
- const domElement = context?.domElement ?? document.querySelector("needle-engine");
113
+ let domElement = context?.domElement ?? document.querySelector("needle-engine");
114
+ // check if we're in webxr dom overlay
115
+ if (context.isInAR) {
116
+ domElement = context.arOverlayElement;
117
+ }
114
118
  if (!domElement) return;
115
119
  if (Array.isArray(message)) {
116
120
  let newMessage = "";
@@ -176,7 +176,7 @@ export class ButtonsFactory {
176
176
  * The QR code will be generated with the current URL when the button is clicked
177
177
  * @returns the QR code button element
178
178
  */
179
- createQRCode(): HTMLButtonElement {
179
+ createQRCode(opts?: { anchorElement?: HTMLElement }): HTMLButtonElement {
180
180
 
181
181
  if (this._qrButton) return this._qrButton;
182
182
 
@@ -223,7 +223,7 @@ export class ButtonsFactory {
223
223
  // TODO: we would need to search for the right engine element to insert this into if there are more
224
224
  // Insert the QR code overlay inside the needle-engine element
225
225
  const engine_element = document.body.querySelector("needle-engine");
226
- const parent = engine_element || document.body;
226
+ const parent = opts?.anchorElement?.parentElement || engine_element || document.body;
227
227
  parent.appendChild(qrCodeContainer);
228
228
  const containerRect = qrCodeElement.getBoundingClientRect();
229
229
  const buttonRect = qrCodeButton.getBoundingClientRect();
@@ -1,4 +1,5 @@
1
1
  import { isDevEnvironment } from "../debug/index.js";
2
+ import { ButtonsFactory } from "./buttons.js";
2
3
  import { iconFontUrl, loadFont } from "./fonts.js";
3
4
  import { WebXRButtonFactory } from "./WebXRButtons.js";
4
5
 
@@ -41,7 +42,7 @@ const isDev = isDevEnvironment();
41
42
  */
42
43
  export class NeedleButtonElement extends HTMLElement {
43
44
 
44
- static observedAttributes = ["ar", "vr", "quicklook"];
45
+ static observedAttributes = ["ar", "vr", "quicklook", "qrcode"];
45
46
 
46
47
  constructor() {
47
48
  super();
@@ -62,13 +63,13 @@ export class NeedleButtonElement extends HTMLElement {
62
63
  #button: HTMLButtonElement | undefined;
63
64
  /** If AR or VR is requested we create and use the webxr button factory to create a button with default behaviour */
64
65
  #webxrfactory: WebXRButtonFactory | undefined;
66
+ #buttonfactory: ButtonsFactory | undefined;
65
67
 
66
68
  #observer: MutationObserver | undefined;
67
69
 
68
70
  #update() {
69
71
  this.#button?.remove();
70
72
 
71
-
72
73
  if (this.getAttribute("ar") != null) {
73
74
  this.#webxrfactory ??= new WebXRButtonFactory()
74
75
  this.#button = this.#webxrfactory.createARButton();
@@ -81,11 +82,15 @@ export class NeedleButtonElement extends HTMLElement {
81
82
  this.#webxrfactory ??= new WebXRButtonFactory()
82
83
  this.#button = this.#webxrfactory.createQuicklookButton();
83
84
  }
85
+ else if (this.getAttribute("qrcode") != null) {
86
+ this.#buttonfactory ??= new ButtonsFactory();
87
+ this.#button = this.#buttonfactory.createQRCode({ anchorElement: this });
88
+ }
84
89
  else {
85
90
  if (isDev) {
86
91
  console.warn("No button type specified for <needle-button>. Use either ar, vr or quicklook attribute.")
87
92
  }
88
- else {
93
+ else {
89
94
  console.debug("No button type specified for <needle-button>. Use either ar, vr or quicklook attribute.")
90
95
  }
91
96
  return;
@@ -96,30 +101,29 @@ export class NeedleButtonElement extends HTMLElement {
96
101
  this.#styles ??= document.createElement("style");
97
102
  this.#styles.innerHTML = `
98
103
  button {
99
- all: initial;
100
- cursor: inherit;
101
- color: inherit;
102
- font-family: inherit;
103
- gap: inherit;
104
- white-space: nowrap;
104
+ all: unset;
105
105
  }
106
106
  `;
107
107
  const hasUnstyledAttribute = this.getAttribute("unstyled") != undefined;
108
108
  if (!hasUnstyledAttribute) {
109
109
  this.#styles.innerHTML += `
110
110
  :host {
111
- display: inline-block;
112
- background: rgba(255, 255, 255, .8);
113
- backdrop-filter: blur(10px);
111
+ display: inline-flex;
112
+ align-items: center;
113
+ justify-content: center;
114
114
  width: fit-content;
115
- transition: background .2s;
116
115
 
117
- cursor: pointer;
118
116
  padding: 0.4rem .5rem;
119
- border-radius: 0.8rem;
120
- color: black;
117
+ border-radius: 100vw;
118
+
121
119
  background: rgba(245, 245, 245, .8);
120
+ backdrop-filter: blur(10px);
121
+
122
+ cursor: pointer;
123
+ color: black;
122
124
  outline: rgba(0,0,0,.05) 1px solid;
125
+
126
+ transition: all .2s;
123
127
  }
124
128
  :host(:hover) {
125
129
  background: rgba(255, 255, 255, 1);
@@ -152,8 +156,8 @@ export class NeedleButtonElement extends HTMLElement {
152
156
  this.#observer?.disconnect();
153
157
  this.#observer ??= new MutationObserver(() => this.#updateVisibility());
154
158
  this.#observer.observe(this.#button, { attributes: true });
155
- if(isDev) {
156
- console.log("Needle Button updated")
159
+ if (isDev) {
160
+ console.log("Needle Button updated", this);
157
161
  }
158
162
  }
159
163
 
@@ -170,7 +174,7 @@ export class NeedleButtonElement extends HTMLElement {
170
174
 
171
175
  #onclick = (_ev: MouseEvent) => {
172
176
  if (isDev) {
173
- console.log("Needle Button clicked")
177
+ console.log("Needle Button clicked", { defaultPrevented: _ev.defaultPrevented, hasButton: !!this.#button });
174
178
  }
175
179
  if (_ev.defaultPrevented) return;
176
180
 
@@ -120,6 +120,7 @@ export class AROverlayHandler {
120
120
 
121
121
 
122
122
  const quitARSlot = document.createElement("slot");
123
+ quitARSlot.style.display = "contents";
123
124
  quitARSlot.setAttribute("name", "quit-ar");
124
125
  this.appendElement(quitARSlot, element);
125
126
  this._createdAROnlyElements.push(quitARSlot);
@@ -254,7 +254,7 @@ export class NeedleEngineWebComponent extends HTMLElement implements INeedleEngi
254
254
  <canvas></canvas>
255
255
  </div>
256
256
  <div class="content">
257
- <slot class="overlay-content"></slot>
257
+ <slot class="overlay-content" style="display: contents;"></slot>
258
258
  </div>
259
259
  `;
260
260
  // #endregion