@gamelearn/arcade-components 3.32.0 → 3.32.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.
@@ -19,8 +19,8 @@ var Nc = (l, e, n, t) => ({
19
19
  }), Ue = (l, e, n) => (Am(l, e, "access private method"), n);
20
20
  import * as React$2 from "react";
21
21
  import React__default, { useRef, useEffect, useCallback, createContext, useReducer, forwardRef, useImperativeHandle, useMemo, useContext, useLayoutEffect, useState } from "react";
22
- import { OrbitControls, PerspectiveCamera as PerspectiveCamera$1 } from "@react-three/drei";
23
- import { Renderer, SceneResource, CameraControls, SettingsController, EnvironmentWrapper, ProgressManager, QualityManager, HtmlPro, AssetLoader } from "@gamelearn/arcade-three-core";
22
+ import { OrbitControls, PerspectiveCamera as PerspectiveCamera$1, Environment } from "@react-three/drei";
23
+ import { Renderer, SceneResource, CameraControls, SettingsController, QualityManager, HtmlPro, ProgressManager, AssetLoader } from "@gamelearn/arcade-three-core";
24
24
  import { useThree, useFrame } from "@react-three/fiber";
25
25
  import { Vector3, Box3, TrianglesDrawMode, TriangleFanDrawMode, TriangleStripDrawMode, Loader, LoaderUtils, FileLoader, Color, LinearSRGBColorSpace, SpotLight, PointLight, DirectionalLight, MeshBasicMaterial, SRGBColorSpace, MeshPhysicalMaterial, Vector2, Matrix4, Quaternion, InstancedMesh, InstancedBufferAttribute, Object3D, TextureLoader, ImageBitmapLoader, BufferAttribute, InterleavedBuffer, InterleavedBufferAttribute, LinearFilter, LinearMipmapLinearFilter, RepeatWrapping, PointsMaterial, Material, LineBasicMaterial, MeshStandardMaterial, DoubleSide, PropertyBinding, BufferGeometry, SkinnedMesh, Mesh, LineSegments, Line as Line$3, LineLoop, Points, Group as Group$3, PerspectiveCamera, MathUtils, OrthographicCamera, Skeleton, AnimationClip, Bone, InterpolateLinear, ColorManagement, NearestFilter, NearestMipmapNearestFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, ClampToEdgeWrapping, MirroredRepeatWrapping, InterpolateDiscrete, FrontSide, Texture, VectorKeyframeTrack, NumberKeyframeTrack, QuaternionKeyframeTrack, Sphere, Interpolant, Raycaster, LoopRepeat } from "three";
26
26
  import require$$0 from "react-dom";
@@ -29730,92 +29730,92 @@ function addPrimitiveAttributes(l, e, n) {
29730
29730
  });
29731
29731
  }
29732
29732
  const defaultCamPos = [0, 14.63, 16], isMobile = DeviceDetection(), loader$1 = new GLTFLoader(), box = new Box3(), worldPos = new Vector3(), size = new Vector3();
