@reuse-sh/lightbox 0.0.6 → 0.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.
Files changed (53) hide show
  1. package/README.md +65 -16
  2. package/dist/audio.d.ts +2 -0
  3. package/dist/audio.js +17 -0
  4. package/dist/base.css +602 -0
  5. package/dist/browser/audio.js +3 -0
  6. package/dist/browser/audio.js.map +1 -0
  7. package/dist/browser/carousel-link.js +3 -0
  8. package/dist/browser/carousel-link.js.map +1 -0
  9. package/dist/browser/embed.js +3 -0
  10. package/dist/browser/embed.js.map +1 -0
  11. package/dist/browser/html.js +3 -0
  12. package/dist/browser/html.js.map +1 -0
  13. package/dist/browser/iframe.js +3 -0
  14. package/dist/browser/iframe.js.map +1 -0
  15. package/dist/browser/lightbox.js +3 -0
  16. package/dist/browser/lightbox.js.map +1 -0
  17. package/dist/browser/video.js +3 -0
  18. package/dist/browser/video.js.map +1 -0
  19. package/dist/carousel.d.ts +6 -0
  20. package/dist/carousel.js +17 -0
  21. package/dist/chrome.d.ts +35 -0
  22. package/dist/chrome.js +53 -0
  23. package/dist/embed.d.ts +14 -0
  24. package/dist/embed.js +173 -0
  25. package/dist/geometry.d.ts +37 -1
  26. package/dist/geometry.js +75 -5
  27. package/dist/html.d.ts +2 -0
  28. package/dist/html.js +15 -0
  29. package/dist/icons.d.ts +15 -0
  30. package/dist/icons.js +40 -0
  31. package/dist/iframe.d.ts +8 -0
  32. package/dist/iframe.js +43 -0
  33. package/dist/index.d.ts +180 -47
  34. package/dist/index.js +3817 -398
  35. package/dist/react.d.ts +18 -9
  36. package/dist/react.js +71 -46
  37. package/dist/sources.d.ts +28 -0
  38. package/dist/sources.js +179 -0
  39. package/dist/theme.css +236 -0
  40. package/dist/themes/dark.css +12 -0
  41. package/dist/themes/light.css +12 -0
  42. package/dist/themes/page.css +28 -0
  43. package/dist/themes/photos.css +17 -0
  44. package/dist/unlayered/base.css +599 -0
  45. package/dist/unlayered/theme.css +233 -0
  46. package/dist/unlayered/themes/dark.css +9 -0
  47. package/dist/unlayered/themes/light.css +9 -0
  48. package/dist/unlayered/themes/page.css +25 -0
  49. package/dist/unlayered/themes/photos.css +14 -0
  50. package/dist/video.d.ts +3 -0
  51. package/dist/video.js +55 -0
  52. package/package.json +33 -4
  53. package/dist/styles.css +0 -218
package/README.md CHANGED
@@ -8,12 +8,33 @@ An image viewer that opens from a thumbnail, including a cropped one, and return
8
8
 
9
9
  These are the rules the code keeps. An adaptation on any framework keeps them too.
10
10
 
