@reuse-sh/lightbox 0.3.1 → 0.4.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/README.md CHANGED
@@ -10,6 +10,7 @@ These are the rules the code keeps. An adaptation on any framework keeps them to
10
10
 
11
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
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
+ - **Carry what is drawn on the photo.** An item's margins make the photo and the room around it one picture that fits the screen, zooms to the photo's own pixels, pans and flies as a whole. What renderContent draws in it, labels beside the photo included, grows out of the tile with the photo, rests uncut and lands back with it, never fading or moving apart. An image tile shows the photo alone and any other tile the whole picture. A footer slot's height joins the room under the photo.
13
14
  - **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
15
  - **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
16
  - **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.
@@ -19,7 +20,7 @@ These are the rules the code keeps. An adaptation on any framework keeps them to
19
20
  - **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
21
  - **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
22
  - **Frame a photo that reads as a page.** A photo more than twice as tall as it is wide rests in a window the padding below the toolbar, beside the arrows and above the bottom room, ringed with --re-lightbox-media-ring, and scrolls inside it, so no control sits on it, a one-line caption stays below it, and a pale page still shows its edge on a pale room. Zoomed in, during a dismiss drag and in the close flight the window opens to the whole screen, the open flight closes it around the landing photo, and the ring shows only at the photo's resting size.
22
- - **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.
23
+ - **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, or the nodes captionContent builds, 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.
23
24
  - **Return to what is on screen.** A linked page carousel brings the current slide into view if less than half of its width is visible or if a move in progress would leave less than half visible. Close returns to the current photo's tile and fades in place when the window or a clipping container hides the tile. A close during a mouse drag or a fling ends it, puts the lightbox 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.
24
25
  - **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.
25
26
  - **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.
package/dist/base.css CHANGED
@@ -101,11 +101,12 @@
101
101
  }
102
102
  .re-lightbox-frame {
103
103
  position: relative;
104
+ box-sizing: border-box;
104
105
  flex: none;
105
106
  transform-origin: center;
106
107
  }
107
108
  .re-lightbox-frame[data-transparent]:not([data-loading], [data-error]) {
108
- background: var(--re-lightbox-media-background);
109
+ background: var(--re-lightbox-media-background) content-box;
109
110
  }
