@terrafirmagreg-team/ui 0.0.0-stage → 0.1.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 +48 -0
- package/src/components/blocks/canvas/chevron-edge.tsx +134 -0
- package/src/components/blocks/canvas/flow-canvas.tsx +177 -0
- package/src/components/blocks/canvas/flow-toolbar.tsx +32 -0
- package/src/components/blocks/canvas/flow-viewport.tsx +243 -0
- package/src/components/blocks/git/github-info.tsx +77 -0
- package/src/components/blocks/lang/content.tsx +22 -0
- package/src/components/blocks/lang/flag.tsx +24 -0
- package/src/components/blocks/lang/link.tsx +22 -0
- package/src/components/blocks/lang/redirect.tsx +47 -0
- package/src/components/blocks/lang/switcher.tsx +53 -0
- package/src/components/blocks/lang/untranslated-callout.tsx +28 -0
- package/src/components/blocks/link/link-preview.tsx +256 -0
- package/src/components/blocks/list/row.tsx +91 -0
- package/src/components/blocks/media/glb/model.tsx +243 -0
- package/src/components/blocks/media/glb/scene.tsx +372 -0
- package/src/components/blocks/media/glb/viewer.tsx +51 -0
- package/src/components/blocks/media/image.tsx +135 -0
- package/src/components/blocks/media/slideshow.tsx +177 -0
- package/src/components/blocks/nav/breadcrumb.tsx +50 -0
- package/src/components/blocks/nav/link.tsx +85 -0
- package/src/components/blocks/nav/site-menu.tsx +77 -0
- package/src/components/blocks/nav/site-title.tsx +60 -0
- package/src/components/blocks/nav/switcher.tsx +205 -0
- package/src/components/blocks/page/empty-state.tsx +31 -0
- package/src/components/blocks/page/heading.tsx +53 -0
- package/src/components/blocks/page/pager.tsx +112 -0
- package/src/components/blocks/readability/menu.tsx +431 -0
- package/src/components/blocks/readability/track.tsx +164 -0
- package/src/components/blocks/search/command.tsx +79 -0
- package/src/components/blocks/search/dialog.tsx +712 -0
- package/src/components/blocks/search/provider.tsx +117 -0
- package/src/components/blocks/sidebar.tsx +406 -0
- package/src/components/blocks/theme/toggle.tsx +71 -0
- package/src/components/blocks/tooltip/hint.tsx +27 -0
- package/src/components/blocks/viewer/controls.tsx +279 -0
- package/src/components/blocks/viewer/float-bar.tsx +50 -0
- package/src/components/layouts/layout.tsx +93 -0
- package/src/components/layouts/left-sidebar/content.tsx +62 -0
- package/src/components/layouts/left-sidebar/context.tsx +54 -0
- package/src/components/layouts/left-sidebar/expand.tsx +22 -0
- package/src/components/layouts/left-sidebar/footer.tsx +105 -0
- package/src/components/layouts/left-sidebar/index.ts +28 -0
- package/src/components/layouts/left-sidebar/items.tsx +102 -0
- package/src/components/layouts/left-sidebar/search.tsx +74 -0
- package/src/components/layouts/left-sidebar/sidebar.tsx +188 -0
- package/src/components/layouts/left-sidebar/tree.tsx +156 -0
- package/src/components/layouts/right-sidebar.tsx +95 -0
- package/src/components/layouts/tree-context.tsx +41 -0
- package/src/components/mdx/accordion.tsx +184 -0
- package/src/components/mdx/banner.tsx +154 -0
- package/src/components/mdx/callout.tsx +96 -0
- package/src/components/mdx/card.tsx +49 -0
- package/src/components/mdx/codeblock.tsx +249 -0
- package/src/components/mdx/collapsible.tsx +32 -0
- package/src/components/mdx/files.tsx +62 -0
- package/src/components/mdx/glow-header.tsx +40 -0
- package/src/components/mdx/gradient-text.tsx +27 -0
- package/src/components/mdx/image-zoom.tsx +314 -0
- package/src/components/mdx/mermaid.tsx +16 -0
- package/src/components/mdx/multiblock.tsx +18 -0
- package/src/components/mdx/preview.tsx +100 -0
- package/src/components/mdx/steps.tsx +9 -0
- package/src/components/mdx/table.tsx +13 -0
- package/src/components/mdx/tabs.tsx +353 -0
- package/src/components/mdx/type-table.tsx +170 -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 +18 -0
- package/src/hooks/canvas/use-flow-viewport-persist.ts +33 -0
- package/src/hooks/lang.ts +8 -0
- package/src/hooks/layout.ts +18 -0
- package/src/hooks/page/use-fit-pages.ts +91 -0
- package/src/hooks/page/use-location-search.ts +25 -0
- package/src/hooks/page/use-page-preview.ts +40 -0
- package/src/hooks/page/use-paged-list.ts +20 -0
- package/src/hooks/readability/provider.ts +86 -0
- package/src/hooks/search/dialog.ts +41 -0
- package/src/hooks/search/provider.ts +25 -0
- package/src/hooks/search/use-highlight-query.ts +51 -0
- package/src/hooks/sidebar.ts +63 -0
- package/src/hooks/use-async-value.ts +57 -0
- package/src/hooks/use-close-on-scroll.ts +23 -0
- package/src/hooks/use-copy-button.ts +46 -0
- package/src/hooks/use-cycle-index.ts +75 -0
- package/src/hooks/use-document-title.ts +9 -0
- package/src/hooks/use-element-size.ts +35 -0
- package/src/hooks/use-external-meta.ts +132 -0
- package/src/hooks/use-hot-key.ts +33 -0
- package/src/hooks/use-hover-follow.ts +54 -0
- package/src/hooks/use-in-view.ts +30 -0
- package/src/hooks/use-last-value.ts +15 -0
- package/src/hooks/use-marquee.ts +51 -0
- package/src/hooks/use-media-query.ts +14 -0
- package/src/hooks/use-mobile.ts +19 -0
- package/src/hooks/use-modifier-keys.ts +31 -0
- package/src/hooks/use-on-change.ts +35 -0
- package/src/hooks/use-pane-keys.ts +28 -0
- package/src/hooks/use-swipe.ts +26 -0
- package/src/hooks/use-tree.ts +102 -0
- package/src/hooks/viewer/use-in-float-bar.ts +6 -0
- package/src/hooks/viewer/use-viewer-prefs.ts +77 -0
- package/src/lib/canvas/edge.ts +173 -0
- package/src/lib/canvas/geometry.ts +53 -0
- package/src/lib/canvas/state.ts +47 -0
- package/src/lib/canvas/viewport.ts +37 -0
- package/src/lib/canvas/xyflow.ts +1 -0
- package/src/lib/config.ts +81 -0
- package/src/lib/mdx/callout.ts +20 -0
- package/src/lib/mdx/gradient.ts +15 -0
- package/src/lib/mdx/mermaid.ts +14 -0
- package/src/lib/media/crop-opaque.ts +76 -0
- package/src/lib/media/nearby-indexes.ts +6 -0
- package/src/lib/media/trim-transparent.ts +117 -0
- package/src/lib/readability/config.ts +10 -0
- package/src/lib/readability/spotlight.ts +186 -0
- package/src/lib/readability/store.ts +146 -0
- package/src/lib/tree.ts +92 -0
- package/src/lib/utils/async-cache.ts +32 -0
- package/src/lib/utils/cn.ts +1 -0
- package/src/lib/utils/format.ts +22 -0
- package/src/lib/utils/history.ts +9 -0
- package/src/lib/utils/merge-refs.ts +13 -0
- package/src/lib/utils/nav-active.ts +58 -0
- package/src/lib/utils/stored-value.ts +136 -0
- package/src/lib/utils/urls.ts +17 -0
- package/src/locales/en_us.json +119 -0
- package/src/locales/pl_pl.json +35 -0
- package/src/locales/ru_ru.json +119 -0
- package/src/locales/uk_ua.json +35 -0
- package/src/locales/zh_cn.json +17 -0
- package/src/locales/zh_tw.json +17 -0
- package/src/locales.ts +5 -0
- package/src/provider.tsx +141 -0
- package/src/types/canvas.ts +49 -0
- package/src/types/glb.ts +25 -0
- package/src/types/nav.ts +95 -0
- package/src/types/preview.ts +9 -0
- package/src/types/readability.ts +28 -0
- package/src/types/search.ts +56 -0
- package/src/types/tree.ts +18 -0
- package/src/types/viewer.ts +53 -0
- package/styles/content/base.css +194 -0
- package/styles/content/default-colors.css +51 -0
- package/styles/content/shiki.css +108 -0
- package/styles/content/typography.mjs +3941 -0
- package/styles/content.css +7 -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 +413 -0
- package/README.md +0 -3
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import Image, { type ImageProps } from 'next/image';
|
|
4
|
+
import {
|
|
5
|
+
type ComponentProps,
|
|
6
|
+
createContext,
|
|
7
|
+
type CSSProperties,
|
|
8
|
+
type ReactNode,
|
|
9
|
+
use,
|
|
10
|
+
useRef,
|
|
11
|
+
useState,
|
|
12
|
+
} from 'react';
|
|
13
|
+
import { createPortal, flushSync } from 'react-dom';
|
|
14
|
+
import Zoom, { type UncontrolledProps } from 'react-medium-image-zoom';
|
|
15
|
+
import { ChevronLeft, ChevronRight, X } from 'lucide-react';
|
|
16
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
17
|
+
import { buttonVariants } from '@terrafirmagreg-team/ui/components/ui/button';
|
|
18
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
19
|
+
import '../../../styles/image-zoom.css';
|
|
20
|
+
|
|
21
|
+
export type ImageZoomProps = ImageProps & {
|
|
22
|
+
|
|
23
|
+
zoomInProps?: ComponentProps<'img'>;
|
|
24
|
+
|
|
25
|
+
rmiz?: UncontrolledProps;
|
|
26
|
+
|
|
27
|
+
caption?: ReactNode;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
interface Item {
|
|
31
|
+
element: HTMLElement;
|
|
32
|
+
image: ComponentProps<'img'>;
|
|
33
|
+
caption?: ReactNode;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface Slide extends Item {
|
|
37
|
+
style?: CSSProperties;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const LightboxContext = createContext<{
|
|
41
|
+
register: (item: Item) => () => void;
|
|
42
|
+
open: (element: HTMLElement) => void;
|
|
43
|
+
} | null>(null);
|
|
44
|
+
|
|
45
|
+
function getImageSrc(src: ImageProps['src']): string {
|
|
46
|
+
if (typeof src === 'string') return src;
|
|
47
|
+
|
|
48
|
+
if (typeof src === 'object') {
|
|
49
|
+
|
|
50
|
+
if ('default' in src) return (src as { default: { src: string } }).default.src;
|
|
51
|
+
return src.src;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function ImageZoom({ zoomInProps, children, rmiz, caption, ...props }: ImageZoomProps) {
|
|
58
|
+
const lightbox = use(LightboxContext);
|
|
59
|
+
const zoomImg = { src: getImageSrc(props.src), sizes: undefined, ...zoomInProps };
|
|
60
|
+
const image = children ?? (
|
|
61
|
+
<Image sizes="(max-width: 768px) 100vw, (max-width: 1200px) 70vw, 900px" {...props} />
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
if (lightbox) {
|
|
65
|
+
return (
|
|
66
|
+
<span
|
|
67
|
+
role="button"
|
|
68
|
+
tabIndex={0}
|
|
69
|
+
aria-haspopup="dialog"
|
|
70
|
+
ref={(element) => {
|
|
71
|
+
if (!element) return;
|
|
72
|
+
return lightbox.register({
|
|
73
|
+
element,
|
|
74
|
+
image: { alt: props.alt, ...zoomImg },
|
|
75
|
+
caption: caption ?? props.title,
|
|
76
|
+
});
|
|
77
|
+
}}
|
|
78
|
+
onClick={(e) => {
|
|
79
|
+
if (e.target !== e.currentTarget) lightbox.open(e.currentTarget);
|
|
80
|
+
}}
|
|
81
|
+
onKeyDown={(e) => {
|
|
82
|
+
if (e.key !== 'Enter' && e.key !== ' ') return;
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
lightbox.open(e.currentTarget);
|
|
85
|
+
}}
|
|
86
|
+
className="block outline-none [&_img]:cursor-zoom-in [&:focus-visible_img]:ring-2 [&:focus-visible_img]:ring-ring"
|
|
87
|
+
>
|
|
88
|
+
{image}
|
|
89
|
+
</span>
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<Zoom zoomMargin={20} wrapElement="span" {...rmiz} zoomImg={zoomImg}>
|
|
95
|
+
{image}
|
|
96
|
+
</Zoom>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function Lightbox({ children }: { children: ReactNode }) {
|
|
101
|
+
const t = useTranslations();
|
|
102
|
+
const [slides, setSlides] = useState<Slide[] | null>(null);
|
|
103
|
+
const scrollerRef = useRef<HTMLDivElement>(null);
|
|
104
|
+
const [context] = useState(() => {
|
|
105
|
+
const items = new Set<Item>();
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
register(item: Item) {
|
|
109
|
+
items.add(item);
|
|
110
|
+
return () => void items.delete(item);
|
|
111
|
+
},
|
|
112
|
+
open(element: HTMLElement) {
|
|
113
|
+
const list: Slide[] = [];
|
|
114
|
+
for (const item of items) {
|
|
115
|
+
if (!item.element.checkVisibility()) continue;
|
|
116
|
+
const img = item.element.querySelector('img');
|
|
117
|
+
list.push({ ...item, style: img ? getSlideStyle(img) : undefined });
|
|
118
|
+
}
|
|
119
|
+
list.sort((a, b) =>
|
|
120
|
+
a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1,
|
|
121
|
+
);
|
|
122
|
+
const index = list.findIndex((slide) => slide.element === element);
|
|
123
|
+
|
|
124
|
+
transition(getImage(element), () => {
|
|
125
|
+
flushSync(() => setSlides(list));
|
|
126
|
+
const slide = scrollerRef.current!.children[index];
|
|
127
|
+
slide.scrollIntoView({ block: 'nearest', inline: 'start', behavior: 'instant' });
|
|
128
|
+
return slide.querySelector('img')!;
|
|
129
|
+
});
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
function close() {
|
|
135
|
+
const scroller = scrollerRef.current;
|
|
136
|
+
if (!scroller || !slides) return;
|
|
137
|
+
const index = getIndex(scroller);
|
|
138
|
+
const { element } = slides[index];
|
|
139
|
+
|
|
140
|
+
transition(scroller.children[index].querySelector('img')!, () => {
|
|
141
|
+
flushSync(() => setSlides(null));
|
|
142
|
+
element.focus({ preventScroll: true });
|
|
143
|
+
const image = getImage(element);
|
|
144
|
+
image.scrollIntoView({ block: 'nearest', behavior: 'instant' });
|
|
145
|
+
return image;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function navigate(step: number) {
|
|
150
|
+
const scroller = scrollerRef.current!;
|
|
151
|
+
scroller.children[getIndex(scroller) + step]?.scrollIntoView({
|
|
152
|
+
block: 'nearest',
|
|
153
|
+
inline: 'start',
|
|
154
|
+
behavior: 'smooth',
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<LightboxContext value={context}>
|
|
160
|
+
{children}
|
|
161
|
+
{slides &&
|
|
162
|
+
createPortal(
|
|
163
|
+
<dialog
|
|
164
|
+
ref={initDialog}
|
|
165
|
+
tabIndex={-1}
|
|
166
|
+
aria-label={t('ui.image_viewer', { note: 'aria-label' })}
|
|
167
|
+
onCancel={(e) => {
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
close();
|
|
170
|
+
}}
|
|
171
|
+
onClose={() => setSlides(null)}
|
|
172
|
+
onKeyDown={(e) => {
|
|
173
|
+
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
const rtl = getComputedStyle(e.currentTarget).direction === 'rtl';
|
|
176
|
+
navigate((e.key === 'ArrowRight') !== rtl ? 1 : -1);
|
|
177
|
+
}}
|
|
178
|
+
className="m-0 size-full max-h-none max-w-none overflow-hidden border-none bg-background p-0 text-foreground outline-none"
|
|
179
|
+
>
|
|
180
|
+
<button
|
|
181
|
+
type="button"
|
|
182
|
+
aria-label={t('ui.close', { note: 'aria-label' })}
|
|
183
|
+
onClick={close}
|
|
184
|
+
className={cn(
|
|
185
|
+
buttonVariants({
|
|
186
|
+
variant: 'ghost',
|
|
187
|
+
size: 'icon-sm',
|
|
188
|
+
className: 'absolute top-3.25 inset-e-2.5',
|
|
189
|
+
}),
|
|
190
|
+
)}
|
|
191
|
+
>
|
|
192
|
+
<X />
|
|
193
|
+
</button>
|
|
194
|
+
<div
|
|
195
|
+
ref={scrollerRef}
|
|
196
|
+
onClick={(e) => {
|
|
197
|
+
if (!(e.target as Element).closest('figcaption')) close();
|
|
198
|
+
}}
|
|
199
|
+
className="flex size-full snap-x snap-mandatory overflow-x-auto overscroll-x-contain [scrollbar-width:none]"
|
|
200
|
+
>
|
|
201
|
+
{slides.map((slide, i) => (
|
|
202
|
+
<figure
|
|
203
|
+
key={i}
|
|
204
|
+
className="flex w-full shrink-0 snap-start snap-always flex-col items-center pb-6"
|
|
205
|
+
>
|
|
206
|
+
<p className="flex h-14 w-full items-center px-4 text-sm text-muted-foreground tabular-nums">
|
|
207
|
+
{slides.length > 1 && `${i + 1} / ${slides.length}`}
|
|
208
|
+
</p>
|
|
209
|
+
<div className="flex min-h-0 w-full flex-1 items-center justify-center px-4 [container-type:size] md:px-16">
|
|
210
|
+
<img
|
|
211
|
+
loading="lazy"
|
|
212
|
+
{...slide.image}
|
|
213
|
+
style={slide.style}
|
|
214
|
+
className={cn('max-h-full cursor-zoom-out bg-cover', slide.image.className)}
|
|
215
|
+
/>
|
|
216
|
+
</div>
|
|
217
|
+
{slide.caption && (
|
|
218
|
+
<figcaption className="prose prose-sm mt-4 px-4 text-center text-muted-foreground md:px-16">
|
|
219
|
+
{slide.caption}
|
|
220
|
+
</figcaption>
|
|
221
|
+
)}
|
|
222
|
+
</figure>
|
|
223
|
+
))}
|
|
224
|
+
</div>
|
|
225
|
+
{slides.length > 1 && (
|
|
226
|
+
<>
|
|
227
|
+
<button
|
|
228
|
+
type="button"
|
|
229
|
+
aria-label={t('ui.prev_image', { note: 'aria-label' })}
|
|
230
|
+
onClick={() => navigate(-1)}
|
|
231
|
+
className={cn(
|
|
232
|
+
buttonVariants({
|
|
233
|
+
variant: 'ghost',
|
|
234
|
+
size: 'icon',
|
|
235
|
+
className: 'absolute top-1/2 inset-s-2.5 -translate-y-1/2 max-md:hidden',
|
|
236
|
+
}),
|
|
237
|
+
)}
|
|
238
|
+
>
|
|
239
|
+
<ChevronLeft className="rtl:-scale-x-100" />
|
|
240
|
+
</button>
|
|
241
|
+
<button
|
|
242
|
+
type="button"
|
|
243
|
+
aria-label={t('ui.next_image', { note: 'aria-label' })}
|
|
244
|
+
onClick={() => navigate(1)}
|
|
245
|
+
className={cn(
|
|
246
|
+
buttonVariants({
|
|
247
|
+
variant: 'ghost',
|
|
248
|
+
size: 'icon',
|
|
249
|
+
className: 'absolute top-1/2 inset-e-2.5 -translate-y-1/2 max-md:hidden',
|
|
250
|
+
}),
|
|
251
|
+
)}
|
|
252
|
+
>
|
|
253
|
+
<ChevronRight className="rtl:-scale-x-100" />
|
|
254
|
+
</button>
|
|
255
|
+
</>
|
|
256
|
+
)}
|
|
257
|
+
</dialog>,
|
|
258
|
+
document.body,
|
|
259
|
+
)}
|
|
260
|
+
</LightboxContext>
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function initDialog(element: HTMLDialogElement) {
|
|
265
|
+
|
|
266
|
+
if (!element.open) element.showModal();
|
|
267
|
+
element.focus();
|
|
268
|
+
const { style } = document.documentElement;
|
|
269
|
+
const overflow = style.overflow;
|
|
270
|
+
style.overflow = 'hidden';
|
|
271
|
+
return () => {
|
|
272
|
+
style.overflow = overflow;
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function getIndex(scroller: HTMLElement) {
|
|
277
|
+
return Math.round(Math.abs(scroller.scrollLeft) / scroller.clientWidth);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function getImage(element: HTMLElement): HTMLElement {
|
|
281
|
+
return element.querySelector('img') ?? element;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function getSlideStyle(img: HTMLImageElement): CSSProperties {
|
|
285
|
+
const ratio = (img.naturalWidth || img.width) / (img.naturalHeight || img.height);
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
width: ratio ? `min(100cqw, ${ratio} * 100cqh)` : undefined,
|
|
289
|
+
aspectRatio: ratio ? `auto ${ratio}` : undefined,
|
|
290
|
+
backgroundImage: img.currentSrc ? `url(${JSON.stringify(img.currentSrc)})` : undefined,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function transition(from: HTMLElement, update: () => HTMLElement) {
|
|
295
|
+
if (
|
|
296
|
+
!('startViewTransition' in document) ||
|
|
297
|
+
matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
298
|
+
) {
|
|
299
|
+
update();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let to: HTMLElement | undefined;
|
|
304
|
+
from.style.viewTransitionName = 'lightbox';
|
|
305
|
+
document
|
|
306
|
+
.startViewTransition(() => {
|
|
307
|
+
from.style.viewTransitionName = '';
|
|
308
|
+
to = update();
|
|
309
|
+
to.style.viewTransitionName = 'lightbox';
|
|
310
|
+
})
|
|
311
|
+
.finished.finally(() => {
|
|
312
|
+
if (to) to.style.viewTransitionName = '';
|
|
313
|
+
});
|
|
314
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CodeBlock, Pre } from '@terrafirmagreg-team/ui/components/mdx/codeblock';
|
|
2
|
+
import { renderMermaidChart } from '@terrafirmagreg-team/ui/lib/mdx/mermaid';
|
|
3
|
+
|
|
4
|
+
export function Mermaid({ chart }: { chart: string }) {
|
|
5
|
+
const svg = renderMermaidChart(chart);
|
|
6
|
+
|
|
7
|
+
if (svg === null) {
|
|
8
|
+
return (
|
|
9
|
+
<CodeBlock title="Mermaid">
|
|
10
|
+
<Pre>{chart}</Pre>
|
|
11
|
+
</CodeBlock>
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return <div dangerouslySetInnerHTML={{ __html: svg }} />;
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function Multiblock({
|
|
2
|
+
id,
|
|
3
|
+
children,
|
|
4
|
+
}: {
|
|
5
|
+
id?: string;
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
}) {
|
|
8
|
+
return (
|
|
9
|
+
<div className="not-prose my-4 rounded-xl border border-dashed border-border bg-secondary/40 p-4">
|
|
10
|
+
<div className="text-xs uppercase tracking-wide text-muted-foreground mb-2">
|
|
11
|
+
Multiblock{id ? ` · ${id}` : ''}
|
|
12
|
+
</div>
|
|
13
|
+
<div className="text-sm text-muted-foreground [&_pre]:overflow-x-auto [&_code]:font-mono">
|
|
14
|
+
{children ?? 'Multiblock pattern will render here.'}
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useTranslations } from '@terrafirmagreg-team/translate/hooks/use-translations';
|
|
4
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
|
|
7
|
+
function Pane({
|
|
8
|
+
kind,
|
|
9
|
+
label,
|
|
10
|
+
children,
|
|
11
|
+
className,
|
|
12
|
+
}: {
|
|
13
|
+
kind: 'input' | 'output';
|
|
14
|
+
label?: string;
|
|
15
|
+
children?: ReactNode;
|
|
16
|
+
className?: string;
|
|
17
|
+
}) {
|
|
18
|
+
const t = useTranslations();
|
|
19
|
+
const text =
|
|
20
|
+
label ?? (kind === 'input' ? t('ui.input') : t('ui.output'));
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<div className={cn('min-w-0', className)}>
|
|
24
|
+
<div className="mb-3 flex items-center gap-2.5">
|
|
25
|
+
<span
|
|
26
|
+
className={cn(
|
|
27
|
+
'inline-flex shrink-0 items-center rounded-md border px-2 py-0.5 font-mono text-2xs font-semibold uppercase tracking-wider',
|
|
28
|
+
kind === 'input'
|
|
29
|
+
? 'border-border bg-secondary text-muted-foreground'
|
|
30
|
+
: 'border-primary/30 bg-primary/10 text-primary',
|
|
31
|
+
)}
|
|
32
|
+
>
|
|
33
|
+
{text}
|
|
34
|
+
</span>
|
|
35
|
+
<span className="h-px min-w-4 flex-1 bg-border" aria-hidden />
|
|
36
|
+
</div>
|
|
37
|
+
<div
|
|
38
|
+
className={cn(
|
|
39
|
+
kind === 'input' &&
|
|
40
|
+
'[&_.codeblock]:my-0 [&_figure]:my-0 [&_pre]:my-0',
|
|
41
|
+
)}
|
|
42
|
+
>
|
|
43
|
+
{children}
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function Preview({
|
|
50
|
+
children,
|
|
51
|
+
className,
|
|
52
|
+
}: {
|
|
53
|
+
children?: ReactNode;
|
|
54
|
+
className?: string;
|
|
55
|
+
}) {
|
|
56
|
+
return (
|
|
57
|
+
<section
|
|
58
|
+
className={cn(
|
|
59
|
+
'dev-doc-preview my-6 space-y-5 rounded-lg border border-dashed border-border bg-transparent p-4',
|
|
60
|
+
className,
|
|
61
|
+
)}
|
|
62
|
+
>
|
|
63
|
+
{children}
|
|
64
|
+
</section>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function Input({
|
|
69
|
+
children,
|
|
70
|
+
label,
|
|
71
|
+
className,
|
|
72
|
+
}: {
|
|
73
|
+
children?: ReactNode;
|
|
74
|
+
label?: string;
|
|
75
|
+
className?: string;
|
|
76
|
+
}) {
|
|
77
|
+
return (
|
|
78
|
+
<Pane kind="input" label={label} className={className}>
|
|
79
|
+
{children}
|
|
80
|
+
</Pane>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function Output({
|
|
85
|
+
children,
|
|
86
|
+
label,
|
|
87
|
+
className,
|
|
88
|
+
}: {
|
|
89
|
+
children?: ReactNode;
|
|
90
|
+
label?: string;
|
|
91
|
+
className?: string;
|
|
92
|
+
}) {
|
|
93
|
+
return (
|
|
94
|
+
<Pane kind="output" label={label} className={className}>
|
|
95
|
+
{children}
|
|
96
|
+
</Pane>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export { Preview, Input, Output };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
export function Steps({ children }: { children: ReactNode }) {
|
|
4
|
+
return <div className="fd-steps">{children}</div>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function Step({ children }: { children: ReactNode }) {
|
|
8
|
+
return <div className="fd-step">{children}</div>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
|
|
2
|
+
import type { ComponentProps } from 'react';
|
|
3
|
+
|
|
4
|
+
export function Table(props: ComponentProps<'table'>) {
|
|
5
|
+
return (
|
|
6
|
+
<div className="relative overflow-auto prose-no-margin my-6" tabIndex={0}>
|
|
7
|
+
<table
|
|
8
|
+
{...props}
|
|
9
|
+
className={cn('w-full', props.className)}
|
|
10
|
+
/>
|
|
11
|
+
</div>
|
|
12
|
+
);
|
|
13
|
+
}
|