@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.
Files changed (30) hide show
  1. package/README.md +57 -2
  2. package/dist/components/image-viewer/ImageComparison.d.ts +41 -0
  3. package/dist/components/image-viewer/ImageComparisonToolbar.d.ts +22 -0
  4. package/dist/components/image-viewer/ImageDifferenceOverlay.d.ts +8 -0
  5. package/dist/components/image-viewer/ImageSwipeDivider.d.ts +15 -0
  6. package/dist/components/image-viewer/ImageViewer.d.ts +34 -0
  7. package/dist/components/image-viewer/ImageViewport.d.ts +23 -0
  8. package/dist/components/image-viewer/ImageZoomToggle.d.ts +19 -0
  9. package/dist/components/image-viewer/computeImageDiff.d.ts +11 -0
  10. package/dist/components/image-viewer/getContainedRect.d.ts +3 -0
  11. package/dist/components/image-viewer/getImageStageSize.d.ts +6 -0
  12. package/dist/components/image-viewer/getNormalizedImagePoint.d.ts +7 -0
  13. package/dist/components/image-viewer/hooks/useElementSize.d.ts +4 -0
  14. package/dist/components/image-viewer/hooks/useImageDifferences.d.ts +20 -0
  15. package/dist/components/image-viewer/hooks/useImageLoad.d.ts +9 -0
  16. package/dist/components/image-viewer/index.d.ts +9 -0
  17. package/dist/components/image-viewer/index.js +1114 -0
  18. package/dist/components/image-viewer/measureImageDifferences.d.ts +19 -0
  19. package/dist/components/image-viewer/types.d.ts +84 -0
  20. package/dist/components/tree/TreeItem.d.ts +4 -1
  21. package/dist/components/tree/index.js +3 -1
  22. package/dist/index.js +23 -23
  23. package/dist/prototype.js +5 -1
  24. package/llms/components/data-display/ImageComparison.md +153 -0
  25. package/llms/components/data-display/ImageViewer.md +117 -0
  26. package/llms/components/data-display/ImageZoomToggle.md +82 -0
  27. package/llms/components/navigation/Tree.md +8 -0
  28. package/llms/setup.md +57 -2
  29. package/llms.txt +3 -0
  30. package/package.json +5 -1
package/llms/setup.md CHANGED
@@ -71,6 +71,7 @@ Import shared controls and providers from `@alexgorbatchev/shadcn`. Import the f
71
71
  | `/file-upload` | FileUpload selection and validation | `bun add react-dropzone@^20.1.4` |
72
72
  | `/color-picker` | ColorPicker | `bun add react-colorful@^5.8.1` |
73
73
  | `/image-crop` | ImageCrop and native export helpers | `bun add react-image-crop@^11.1.2` |
74
+ | `/image-viewer` | ImageViewer, ImageZoomToggle, ImageComparison, and image helpers | Existing core peers |
74
75
  | `/tree` | Tree, native hooks and features | `bun add @headless-tree/core@^1.8.0 @headless-tree/react@^1.8.0`; patched runtimes are bundled |
75
76
  | `/editor` | RichTextEditor, native Tiptap hooks and StarterKit | `bun add @tiptap/core@^3.32.0 @tiptap/react@^3.32.0 @tiptap/pm@^3.32.0 @tiptap/starter-kit@^3.32.0` |
76
77
  | `/event-calendar` | EventCalendar, EventForm and native calendar APIs | `bun add date-fns@^4.4.0`; TypeScript: `bun add -d @types/react-big-calendar@^1.16.3` |
@@ -269,7 +270,7 @@ The npm package includes the same index at `llms.txt` in its root and its linked
269
270
  | Forms and selections | AuthForm, Calendar, Checkbox, Combobox, Command, EmailCodeAuthForm, Field, Input, InputGroup, InputOTP, Label, OptionSelect, Questionnaire, RadioGroup, Select, Slider, Switch, Textarea |
270
271
  | Structure and navigation | Accordion, AspectRatio, Avatar, Breadcrumb, Card, Carousel, Chart, Collapsible, Empty, Item, Kbd, Menubar, NavigationMenu, Pagination, Resizable, ScrollArea, Separator, Sidebar, Table, Tabs |
271
272
  | Layout and typography | AppShell, Container, Grid, GridItem, Heading, PageHeader, PageIntro, Stack, Text |
272
- | Data display | WeatherForecast, WeatherSummary |
273
+ | Data display | ImageComparison, ImageViewer, WeatherForecast, WeatherSummary |
273
274
  | Overlays | AlertDialog, ContextMenu, Dialog, Drawer, DropdownMenu, HoverCard, Popover, Sheet, Tooltip |
274
275
  | Loading | Progress, Skeleton, Spinner |
275
276
  | Conversations | Attachment, Bubble, Marker, Message, MessageScroller |