11
- - **Page with native scroll snap.** Pages are a scroll-snap strip from the carousel, so touch and trackpads keep the system's momentum.
12
- - **Open from the thumbnail and return to it.** The image grows out of its cropped preview and goes back to the same place on close.
13
- - **Load only what is near.** Only the current and neighboring images load, and a long jump skips the pages in between.
14
- - **Zoom around the point you touch.** Pinch, wheel and double-tap zoom around the pointer or fingers, and panning stops at the image's edges.
15
- - **Keep focus inside and give it back.** The viewer is a native modal dialog, and closing it returns focus to the element that opened it.
16
- - **Leave the page as it was.** Destroy restores the page scroll, the hidden thumbnail, and every style and listener the viewer touched.
11
+ - **Page with native scroll snap.** Pages are a scroll-snap strip from the carousel, so touch and trackpads keep the system's momentum. A key, a thumbnail or goTo() during a held mouse drag ends the drag and goes straight to the new photo, so its release does not page back.
12
+ - **Open from the thumbnail and return to it.** The image grows out of its cropped preview with the tile's rounded corners and shrinks back into the current photo's tile on close.
13
+ - **Load only what is near.** Only the current and neighboring images load, the current one first, the neighbors not at all under Save-Data, and a long jump skips the pages in between.
14
+ - **Scrub through the strip.** A drag or a wheel on the thumbnail strip swaps the photo as each thumbnail reaches the ring, a scroll that ends in one frame too, with previews standing in until it stops, and reports and announces the photo it stops on once. A horizontal wheel over a bottom thumbnail uses native scrolling, and the empty ends of the strip pass pointer input through. Arrows, Home and End in the strip page the viewer, the arrows wrapping when loop is on, and focus and the tab stop follow the thumbnail under the ring. A thumbnail is at most three times as wide as it is tall.
15
+ - **Zoom around the point you touch.** Pinch, wheel, a double tap and a click zoom in around the pointer or fingers, and a double tap, a click or the zoom button zooms back out to the whole photo. A pinch and a wheel follow the input at once, and the rest ease over the zoom duration from wherever the photo is. A single finger tap shows or hides the controls.
16
+ - **Keep focus inside and give it back.** The viewer is a native modal dialog, and closing it returns focus to the current photo's tile, or else to the element that opened it.
17
+ - **Leave the page as it was.** Destroy restores the page scroll, the hidden thumbnail, and every style and listener the viewer touched, the abort listeners on your signals included. Back closes the viewer, and its one history entry leaves without a navigation, also when another viewer opened above it.
18
+ - **Behave like the platform's photo viewer.** Gestures, keys and timing match iOS Photos, macOS Photos and Google Photos unless a recorded decision says otherwise.
19
+ - **Dismiss like a photos app.** A vertical swipe carries the photo, fades the backdrop and the controls with it, and closes past a distance or a speed. A cancelled pointer never closes, a second finger leaves the swipe with the first, and a close ends the gesture.
20
+ - **Let the photo lead.** Controls fade in after the photo starts moving and leave before it. They hide while zoomed and after a still pointer, and a still pointer never hides them while one is hovered or keyboard-focused. While zoomed only close and zoom come back, focus on any other control, or on one a zoom stops rendering, moves to the photo, and the photo pans to the window's edges under the room the other controls kept.
21
+ - **Change the caption with the photo.** Each page fades the caption out while it rises 0.4em and fades the next one in as it rises from 0.4em below, over --re-lightbox-fade-duration, the other way when paging back, and swaps its text while it is hidden, so a caption of another height, or none, never jumps into view. A page during the fade goes on from the opacity and the shift on screen with the newest caption, the shift adds to a host's own translate, and reduced motion swaps it at once. The announcement of the settled photo reads its number and its caption once, through strings.slide(index, count, caption), so a translation sets the order and the separator.
22
+ - **Return to what is on screen.** Close goes back to the current photo's tile, after bringing it into view in its own carousel, and fades in place when the tile cannot be seen, in the window and in every container that clips it. A close during a mouse drag or a fling ends it, puts the strip on the current photo at once and flies from where the photo was, with no neighbor in view. The page scrolls and takes clicks during the flight and stays where it was scrolled once the viewer is gone, focus moved there stays, the tile's container does not cut the photo before it nears the tile, and the landing photo never changes the size of a scroll area.
23
+ - **Fetch the pixels the screen shows.** Each image loads the source that fits the rendered size, a zoom asks for more, and the preview stays until the sharper file has decoded and no finger holds the photo. A photo without a size fits the screen at its tile's proportions from the start and eases to its file's size once the file decodes.
24
+ - **Roll the count with the page.** Every counter, the built-in one and each a slot takes from counter(), rolls a changed digit up when paging forward and down when paging back, and switches at once under reduced motion.
25
+ - **Zoom to real pixels.** Zoom levels follow the image's own resolution. Panning stretches past the edge and glides on release.
26
+ - **Never block a frame.** No layout read or framework render runs per pointer move, scroll or wheel event.
27
+ - **Press like a native button.** A pressed control shrinks to --re-lightbox-press-scale, but a mouse press acts on release anywhere over the size it rests at, its outer edge included, and a release off it does nothing.
28
+ - **Give focus back quietly.** A click or a tap opens with focus on the close button and no ring. Focus returns to the photo's tile without a ring after a pointer close, and with one after a keyboard close, unless the visitor moved it during the close flight.
29
+ - **Show every shape readably.** A long screenshot opens at the screen's width and scrolls, a panorama zooms to the screen's height, a transparent photo sits on its own backing, and an SVG takes the size its file declares.
30
+ - **Hand the photo to the system.** The photo is a real image: the browser's menu saves and copies it, and Cmd or Ctrl and C copies it. protect turns these off. A mouse drag on it pages like a finger, so saving stays on Download and the context menu.
31
+ - **Stay light in large galleries.** A thousand photos open as fast as ten. Slides outside the preload window are empty shells, the strip's positions are arithmetic, and the next photo in the direction of travel loads first.
32
+ - **Let a slideshow yield.** A slideshow waits while the photo is zoomed, a video or audio slide plays, an embed is on screen, the mouse is over the controls, the tab is hidden or a slot's menu is open, and goes on with the time it had left, or at once when the video or audio ends. From the last photo it returns to the first without showing the photos between.
33
+ - **Play only the current slide.** Video, audio and embeds are optional modules. Leaving a slide pauses its player, close pauses them all at once, and over a player the pointer belongs to the player.
34
+ - **Trust no page by default.** Items read from markup are untrusted. An embed plays only a known provider, every frame from another origin and every popup it opens is sandboxed, and Download offers only web, blob and raster data files and never navigates the tab away.
35
+ - **Publish one state.** getState() returns the snapshot subscribers last received, so a gesture shows up once it settles, and a React component re-renders only for the part of it that it selects and hydrates from the state the lightbox was created with.
36
+ - **Take settings from markup or code.** A gallery reads JSON options from its markup under the options given in code, only while a photo from that gallery is open, and JSON it cannot read throws an error that names the element. A link is a trigger only when it holds an image or carries lightbox data, never a download link, and a trigger with no image file and no media type, or one clicked after the lightbox is destroyed, keeps its own click.
37
+ - **Survive every interruption.** Opening, closing, swiping, zooming, resizing, appending or destroying at any moment, or a callback that throws during open, leaves no dialog, timer, hidden tile, scroll lock or extra history entry behind.
17
38
 
