@alexgorbatchev/shadcn 0.0.70 → 0.0.72
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/README.md +57 -2
- package/dist/components/image-viewer/ImageComparison.d.ts +41 -0
- package/dist/components/image-viewer/ImageComparisonToolbar.d.ts +22 -0
- package/dist/components/image-viewer/ImageDifferenceOverlay.d.ts +8 -0
- package/dist/components/image-viewer/ImageSwipeDivider.d.ts +15 -0
- package/dist/components/image-viewer/ImageViewer.d.ts +34 -0
- package/dist/components/image-viewer/ImageViewport.d.ts +23 -0
- package/dist/components/image-viewer/ImageZoomToggle.d.ts +19 -0
- package/dist/components/image-viewer/computeImageDiff.d.ts +11 -0
- package/dist/components/image-viewer/getContainedRect.d.ts +3 -0
- package/dist/components/image-viewer/getImageStageSize.d.ts +6 -0
- package/dist/components/image-viewer/getNormalizedImagePoint.d.ts +7 -0
- package/dist/components/image-viewer/hooks/useElementSize.d.ts +4 -0
- package/dist/components/image-viewer/hooks/useImageDifferences.d.ts +20 -0
- package/dist/components/image-viewer/hooks/useImageLoad.d.ts +9 -0
- package/dist/components/image-viewer/index.d.ts +9 -0
- package/dist/components/image-viewer/index.js +1114 -0
- package/dist/components/image-viewer/measureImageDifferences.d.ts +19 -0
- package/dist/components/image-viewer/types.d.ts +84 -0
- package/dist/components/tree/TreeItem.d.ts +4 -1
- package/dist/components/tree/index.js +3 -1
- package/dist/index.js +23 -23
- package/dist/prototype.js +5 -1
- package/llms/components/data-display/ImageComparison.md +153 -0
- package/llms/components/data-display/ImageViewer.md +117 -0
- package/llms/components/data-display/ImageZoomToggle.md +82 -0
- package/llms/components/navigation/Tree.md +8 -0
- package/llms/setup.md +57 -2
- package/llms.txt +3 -0
- package/package.json +5 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { IImageDiff, IImageDiffOptions } from "./types.js";
|
|
2
|
+
export interface IMeasureImageDifferencesOptions extends IImageDiffOptions {
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
/** Milliseconds of comparison work per task before yielding to the browser. */
|
|
5
|
+
sliceBudget?: number;
|
|
6
|
+
/** Resolves when the browser may handle input and rendering. */
|
|
7
|
+
yieldToMain?: () => Promise<void>;
|
|
8
|
+
now?: () => number;
|
|
9
|
+
}
|
|
10
|
+
/** Explains why image pixels could not be read, or returns undefined for cancellation. */
|
|
11
|
+
export declare function describeImageReadError(error: unknown): string | undefined;
|
|
12
|
+
/** Checks with a one-pixel draw whether the image's pixels are readable, resolving the reason when they are not. */
|
|
13
|
+
export declare function getImageReadFailure(image: HTMLImageElement): Promise<string | undefined>;
|
|
14
|
+
/**
|
|
15
|
+
* Compares two loaded images at the after image's natural size, drawing the before image inside that box with
|
|
16
|
+
* `contain` scaling. Pixel rows are read and compared in slices that yield between tasks, so large screenshots do not
|
|
17
|
+
* block input or rendering.
|
|
18
|
+
*/
|
|
19
|
+
export declare function measureImageDifferences(before: HTMLImageElement, after: HTMLImageElement, { signal, sliceBudget, yieldToMain: yieldTask, now, ...options }?: IMeasureImageDifferencesOptions): Promise<IImageDiff>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { StackDirection } from "../../layout/types.js";
|
|
2
|
+
/** `fit` scales the image down to the viewport; `original` shows it at its natural size in CSS pixels. */
|
|
3
|
+
export type ImageZoom = "fit" | "original";
|
|
4
|
+
/** How ImageComparison presents the before and after images. */
|
|
5
|
+
export type ImageComparisonMode = "toggle" | "swipe" | "side-by-side";
|
|
6
|
+
/** Side-by-side pane arrangement: `horizontal` places panes left and right, `vertical` top and bottom. */
|
|
7
|
+
export type ImageComparisonOrientation = StackDirection;
|
|
8
|
+
export interface IImageSize {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
export interface IImageRect extends IImageSize {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
}
|
|
16
|
+
/** A position inside an image, from 0 (left or top edge) to 1 (right or bottom edge). */
|
|
17
|
+
export interface INormalizedImagePoint {
|
|
18
|
+
x: number;
|
|
19
|
+
y: number;
|
|
20
|
+
}
|
|
21
|
+
export interface IImageStageSize extends IImageSize {
|
|
22
|
+
/** Rendered CSS pixels per natural image pixel. */
|
|
23
|
+
scale: number;
|
|
24
|
+
}
|
|
25
|
+
export interface IImageComparisonSource {
|
|
26
|
+
src: string;
|
|
27
|
+
alt: string;
|
|
28
|
+
/** CORS mode for the image request. Cross-origin pixels can only be compared when the server allows CORS. */
|
|
29
|
+
crossOrigin?: "anonymous" | "use-credentials";
|
|
30
|
+
}
|
|
31
|
+
/** RGBA pixels in row-major order, such as an `ImageData`. */
|
|
32
|
+
export interface IImagePixels {
|
|
33
|
+
width: number;
|
|
34
|
+
height: number;
|
|
35
|
+
data: ArrayLike<number>;
|
|
36
|
+
}
|
|
37
|
+
export interface IImageDiffOptions {
|
|
38
|
+
/** Largest per-channel difference, from 0 to 255, still treated as unchanged. Defaults to 32. */
|
|
39
|
+
threshold?: number;
|
|
40
|
+
/** Side length in pixels of the square cells that changed pixels are aggregated into. Defaults to 16. */
|
|
41
|
+
cellSize?: number;
|
|
42
|
+
/** Changed pixels a cell needs before it counts as changed, which filters isolated noise. Defaults to 2. */
|
|
43
|
+
minChangedPixels?: number;
|
|
44
|
+
}
|
|
45
|
+
/** A connected group of changed cells, bounded tightly around its changed pixels in image pixel coordinates. */
|
|
46
|
+
export interface IImageDiffRegion extends IImageRect {
|
|
47
|
+
changedPixels: number;
|
|
48
|
+
}
|
|
49
|
+
export interface IImageDiff {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
cellSize: number;
|
|
53
|
+
columns: number;
|
|
54
|
+
rows: number;
|
|
55
|
+
/** One entry per cell in row-major order: 1 when the cell changed, otherwise 0. */
|
|
56
|
+
cells: Uint8Array;
|
|
57
|
+
/** Changed regions ordered from top to bottom, then left to right. */
|
|
58
|
+
regions: IImageDiffRegion[];
|
|
59
|
+
/** Changed pixels inside changed cells. */
|
|
60
|
+
changedPixels: number;
|
|
61
|
+
}
|
|
62
|
+
export interface IImageDiffAccumulator {
|
|
63
|
+
/**
|
|
64
|
+
* Compares `rowCount` image rows starting at row `startY`. Both buffers hold RGBA rows that span the full image
|
|
65
|
+
* width, starting with row `startY`.
|
|
66
|
+
*/
|
|
67
|
+
addRows(before: ArrayLike<number>, after: ArrayLike<number>, startY: number, rowCount: number): void;
|
|
68
|
+
finish(): IImageDiff;
|
|
69
|
+
}
|
|
70
|
+
export interface IImageLoadState {
|
|
71
|
+
status: "loading" | "loaded" | "error";
|
|
72
|
+
/** Natural size once the image has loaded. */
|
|
73
|
+
size?: IImageSize;
|
|
74
|
+
}
|
|
75
|
+
/** Pixel comparison progress; `reason` explains why pixels could not be read. */
|
|
76
|
+
export type ImageDifferenceState = {
|
|
77
|
+
status: "idle" | "measuring";
|
|
78
|
+
} | {
|
|
79
|
+
status: "ready";
|
|
80
|
+
diff: IImageDiff;
|
|
81
|
+
} | {
|
|
82
|
+
status: "unavailable";
|
|
83
|
+
reason: string;
|
|
84
|
+
};
|
|
@@ -8,6 +8,7 @@ type TreeItemState = {
|
|
|
8
8
|
selected: boolean;
|
|
9
9
|
expanded: boolean;
|
|
10
10
|
dropTarget: boolean;
|
|
11
|
+
dimmed: boolean;
|
|
11
12
|
density: IDensityProps["density"];
|
|
12
13
|
};
|
|
13
14
|
type TreeItemProps<T> = useRender.ComponentProps<"div", TreeItemState> & IDensityProps & IAnalyticsProps & {
|
|
@@ -17,6 +18,8 @@ type TreeItemProps<T> = useRender.ComponentProps<"div", TreeItemState> & IDensit
|
|
|
17
18
|
expandOn?: "click" | "doubleClick" | "disclosure";
|
|
18
19
|
isEditing?: boolean;
|
|
19
20
|
isDropTarget?: boolean;
|
|
21
|
+
/** Fades a settled row, such as completed work, to 70% opacity; hover and keyboard focus restore full opacity. */
|
|
22
|
+
isDimmed?: boolean;
|
|
20
23
|
/** The registered native link owns row focus; disclosure and actions remain siblings. */
|
|
21
24
|
linkProps?: useRender.ComponentProps<"a", TreeItemState>;
|
|
22
25
|
/** Domain-controlled drag feedback; omitted rows have no tooltip wrapper. */
|
|
@@ -27,5 +30,5 @@ type TreeItemProps<T> = useRender.ComponentProps<"div", TreeItemState> & IDensit
|
|
|
27
30
|
};
|
|
28
31
|
};
|
|
29
32
|
/** Registered tree row; compose menus with render and place counts/actions in endEnhancer. */
|
|
30
|
-
export declare function TreeItem<T>({ analytics, item, children, startEnhancer, endEnhancer, expandOn, isEditing, isDropTarget, linkProps, dropHint, density, render, ref, ...props }: TreeItemProps<T>): ReactElement;
|
|
33
|
+
export declare function TreeItem<T>({ analytics, item, children, startEnhancer, endEnhancer, expandOn, isEditing, isDropTarget, isDimmed, linkProps, dropHint, density, render, ref, ...props }: TreeItemProps<T>): ReactElement;
|
|
31
34
|
export type { TreeItemProps };
|
|
@@ -36,6 +36,7 @@ function TreeItem({
|
|
|
36
36
|
expandOn = "click",
|
|
37
37
|
isEditing = false,
|
|
38
38
|
isDropTarget = false,
|
|
39
|
+
isDimmed = false,
|
|
39
40
|
linkProps,
|
|
40
41
|
dropHint,
|
|
41
42
|
density,
|
|
@@ -54,6 +55,7 @@ function TreeItem({
|
|
|
54
55
|
selected: isSelected,
|
|
55
56
|
expanded: isExpanded,
|
|
56
57
|
dropTarget: isInsideTarget || isDropTarget,
|
|
58
|
+
dimmed: isDimmed,
|
|
57
59
|
density
|
|
58
60
|
};
|
|
59
61
|
const toggle = () => {
|
|
@@ -146,7 +148,7 @@ function TreeItem({
|
|
|
146
148
|
onDragStart: undefined
|
|
147
149
|
} : {},
|
|
148
150
|
style: { paddingInlineStart: `${item.getItemMeta().level * (item.getTree().getConfig().indent ?? 20) + 8}px` },
|
|
149
|
-
className: cn2("relative flex min-h-control min-w-0 cursor-default items-center gap-2 rounded-sm py-1 pr-2 text-sm outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring", (isSelected || isDropTarget || isInsideTarget) && "bg-accent text-accent-foreground"),
|
|
151
|
+
className: cn2("relative flex min-h-control min-w-0 cursor-default items-center gap-2 rounded-sm py-1 pr-2 text-sm outline-none hover:bg-accent focus-visible:ring-2 focus-visible:ring-ring", (isSelected || isDropTarget || isInsideTarget) && "bg-accent text-accent-foreground", isDimmed && "opacity-70 focus-within:opacity-100 hover:opacity-100"),
|
|
150
152
|
children: /* @__PURE__ */ jsxs(Fragment, {
|
|
151
153
|
children: [
|
|
152
154
|
item.isFolder() && expandOn === "disclosure" ? /* @__PURE__ */ jsx(Button2, {
|
package/dist/index.js
CHANGED
|
@@ -172,29 +172,6 @@ import {
|
|
|
172
172
|
DashboardLayout2,
|
|
173
173
|
BillingUsage2
|
|
174
174
|
} from "./chunk-pr5s27j8.js";
|
|
175
|
-
import {
|
|
176
|
-
Tabs2,
|
|
177
|
-
tabsListVariants2,
|
|
178
|
-
TabsList2,
|
|
179
|
-
TabsTrigger2,
|
|
180
|
-
TabsContent2,
|
|
181
|
-
DragDropPreview2,
|
|
182
|
-
DragDropProvider2,
|
|
183
|
-
useDragDrop2,
|
|
184
|
-
useDragSource2,
|
|
185
|
-
DragSource2,
|
|
186
|
-
useDropTarget2,
|
|
187
|
-
DropTarget2,
|
|
188
|
-
Kanban2
|
|
189
|
-
} from "./chunk-k45r2rz0.js";
|
|
190
|
-
import {
|
|
191
|
-
Toolbar2,
|
|
192
|
-
ToolbarButton2,
|
|
193
|
-
ToolbarLink2,
|
|
194
|
-
ToolbarInput2,
|
|
195
|
-
ToolbarGroup2,
|
|
196
|
-
ToolbarSeparator2
|
|
197
|
-
} from "./chunk-7srpghny.js";
|
|
198
175
|
import {
|
|
199
176
|
Combobox2,
|
|
200
177
|
ComboboxValue2,
|
|
@@ -220,6 +197,29 @@ import {
|
|
|
220
197
|
NumberFieldScrubArea2,
|
|
221
198
|
NumberFieldScrubAreaCursor2
|
|
222
199
|
} from "./chunk-31wptjv4.js";
|
|
200
|
+
import {
|
|
201
|
+
Tabs2,
|
|
202
|
+
tabsListVariants2,
|
|
203
|
+
TabsList2,
|
|
204
|
+
TabsTrigger2,
|
|
205
|
+
TabsContent2,
|
|
206
|
+
DragDropPreview2,
|
|
207
|
+
DragDropProvider2,
|
|
208
|
+
useDragDrop2,
|
|
209
|
+
useDragSource2,
|
|
210
|
+
DragSource2,
|
|
211
|
+
useDropTarget2,
|
|
212
|
+
DropTarget2,
|
|
213
|
+
Kanban2
|
|
214
|
+
} from "./chunk-k45r2rz0.js";
|
|
215
|
+
import {
|
|
216
|
+
Toolbar2,
|
|
217
|
+
ToolbarButton2,
|
|
218
|
+
ToolbarLink2,
|
|
219
|
+
ToolbarInput2,
|
|
220
|
+
ToolbarGroup2,
|
|
221
|
+
ToolbarSeparator2
|
|
222
|
+
} from "./chunk-7srpghny.js";
|
|
223
223
|
import {
|
|
224
224
|
Slider2
|
|
225
225
|
} from "./chunk-7cq1s2ey.js";
|
package/dist/prototype.js
CHANGED
|
@@ -2051,7 +2051,7 @@ var program = new Command;
|
|
|
2051
2051
|
// package.json
|
|
2052
2052
|
var package_default = {
|
|
2053
2053
|
name: "@alexgorbatchev/shadcn",
|
|
2054
|
-
version: "0.0.
|
|
2054
|
+
version: "0.0.72",
|
|
2055
2055
|
description: "Sharp, monospace React components with compact and comfortable densities.",
|
|
2056
2056
|
license: "MIT",
|
|
2057
2057
|
repository: {
|
|
@@ -3063,6 +3063,10 @@ var package_default = {
|
|
|
3063
3063
|
types: "./dist/components/image-crop/index.d.ts",
|
|
3064
3064
|
import: "./dist/components/image-crop/index.js"
|
|
3065
3065
|
},
|
|
3066
|
+
"./image-viewer": {
|
|
3067
|
+
types: "./dist/components/image-viewer/index.d.ts",
|
|
3068
|
+
import: "./dist/components/image-viewer/index.js"
|
|
3069
|
+
},
|
|
3066
3070
|
"./editor": {
|
|
3067
3071
|
types: "./dist/components/editor/index.d.ts",
|
|
3068
3072
|
import: "./dist/components/editor/index.js"
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# ImageComparison
|
|
2
|
+
|
|
3
|
+
Import from `@alexgorbatchev/shadcn/image-viewer`. ImageComparison fills its container and compares `before` and `after` images (`{ src, alt, crossOrigin? }`) labelled by `beforeLabel` and `afterLabel` (default "Before" and "After"). `toggle` (the default) shows the after image and the "Hold to show before" button shows the before image while a pointer, Space, or Enter is held. `swipe` stacks both images; the divider is a slider (0–100, arrows ±1, Page Up/Page Down ±10, Home/End) whose handle drags with pointer capture. `side-by-side` shows labelled panes left and right (`horizontal`) or top and bottom (`vertical`) that scroll in sync at original size. Every mode starts fitted and offers original size. A differently sized before image is drawn inside the after image box, and the toolbar reports the mismatch. "Highlight differences" compares pixels on first use, caches the result per image pair, outlines changed regions, and summarizes them; it is disabled with a reason when pixels cannot be read. `mode`, `orientation`, `zoom`, and `showDifferences` are controllable with matching `default*` and `on*Change` props; `showToolbar={false}` hides the controls, which sit beside wide comparisons and below narrow ones.
|
|
4
|
+
|
|
5
|
+
Story: @alexgorbatchev/shadcn/components/data-display/ImageComparison
|
|
6
|
+
Source: src/components/stories/data-display/ImageComparison.stories.tsx
|
|
7
|
+
|
|
8
|
+
[Full source and local helpers](https://github.com/alexgorbatchev/shadcn/blob/main/src/components/stories/data-display/ImageComparison.stories.tsx)
|
|
9
|
+
|
|
10
|
+
## Public imports
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { ImageComparison, type IImageComparisonProps, type ImageComparisonMode, type ImageComparisonOrientation, type ImageZoom } from "@alexgorbatchev/shadcn/image-viewer";
|
|
14
|
+
import { Button, Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@alexgorbatchev/shadcn";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Supporting imports
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { useState, type ReactElement } from "react";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Default component
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
ImageComparison
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Story controls
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
{
|
|
33
|
+
defaultMode: { control: "inline-radio", options: ["toggle", "swipe", "side-by-side"] },
|
|
34
|
+
defaultOrientation: { control: "inline-radio", options: ["horizontal", "vertical"] },
|
|
35
|
+
defaultZoom: { control: "inline-radio", options: ["fit", "original"] },
|
|
36
|
+
defaultShowDifferences: { control: "boolean" },
|
|
37
|
+
showToolbar: { control: "boolean" },
|
|
38
|
+
density: { control: "select", options: ["compact", "comfortable"] },
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Default args
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
{
|
|
46
|
+
before: { src: fixture_beforeScreenshot, alt: BEFORE_ALT },
|
|
47
|
+
after: { src: fixture_afterScreenshot, alt: AFTER_ALT },
|
|
48
|
+
onModeChange: fn(),
|
|
49
|
+
onOrientationChange: fn(),
|
|
50
|
+
onZoomChange: fn(),
|
|
51
|
+
onShowDifferencesChange: fn(),
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Default render
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
(args) => (<div className="h-[36rem] w-full border border-border">
|
|
59
|
+
<ImageComparison {...args}/>
|
|
60
|
+
</div>)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Examples
|
|
64
|
+
|
|
65
|
+
Storybook CSF excerpts. Default args and render apply unless overridden. Local helpers, fixtures, decorators, and providers may be required; these are reference excerpts, not standalone consumer modules. Interaction tests are omitted.
|
|
66
|
+
|
|
67
|
+
### Toggle
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
{}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Swipe
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
{
|
|
77
|
+
args: { defaultMode: "swipe" }
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### SideBySide
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
{
|
|
85
|
+
args: { defaultMode: "side-by-side" }
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### HighlightDifferences
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
{}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### NoDifferences
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
{
|
|
99
|
+
args: {
|
|
100
|
+
before: { src: fixture_afterScreenshot, alt: BEFORE_ALT },
|
|
101
|
+
defaultShowDifferences: true,
|
|
102
|
+
defaultMode: "swipe",
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### SizeMismatch
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
{
|
|
111
|
+
args: { before: { src: fixture_widerBeforeScreenshot, alt: BEFORE_ALT }, defaultMode: "side-by-side" }
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### UnreadablePixels
|
|
116
|
+
|
|
117
|
+
```tsx
|
|
118
|
+
{
|
|
119
|
+
args: { before: { src: fixture_brokenImage, alt: BEFORE_ALT } }
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### ModeChangesKeepViewedCenter
|
|
124
|
+
|
|
125
|
+
```tsx
|
|
126
|
+
{
|
|
127
|
+
args: { defaultZoom: "original" }
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Controlled
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
{
|
|
135
|
+
render: (args) => <ControlledComparison {...args}/>
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### WithoutToolbar
|
|
140
|
+
|
|
141
|
+
```tsx
|
|
142
|
+
{
|
|
143
|
+
args: { showToolbar: false, defaultMode: "swipe", beforeLabel: "Baseline", afterLabel: "Candidate" }
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### FullscreenDialog
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
{
|
|
151
|
+
render: (args) => <FullscreenComparison {...args}/>
|
|
152
|
+
}
|
|
153
|
+
```
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# ImageViewer
|
|
2
|
+
|
|
3
|
+
Import from `@alexgorbatchev/shadcn/image-viewer`. ImageViewer fills the container it is given, such as a `DialogContent size="fullscreen"` body, and shows one image in a native scroll viewport. `fit` (the default) scales the image down proportionally to fit both dimensions, centered and without scrollbars, and never upscales it; `original` shows natural size in CSS pixels, centered on axes where it is smaller and scrolling where it is larger. Switching zoom keeps the viewed center. Control zoom with `zoom` and `onZoomChange`, or leave it uncontrolled with `defaultZoom`; place `ImageZoomToggle` in a header or toolbar, or set `showZoomControl` for the built-in toggle. `overlay` renders content sized and positioned exactly over the rendered image at every zoom, `imageRef` and `overlayRef` expose the rendered image box, and `getNormalizedImagePoint(event, box)` maps pointer coordinates to 0–1 image coordinates.
|
|
4
|
+
|
|
5
|
+
Story: @alexgorbatchev/shadcn/components/data-display/ImageViewer
|
|
6
|
+
Source: src/components/stories/data-display/ImageViewer.stories.tsx
|
|
7
|
+
|
|
8
|
+
[Full source and local helpers](https://github.com/alexgorbatchev/shadcn/blob/main/src/components/stories/data-display/ImageViewer.stories.tsx)
|
|
9
|
+
|
|
10
|
+
## Public imports
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { ImageViewer, ImageZoomToggle, getNormalizedImagePoint, type IImageViewerProps, type INormalizedImagePoint, type ImageZoom } from "@alexgorbatchev/shadcn/image-viewer";
|
|
14
|
+
import { Button, Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@alexgorbatchev/shadcn";
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Supporting imports
|
|
18
|
+
|
|
19
|
+
```tsx
|
|
20
|
+
import { useState, type ReactElement } from "react";
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Default component
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
ImageViewer
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Story controls
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
{
|
|
33
|
+
defaultZoom: { control: "inline-radio", options: ["fit", "original"] },
|
|
34
|
+
showZoomControl: { control: "boolean" },
|
|
35
|
+
density: { control: "select", options: ["compact", "comfortable"] },
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Default args
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
{ src: fixture_largeScreenshot, alt: "Dashboard screenshot", onZoomChange: fn() }
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Default render
|
|
46
|
+
|
|
47
|
+
```tsx
|
|
48
|
+
(args) => (<div className="h-80 w-full border border-border">
|
|
49
|
+
<ImageViewer {...args}/>
|
|
50
|
+
</div>)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Examples
|
|
54
|
+
|
|
55
|
+
Storybook CSF excerpts. Default args and render apply unless overridden. Local helpers, fixtures, decorators, and providers may be required; these are reference excerpts, not standalone consumer modules. Interaction tests are omitted.
|
|
56
|
+
|
|
57
|
+
### FitToScreen
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
{}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### OriginalSize
|
|
64
|
+
|
|
65
|
+
```tsx
|
|
66
|
+
{
|
|
67
|
+
args: { defaultZoom: "original" }
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### SmallImage
|
|
72
|
+
|
|
73
|
+
```tsx
|
|
74
|
+
{
|
|
75
|
+
args: { src: fixture_smallScreenshot, alt: "Toolbar screenshot" }
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### BuiltInZoomControl
|
|
80
|
+
|
|
81
|
+
```tsx
|
|
82
|
+
{
|
|
83
|
+
args: { showZoomControl: true }
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### RestoresViewedCenter
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
{
|
|
91
|
+
args: { showZoomControl: true, defaultZoom: "original" }
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### OverlayCoordinates
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
{
|
|
99
|
+
render: (args) => <OverlayExample {...args}/>
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### FullscreenDialog
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
{
|
|
107
|
+
render: (args) => <FullscreenExample {...args}/>
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### LoadError
|
|
112
|
+
|
|
113
|
+
```tsx
|
|
114
|
+
{
|
|
115
|
+
args: { src: fixture_brokenImage, alt: "Missing screenshot" }
|
|
116
|
+
}
|
|
117
|
+
```
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# ImageZoomToggle
|
|
2
|
+
|
|
3
|
+
Import from `@alexgorbatchev/shadcn/image-viewer`. A two-option toggle for ImageViewer and ImageComparison zoom that consumers place in a header or toolbar. "Fit to screen" and "Original size" are pressed-state toggles with constant names, so assistive technology announces the active zoom through `aria-pressed`. One option always stays pressed. `label` names the group (default "Zoom"); `size`, `orientation`, `layout`, `disabled`, and `density` follow ToggleGroup.
|
|
4
|
+
|
|
5
|
+
Story: @alexgorbatchev/shadcn/components/data-display/ImageZoomToggle
|
|
6
|
+
Source: src/components/stories/data-display/ImageZoomToggle.stories.tsx
|
|
7
|
+
|
|
8
|
+
[Full source and local helpers](https://github.com/alexgorbatchev/shadcn/blob/main/src/components/stories/data-display/ImageZoomToggle.stories.tsx)
|
|
9
|
+
|
|
10
|
+
## Public imports
|
|
11
|
+
|
|
12
|
+
```tsx
|
|
13
|
+
import { ImageZoomToggle, type ImageZoom } from "@alexgorbatchev/shadcn/image-viewer";
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Supporting imports
|
|
17
|
+
|
|
18
|
+
```tsx
|
|
19
|
+
import { useState } from "react";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Default component
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
ImageZoomToggle
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Story controls
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
{
|
|
32
|
+
zoom: { control: "inline-radio", options: ["fit", "original"] },
|
|
33
|
+
size: { control: "select", options: ["sm", "default", "lg"] },
|
|
34
|
+
orientation: { control: "inline-radio", options: ["horizontal", "vertical"] },
|
|
35
|
+
layout: { control: "inline-radio", options: ["content", "fill"] },
|
|
36
|
+
density: { control: "select", options: ["compact", "comfortable"] },
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Default args
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
{ zoom: "fit", onZoomChange: fn() }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Default render
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
function Render(args) {
|
|
50
|
+
const [zoom, setZoom] = useState<ImageZoom>(args.zoom);
|
|
51
|
+
return (<ImageZoomToggle {...args} zoom={zoom} onZoomChange={(next) => {
|
|
52
|
+
setZoom(next);
|
|
53
|
+
args.onZoomChange(next);
|
|
54
|
+
}}/>);
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Examples
|
|
59
|
+
|
|
60
|
+
Storybook CSF excerpts. Default args and render apply unless overridden. Local helpers, fixtures, decorators, and providers may be required; these are reference excerpts, not standalone consumer modules. Interaction tests are omitted.
|
|
61
|
+
|
|
62
|
+
### Default
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
{}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### VerticalFill
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
{
|
|
72
|
+
args: { orientation: "vertical", layout: "fill", label: "Screenshot zoom", zoom: "original" }
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Disabled
|
|
77
|
+
|
|
78
|
+
```tsx
|
|
79
|
+
{
|
|
80
|
+
args: { disabled: true }
|
|
81
|
+
}
|
|
82
|
+
```
|