110
111
  .re-lightbox[data-zoom="in"]:where([data-zoomable="true"]) .re-lightbox-frame {
111
112
  cursor: zoom-in;
@@ -1,3 +1,3 @@
1
- /*! @reuse-sh/lightbox 0.3.1 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.4.0 | MIT License */
2
2
  import{playerOf as e}from"./video.js";function t(){return{type:`audio`,mount(t,{item:n,signal:r,autoplay:i}){let a=t.ownerDocument.createElement(`audio`);return a.className=`re-lightbox-audio`,a.controls=!0,a.preload=`metadata`,a.src=n.src??``,n.alt&&a.setAttribute(`aria-label`,n.alt),t.append(a),e(a,i,r)}}}export{t as audio};
3
3
  //# sourceMappingURL=audio.js.map
@@ -1,3 +1,3 @@
1
- /*! @reuse-sh/lightbox 0.3.1 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.4.0 | MIT License */
2
2
  const e=Symbol.for(`@reuse-sh/carousel internals`);function t(t,n,{slideOf:r=e=>e}={}){let i=n[e],a=e=>n.hold(`lightbox`,e),o=({index:e})=>{let t=r(e);(i?.willKeepVisible?.(t)??n.getState().visible.includes(t))||n.goTo(t,`instant`)},s=[t.on(`open`,()=>a(!0)),t.on(`settle`,o),t.on(`beforeclose`,o),t.on(`closed`,()=>a(!1))];return t.getState().isOpen&&a(!0),()=>{for(let e of s)e();a(!1)}}export{t as connectCarousel};
3
3
  //# sourceMappingURL=carousel-link.js.map
@@ -1,3 +1,3 @@
1
- /*! @reuse-sh/lightbox 0.3.1 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.4.0 | MIT License */
2
2
  import{frameOf as e,loaded as t}from"./iframe.js";const n=e=>{try{let t=typeof e==`string`?JSON.parse(e):e;return typeof t==`object`&&t?t:void 0}catch{return}},r={greet:e=>e({event:`listening`,id:1,channel:`widget`}),command:e=>({event:`command`,func:e===`mute`?`mute`:`${e}Video`,args:[]}),state(e){let t=e.info?.playerState;return t===1?`playing`:t===3?`waiting`:t===2||t===0?`paused`:t===-1||t===5?`unstarted`:void 0}},i={greet(e){for(let t of[`play`,`pause`,`ended`])e({method:`addEventListener`,value:t})},command:e=>e===`mute`?{method:`setVolume`,value:0}:{method:e},state:e=>e.event===`play`?`playing`:e.event===`pause`||e.event===`ended`?`paused`:void 0},a=/* @__PURE__ */ new WeakMap,o=e=>`https://www.youtube-nocookie.com/embed/${e}?enablejsapi=1&playsinline=1`,s=[{name:`youtube-shorts`,pattern:/^https?:\/\/(?:www\.|m\.)?youtube\.com\/shorts\/([\w-]+)/,url:e=>o(e[1]),aspect:9/16},{name:`youtube`,pattern:/^https?:\/\/(?:(?:www\.|m\.)?youtube(?:-nocookie)?\.com\/(?:watch\?(?:.*&)?v=|embed\/|live\/)|youtu\.be\/)([\w-]+)/,url:e=>o(e[1])},{name:`vimeo`,pattern:/^https?:\/\/(?:player\.)?vimeo\.com\/(?:video\/)?(\d+)(?:\/([\da-f]+))?/,url:e=>`https://player.vimeo.com/video/${e[1]}${e[2]?`?h=${e[2]}`:``}`}];a.set(s[0],r),a.set(s[1],r),a.set(s[2],i);function c(e,t){try{let n=new URL(e);for(let[e,r]of new URL(t).searchParams)if(!(e===`v`||n.searchParams.has(e===`t`?`start`:e))){if(e!==`t`)n.searchParams.set(e,r);else{let[,e=0,t=0,i=0]=/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$/.exec(r)??[],a=Number(e)*3600+Number(t)*60+Number(i);a&&n.searchParams.set(`start`,String(a))}}return n.href}catch{return e}}function l(r={}){let i=[...r.providers??[],...s];return{type:`embed`,mount(o,{item:s,signal:l,autoplay:u}){let d=s.src??``,f,p=null;for(let e of i)if(p=e.pattern.exec(d),p){f=e;break}let m=f&&p?c(f.url(p,s),d):``,h=e(o,m,s.alt??f?.name??``,r.sandbox),g=t(h,l),_={interactive:!0,aspect:f?.aspect,ready:g,unmount:()=>h.remove()},v=f&&a.get(f);if(!v)return _;let y=new URL(m).origin,b=e=>h.contentWindow?.postMessage(JSON.stringify(e),y),x=u,S=!1,C,w;return o.ownerDocument.defaultView?.addEventListener(`message`,e=>{if(e.source!==h.contentWindow||e.origin!==y)return;let t=n(e.data);C=(t&&v.state(t))??C,C===`playing`&&(x=!1,clearTimeout(w))},{signal:l}),l.addEventListener(`abort`,()=>clearTimeout(w)),g.then(()=>v.greet(b)),{..._,pause(){S=!1,clearTimeout(w),b(v.command(`pause`))},resume(){S=!0,x&&(x=!1,g.then(()=>{!l.aborted&&S&&(b(v.command(`play`)),w=setTimeout(()=>{C!==`playing`&&C!==`waiting`&&(b(v.command(`mute`)),b(v.command(`play`)))},1e3))}))}}}}}export{l as embed};
3
3
  //# sourceMappingURL=embed.js.map
@@ -1,3 +1,3 @@
1
- /*! @reuse-sh/lightbox 0.3.1 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.4.0 | MIT License */
2
2
  function e(){return{type:`html`,mount(e,{item:t}){let n=e.ownerDocument.createElement(`div`);n.className=`re-lightbox-html`;let r=t.html?.();return r&&n.append(r),e.append(n),{interactive:!0,unmount:()=>n.remove()}}}}export{e as html};
3
3
  //# sourceMappingURL=html.js.map
@@ -1,3 +1,3 @@
1
- /*! @reuse-sh/lightbox 0.3.1 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.4.0 | MIT License */
2
2
  function e(e,t,n,r){let i=e.ownerDocument,a=i.createElement(`iframe`);if(a.className=`re-lightbox-iframe`,a.allow=`autoplay; fullscreen; picture-in-picture`,a.referrerPolicy=`strict-origin-when-cross-origin`,a.loading=`lazy`,a.title=n,a.src=`about:blank`,t.trim())try{let e=new URL(t,i.baseURI);/^https?:$/.test(e.protocol)&&(a.src=e.href),e.origin!==i.location.origin&&(r??=`allow-scripts allow-same-origin allow-forms allow-presentation allow-popups`)}catch{}return r!=null&&(a.sandbox=r),e.append(a),a}function t(e,t){return new Promise(n=>e.addEventListener(`load`,n,{once:!0,signal:t}))}function n(n={}){return{type:`iframe`,mount(r,{item:i,signal:a}){let o=e(r,i.src??``,i.alt??``,n.sandbox);return{interactive:!0,ready:t(o,a),unmount:()=>o.remove()}}}}export{e as frameOf,n as iframe,t as loaded};
3
3
  //# sourceMappingURL=iframe.js.map