18
39
  <!-- principles:end -->
19
40
 
@@ -23,6 +44,30 @@ These are the rules the code keeps. An adaptation on any framework keeps them to
23
44
  npm install @reuse-sh/lightbox
24
45
  ```
25
46
 
47
+ ## Browser build
48
+
49
+ For a page without a bundler or an import map, such as a theme or a plugin, copy `dist/browser/`, `dist/base.css` and `dist/theme.css` from the package into your assets. `lightbox.js` is one minified ES module with a source map and no imports, with the carousel inside it. `base.css` holds the layout in `@layer re.base` and `theme.css` the default theme in `@layer re.theme`; `dist/unlayered/` holds both without layers for a site whose own unlayered styles would win.
50
+
51
+ ```html
52
+ <link rel="stylesheet" href="/assets/lightbox/base.css" />
53
+ <link rel="stylesheet" href="/assets/lightbox/theme.css" />
54
+ <script type="module">
55
+ import {
56
+ bindLightboxGallery,
57
+ createLightbox,
58
+ } from "/assets/lightbox/browser/lightbox.js";
59
+
60
+ const lightbox = createLightbox();
61
+ const unbind = bindLightboxGallery(document.querySelector("#gallery"), lightbox);
62
+ </script>
63
+ ```
64
+
65
+ A theme or a plugin that prints its settings into the page can put them on the gallery as JSON, such as `<div id="gallery" data-lightbox-options='{"thumbnails":"bottom","loop":true}'>`. They fill whatever the lightbox was not given in code while a photo from that gallery is open, so galleries that share one lightbox keep their own settings, and JSON that does not parse throws a `TypeError` that names the element. A link opens in the lightbox when it holds an image or carries `data-lightbox-type` or `data-lightbox-src`, so a text link such as "Download full size" and any link with `download` stay links. Captions come from a `figcaption`, else `data-lightbox-caption`.
66
+
67
+ ## Trust
68
+
69
+ Items read from markup are untrusted: `data-lightbox-type`, a link's `href` and `data-lightbox-src` come from whoever wrote the page. `embed()` plays only YouTube, Vimeo and the providers you pass in `embed({ providers })`, and any other URL stays blank. Every frame `iframe()` or `embed()` loads from another origin, a provider's player included, gets `sandbox="allow-scripts allow-same-origin allow-forms allow-presentation allow-popups"`, so it cannot navigate your tab. Its popups keep the sandbox, so they cannot navigate it either. A page from your own origin loads unsandboxed, so a quick view keeps its links. That makes a same-origin URL trusted: an open redirect on your site leads the frame to any page without a sandbox. Pass `sandbox` to either module to set the attribute yourself. The Download button appears only for an `http:`, `https:` or `blob:` file or a PNG, JPEG, GIF, WebP or AVIF `data:` image. A web file, same-origin included, is fetched when the button is pressed and saved under the name its `Content-Disposition` header gives when the page can read it, else its decoded name, or opened in a new tab when its server refuses the fetch, so the page itself never navigates.
70
+
26
71
  <!-- examples:start -->
27
72
 
28
73
  ## Usage
@@ -33,10 +78,11 @@ npm install @reuse-sh/lightbox
33
78
 
34
79
  #### Package styles
35
80
 
36
- Import the package stylesheet once in your main CSS. The components layer lets Tailwind utilities adapt its presentation.
81
+ Import the package stylesheets once in your main CSS: base.css holds the layout and theme.css the default theme. The components layer lets Tailwind utilities adapt their presentation.
37
82
 
38
83
  ```css
