@lobehub/ui 1.138.6 → 1.138.7

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.
@@ -1,5 +1,5 @@
1
- import { type SplineProps } from '@splinetool/react-spline';
2
1
  import { CSSProperties } from 'react';
2
+ import { type SplineProps } from "../Spline";
3
3
  export interface LogoSplineProps extends Partial<SplineProps> {
4
4
  className?: string;
5
5
  height?: number | string;
@@ -2,9 +2,9 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
4
  var _excluded = ["className", "style", "width", "height", "onLoad"];
5
- import Spline from '@splinetool/react-spline';
6
5
  import { useThemeMode } from 'antd-style';
7
6
  import { memo, useState } from 'react';
7
+ import Spline from "../Spline";
8
8
  import Loading from "./Loading";
9
9
  import { jsx as _jsx } from "react/jsx-runtime";
10
10
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -1,5 +1,5 @@
1
- import { type SplineProps } from '@splinetool/react-spline';
2
1
  import { CSSProperties } from 'react';
2
+ import { type SplineProps } from "../Spline";
3
3
  export interface LogoThreeProps extends Partial<SplineProps> {
4
4
  className?: string;
5
5
  size?: number;
@@ -4,12 +4,12 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
4
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
5
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
6
  var _excluded = ["className", "style", "size", "onLoad"];
7
- import Spline from '@splinetool/react-spline';
8
7
  import { memo, useState } from 'react';
9
8
  import { Flexbox } from 'react-layout-kit';
10
9
  import { useCdnFn } from "../ConfigProvider";
11
10
  import Img from "../Img";
12
11
  import { LOGO_3D } from "../Logo/style";
12
+ import Spline from "../Spline";
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
15
  var LogoThree = /*#__PURE__*/memo(function (_ref) {
@@ -0,0 +1,35 @@
1
+ import { type CSSProperties, type ReactNode } from 'react';
2
+ interface ResizeObserverCallback {
3
+ (entries: ResizeObserverEntry[], observer: ResizeObserver): void;
4
+ }
5
+ interface ResizeObserverPolyfill {
6
+ new (callback: ResizeObserverCallback): ResizeObserver;
7
+ }
8
+ export type ParentSizeProps = {
9
+ /** Child render function `({ width, height, top, left, ref, resize }) => ReactNode`. */
10
+ children: (args: {
11
+ ref: HTMLDivElement | null;
12
+ resize: (state: ParentSizeState) => void;
13
+ } & ParentSizeState) => ReactNode;
14
+ /** Optional `className` to add to the parent `div` wrapper used for size measurement. */
15
+ className?: string;
16
+ /** Child render updates upon resize are delayed until `debounceTime` milliseconds _after_ the last resize event is observed. */
17
+ debounceTime?: number;
18
+ /** Optional flag to toggle leading debounce calls. When set to true this will ensure that the component always renders immediately. (defaults to true) */
19
+ enableDebounceLeadingCall?: boolean;
20
+ /** Optional dimensions provided won't trigger a state change when changed. */
21
+ ignoreDimensions?: keyof ParentSizeState | (keyof ParentSizeState)[];
22
+ /** Optional `style` object to apply to the parent `div` wrapper used for size measurement. */
23
+ parentSizeStyles?: CSSProperties;
24
+ /** Optionally inject a ResizeObserver polyfill, else this *must* be globally available. */
25
+ resizeObserverPolyfill?: ResizeObserverPolyfill;
26
+ };
27
+ type ParentSizeState = {
28
+ height: number;
29
+ left: number;
30
+ top: number;
31
+ width: number;
32
+ };
33
+ export type ParentSizeProvidedProps = ParentSizeState;
34
+ declare const _default: import("react").ForwardRefExoticComponent<ParentSizeProps & import("react").RefAttributes<HTMLDivElement>>;
35
+ export default _default;
@@ -0,0 +1,106 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
+ var _excluded = ["className", "children", "debounceTime", "ignoreDimensions", "parentSizeStyles", "enableDebounceLeadingCall", "resizeObserverPolyfill"];
6
+ import { debounce } from 'lodash-es';
7
+ import { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
8
+ import { mergeRefs } from 'react-merge-refs';
9
+
10
+ // @TODO remove when upgraded to TS 4 which has its own declaration
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ var defaultIgnoreDimensions = [];
13
+ var defaultParentSizeStyles = {
14
+ height: '100%',
15
+ width: '100%'
16
+ };
17
+ export default /*#__PURE__*/forwardRef(function ParentSize(_ref, ref) {
18
+ var className = _ref.className,
19
+ children = _ref.children,
20
+ _ref$debounceTime = _ref.debounceTime,
21
+ debounceTime = _ref$debounceTime === void 0 ? 300 : _ref$debounceTime,
22
+ _ref$ignoreDimensions = _ref.ignoreDimensions,
23
+ ignoreDimensions = _ref$ignoreDimensions === void 0 ? defaultIgnoreDimensions : _ref$ignoreDimensions,
24
+ parentSizeStyles = _ref.parentSizeStyles,
25
+ _ref$enableDebounceLe = _ref.enableDebounceLeadingCall,
26
+ enableDebounceLeadingCall = _ref$enableDebounceLe === void 0 ? true : _ref$enableDebounceLe,
27
+ resizeObserverPolyfill = _ref.resizeObserverPolyfill,
28
+ restProps = _objectWithoutProperties(_ref, _excluded);
29
+ var target = useRef(null);
30
+ var animationFrameID = useRef(0);
31
+ var _useState = useState({
32
+ height: 0,
33
+ left: 0,
34
+ top: 0,
35
+ width: 0
36
+ }),
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ state = _useState2[0],
39
+ setState = _useState2[1];
40
+ var resize = useMemo(function () {
41
+ var normalized = Array.isArray(ignoreDimensions) ? ignoreDimensions : [ignoreDimensions];
42
+ return debounce(function (incoming) {
43
+ setState(function (existing) {
44
+ var stateKeys = Object.keys(existing);
45
+ var keysWithChanges = stateKeys.filter(function (key) {
46
+ return existing[key] !== incoming[key];
47
+ });
48
+ var shouldBail = keysWithChanges.every(function (key) {
49
+ return normalized.includes(key);
50
+ });
51
+ return shouldBail ? existing : incoming;
52
+ });
53
+ }, debounceTime, {
54
+ leading: enableDebounceLeadingCall
55
+ });
56
+ }, [debounceTime, enableDebounceLeadingCall, ignoreDimensions]);
57
+ useEffect(function () {
58
+ var LocalResizeObserver = resizeObserverPolyfill || window.ResizeObserver;
59
+ var observer = new LocalResizeObserver(function (entries) {
60
+ var _iterator = _createForOfIteratorHelper(entries),
61
+ _step;
62
+ try {
63
+ var _loop = function _loop() {
64
+ var _entry$contentRect;
65
+ var entry = _step.value;
66
+ var _ref2 = (_entry$contentRect = entry === null || entry === void 0 ? void 0 : entry.contentRect) !== null && _entry$contentRect !== void 0 ? _entry$contentRect : {},
67
+ left = _ref2.left,
68
+ top = _ref2.top,
69
+ width = _ref2.width,
70
+ height = _ref2.height;
71
+ animationFrameID.current = window.requestAnimationFrame(function () {
72
+ resize({
73
+ height: height,
74
+ left: left,
75
+ top: top,
76
+ width: width
77
+ });
78
+ });
79
+ };
80
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
81
+ _loop();
82
+ }
83
+ } catch (err) {
84
+ _iterator.e(err);
85
+ } finally {
86
+ _iterator.f();
87
+ }
88
+ });
89
+ if (target.current) observer.observe(target.current);
90
+ return function () {
91
+ window.cancelAnimationFrame(animationFrameID.current);
92
+ observer.disconnect();
93
+ resize.cancel();
94
+ };
95
+ }, [resize, resizeObserverPolyfill]);
96
+ return /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
97
+ className: className,
98
+ ref: mergeRefs([ref, target]),
99
+ style: _objectSpread(_objectSpread({}, defaultParentSizeStyles), parentSizeStyles)
100
+ }, restProps), {}, {
101
+ children: children(_objectSpread(_objectSpread({}, state), {}, {
102
+ ref: target.current,
103
+ resize: resize
104
+ }))
105
+ }));
106
+ });
@@ -0,0 +1,20 @@
1
+ import { Application } from '@splinetool/runtime';
2
+ import type { SplineEvent } from '@splinetool/runtime';
3
+ import { type HTMLAttributes } from 'react';
4
+ export interface SplineProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onLoad' | 'onMouseDown' | 'onMouseUp' | 'onMouseHover' | 'onKeyDown' | 'onKeyUp' | 'onWheel'> {
5
+ onFollow?: (e: SplineEvent) => void;
6
+ onKeyDown?: (e: SplineEvent) => void;
7
+ onKeyUp?: (e: SplineEvent) => void;
8
+ onLoad?: (e: Application) => void;
9
+ onLookAt?: (e: SplineEvent) => void;
10
+ onMouseDown?: (e: SplineEvent) => void;
11
+ onMouseHover?: (e: SplineEvent) => void;
12
+ onMouseUp?: (e: SplineEvent) => void;
13
+ onStart?: (e: SplineEvent) => void;
14
+ onWheel?: (e: SplineEvent) => void;
15
+ renderOnDemand?: boolean;
16
+ scene: string;
17
+ }
18
+ declare const Spline: import("react").ForwardRefExoticComponent<SplineProps & import("react").RefAttributes<HTMLDivElement>>;
19
+ export default Spline;
20
+ export { type SPEObject, type SplineEvent, type SplineEventName } from '@splinetool/runtime';
@@ -0,0 +1,132 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
3
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
4
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
7
+ var _excluded = ["scene", "style", "onMouseDown", "onMouseUp", "onMouseHover", "onKeyDown", "onKeyUp", "onStart", "onLookAt", "onFollow", "onWheel", "onLoad", "renderOnDemand"];
8
+ import { Application } from '@splinetool/runtime';
9
+ import { forwardRef, useEffect, useRef, useState } from 'react';
10
+ import ParentSize from "./ParentSize";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ var Spline = /*#__PURE__*/forwardRef(function (_ref, ref) {
13
+ var scene = _ref.scene,
14
+ style = _ref.style,
15
+ onMouseDown = _ref.onMouseDown,
16
+ onMouseUp = _ref.onMouseUp,
17
+ onMouseHover = _ref.onMouseHover,
18
+ onKeyDown = _ref.onKeyDown,
19
+ onKeyUp = _ref.onKeyUp,
20
+ onStart = _ref.onStart,
21
+ onLookAt = _ref.onLookAt,
22
+ onFollow = _ref.onFollow,
23
+ onWheel = _ref.onWheel,
24
+ onLoad = _ref.onLoad,
25
+ _ref$renderOnDemand = _ref.renderOnDemand,
26
+ renderOnDemand = _ref$renderOnDemand === void 0 ? true : _ref$renderOnDemand,
27
+ props = _objectWithoutProperties(_ref, _excluded);
28
+ var canvasRef = useRef(null);
29
+ var _useState = useState(true),
30
+ _useState2 = _slicedToArray(_useState, 2),
31
+ isLoading = _useState2[0],
32
+ setIsLoading = _useState2[1];
33
+ var init = /*#__PURE__*/function () {
34
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(speApp, events) {
35
+ var _iterator, _step, event;
36
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
37
+ while (1) switch (_context.prev = _context.next) {
38
+ case 0:
39
+ _context.next = 2;
40
+ return speApp.load(scene);
41
+ case 2:
42
+ _iterator = _createForOfIteratorHelper(events);
43
+ try {
44
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
45
+ event = _step.value;
46
+ if (event.cb) {
47
+ speApp.addEventListener(event.name, event.cb);
48
+ }
49
+ }
50
+ } catch (err) {
51
+ _iterator.e(err);
52
+ } finally {
53
+ _iterator.f();
54
+ }
55
+ setIsLoading(false);
56
+ onLoad === null || onLoad === void 0 || onLoad(speApp);
57
+ case 6:
58
+ case "end":
59
+ return _context.stop();
60
+ }
61
+ }, _callee);
62
+ }));
63
+ return function init(_x, _x2) {
64
+ return _ref2.apply(this, arguments);
65
+ };
66
+ }();
67
+
68
+ // Initialize runtime when component is mounted
69
+ useEffect(function () {
70
+ setIsLoading(true);
71
+ var speApp;
72
+ var events = [{
73
+ cb: onMouseDown,
74
+ name: 'mouseDown'
75
+ }, {
76
+ cb: onMouseUp,
77
+ name: 'mouseUp'
78
+ }, {
79
+ cb: onMouseHover,
80
+ name: 'mouseHover'
81
+ }, {
82
+ cb: onKeyDown,
83
+ name: 'keyDown'
84
+ }, {
85
+ cb: onKeyUp,
86
+ name: 'keyUp'
87
+ }, {
88
+ cb: onStart,
89
+ name: 'start'
90
+ }, {
91
+ cb: onLookAt,
92
+ name: 'lookAt'
93
+ }, {
94
+ cb: onFollow,
95
+ name: 'follow'
96
+ }, {
97
+ cb: onWheel,
98
+ name: 'scroll'
99
+ }];
100
+ if (canvasRef.current) {
101
+ speApp = new Application(canvasRef.current, {
102
+ renderOnDemand: renderOnDemand
103
+ });
104
+ init(speApp, events);
105
+ }
106
+ return function () {
107
+ for (var _i = 0, _events = events; _i < _events.length; _i++) {
108
+ var event = _events[_i];
109
+ if (event.cb) {
110
+ speApp.removeEventListener(event.name, event.cb);
111
+ }
112
+ }
113
+ speApp.dispose();
114
+ };
115
+ // eslint-disable-next-line react-hooks/exhaustive-deps
116
+ }, [scene]);
117
+ return /*#__PURE__*/_jsx(ParentSize, _objectSpread(_objectSpread({
118
+ debounceTime: 50,
119
+ parentSizeStyles: style,
120
+ ref: ref
121
+ }, props), {}, {
122
+ children: function children() {
123
+ return /*#__PURE__*/_jsx("canvas", {
124
+ ref: canvasRef,
125
+ style: {
126
+ display: isLoading ? 'none' : 'block'
127
+ }
128
+ });
129
+ }
130
+ }));
131
+ });
132
+ export default Spline;
package/es/index.d.ts CHANGED
@@ -71,6 +71,7 @@ export { default as SideNav, type SideNavProps } from './SideNav';
71
71
  export { default as SliderWithInput, type SliderWithInputProps } from './SliderWithInput';
