react-img-cutout 1.1.0 → 1.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.
- package/dist/components/cutout-viewer/cutouts/image/alpha-contour.d.ts +27 -0
- package/dist/components/cutout-viewer/cutouts/image/image-hit-test-strategy.d.ts +1 -0
- package/dist/components/cutout-viewer/hit-test-strategy.d.ts +2 -0
- package/dist/components/cutout-viewer/hover-effects.d.ts +3 -2
- package/dist/components/cutout-viewer/use-cutout-hit-test.d.ts +1 -0
- package/dist/components/cutout-viewer/viewer-context.d.ts +1 -0
- package/dist/index.cjs +6 -10
- package/dist/index.js +726 -629
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contour-tracing utilities for extracting polygon outlines from alpha data.
|
|
3
|
+
*
|
|
4
|
+
* Used by the trace effect to render image cutouts with the same SVG
|
|
5
|
+
* stroke-dasharray animation that geometric shapes use.
|
|
6
|
+
*
|
|
7
|
+
* Pipeline:
|
|
8
|
+
* 1. Downscale alpha buffer to a working resolution for performance
|
|
9
|
+
* 2. Build binary grid from alpha threshold
|
|
10
|
+
* 3. Trace the outer boundary using Moore-Neighbor contour tracing
|
|
11
|
+
* 4. Simplify with Ramer–Douglas–Peucker
|
|
12
|
+
* 5. Return normalized [0-1] coordinate pairs
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Extract a simplified polygon contour from a pre-computed alpha buffer.
|
|
16
|
+
*
|
|
17
|
+
* Accepts the alpha data already extracted by the hit-test strategy,
|
|
18
|
+
* avoiding a redundant image load.
|
|
19
|
+
*
|
|
20
|
+
* @param alpha Compact alpha buffer (one byte per pixel)
|
|
21
|
+
* @param srcW Source image width in pixels
|
|
22
|
+
* @param srcH Source image height in pixels
|
|
23
|
+
* @param alphaThreshold Minimum alpha value (0-255) to consider opaque
|
|
24
|
+
* @param epsilon RDP simplification tolerance in normalized coords
|
|
25
|
+
* (default: 0.003 — roughly 0.3 % of image size)
|
|
26
|
+
*/
|
|
27
|
+
export declare function traceContour(alpha: Uint8Array, srcW: number, srcH: number, alphaThreshold?: number, epsilon?: number): [number, number][];
|
|
@@ -17,6 +17,7 @@ import type { CutoutBounds, HitTestStrategy, ImageCutoutDefinition } from "../..
|
|
|
17
17
|
export declare class ImageHitTestStrategy implements HitTestStrategy {
|
|
18
18
|
id: string;
|
|
19
19
|
bounds: CutoutBounds;
|
|
20
|
+
contour: [number, number][];
|
|
20
21
|
/** URL of the cutout mask image */
|
|
21
22
|
private src;
|
|
22
23
|
/** Alpha value (0-255) a pixel must exceed to be considered "visible" */
|
|
@@ -44,6 +44,8 @@ export interface HitTestStrategy {
|
|
|
44
44
|
hitTest(nx: number, ny: number): boolean;
|
|
45
45
|
/** Pre-computed bounding box (normalized 0-1) */
|
|
46
46
|
bounds: CutoutBounds;
|
|
47
|
+
/** Pre-computed contour polygon (normalized 0-1), if available */
|
|
48
|
+
contour?: [number, number][];
|
|
47
49
|
/** Optional async setup (e.g., image loading) */
|
|
48
50
|
prepare?(): Promise<void>;
|
|
49
51
|
/** Cleanup */
|
|
@@ -166,8 +166,9 @@ export declare const liftEffect: HoverEffect;
|
|
|
166
166
|
export declare const subtleEffect: HoverEffect;
|
|
167
167
|
/**
|
|
168
168
|
* Trace effect — a short white dash endlessly travels around the cutout
|
|
169
|
-
* border, tracing its outline. For image-based cutouts
|
|
170
|
-
*
|
|
169
|
+
* border, tracing its outline. For image-based cutouts, the alpha channel
|
|
170
|
+
* is converted to a polygon outline and rendered with the same SVG
|
|
171
|
+
* stroke-dasharray animation used on geometric shapes.
|
|
171
172
|
*/
|
|
172
173
|
export declare const traceEffect: HoverEffect;
|
|
173
174
|
/**
|
|
@@ -20,6 +20,7 @@ export declare function useCutoutHitTest(definitions: CutoutDefinition[], enable
|
|
|
20
20
|
selectedId: string | null;
|
|
21
21
|
activeId: string | null;
|
|
22
22
|
boundsMap: Record<string, CutoutBounds>;
|
|
23
|
+
contourMap: Record<string, [number, number][]>;
|
|
23
24
|
containerRef: import("react").RefObject<HTMLDivElement | null>;
|
|
24
25
|
containerProps: {
|
|
25
26
|
onPointerMove: (e: React.PointerEvent<HTMLDivElement>) => void;
|
|
@@ -13,6 +13,7 @@ export interface CutoutViewerContextValue {
|
|
|
13
13
|
enabled: boolean;
|
|
14
14
|
showAll: boolean;
|
|
15
15
|
boundsMap: Record<string, CutoutBounds>;
|
|
16
|
+
contourMap: Record<string, [number, number][]>;
|
|
16
17
|
isAnyActive: boolean;
|
|
17
18
|
}
|
|
18
19
|
export declare const CutoutViewerContext: import("react").Context<CutoutViewerContextValue | null>;
|
package/dist/index.cjs
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");var Z={exports:{}},X={};var st;function Tt(){if(st)return X;st=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(r,i,l){var a=null;if(l!==void 0&&(a=""+l),i.key!==void 0&&(a=""+i.key),"key"in i){l={};for(var s in i)s!=="key"&&(l[s]=i[s])}else l=i;return i=l.ref,{$$typeof:t,type:r,key:a,ref:i!==void 0?i:null,props:l}}return X.Fragment=e,X.jsx=n,X.jsxs=n,X}var q={};var it;function jt(){return it||(it=1,process.env.NODE_ENV!=="production"&&(function(){function t(o){if(o==null)return null;if(typeof o=="function")return o.$$typeof===L?null:o.displayName||o.name||null;if(typeof o=="string")return o;switch(o){case d:return"Fragment";case g:return"Profiler";case v:return"StrictMode";case $:return"Suspense";case W:return"SuspenseList";case z:return"Activity"}if(typeof o=="object")switch(typeof o.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),o.$$typeof){case x:return"Portal";case k:return o.displayName||"Context";case C:return(o._context.displayName||"Context")+".Consumer";case w:var b=o.render;return o=o.displayName,o||(o=b.displayName||b.name||"",o=o!==""?"ForwardRef("+o+")":"ForwardRef"),o;case V:return b=o.displayName||null,b!==null?b:t(o.type)||"Memo";case Y:b=o._payload,o=o._init;try{return t(o(b))}catch{}}return null}function e(o){return""+o}function n(o){try{e(o);var b=!1}catch{b=!0}if(b){b=console;var A=b.error,j=typeof Symbol=="function"&&Symbol.toStringTag&&o[Symbol.toStringTag]||o.constructor.name||"Object";return A.call(b,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",j),e(o)}}function r(o){if(o===d)return"<>";if(typeof o=="object"&&o!==null&&o.$$typeof===Y)return"<...>";try{var b=t(o);return b?"<"+b+">":"<...>"}catch{return"<...>"}}function i(){var o=T.A;return o===null?null:o.getOwner()}function l(){return Error("react-stack-top-frame")}function a(o){if(S.call(o,"key")){var b=Object.getOwnPropertyDescriptor(o,"key").get;if(b&&b.isReactWarning)return!1}return o.key!==void 0}function s(o,b){function A(){M||(M=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",b))}A.isReactWarning=!0,Object.defineProperty(o,"key",{get:A,configurable:!0})}function f(){var o=t(this.type);return O[o]||(O[o]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),o=this.props.ref,o!==void 0?o:null}function c(o,b,A,j,K,tt){var P=A.ref;return o={$$typeof:m,type:o,key:b,props:A,_owner:j},(P!==void 0?P:null)!==null?Object.defineProperty(o,"ref",{enumerable:!1,get:f}):Object.defineProperty(o,"ref",{enumerable:!1,value:null}),o._store={},Object.defineProperty(o._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(o,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(o,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:K}),Object.defineProperty(o,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:tt}),Object.freeze&&(Object.freeze(o.props),Object.freeze(o)),o}function h(o,b,A,j,K,tt){var P=b.children;if(P!==void 0)if(j)if(R(P)){for(j=0;j<P.length;j++)E(P[j]);Object.freeze&&Object.freeze(P)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else E(P);if(S.call(b,"key")){P=t(o);var H=Object.keys(b).filter(function(_t){return _t!=="key"});j=0<H.length?"{key: someKey, "+H.join(": ..., ")+": ...}":"{key: someKey}",ot[P+j]||(H=0<H.length?"{"+H.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
2
|
let props = %s;
|
|
3
3
|
<%s {...props} />
|
|
4
4
|
React keys must be passed directly to JSX without using spread:
|
|
5
5
|
let props = %s;
|
|
6
|
-
<%s key={someKey} {...props} />`,j,P,
|
|
7
|
-
${
|
|
8
|
-
}`,document.head.appendChild(
|
|
9
|
-
to { stroke-dashoffset: -1; }`),
|
|
10
|
-
25% { filter: drop-shadow(3px -3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15)); }
|
|
11
|
-
50% { filter: drop-shadow(3px 3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15)); }
|
|
12
|
-
75% { filter: drop-shadow(-3px 3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15)); }
|
|
13
|
-
100% { filter: drop-shadow(-3px -3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15)); }`),Et={name:"trace",transition:X,keyframes:[lt,ut],mainImageHovered:{filter:"brightness(0.35) saturate(0.5)"},vignetteStyle:{background:"radial-gradient(ellipse at center, transparent 20%, rgba(0,0,0,0.5) 100%)"},cutoutActive:{transform:"scale(1)",filter:"drop-shadow(-3px -3px 6px rgba(255,255,255,0.6)) drop-shadow(0 0 2px rgba(255,255,255,0.15))",opacity:1,animation:`${ut.name} 3s linear infinite`},cutoutInactive:{transform:"scale(1)",filter:"brightness(0.35) saturate(0.4)",opacity:.4},cutoutIdle:{transform:"scale(1)",filter:"none",opacity:1},geometryActive:{fill:"rgba(255, 255, 255, 0.03)",stroke:"rgba(255, 255, 255, 0.9)",strokeWidth:2.5,strokeDasharray:"0.15 0.85",animation:`${lt.name} 3s linear infinite`,glow:"0 0 10px rgba(255, 255, 255, 0.25)"},geometryInactive:{fill:"transparent",stroke:"rgba(255, 255, 255, 0.15)",strokeWidth:1},geometryIdle:{fill:"transparent",stroke:"transparent",strokeWidth:1}},ct=Z("_ricut-shimmer",`0%, 100% {
|
|
6
|
+
<%s key={someKey} {...props} />`,j,P,H,P),ot[P+j]=!0)}if(P=null,A!==void 0&&(n(A),P=""+A),a(b)&&(n(b.key),P=""+b.key),"key"in b){A={};for(var et in b)et!=="key"&&(A[et]=b[et])}else A=b;return P&&s(A,typeof o=="function"?o.displayName||o.name||"Unknown":o),c(o,P,A,i(),K,tt)}function E(o){y(o)?o._store&&(o._store.validated=1):typeof o=="object"&&o!==null&&o.$$typeof===Y&&(o._payload.status==="fulfilled"?y(o._payload.value)&&o._payload.value._store&&(o._payload.value._store.validated=1):o._store&&(o._store.validated=1))}function y(o){return typeof o=="object"&&o!==null&&o.$$typeof===m}var p=u,m=Symbol.for("react.transitional.element"),x=Symbol.for("react.portal"),d=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),g=Symbol.for("react.profiler"),C=Symbol.for("react.consumer"),k=Symbol.for("react.context"),w=Symbol.for("react.forward_ref"),$=Symbol.for("react.suspense"),W=Symbol.for("react.suspense_list"),V=Symbol.for("react.memo"),Y=Symbol.for("react.lazy"),z=Symbol.for("react.activity"),L=Symbol.for("react.client.reference"),T=p.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,S=Object.prototype.hasOwnProperty,R=Array.isArray,_=console.createTask?console.createTask:function(){return null};p={react_stack_bottom_frame:function(o){return o()}};var M,O={},N=p.react_stack_bottom_frame.bind(p,l)(),D=_(r(l)),ot={};q.Fragment=d,q.jsx=function(o,b,A){var j=1e4>T.recentlyCreatedOwnerStacks++;return h(o,b,A,!1,j?Error("react-stack-top-frame"):N,j?_(r(o)):D)},q.jsxs=function(o,b,A){var j=1e4>T.recentlyCreatedOwnerStacks++;return h(o,b,A,!0,j?Error("react-stack-top-frame"):N,j?_(r(o)):D)}})()),q}var at;function Pt(){return at||(at=1,process.env.NODE_ENV==="production"?Z.exports=Tt():Z.exports=jt()),Z.exports}var I=Pt();const Mt=200;function $t(t,e,n){const r=n[0]-e[0],i=n[1]-e[1],l=r*r+i*i;if(l===0){const s=t[0]-e[0],f=t[1]-e[1];return Math.sqrt(s*s+f*f)}return Math.abs(r*(e[1]-t[1])-i*(e[0]-t[0]))/Math.sqrt(l)}function rt(t,e){if(t.length<=2)return t;let n=0,r=0;const i=t[0],l=t[t.length-1];for(let a=1;a<t.length-1;a++){const s=$t(t[a],i,l);s>n&&(n=s,r=a)}if(n>e){const a=rt(t.slice(0,r+1),e),s=rt(t.slice(r),e);return a.slice(0,-1).concat(s)}return[i,l]}function Dt(t,e,n){let r=-1,i=-1;t:for(let p=0;p<n;p++)for(let m=0;m<e;m++)if(t[p*e+m]){r=m,i=p;break t}if(r<0)return[];const l=[1,1,0,-1,-1,-1,0,1],a=[0,1,1,1,0,-1,-1,-1],s=[];let f=r,c=i,h=5;const E=e*n*4;let y=0;do{s.push([f,c]);let p=!1;for(let m=0;m<8;m++){const x=(h+m)%8,d=f+l[x],v=c+a[x];if(d>=0&&d<e&&v>=0&&v<n&&t[v*e+d]){f=d,c=v,h=((x+4)%8+1)%8,p=!0;break}}if(!p||++y>E)break}while(f!==r||c!==i);return s}function Ot(t,e,n,r=30,i=.003){if(e<=0||n<=0||t.length===0)return[];const l=Math.min(1,Mt/Math.max(e,n)),a=Math.max(1,Math.round(e*l)),s=Math.max(1,Math.round(n*l)),f=new Uint8Array(a*s);for(let y=0;y<s;y++){const p=Math.min(n-1,Math.floor(y/l));for(let m=0;m<a;m++){const x=Math.min(e-1,Math.floor(m/l));f[y*a+m]=t[p*e+x]>r?1:0}}const c=Dt(f,a,s);if(c.length<3)return[];const h=c.map(([y,p])=>[(y+.5)/a,(p+.5)/s]),E=rt(h,i);return E.length>=3?E:h}function Wt(t,e){const n=new Uint8Array(e);for(let r=0;r<e;r++)n[r]=t[r*4+3];return n}function Nt(t,e,n,r){if(e<=0||n<=0)return{x:0,y:0,w:1,h:1};let i=e,l=n,a=0,s=0,f=!1;for(let c=0;c<n;c++)for(let h=0;h<e;h++)t[c*e+h]>r&&(h<i&&(i=h),h>a&&(a=h),c<l&&(l=c),c>s&&(s=c),f=!0);return f?{x:i/e,y:l/n,w:(a-i+1)/e,h:(s-l+1)/n}:{x:0,y:0,w:1,h:1}}class gt{id;bounds={x:0,y:0,w:1,h:1};contour=[];src;threshold;alpha=new Uint8Array(0);width=0;height=0;constructor(e,n){this.id=e.id,this.src=e.src,this.threshold=n}async prepare(){const e=new Image;e.crossOrigin="anonymous",e.src=this.src,await new Promise(a=>{e.onload=()=>a(),e.onerror=()=>a()});const n=e.naturalWidth,r=e.naturalHeight;if(n<=0||r<=0)return;const i=document.createElement("canvas");i.width=n,i.height=r;const l=i.getContext("2d",{willReadFrequently:!0});if(l)try{l.drawImage(e,0,0);const a=l.getImageData(0,0,n,r);this.alpha=Wt(a.data,n*r),this.width=n,this.height=r,this.bounds=Nt(this.alpha,n,r,this.threshold),this.contour=Ot(this.alpha,n,r,this.threshold)}catch{this.alpha=new Uint8Array(0)}}hitTest(e,n){if(this.alpha.length===0)return!1;const r=this.bounds;if(e<r.x||e>r.x+r.w||n<r.y||n>r.y+r.h)return!1;const i=Math.min(this.width-1,Math.max(0,Math.floor(e*this.width))),l=Math.min(this.height-1,Math.max(0,Math.floor(n*this.height)));return this.alpha[l*this.width+i]>this.threshold}}class pt{id;bounds;constructor(e){this.id=e.id,this.bounds={...e.bounds}}hitTest(e,n){const r=this.bounds;return e>=r.x&&e<=r.x+r.w&&n>=r.y&&n<=r.y+r.h}}function Yt(t,e,n){let r=!1;for(let i=0,l=n.length-1;i<n.length;l=i++){const a=n[i][0],s=n[i][1],f=n[l][0],c=n[l][1];s>e!=c>e&&t<(f-a)*(e-s)/(c-s)+a&&(r=!r)}return r}class yt{id;bounds;points;constructor(e){this.id=e.id,this.points=e.points;let n=1/0,r=1/0,i=-1/0,l=-1/0;for(const[a,s]of e.points)a<n&&(n=a),a>i&&(i=a),s<r&&(r=s),s>l&&(l=s);this.bounds={x:n,y:r,w:i-n,h:l-r}}hitTest(e,n){const r=this.bounds;return e<r.x||e>r.x+r.w||n<r.y||n>r.y+r.h?!1:Yt(e,n,this.points)}}function mt(t,e){switch(t.type){case"image":return new gt(t,e);case"bbox":return new pt(t);case"polygon":return new yt(t)}}function Vt(t){switch(t.type){case"image":return`${t.id}:image:${t.src}:${t.label??""}`;case"bbox":return`${t.id}:bbox:${t.bounds.x},${t.bounds.y},${t.bounds.w},${t.bounds.h}:${t.label??""}`;case"polygon":return`${t.id}:polygon:${t.points.flat().join(",")}:${t.label??""}`}}function bt(t,e=!0,n=30,r=150){const[i,l]=u.useState(null),[a,s]=u.useState(null),f=u.useRef(null),c=u.useRef([]),[h,E]=u.useState({}),[y,p]=u.useState({}),m=Math.min(255,Math.max(0,n)),x=u.useRef(null),d=u.useCallback(()=>{x.current===null&&(x.current=setTimeout(()=>{x.current=null,l(null)},r))},[r]),v=u.useCallback(()=>{x.current!==null&&(clearTimeout(x.current),x.current=null)},[]),g=t.map(Vt).join("|"),C=u.useMemo(()=>t,[g]);u.useEffect(()=>{if(!e){c.current=[];return}let T=!1,S=[];async function R(){const _=[],M={},O={};for(const N of C){const D=mt(N,m);if(D.prepare&&await D.prepare(),T)return;_.push(D),M[D.id]=D.bounds,D.contour&&D.contour.length>=3&&(O[D.id]=D.contour)}T||(S=_,c.current=_,E(M),p(O))}return R(),()=>{T=!0;for(const _ of S)_.dispose?.()}},[C,e,m]);const k=u.useCallback((T,S)=>{const R=c.current;for(let _=R.length-1;_>=0;_--)if(R[_].hitTest(T,S))return R[_].id;return null},[]),w=u.useCallback(T=>{const S=f.current;if(!S)return null;const R=S.getBoundingClientRect(),_=(T.clientX-R.left)/R.width,M=(T.clientY-R.top)/R.height;return _<0||_>1||M<0||M>1?null:{nx:_,ny:M}},[]),$=u.useCallback(T=>{if(!e)return;const S=w(T);if(!S){d();return}const R=k(S.nx,S.ny);if(R===null){if(T.target?.closest('[data-cutout-overlay="true"]')){v();return}d();return}v(),l(R)},[e,w,k,d,v]),W=u.useCallback(()=>{d()},[d]),V=u.useCallback(T=>{if(!e)return;const S=w(T);if(!S){s(null);return}const R=k(S.nx,S.ny);s(R===a||R===null?null:R)},[e,w,k,a]),Y=a??i,z=e?h:{},L=e?y:{};return u.useEffect(()=>()=>{v()},[v]),{hoveredId:i,selectedId:a,activeId:Y,boundsMap:z,contourMap:L,containerRef:f,containerProps:{onPointerMove:$,onPointerLeave:W,onClick:V}}}function nt(t,e){return{name:t,css:e}}const lt=new Set;function Lt(t){if(!(!t.keyframes?.length||typeof document>"u"))for(const e of t.keyframes){if(lt.has(e.name))continue;lt.add(e.name);const n=document.createElement("style");n.setAttribute("data-ricut-kf",e.name),n.textContent=`@keyframes ${e.name} {
|
|
7
|
+
${e.css}
|
|
8
|
+
}`,document.head.appendChild(n)}}const U="all 0.5s cubic-bezier(0.22, 1, 0.36, 1)",vt={name:"elevate",transition:U,mainImageHovered:{filter:"brightness(0.45) saturate(0.7)"},vignetteStyle:{background:"radial-gradient(ellipse at center, transparent 20%, rgba(0,0,0,0.4) 100%)"},cutoutActive:{transform:"scale(1.04) translateY(-6px)",filter:"drop-shadow(0 0 28px rgba(130, 190, 255, 0.5)) drop-shadow(0 16px 48px rgba(0, 0, 0, 0.55))",opacity:1},cutoutInactive:{transform:"scale(1)",filter:"brightness(0.45) saturate(0.6)",opacity:.55},cutoutIdle:{transform:"scale(1)",filter:"drop-shadow(0 1px 4px rgba(0, 0, 0, 0.12))",opacity:1},geometryActive:{fill:"rgba(130, 190, 255, 0.2)",stroke:"rgba(130, 190, 255, 0.9)",strokeWidth:2,glow:"0 0 24px rgba(130, 190, 255, 0.5), 0 0 56px rgba(130, 190, 255, 0.2), 0 12px 40px rgba(0, 0, 0, 0.4)"},geometryInactive:{fill:"rgba(100, 150, 200, 0.06)",stroke:"rgba(100, 150, 200, 0.2)",strokeWidth:1},geometryIdle:{fill:"transparent",stroke:"transparent",strokeWidth:1}},xt={name:"glow",transition:U,mainImageHovered:{filter:"brightness(0.55) saturate(0.8)"},vignetteStyle:{background:"radial-gradient(ellipse at center, transparent 30%, rgba(0,0,0,0.3) 100%)"},cutoutActive:{transform:"scale(1)",filter:"drop-shadow(0 0 20px rgba(255, 200, 100, 0.6)) drop-shadow(0 0 60px rgba(255, 200, 100, 0.25))",opacity:1},cutoutInactive:{transform:"scale(1)",filter:"brightness(0.5) saturate(0.5)",opacity:.5},cutoutIdle:{transform:"scale(1)",filter:"none",opacity:1},geometryActive:{fill:"rgba(255, 200, 100, 0.15)",stroke:"rgba(255, 200, 100, 0.85)",strokeWidth:2,glow:"0 0 20px rgba(255, 200, 100, 0.5), 0 0 56px rgba(255, 200, 100, 0.2)"},geometryInactive:{fill:"rgba(200, 160, 80, 0.05)",stroke:"rgba(200, 160, 80, 0.2)",strokeWidth:1},geometryIdle:{fill:"transparent",stroke:"transparent",strokeWidth:1}},wt={name:"lift",transition:U,mainImageHovered:{filter:"brightness(0.4)"},vignetteStyle:{background:"rgba(0,0,0,0.25)"},cutoutActive:{transform:"scale(1.06) translateY(-10px)",filter:"drop-shadow(0 24px 64px rgba(0, 0, 0, 0.7))",opacity:1},cutoutInactive:{transform:"scale(0.97)",filter:"brightness(0.35)",opacity:.4},cutoutIdle:{transform:"scale(1)",filter:"none",opacity:1},geometryActive:{fill:"rgba(255, 255, 255, 0.1)",stroke:"rgba(255, 255, 255, 0.7)",strokeWidth:2,glow:"0 20px 56px rgba(0, 0, 0, 0.6), 0 0 16px rgba(255, 255, 255, 0.1)"},geometryInactive:{fill:"rgba(255, 255, 255, 0.02)",stroke:"rgba(255, 255, 255, 0.1)",strokeWidth:1},geometryIdle:{fill:"transparent",stroke:"transparent",strokeWidth:1}},kt={name:"subtle",transition:"all 0.3s ease",mainImageHovered:{filter:"brightness(0.7)"},vignetteStyle:{background:"transparent"},cutoutActive:{transform:"scale(1)",filter:"none",opacity:1},cutoutInactive:{transform:"scale(1)",filter:"none",opacity:.35},cutoutIdle:{transform:"scale(1)",filter:"none",opacity:1},geometryActive:{fill:"rgba(255, 255, 255, 0.08)",stroke:"rgba(255, 255, 255, 0.5)",strokeWidth:1},geometryInactive:{fill:"transparent",stroke:"rgba(255, 255, 255, 0.1)",strokeWidth:1},geometryIdle:{fill:"transparent",stroke:"transparent",strokeWidth:1}},ct=nt("_ricut-trace-stroke",`from { stroke-dashoffset: 0; }
|
|
9
|
+
to { stroke-dashoffset: -1; }`),Et={name:"trace",transition:U,keyframes:[ct],mainImageHovered:{filter:"brightness(0.35) saturate(0.5)"},vignetteStyle:{background:"radial-gradient(ellipse at center, transparent 20%, rgba(0,0,0,0.5) 100%)"},cutoutActive:{transform:"scale(1)",filter:"drop-shadow(0 0 8px rgba(255,255,255,0.15))",opacity:1},cutoutInactive:{transform:"scale(1)",filter:"brightness(0.35) saturate(0.4)",opacity:.4},cutoutIdle:{transform:"scale(1)",filter:"none",opacity:1},geometryActive:{fill:"rgba(255, 255, 255, 0.03)",stroke:"rgba(255, 255, 255, 0.9)",strokeWidth:2.5,strokeDasharray:"0.15 0.85",animation:`${ct.name} 3s linear infinite`,glow:"0 0 10px rgba(255, 255, 255, 0.25)"},geometryInactive:{fill:"transparent",stroke:"rgba(255, 255, 255, 0.15)",strokeWidth:1},geometryIdle:{fill:"transparent",stroke:"transparent",strokeWidth:1}},ut=nt("_ricut-shimmer",`0%, 100% {
|
|
14
10
|
filter: brightness(1.05) contrast(1.02)
|
|
15
11
|
drop-shadow(0 0 6px rgba(255, 255, 255, 0.12))
|
|
16
12
|
drop-shadow(0 12px 32px rgba(0, 0, 0, 0.4));
|
|
@@ -24,4 +20,4 @@ ${r.css}
|
|
|
24
20
|
filter: brightness(1.05) contrast(1.02)
|
|
25
21
|
drop-shadow(0 0 6px rgba(255, 255, 255, 0.12))
|
|
26
22
|
drop-shadow(0 12px 32px rgba(0, 0, 0, 0.4));
|
|
27
|
-
}`),Ct={name:"shimmer",transition:X,keyframes:[ct],mainImageHovered:{filter:"brightness(0.35) saturate(0.6)"},vignetteStyle:{background:"radial-gradient(ellipse at center, transparent 20%, rgba(0,0,0,0.5) 100%)"},cutoutActive:{transform:"scale(1.04) translateY(-6px)",filter:"brightness(1.05) contrast(1.02) drop-shadow(0 0 6px rgba(255,255,255,0.12)) drop-shadow(0 12px 32px rgba(0,0,0,0.4))",opacity:1,animation:`${ct.name} 2.4s ease-in-out infinite`},cutoutInactive:{transform:"scale(1)",filter:"brightness(0.35) saturate(0.5)",opacity:.4},cutoutIdle:{transform:"scale(1)",filter:"drop-shadow(0 1px 4px rgba(0, 0, 0, 0.1))",opacity:1},geometryActive:{fill:"rgba(255, 255, 255, 0.1)",stroke:"rgba(255, 255, 255, 0.7)",strokeWidth:2,glow:"0 0 14px rgba(255, 255, 255, 0.35), 0 12px 32px rgba(0, 0, 0, 0.4)"},geometryInactive:{fill:"rgba(255, 255, 255, 0.02)",stroke:"rgba(255, 255, 255, 0.1)",strokeWidth:1},geometryIdle:{fill:"transparent",stroke:"transparent",strokeWidth:1}},V={elevate:vt,glow:xt,lift:wt,subtle:kt,trace:Et,shimmer:Ct},G=i.createContext(null),Rt=i.createContext(null);function Q(){const t=i.useContext(Rt);if(!t)throw new Error("Must be used inside <CutoutViewer>");return t}const q=i.createContext(null);function Nt(){const t=i.useContext(q);if(!t)throw new Error("useCutout must be used inside <CutoutViewer.Cutout>");return t}function Yt({id:t,src:r,label:o,effect:n,children:a,renderLayer:c}){const l=i.useContext(G),s=Q();if(!l)throw new Error("<CutoutViewer.Cutout> must be used inside <CutoutViewer>");i.useEffect(()=>(l.registerCutout({type:"image",id:t,src:r,label:o}),()=>l.unregisterCutout(t)),[t,r,o,l]);const d=n?typeof n=="string"?V[n]??s.effect:n:s.effect,u=s.activeId===t,h=s.hoveredId===t,E=s.selectedId===t,y={x:0,y:0,w:1,h:1},g=s.boundsMap[t]??y;let b;!s.enabled||!s.isAnyActive&&!s.showAll?b=d.cutoutIdle:s.showAll||u?b=d.cutoutActive:b=d.cutoutInactive;const C=i.useMemo(()=>({id:t,label:o,bounds:g,isActive:u,isHovered:h,isSelected:E,effect:d}),[t,o,g,u,h,E,d]);return R.jsxs(q.Provider,{value:C,children:[R.jsx("div",{"data-cutout-id":t,style:{pointerEvents:"none",position:"absolute",inset:0,zIndex:u?20:10,transition:d.transition,...b},children:c?c({isActive:u,isHovered:h,isSelected:E,bounds:g,effect:d}):R.jsx("img",{src:r,alt:o||t,draggable:!1,style:{width:"100%",height:"100%",objectFit:"fill",userSelect:"none"}})}),a]})}function ft(t){const{filter:r,...o}=t;return o}function Vt({id:t,bounds:r,label:o,effect:n,children:a,renderLayer:c}){const l=i.useContext(G),s=Q();if(!l)throw new Error("<CutoutViewer.BBoxCutout> must be used inside <CutoutViewer>");const{x:d,y:u,w:h,h:E}=r;i.useEffect(()=>(l.registerCutout({type:"bbox",id:t,bounds:{x:d,y:u,w:h,h:E},label:o}),()=>l.unregisterCutout(t)),[t,d,u,h,E,o,l]);const y=n?typeof n=="string"?V[n]??s.effect:n:s.effect,g=s.activeId===t,b=s.hoveredId===t,C=s.selectedId===t,w={x:0,y:0,w:1,h:1},k=s.boundsMap[t]??w;let f,v;!s.enabled||!s.isAnyActive&&!s.showAll?(v={...y.cutoutIdle,filter:"none",opacity:0},f=y.geometryIdle):s.showAll||g?(v=ft(y.cutoutActive),f=y.geometryActive):(v=ft(y.cutoutInactive),f=y.geometryInactive);const m=f??{fill:"rgba(37, 99, 235, 0.15)",stroke:"rgba(37, 99, 235, 0.6)",strokeWidth:2},M=i.useMemo(()=>({id:t,label:o,bounds:k,isActive:g,isHovered:b,isSelected:C,effect:y}),[t,o,k,g,b,C,y]);return R.jsxs(q.Provider,{value:M,children:[R.jsx("div",{"data-cutout-id":t,style:{pointerEvents:"none",position:"absolute",inset:0,zIndex:g?20:10,transition:y.transition,...v},children:c?c({isActive:g,isHovered:b,isSelected:C,bounds:k,effect:y}):R.jsx("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",filter:m.glow?`drop-shadow(${m.glow.split(",")[0]?.trim()??""})`:"none"},children:R.jsx("rect",{x:k.x,y:k.y,width:k.w,height:k.h,rx:.004,fill:m.fill,stroke:m.stroke,strokeWidth:(m.strokeWidth??2)*.0015,strokeLinecap:m.strokeDasharray?"round":void 0,strokeDasharray:m.strokeDasharray,pathLength:m.strokeDasharray?1:void 0,style:{transition:y.transition,animation:m.animation}})})}),a]})}function dt(t){const{filter:r,...o}=t;return o}function Ht({id:t,points:r,label:o,effect:n,children:a,renderLayer:c}){const l=i.useContext(G),s=Q();if(!l)throw new Error("<CutoutViewer.PolygonCutout> must be used inside <CutoutViewer>");const d=r.flat().join(",");i.useEffect(()=>(l.registerCutout({type:"polygon",id:t,points:r,label:o}),()=>l.unregisterCutout(t)),[t,d,o,l]);const u=n?typeof n=="string"?V[n]??s.effect:n:s.effect,h=s.activeId===t,E=s.hoveredId===t,y=s.selectedId===t,g={x:0,y:0,w:1,h:1},b=s.boundsMap[t]??g;let C,w;!s.enabled||!s.isAnyActive&&!s.showAll?(w={...u.cutoutIdle,filter:"none",opacity:0},C=u.geometryIdle):s.showAll||h?(w=dt(u.cutoutActive),C=u.geometryActive):(w=dt(u.cutoutInactive),C=u.geometryInactive);const f=C??{fill:"rgba(37, 99, 235, 0.15)",stroke:"rgba(37, 99, 235, 0.6)",strokeWidth:2},v=i.useMemo(()=>({id:t,label:o,bounds:b,isActive:h,isHovered:E,isSelected:y,effect:u}),[t,o,b,h,E,y,u]);return R.jsxs(q.Provider,{value:v,children:[R.jsx("div",{"data-cutout-id":t,style:{pointerEvents:"none",position:"absolute",inset:0,zIndex:h?20:10,transition:u.transition,...w},children:c?c({isActive:h,isHovered:E,isSelected:y,bounds:b,effect:u}):R.jsx("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",filter:f.glow?`drop-shadow(${f.glow.split(",")[0]?.trim()??""})`:"none"},children:R.jsx("polygon",{points:r.map(([x,m])=>`${x},${m}`).join(" "),fill:f.fill,stroke:f.stroke,strokeWidth:(f.strokeWidth??2)*.0015,strokeLinejoin:"round",strokeLinecap:f.strokeDasharray?"round":void 0,strokeDasharray:f.strokeDasharray,pathLength:f.strokeDasharray?1:void 0,style:{transition:u.transition,animation:f.animation}})})}),a]})}function Bt(t,r){const{x:o,y:n,w:a,h:c}=r;let l,s;t.includes("left")?(l=`${o*100}%`,s="0"):t.includes("right")?(l=`${(o+a)*100}%`,s="-100%"):(l=`${(o+a/2)*100}%`,s="-50%");let d,u;return t.startsWith("top")?(d=`${n*100}%`,u="-100%"):t.startsWith("bottom")?(d=`${(n+c)*100}%`,u="0"):(d=`${(n+c/2)*100}%`,u="-50%"),{position:"absolute",left:l,top:d,transform:`translate(${s}, ${u})`}}function It({placement:t="top-center",children:r,className:o="",style:n}){const a=i.useContext(q),c=Q();if(!a)throw new Error("<CutoutViewer.Overlay> must be used inside <CutoutViewer.Cutout>");const l=c.enabled&&(c.showAll||a.isActive),s=Bt(t,a.bounds);return R.jsx("div",{"data-cutout-overlay":"true",className:o,style:{zIndex:30,transition:a.effect.transition,opacity:l?1:0,pointerEvents:l?"auto":"none",...s,...n},children:r})}function At({onComplete:t,minPoints:r=3,closeThreshold:o=.03}){const[n,a]=i.useState([]),[c,l]=i.useState(null),s=i.useRef(null),d=i.useCallback((f,v)=>{const x=s.current;if(!x)return null;const m=x.getBoundingClientRect(),M=(f-m.left)/m.width,O=(v-m.top)/m.height;return M<0||M>1||O<0||O>1?null:[M,O]},[]),u=i.useCallback((f,v)=>{if(v.length<r)return!1;const x=f[0]-v[0][0],m=f[1]-v[0][1];return Math.sqrt(x*x+m*m)<o},[r,o]),h=i.useCallback(f=>{f.length<r||(t(f),a([]),l(null))},[t,r]),E=i.useCallback(()=>{a([]),l(null)},[]),y=i.useCallback(f=>{l(d(f.clientX,f.clientY))},[d]),g=i.useCallback(()=>{l(null)},[]),b=i.useCallback(f=>{f.stopPropagation();const v=d(f.clientX,f.clientY);v&&a(x=>u(v,x)?(h(x),[]):[...x,v])},[d,u,h]),C=i.useCallback(f=>{f.stopPropagation(),a(v=>{const x=v.slice(0,-1);return x.length>=r?(h(x),[]):x})},[r,h]),w=i.useCallback(f=>{f.preventDefault(),a(v=>v.slice(0,-1))},[]),k=c!==null&&u(c,n);return{points:n,previewPoint:c,willClose:k,reset:E,containerRef:s,containerProps:{onPointerMove:y,onPointerLeave:g,onClick:b,onDoubleClick:C,onContextMenu:w}}}function _t({onComplete:t,minPoints:r=3,closeThreshold:o=.03,strokeColor:n="#3b82f6",enabled:a=!0,style:c,className:l=""}){if(!i.useContext(G))throw new Error("<CutoutViewer.DrawPolygon> must be used inside <CutoutViewer>");const{points:d,previewPoint:u,willClose:h,reset:E,containerRef:y,containerProps:g}=At({onComplete:t,minPoints:r,closeThreshold:o});i.useEffect(()=>{function w(k){k.key==="Escape"&&E()}return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[E]),i.useEffect(()=>{a||E()},[a,E]);const b=u?[...d,u]:d,C=b.map(([w,k])=>`${w},${k}`).join(" ");return R.jsx("div",{ref:y,"data-draw-polygon":"true",className:l,style:{position:"absolute",inset:0,cursor:a?h?"cell":"crosshair":"default",zIndex:30,pointerEvents:a?"auto":"none",...c},...a?g:{},children:d.length>0&&R.jsxs("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},children:[d.length>=3&&R.jsx("polygon",{points:d.map(([w,k])=>`${w},${k}`).join(" "),fill:n,fillOpacity:.15,stroke:"none"}),b.length>=2&&R.jsx("polyline",{points:C,fill:"none",stroke:n,strokeWidth:.003,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:u?"0.015 0.008":void 0}),u&&d.length>=1&&R.jsx("line",{x1:u[0],y1:u[1],x2:d[0][0],y2:d[0][1],stroke:n,strokeWidth:.002,strokeDasharray:"0.015 0.008",strokeLinecap:"round",opacity:h?.9:.35}),d.map(([w,k],f)=>R.jsx("circle",{cx:w,cy:k,r:f===0?.012:.007,fill:f===0&&h?n:"white",stroke:n,strokeWidth:.002},f)),u&&R.jsx("circle",{cx:u[0],cy:u[1],r:.005,fill:h?n:"white",stroke:n,strokeWidth:.002,opacity:.8})]})})}function ht(t){switch(t.type){case"image":return`image:${t.src}:${t.label??""}`;case"bbox":return`bbox:${t.bounds.x},${t.bounds.y},${t.bounds.w},${t.bounds.h}:${t.label??""}`;case"polygon":return`polygon:${t.points.flat().join(",")}:${t.label??""}`}}function Lt({mainImage:t,mainImageAlt:r="Main image",effect:o="elevate",enabled:n=!0,showAll:a=!1,alphaThreshold:c=30,hoverLeaveDelay:l=150,children:s,className:d="",style:u,onHover:h,onActiveChange:E,onSelect:y}){const g=typeof o=="string"?V[o]??V.elevate:o;i.useEffect(()=>{Dt(g)},[g]);const[b,C]=i.useState(()=>new Map),w=i.useCallback($=>{C(D=>{const N=D.get($.id);if(N&&ht(N)===ht($))return D;const F=new Map(D);return F.set($.id,$),F})},[]),k=i.useCallback($=>{C(D=>{if(!D.has($))return D;const N=new Map(D);return N.delete($),N})},[]),f=i.useMemo(()=>({registerCutout:w,unregisterCutout:k}),[w,k]),v=i.useMemo(()=>Array.from(b.values()),[b]),{activeId:x,selectedId:m,hoveredId:M,boundsMap:O,containerRef:B,containerProps:T}=bt(v,n,c,l),S=i.useRef(null),I=i.useRef(null),A=i.useRef(null);i.useEffect(()=>{M!==S.current&&(S.current=M,h?.(M))},[M,h]),i.useEffect(()=>{x!==I.current&&(I.current=x,E?.(x))},[x,E]),i.useEffect(()=>{m!==A.current&&(A.current=m,y?.(m))},[m,y]);const W=a||x!==null,L=i.useMemo(()=>({activeId:x,selectedId:m,hoveredId:M,effect:g,enabled:n,showAll:a,boundsMap:O,isAnyActive:W}),[x,m,M,g,n,a,O,W]);return R.jsx(G.Provider,{value:f,children:R.jsx(Rt.Provider,{value:L,children:R.jsxs("div",{ref:B,className:d,style:{position:"relative",width:"100%",overflow:"hidden",cursor:W&&n?"pointer":"default",...u},...T,children:[R.jsx("img",{src:t,alt:r,draggable:!1,style:{display:"block",width:"100%",height:"auto",userSelect:"none",transition:g.transition,...W&&n?g.mainImageHovered:{}}}),R.jsx("div",{style:{pointerEvents:"none",position:"absolute",inset:0,transition:g.transition,opacity:W&&n?1:0,...g.vignetteStyle}}),s]})})})}const H=Lt;H.Cutout=Yt;H.BBoxCutout=Vt;H.PolygonCutout=Ht;H.Overlay=It;H.DrawPolygon=_t;exports.CutoutOverlay=It;exports.CutoutViewer=H;exports.DrawPolygon=_t;exports.ImageHitTestStrategy=pt;exports.PolygonHitTestStrategy=yt;exports.RectHitTestStrategy=gt;exports.createHitTestStrategy=mt;exports.defineKeyframes=Z;exports.elevateEffect=vt;exports.glowEffect=xt;exports.hoverEffects=V;exports.liftEffect=wt;exports.shimmerEffect=Ct;exports.subtleEffect=kt;exports.traceEffect=Et;exports.useCutout=Nt;exports.useCutoutHitTest=bt;exports.useDrawPolygon=At;
|
|
23
|
+
}`),Ct={name:"shimmer",transition:U,keyframes:[ut],mainImageHovered:{filter:"brightness(0.35) saturate(0.6)"},vignetteStyle:{background:"radial-gradient(ellipse at center, transparent 20%, rgba(0,0,0,0.5) 100%)"},cutoutActive:{transform:"scale(1.04) translateY(-6px)",filter:"brightness(1.05) contrast(1.02) drop-shadow(0 0 6px rgba(255,255,255,0.12)) drop-shadow(0 12px 32px rgba(0,0,0,0.4))",opacity:1,animation:`${ut.name} 2.4s ease-in-out infinite`},cutoutInactive:{transform:"scale(1)",filter:"brightness(0.35) saturate(0.5)",opacity:.4},cutoutIdle:{transform:"scale(1)",filter:"drop-shadow(0 1px 4px rgba(0, 0, 0, 0.1))",opacity:1},geometryActive:{fill:"rgba(255, 255, 255, 0.1)",stroke:"rgba(255, 255, 255, 0.7)",strokeWidth:2,glow:"0 0 14px rgba(255, 255, 255, 0.35), 0 12px 32px rgba(0, 0, 0, 0.4)"},geometryInactive:{fill:"rgba(255, 255, 255, 0.02)",stroke:"rgba(255, 255, 255, 0.1)",strokeWidth:1},geometryIdle:{fill:"transparent",stroke:"transparent",strokeWidth:1}},B={elevate:vt,glow:xt,lift:wt,subtle:kt,trace:Et,shimmer:Ct},G=u.createContext(null),It=u.createContext(null);function Q(){const t=u.useContext(It);if(!t)throw new Error("Must be used inside <CutoutViewer>");return t}const J=u.createContext(null);function Ht(){const t=u.useContext(J);if(!t)throw new Error("useCutout must be used inside <CutoutViewer.Cutout>");return t}function Bt({id:t,src:e,label:n,effect:r,children:i,renderLayer:l}){const a=u.useContext(G),s=Q();if(!a)throw new Error("<CutoutViewer.Cutout> must be used inside <CutoutViewer>");u.useEffect(()=>(a.registerCutout({type:"image",id:t,src:e,label:n}),()=>a.unregisterCutout(t)),[t,e,n,a]);const f=r?typeof r=="string"?B[r]??s.effect:r:s.effect,c=s.contourMap[t]??null,h=s.activeId===t,E=s.hoveredId===t,y=s.selectedId===t,p={x:0,y:0,w:1,h:1},m=s.boundsMap[t]??p;let x,d;!s.enabled||!s.isAnyActive&&!s.showAll?(x=f.cutoutIdle,d=f.geometryIdle):s.showAll||h?(x=f.cutoutActive,d=f.geometryActive):(x=f.cutoutInactive,d=f.geometryInactive);const v=u.useMemo(()=>({id:t,label:n,bounds:m,isActive:h,isHovered:E,isSelected:y,effect:f}),[t,n,m,h,E,y,f]);return I.jsxs(J.Provider,{value:v,children:[I.jsxs("div",{"data-cutout-id":t,style:{pointerEvents:"none",position:"absolute",inset:0,zIndex:h?20:10,transition:f.transition,...x},children:[l?l({isActive:h,isHovered:E,isSelected:y,bounds:m,effect:f}):I.jsx("img",{src:e,alt:n||t,draggable:!1,style:{width:"100%",height:"100%",objectFit:"fill",userSelect:"none"}}),c&&d&&I.jsx("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",filter:d.glow?`drop-shadow(${d.glow.split(",")[0]?.trim()??""})`:"none"},children:I.jsx("polygon",{points:c.map(([g,C])=>`${g},${C}`).join(" "),fill:d.fill,stroke:d.stroke,strokeWidth:(d.strokeWidth??2)*.0015,strokeLinejoin:"round",strokeLinecap:d.strokeDasharray?"round":void 0,strokeDasharray:d.strokeDasharray,pathLength:d.strokeDasharray?1:void 0,style:{transition:f.transition,animation:d.animation}})})]}),i]})}function ft(t){const{filter:e,...n}=t;return n}function Ft({id:t,bounds:e,label:n,effect:r,children:i,renderLayer:l}){const a=u.useContext(G),s=Q();if(!a)throw new Error("<CutoutViewer.BBoxCutout> must be used inside <CutoutViewer>");const{x:f,y:c,w:h,h:E}=e;u.useEffect(()=>(a.registerCutout({type:"bbox",id:t,bounds:{x:f,y:c,w:h,h:E},label:n}),()=>a.unregisterCutout(t)),[t,f,c,h,E,n,a]);const y=r?typeof r=="string"?B[r]??s.effect:r:s.effect,p=s.activeId===t,m=s.hoveredId===t,x=s.selectedId===t,d={x:0,y:0,w:1,h:1},v=s.boundsMap[t]??d;let g,C;!s.enabled||!s.isAnyActive&&!s.showAll?(C={...y.cutoutIdle,filter:"none",opacity:0},g=y.geometryIdle):s.showAll||p?(C=ft(y.cutoutActive),g=y.geometryActive):(C=ft(y.cutoutInactive),g=y.geometryInactive);const w=g??{fill:"rgba(37, 99, 235, 0.15)",stroke:"rgba(37, 99, 235, 0.6)",strokeWidth:2},$=u.useMemo(()=>({id:t,label:n,bounds:v,isActive:p,isHovered:m,isSelected:x,effect:y}),[t,n,v,p,m,x,y]);return I.jsxs(J.Provider,{value:$,children:[I.jsx("div",{"data-cutout-id":t,style:{pointerEvents:"none",position:"absolute",inset:0,zIndex:p?20:10,transition:y.transition,...C},children:l?l({isActive:p,isHovered:m,isSelected:x,bounds:v,effect:y}):I.jsx("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",filter:w.glow?`drop-shadow(${w.glow.split(",")[0]?.trim()??""})`:"none"},children:I.jsx("rect",{x:v.x,y:v.y,width:v.w,height:v.h,rx:.004,fill:w.fill,stroke:w.stroke,strokeWidth:(w.strokeWidth??2)*.0015,strokeLinecap:w.strokeDasharray?"round":void 0,strokeDasharray:w.strokeDasharray,pathLength:w.strokeDasharray?1:void 0,style:{transition:y.transition,animation:w.animation}})})}),i]})}function dt(t){const{filter:e,...n}=t;return n}function zt({id:t,points:e,label:n,effect:r,children:i,renderLayer:l}){const a=u.useContext(G),s=Q();if(!a)throw new Error("<CutoutViewer.PolygonCutout> must be used inside <CutoutViewer>");const f=e.flat().join(",");u.useEffect(()=>(a.registerCutout({type:"polygon",id:t,points:e,label:n}),()=>a.unregisterCutout(t)),[t,f,n,a]);const c=r?typeof r=="string"?B[r]??s.effect:r:s.effect,h=s.activeId===t,E=s.hoveredId===t,y=s.selectedId===t,p={x:0,y:0,w:1,h:1},m=s.boundsMap[t]??p;let x,d;!s.enabled||!s.isAnyActive&&!s.showAll?(d={...c.cutoutIdle,filter:"none",opacity:0},x=c.geometryIdle):s.showAll||h?(d=dt(c.cutoutActive),x=c.geometryActive):(d=dt(c.cutoutInactive),x=c.geometryInactive);const g=x??{fill:"rgba(37, 99, 235, 0.15)",stroke:"rgba(37, 99, 235, 0.6)",strokeWidth:2},C=u.useMemo(()=>({id:t,label:n,bounds:m,isActive:h,isHovered:E,isSelected:y,effect:c}),[t,n,m,h,E,y,c]);return I.jsxs(J.Provider,{value:C,children:[I.jsx("div",{"data-cutout-id":t,style:{pointerEvents:"none",position:"absolute",inset:0,zIndex:h?20:10,transition:c.transition,...d},children:l?l({isActive:h,isHovered:E,isSelected:y,bounds:m,effect:c}):I.jsx("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",filter:g.glow?`drop-shadow(${g.glow.split(",")[0]?.trim()??""})`:"none"},children:I.jsx("polygon",{points:e.map(([k,w])=>`${k},${w}`).join(" "),fill:g.fill,stroke:g.stroke,strokeWidth:(g.strokeWidth??2)*.0015,strokeLinejoin:"round",strokeLinecap:g.strokeDasharray?"round":void 0,strokeDasharray:g.strokeDasharray,pathLength:g.strokeDasharray?1:void 0,style:{transition:c.transition,animation:g.animation}})})}),i]})}function Xt(t,e){const{x:n,y:r,w:i,h:l}=e;let a,s;t.includes("left")?(a=`${n*100}%`,s="0"):t.includes("right")?(a=`${(n+i)*100}%`,s="-100%"):(a=`${(n+i/2)*100}%`,s="-50%");let f,c;return t.startsWith("top")?(f=`${r*100}%`,c="-100%"):t.startsWith("bottom")?(f=`${(r+l)*100}%`,c="0"):(f=`${(r+l/2)*100}%`,c="-50%"),{position:"absolute",left:a,top:f,transform:`translate(${s}, ${c})`}}function Rt({placement:t="top-center",children:e,className:n="",style:r}){const i=u.useContext(J),l=Q();if(!i)throw new Error("<CutoutViewer.Overlay> must be used inside <CutoutViewer.Cutout>");const a=l.enabled&&(l.showAll||i.isActive),s=Xt(t,i.bounds);return I.jsx("div",{"data-cutout-overlay":"true",className:n,style:{zIndex:30,transition:i.effect.transition,opacity:a?1:0,pointerEvents:a?"auto":"none",...s,...r},children:e})}function At({onComplete:t,minPoints:e=3,closeThreshold:n=.03}){const[r,i]=u.useState([]),[l,a]=u.useState(null),s=u.useRef(null),f=u.useCallback((g,C)=>{const k=s.current;if(!k)return null;const w=k.getBoundingClientRect(),$=(g-w.left)/w.width,W=(C-w.top)/w.height;return $<0||$>1||W<0||W>1?null:[$,W]},[]),c=u.useCallback((g,C)=>{if(C.length<e)return!1;const k=g[0]-C[0][0],w=g[1]-C[0][1];return Math.sqrt(k*k+w*w)<n},[e,n]),h=u.useCallback(g=>{g.length<e||(t(g),i([]),a(null))},[t,e]),E=u.useCallback(()=>{i([]),a(null)},[]),y=u.useCallback(g=>{a(f(g.clientX,g.clientY))},[f]),p=u.useCallback(()=>{a(null)},[]),m=u.useCallback(g=>{g.stopPropagation();const C=f(g.clientX,g.clientY);C&&i(k=>c(C,k)?(h(k),[]):[...k,C])},[f,c,h]),x=u.useCallback(g=>{g.stopPropagation(),i(C=>{const k=C.slice(0,-1);return k.length>=e?(h(k),[]):k})},[e,h]),d=u.useCallback(g=>{g.preventDefault(),i(C=>C.slice(0,-1))},[]),v=l!==null&&c(l,r);return{points:r,previewPoint:l,willClose:v,reset:E,containerRef:s,containerProps:{onPointerMove:y,onPointerLeave:p,onClick:m,onDoubleClick:x,onContextMenu:d}}}function St({onComplete:t,minPoints:e=3,closeThreshold:n=.03,strokeColor:r="#3b82f6",enabled:i=!0,style:l,className:a=""}){if(!u.useContext(G))throw new Error("<CutoutViewer.DrawPolygon> must be used inside <CutoutViewer>");const{points:f,previewPoint:c,willClose:h,reset:E,containerRef:y,containerProps:p}=At({onComplete:t,minPoints:e,closeThreshold:n});u.useEffect(()=>{function d(v){v.key==="Escape"&&E()}return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[E]),u.useEffect(()=>{i||E()},[i,E]);const m=c?[...f,c]:f,x=m.map(([d,v])=>`${d},${v}`).join(" ");return I.jsx("div",{ref:y,"data-draw-polygon":"true",className:a,style:{position:"absolute",inset:0,cursor:i?h?"cell":"crosshair":"default",zIndex:30,pointerEvents:i?"auto":"none",...l},...i?p:{},children:f.length>0&&I.jsxs("svg",{viewBox:"0 0 1 1",preserveAspectRatio:"none",style:{position:"absolute",inset:0,width:"100%",height:"100%",overflow:"visible",pointerEvents:"none"},children:[f.length>=3&&I.jsx("polygon",{points:f.map(([d,v])=>`${d},${v}`).join(" "),fill:r,fillOpacity:.15,stroke:"none"}),m.length>=2&&I.jsx("polyline",{points:x,fill:"none",stroke:r,strokeWidth:.003,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:c?"0.015 0.008":void 0}),c&&f.length>=1&&I.jsx("line",{x1:c[0],y1:c[1],x2:f[0][0],y2:f[0][1],stroke:r,strokeWidth:.002,strokeDasharray:"0.015 0.008",strokeLinecap:"round",opacity:h?.9:.35}),f.map(([d,v],g)=>I.jsx("circle",{cx:d,cy:v,r:g===0?.012:.007,fill:g===0&&h?r:"white",stroke:r,strokeWidth:.002},g)),c&&I.jsx("circle",{cx:c[0],cy:c[1],r:.005,fill:h?r:"white",stroke:r,strokeWidth:.002,opacity:.8})]})})}function ht(t){switch(t.type){case"image":return`image:${t.src}:${t.label??""}`;case"bbox":return`bbox:${t.bounds.x},${t.bounds.y},${t.bounds.w},${t.bounds.h}:${t.label??""}`;case"polygon":return`polygon:${t.points.flat().join(",")}:${t.label??""}`}}function qt({mainImage:t,mainImageAlt:e="Main image",effect:n="elevate",enabled:r=!0,showAll:i=!1,alphaThreshold:l=30,hoverLeaveDelay:a=150,children:s,className:f="",style:c,onHover:h,onActiveChange:E,onSelect:y}){const p=typeof n=="string"?B[n]??B.elevate:n;u.useEffect(()=>{Lt(p)},[p]);const[m,x]=u.useState(()=>new Map),d=u.useCallback(M=>{x(O=>{const N=O.get(M.id);if(N&&ht(N)===ht(M))return O;const D=new Map(O);return D.set(M.id,M),D})},[]),v=u.useCallback(M=>{x(O=>{if(!O.has(M))return O;const N=new Map(O);return N.delete(M),N})},[]),g=u.useMemo(()=>({registerCutout:d,unregisterCutout:v}),[d,v]),C=u.useMemo(()=>Array.from(m.values()),[m]),{activeId:k,selectedId:w,hoveredId:$,boundsMap:W,contourMap:V,containerRef:Y,containerProps:z}=bt(C,r,l,a),L=u.useRef(null),T=u.useRef(null),S=u.useRef(null);u.useEffect(()=>{$!==L.current&&(L.current=$,h?.($))},[$,h]),u.useEffect(()=>{k!==T.current&&(T.current=k,E?.(k))},[k,E]),u.useEffect(()=>{w!==S.current&&(S.current=w,y?.(w))},[w,y]);const R=i||k!==null,_=u.useMemo(()=>({activeId:k,selectedId:w,hoveredId:$,effect:p,enabled:r,showAll:i,boundsMap:W,contourMap:V,isAnyActive:R}),[k,w,$,p,r,i,W,V,R]);return I.jsx(G.Provider,{value:g,children:I.jsx(It.Provider,{value:_,children:I.jsxs("div",{ref:Y,className:f,style:{position:"relative",width:"100%",overflow:"hidden",cursor:R&&r?"pointer":"default",...c},...z,children:[I.jsx("img",{src:t,alt:e,draggable:!1,style:{display:"block",width:"100%",height:"auto",userSelect:"none",transition:p.transition,...R&&r?p.mainImageHovered:{}}}),I.jsx("div",{style:{pointerEvents:"none",position:"absolute",inset:0,transition:p.transition,opacity:R&&r?1:0,...p.vignetteStyle}}),s]})})})}const F=qt;F.Cutout=Bt;F.BBoxCutout=Ft;F.PolygonCutout=zt;F.Overlay=Rt;F.DrawPolygon=St;exports.CutoutOverlay=Rt;exports.CutoutViewer=F;exports.DrawPolygon=St;exports.ImageHitTestStrategy=gt;exports.PolygonHitTestStrategy=yt;exports.RectHitTestStrategy=pt;exports.createHitTestStrategy=mt;exports.defineKeyframes=nt;exports.elevateEffect=vt;exports.glowEffect=xt;exports.hoverEffects=B;exports.liftEffect=wt;exports.shimmerEffect=Ct;exports.subtleEffect=kt;exports.traceEffect=Et;exports.useCutout=Ht;exports.useCutoutHitTest=bt;exports.useDrawPolygon=At;
|