@@ -451,7 +452,7 @@ Keep preferred widths separate from the table's rendered sizing atom. In `onFitW
451
452
 
452
453
  For nested layouts, compose `ActionsMenuTrigger`, `ActionsMenuContextTarget`, and `ActionsMenuContextContent` explicitly inside `ActionsMenu`. The dropdown trigger owns its local native dropdown root and popup; the context target and content share an independent context root. A tree row can use `TreeItem render={<ActionsMenuContextTarget />}` and put the trigger in its action slot. For a table row, render the context target as the actual `tr`, then place the dropdown trigger and context content inside a `td`: native popup portals insert focus guards at their declaration, which must remain valid table children.
453
454
 
454
- `TreeItem linkProps` places the registered tree item, roving focus, and native drag handlers on an anchor. Pass `href` and anchor events directly, or compose a router link through `linkProps.render`. The outer `render` and `ref` remain available for row overlays; disclosure and `endEnhancer` controls remain siblings of the link. Enter and modified clicks retain native link behavior, while tree arrows retain navigation and expansion behavior. Optional `dropHint={{ content, open, side }}` displays caller-controlled drag feedback without adding a focus target.
455
+ `TreeItem linkProps` places the registered tree item, roving focus, and native drag handlers on an anchor. Pass `href` and anchor events directly, or compose a router link through `linkProps.render`. The outer `render` and `ref` remain available for row overlays; disclosure and `endEnhancer` controls remain siblings of the link. Enter and modified clicks retain native link behavior, while tree arrows retain navigation and expansion behavior. Optional `dropHint={{ content, open, side }}` displays caller-controlled drag feedback without adding a focus target. `isDimmed` fades a settled row, such as completed work, to 70% opacity and exposes `data-dimmed`; hovering or focusing anything in the row restores full opacity, and the row stays interactive.
455
456
 
456
457
  Embedded actions, links, menus, editable fields, and media controls retain their own keyboard behavior. Registered anchor and button rows still participate in tree navigation; rename and search inputs retain their completion and cancellation shortcuts.
457
458
 
@@ -477,6 +478,60 @@ Embedded actions, links, menus, editable fields, and media controls retain their
477
478
 
478
479
  `TableHead` and `TableCell` accept `textAlign="start"`, `"center"`, or `"end"` to align labels and numeric columns consistently in either text direction.
479
480
 
