efficient-storefront-blocks 0.129.0 → 0.130.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 +24 -0
- package/dist/index.js +26 -26
- package/dist/render/components/product-hero/SpinLayer.js +1 -1
- package/dist/render/lib/sections/spin-sets.d.ts +19 -1
- package/dist/render/lib/sections/spin-sets.js +1 -1
- package/dist/routine-index.json +1 -1
- package/dist/value-index.json +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as x}from"react/jsx-runtime";import{useCallback as z,useEffect as b,useRef as p,useState as $}from"react";import{VIEW_TABLET_MIN as oe}from"efficient-easel/screen/lib/content/view-tiers";import{cssStringBody as se}from"efficient-web-builder/format/lib/document/style-text";import{HALF_SIZES as L,sizedImage as ae}from"efficient-web-builder/format/lib/sized-image";import{prefersReducedMotion as ce}from"efficient-web-builder/render/components/useReducedMotion";import{isFullTurn as H,spinClampPosition as ie,spinFrameIndex as K,spinPositionAfterDrag as U,spinCell as j,spinStartPosition as T}from"../../lib/sections/spin-sets.js";const le=.3,ue=.85,B=24,G=4,q=1e3,Z=77/72,Q=`${(1-Z)/2*100}%`,V=`${Z*100}%`,Y={left:Q,top:Q,width:V,height:V},de=`(max-width: ${oe-.02}px)`,R=new Map;function J(n,E){let f=R.get(n);return f||(f=new Promise(k=>{const o=new Image;o.onload=()=>k({w:o.naturalWidth,h:o.naturalHeight}),o.onerror=()=>{R.delete(n),k(null)},E&&(o.sizes=L,o.srcset=E),o.src=n}),R.set(n,f)),f}const ee=new Set,W=n=>ae(n,{fallbackWidth:q,maxWidth:q});function fe({set:n,name:E}){const[f,k]=$(()=>T(n)),o=p(null),F=p(0),P=p(f),v=p(null),w=p(null),r=n.count,[M,C]=$(null),I=p(null),[D,X]=$(null),_=H(n),g=K(f,r,_),y=z(e=>{const t=ie(e,r,_);return P.current=t,k(t),t},[r,_]),A=z(()=>cancelAnimationFrame(F.current),[]);b(()=>{const e=window.matchMedia?.(de);if(!e)return X(!1);const t=()=>X(e.matches);return t(),e.addEventListener?.("change",t),()=>e.removeEventListener?.("change",t)},[]),b(()=>{if(!n.sheets||!n.startFrame||D===null)return;const e=D?n.sheets.phone:n.sheets.desktop,t=`${n.startFrame} ${e.urls[0]}`;if(w.current===t)return;w.current=t,C({key:t,sheet:e,ready:new Set});const c=Math.floor(T(n)/(e.cols*e.rows)),l=e.urls.map((h,d)=>e.urls[(c+d)%e.urls.length]),u=W(n.startFrame);J(u.src,u.srcSet).then(()=>{for(const h of l)J(h).then(d=>{!d||d.w!==e.cols*e.frame||d.h!==e.rows*e.frame||w.current===t&&C(i=>i?.key===t?{...i,ready:new Set(i.ready).add(h)}:i)})})},[n,D]),b(()=>{if(!n.frames)return;const e=n.frames,t=e[0];if(w.current===t||(w.current=t,ee.has(t)))return;ee.add(t);const c=K(T(n),r,H(n)),l=[];for(let i=0;i<G;i+=1)for(let m=i;m<r;m+=G)l.push((c+m)%r);const u=i=>{const m=W(e[i]),S=new Image;return S.sizes=L,m.srcSet&&(S.srcset=m.srcSet),S.src=m.src,S},h=u(l[0]),d=()=>l.slice(1).forEach(u);h.onload=d,h.onerror=d},[r,n]),b(()=>A,[A]);const te=e=>{A(),e.currentTarget.setPointerCapture?.(e.pointerId),v.current={x0:e.clientX,f0:P.current,last:e.clientX,speed:0}},ne=e=>{const t=v.current,c=o.current;!t||!c||(t.speed=e.clientX-t.last,t.last=e.clientX,y(U(t.f0,e.clientX-t.x0,c.clientWidth,r)))},N=()=>{const e=v.current;v.current=null;const t=o.current;if(!e||!t||ce())return;let c=Math.max(-B,Math.min(B,e.speed));const l=()=>{if(Math.abs(c)<le)return;const u=U(P.current,c,t.clientWidth,r);y(u)===u&&(c*=ue,F.current=requestAnimationFrame(l))};F.current=requestAnimationFrame(l)},re=e=>{const t=e.key==="ArrowRight"||e.key==="ArrowUp"?1:e.key==="ArrowLeft"||e.key==="ArrowDown"?-1:0;if(e.key==="Home")y(0);else if(e.key==="End")y(r-1);else if(t)y(Math.round(P.current)+t);else return;A(),e.preventDefault()},s=n.sheets&&M&&M.key.startsWith(`${n.startFrame} `)?M:null;s&&s.ready.has(j(s.sheet,g).url)&&(I.current={key:s.key,frame:g});const O=s&&I.current?.key===s.key?I.current.frame:null,a=s&&O!==null?{...j(s.sheet,O),cols:s.sheet.cols,rows:s.sheet.rows}:null;return x("div",{ref:o,"data-spin-well":!0,role:"slider",tabIndex:0,"aria-label":`${E}, 360° view: drag or use the arrow keys to turn`,"aria-valuemin":1,"aria-valuemax":r,"aria-valuenow":g+1,"aria-valuetext":`Angle ${g+1} of ${r}`,onKeyDown:re,className:"absolute inset-0 select-none overflow-hidden cursor-grab active:cursor-grabbing focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-fg",style:{touchAction:"pan-y"},onPointerDown:te,onPointerMove:ne,onPointerUp:N,onPointerCancel:N,onTouchStart:e=>e.stopPropagation(),onTouchMove:e=>e.stopPropagation(),onTouchEnd:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:a?x("div",{"data-spin-frame":!0,className:"pointer-events-none absolute",style:{...Y,backgroundImage:`url("${se(a.url)}")`,backgroundSize:`${a.cols*100}% ${a.rows*100}%`,backgroundPosition:`${a.cols>1?a.col*100/(a.cols-1):0}% ${a.rows>1?a.row*100/(a.rows-1):0}%`}}):x("img",{...W(n.frames?n.frames[g]:n.startFrame??""),sizes:L,alt:"",draggable:!1,fetchPriority:"high","data-spin-frame":!0,className:"pointer-events-none absolute max-w-none object-contain",style:Y})})}export{fe as default};
|
|
@@ -1,5 +1,18 @@
|
|
|
1
|
+
export interface SpinSheet {
|
|
2
|
+
frame: number;
|
|
3
|
+
cols: number;
|
|
4
|
+
rows: number;
|
|
5
|
+
urls: string[];
|
|
6
|
+
}
|
|
7
|
+
export declare const SPIN_SHEET_MAX_SIDE = 4096;
|
|
1
8
|
export interface SpinSet {
|
|
2
|
-
|
|
9
|
+
count: number;
|
|
10
|
+
frames?: string[];
|
|
11
|
+
startFrame?: string;
|
|
12
|
+
sheets?: {
|
|
13
|
+
desktop: SpinSheet;
|
|
14
|
+
phone: SpinSheet;
|
|
15
|
+
};
|
|
3
16
|
arc?: number;
|
|
4
17
|
start?: number;
|
|
5
18
|
}
|
|
@@ -11,3 +24,8 @@ export declare function spinStartPosition(set: SpinSet): number;
|
|
|
11
24
|
export declare function spinFrameIndex(position: number, count: number, loop?: boolean): number;
|
|
12
25
|
export declare function spinClampPosition(position: number, count: number, loop: boolean): number;
|
|
13
26
|
export declare function spinPositionAfterDrag(start: number, dx: number, width: number, count: number): number;
|
|
27
|
+
export declare function spinCell(sheet: SpinSheet, i: number): {
|
|
28
|
+
url: string;
|
|
29
|
+
col: number;
|
|
30
|
+
row: number;
|
|
31
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const l=360,y=.9,
|
|
1
|
+
import{resolveMedia as h}from"efficient-web-builder/render/lib/media";const l=4096,a=360,y=.9,p=t=>Array.isArray(t)&&t.length>0&&t.every(r=>typeof r=="string"&&r.length>0),c=t=>h(t)??t,f=t=>Number.isInteger(t)&&t>0;function m(t,r){if(!t||typeof t!="object")return null;const{frame:n,cols:e,rows:o,urls:s}=t;return!f(n)||!f(e)||!f(o)||!p(s)||n*e>l||n*o>l||s.length!==Math.ceil(r/(e*o))?null:{frame:n,cols:e,rows:o,urls:s.map(c)}}function x(t){const{frames:r,count:n,startFrame:e,sheets:o}=t,s=p(r)?{count:r.length,frames:r.map(c)}:null;if(o&&typeof o=="object"&&f(n)&&typeof e=="string"&&e){const u=m(o.desktop,n),i=m(o.phone,n);if(u&&i)return{count:n,startFrame:c(e),sheets:{desktop:u,phone:i}}}return s}function M(t){if(!t||typeof t!="object")return null;const{arc:r,start:n}=t,e=x(t);if(!e)return null;if(r!==void 0){if(typeof r!="number"||!(r>0&&r<=a))return null;e.arc=r}return Number.isInteger(n)&&n>=0&&n<e.count&&(e.start=n),e}function S(t){if(!t||typeof t!="object"||Array.isArray(t))return{};const r={};for(const[n,e]of Object.entries(t)){if(!e||typeof e!="object"||Array.isArray(e))continue;const o={};for(const[s,u]of Object.entries(e)){const i=M(u);i&&(o[s]=i)}Object.keys(o).length>0&&(r[n]=o)}return r}function j(t,r,n){return n?t[r]?.[n]??null:null}function b(t){return t.arc===void 0||t.arc>=a}function g(t){return b(t)?0:Math.floor(t.count/2)}function A(t){return t.start??g(t)}function F(t,r,n=!0){return n?(Math.floor(t)%r+r)%r:Math.max(0,Math.min(r-1,Math.floor(t)))}function P(t,r,n){return n?t:Math.max(0,Math.min(r-1,t))}function T(t,r,n,e){return n<=0?t:t-r/n*e*y}function _(t,r){const n=t.cols*t.rows,e=r%n;return{url:t.urls[Math.floor(r/n)],col:e%t.cols,row:Math.floor(e/t.cols)}}export{l as SPIN_SHEET_MAX_SIDE,b as isFullTurn,S as parseSpinSets,_ as spinCell,P as spinClampPosition,F as spinFrameIndex,T as spinPositionAfterDrag,j as spinSetFor,A as spinStartPosition};
|