softbox 4.23.0 → 4.24.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.
@@ -492,7 +492,7 @@ var Jt = class {
492
492
  }
493
493
  }, Yt = class {
494
494
  constructor(e) {
495
- this.currentModel = null, this.currentVariants = [], this.modelLoader = e.modelLoader, this.scene = e.scene, this.camera = e.camera, this.controls = e.controls, this.floorAlignmentService = e.floorAlignmentService, this.sceneSetupService = e.sceneSetupService, this.autoFitToObject = e.autoFitToObject ?? !1, this.floorAlignment = e.floorAlignment ?? !0, this.unitsScaleToMeters = e.unitsScaleToMeters ?? 1;
495
+ this.currentModel = null, this.currentModelUrl = null, this.currentVariants = [], this.modelLoader = e.modelLoader, this.scene = e.scene, this.camera = e.camera, this.controls = e.controls, this.floorAlignmentService = e.floorAlignmentService, this.sceneSetupService = e.sceneSetupService, this.autoFitToObject = e.autoFitToObject ?? !1, this.floorAlignment = e.floorAlignment ?? !0, this.unitsScaleToMeters = e.unitsScaleToMeters ?? 1;
496
496
  }
497
497
  getCurrentModel() {
498
498
  return this.currentModel;
@@ -500,6 +500,9 @@ var Jt = class {
500
500
  getLastModelUrl() {
501
501
  return this.lastModelUrl;
502
502
  }
503
+ getCurrentModelUrl() {
504
+ return this.currentModelUrl;
505
+ }
503
506
  getVariantNames() {
504
507
  return [...this.currentVariants];
505
508
  }
@@ -517,8 +520,8 @@ var Jt = class {
517
520
  });
518
521
  });
519
522
  if (!t.ok) throw t.error;