39
- @import "@reuse-sh/lightbox/styles.css" layer(components);
84
+ @import "@reuse-sh/lightbox/base.css" layer(components);
85
+ @import "@reuse-sh/lightbox/theme.css" layer(components);
40
86
  ```
41
87
 
42
88
  #### Usage
@@ -68,7 +114,7 @@ export function Gallery() {
68
114
 
69
115
  #### Integration
70
116
 
71
- Links still open the image without JavaScript. The native dialog keeps focus inside, Escape closes it, and close restores the opening element. The React hook destroys its viewer on unmount.
117
+ Links still open the image without JavaScript. The native dialog keeps focus inside, Escape closes it, and close returns focus to the current photo's tile. The React hook closes its viewer at once and frees it on unmount or when Activity hides it, and opens the same viewer again when Activity shows it.
72
118
 
73
119
  ### HTML + JavaScript
74
120
 
@@ -86,32 +132,35 @@ Keep a real image link as the trigger, then enhance the gallery with bindLightbo
86
132
 
87
133
  #### Styles
88
134
 
89
- Import the package stylesheet once. Keep application layout styles scoped to this integration.
135
+ Import the package stylesheets once: base.css holds the layout and theme.css the default theme. Keep application layout styles scoped to this integration.
90
136
 
91
137
  ```css
92
- @import "@reuse-sh/lightbox/styles.css";
138
+ @import "@reuse-sh/lightbox/base.css";
139
+ @import "@reuse-sh/lightbox/theme.css";
93
140
  ```
94
141
 
95
142
  #### Initialize
96
143
 
97
- Run this after the markup exists. Keep the returned controller for the lifetime of this content.
144
+ Run this after the markup exists. Keep the lightbox and the unbind function for the lifetime of this content.
98
145
 
99
146
  ```javascript
100
- import { bindLightboxGallery } from "@reuse-sh/lightbox";
147
+ import { bindLightboxGallery, createLightbox } from "@reuse-sh/lightbox";
101
148
 
102
- const gallery = bindLightboxGallery(document.querySelector("#gallery"), {});
149
+ const lightbox = createLightbox();
150
+ const unbind = bindLightboxGallery(document.querySelector("#gallery"), lightbox);
103
151
  ```
104
152
 
105
153
  #### Integration
106
154
 
107
- Links still open the image without JavaScript. The native dialog keeps focus inside, Escape closes it, and close restores the opening element.
155
+ Links still open the image without JavaScript. The native dialog keeps focus inside, Escape closes it, and close returns focus to the current photo's tile.
108
156
 
109
157
  #### Cleanup
110
158
 
111
159
  Run this when the view is removed, before mounting another controller on the same element.
112
160
 
113
161
  ```javascript
114
- gallery.destroy();
162
+ unbind();
163
+ lightbox.destroy();
115
164
  ```
116
165
 
117
166
  <!-- examples:end -->
@@ -0,0 +1,2 @@
1
+ import type { LightboxContent } from "./index.js";
2
+ export declare function audio(): LightboxContent;
package/dist/audio.js ADDED
@@ -0,0 +1,17 @@
1
+ import { playerOf } from "./video.js";
2
+ export function audio() {
3
+ return {
4
+ type: "audio",
5
+ mount(container, { item, signal, autoplay }) {
6
+ const element = container.ownerDocument.createElement("audio");
7
+ element.className = "re-lightbox-audio";
8
+ element.controls = true;
9
+ element.preload = "metadata";
10
+ element.src = item.src ?? "";
11
+ if (item.alt)
12
+ element.setAttribute("aria-label", item.alt);
13
+ container.append(element);
14
+ return playerOf(element, autoplay, signal);
15
+ },
16
+ };
17
+ }