@reuse-sh/lightbox 0.3.0 → 0.3.1

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
@@ -20,13 +20,13 @@ These are the rules the code keeps. An adaptation on any framework keeps them to
20
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
21
  - **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
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
- - **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
+ - **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
24
  - **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
25
  - **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.
26
26
  - **Zoom to real pixels.** Zoom levels follow the image's own resolution. Panning stretches past the edge and glides on release.
27
27
  - **Never block a frame.** No layout read or framework render runs per pointer move, scroll or wheel event.
28
28
  - **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.
29
- - **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
+ - **Give focus back quietly.** A click or a tap opens with focus on the close button and no ring. Escape closes without changing the input mode. Focus returns to the photo's tile without a ring after pointer use, and with one after keyboard use, unless the visitor moved it during the close flight.
30
30
  - **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.
31
31
  - **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.
32
32
  - **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.
@@ -1,3 +1,3 @@
1
- /*! @reuse-sh/lightbox 0.3.0 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.3.1 | 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.0 | MIT License */
2
- function e(e,t,{slideOf:n=e=>e}={}){let r=e=>t.hold(`lightbox`,e),i=e=>t.goTo(n(e.index),`instant`),a=[e.on(`open`,()=>r(!0)),e.on(`settle`,i),e.on(`beforeclose`,i),e.on(`closed`,()=>r(!1))];return e.getState().isOpen&&r(!0),()=>{for(let e of a)e();r(!1)}}export{e as connectCarousel};
1
+ /*! @reuse-sh/lightbox 0.3.1 | MIT License */
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 +1 @@
1
- {"version":3,"file":"carousel-link.js","names":["connectCarousel","index","hold","carousel","isHeld","follow","slideOf","event","stops","lightbox","stop"],"sources":["../carousel.js"],"sourcesContent":["export function connectCarousel(lightbox, carousel, { slideOf = (index) => index } = {}) {\n const hold = (isHeld) => carousel.hold(\"lightbox\", isHeld);\n const follow = (event) => carousel.goTo(slideOf(event.index), \"instant\");\n const stops = [\n lightbox.on(\"open\", () => hold(true)),\n lightbox.on(\"settle\", follow),\n lightbox.on(\"beforeclose\", follow),\n lightbox.on(\"closed\", () => hold(false)),\n ];\n if (lightbox.getState().isOpen)\n hold(true);\n return () => {\n for (const stop of stops)\n stop();\n hold(false);\n };\n}\n"],"mappings":";AAAA,SAAgBA,EAAgB,EAAU,EAAU,CAAE,UAAW,GAAUC,GAAU,CAAC,EAAG,CACrF,IAAMC,EAAQ,GAAWC,EAAS,KAAK,WAAYC,CAAM,EACnDC,EAAU,GAAUF,EAAS,KAAKG,EAAQC,EAAM,KAAK,EAAG,SAAS,EACjEC,EAAQ,CACVC,EAAS,GAAG,WAAcP,EAAK,EAAI,CAAC,EACpCO,EAAS,GAAG,SAAUJ,CAAM,EAC5BI,EAAS,GAAG,cAAeJ,CAAM,EACjCI,EAAS,GAAG,aAAgBP,EAAK,EAAK,CAAC,CAC3C,EAGA,OAFIO,EAAS,SAAS,CAAC,CAAC,QACpBP,EAAK,EAAI,MACA,CACT,IAAK,IAAMQ,KAAQF,EACfE,EAAK,EACTR,EAAK,EAAK,CACd,CACJ,C"}
1
+ {"version":3,"file":"carousel-link.js","names":["carouselInternals","connectCarousel","index","strip","carousel","hold","isHeld","follow","slide","slideOf","stops","lightbox","stop"],"sources":["../carousel.js"],"sourcesContent":["const carouselInternals = Symbol.for(\"@reuse-sh/carousel internals\");\nexport function connectCarousel(lightbox, carousel, { slideOf = (index) => index } = {}) {\n const strip = carousel[carouselInternals];\n const hold = (isHeld) => carousel.hold(\"lightbox\", isHeld);\n const follow = ({ index }) => {\n const slide = slideOf(index);\n const visible = strip?.willKeepVisible?.(slide) ??\n carousel.getState().visible.includes(slide);\n if (!visible)\n carousel.goTo(slide, \"instant\");\n };\n const stops = [\n lightbox.on(\"open\", () => hold(true)),\n lightbox.on(\"settle\", follow),\n lightbox.on(\"beforeclose\", follow),\n lightbox.on(\"closed\", () => hold(false)),\n ];\n if (lightbox.getState().isOpen)\n hold(true);\n return () => {\n for (const stop of stops)\n stop();\n hold(false);\n };\n}\n"],"mappings":";AAAA,MAAMA,EAAoB,OAAO,IAAI,8BAA8B,EACnE,SAAgBC,EAAgB,EAAU,EAAU,CAAE,UAAW,GAAUC,GAAU,CAAC,EAAG,CACrF,IAAMC,EAAQC,EAASJ,GACjBK,EAAQ,GAAWD,EAAS,KAAK,WAAYE,CAAM,EACnDC,GAAU,CAAE,WAAY,CAC1B,IAAMC,EAAQC,EAAQP,CAAK,GACXC,GAAO,kBAAkBK,CAAK,GAC1CJ,EAAS,SAAS,CAAC,CAAC,QAAQ,SAASI,CAAK,IAE1CJ,EAAS,KAAKI,EAAO,SAAS,CACtC,EACME,EAAQ,CACVC,EAAS,GAAG,WAAcN,EAAK,EAAI,CAAC,EACpCM,EAAS,GAAG,SAAUJ,CAAM,EAC5BI,EAAS,GAAG,cAAeJ,CAAM,EACjCI,EAAS,GAAG,aAAgBN,EAAK,EAAK,CAAC,CAC3C,EAGA,OAFIM,EAAS,SAAS,CAAC,CAAC,QACpBN,EAAK,EAAI,MACA,CACT,IAAK,IAAMO,KAAQF,EACfE,EAAK,EACTP,EAAK,EAAK,CACd,CACJ,C"}
@@ -1,3 +1,3 @@
1
- /*! @reuse-sh/lightbox 0.3.0 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.3.1 | 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.0 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.3.1 | 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.0 | MIT License */
1
+ /*! @reuse-sh/lightbox 0.3.1 | 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