29733
- function Panel({ character: l, ttsStarted: e, active: n, visible: t }) {
29734
- var x, S, g;
29735
- const s = useRef(null), o = useRef(null), d = l.type === "character", [h, f] = useState(!1), u = useRef(), p = useMemo(() => {
29736
- var v, b, R, y, w, C, N, D;
29737
- return d ? l.animationId && ((v = l.animation) != null && v.url) ? l.animation : (y = (R = (b = l == null ? void 0 : l.resource) == null ? void 0 : b.animations) == null ? void 0 : R[l.emotion]) != null && y.url ? (C = (w = l == null ? void 0 : l.resource) == null ? void 0 : w.animations) == null ? void 0 : C[l.emotion] : (D = (N = l == null ? void 0 : l.resource) == null ? void 0 : N.animations) == null ? void 0 : D.neutral : {};
29738
- }, [l.emotion, l == null ? void 0 : l.animationId, l == null ? void 0 : l.animation, (x = l == null ? void 0 : l.resource) == null ? void 0 : x.animations, d]), _ = useCallback(() => {
29739
- if (u.current) {
29740
- const v = u.current.userData.animator;
29741
- v.getAction("idle") && v.mix("idle", 0.1);
29733
+ function Panel({ character: l, ttsStarted: e, active: n, visible: t, onLoad: s }) {
29734
+ var S, g, v;
29735
+ const o = useRef(null), d = useRef(null), h = l.type === "character", [f, u] = useState(!1), p = useRef(), _ = useMemo(() => {
29736
+ var b, R, y, w, C, N, D, P;
29737
+ return h ? l.animationId && ((b = l.animation) != null && b.url) ? l.animation : (w = (y = (R = l == null ? void 0 : l.resource) == null ? void 0 : R.animations) == null ? void 0 : y[l.emotion]) != null && w.url ? (N = (C = l == null ? void 0 : l.resource) == null ? void 0 : C.animations) == null ? void 0 : N[l.emotion] : (P = (D = l == null ? void 0 : l.resource) == null ? void 0 : D.animations) == null ? void 0 : P.neutral : {};
29738
+ }, [l.emotion, l == null ? void 0 : l.animationId, l == null ? void 0 : l.animation, (S = l == null ? void 0 : l.resource) == null ? void 0 : S.animations, h]), T = useCallback(() => {
29739
+ if (p.current) {
29740
+ const b = p.current.userData.animator;
29741
+ b.getAction("idle") && b.mix("idle", 0.1);
29742
29742
  }
29743
29743
  }, []);
29744
29744
  useEffect(() => {
29745
- var v, b, R, y, w, C;
29746
- if (t)
29747
- if (n)
29748
- if (e) {
29749
- const N = (R = (b = (v = l == null ? void 0 : l.resource) == null ? void 0 : v.animations) == null ? void 0 : b.talking) == null ? void 0 : R.url, P = ((C = (w = (y = l == null ? void 0 : l.resource) == null ? void 0 : y.animations) == null ? void 0 : w["talking-short"]) == null ? void 0 : C.url) || N;
29750
- if (P && u.current) {
29751
- const k = u.current.userData.animator, F = `${P}_talking`;
29752
- k.getAction(F) ? (k.mix(F, 0.1), f(!0)) : loader$1.load(P, ({ animations: M }) => {
29753
- if (!u.current)
29754
- return;
29755
- const j = k.getAction("idle").getClip();
29756
- k.register(F, mixWithTalkingClip(M[0], j)), k.mix(F, 0.1), f(!0);
29757
- });
29758
- }
29759
- } else
29760
- _();
29761
- else
29762
- h && _();
29763
- }, [e, n, _, h, t, (S = l == null ? void 0 : l.resource) == null ? void 0 : S.animations]);
29764
- const T = useCallback(
29765
- (v) => {
29745
+ var b, R, y, w, C, N;
29746
+ if (n)
29747
+ if (e) {
29748
+ const D = (y = (R = (b = l == null ? void 0 : l.resource) == null ? void 0 : b.animations) == null ? void 0 : R.talking) == null ? void 0 : y.url, k = ((N = (C = (w = l == null ? void 0 : l.resource) == null ? void 0 : w.animations) == null ? void 0 : C["talking-short"]) == null ? void 0 : N.url) || D;
29749
+ if (k && p.current) {
29750
+ const F = p.current.userData.animator, M = `${k}_talking`;
29751
+ F.getAction(M) ? (F.mix(M, 0.1), u(!0)) : loader$1.load(k, ({ animations: j }) => {
29752
+ if (!p.current)
29753
+ return;
29754
+ const B = F.getAction("idle").getClip();
29755
+ F.register(M, mixWithTalkingClip(j[0], B)), F.mix(M, 0.1), u(!0);
29756
+ });
29757
+ }
29758
+ } else
29759
+ T();
29760
+ else
29761
+ f && T();
29762
+ }, [e, n, T, f, (g = l == null ? void 0 : l.resource) == null ? void 0 : g.animations]);
29763
+ const x = useCallback(
29764
+ (b) => {
29766
29765
  if (l.type === "character") {
29767
- const b = v.getObjectByName("Head_M", !0);
29768
- b ? (b.updateMatrixWorld(!0), box.setFromObject(v), box.getSize(size), b.getWorldPosition(worldPos), s.current.lookAt(worldPos)) : s.current.position.setY(size.y - 1.5 * 1.3), s.current.zoom = 1.5;
29766
+ const R = b.getObjectByName("Head_M", !0);
29767
+ R ? (R.updateMatrixWorld(!0), box.setFromObject(b), box.getSize(size), R.getWorldPosition(worldPos), o.current.lookAt(worldPos)) : o.current.position.setY(size.y - 1.5 * 1.3), o.current.zoom = 1.5;
29769
29768
  } else
29770
- cameraFitAnyObject(v, s.current), s.current.zoom = 1;
29771
- s.current.updateProjectionMatrix();
29769
+ cameraFitAnyObject(b, o.current), o.current.zoom = 1;
29770
+ o.current.updateProjectionMatrix(), s();
29772
29771
  },
29773
- [l]
29772
+ [l, s]
29774
29773
  );
29775
- return useFrame(({ gl: v, scene: b }) => {
29776
- if (s.current && o.current) {
29777
- const R = document.querySelectorAll(".conversation--character__item")[l.slot];
29778
- if (R) {
29779
- const y = R.getBoundingClientRect(), w = R.parentNode.getBoundingClientRect(), [C, N] = [y.right - y.left, y.bottom - y.top];
29780
- if (s.current.aspect = C / N, s.current.updateProjectionMatrix(), d && u.current) {
29781
- box.setFromObject(u.current), box.getSize(size);
29782
- const k = u.current.getObjectByName("Head_M", !0);
29783
- k ? (k.getWorldPosition(worldPos), s.current.lookAt(worldPos)) : s.current.position.setY(size.y - 1.5 * 1.3), s.current.zoom = 1.5;
29784
- }
29785
- const D = {
29786
- top: y.top - w.top,
29787
- right: y.right - w.right,
29788
- left: y.left - w.left,
29789
- bottom: y.bottom - w.bottom
29790
- }, P = isMobile ? 24 : 40;
29791
- D.bottom += n ? -P : P, v.setViewport(D.left, D.bottom, C, N), v.setScissor(D.left, D.bottom, C, N), o.current.environment = b.environment, v.render(o.current, s.current);
29792
- }
29793
- }
29794
- }, 1), l.type === "image" ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs("scene", { ref: o, children: [
29795
- (g = l.resource) != null && g.url ? /* @__PURE__ */ jsxRuntimeExports.jsx(
29774
+ return useFrame(({ gl: b, scene: R }) => {
29775
+ if (o.current && d.current) {
29776
+ const y = document.querySelectorAll(".conversation--character__item")[l.slot];
29777
+ if (y) {
29778
+ const w = y.getBoundingClientRect(), C = y.parentNode.getBoundingClientRect(), [N, D] = [w.right - w.left, w.bottom - w.top];
29779
+ if (o.current.aspect = N / D, o.current.updateProjectionMatrix(), h && p.current) {
29780
+ box.setFromObject(p.current), box.getSize(size);
29781
+ const F = p.current.getObjectByName("Head_M", !0);
29782
+ F ? (F.getWorldPosition(worldPos), o.current.lookAt(worldPos)) : o.current.position.setY(size.y - 1.5 * 1.3), o.current.zoom = 1.5;
29783
+ }
29784
+ const P = {
29785
+ top: w.top - C.top,
29786
+ right: w.right - C.right,
29787
+ left: w.left - C.left,
29788
+ bottom: w.bottom - C.bottom
29789
+ }, k = isMobile ? 24 : 40;
29790
+ P.bottom += n ? -k : k, b.setViewport(P.left, P.bottom, N, D), b.setScissor(P.left, P.bottom, N, D), d.current.environment = R.environment, b.render(d.current, o.current);
29791
+ }
29792
+ }
29793
+ }, 1), !((v = l.resource) != null && v.url) || l.type === "image" ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs("scene", { ref: d, children: [
29794
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
29796
29795
  SceneResource,
29797
29796
  {
29798
- ref: u,
29797
+ ref: p,
29799
29798
  name: `char_${l.uid}`,
29800
29799
  url: l.resource.url,
29801
- animationUrl: p.url,
29800
+ animationStates: { idle: _.url },
29802
29801
  type: l.type,
29803
- onRender: T,
29802
+ onRender: x,
29804
29803
  texturable: !0,
29805
- interactive: !0,
29804
+ interactive: !1,
29805
+ generate: !1,
29806
29806
  merge: l.type !== "character",
29807
29807
  visible: t
29808
29808
  }
29809
- ) : null,
29809
+ ),
29810
29810
  /* @__PURE__ */ jsxRuntimeExports.jsx(
29811
29811
  PerspectiveCamera$1,
29812
29812
  {
29813
- ref: s,
29813
+ ref: o,
29814
29814
  fov: 35,
29815
29815
  position: defaultCamPos,
29816
29816
  rotation: [0, 0, 0],
29817
- onUpdate: (v) => {
29818
- v.layers.enableAll();
29817
+ onUpdate: (b) => {
29818
+ b.layers.enableAll();
29819
29819
  },
29820
29820
  manual: !0
29821
29821
  }
@@ -29827,14 +29827,7 @@ function PanelsWrapper({ characters: l, slots: e, ttsStarted: n, flex: t, curren
29827
29827
  const [d, h] = useState(!1);
29828
29828
  return useFrame(({ gl: f }) => {
29829
29829
  f.setScissorTest(!1), f.clear(!0, !0), f.setScissorTest(!0);
29830
- }), useEffect(() => {
29831
- const f = () => {
29832
- h(!0);
29833
- };
29834
- return ProgressManager.addEventListener("loaded", f), () => {
29835
- ProgressManager.removeEventListener("loaded", f);
29836
- };
29837
- }, []), /* @__PURE__ */ jsxRuntimeExports.jsx(QualityManager, { lod: o, active: !0, children: e.map((f, u) => {
29830
+ }), /* @__PURE__ */ jsxRuntimeExports.jsx(QualityManager, { lod: d ? o : "divideby64", active: d, children: e.map((f, u) => {
29838
29831
  let p = null;
29839
29832
  const _ = l.findIndex((T) => T && T.uid === f.uid);
29840
29833
  if (_ >= 0) {
@@ -29845,7 +29838,7 @@ function PanelsWrapper({ characters: l, slots: e, ttsStarted: n, flex: t, curren
29845
29838
  character: p,
29846
29839
  active: s.position === T,
29847
29840
  ttsStarted: n,
29848
- visible: d
29841
+ onLoad: () => h(!0)
29849
29842
  },
29850
29843
  `${`${p.uid}_${u}`}_${_}`
29851
29844
  );
@@ -29870,7 +29863,7 @@ function Scene(l) {
29870
29863
  },
29871
29864
  children: [
29872
29865
  /* @__PURE__ */ jsxRuntimeExports.jsx(SettingsController, { current: { animate: l.pause } }),
29873
- /* @__PURE__ */ jsxRuntimeExports.jsx(EnvironmentWrapper, { url: "https://min.gamelearn.io/statics/envs/envmap_1k.hdr" }),
29866
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Environment, { files: "https://min.gamelearn.io/statics/envs/envmap_1k.hdr" }),
29874
29867
  /* @__PURE__ */ jsxRuntimeExports.jsx(PanelsWrapper, { ...l })
29875
29868
  ]
29876
29869
  }
@@ -30742,15 +30735,28 @@ function ConversationalComponent({
30742
30735
  ) });
30743
30736
  }
30744
30737
  function Vignette({ vignette: l, alias: e, translate: n, backgroundImageCover: t }) {
30745
- var u;
30738
+ var _;
30746
30739
  const o = (l.img || {
30747
30740
  url: "https://min.gamelearn.io/css-resources/gamelearn/resources/conversation.jpg"
30748
- }).url, [d, h] = useState(!0), f = (p) => {
30749
- document.querySelector(`#${p}`).focus(), h(!d);
30741
+ }).url, [d, h] = useState(!0), f = (T) => {
30742
+ document.querySelector(`#${T}`).focus(), h(!d);
30743
+ }, u = /\.(mp4|mov|webm)$/i.test(o), p = {
30744
+ src: o,
30745
+ style: t ? {
30746
+ minHeight: "100%",
30747
+ minWidth: "100%",
30748
+ position: "fixed",
30749
+ top: "50%",
30750
+ left: "50%",
30751
+ transform: "translate(-50%, -50%)"
30752
+ } : { height: "100%", width: "100%" }
30750
30753
  };
30751
30754
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
30752
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { "data-testid": "comic-image", className: `comic-image ${t ? "comic-image--cover" : ""}`, children: o && /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: o, alt: "comic pic" }) }),
30753
- (u = l == null ? void 0 : l.textData) != null && u.text ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
30755
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { "data-testid": "comic-image", className: `comic-image ${t ? "comic-image--cover" : ""}`, children: [
30756
+ u && /* @__PURE__ */ jsxRuntimeExports.jsx("video", { "data-testid": "videoTestId", autoPlay: !0, ...p }),
30757
+ o && !u && /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: o, alt: "comic pic" })
30758
+ ] }),
30759
+ (_ = l == null ? void 0 : l.textData) != null && _.text ? /* @__PURE__ */ jsxRuntimeExports.jsxs(
30754
30760
  "div",
30755
30761
  {
30756
30762
  "data-testid": "comicCollapsable",