520
- o = t.value.scene, this.currentVariants = t.value.userData?.softboxVariants ?? [];
521
- } else o = e, this.currentVariants = [];
523
+ o = t.value.scene, this.currentModelUrl = e, this.currentVariants = t.value.userData?.softboxVariants ?? [];
524
+ } else o = e, this.currentModelUrl = null, this.currentVariants = [];
522
525
  if (this.unitsScaleToMeters !== 1) {
523
526
  if (!this.sceneSetupService) throw new t("A units conversion is configured but no scene setup service is available to apply it", i.INVALID_PARAMETER);
524
527
  let e = this.sceneSetupService.wrapInUnitsScaleGroup(o, this.unitsScaleToMeters);
@@ -1148,6 +1151,9 @@ var $t = (e) => [
1148
1151
  getVariantNames() {
1149
1152
  return this.modelManager.getVariantNames();
1150
1153
  }
1154
+ getModelUrl() {
1155
+ return this.modelManager.getCurrentModelUrl();
1156
+ }
1151
1157
  setMaterialVariant(e) {
1152
1158
  let n = this.modelManager.getCurrentModel();
1153
1159
  return n && e !== null && !this.modelManager.getVariantNames().includes(e) ? r.err(new t(`Unknown material variant '${e}'`, i.INVALID_PARAMETER)) : (this.options.variant = e ?? void 0, !n || !this.sceneSetupService || this.sceneSetupService.applyMaterialVariant(n, e).then((e) => {
@@ -8645,33 +8651,141 @@ function cc({ active: e, onSelect: t }) {
8645
8651
  });
8646
8652
  }
8647
8653
  //#endregion
8654
+ //#region src/presentation/components/arHandoff.ts
8655
+ var lc = "#softbox-ar-failed";
8656
+ function uc() {
8657
+ return typeof document > "u" || typeof navigator > "u" ? null : document.createElement("a").relList?.supports?.("ar") ? "quick-look" : /android/i.test(navigator.userAgent) ? "scene-viewer" : null;
8658
+ }
8659
+ function dc(e) {
8660
+ if (typeof window > "u" || typeof e != "string" || e.length === 0) return null;
8661
+ try {
8662
+ let t = new URL(e, window.location.href);
8663
+ return t.protocol === "https:" ? t.toString() : null;
8664
+ } catch {
8665
+ return null;
8666
+ }
8667
+ }
8668
+ function fc(e, t) {
8669
+ let n = `file=${encodeURIComponent(e)}&mode=ar_preferred`;
8670
+ t && (n += `&title=${encodeURIComponent(t)}`);
8671
+ let r = new URL(window.location.href);
8672
+ return r.hash = lc, `intent://arvr.google.com/scene-viewer/1.0?${n}#Intent;scheme=https;package=com.google.ar.core;action=android.intent.action.VIEW;S.browser_fallback_url=${encodeURIComponent(r.toString())};end;`;
8673
+ }
8674
+ function pc(e) {
8675
+ let t = document.createElement("a");
8676
+ t.rel = "ar", t.appendChild(document.createElement("img")), t.href = e, t.click();
8677
+ }
8678
+ function mc(e) {
8679
+ let t = document.createElement("a");
8680
+ t.href = e, t.click();
8681
+ }
8682
+ //#endregion
8683
+ //#region src/presentation/components/ArButton.tsx
8684
+ var hc = {
8685
+ "top-left": {
8686
+ top: 16,
8687
+ left: 16
8688
+ },
8689
+ "top-right": {
8690
+ top: 16,
8691
+ right: 16
8692
+ },
8693
+ "bottom-left": {
8694
+ bottom: 16,
8695
+ left: 16
8696
+ },
8697
+ "bottom-right": {
8698
+ bottom: 16,
8699
+ right: 16
8700
+ }
8701
+ };
8702
+ function gc({ source: e, options: t, clearPresetRow: n }) {
8703
+ let [r, i] = k(null);
8704
+ E(() => {
8705
+ i(uc());
8706
+ }, []);
8707
+ let [a, o] = k(!1);
8708
+ E(() => {
8709
+ let e = () => {
8710
+ window.location.hash === "#softbox-ar-failed" && (history.replaceState(null, "", window.location.pathname + window.location.search), o(!0));
8711
+ };
8712
+ return window.addEventListener("hashchange", e), () => window.removeEventListener("hashchange", e);
8713
+ }, []);
8714
+ let s = dc(e), c = D(() => {
8715
+ if (a) return null;
8716
+ if (r === "quick-look" && t.iosSrc) {
8717
+ let e = t.iosSrc;
8718
+ return () => pc(e);
8719
+ }
8720
+ return r === "scene-viewer" && s ? () => mc(fc(s, t.title)) : null;
8721
+ }, [
8722
+ a,
8723
+ r,
8724
+ t.iosSrc,
8725
+ t.title,
8726
+ s
8727
+ ]);
8728
+ if (!c) return null;
8729
+ let l = { ...hc[t.placement ?? "bottom-left"] };
8730
+ return n && l.bottom !== void 0 && (l.bottom = 64), /* @__PURE__ */ H("button", {
8731
+ type: "button",
8732
+ "data-testid": "viewer-ar-button",
8733
+ "aria-label": "View in your space (AR)",
8734
+ onClick: c,
8735
+ style: {
8736
+ position: "absolute",
8737
+ zIndex: 10,
8738
+ padding: "8px 16px",
8739
+ borderRadius: 999,
8740
+ color: "#111318",
8741
+ fontFamily: ac,
8742
+ fontSize: 13,
8743
+ fontWeight: 600,
8744
+ lineHeight: 1,
8745
+ cursor: "pointer",
8746
+ ...l,
8747
+ ...oc
8748
+ },
8749
+ children: "AR"
8750
+ });
8751
+ }
8752
+ //#endregion
8648
8753
  //#region src/presentation/components/loadingIndicatorConfig.ts
8649
- var lc = {
8754
+ var _c = {
8650
8755
  enabled: !0,
8651
8756
  label: "Loading…",
8652
8757
  color: "#ffffff",
8653
8758
  backdrop: "rgba(15,16,20,0.6)"
8654
8759
  };
8655
- function uc(e) {
8656
- return e === void 0 || e === !0 ? lc : e === !1 ? {
8657
- ...lc,
8760
+ function vc(e) {
8761
+ return e === void 0 || e === !0 ? _c : e === !1 ? {
8762
+ ..._c,
8658
8763
  enabled: !1
8659
8764
  } : {
8660
8765
  enabled: e.enabled ?? !0,
8661
- label: e.label ?? lc.label,
8766
+ label: e.label ?? _c.label,
8662
8767
  errorLabel: e.errorLabel,
8663
- color: e.color ?? lc.color,
8664
- backdrop: e.backdrop ?? lc.backdrop
8768
+ color: e.color ?? _c.color,
8769
+ backdrop: e.backdrop ?? _c.backdrop
8665
8770
  };
8666
8771
  }
8667
8772
  //#endregion
8668
8773
  //#region src/presentation/components/SimpleViewer.tsx
8669
- var dc = () => new t("Viewer is not ready yet", i.COMPONENT_NOT_MOUNTED), fc = ne(({ object: e, options: t = {}, preset: n, pathTraced: r, turntable: i, animations: a, children: s }, c) => {
8774
+ var yc = () => new t("Viewer is not ready yet", i.COMPONENT_NOT_MOUNTED), bc = ne(({ object: e, options: t = {}, preset: n, pathTraced: r, turntable: i, animations: a, children: s }, c) => {
8670
8775
  let l = O(null), { activePreset: u, pickerEnabled: d, selectPreset: f } = Lo(t.preset ?? n, t.ui), { viewer: p, isInitialized: m, initError: h } = Fo(l, Ro(t, u, r, i, a)), g = zo(p, m, e), y = Vo(p);
8671
8776
  Ho(p, h, t);
8672
8777
  let x = p ? _(p.getCamera()) : null, S = p ? b(p.getControls()) : null, ee = p ? o(p.getRenderer()) : null, te = re(() => {
8673
8778
  p?.requestRender();
8674
- }, [p]), C = t.helpers?.gizmo !== void 0 && t.helpers.gizmo !== !1, w = typeof t.helpers?.gizmo == "object" ? t.helpers.gizmo : {}, T = D(() => uc(t.loadingIndicator), [t.loadingIndicator]), ne = g.status === "error" || !!h, ie = T.enabled && (g.status === "loading" || ne);
8779
+ }, [p]), C = t.helpers?.gizmo !== void 0 && t.helpers.gizmo !== !1, w = typeof t.helpers?.gizmo == "object" ? t.helpers.gizmo : {}, T = t.ar === !0 ? {} : t.ar || null, [ne, ie] = k(null);
8780
+ E(() => {
8781
+ if (!p) {
8782
+ ie(null);
8783
+ return;
8784
+ }
8785
+ let e = () => ie(p.getModelUrl());
8786
+ return e(), y.on("model:loaded", e), () => y.off("model:loaded", e);
8787
+ }, [p, y]);
8788
+ let oe = ne ?? e, A = D(() => vc(t.loadingIndicator), [t.loadingIndicator]), se = g.status === "error" || !!h, ce = A.enabled && (g.status === "loading" || se);
8675
8789
  return ae(c, () => ({
8676
8790
  scene: p ? v(p.getScene()) : null,
8677
8791
  camera: x,
@@ -8679,18 +8793,18 @@ var dc = () => new t("Viewer is not ready yet", i.COMPONENT_NOT_MOUNTED), fc = n
8679
8793
  controls: S,
8680
8794
  events: y,
8681
8795
  loadModel: async (e) => {
8682
- if (!p) throw dc();
8796
+ if (!p) throw yc();
8683
8797
  let t = typeof e == "string" ? e : new on(e), n = await p.loadModel(t);
8684
8798
  if (!n.ok) throw n.error;
8685
8799
  },
8686
8800
  captureStill: async (e) => {
8687
- if (!p) throw dc();
8801
+ if (!p) throw yc();
8688
8802
  let t = await p.captureStill(e);
8689
8803
  if (!t.ok) throw t.error;
8690
8804
  return t.value;
8691
8805
  },
8692
8806
  captureVideo: async (e) => {
8693
- if (!p) throw dc();
8807
+ if (!p) throw yc();
8694
8808
  let t = await p.captureVideo(e);
8695
8809
  if (!t.ok) throw t.error;
8696
8810
  return t.value;
@@ -8698,12 +8812,12 @@ var dc = () => new t("Viewer is not ready yet", i.COMPONENT_NOT_MOUNTED), fc = n
8698
8812
  getAnimationNames: () => p?.getAnimationNames() ?? [],
8699
8813
  getVariantNames: () => p?.getVariantNames() ?? [],
8700
8814
  setVariant: (e) => {
8701
- if (!p) throw dc();
8815
+ if (!p) throw yc();
8702
8816
  let t = p.setMaterialVariant(e);
8703
8817
  if (!t.ok) throw t.error;
8704
8818
  },
8705
8819
  playAnimations: (e) => {
8706
- if (!p) throw dc();
8820
+ if (!p) throw yc();
8707
8821
  let t = p.playAnimations(e);
8708
8822
  if (!t.ok) throw t.error;
8709
8823
  },
@@ -8711,22 +8825,22 @@ var dc = () => new t("Viewer is not ready yet", i.COMPONENT_NOT_MOUNTED), fc = n
8711
8825
  p?.pauseAnimations();
8712
8826
  },
8713
8827
  setEnvironmentMap: async (e) => {
8714
- if (!p) throw dc();
8828
+ if (!p) throw yc();
8715
8829
  let t = await p.setEnvironmentMap(e);
8716
8830
  if (!t.ok) throw t.error;
8717
8831
  },
8718
8832
  resetEnvironment: () => {
8719
- if (!p) throw dc();
8833
+ if (!p) throw yc();
8720
8834
  let e = p.resetEnvironment();
8721
8835
  if (!e.ok) throw e.error;
8722
8836
  },
8723
8837
  setBackgroundImage: async (e) => {
8724
- if (!p) throw dc();
8838
+ if (!p) throw yc();
8725
8839
  let t = await p.setBackgroundImage(e);
8726
8840
  if (!t.ok) throw t.error;
8727
8841
  },
8728
8842
  setBackgroundColor: (e) => {
8729
- if (!p) throw dc();
8843
+ if (!p) throw yc();
8730
8844
  let t = p.setBackgroundColor(e);
8731
8845
  if (!t.ok) throw t.error;
8732
8846
  },
@@ -8757,32 +8871,37 @@ var dc = () => new t("Viewer is not ready yet", i.COMPONENT_NOT_MOUNTED), fc = n
8757
8871
  placement: w.placement,
8758
8872
  size: w.size
8759
8873
  }),
8760
- ie && /* @__PURE__ */ H(ic, {
8761
- status: ne ? "error" : "loading",
8762
- label: ne ? T.errorLabel ?? h?.message ?? g.error ?? "Failed to load model" : T.label,
8763
- color: T.color,
8764
- backdrop: T.backdrop
8874
+ ce && /* @__PURE__ */ H(ic, {
8875
+ status: se ? "error" : "loading",
8876
+ label: se ? A.errorLabel ?? h?.message ?? g.error ?? "Failed to load model" : A.label,
8877
+ color: A.color,
8878
+ backdrop: A.backdrop
8765
8879
  }),
8766
8880
  d && /* @__PURE__ */ H(cc, {
8767
8881
  active: u ?? "studio",
8768
8882
  onSelect: f
8769
8883
  }),
8884
+ T && /* @__PURE__ */ H(gc, {
8885
+ source: oe,
8886
+ options: T,
8887
+ clearPresetRow: d
8888
+ }),
8770
8889
  s
8771
8890
  ]
8772
8891
  })
8773
8892
  }) });
8774
8893
  });
8775
- fc.displayName = "SimpleViewer";
8894
+ bc.displayName = "SimpleViewer";
8776
8895
  //#endregion
8777
8896
  //#region src/SimpleViewerWrapper.tsx
8778
- var pc = ne((e, t) => /* @__PURE__ */ H(fc, {
8897
+ var xc = ne((e, t) => /* @__PURE__ */ H(bc, {
8779
8898
  ref: t,
8780
8899
  ...e
8781
8900
  }));
8782
- pc.displayName = "SimpleViewer";
8901
+ xc.displayName = "SimpleViewer";
8783
8902
  //#endregion
8784
8903
  //#region src/presentation/components/Hotspot.tsx
8785
- var mc = () => /* @__PURE__ */ H("span", {
8904
+ var Sc = () => /* @__PURE__ */ H("span", {
8786
8905
  "aria-hidden": "true",
8787
8906
  style: {
8788
8907
  display: "block",
@@ -8794,7 +8913,7 @@ var mc = () => /* @__PURE__ */ H("span", {
8794
8913
  boxShadow: "0 2px 8px rgba(0,0,0,0.35)"
8795
8914
  }
8796
8915
  });
8797
- function hc({ position: e, occlude: t = !1, children: n }) {
8916
+ function Cc({ position: e, occlude: t = !1, children: n }) {
8798
8917
  let { viewer: r } = Go(), i = O(null), [a, o, s] = e;
8799
8918
  E(() => {
8800
8919
  if (!r) return;
@@ -8847,8 +8966,8 @@ function hc({ position: e, occlude: t = !1, children: n }) {
8847
8966
  zIndex: 5,
8848
8967
  pointerEvents: c ? "auto" : "none"
8849
8968
  },
8850
- children: c ? n : /* @__PURE__ */ H(mc, {})
8969
+ children: c ? n : /* @__PURE__ */ H(Sc, {})
8851
8970
  });
8852
8971
  }
8853
8972
  //#endregion
8854
- export { Xa as ControlType, wo as DEFAULT_OUTDOOR_CONCRETE_TEXTURES, Co as DEFAULT_OUTDOOR_HDRI_URL, Eo as DEFAULT_SCENE, Za as DEFAULT_STUDIO_LOOK, i as ErrorCode, hc as Hotspot, pc as SimpleViewer, t as ThreeViewerError, n as TypedEventEmitter, Oo as VIEWER_PRESETS, To as VIEWER_SCENES, So as defaultOptions, ko as resolvePreset, Do as resolveScene };
8973
+ export { Xa as ControlType, wo as DEFAULT_OUTDOOR_CONCRETE_TEXTURES, Co as DEFAULT_OUTDOOR_HDRI_URL, Eo as DEFAULT_SCENE, Za as DEFAULT_STUDIO_LOOK, i as ErrorCode, Cc as Hotspot, xc as SimpleViewer, t as ThreeViewerError, n as TypedEventEmitter, Oo as VIEWER_PRESETS, To as VIEWER_SCENES, So as defaultOptions, ko as resolvePreset, Do as resolveScene };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "softbox",
3
3
  "private": false,
4
- "version": "4.23.0",
4
+ "version": "4.24.0",
5
5
  "homepage": "https://leming.github.io/softbox/",
6
6
  "type": "module",
7
7
  "description": "Batteries-included React 3D viewer — any GLB looks studio-shot in one line",