@fluritheme/image-zoom 0.0.0-stage → 1.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 — 2026-12-05
4
+
5
+ - First release.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 František Gejdoš (Fluri, https://fluri.xyz)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,104 @@
1
- # Temporary Holding Version
1
+ # Image Zoom by Fluri
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Click a picture and it grows to fill the screen. Image Zoom.
4
+
5
+ **[Live demo →](https://fluri.xyz/image-zoom/)** · [All Fluri themes](https://fluri.xyz/themes/) · No-code install for WordPress, Shopify, Wix & more at [fluri.xyz](https://fluri.xyz/image-zoom/)
6
+
7
+ ![Image Zoom by Fluri on a website](https://fluri.xyz/previews/npm/v2/image-zoom.png)
8
+
9
+ - Zero dependencies, about 10 KB minified
10
+ - The picture grows from its own place, so the eye never loses it
11
+ - Never bigger than the real image, so it doesn't go blurry (raise `maxScale` if you want)
12
+ - Click, scroll, resize or Esc closes it; Tab and Enter open it
13
+ - A picture that is a link stays a link (add `data-zoom` to zoom it anyway)
14
+ - Small icons and avatars are skipped by width; images added later are picked up
15
+ - Works with plain HTML, React, Vue, Svelte, Astro, Next.js and anything else
16
+ - TypeScript types included
17
+
18
+ ## Quick start: one line of HTML
19
+
20
+ Paste this before `</body>`:
21
+
22
+ ```html
23
+ <script src="https://cdn.jsdelivr.net/npm/@fluritheme/image-zoom@1/dist/image-zoom.global.js" data-auto></script>
24
+ ```
25
+
26
+ Pass options as JSON:
27
+
28
+ ```html
29
+ <script src="https://cdn.jsdelivr.net/npm/@fluritheme/image-zoom@1/dist/image-zoom.global.js" data-auto data-options='{"target":"article img, main img"}'></script>
30
+ ```
31
+
32
+ The running effect is available as `window.FluriImageZoom.instance`.
33
+
34
+
35
+ ## Install with npm
36
+
37
+ ```sh
38
+ npm install @fluritheme/image-zoom
39
+ ```
40
+
41
+ ```ts
42
+ import { createImageZoom } from "@fluritheme/image-zoom";
43
+
44
+ const zoom = createImageZoom({
45
+ target: "article img", // add data-no-zoom to skip one
46
+ margin: 24,
47
+ background: "rgba(10,10,14,.88)",
48
+ });
49
+
50
+ zoom.open(document.querySelector("img.hero"));
51
+ zoom.close();
52
+
53
+ // When leaving the page or unmounting a component:
54
+ zoom.destroy();
55
+ ```
56
+
57
+ ### React
58
+
59
+ ```tsx
60
+ import { useEffect } from "react";
61
+ import { createImageZoom } from "@fluritheme/image-zoom";
62
+
63
+ export function ImageZoom() {
64
+ useEffect(() => {
65
+ const effect = createImageZoom();
66
+ return () => effect.destroy();
67
+ }, []);
68
+ return null;
69
+ }
70
+ ```
71
+
72
+ ## Options
73
+
74
+ | Option | What it does | Default |
75
+ | --- | --- | --- |
76
+ | `target` | What can be zoomed (CSS selector) | `"img"` |
77
+ | `margin` | Space kept around the zoomed picture, in pixels | `24` |
78
+ | `background` | Backdrop colour | `"rgba(10,10,14,.88)"` |
79
+ | `minWidth` | Pictures narrower than this are left alone | `120` |
80
+ | `maxScale` | How far a picture may grow past its real size | `1` |
81
+ | `root` | Limit to one element | document |
82
+ | `zIndex` | Stacking order | `2147483000` |
83
+
84
+ ## Methods
85
+
86
+ - `open(element)`
87
+ - `close()`
88
+ - `update(options)`
89
+ - `getState()`
90
+ - `destroy()`
91
+
92
+ ## Great for
93
+
94
+ - Product photos in online shops
95
+ - Portfolios and photography
96
+ - Screenshots in blogs and documentation
97
+
98
+ ## No code? Use Fluri
99
+
100
+ Don’t want to touch code? [Fluri](https://fluri.xyz/image-zoom/) installs Image Zoom on WordPress, Shopify, Webflow, Wix, Squarespace and Framer with one snippet, with live settings and a dashboard. There are more than a dozen animated themes, from a pet dragon to a koi pond. [See them all →](https://fluri.xyz/themes/)
101
+
102
+ ## License
103
+
104
+ MIT © František Gejdoš · [fluri.xyz](https://fluri.xyz)
@@ -0,0 +1 @@
1
+ export declare function showFluriBadge(slug: string): void;
@@ -0,0 +1,28 @@
1
+ export interface ImageZoomOptions {
2
+ /** Limit it to one element (for previews). */
3
+ root?: HTMLElement;
4
+ /** What can be zoomed (CSS selector). Default "img". Add data-no-zoom to skip one. */
5
+ target?: string;
6
+ /** Space kept around the zoomed picture, in pixels. Default 24. */
7
+ margin?: number;
8
+ /** Backdrop colour. Default "rgba(10,10,14,.88)". */
9
+ background?: string;
10
+ /** Pictures narrower than this are left alone (icons, avatars). Default 120. */
11
+ minWidth?: number;
12
+ /** How far a picture may grow past its real size. Default 1. */
13
+ maxScale?: number;
14
+ /** Stacking order. Default 2147483000. */
15
+ zIndex?: number;
16
+ }
17
+ export interface ImageZoomState {
18
+ open: boolean;
19
+ }
20
+ export declare function createImageZoom(options?: ImageZoomOptions): {
21
+ open: (el: HTMLElement) => void;
22
+ close: () => void;
23
+ update(next: Partial<ImageZoomOptions>): void;
24
+ pause(): void;
25
+ resume(): void;
26
+ destroy(): void;
27
+ getState(): ImageZoomState;
28
+ };
@@ -0,0 +1,29 @@
1
+ /*! @fluritheme/image-zoom v1.0.0 | MIT | https://fluri.xyz/image-zoom/ */
2
+ (()=>{var S=(l,n,i)=>Math.max(n,Math.min(i,l));var G=`
3
+ .fluri-iz-able{cursor:zoom-in}
4
+ .fluri-iz-back{position:fixed;inset:0;opacity:0;transition:opacity .3s ease;cursor:zoom-out}
5
+ .fluri-iz-back.on{opacity:1}
6
+ .fluri-iz-clone{position:fixed;margin:0!important;max-width:none!important;max-height:none!important;transform-origin:0 0;transition:transform .32s cubic-bezier(.2,.8,.2,1);cursor:zoom-out;will-change:transform}
7
+ @media (prefers-reduced-motion:reduce){.fluri-iz-back,.fluri-iz-clone{transition:none}}
8
+ `;function q(l={}){var F;let n={target:"img",margin:24,background:"rgba(10,10,14,.88)",minWidth:120,maxScale:1,zIndex:2147483e3,...l};if(!document.getElementById("fluri-iz-css")){let e=document.createElement("style");e.id="fluri-iz-css",e.textContent=G,document.head.appendChild(e)}let i=matchMedia("(prefers-reduced-motion: reduce)").matches,m=(F=n.root)!=null?F:document.body,a=null,r=null,o=null,p=0,g=0,h=[];function x(e){if(!(e instanceof Element))return null;let t=null;try{t=e.closest(n.target)}catch{t=e.closest("img")}return!t||!m.contains(t)||t.closest("[data-no-zoom],.fluri-iz-clone")||t===a||t.closest("a[href]")&&!t.hasAttribute("data-zoom")||t.getBoundingClientRect().width<n.minWidth?null:t}function b(){for(let t of h)t.classList.remove("fluri-iz-able");h=[];let e=[];try{e=[...m.querySelectorAll(n.target)]}catch{e=[]}for(let t of e)x(t)&&(t.classList.add("fluri-iz-able"),t.hasAttribute("tabindex")||(t.tabIndex=0,t.dataset.fluriIzTab=""),h.push(t))}function M(e){var s;let t=(s=n.root)!=null?s:document.documentElement;for(let c=e.parentElement;c&&c!==t&&c!==document.body;c=c.parentElement){let d=getComputedStyle(c);if(d.overflowX!=="visible"||d.overflowY!=="visible"||d.transform!=="none"||d.filter!=="none"||d.opacity!=="1"||d.isolation==="isolate"||d.contain!=="none"||d.position!=="static"&&d.zIndex!=="auto")return!1}return!0}let u=null,k=["translate","scale","transition","position","zIndex","cursor"];function I(e){var P,$,B,D,N,j;if(a)return;clearTimeout(g);let t=e.getBoundingClientRect(),s=(P=n.root)==null?void 0:P.getBoundingClientRect(),c=s?s.width:innerWidth,d=s?s.height:innerHeight,w=($=s==null?void 0:s.left)!=null?$:0,L=(B=s==null?void 0:s.top)!=null?B:0,y=S(n.margin,0,200),f=e instanceof HTMLImageElement&&e.naturalWidth?e.naturalWidth/t.width*S(n.maxScale,1,4):2.4,v=Math.max(1,Math.min((c-y*2)/t.width,(d-y*2)/t.height,f)),W=c/2-(t.left-w+t.width/2),Z=d/2-(t.top-L+t.height/2);if(o=document.createElement("div"),o.className="fluri-iz-back",o.style.background=n.background,o.style.zIndex=String(n.zIndex),n.root&&(o.style.position="absolute"),((D=n.root)!=null?D:document.body).append(o),a=e,p=scrollY,M(e)){let T=e.style;u={};for(let z of k)u[z]=(N=T[z])!=null?N:"";getComputedStyle(e).position==="static"&&(e.style.position="relative"),e.style.zIndex=String(n.zIndex+1),e.style.cursor="zoom-out",e.style.transition=i?"none":"translate .32s cubic-bezier(.2,.8,.2,1), scale .32s cubic-bezier(.2,.8,.2,1)",e.offsetWidth,e.style.translate=`${W}px ${Z}px`,e.style.scale=String(v)}else{r=e.cloneNode(!0),r.removeAttribute("id"),r.classList.remove("fluri-iz-able"),r.classList.add("fluri-iz-clone"),e instanceof HTMLImageElement&&r instanceof HTMLImageElement&&(r.src=e.currentSrc||e.src,r.removeAttribute("srcset"),r.removeAttribute("loading"));let T=getComputedStyle(e);for(let z of["borderRadius","objectFit","objectPosition","background","boxShadow","border"])r.style[z]=T[z];Object.assign(r.style,{left:`${t.left-w}px`,top:`${t.top-L}px`,width:`${t.width}px`,height:`${t.height}px`,zIndex:String(n.zIndex+1)}),n.root&&(r.style.position="absolute"),r.setAttribute("role","button"),r.setAttribute("aria-label","Close the enlarged picture"),((j=n.root)!=null?j:document.body).append(r),e.style.visibility="hidden",r.offsetWidth,r.style.transform=`translate(${W-t.width*(v-1)/2}px,${Z-t.height*(v-1)/2}px) scale(${v})`}o.classList.add("on")}function E(){var d,w,L;if(!a||!o)return;let e=a,t=r,s=o,c=u;if(a=r=o=null,u=null,s.classList.remove("on"),t){let y=e.getBoundingClientRect(),f=(d=n.root)==null?void 0:d.getBoundingClientRect();t.style.transform=`translate(${y.left-((w=f==null?void 0:f.left)!=null?w:0)-parseFloat(t.style.left)}px,${y.top-((L=f==null?void 0:f.top)!=null?L:0)-parseFloat(t.style.top)}px) scale(1)`}else e.style.translate=(c==null?void 0:c.translate)||"0px 0px",e.style.scale=(c==null?void 0:c.scale)||"1";g=window.setTimeout(()=>{var y;if(t)e.style.visibility="",t.remove();else if(c){let f=e.style;for(let v of k)f[v]=(y=c[v])!=null?y:""}s.remove()},330)}let A=e=>{if(a)return e.preventDefault(),E();let t=x(e.target);!t||e.button!==0||e.metaKey||e.ctrlKey||(e.preventDefault(),I(t))},R=e=>{if(a){(e.key==="Escape"||e.key==="Enter"||e.key===" ")&&(e.preventDefault(),E());return}if(e.key!=="Enter"&&e.key!==" ")return;let t=x(document.activeElement);t&&t===document.activeElement&&(e.preventDefault(),I(t))},O=()=>{a&&Math.abs(scrollY-p)>40&&E()};document.addEventListener("click",A),document.addEventListener("keydown",R),addEventListener("scroll",O,{passive:!0}),addEventListener("resize",E),b();let J=window.setInterval(()=>!a&&b(),2e3);return{open:I,close:E,update(e){Object.assign(n,e),b()},pause(){},resume(){},destroy(){var e;if(clearInterval(J),clearTimeout(g),document.removeEventListener("click",A),document.removeEventListener("keydown",R),removeEventListener("scroll",O),removeEventListener("resize",E),a&&(a.style.visibility="",u)){let t=a.style;for(let s of k)t[s]=(e=u[s])!=null?e:""}r==null||r.remove(),o==null||o.remove(),a=r=o=null,u=null;for(let t of h)t.classList.remove("fluri-iz-able"),"fluriIzTab"in t.dataset&&(t.removeAttribute("tabindex"),delete t.dataset.fluriIzTab);h=[]},getState(){return{open:!!a}}}}var Q="https://fluri.xyz/themes/",K=!1,V=`
9
+ :host{all:initial}
10
+ a{position:fixed;z-index:2147483600;display:inline-flex;align-items:center;gap:9px;padding:8px 10px 8px 9px;max-width:calc(100vw - 32px);
11
+ border-radius:999px;background:rgba(22,18,36,.88);-webkit-backdrop-filter:blur(12px) saturate(1.4);backdrop-filter:blur(12px) saturate(1.4);
12
+ border:1px solid rgba(255,255,255,.14);box-shadow:0 10px 30px rgba(10,6,30,.28),0 1px 0 rgba(255,255,255,.08) inset;
13
+ color:#fff;font:600 13px/1.2 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;letter-spacing:.01em;text-decoration:none;
14
+ opacity:0;transform:translateY(10px) scale(.98);transition:opacity .35s ease,transform .35s cubic-bezier(.2,.8,.2,1),background .2s}
15
+ a.in{opacity:1;transform:none}
16
+ a:hover{background:rgba(32,26,52,.96)}
17
+ a:focus-visible{outline:3px solid #a78bfa;outline-offset:3px}
18
+ .star{flex:none;display:grid;place-items:center;width:22px;height:22px;border-radius:50%;background:conic-gradient(from 210deg,#8b5cf6,#ec4899,#f59e0b,#8b5cf6);box-shadow:0 0 12px rgba(167,139,250,.55)}
19
+ .star svg{width:12px;height:12px;fill:#fff}
20
+ .txt{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
21
+ .txt b{font-weight:700;background:linear-gradient(90deg,#c4b5fd,#fbcfe8);-webkit-background-clip:text;background-clip:text;color:transparent}
22
+ .arrow{flex:none;transition:transform .2s}
23
+ a:hover .arrow{transform:translateX(2px)}
24
+ button{all:unset;flex:none;display:grid;place-items:center;width:20px;height:20px;margin-left:2px;border-radius:50%;color:rgba(255,255,255,.7);font:600 14px/1 system-ui;cursor:pointer}
25
+ button:hover{background:rgba(255,255,255,.14);color:#fff}
26
+ button:focus-visible{outline:2px solid #a78bfa}
27
+ @media (max-width:480px){a{font-size:12px;padding:7px 8px 7px 7px;gap:7px}.star{width:20px;height:20px}}
28
+ @media (prefers-reduced-motion:reduce){a{transition:opacity .2s}a,a.in{transform:none}}
29
+ `,U=["bottom-left","bottom-center","bottom-right","top-right"];function Y(l,n){let i=l.style;i.top=i.bottom=i.left=i.right=i.transform="",n.startsWith("bottom")?i.bottom="16px":i.top="16px",n.endsWith("left")?i.left="16px":n.endsWith("right")?i.right="16px":(i.left="50%",i.marginLeft=-(l.offsetWidth/2)+"px"),n!=="bottom-center"&&(i.marginLeft="")}function ee(l,n){let i=[[n.left+4,n.top+4],[n.right-4,n.top+4],[n.left+4,n.bottom-4],[n.right-4,n.bottom-4],[n.left+n.width/2,n.top+n.height/2]];for(let[m,a]of i)for(let r of document.elementsFromPoint(m,a))if(!(r===l||r===document.body||r===document.documentElement))for(let o=r;o&&o!==document.body;o=o.parentElement){let p=getComputedStyle(o).position;if(p==="fixed"||p==="sticky")return!0}return!1}function te(){try{let l=location.hostname;if(/(^|\.)fluri\.xyz$/.test(l)||/(^|\.)(codepen\.io|cdpn\.io)$/.test(l)||navigator.webdriver||/HeadlessChrome|Playwright|Puppeteer/i.test(navigator.userAgent))return!0}catch{}return!1}function _(l){if(K||typeof document=="undefined"||typeof window=="undefined"||te())return;K=!0;let n=()=>{let m=document.createElement("fluri-badge");m.setAttribute("style","all:initial");let a=m.attachShadow({mode:"open"}),r=document.createElement("style");r.textContent=V;let o=document.createElement("a");o.href=Q+"?utm_source=npm&utm_medium=badge&utm_campaign="+encodeURIComponent(l),o.target="_blank",o.rel="noopener",o.setAttribute("aria-label","Unlock all themes on fluri.xyz (opens in a new tab)");let p=document.createElement("span");p.className="star",p.innerHTML='<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2l2.4 6.6L21 11l-6.6 2.4L12 20l-2.4-6.6L3 11l6.6-2.4z"/></svg>';let g=document.createElement("span");g.className="txt",g.append("Unlock all themes on ");let h=document.createElement("b");h.textContent="fluri.xyz",g.append(h);let x=document.createElement("span");x.className="arrow",x.setAttribute("aria-hidden","true"),x.textContent="\u2192";let b=document.createElement("button");b.type="button",b.setAttribute("aria-label","Hide"),b.textContent="\xD7",b.addEventListener("click",u=>{u.preventDefault(),u.stopPropagation(),o.classList.remove("in"),setTimeout(()=>m.remove(),350)}),o.append(p,g,x,b),a.append(r,o),document.body.appendChild(m);let M=U[0];for(let u of U)if(Y(o,u),!ee(m,o.getBoundingClientRect())){M=u;break}Y(o,M),requestAnimationFrame(()=>requestAnimationFrame(()=>o.classList.add("in")))},i=()=>setTimeout(n,1200);document.readyState==="loading"?document.addEventListener("DOMContentLoaded",i,{once:!0}):i()}function C(...l){return _("image-zoom"),q(...l)}var X={createImageZoom:C};window.FluriImageZoom=X;var H=document.currentScript;if(H&&H.hasAttribute("data-auto")){let l=()=>{let n={};try{n=JSON.parse(H.getAttribute("data-options")||"{}")}catch{}X.instance=C(n)};document.readyState==="loading"?document.addEventListener("DOMContentLoaded",l,{once:!0}):l()}})();
@@ -0,0 +1,4 @@
1
+ export * from "./image-zoom.js";
2
+ import { createImageZoom as base } from "./image-zoom.js";
3
+ /** createImageZoom from Fluri. Also shows a small "Unlock all themes on fluri.xyz" badge. */
4
+ export declare function createImageZoom(...args: Parameters<typeof base>): ReturnType<typeof base>;
package/dist/index.js ADDED
@@ -0,0 +1,374 @@
1
+ /*! @fluritheme/image-zoom v1.0.0 | MIT | https://fluri.xyz/image-zoom/ */
2
+
3
+ // packages/image-zoom/src/overlay.ts
4
+ var clamp = (v, a, b) => Math.max(a, Math.min(b, v));
5
+
6
+ // packages/image-zoom/src/image-zoom.ts
7
+ var CSS = `
8
+ .fluri-iz-able{cursor:zoom-in}
9
+ .fluri-iz-back{position:fixed;inset:0;opacity:0;transition:opacity .3s ease;cursor:zoom-out}
10
+ .fluri-iz-back.on{opacity:1}
11
+ .fluri-iz-clone{position:fixed;margin:0!important;max-width:none!important;max-height:none!important;transform-origin:0 0;transition:transform .32s cubic-bezier(.2,.8,.2,1);cursor:zoom-out;will-change:transform}
12
+ @media (prefers-reduced-motion:reduce){.fluri-iz-back,.fluri-iz-clone{transition:none}}
13
+ `;
14
+ function createImageZoom(options = {}) {
15
+ const o = {
16
+ target: "img",
17
+ margin: 24,
18
+ background: "rgba(10,10,14,.88)",
19
+ minWidth: 120,
20
+ maxScale: 1,
21
+ zIndex: 2147483e3,
22
+ ...options
23
+ };
24
+ if (!document.getElementById("fluri-iz-css")) {
25
+ const s = document.createElement("style");
26
+ s.id = "fluri-iz-css";
27
+ s.textContent = CSS;
28
+ document.head.appendChild(s);
29
+ }
30
+ const reduced = matchMedia("(prefers-reduced-motion: reduce)").matches;
31
+ const scope = o.root ?? document.body;
32
+ let source = null, clone = null, back = null, startScroll = 0, closing = 0, marked = [];
33
+ function zoomable(t) {
34
+ if (!(t instanceof Element)) return null;
35
+ let el = null;
36
+ try {
37
+ el = t.closest(o.target);
38
+ } catch {
39
+ el = t.closest("img");
40
+ }
41
+ if (!el || !scope.contains(el) || el.closest("[data-no-zoom],.fluri-iz-clone")) return null;
42
+ if (el === source) return null;
43
+ if (el.closest("a[href]") && !el.hasAttribute("data-zoom")) return null;
44
+ if (el.getBoundingClientRect().width < o.minWidth) return null;
45
+ return el;
46
+ }
47
+ function mark() {
48
+ for (const el of marked) el.classList.remove("fluri-iz-able");
49
+ marked = [];
50
+ let all = [];
51
+ try {
52
+ all = [...scope.querySelectorAll(o.target)];
53
+ } catch {
54
+ all = [];
55
+ }
56
+ for (const el of all)
57
+ if (zoomable(el)) {
58
+ el.classList.add("fluri-iz-able");
59
+ if (!el.hasAttribute("tabindex")) {
60
+ el.tabIndex = 0;
61
+ el.dataset.fluriIzTab = "";
62
+ }
63
+ marked.push(el);
64
+ }
65
+ }
66
+ function free(el) {
67
+ const stop = o.root ?? document.documentElement;
68
+ for (let p = el.parentElement; p && p !== stop && p !== document.body; p = p.parentElement) {
69
+ const c = getComputedStyle(p);
70
+ if (c.overflowX !== "visible" || c.overflowY !== "visible" || c.transform !== "none" || c.filter !== "none" || c.opacity !== "1" || c.isolation === "isolate" || c.contain !== "none" || c.position !== "static" && c.zIndex !== "auto")
71
+ return false;
72
+ }
73
+ return true;
74
+ }
75
+ let saved = null;
76
+ const KEEP = ["translate", "scale", "transition", "position", "zIndex", "cursor"];
77
+ function open(el) {
78
+ if (source) return;
79
+ clearTimeout(closing);
80
+ const r = el.getBoundingClientRect();
81
+ const g = o.root?.getBoundingClientRect();
82
+ const vw = g ? g.width : innerWidth, vh = g ? g.height : innerHeight, ox = g?.left ?? 0, oy = g?.top ?? 0;
83
+ const m = clamp(o.margin, 0, 200);
84
+ const natural = el instanceof HTMLImageElement && el.naturalWidth ? el.naturalWidth / r.width * clamp(o.maxScale, 1, 4) : 2.4;
85
+ const scale = Math.max(
86
+ 1,
87
+ Math.min((vw - m * 2) / r.width, (vh - m * 2) / r.height, natural)
88
+ );
89
+ const cx = vw / 2 - (r.left - ox + r.width / 2), cy = vh / 2 - (r.top - oy + r.height / 2);
90
+ back = document.createElement("div");
91
+ back.className = "fluri-iz-back";
92
+ back.style.background = o.background;
93
+ back.style.zIndex = String(o.zIndex);
94
+ if (o.root) back.style.position = "absolute";
95
+ (o.root ?? document.body).append(back);
96
+ source = el;
97
+ startScroll = scrollY;
98
+ if (free(el)) {
99
+ const st = el.style;
100
+ saved = {};
101
+ for (const k of KEEP) saved[k] = st[k] ?? "";
102
+ if (getComputedStyle(el).position === "static") el.style.position = "relative";
103
+ el.style.zIndex = String(o.zIndex + 1);
104
+ el.style.cursor = "zoom-out";
105
+ el.style.transition = reduced ? "none" : "translate .32s cubic-bezier(.2,.8,.2,1), scale .32s cubic-bezier(.2,.8,.2,1)";
106
+ void el.offsetWidth;
107
+ el.style.translate = `${cx}px ${cy}px`;
108
+ el.style.scale = String(scale);
109
+ } else {
110
+ clone = el.cloneNode(true);
111
+ clone.removeAttribute("id");
112
+ clone.classList.remove("fluri-iz-able");
113
+ clone.classList.add("fluri-iz-clone");
114
+ if (el instanceof HTMLImageElement && clone instanceof HTMLImageElement) {
115
+ clone.src = el.currentSrc || el.src;
116
+ clone.removeAttribute("srcset");
117
+ clone.removeAttribute("loading");
118
+ }
119
+ const cs = getComputedStyle(el);
120
+ for (const k of ["borderRadius", "objectFit", "objectPosition", "background", "boxShadow", "border"])
121
+ clone.style[k] = cs[k];
122
+ Object.assign(clone.style, {
123
+ left: `${r.left - ox}px`,
124
+ top: `${r.top - oy}px`,
125
+ width: `${r.width}px`,
126
+ height: `${r.height}px`,
127
+ zIndex: String(o.zIndex + 1)
128
+ });
129
+ if (o.root) clone.style.position = "absolute";
130
+ clone.setAttribute("role", "button");
131
+ clone.setAttribute("aria-label", "Close the enlarged picture");
132
+ (o.root ?? document.body).append(clone);
133
+ el.style.visibility = "hidden";
134
+ void clone.offsetWidth;
135
+ clone.style.transform = `translate(${cx - r.width * (scale - 1) / 2}px,${cy - r.height * (scale - 1) / 2}px) scale(${scale})`;
136
+ }
137
+ back.classList.add("on");
138
+ }
139
+ function close() {
140
+ if (!source || !back) return;
141
+ const el = source, c = clone, b = back, keep = saved;
142
+ source = clone = back = null;
143
+ saved = null;
144
+ b.classList.remove("on");
145
+ if (c) {
146
+ const r = el.getBoundingClientRect();
147
+ const g = o.root?.getBoundingClientRect();
148
+ c.style.transform = `translate(${r.left - (g?.left ?? 0) - parseFloat(c.style.left)}px,${r.top - (g?.top ?? 0) - parseFloat(c.style.top)}px) scale(1)`;
149
+ } else {
150
+ el.style.translate = keep?.translate || "0px 0px";
151
+ el.style.scale = keep?.scale || "1";
152
+ }
153
+ closing = window.setTimeout(() => {
154
+ if (c) {
155
+ el.style.visibility = "";
156
+ c.remove();
157
+ } else if (keep) {
158
+ const st = el.style;
159
+ for (const k of KEEP) st[k] = keep[k] ?? "";
160
+ }
161
+ b.remove();
162
+ }, 330);
163
+ }
164
+ const click = (e) => {
165
+ if (source) {
166
+ e.preventDefault();
167
+ return close();
168
+ }
169
+ const el = zoomable(e.target);
170
+ if (!el || e.button !== 0 || e.metaKey || e.ctrlKey) return;
171
+ e.preventDefault();
172
+ open(el);
173
+ };
174
+ const key = (e) => {
175
+ if (source) {
176
+ if (e.key === "Escape" || e.key === "Enter" || e.key === " ") {
177
+ e.preventDefault();
178
+ close();
179
+ }
180
+ return;
181
+ }
182
+ if (e.key !== "Enter" && e.key !== " ") return;
183
+ const el = zoomable(document.activeElement);
184
+ if (el && el === document.activeElement) {
185
+ e.preventDefault();
186
+ open(el);
187
+ }
188
+ };
189
+ const scroll = () => {
190
+ if (source && Math.abs(scrollY - startScroll) > 40) close();
191
+ };
192
+ document.addEventListener("click", click);
193
+ document.addEventListener("keydown", key);
194
+ addEventListener("scroll", scroll, { passive: true });
195
+ addEventListener("resize", close);
196
+ mark();
197
+ const scan = window.setInterval(() => !source && mark(), 2e3);
198
+ return {
199
+ open,
200
+ close,
201
+ update(next) {
202
+ Object.assign(o, next);
203
+ mark();
204
+ },
205
+ pause() {
206
+ },
207
+ resume() {
208
+ },
209
+ destroy() {
210
+ clearInterval(scan);
211
+ clearTimeout(closing);
212
+ document.removeEventListener("click", click);
213
+ document.removeEventListener("keydown", key);
214
+ removeEventListener("scroll", scroll);
215
+ removeEventListener("resize", close);
216
+ if (source) {
217
+ source.style.visibility = "";
218
+ if (saved) {
219
+ const st = source.style;
220
+ for (const k of KEEP) st[k] = saved[k] ?? "";
221
+ }
222
+ }
223
+ clone?.remove();
224
+ back?.remove();
225
+ source = clone = back = null;
226
+ saved = null;
227
+ for (const el of marked) {
228
+ el.classList.remove("fluri-iz-able");
229
+ if ("fluriIzTab" in el.dataset) {
230
+ el.removeAttribute("tabindex");
231
+ delete el.dataset.fluriIzTab;
232
+ }
233
+ }
234
+ marked = [];
235
+ },
236
+ getState() {
237
+ return { open: !!source };
238
+ }
239
+ };
240
+ }
241
+
242
+ // packages/image-zoom/src/badge.ts
243
+ var SITE = "https://fluri.xyz/themes/";
244
+ var shown = false;
245
+ var CSS2 = `
246
+ :host{all:initial}
247
+ a{position:fixed;z-index:2147483600;display:inline-flex;align-items:center;gap:9px;padding:8px 10px 8px 9px;max-width:calc(100vw - 32px);
248
+ border-radius:999px;background:rgba(22,18,36,.88);-webkit-backdrop-filter:blur(12px) saturate(1.4);backdrop-filter:blur(12px) saturate(1.4);
249
+ border:1px solid rgba(255,255,255,.14);box-shadow:0 10px 30px rgba(10,6,30,.28),0 1px 0 rgba(255,255,255,.08) inset;
250
+ color:#fff;font:600 13px/1.2 ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;letter-spacing:.01em;text-decoration:none;
251
+ opacity:0;transform:translateY(10px) scale(.98);transition:opacity .35s ease,transform .35s cubic-bezier(.2,.8,.2,1),background .2s}
252
+ a.in{opacity:1;transform:none}
253
+ a:hover{background:rgba(32,26,52,.96)}
254
+ a:focus-visible{outline:3px solid #a78bfa;outline-offset:3px}
255
+ .star{flex:none;display:grid;place-items:center;width:22px;height:22px;border-radius:50%;background:conic-gradient(from 210deg,#8b5cf6,#ec4899,#f59e0b,#8b5cf6);box-shadow:0 0 12px rgba(167,139,250,.55)}
256
+ .star svg{width:12px;height:12px;fill:#fff}
257
+ .txt{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
258
+ .txt b{font-weight:700;background:linear-gradient(90deg,#c4b5fd,#fbcfe8);-webkit-background-clip:text;background-clip:text;color:transparent}
259
+ .arrow{flex:none;transition:transform .2s}
260
+ a:hover .arrow{transform:translateX(2px)}
261
+ button{all:unset;flex:none;display:grid;place-items:center;width:20px;height:20px;margin-left:2px;border-radius:50%;color:rgba(255,255,255,.7);font:600 14px/1 system-ui;cursor:pointer}
262
+ button:hover{background:rgba(255,255,255,.14);color:#fff}
263
+ button:focus-visible{outline:2px solid #a78bfa}
264
+ @media (max-width:480px){a{font-size:12px;padding:7px 8px 7px 7px;gap:7px}.star{width:20px;height:20px}}
265
+ @media (prefers-reduced-motion:reduce){a{transition:opacity .2s}a,a.in{transform:none}}
266
+ `;
267
+ var ORDER = ["bottom-left", "bottom-center", "bottom-right", "top-right"];
268
+ function place(a, c) {
269
+ const s = a.style;
270
+ s.top = s.bottom = s.left = s.right = s.transform = "";
271
+ if (c.startsWith("bottom")) s.bottom = "16px";
272
+ else s.top = "16px";
273
+ if (c.endsWith("left")) s.left = "16px";
274
+ else if (c.endsWith("right")) s.right = "16px";
275
+ else {
276
+ s.left = "50%";
277
+ s.marginLeft = -(a.offsetWidth / 2) + "px";
278
+ }
279
+ if (c !== "bottom-center") s.marginLeft = "";
280
+ }
281
+ function taken(host, r) {
282
+ const pts = [
283
+ [r.left + 4, r.top + 4],
284
+ [r.right - 4, r.top + 4],
285
+ [r.left + 4, r.bottom - 4],
286
+ [r.right - 4, r.bottom - 4],
287
+ [r.left + r.width / 2, r.top + r.height / 2]
288
+ ];
289
+ for (const [x, y] of pts) {
290
+ for (const el of document.elementsFromPoint(x, y)) {
291
+ if (el === host || el === document.body || el === document.documentElement) continue;
292
+ for (let e = el; e && e !== document.body; e = e.parentElement) {
293
+ const p = getComputedStyle(e).position;
294
+ if (p === "fixed" || p === "sticky") return true;
295
+ }
296
+ }
297
+ }
298
+ return false;
299
+ }
300
+ function isPreview() {
301
+ try {
302
+ const h = location.hostname;
303
+ if (/(^|\.)fluri\.xyz$/.test(h) || /(^|\.)(codepen\.io|cdpn\.io)$/.test(h)) return true;
304
+ if (navigator.webdriver) return true;
305
+ if (/HeadlessChrome|Playwright|Puppeteer/i.test(navigator.userAgent)) return true;
306
+ } catch {
307
+ }
308
+ return false;
309
+ }
310
+ function showFluriBadge(slug) {
311
+ if (shown || typeof document === "undefined" || typeof window === "undefined") return;
312
+ if (isPreview()) return;
313
+ shown = true;
314
+ const start = () => {
315
+ const host = document.createElement("fluri-badge");
316
+ host.setAttribute("style", "all:initial");
317
+ const root = host.attachShadow({ mode: "open" });
318
+ const style = document.createElement("style");
319
+ style.textContent = CSS2;
320
+ const a = document.createElement("a");
321
+ a.href = SITE + "?utm_source=npm&utm_medium=badge&utm_campaign=" + encodeURIComponent(slug);
322
+ a.target = "_blank";
323
+ a.rel = "noopener";
324
+ a.setAttribute("aria-label", "Unlock all themes on fluri.xyz (opens in a new tab)");
325
+ const star = document.createElement("span");
326
+ star.className = "star";
327
+ star.innerHTML = '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 2l2.4 6.6L21 11l-6.6 2.4L12 20l-2.4-6.6L3 11l6.6-2.4z"/></svg>';
328
+ const txt = document.createElement("span");
329
+ txt.className = "txt";
330
+ txt.append("Unlock all themes on ");
331
+ const b = document.createElement("b");
332
+ b.textContent = "fluri.xyz";
333
+ txt.append(b);
334
+ const arrow = document.createElement("span");
335
+ arrow.className = "arrow";
336
+ arrow.setAttribute("aria-hidden", "true");
337
+ arrow.textContent = "\u2192";
338
+ const close = document.createElement("button");
339
+ close.type = "button";
340
+ close.setAttribute("aria-label", "Hide");
341
+ close.textContent = "\xD7";
342
+ close.addEventListener("click", (e) => {
343
+ e.preventDefault();
344
+ e.stopPropagation();
345
+ a.classList.remove("in");
346
+ setTimeout(() => host.remove(), 350);
347
+ });
348
+ a.append(star, txt, arrow, close);
349
+ root.append(style, a);
350
+ document.body.appendChild(host);
351
+ let corner = ORDER[0];
352
+ for (const c of ORDER) {
353
+ place(a, c);
354
+ if (!taken(host, a.getBoundingClientRect())) {
355
+ corner = c;
356
+ break;
357
+ }
358
+ }
359
+ place(a, corner);
360
+ requestAnimationFrame(() => requestAnimationFrame(() => a.classList.add("in")));
361
+ };
362
+ const later = () => setTimeout(start, 1200);
363
+ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", later, { once: true });
364
+ else later();
365
+ }
366
+
367
+ // packages/image-zoom/src/index.ts
368
+ function createImageZoom2(...args) {
369
+ showFluriBadge("image-zoom");
370
+ return createImageZoom(...args);
371
+ }
372
+ export {
373
+ createImageZoom2 as createImageZoom
374
+ };
@@ -0,0 +1,31 @@
1
+ export interface OverlayOptions {
2
+ root?: HTMLElement | undefined;
3
+ zIndex?: number | undefined;
4
+ maxFPS?: number | undefined;
5
+ }
6
+ export interface Overlay {
7
+ canvas: HTMLCanvasElement;
8
+ ctx: CanvasRenderingContext2D;
9
+ /** CSS pixel size of the drawing area. */
10
+ width: number;
11
+ height: number;
12
+ /** Area origin in viewport coordinates (for converting client points). */
13
+ origin(): {
14
+ x: number;
15
+ y: number;
16
+ };
17
+ start(frame: (dt: number, t: number) => void): void;
18
+ pause(): void;
19
+ resume(): void;
20
+ destroy(): void;
21
+ reduced: boolean;
22
+ }
23
+ export declare function createOverlay(o?: OverlayOptions): Overlay;
24
+ export declare function surfacesIn(selector: string, root?: HTMLElement, limit?: number): HTMLElement[];
25
+ export declare const rand: (a: number, b: number) => number;
26
+ export declare const clamp: (v: number, a: number, b: number) => number;
27
+ /**
28
+ * Moves an overlay canvas behind the content of its host (the root, or the
29
+ * body) by giving the host its own stacking context. Returns an undo function.
30
+ */
31
+ export declare function sendBehind(canvas: HTMLCanvasElement, root?: HTMLElement): () => void;
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@fluritheme/image-zoom",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "Image Zoom: click an image and it grows smoothly from where it sits to fill the screen; click, scroll or Esc and it glides back. Works on the images a page already has, with keyboard support. A tiny medium-zoom alternative, zero dependencies.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": {
8
+ "name": "František Gejdoš",
9
+ "url": "https://fluri.xyz/founder/",
10
+ "email": "fluritheme@gmail.com"
11
+ },
12
+ "homepage": "https://fluri.xyz/image-zoom/",
13
+ "keywords": [
14
+ "image-zoom",
15
+ "zoom",
16
+ "lightbox",
17
+ "medium-zoom",
18
+ "click-to-zoom",
19
+ "image",
20
+ "gallery",
21
+ "photo",
22
+ "product-image",
23
+ "modal",
24
+ "a11y",
25
+ "website-effects",
26
+ "fluri"
27
+ ],
28
+ "sideEffects": false,
29
+ "files": [
30
+ "dist",
31
+ "README.md",
32
+ "LICENSE",
33
+ "CHANGELOG.md"
34
+ ],
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "import": "./dist/index.js"
39
+ },
40
+ "./global": "./dist/image-zoom.global.js",
41
+ "./package.json": "./package.json"
42
+ },
43
+ "main": "./dist/index.js",
44
+ "module": "./dist/index.js",
45
+ "types": "./dist/index.d.ts",
46
+ "unpkg": "./dist/image-zoom.global.js",
47
+ "jsdelivr": "./dist/image-zoom.global.js",
48
+ "publishConfig": {
49
+ "access": "public"
50
+ }
51
+ }