481
+ # Image viewing and comparison
482
+
483
+ Import `ImageViewer`, `ImageZoomToggle`, and `ImageComparison` from `@alexgorbatchev/shadcn/image-viewer`. Both viewers fill the container they are given, such as a `DialogContent size="fullscreen"` body, and use only the core peers.
484
+
485
+ ```tsx
486
+ import { useState } from "react";
487
+ import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@alexgorbatchev/shadcn";
488
+ import {
489
+ ImageViewer,
490
+ ImageZoomToggle,
491
+ getNormalizedImagePoint,
492
+ type INormalizedImagePoint,
493
+ type ImageZoom,
494
+ } from "@alexgorbatchev/shadcn/image-viewer";
495
+
496
+ function Screenshot({ src, onPick }: { src: string; onPick: (point: INormalizedImagePoint) => void }) {
497
+ const [zoom, setZoom] = useState<ImageZoom>("fit");
498
+ return (
499
+ <Dialog defaultOpen>
500
+ <DialogContent size="fullscreen">
501
+ <DialogHeader>
502
+ <DialogTitle>Checkout page</DialogTitle>
503
+ <ImageZoomToggle zoom={zoom} onZoomChange={setZoom} />
504
+ </DialogHeader>
505
+ <ImageViewer
506
+ src={src}
507
+ alt="Checkout page"
508
+ zoom={zoom}
509
+ onZoomChange={setZoom}
510
+ overlay={
511
+ <div
512
+ className="absolute inset-0 cursor-crosshair"
513
+ onPointerDown={(event) =>
514
+ onPick(getNormalizedImagePoint(event, event.currentTarget.getBoundingClientRect()))
515
+ }
516
+ />
517
+ }
518
+ />
519
+ </DialogContent>
520
+ </Dialog>
521
+ );
522
+ }
523
+ ```
524
+
525
+ `ImageViewer` zoom is `"fit"` or `"original"`, controlled with `zoom` and `onZoomChange` or uncontrolled with `defaultZoom` (default `"fit"`). Fit scales the image down proportionally to fit both viewport dimensions, centered and without scrollbars, and never upscales it. Original shows the natural size in CSS pixels, centered on any axis where it is smaller than the viewport and scrolling on any axis where it is larger; switching zoom keeps the viewed center. The viewport is a focusable native scroll region named by `label` (default `alt`) for keyboard scrolling. Place `ImageZoomToggle` in a header or toolbar, or set `showZoomControl` for a built-in toggle above the image; its "Fit to screen" and "Original size" options report their state with `aria-pressed`.
526
+
527
+ `overlay` renders inside a box sized and positioned exactly over the rendered image at every zoom level, so children positioned in percentages stay aligned with the image. `imageRef` and `overlayRef` expose the rendered image box; `getNormalizedImagePoint(point, box)` maps viewport coordinates, such as a pointer event, to 0–1 image coordinates within that box and clamps points outside it. Multiply by the image's `naturalWidth` and `naturalHeight` for pixel coordinates. A failed load shows "Image could not be loaded." and sets `data-status="error"` on the viewer root.
528
+
529
+ `ImageComparison` compares `before` and `after` sources (`{ src, alt, crossOrigin? }`) labelled by `beforeLabel` and `afterLabel` (default "Before" and "After"). `mode` is `"toggle"` (default), `"swipe"`, or `"side-by-side"`; `orientation` is `"horizontal"` (panes left and right, default) or `"vertical"` (top and bottom); `zoom` is shared by every mode; `showDifferences` defaults to false. Each is controlled with its value and `on*Change` callback or uncontrolled with its `default*` prop. Toggle shows the after image while "Hold to show before" shows the before image as long as a pointer, Space, or Enter is held, returning on release, pointer leave, cancel, or blur. Swipe stacks both images behind a divider that is a native slider (0–100; arrows ±1, Page Up/Page Down ±10, Home/End) whose handle drags with pointer capture; the rest of the image keeps native panning. Side-by-side panes scroll in sync at original size. When the image sizes differ, the before image is drawn inside the after image box with `contain` scaling, and the toolbar reports both sizes.
530
+
531
+ "Highlight differences" draws both images at the after image's natural size and compares premultiplied channels against a threshold. Changed pixels are aggregated into 16px cells and connected regions, outlined with the warning token over the after image (toggle and swipe) or both panes (side-by-side), and summarized as "3 changed regions" or "No visible differences". The comparison runs in time-boxed slices that yield to the browser and is cached per image pair for the component's lifetime. When pixels cannot be read, such as a cross-origin image served without CORS or an image that failed to decode, the switch is disabled and the reason is shown. Pass `crossOrigin: "anonymous"` only when the image server sends CORS headers. `computeImageDiff(before, after, options)` exposes the same pure comparison for equally sized `ImageData`.
532
+
533
+ The toolbar holds the mode, orientation (enabled for side-by-side), zoom, hold-to-show-before (enabled for toggle), and highlight controls with the legend and status. It sits beside a comparison at least 48rem wide and wraps below narrower ones; `showToolbar={false}` hides it, leaving consumers to control the props themselves.
534
+
480
535
  # Drag and drop
481
536
 
482
537
  Wrap draggable sources and drop targets in `DragDropProvider`. `DragSource` and `DropTarget` accept Base UI's `render` composition, so a button, table row, or sidebar item keeps its native element. For compositions that already manage rendering, use `useDragSource` and `useDropTarget` and spread their `props` onto the existing element.
package/llms.txt CHANGED
@@ -340,6 +340,9 @@ Generated from the public package exports and Storybook sources.
340
340
  - [DataGridSelectHeader](./llms/components/data-display/DataGridSelectHeader.md)
341
341
  - [DataViewer](./llms/components/data-display/DataViewer.md)
342
342
  - [Heading](./llms/components/data-display/Heading.md): Heading renders `h1`–`h6` from the required `level` so the document outline stays correct, while `size` (sm, base, lg, xl) sets the visual size independently. Sizes default by level: 1 xl, 2 lg, 3 base, 4–6 sm. `truncate` keeps one line.
343
+ - [ImageComparison](./llms/components/data-display/ImageComparison.md): 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.
344
+ - [ImageViewer](./llms/components/data-display/ImageViewer.md): 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.
345
+ - [ImageZoomToggle](./llms/components/data-display/ImageZoomToggle.md): 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.
343
346
  - [Item](./llms/components/data-display/Item.md)
344
347
  - [JsonRender](./llms/components/data-display/JsonRender.md)
345
348
  - [JsonViewer](./llms/components/data-display/JsonViewer.md)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexgorbatchev/shadcn",
3
- "version": "0.0.70",
3
+ "version": "0.0.72",
4
4
  "description": "Sharp, monospace React components with compact and comfortable densities.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -1012,6 +1012,10 @@
1012
1012
  "types": "./dist/components/image-crop/index.d.ts",
1013
1013
  "import": "./dist/components/image-crop/index.js"
1014
1014
  },
1015
+ "./image-viewer": {
1016
+ "types": "./dist/components/image-viewer/index.d.ts",
1017
+ "import": "./dist/components/image-viewer/index.js"
1018
+ },
1015
1019
  "./editor": {
1016
1020
  "types": "./dist/components/editor/index.d.ts",
1017
1021
  "import": "./dist/components/editor/index.js"