@terrafirmagreg-team/ui 0.0.0-stage → 1.2.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/package.json +93 -3
- package/src/components/blocks/button/icon-button.tsx +49 -0
- package/src/components/blocks/canvas/chevron-edge.tsx +242 -0
- package/src/components/blocks/canvas/flow-canvas.tsx +181 -0
- package/src/components/blocks/canvas/flow-toolbar.tsx +33 -0
- package/src/components/blocks/canvas/flow-viewport.tsx +244 -0
- package/src/components/blocks/fit-box.tsx +26 -0
- package/src/components/blocks/git/github-info.tsx +78 -0
- package/src/components/blocks/lang/content.tsx +52 -0
- package/src/components/blocks/lang/flag.tsx +25 -0
- package/src/components/blocks/lang/link.tsx +23 -0
- package/src/components/blocks/lang/redirect.tsx +48 -0
- package/src/components/blocks/lang/switcher.tsx +54 -0
- package/src/components/blocks/lang/untranslated-callout.tsx +29 -0
- package/src/components/blocks/lang/untranslated-chip.tsx +53 -0
- package/src/components/blocks/link/link-preview.tsx +257 -0
- package/src/components/blocks/list/row.tsx +92 -0
- package/src/components/blocks/media/glb/model.tsx +244 -0
- package/src/components/blocks/media/glb/scene.tsx +373 -0
- package/src/components/blocks/media/glb/viewer.tsx +52 -0
- package/src/components/blocks/media/image.tsx +136 -0
- package/src/components/blocks/media/slideshow.tsx +178 -0
- package/src/components/blocks/nav/breadcrumb.tsx +51 -0
- package/src/components/blocks/nav/copy-menu.tsx +37 -0
- package/src/components/blocks/nav/link.tsx +86 -0
- package/src/components/blocks/nav/site-menu.tsx +78 -0
- package/src/components/blocks/nav/site-title.tsx +61 -0
- package/src/components/blocks/nav/switcher.tsx +206 -0
- package/src/components/blocks/page/empty-state.tsx +32 -0
- package/src/components/blocks/page/heading.tsx +54 -0
- package/src/components/blocks/page/pager.tsx +220 -0
- package/src/components/blocks/readability/fields.tsx +250 -0
- package/src/components/blocks/readability/menu.tsx +247 -0
- package/src/components/blocks/readability/track.tsx +165 -0
- package/src/components/blocks/search/command.tsx +80 -0
- package/src/components/blocks/search/dialog.tsx +724 -0
- package/src/components/blocks/search/provider.tsx +118 -0
- package/src/components/blocks/sidebar.tsx +406 -0
- package/src/components/blocks/sprite.tsx +231 -0
- package/src/components/blocks/text/format-text.tsx +110 -0
- package/src/components/blocks/theme/toggle.tsx +75 -0
- package/src/components/blocks/tooltip/hint.tsx +28 -0
- package/src/components/blocks/tooltip/lazy.tsx +41 -0
- package/src/components/blocks/viewer/controls.tsx +284 -0
- package/src/components/blocks/viewer/float-bar.tsx +51 -0
- package/src/components/layouts/layout.tsx +94 -0
- package/src/components/layouts/left-sidebar/content.tsx +63 -0
- package/src/components/layouts/left-sidebar/context.tsx +55 -0
- package/src/components/layouts/left-sidebar/expand.tsx +23 -0
- package/src/components/layouts/left-sidebar/footer.tsx +111 -0
- package/src/components/layouts/left-sidebar/index.ts +29 -0
- package/src/components/layouts/left-sidebar/items.tsx +103 -0
- package/src/components/layouts/left-sidebar/search.tsx +75 -0
- package/src/components/layouts/left-sidebar/sidebar.tsx +189 -0
- package/src/components/layouts/left-sidebar/tree.tsx +157 -0
- package/src/components/layouts/right-sidebar.tsx +96 -0
- package/src/components/layouts/tree-context.tsx +42 -0
- package/src/components/mdx/accordion.tsx +185 -0
- package/src/components/mdx/banner.tsx +157 -0
- package/src/components/mdx/callout.tsx +97 -0
- package/src/components/mdx/card.tsx +56 -0
- package/src/components/mdx/codeblock.tsx +250 -0
- package/src/components/mdx/collapsible.tsx +33 -0
- package/src/components/mdx/files.tsx +63 -0
- package/src/components/mdx/glow-header.tsx +54 -0
- package/src/components/mdx/gradient-text.tsx +28 -0
- package/src/components/mdx/icon.tsx +35 -0
- package/src/components/mdx/image-zoom.tsx +315 -0
- package/src/components/mdx/math.tsx +30 -0
- package/src/components/mdx/mermaid.tsx +23 -0
- package/src/components/mdx/multiblock.tsx +19 -0
- package/src/components/mdx/preview.tsx +101 -0
- package/src/components/mdx/steps.tsx +10 -0
- package/src/components/mdx/table.tsx +14 -0
- package/src/components/mdx/tabs.tsx +354 -0
- package/src/components/mdx/type-table.tsx +171 -0
- package/src/components/provider.tsx +139 -0
- package/src/components/ui/accordion.tsx +71 -0
- package/src/components/ui/alert-dialog.tsx +187 -0
- package/src/components/ui/alert.tsx +75 -0
- package/src/components/ui/aspect-ratio.tsx +22 -0
- package/src/components/ui/attachment.tsx +207 -0
- package/src/components/ui/avatar.tsx +108 -0
- package/src/components/ui/badge.tsx +51 -0
- package/src/components/ui/breadcrumb.tsx +124 -0
- package/src/components/ui/bubble.tsx +127 -0
- package/src/components/ui/button-group.tsx +87 -0
- package/src/components/ui/button.tsx +57 -0
- package/src/components/ui/calendar.tsx +221 -0
- package/src/components/ui/card.tsx +102 -0
- package/src/components/ui/carousel.tsx +242 -0
- package/src/components/ui/chart.tsx +371 -0
- package/src/components/ui/checkbox.tsx +28 -0
- package/src/components/ui/collapsible.tsx +21 -0
- package/src/components/ui/combobox.tsx +297 -0
- package/src/components/ui/command.tsx +198 -0
- package/src/components/ui/context-menu.tsx +270 -0
- package/src/components/ui/dialog.tsx +160 -0
- package/src/components/ui/direction.tsx +6 -0
- package/src/components/ui/drawer.tsx +227 -0
- package/src/components/ui/dropdown-menu.tsx +269 -0
- package/src/components/ui/empty.tsx +103 -0
- package/src/components/ui/field.tsx +238 -0
- package/src/components/ui/hover-card.tsx +50 -0
- package/src/components/ui/input-group.tsx +158 -0
- package/src/components/ui/input-otp.tsx +86 -0
- package/src/components/ui/input.tsx +19 -0
- package/src/components/ui/item.tsx +201 -0
- package/src/components/ui/kbd.tsx +26 -0
- package/src/components/ui/label.tsx +19 -0
- package/src/components/ui/marker.tsx +70 -0
- package/src/components/ui/menubar.tsx +280 -0
- package/src/components/ui/message-scroller.tsx +131 -0
- package/src/components/ui/message.tsx +91 -0
- package/src/components/ui/native-select.tsx +60 -0
- package/src/components/ui/navigation-menu.tsx +167 -0
- package/src/components/ui/pagination.tsx +130 -0
- package/src/components/ui/popover.tsx +91 -0
- package/src/components/ui/progress.tsx +82 -0
- package/src/components/ui/questionnaire.tsx +324 -0
- package/src/components/ui/radio-group.tsx +37 -0
- package/src/components/ui/resizable.tsx +49 -0
- package/src/components/ui/scroll-area.tsx +54 -0
- package/src/components/ui/select.tsx +200 -0
- package/src/components/ui/separator.tsx +24 -0
- package/src/components/ui/sheet.tsx +138 -0
- package/src/components/ui/sidebar.tsx +730 -0
- package/src/components/ui/skeleton.tsx +13 -0
- package/src/components/ui/slider.tsx +51 -0
- package/src/components/ui/spinner.tsx +10 -0
- package/src/components/ui/switch.tsx +31 -0
- package/src/components/ui/table.tsx +115 -0
- package/src/components/ui/tabs.tsx +81 -0
- package/src/components/ui/textarea.tsx +17 -0
- package/src/components/ui/toast.tsx +234 -0
- package/src/components/ui/toggle-group.tsx +89 -0
- package/src/components/ui/toggle.tsx +44 -0
- package/src/components/ui/tooltip.tsx +65 -0
- package/src/hooks/canvas/use-flow-hover.ts +19 -0
- package/src/hooks/canvas/use-flow-viewport-persist.ts +34 -0
- package/src/hooks/page/use-fit-pages.ts +92 -0
- package/src/hooks/page/use-location-search.ts +31 -0
- package/src/hooks/page/use-page-preview.ts +41 -0
- package/src/hooks/page/use-paged-list.ts +21 -0
- package/src/hooks/readability/use-readability.ts +87 -0
- package/src/hooks/search/use-dialog.ts +42 -0
- package/src/hooks/search/use-highlight-query.ts +58 -0
- package/src/hooks/search/use-provider.ts +26 -0
- package/src/hooks/use-async-value.ts +60 -0
- package/src/hooks/use-close-on-scroll.ts +24 -0
- package/src/hooks/use-copy-button.ts +47 -0
- package/src/hooks/use-cycle-index.ts +76 -0
- package/src/hooks/use-document-title.ts +10 -0
- package/src/hooks/use-element-size.ts +36 -0
- package/src/hooks/use-external-meta.ts +133 -0
- package/src/hooks/use-hot-key.ts +34 -0
- package/src/hooks/use-hover-follow.ts +55 -0
- package/src/hooks/use-in-view.ts +31 -0
- package/src/hooks/use-lang.ts +9 -0
- package/src/hooks/use-last-value.ts +16 -0
- package/src/hooks/use-layout.ts +19 -0
- package/src/hooks/use-marquee.ts +52 -0
- package/src/hooks/use-media-query.ts +15 -0
- package/src/hooks/use-mobile.ts +20 -0
- package/src/hooks/use-modifier-keys.ts +32 -0
- package/src/hooks/use-on-change.ts +36 -0
- package/src/hooks/use-pane-keys.ts +29 -0
- package/src/hooks/use-sidebar.ts +64 -0
- package/src/hooks/use-swipe.ts +27 -0
- package/src/hooks/use-tree.ts +100 -0
- package/src/hooks/viewer/use-in-float-bar.ts +7 -0
- package/src/hooks/viewer/use-viewer-prefs.ts +78 -0
- package/src/lib/canvas/edge.ts +202 -0
- package/src/lib/canvas/geometry.ts +54 -0
- package/src/lib/canvas/state.ts +48 -0
- package/src/lib/canvas/viewport.ts +38 -0
- package/src/lib/canvas/xyflow.ts +2 -0
- package/src/lib/config.ts +106 -0
- package/src/lib/mdx/callout.ts +21 -0
- package/src/lib/mdx/gradient.ts +16 -0
- package/src/lib/mdx/mermaid.ts +15 -0
- package/src/lib/media/crop-opaque.ts +77 -0
- package/src/lib/media/nearby-indexes.ts +7 -0
- package/src/lib/media/trim-transparent.ts +118 -0
- package/src/lib/readability/config.ts +11 -0
- package/src/lib/readability/spotlight.ts +187 -0
- package/src/lib/readability/store.ts +147 -0
- package/src/lib/tree.ts +90 -0
- package/src/lib/utils/cn.ts +2 -0
- package/src/lib/utils/format.ts +22 -0
- package/src/lib/utils/highlight-style.ts +10 -0
- package/src/lib/utils/history.ts +10 -0
- package/src/lib/utils/merge-refs.ts +14 -0
- package/src/lib/utils/nav-active.ts +59 -0
- package/src/lib/utils/stored-value.ts +137 -0
- package/src/lib/utils/urls.ts +18 -0
- package/src/locales/en_us.json +110 -0
- package/src/locales/pl_pl.json +33 -0
- package/src/locales/ru_ru.json +110 -0
- package/src/locales/uk_ua.json +33 -0
- package/src/locales/zh_cn.json +15 -0
- package/src/locales/zh_tw.json +15 -0
- package/src/locales.ts +6 -0
- package/src/types/canvas.ts +54 -0
- package/src/types/glb.ts +26 -0
- package/src/types/mdx-directives.ts +106 -0
- package/src/types/nav.ts +96 -0
- package/src/types/preview.ts +15 -0
- package/src/types/readability.ts +29 -0
- package/src/types/search.ts +57 -0
- package/src/types/tree.ts +19 -0
- package/src/types/viewer.ts +54 -0
- package/styles/content/base.css +198 -0
- package/styles/content/default-colors.css +51 -0
- package/styles/content/shiki.css +107 -0
- package/styles/content/typography.mjs +3637 -0
- package/styles/content.css +5 -0
- package/styles/image-zoom.css +83 -0
- package/styles/layout.css +28 -0
- package/styles/left-sidebar.css +140 -0
- package/styles/readability.css +50 -0
- package/styles/right-sidebar.css +6 -0
- package/styles/workspace.css +26 -0
- package/styles.css +430 -0
- package/README.md +0 -3
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { OrbitControls } from '@react-three/drei';
|
|
4
|
+
import { Canvas, useLoader } from '@react-three/fiber';
|
|
5
|
+
import {
|
|
6
|
+
Component,
|
|
7
|
+
Suspense,
|
|
8
|
+
useCallback,
|
|
9
|
+
useEffect,
|
|
10
|
+
useMemo,
|
|
11
|
+
useRef,
|
|
12
|
+
useState,
|
|
13
|
+
type ReactNode,
|
|
14
|
+
} from 'react';
|
|
15
|
+
import {
|
|
16
|
+
Gauge,
|
|
17
|
+
Grid3x3,
|
|
18
|
+
MoveHorizontal,
|
|
19
|
+
MoveVertical,
|
|
20
|
+
Play,
|
|
21
|
+
RotateCw,
|
|
22
|
+
Timer,
|
|
23
|
+
} from 'lucide-react';
|
|
24
|
+
import type { WebGLRenderer } from 'three';
|
|
25
|
+
import {
|
|
26
|
+
ViewerToolbar,
|
|
27
|
+
ViewerControls,
|
|
28
|
+
} from '@terrafirmagreg-team/ui/components/blocks/viewer/controls';
|
|
29
|
+
import {
|
|
30
|
+
GlbModel,
|
|
31
|
+
glbLoaderClass,
|
|
32
|
+
GlbSceneApi,
|
|
33
|
+
} from '@terrafirmagreg-team/ui/components/blocks/media/glb/model';
|
|
34
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
35
|
+
import { useCycleIndex } from '@terrafirmagreg-team/ui/hooks/use-cycle-index';
|
|
36
|
+
import {
|
|
37
|
+
AUTOPLAY_SPEED_MAX,
|
|
38
|
+
AUTOPLAY_SPEED_MIN,
|
|
39
|
+
ROTATE_MAX,
|
|
40
|
+
ROTATE_MIN,
|
|
41
|
+
SCENE_HEIGHT_MAX,
|
|
42
|
+
SCENE_HEIGHT_MIN,
|
|
43
|
+
SCENE_WIDTH_MAX,
|
|
44
|
+
SCENE_WIDTH_MIN,
|
|
45
|
+
useViewerPrefs,
|
|
46
|
+
} from '@terrafirmagreg-team/ui/hooks/viewer/use-viewer-prefs';
|
|
47
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
48
|
+
import type {
|
|
49
|
+
GlbHomeView,
|
|
50
|
+
GlbOrbitControls,
|
|
51
|
+
GlbSceneHandle,
|
|
52
|
+
GlbSessionProps,
|
|
53
|
+
} from '@terrafirmagreg-team/ui/types/glb';
|
|
54
|
+
|
|
55
|
+
class ErrorBoundary extends Component<
|
|
56
|
+
{ children?: ReactNode; onError?: (error: unknown) => void },
|
|
57
|
+
{ hasError: boolean }
|
|
58
|
+
> {
|
|
59
|
+
state = { hasError: false };
|
|
60
|
+
static getDerivedStateFromError() {
|
|
61
|
+
return { hasError: true };
|
|
62
|
+
}
|
|
63
|
+
componentDidCatch(error: unknown) {
|
|
64
|
+
this.props.onError?.(error);
|
|
65
|
+
}
|
|
66
|
+
render() {
|
|
67
|
+
return this.state.hasError ? null : this.props.children;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const GLB_ZOOM_STEP = 1.3;
|
|
72
|
+
|
|
73
|
+
export function GlbScene({
|
|
74
|
+
urls,
|
|
75
|
+
title,
|
|
76
|
+
scale,
|
|
77
|
+
offset,
|
|
78
|
+
bare = false,
|
|
79
|
+
resolveResource,
|
|
80
|
+
}: {
|
|
81
|
+
urls: string[];
|
|
82
|
+
title?: string;
|
|
83
|
+
scale?: number;
|
|
84
|
+
offset?: number;
|
|
85
|
+
bare?: boolean;
|
|
86
|
+
resolveResource?: (
|
|
87
|
+
resourceUrl: string,
|
|
88
|
+
modelUrl: string,
|
|
89
|
+
) => string | undefined;
|
|
90
|
+
}) {
|
|
91
|
+
const t = useTranslations();
|
|
92
|
+
const {
|
|
93
|
+
autoplay,
|
|
94
|
+
setAutoplay,
|
|
95
|
+
autoplaySpeed,
|
|
96
|
+
setAutoplaySpeed,
|
|
97
|
+
autoRotate,
|
|
98
|
+
setAutoRotate,
|
|
99
|
+
rotateSpeed,
|
|
100
|
+
setRotateSpeed,
|
|
101
|
+
dotGrid,
|
|
102
|
+
setDotGrid,
|
|
103
|
+
sceneWidth,
|
|
104
|
+
setSceneWidth,
|
|
105
|
+
sceneHeight,
|
|
106
|
+
setSceneHeight,
|
|
107
|
+
} = useViewerPrefs();
|
|
108
|
+
const [hovered, setHovered] = useState(false);
|
|
109
|
+
const [selected, setSelected] = useCycleIndex(urls.length, {
|
|
110
|
+
enabled: autoplay,
|
|
111
|
+
paused: hovered,
|
|
112
|
+
intervalMs: autoplaySpeed * 1000,
|
|
113
|
+
});
|
|
114
|
+
const [active, setActive] = useState(false);
|
|
115
|
+
const hostRef = useRef<HTMLDivElement>(null);
|
|
116
|
+
const surfaceRef = useRef<HTMLDivElement>(null);
|
|
117
|
+
const apiRef = useRef<GlbSceneHandle>(null);
|
|
118
|
+
const controlsRef = useRef<GlbOrbitControls>(null);
|
|
119
|
+
const homeRef = useRef<GlbHomeView | null>(null);
|
|
120
|
+
const initializedRef = useRef(false);
|
|
121
|
+
const rendererRef = useRef<WebGLRenderer | null>(null);
|
|
122
|
+
const label = title || t('3D model', { note: 'ui.viewer.label' });
|
|
123
|
+
const url = urls[Math.min(selected, urls.length - 1)];
|
|
124
|
+
const [statusEntry, setStatusEntry] = useState<{
|
|
125
|
+
url: string;
|
|
126
|
+
status: 'loading' | 'ready' | 'error';
|
|
127
|
+
}>({ url, status: 'loading' });
|
|
128
|
+
const status = statusEntry.url === url ? statusEntry.status : 'loading';
|
|
129
|
+
const setStatus = useCallback(
|
|
130
|
+
(next: 'loading' | 'ready' | 'error') =>
|
|
131
|
+
setStatusEntry({ url, status: next }),
|
|
132
|
+
[url],
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const handleReady = useCallback(() => setStatus('ready'), [setStatus]);
|
|
136
|
+
const handleError = useCallback(() => setStatus('error'), [setStatus]);
|
|
137
|
+
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
const host = hostRef.current;
|
|
140
|
+
if (!host) return;
|
|
141
|
+
const io = new IntersectionObserver(
|
|
142
|
+
([entry]) => {
|
|
143
|
+
if (entry?.isIntersecting) {
|
|
144
|
+
setActive(true);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
rendererRef.current?.forceContextLoss();
|
|
148
|
+
rendererRef.current = null;
|
|
149
|
+
initializedRef.current = false;
|
|
150
|
+
setStatus('loading');
|
|
151
|
+
setActive(false);
|
|
152
|
+
},
|
|
153
|
+
{ rootMargin: '160px', threshold: 0.01 },
|
|
154
|
+
);
|
|
155
|
+
io.observe(host);
|
|
156
|
+
return () => io.disconnect();
|
|
157
|
+
}, [setStatus]);
|
|
158
|
+
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (!active || urls.length < 2) return;
|
|
161
|
+
const nextUrl = urls[(selected + 1) % urls.length];
|
|
162
|
+
if (nextUrl)
|
|
163
|
+
useLoader.preload(glbLoaderClass(nextUrl, resolveResource), nextUrl);
|
|
164
|
+
}, [active, selected, urls, resolveResource]);
|
|
165
|
+
|
|
166
|
+
const flip = typeof scale === 'number' && scale < 0;
|
|
167
|
+
const multi = urls.length > 1;
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<div
|
|
171
|
+
ref={surfaceRef}
|
|
172
|
+
className={cn(
|
|
173
|
+
'not-prose overflow-hidden',
|
|
174
|
+
bare
|
|
175
|
+
? 'relative h-full w-full'
|
|
176
|
+
: 'viewer-surface mx-auto my-3 rounded-xl border border-border',
|
|
177
|
+
)}
|
|
178
|
+
style={bare ? undefined : { width: `${sceneWidth}%` }}
|
|
179
|
+
onPointerEnter={() => setHovered(true)}
|
|
180
|
+
onPointerLeave={() => setHovered(false)}
|
|
181
|
+
onFocus={() => setHovered(true)}
|
|
182
|
+
onBlur={() => setHovered(false)}
|
|
183
|
+
>
|
|
184
|
+
<div
|
|
185
|
+
className={cn(
|
|
186
|
+
'relative w-full',
|
|
187
|
+
bare ? 'h-full' : 'viewer-scene',
|
|
188
|
+
!bare && dotGrid && 'viewer-dots',
|
|
189
|
+
)}
|
|
190
|
+
style={bare ? undefined : { height: sceneHeight }}
|
|
191
|
+
>
|
|
192
|
+
<div
|
|
193
|
+
ref={hostRef}
|
|
194
|
+
className="absolute inset-0 transition-opacity duration-300"
|
|
195
|
+
style={{ opacity: status === 'ready' ? 1 : 0 }}
|
|
196
|
+
>
|
|
197
|
+
{active ? (
|
|
198
|
+
<Canvas
|
|
199
|
+
flat
|
|
200
|
+
gl={{ antialias: true, alpha: true }}
|
|
201
|
+
dpr={[1, 2]}
|
|
202
|
+
camera={{ fov: 35, position: [4, 3, 6] }}
|
|
203
|
+
role="img"
|
|
204
|
+
aria-label={label}
|
|
205
|
+
onCreated={({ gl }) => {
|
|
206
|
+
rendererRef.current = gl;
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
<ambientLight intensity={0.85} />
|
|
210
|
+
<directionalLight position={[6, 10, 4]} intensity={1.1} />
|
|
211
|
+
<ErrorBoundary key={url} onError={handleError}>
|
|
212
|
+
<Suspense fallback={null}>
|
|
213
|
+
<GlbModel
|
|
214
|
+
url={url}
|
|
215
|
+
flip={flip}
|
|
216
|
+
scale={scale}
|
|
217
|
+
offset={offset}
|
|
218
|
+
controlsRef={controlsRef}
|
|
219
|
+
homeRef={homeRef}
|
|
220
|
+
initializedRef={initializedRef}
|
|
221
|
+
resolveResource={resolveResource}
|
|
222
|
+
onReady={handleReady}
|
|
223
|
+
/>
|
|
224
|
+
</Suspense>
|
|
225
|
+
</ErrorBoundary>
|
|
226
|
+
<GlbSceneApi
|
|
227
|
+
ref={apiRef}
|
|
228
|
+
controlsRef={controlsRef}
|
|
229
|
+
homeRef={homeRef}
|
|
230
|
+
/>
|
|
231
|
+
<OrbitControls
|
|
232
|
+
makeDefault
|
|
233
|
+
enableDamping
|
|
234
|
+
autoRotate={autoRotate}
|
|
235
|
+
autoRotateSpeed={rotateSpeed}
|
|
236
|
+
ref={controlsRef}
|
|
237
|
+
/>
|
|
238
|
+
</Canvas>
|
|
239
|
+
) : null}
|
|
240
|
+
</div>
|
|
241
|
+
{bare ? null : (
|
|
242
|
+
<ViewerToolbar>
|
|
243
|
+
<ViewerControls
|
|
244
|
+
pager={
|
|
245
|
+
multi
|
|
246
|
+
? { index: selected, count: urls.length, onSelect: setSelected }
|
|
247
|
+
: undefined
|
|
248
|
+
}
|
|
249
|
+
zoom={{
|
|
250
|
+
onZoomIn: () => apiRef.current?.zoomBy(1 / GLB_ZOOM_STEP),
|
|
251
|
+
onZoomOut: () => apiRef.current?.zoomBy(GLB_ZOOM_STEP),
|
|
252
|
+
onFit: () => apiRef.current?.reset(),
|
|
253
|
+
fitLabel: t('Reset view', { note: 'ui.viewer.reset_view' }),
|
|
254
|
+
}}
|
|
255
|
+
expand={{ target: surfaceRef }}
|
|
256
|
+
settings={{
|
|
257
|
+
label: t('Viewer settings', { note: 'ui.viewer.settings' }),
|
|
258
|
+
sliders: [
|
|
259
|
+
{
|
|
260
|
+
icon: <MoveHorizontal />,
|
|
261
|
+
label: t('Width', { note: 'ui.viewer.width' }),
|
|
262
|
+
min: SCENE_WIDTH_MIN,
|
|
263
|
+
max: SCENE_WIDTH_MAX,
|
|
264
|
+
step: 5,
|
|
265
|
+
format: (value) => `${value}%`,
|
|
266
|
+
value: sceneWidth,
|
|
267
|
+
onChange: setSceneWidth,
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
icon: <MoveVertical />,
|
|
271
|
+
label: t('Height', { note: 'ui.viewer.height' }),
|
|
272
|
+
min: SCENE_HEIGHT_MIN,
|
|
273
|
+
max: SCENE_HEIGHT_MAX,
|
|
274
|
+
step: 16,
|
|
275
|
+
format: (value) => `${value}px`,
|
|
276
|
+
value: sceneHeight,
|
|
277
|
+
onChange: setSceneHeight,
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
icon: <Gauge />,
|
|
281
|
+
label: t('Rotate speed', { note: 'ui.viewer.rotate_speed' }),
|
|
282
|
+
min: ROTATE_MIN,
|
|
283
|
+
max: ROTATE_MAX,
|
|
284
|
+
step: 0.1,
|
|
285
|
+
format: (value) => `${value.toFixed(1)}×`,
|
|
286
|
+
value: rotateSpeed,
|
|
287
|
+
onChange: setRotateSpeed,
|
|
288
|
+
},
|
|
289
|
+
...(multi
|
|
290
|
+
? [
|
|
291
|
+
{
|
|
292
|
+
icon: <Timer />,
|
|
293
|
+
label: t('Autoplay speed', { note: 'ui.viewer.autoplay_speed' }),
|
|
294
|
+
min: AUTOPLAY_SPEED_MIN,
|
|
295
|
+
max: AUTOPLAY_SPEED_MAX,
|
|
296
|
+
step: 0.5,
|
|
297
|
+
disabled: !autoplay,
|
|
298
|
+
format: (value: number) => `${value.toFixed(1)}s`,
|
|
299
|
+
value: autoplaySpeed,
|
|
300
|
+
onChange: setAutoplaySpeed,
|
|
301
|
+
},
|
|
302
|
+
]
|
|
303
|
+
: []),
|
|
304
|
+
],
|
|
305
|
+
toggles: [
|
|
306
|
+
{
|
|
307
|
+
icon: <RotateCw />,
|
|
308
|
+
label: t('Spin', { note: 'ui.viewer.spin' }),
|
|
309
|
+
checked: autoRotate,
|
|
310
|
+
onChange: setAutoRotate,
|
|
311
|
+
},
|
|
312
|
+
...(multi
|
|
313
|
+
? [
|
|
314
|
+
{
|
|
315
|
+
icon: <Play />,
|
|
316
|
+
label: t('Autoplay', { note: 'ui.viewer.autoplay' }),
|
|
317
|
+
checked: autoplay,
|
|
318
|
+
onChange: setAutoplay,
|
|
319
|
+
},
|
|
320
|
+
]
|
|
321
|
+
: []),
|
|
322
|
+
{
|
|
323
|
+
icon: <Grid3x3 />,
|
|
324
|
+
label: t('Grid', { note: 'ui.viewer.grid' }),
|
|
325
|
+
checked: dotGrid,
|
|
326
|
+
onChange: setDotGrid,
|
|
327
|
+
},
|
|
328
|
+
],
|
|
329
|
+
}}
|
|
330
|
+
/>
|
|
331
|
+
</ViewerToolbar>
|
|
332
|
+
)}
|
|
333
|
+
{status === 'loading' ? (
|
|
334
|
+
<p className="pointer-events-none absolute inset-0 flex items-center justify-center text-sm text-muted-foreground">
|
|
335
|
+
{t('Loading…', { note: 'ui.viewer.loading' })}
|
|
336
|
+
</p>
|
|
337
|
+
) : status === 'error' ? (
|
|
338
|
+
<p className="pointer-events-none absolute inset-0 flex items-center justify-center text-sm text-muted-foreground">
|
|
339
|
+
{t('Image unavailable', { note: 'ui.image_unavailable' })}
|
|
340
|
+
</p>
|
|
341
|
+
) : null}
|
|
342
|
+
</div>
|
|
343
|
+
</div>
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export function GlbSession({
|
|
348
|
+
src,
|
|
349
|
+
sources,
|
|
350
|
+
title,
|
|
351
|
+
scale,
|
|
352
|
+
offset,
|
|
353
|
+
bare = false,
|
|
354
|
+
resolveResource,
|
|
355
|
+
}: GlbSessionProps) {
|
|
356
|
+
const urls = useMemo(
|
|
357
|
+
() => (sources?.length ? sources : src ? [src] : []).filter(Boolean),
|
|
358
|
+
[src, sources],
|
|
359
|
+
);
|
|
360
|
+
if (urls.length === 0) return null;
|
|
361
|
+
return (
|
|
362
|
+
<GlbScene
|
|
363
|
+
key={urls.join('\0')}
|
|
364
|
+
urls={urls}
|
|
365
|
+
title={title}
|
|
366
|
+
scale={scale}
|
|
367
|
+
offset={offset}
|
|
368
|
+
bare={bare}
|
|
369
|
+
resolveResource={resolveResource}
|
|
370
|
+
/>
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import dynamic from 'next/dynamic';
|
|
2
|
+
import { Box } from 'lucide-react';
|
|
3
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
4
|
+
|
|
5
|
+
export const GlbViewer = dynamic(
|
|
6
|
+
() =>
|
|
7
|
+
import('@terrafirmagreg-team/ui/components/blocks/media/glb/scene').then(
|
|
8
|
+
(mod) => mod.GlbSession,
|
|
9
|
+
),
|
|
10
|
+
{ loading: () => <GlbPlaceholder /> },
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
export const GlbEmbedViewer = dynamic(
|
|
14
|
+
() =>
|
|
15
|
+
import('@terrafirmagreg-team/ui/components/blocks/media/glb/scene').then(
|
|
16
|
+
(mod) => mod.GlbSession,
|
|
17
|
+
),
|
|
18
|
+
{ loading: () => <GlbPlaceholder bare /> },
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export function GlbPlaceholder({
|
|
22
|
+
title,
|
|
23
|
+
bare,
|
|
24
|
+
}: {
|
|
25
|
+
title?: string;
|
|
26
|
+
bare?: boolean;
|
|
27
|
+
}) {
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
className={cn(
|
|
31
|
+
'not-prose overflow-hidden',
|
|
32
|
+
bare
|
|
33
|
+
? 'h-full w-full'
|
|
34
|
+
: 'viewer-surface my-3 rounded-xl border border-border',
|
|
35
|
+
)}
|
|
36
|
+
aria-label={title}
|
|
37
|
+
>
|
|
38
|
+
<div
|
|
39
|
+
className={cn(
|
|
40
|
+
'flex items-center justify-center',
|
|
41
|
+
bare ? 'h-full w-full' : 'viewer-scene h-72 w-full',
|
|
42
|
+
)}
|
|
43
|
+
aria-hidden
|
|
44
|
+
>
|
|
45
|
+
{bare ? null : (
|
|
46
|
+
<Box className="size-10 text-muted-foreground/40" />
|
|
47
|
+
)}
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useState, type CSSProperties } from 'react';
|
|
4
|
+
import { useAsyncEffect, useAsyncResult, useAsyncValue } from '@terrafirmagreg-team/ui/hooks/use-async-value';
|
|
5
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
6
|
+
import { cropOpaqueImageDataUrl } from '@terrafirmagreg-team/ui/lib/media/crop-opaque';
|
|
7
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
8
|
+
|
|
9
|
+
export function MediaImage({
|
|
10
|
+
src,
|
|
11
|
+
alt,
|
|
12
|
+
eager = false,
|
|
13
|
+
className,
|
|
14
|
+
style,
|
|
15
|
+
href,
|
|
16
|
+
missing = 'box',
|
|
17
|
+
crop = false,
|
|
18
|
+
width,
|
|
19
|
+
height,
|
|
20
|
+
align,
|
|
21
|
+
pixelated,
|
|
22
|
+
onError,
|
|
23
|
+
}: {
|
|
24
|
+
src?: string | Promise<string | undefined> | null;
|
|
25
|
+
alt?: string;
|
|
26
|
+
eager?: boolean;
|
|
27
|
+
className?: string;
|
|
28
|
+
style?: CSSProperties;
|
|
29
|
+
href?: string | Promise<string | undefined>;
|
|
30
|
+
missing?: 'box' | 'hide';
|
|
31
|
+
crop?: boolean;
|
|
32
|
+
width?: number;
|
|
33
|
+
height?: number;
|
|
34
|
+
align?: 'center' | string;
|
|
35
|
+
pixelated?: boolean;
|
|
36
|
+
onError?: () => void;
|
|
37
|
+
}) {
|
|
38
|
+
const t = useTranslations();
|
|
39
|
+
const asyncSrc = src != null && typeof src !== 'string';
|
|
40
|
+
const { value: resolved, pending } = useAsyncResult(
|
|
41
|
+
asyncSrc ? () => src : false,
|
|
42
|
+
[src],
|
|
43
|
+
);
|
|
44
|
+
const url = asyncSrc ? resolved : (src ?? undefined);
|
|
45
|
+
const resolvedHref = useAsyncValue(
|
|
46
|
+
href === undefined
|
|
47
|
+
? false
|
|
48
|
+
: typeof href === 'string'
|
|
49
|
+
? () => Promise.resolve(href)
|
|
50
|
+
: () => href,
|
|
51
|
+
[href],
|
|
52
|
+
);
|
|
53
|
+
const sourceKey = url ?? '';
|
|
54
|
+
const [state, setState] = useState<{
|
|
55
|
+
key: string;
|
|
56
|
+
cropped?: string;
|
|
57
|
+
failed?: boolean;
|
|
58
|
+
}>({ key: sourceKey });
|
|
59
|
+
const failed = state.key === sourceKey && state.failed === true;
|
|
60
|
+
const cropped = state.key === sourceKey ? state.cropped : undefined;
|
|
61
|
+
|
|
62
|
+
useAsyncEffect(
|
|
63
|
+
url && crop
|
|
64
|
+
? (isCancelled) => {
|
|
65
|
+
const img = new Image();
|
|
66
|
+
img.onload = () => {
|
|
67
|
+
if (!isCancelled()) {
|
|
68
|
+
setState({
|
|
69
|
+
key: url,
|
|
70
|
+
cropped: cropOpaqueImageDataUrl(img),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
img.onerror = () => {
|
|
75
|
+
if (!isCancelled()) {
|
|
76
|
+
setState({ key: url, failed: true });
|
|
77
|
+
onError?.();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
img.src = url;
|
|
81
|
+
}
|
|
82
|
+
: false,
|
|
83
|
+
[url, crop],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
if (asyncSrc && pending) return null;
|
|
87
|
+
if (!url || failed) {
|
|
88
|
+
if (missing === 'hide') return null;
|
|
89
|
+
return (
|
|
90
|
+
<div
|
|
91
|
+
role="img"
|
|
92
|
+
aria-label={alt || t('Image unavailable', { note: 'ui.image_unavailable' })}
|
|
93
|
+
className={cn(
|
|
94
|
+
'flex min-h-24 w-full items-center justify-center rounded-md border border-border bg-secondary text-sm text-muted-foreground',
|
|
95
|
+
className,
|
|
96
|
+
)}
|
|
97
|
+
>
|
|
98
|
+
{t('Image unavailable', { note: 'ui.image_unavailable' })}
|
|
99
|
+
</div>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const img = (
|
|
104
|
+
// eslint-disable-next-line @next/next/no-img-element
|
|
105
|
+
<img
|
|
106
|
+
src={cropped ?? url}
|
|
107
|
+
alt={alt}
|
|
108
|
+
width={width}
|
|
109
|
+
height={height}
|
|
110
|
+
loading={eager ? 'eager' : 'lazy'}
|
|
111
|
+
decoding={eager ? 'sync' : 'async'}
|
|
112
|
+
fetchPriority={eager ? 'high' : 'auto'}
|
|
113
|
+
className={cn(crop ? 'max-w-full object-contain' : undefined, className)}
|
|
114
|
+
style={{
|
|
115
|
+
...style,
|
|
116
|
+
...(pixelated ? { imageRendering: 'pixelated' } : null),
|
|
117
|
+
}}
|
|
118
|
+
onError={() => {
|
|
119
|
+
setState({ key: sourceKey, failed: true });
|
|
120
|
+
onError?.();
|
|
121
|
+
}}
|
|
122
|
+
/>
|
|
123
|
+
);
|
|
124
|
+
if (!resolvedHref) return img;
|
|
125
|
+
return (
|
|
126
|
+
<a
|
|
127
|
+
href={resolvedHref}
|
|
128
|
+
target="_blank"
|
|
129
|
+
rel="noreferrer"
|
|
130
|
+
className={align === 'center' ? 'mx-auto block w-fit' : 'contents'}
|
|
131
|
+
>
|
|
132
|
+
{img}
|
|
133
|
+
</a>
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|