72
72
  export { default as Snippet, type SnippetProps } from './Snippet';
73
73
  export { default as SortableList, type SortableListProps } from './SortableList';
74
+ export { default as Spline, type SplineProps } from './Spline';
74
75
  export { default as Spotlight, type SpotlightProps } from './Spotlight';
75
76
  export { default as SpotlightCard, type SpotlightCardProps } from './SpotlightCard';
76
77
  export { default as StoryBook, type StoryBookProps, useControls, useCreateStore, } from './StoryBook';
package/es/index.js CHANGED
@@ -70,6 +70,7 @@ export { default as SideNav } from "./SideNav";
70
70
  export { default as SliderWithInput } from "./SliderWithInput";
71
71
  export { default as Snippet } from "./Snippet";
72
72
  export { default as SortableList } from "./SortableList";
73
+ export { default as Spline } from "./Spline";
73
74
  export { default as Spotlight } from "./Spotlight";
74
75
  export { default as SpotlightCard } from "./SpotlightCard";
75
76
  export { default as StoryBook, useControls, useCreateStore } from "./StoryBook";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.138.6",
3
+ "version": "1.138.7",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -87,7 +87,6 @@
87
87
  "@lobehub/emojilib": "latest",
88
88
  "@react-spring/web": "^9.7.3",
89
89
  "@shikijs/transformers": "^1.3.0",
90
- "@splinetool/react-spline": "^2.2.6",
91
90
  "@splinetool/runtime": "^1.1.2",
92
91
  "ahooks": "^3.7.11",
93
92
  "chroma-js": "^2.4.2",
@@ -107,6 +106,7 @@
107
106
  "react-error-boundary": "^4.0.13",
108
107
  "react-layout-kit": "^1.9.0",
109
108
  "react-markdown": "^8.0.7",
109
+ "react-merge-refs": "^2.1.1",
110
110
  "react-rnd": "^10.4.1",
111
111
  "react-simple-code-editor": "^0.13.1",
112
112
  "rehype-katex": "^6.0.3",