HifiPlanet-Website/hifi/assets/ImageUploadField-2vGOiTjw.js
Max Olchov 05bf780351
KI-Modellbilder: zweiter Durchgang 'Logos entfernen'
Optional unter KI-Modellbilder: das fertige Bild geht mit einem reinen Bearbeitungs-
Prompt (eigener Endpunkt moeglich) noch einmal zu Higgsfield. Stapel und Modell-Panel
laufen ueber HiggsfieldController::advance (car_models.ai_stage = cleanup).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ex4YsMRQ4GF2dkGWuX6Yio
2026-10-23 18:39:14 +00:00

95 lines
30 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{ab as mt,r as m,j as u,c as ft}from"./index-BIW2KHEU.js";import{M as gt,f as vt}from"./resizeImage-C6PvAwh0.js";var V=!1,E,Z,k,N,_,rt,W,B,U,G,nt,H,X,st,at;function g(){if(!V){V=!0;var o=navigator.userAgent,e=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso|Iceweasel).(\d+\.\d+))|(?:Opera(?:.+Version.|.)(\d+\.\d+))|(?:AppleWebKit.(\d+(?:\.\d+)?))|(?:Trident\/\d+\.\d+.*rv:(\d+\.\d+))/.exec(o),t=/(Mac OS X)|(Windows)|(Linux)/.exec(o);if(H=/\b(iPhone|iP[ao]d)/.exec(o),X=/\b(iP[ao]d)/.exec(o),G=/Android/i.exec(o),st=/FBAN\/\w+;/i.exec(o),at=/Mobile/i.exec(o),nt=!!/Win64/.exec(o),e){E=e[1]?parseFloat(e[1]):e[5]?parseFloat(e[5]):NaN,E&&document&&document.documentMode&&(E=document.documentMode);var i=/(?:Trident\/(\d+.\d+))/.exec(o);rt=i?parseFloat(i[1])+4:E,Z=e[2]?parseFloat(e[2]):NaN,k=e[3]?parseFloat(e[3]):NaN,N=e[4]?parseFloat(e[4]):NaN,N?(e=/(?:Chrome\/(\d+\.\d+))/.exec(o),_=e&&e[1]?parseFloat(e[1]):NaN):_=NaN}else E=Z=k=_=N=NaN;if(t){if(t[1]){var r=/(?:Mac OS X (\d+(?:[._]\d+)?))/.exec(o);W=r?parseFloat(r[1].replace("_",".")):!0}else W=!1;B=!!t[2],U=!!t[3]}else W=B=U=!1}}var Y={ie:function(){return g()||E},ieCompatibilityMode:function(){return g()||rt>E},ie64:function(){return Y.ie()&&nt},firefox:function(){return g()||Z},opera:function(){return g()||k},webkit:function(){return g()||N},safari:function(){return Y.webkit()},chrome:function(){return g()||_},windows:function(){return g()||B},osx:function(){return g()||W},linux:function(){return g()||U},iphone:function(){return g()||H},mobile:function(){return g()||H||X||G||at},nativeApp:function(){return g()||st},android:function(){return g()||G},ipad:function(){return g()||X}},wt=Y,bt=!!(typeof window<"u"&&window.document&&window.document.createElement),Ct={canUseDOM:bt},xt=Ct,ht=xt,ct;ht.canUseDOM&&(ct=document.implementation&&document.implementation.hasFeature&&document.implementation.hasFeature("","")!==!0);/**
* Checks if an event is supported in the current execution environment.
*
* NOTE: This will not work correctly for non-generic events such as `change`,
* `reset`, `load`, `error`, and `select`.
*
* Borrows from Modernizr.
*
* @param {string} eventNameSuffix Event name, e.g. "click".
* @param {?boolean} capture Check if the capture phase is supported.
* @return {boolean} True if the event is supported.
* @internal
* @license Modernizr 3.0.0pre (Custom Build) | MIT
*/function yt(o,e){if(!ht.canUseDOM||e&&!("addEventListener"in document))return!1;var t="on"+o,i=t in document;if(!i){var r=document.createElement("div");r.setAttribute(t,"return;"),i=typeof r[t]=="function"}return!i&&ct&&o==="wheel"&&(i=document.implementation.hasFeature("Events.wheel","3.0")),i}var St=yt,zt=wt,Et=St,q=10,J=40,Q=800;function pt(o){var e=0,t=0,i=0,r=0;return"detail"in o&&(t=o.detail),"wheelDelta"in o&&(t=-o.wheelDelta/120),"wheelDeltaY"in o&&(t=-o.wheelDeltaY/120),"wheelDeltaX"in o&&(e=-o.wheelDeltaX/120),"axis"in o&&o.axis===o.HORIZONTAL_AXIS&&(e=t,t=0),i=e*q,r=t*q,"deltaY"in o&&(r=o.deltaY),"deltaX"in o&&(i=o.deltaX),(i||r)&&o.deltaMode&&(o.deltaMode==1?(i*=J,r*=J):(i*=Q,r*=Q)),i&&!e&&(e=i<1?-1:1),r&&!t&&(t=r<1?-1:1),{spinX:e,spinY:t,pixelX:i,pixelY:r}}pt.getEventType=function(){return zt.firefox()?"DOMMouseScroll":Et("wheel")?"wheel":"mousewheel"};var Dt=pt,Rt=Dt;const Pt=mt(Rt);function j(o){"@babel/helpers - typeof";return j=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},j(o)}function Mt(o,e){if(j(o)!="object"||!o)return o;var t=o[Symbol.toPrimitive];if(t!==void 0){var i=t.call(o,e);if(j(i)!="object")return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(o)}function jt(o){var e=Mt(o,"string");return j(e)=="symbol"?e:e+""}function Tt(o,e,t){return(e=jt(e))in o?Object.defineProperty(o,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):o[e]=t,o}function $(o,e){var t=Object.keys(o);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(o);e&&(i=i.filter(function(r){return Object.getOwnPropertyDescriptor(o,r).enumerable})),t.push.apply(t,i)}return t}function d(o){for(var e=1;e<arguments.length;e++){var t=arguments[e]!=null?arguments[e]:{};e%2?$(Object(t),!0).forEach(function(i){Tt(o,i,t[i])}):Object.getOwnPropertyDescriptors?Object.defineProperties(o,Object.getOwnPropertyDescriptors(t)):$(Object(t)).forEach(function(i){Object.defineProperty(o,i,Object.getOwnPropertyDescriptor(t,i))})}return o}function At(o,e,t,i,r,n=0){const{width:s,height:a}=R(o,e,n),h=Math.min(s,t),c=Math.min(a,i);return h>c*r?{width:c*r,height:c}:{width:h,height:h/r}}function Ot(o){return o.width>o.height?o.width/o.naturalWidth:o.height/o.naturalHeight}function M(o,e,t,i,r=0){const{width:n,height:s}=R(e.width,e.height,r);return{x:tt(o.x,n,t.width,i),y:tt(o.y,s,t.height,i)}}function tt(o,e,t,i){const r=Math.abs(e*i/2-t/2);return I(o,-r,r)}function et(o,e){return Math.sqrt(Math.pow(o.y-e.y,2)+Math.pow(o.x-e.x,2))}function it(o,e){return Math.atan2(e.y-o.y,e.x-o.x)*180/Math.PI}function Nt(o,e,t,i,r,n=0,s=!0){const a=s?_t:Wt,h=R(e.width,e.height,n),c=R(e.naturalWidth,e.naturalHeight,n),p={x:a(100,((h.width-t.width/r)/2-o.x/r)/h.width*100),y:a(100,((h.height-t.height/r)/2-o.y/r)/h.height*100),width:a(100,t.width/h.width*100/r),height:a(100,t.height/h.height*100/r)},f=Math.round(a(c.width,p.width*c.width/100)),y=Math.round(a(c.height,p.height*c.height/100)),b=c.width>=c.height*i?{width:Math.round(y*i),height:y}:{width:f,height:Math.round(f/i)};return{croppedAreaPercentages:p,croppedAreaPixels:d(d({},b),{},{x:Math.round(a(c.width-b.width,p.x*c.width/100)),y:Math.round(a(c.height-b.height,p.y*c.height/100))})}}function _t(o,e){return Math.min(o,Math.max(0,e))}function Wt(o,e){return e}function It(o,e,t,i,r,n){const s=R(e.width,e.height,t),a=I(i.width/s.width*(100/o.width),r,n);return{crop:{x:a*s.width/2-i.width/2-s.width*a*(o.x/100),y:a*s.height/2-i.height/2-s.height*a*(o.y/100)},zoom:a}}function Ft(o,e,t){const i=Ot(e);return t.height>t.width?t.height/(o.height*i):t.width/(o.width*i)}function Lt(o,e,t=0,i,r,n){const s=R(e.naturalWidth,e.naturalHeight,t),a=I(Ft(o,e,i),r,n),h=i.height>i.width?i.height/o.height:i.width/o.width;return{crop:{x:((s.width-o.width)/2-o.x)*h,y:((s.height-o.height)/2-o.y)*h},zoom:a}}function ot(o,e){return{x:(e.x+o.x)/2,y:(e.y+o.y)/2}}function Zt(o){return o*Math.PI/180}function R(o,e,t){const i=Zt(t);return{width:Math.abs(Math.cos(i)*o)+Math.abs(Math.sin(i)*e),height:Math.abs(Math.sin(i)*o)+Math.abs(Math.cos(i)*e)}}function I(o,e,t){return Math.min(Math.max(o,e),t)}function O(...o){return o.filter(e=>typeof e=="string"&&e.length>0).join(" ").trim()}var kt=`.reactEasyCrop_Container {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
overflow: hidden;
user-select: none;
touch-action: none;
cursor: move;
display: flex;
justify-content: center;
align-items: center;
}
.reactEasyCrop_Image,
.reactEasyCrop_Video {
will-change: transform; /* this improves performances and prevent painting issues on iOS Chrome */
max-width: unset; /* prevent global img/video reset rules from constraining the cropper media */
}
.reactEasyCrop_Contain {
max-width: 100%;
max-height: 100%;
margin: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
.reactEasyCrop_Cover_Horizontal {
width: 100%;
height: auto;
}
.reactEasyCrop_Cover_Vertical {
width: auto;
height: 100%;
}
.reactEasyCrop_CropArea {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
border: 1px solid rgba(255, 255, 255, 0.5);
box-sizing: border-box;
box-shadow: 0 0 0 9999em;
color: rgba(0, 0, 0, 0.5);
overflow: hidden;
}
.reactEasyCrop_CropAreaRound {
border-radius: 50%;
}
.reactEasyCrop_CropAreaGrid::before {
content: ' ';
box-sizing: border-box;
position: absolute;
border: 1px solid rgba(255, 255, 255, 0.5);
top: 0;
bottom: 0;
left: 33.33%;
right: 33.33%;
border-top: 0;
border-bottom: 0;
}
.reactEasyCrop_CropAreaGrid::after {
content: ' ';
box-sizing: border-box;
position: absolute;
border: 1px solid rgba(255, 255, 255, 0.5);
top: 33.33%;
bottom: 33.33%;
left: 0;
right: 0;
border-left: 0;
border-right: 0;
}
`;const Bt=250,Ut=1,Gt=3,Ht=1;var F=class x extends m.Component{constructor(...e){super(...e),this.cropperRef=m.createRef(),this.imageRef=m.createRef(),this.videoRef=m.createRef(),this.containerPosition={x:0,y:0},this.containerRef=null,this.styleRef=null,this.containerRect=null,this.mediaSize={width:0,height:0,naturalWidth:0,naturalHeight:0},this.dragStartPosition={x:0,y:0},this.dragStartCrop={x:0,y:0},this.gestureZoomStart=0,this.gestureRotationStart=0,this.isTouching=!1,this.lastPinchDistance=0,this.lastPinchRotation=0,this.rafDragTimeout=null,this.rafPinchTimeout=null,this.wheelTimer=null,this.resizeEmitTimer=null,this.currentDoc=typeof document<"u"?document:null,this.currentWindow=typeof window<"u"?window:null,this.resizeObserver=null,this.previousCropSize=null,this.isInitialized=!1,this.dragInteractionSource=null,this.state={cropSize:null,hasWheelJustStarted:!1,mediaObjectFit:void 0},this.initResizeObserver=()=>{if(typeof window.ResizeObserver>"u"||!this.containerRef)return;let t=!0;this.resizeObserver=new window.ResizeObserver(i=>{if(t){t=!1;return}this.computeSizes({isResizeTriggered:!0})}),this.resizeObserver.observe(this.containerRef)},this.onWindowResize=()=>{this.computeSizes({isResizeTriggered:!0})},this.preventZoomSafari=t=>t.preventDefault(),this.cleanEvents=()=>{this.currentDoc&&(this.currentDoc.removeEventListener("mousemove",this.onMouseMove),this.currentDoc.removeEventListener("mouseup",this.onDragStopped),this.currentDoc.removeEventListener("touchmove",this.onTouchMove),this.currentDoc.removeEventListener("touchend",this.onDragStopped),this.currentDoc.removeEventListener("gesturechange",this.onGestureChange),this.currentDoc.removeEventListener("gestureend",this.onGestureEnd),this.currentDoc.removeEventListener("scroll",this.onScroll))},this.clearScrollEvent=()=>{this.containerRef&&this.containerRef.removeEventListener("wheel",this.onWheel),this.wheelTimer&&clearTimeout(this.wheelTimer)},this.onMediaLoad=()=>{const t=this.computeSizes();t&&(this.previousCropSize=t,this.emitCropData(),this.setInitialCrop(t),this.isInitialized=!0),this.props.onMediaLoaded&&this.props.onMediaLoaded(this.mediaSize)},this.setInitialCrop=t=>{if(this.props.initialCroppedAreaPercentages){const{crop:i,zoom:r}=It(this.props.initialCroppedAreaPercentages,this.mediaSize,this.props.rotation,t,this.props.minZoom,this.props.maxZoom);this.props.onCropChange(i),this.props.onZoomChange&&this.props.onZoomChange(r)}else if(this.props.initialCroppedAreaPixels){const{crop:i,zoom:r}=Lt(this.props.initialCroppedAreaPixels,this.mediaSize,this.props.rotation,t,this.props.minZoom,this.props.maxZoom);this.props.onCropChange(i),this.props.onZoomChange&&this.props.onZoomChange(r)}},this.computeSizes=({isResizeTriggered:t=!1}={})=>{const i=this.imageRef.current||this.videoRef.current;if(i&&this.containerRef){var r,n,s,a,h,c;this.containerRect=this.containerRef.getBoundingClientRect(),this.saveContainerPosition();const p=this.containerRect.width/this.containerRect.height,f=((r=this.imageRef.current)===null||r===void 0?void 0:r.naturalWidth)||((n=this.videoRef.current)===null||n===void 0?void 0:n.videoWidth)||0,y=((s=this.imageRef.current)===null||s===void 0?void 0:s.naturalHeight)||((a=this.videoRef.current)===null||a===void 0?void 0:a.videoHeight)||0,b=i.offsetWidth<f||i.offsetHeight<y,S=f/y;let C;if(b)switch(this.state.mediaObjectFit){default:case"contain":C=p>S?{width:this.containerRect.height*S,height:this.containerRect.height}:{width:this.containerRect.width,height:this.containerRect.width/S};break;case"horizontal-cover":C={width:this.containerRect.width,height:this.containerRect.width/S};break;case"vertical-cover":C={width:this.containerRect.height*S,height:this.containerRect.height};break}else C={width:i.offsetWidth,height:i.offsetHeight};this.mediaSize=d(d({},C),{},{naturalWidth:f,naturalHeight:y}),this.props.setMediaSize&&this.props.setMediaSize(this.mediaSize);const v=this.props.cropSize?this.props.cropSize:At(this.mediaSize.width,this.mediaSize.height,this.containerRect.width,this.containerRect.height,this.props.aspect,this.props.rotation);return(((h=this.state.cropSize)===null||h===void 0?void 0:h.height)!==v.height||((c=this.state.cropSize)===null||c===void 0?void 0:c.width)!==v.width)&&this.props.onCropSizeChange&&this.props.onCropSizeChange(v),this.setState({cropSize:v},()=>this.recomputeCropPosition({isResizeTriggered:t})),this.props.setCropSize&&this.props.setCropSize(v),v}},this.saveContainerPosition=()=>{if(this.containerRef){const t=this.containerRef.getBoundingClientRect();this.containerPosition={x:t.left,y:t.top}}},this.onMouseDown=t=>{this.currentDoc&&(t.preventDefault(),this.currentDoc.addEventListener("mousemove",this.onMouseMove),this.currentDoc.addEventListener("mouseup",this.onDragStopped),this.saveContainerPosition(),this.onDragStart(x.getMousePoint(t),"mouse"))},this.onMouseMove=t=>this.onDrag(x.getMousePoint(t)),this.onScroll=t=>{this.currentDoc&&(t.preventDefault(),this.saveContainerPosition())},this.onTouchStart=t=>{this.currentDoc&&(this.isTouching=!0,!(this.props.onTouchRequest&&!this.props.onTouchRequest(t))&&(this.currentDoc.addEventListener("touchmove",this.onTouchMove,{passive:!1}),this.currentDoc.addEventListener("touchend",this.onDragStopped),this.saveContainerPosition(),t.touches.length===2?this.onPinchStart(t):t.touches.length===1&&this.onDragStart(x.getTouchPoint(t.touches[0]),"touch")))},this.onTouchMove=t=>{t.preventDefault(),t.touches.length===2?this.onPinchMove(t):t.touches.length===1&&this.onDrag(x.getTouchPoint(t.touches[0]))},this.onGestureStart=t=>{this.currentDoc&&(t.preventDefault(),this.currentDoc.addEventListener("gesturechange",this.onGestureChange),this.currentDoc.addEventListener("gestureend",this.onGestureEnd),this.gestureZoomStart=this.props.zoom,this.gestureRotationStart=this.props.rotation)},this.onGestureChange=t=>{if(t.preventDefault(),this.isTouching)return;const i=x.getMousePoint(t),r=this.gestureZoomStart-1+t.scale;if(this.setNewZoom(r,i,{shouldUpdatePosition:!0}),this.props.onRotationChange){const n=this.gestureRotationStart+t.rotation;this.props.onRotationChange(n)}},this.onGestureEnd=t=>{this.cleanEvents()},this.onDragStart=({x:t,y:i},r)=>{var n,s;this.dragStartPosition={x:t,y:i},this.dragStartCrop=d({},this.props.crop),this.dragInteractionSource=r,(n=(s=this.props).onInteractionStart)===null||n===void 0||n.call(s,{source:r})},this.onDrag=({x:t,y:i})=>{this.currentWindow&&(this.rafDragTimeout&&this.currentWindow.cancelAnimationFrame(this.rafDragTimeout),this.rafDragTimeout=this.currentWindow.requestAnimationFrame(()=>{if(!this.state.cropSize||t===void 0||i===void 0)return;const r=t-this.dragStartPosition.x,n=i-this.dragStartPosition.y,s={x:this.dragStartCrop.x+r,y:this.dragStartCrop.y+n},a=this.props.restrictPosition?M(s,this.mediaSize,this.state.cropSize,this.props.zoom,this.props.rotation):s;this.props.onCropChange(a)}))},this.onDragStopped=()=>{var t,i,r;this.isTouching=!1,this.cleanEvents(),this.emitCropData(),(t=(i=this.props).onInteractionEnd)===null||t===void 0||t.call(i,{source:(r=this.dragInteractionSource)!==null&&r!==void 0?r:"mouse"}),this.dragInteractionSource=null},this.onWheel=t=>{if(!this.currentWindow||this.props.onWheelRequest&&!this.props.onWheelRequest(t))return;t.preventDefault();const i=x.getMousePoint(t),{pixelY:r}=Pt(t),n=this.props.zoom-r*this.props.zoomSpeed/200;this.setNewZoom(n,i,{shouldUpdatePosition:!0}),this.state.hasWheelJustStarted||this.setState({hasWheelJustStarted:!0},()=>{var s,a;return(s=(a=this.props).onInteractionStart)===null||s===void 0?void 0:s.call(a,{source:"wheel"})}),this.wheelTimer&&clearTimeout(this.wheelTimer),this.wheelTimer=this.currentWindow.setTimeout(()=>this.setState({hasWheelJustStarted:!1},()=>{var s,a;return(s=(a=this.props).onInteractionEnd)===null||s===void 0?void 0:s.call(a,{source:"wheel"})}),250)},this.getPointOnContainer=({x:t,y:i},r)=>{if(!this.containerRect)throw new Error("The Cropper is not mounted");return{x:this.containerRect.width/2-(t-r.x),y:this.containerRect.height/2-(i-r.y)}},this.getPointOnMedia=({x:t,y:i})=>{const{crop:r,zoom:n}=this.props;return{x:(t+r.x)/n,y:(i+r.y)/n}},this.setNewZoom=(t,i,{shouldUpdatePosition:r=!0}={})=>{if(!this.state.cropSize||!this.props.onZoomChange)return;const n=I(t,this.props.minZoom,this.props.maxZoom);if(r){const s=this.getPointOnContainer(i,this.containerPosition),a=this.getPointOnMedia(s),h={x:a.x*n-s.x,y:a.y*n-s.y},c=this.props.restrictPosition?M(h,this.mediaSize,this.state.cropSize,n,this.props.rotation):h;this.props.onCropChange(c)}this.props.onZoomChange(n)},this.getCropData=()=>this.state.cropSize?Nt(this.props.restrictPosition?M(this.props.crop,this.mediaSize,this.state.cropSize,this.props.zoom,this.props.rotation):this.props.crop,this.mediaSize,this.state.cropSize,this.getAspect(),this.props.zoom,this.props.rotation,this.props.restrictPosition):null,this.emitCropData=()=>{this.resizeEmitTimer&&(clearTimeout(this.resizeEmitTimer),this.resizeEmitTimer=null);const t=this.getCropData();if(!t)return;const{croppedAreaPercentages:i,croppedAreaPixels:r}=t;this.props.onCropComplete&&this.props.onCropComplete(i,r),this.props.onCropAreaChange&&this.props.onCropAreaChange(i,r)},this.emitCropAreaChange=()=>{const t=this.getCropData();if(!t)return;const{croppedAreaPercentages:i,croppedAreaPixels:r}=t;this.props.onCropAreaChange&&this.props.onCropAreaChange(i,r)},this.recomputeCropPosition=({isResizeTriggered:t=!1}={})=>{var i,r;if(!this.state.cropSize)return;let n=this.props.crop;if(this.isInitialized&&(!((i=this.previousCropSize)===null||i===void 0)&&i.width)&&(!((r=this.previousCropSize)===null||r===void 0)&&r.height)&&(Math.abs(this.previousCropSize.width-this.state.cropSize.width)>1e-6||Math.abs(this.previousCropSize.height-this.state.cropSize.height)>1e-6)){const a=this.state.cropSize.width/this.previousCropSize.width,h=this.state.cropSize.height/this.previousCropSize.height;n={x:this.props.crop.x*a,y:this.props.crop.y*h}}const s=this.props.restrictPosition?M(n,this.mediaSize,this.state.cropSize,this.props.zoom,this.props.rotation):n;this.previousCropSize=this.state.cropSize,this.props.onCropChange(s),t?this.debouncedEmitCropData():this.emitCropData()},this.debouncedEmitCropData=()=>{this.currentWindow&&(this.resizeEmitTimer&&clearTimeout(this.resizeEmitTimer),this.resizeEmitTimer=this.currentWindow.setTimeout(()=>{this.emitCropData()},Bt))},this.onKeyDown=t=>{const{crop:i,onCropChange:r,keyboardStep:n,zoom:s,rotation:a}=this.props;let h=n;if(!this.state.cropSize)return;t.shiftKey&&(h*=.2);let c=d({},i);switch(t.key){case"ArrowUp":c.y-=h,t.preventDefault();break;case"ArrowDown":c.y+=h,t.preventDefault();break;case"ArrowLeft":c.x-=h,t.preventDefault();break;case"ArrowRight":c.x+=h,t.preventDefault();break;default:return}if(this.props.restrictPosition&&(c=M(c,this.mediaSize,this.state.cropSize,s,a)),!t.repeat){var p,f;(p=(f=this.props).onInteractionStart)===null||p===void 0||p.call(f,{source:"keyboard"})}r(c)},this.onKeyUp=t=>{var i,r;switch(t.key){case"ArrowUp":case"ArrowDown":case"ArrowLeft":case"ArrowRight":t.preventDefault();break;default:return}this.emitCropData(),(i=(r=this.props).onInteractionEnd)===null||i===void 0||i.call(r,{source:"keyboard"})}}componentDidMount(){!this.currentDoc||!this.currentWindow||(this.containerRef&&(this.containerRef.ownerDocument&&(this.currentDoc=this.containerRef.ownerDocument),this.currentDoc.defaultView&&(this.currentWindow=this.currentDoc.defaultView),this.initResizeObserver(),typeof window.ResizeObserver>"u"&&this.currentWindow.addEventListener("resize",this.onWindowResize),this.props.zoomWithScroll&&this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}),this.containerRef.addEventListener("gesturestart",this.onGestureStart)),this.currentDoc.addEventListener("scroll",this.onScroll),this.props.disableAutomaticStylesInjection||(this.styleRef=this.currentDoc.createElement("style"),this.styleRef.setAttribute("type","text/css"),this.props.nonce&&this.styleRef.setAttribute("nonce",this.props.nonce),this.styleRef.innerHTML=kt,this.currentDoc.head.appendChild(this.styleRef)),this.imageRef.current&&this.imageRef.current.complete&&this.onMediaLoad(),this.props.setImageRef&&this.props.setImageRef(this.imageRef),this.props.setVideoRef&&this.props.setVideoRef(this.videoRef),this.props.setCropperRef&&this.props.setCropperRef(this.cropperRef))}componentWillUnmount(){var e;if(!(!this.currentDoc||!this.currentWindow)){if(typeof window.ResizeObserver>"u"&&this.currentWindow.removeEventListener("resize",this.onWindowResize),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),this.resizeEmitTimer&&clearTimeout(this.resizeEmitTimer),this.containerRef&&this.containerRef.removeEventListener("gesturestart",this.preventZoomSafari),this.styleRef){var t;(t=this.styleRef.parentNode)===null||t===void 0||t.removeChild(this.styleRef)}this.cleanEvents(),this.props.zoomWithScroll&&this.clearScrollEvent()}}componentDidUpdate(e){var t,i,r,n,s,a,h,c;if(e.rotation!==this.props.rotation?(this.computeSizes(),this.recomputeCropPosition()):e.aspect!==this.props.aspect?this.computeSizes():e.objectFit!==this.props.objectFit?this.computeSizes():e.zoom!==this.props.zoom?this.recomputeCropPosition():((t=e.cropSize)===null||t===void 0?void 0:t.height)!==((i=this.props.cropSize)===null||i===void 0?void 0:i.height)||((r=e.cropSize)===null||r===void 0?void 0:r.width)!==((n=this.props.cropSize)===null||n===void 0?void 0:n.width)?this.computeSizes():(((s=e.crop)===null||s===void 0?void 0:s.x)!==((a=this.props.crop)===null||a===void 0?void 0:a.x)||((h=e.crop)===null||h===void 0?void 0:h.y)!==((c=this.props.crop)===null||c===void 0?void 0:c.y))&&this.emitCropAreaChange(),e.zoomWithScroll!==this.props.zoomWithScroll&&this.containerRef&&(this.props.zoomWithScroll?this.containerRef.addEventListener("wheel",this.onWheel,{passive:!1}):this.clearScrollEvent()),e.video!==this.props.video){var p;(p=this.videoRef.current)===null||p===void 0||p.load()}const f=this.getObjectFit();f!==this.state.mediaObjectFit&&this.setState({mediaObjectFit:f},this.computeSizes)}getAspect(){const{cropSize:e,aspect:t}=this.props;return e?e.width/e.height:t}getObjectFit(){if(this.props.objectFit==="cover"){if((this.imageRef.current||this.videoRef.current)&&this.containerRef){var e,t,i,r;this.containerRect=this.containerRef.getBoundingClientRect();const n=this.containerRect.width/this.containerRect.height;return(((e=this.imageRef.current)===null||e===void 0?void 0:e.naturalWidth)||((t=this.videoRef.current)===null||t===void 0?void 0:t.videoWidth)||0)/(((i=this.imageRef.current)===null||i===void 0?void 0:i.naturalHeight)||((r=this.videoRef.current)===null||r===void 0?void 0:r.videoHeight)||0)<n?"horizontal-cover":"vertical-cover"}return"horizontal-cover"}return this.props.objectFit}onPinchStart(e){const t=x.getTouchPoint(e.touches[0]),i=x.getTouchPoint(e.touches[1]);this.lastPinchDistance=et(t,i),this.lastPinchRotation=it(t,i),this.onDragStart(ot(t,i),"touch")}onPinchMove(e){if(!this.currentDoc||!this.currentWindow)return;const t=x.getTouchPoint(e.touches[0]),i=x.getTouchPoint(e.touches[1]),r=ot(t,i);this.onDrag(r),this.rafPinchTimeout&&this.currentWindow.cancelAnimationFrame(this.rafPinchTimeout),this.rafPinchTimeout=this.currentWindow.requestAnimationFrame(()=>{const n=et(t,i),s=this.props.zoom*(n/this.lastPinchDistance);this.setNewZoom(s,r,{shouldUpdatePosition:!1}),this.lastPinchDistance=n;const a=it(t,i),h=this.props.rotation+(a-this.lastPinchRotation);this.props.onRotationChange&&this.props.onRotationChange(h),this.lastPinchRotation=a})}render(){var e;const{image:t,video:i,mediaProps:r,cropperProps:n,transform:s,crop:{x:a,y:h},rotation:c,zoom:p,cropShape:f,showGrid:y,roundCropAreaPixels:b,style:{containerStyle:S,cropAreaStyle:C,mediaStyle:v},classes:{containerClassName:T,cropAreaClassName:L,mediaClassName:P}}=this.props,z=(e=this.state.mediaObjectFit)!==null&&e!==void 0?e:this.getObjectFit();return m.createElement("div",{onMouseDown:this.onMouseDown,onTouchStart:this.onTouchStart,ref:D=>this.containerRef=D,"data-testid":"container",style:S,className:O("reactEasyCrop_Container",T)},t?m.createElement("img",d(d({alt:"",className:O("reactEasyCrop_Image",z==="contain"&&"reactEasyCrop_Contain",z==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",z==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",P)},r),{},{src:t,ref:this.imageRef,style:d(d({},v),{},{transform:s||`translate(${a}px, ${h}px) rotate(${c}deg) scale(${p})`}),onLoad:this.onMediaLoad})):i&&m.createElement("video",d(d({autoPlay:!0,playsInline:!0,loop:!0,muted:!0,className:O("reactEasyCrop_Video",z==="contain"&&"reactEasyCrop_Contain",z==="horizontal-cover"&&"reactEasyCrop_Cover_Horizontal",z==="vertical-cover"&&"reactEasyCrop_Cover_Vertical",P)},r),{},{ref:this.videoRef,onLoadedMetadata:this.onMediaLoad,style:d(d({},v),{},{transform:s||`translate(${a}px, ${h}px) rotate(${c}deg) scale(${p})`}),controls:!1}),(Array.isArray(i)?i:[{src:i}]).map(D=>m.createElement("source",d({key:D.src},D)))),this.state.cropSize&&m.createElement("div",d({ref:this.cropperRef,style:d(d({},C),{},{width:b?Math.round(this.state.cropSize.width):this.state.cropSize.width,height:b?Math.round(this.state.cropSize.height):this.state.cropSize.height}),tabIndex:0,onKeyDown:this.onKeyDown,onKeyUp:this.onKeyUp,"data-testid":"cropper",className:O("reactEasyCrop_CropArea",f==="round"&&"reactEasyCrop_CropAreaRound",y&&"reactEasyCrop_CropAreaGrid",L)},n)))}};F.defaultProps={zoom:1,rotation:0,aspect:4/3,maxZoom:Gt,minZoom:Ut,cropShape:"rect",objectFit:"contain",showGrid:!0,style:{},classes:{},mediaProps:{},cropperProps:{},zoomSpeed:1,restrictPosition:!0,zoomWithScroll:!0,keyboardStep:Ht};F.getMousePoint=o=>({x:Number(o.clientX),y:Number(o.clientY)});F.getTouchPoint=o=>({x:Number(o.clientX),y:Number(o.clientY)});var Xt=F;function Yt(o){return new Promise((e,t)=>{const i=new Image;i.addEventListener("load",()=>e(i)),i.addEventListener("error",r=>t(r)),i.crossOrigin="anonymous",i.src=o})}const Kt=2400;async function Vt(o,e,t="image/png"){const i=await Yt(o),r=document.createElement("canvas"),n=Math.min(1,Kt/Math.max(e.width,e.height));return r.width=Math.round(e.width*n),r.height=Math.round(e.height*n),r.getContext("2d").drawImage(i,e.x,e.y,e.width,e.height,0,0,r.width,r.height),new Promise((a,h)=>{r.toBlob(c=>{if(!c){h(new Error("Zuschneiden fehlgeschlagen"));return}a(c)},t,t==="image/png"?void 0:.85)})}function qt(o){return o==="image/jpeg"?"jpg":o==="image/webp"?"webp":"png"}function $t({value:o,onChange:e,label:t="Bild",aspect:i}){const[r,n]=m.useState(!1),[s,a]=m.useState(""),[h,c]=m.useState(null),[p,f]=m.useState("image/png"),[y,b]=m.useState({x:0,y:0}),[S,C]=m.useState(1),[v,T]=m.useState(null),[L,P]=m.useState(i||1),z=l=>{f(l.type||"image/png"),b({x:0,y:0}),C(1),T(null),P(i||1),c(URL.createObjectURL(l))},D=l=>{var A;const w=(A=l.target.files)==null?void 0:A[0];l.target.value="",w&&(a(""),z(w))},ut=async()=>{if(o){a("");try{const w=await(await fetch(o)).blob();z(w)}catch{a("Bild konnte nicht zum Zuschneiden geladen werden.")}}},lt=({width:l,height:w})=>{!i&&l&&w&&P(l/w)},K=()=>{h&&URL.revokeObjectURL(h),c(null)},dt=async()=>{if(!(!h||!v)){n(!0),a("");try{const l=await Vt(h,v,p);if(l.size>gt)throw new Error(`Das Bild ist auch nach dem Verkleinern noch ${vt(l.size)} groß (max. 5 MB). Bitte als JPG statt PNG speichern oder einen kleineren Ausschnitt wählen.`);const w=new FormData;w.append("file",l,`zugeschnitten.${qt(p)}`);const A=await ft.post("/uploads",w);e(A.path),K()}catch(l){a(l.message)}finally{n(!1)}}};return u.jsxs("div",{children:[u.jsx("label",{className:"mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300",children:t}),u.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[o&&u.jsxs("div",{className:"relative",children:[u.jsx("img",{src:o,alt:"",className:"h-12 w-12 rounded-md object-cover"}),u.jsx("button",{type:"button",onClick:()=>e(null),title:"Bild entfernen","aria-label":"Bild entfernen",className:"absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full bg-red-600 text-xs font-bold leading-none text-white shadow hover:bg-red-700",children:"×"})]}),u.jsx("input",{type:"file",accept:"image/png,image/jpeg,image/webp",onChange:D,className:"min-w-0 max-w-full text-sm"}),o&&u.jsx("button",{type:"button",onClick:ut,className:"rounded-md border border-neutral-300 px-2 py-1 text-xs font-medium text-neutral-600 hover:bg-neutral-50 dark:border-neutral-700 dark:text-neutral-300 dark:hover:bg-neutral-800",children:"Zuschneiden"}),r&&u.jsx("span",{className:"text-sm text-neutral-500",children:"Lädt hoch…"})]}),u.jsx("p",{className:"mt-1 text-xs text-neutral-400",children:"JPG, PNG oder WebP. Große Fotos werden automatisch verkleinert."}),s&&u.jsx("p",{className:"mt-1 text-sm text-red-600",children:s}),h&&u.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/70 p-4",children:u.jsxs("div",{className:"w-full max-w-lg rounded-xl bg-white p-4 dark:bg-neutral-900",children:[u.jsx("p",{className:"mb-3 text-sm font-semibold text-neutral-900 dark:text-white",children:"Bild zuschneiden"}),u.jsx("div",{className:"relative h-80 w-full overflow-hidden rounded-md bg-neutral-800 sm:h-96",children:u.jsx(Xt,{image:h,crop:y,zoom:S,aspect:L,onCropChange:b,onZoomChange:C,onCropComplete:(l,w)=>T(w),onMediaLoaded:lt})}),u.jsx("input",{type:"range",min:1,max:3,step:.01,value:S,onChange:l=>C(Number(l.target.value)),className:"mt-4 w-full"}),s&&u.jsx("p",{className:"mt-2 text-sm text-red-600",children:s}),u.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[u.jsx("button",{type:"button",onClick:K,disabled:r,className:"rounded-md border border-neutral-300 px-4 py-2 text-sm dark:border-neutral-700",children:"Abbrechen"}),u.jsx("button",{type:"button",onClick:dt,disabled:r||!v,className:"rounded-md bg-brand-500 px-4 py-2 text-sm font-semibold text-white hover:bg-brand-600 disabled:opacity-50",children:r?"Lädt hoch…":"Übernehmen"})]})]})})]})}export{$t as default};