@antontranelis/money-printer 1.0.45 → 1.0.47
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/index.cjs +2 -2
- package/dist/index.d.ts +17 -0
- package/dist/index.js +717 -659
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react/jsx-runtime"),f=require("react"),_t=require("zustand"),Ot=require("zustand/middleware"),$t=require("jspdf");var ge=typeof document<"u"?document.currentScript:null;function Xt(){return(typeof navigator<"u"?navigator.language:"de").toLowerCase().startsWith("de")?"de":"en"}const Ee=Xt(),tt={personalInfo:{name:"",email:"",phone:""},voucherConfig:{hours:1,description:"",language:Ee,templateHue:29},portrait:{original:null,enhanced:null,useEnhanced:!1,zoom:1,panX:0,panY:0,rawImage:null,bgRemovedImage:null,bgRemoved:!1,bgOpacity:0,bgBlur:0,engravingIntensity:0},currentSide:"front",isEnhancing:!1,isExporting:!1,appLanguage:Ee},y=_t.create()(Ot.persist(e=>({...tt,setPersonalInfo:t=>e(n=>({personalInfo:{...n.personalInfo,...t}})),setVoucherConfig:t=>e(n=>({voucherConfig:{...n.voucherConfig,...t}})),setPortrait:(t,n=null)=>e(a=>({portrait:{...a.portrait,original:t,enhanced:n,useEnhanced:!1,zoom:a.portrait.original&&t?a.portrait.zoom:1,panX:a.portrait.original&&t?a.portrait.panX:0,panY:a.portrait.original&&t?a.portrait.panY:0}})),setEnhancedPortrait:t=>e(n=>({portrait:{...n.portrait,enhanced:t,useEnhanced:t!==null}})),toggleUseEnhanced:()=>e(t=>({portrait:{...t.portrait,useEnhanced:t.portrait.enhanced?!t.portrait.useEnhanced:!1}})),setPortraitZoom:t=>e(n=>({portrait:{...n.portrait,zoom:t}})),setPortraitPan:(t,n)=>e(a=>({portrait:{...a.portrait,panX:t,panY:n}})),setPortraitRawImage:t=>e(n=>({portrait:{...n.portrait,rawImage:t}})),setPortraitBgRemoved:(t,n)=>e(a=>({portrait:{...a.portrait,bgRemoved:t,bgRemovedImage:n!==void 0?n:a.portrait.bgRemovedImage}})),setPortraitBgOpacity:t=>e(n=>({portrait:{...n.portrait,bgOpacity:t}})),setPortraitBgBlur:t=>e(n=>({portrait:{...n.portrait,bgBlur:t}})),setPortraitEngravingIntensity:t=>e(n=>({portrait:{...n.portrait,engravingIntensity:t}})),setCurrentSide:t=>e({currentSide:t}),flipSide:()=>e(t=>({currentSide:t.currentSide==="front"?"back":"front"})),setIsEnhancing:t=>e({isEnhancing:t}),setIsExporting:t=>e({isExporting:t}),setAppLanguage:t=>e({appLanguage:t}),setBillLanguage:t=>e(n=>({voucherConfig:{...n.voucherConfig,language:t}})),setHours:t=>e(n=>({voucherConfig:{...n.voucherConfig,hours:t}})),setTemplateHue:t=>e(n=>({voucherConfig:{...n.voucherConfig,templateHue:t}})),reset:()=>e(tt)}),{name:"money-generator-storage",migrate:e=>{const t=e;return t!=null&&t.voucherConfig&&(t.voucherConfig.templateHue=29,t.voucherConfig.hours=1,t.voucherConfig.language=Ee),t&&(t.appLanguage=Ee),t},version:1,partialize:e=>({personalInfo:e.personalInfo,voucherConfig:{...e.voucherConfig,templateHue:29},appLanguage:e.appLanguage,portrait:{original:null,enhanced:null,useEnhanced:e.portrait.useEnhanced,zoom:e.portrait.zoom,panX:e.portrait.panX,panY:e.portrait.panY,rawImage:null,bgRemovedImage:null,bgRemoved:!1,bgOpacity:0,bgBlur:0,engravingIntensity:e.portrait.engravingIntensity},currentSide:"front",isEnhancing:!1,isExporting:!1})})),Kt={header:{title:"Money Generator",subtitle:"Erstelle deinen persönlichen Zeitgutschein"},form:{personalInfo:{title:"Persönliche Daten",name:"Name",namePlaceholder:"Dein Name",email:"E-Mail",emailPlaceholder:"deine@email.de",phone:"Telefon",phonePlaceholder:"+49 123 456789"},portrait:{title:"Portrait",upload:"Bild hochladen",dragDrop:"oder hierher ziehen",enhance:"Mit AI verbessern",enhancing:"Wird verbessert...",useOriginal:"Original verwenden",useEnhanced:"Verbessertes verwenden",zoom:"Zoom"},voucher:{title:"Gutschein",hours:"Stunden",hourLabel:"Stunde",hoursLabel:"Stunden",description:"Beschreibung",descriptionPlaceholder:"Was kann mit diesem Gutschein eingelöst werden?",billLanguage:"Schein-Sprache",billLanguageGerman:"Deutsch",billLanguageEnglish:"Englisch"},billColor:{title:"Scheinfarbe",label:"Farbton"}},preview:{front:"Vorderseite",back:"Rückseite",flip:"Umdrehen"},export:{button:"Als PDF herunterladen",exporting:"PDF wird erstellt...",success:"Download gestartet!"},bill:{descriptionText:"Für diesen Schein erhältst du {bannerText} meiner Zeit oder ein gleichwertiges Dankeschön",bannerText:{1:"eine Stunde",5:"fünf Stunden",10:"zehn Stunden"}}},qt={header:{title:"Money Generator",subtitle:"Create your personal time voucher"},form:{personalInfo:{title:"Personal Information",name:"Name",namePlaceholder:"Your name",email:"Email",emailPlaceholder:"your@email.com",phone:"Phone",phonePlaceholder:"+1 234 567890"},portrait:{title:"Portrait",upload:"Upload image",dragDrop:"or drag and drop",enhance:"Enhance with AI",enhancing:"Enhancing...",useOriginal:"Use original",useEnhanced:"Use enhanced",zoom:"Zoom"},voucher:{title:"Voucher",hours:"Hours",hourLabel:"hour",hoursLabel:"hours",description:"Description",descriptionPlaceholder:"What can be redeemed with this voucher?",billLanguage:"Bill Language",billLanguageGerman:"German",billLanguageEnglish:"English"},billColor:{title:"Bill Color",label:"Hue"}},preview:{front:"Front",back:"Back",flip:"Flip"},export:{button:"Download as PDF",exporting:"Creating PDF...",success:"Download started!"},bill:{descriptionText:"This voucher entitles you to {bannerText} of my time or an equivalent thank you",bannerText:{1:"one hour",5:"five hours",10:"ten hours"}}},Vt={de:Kt,en:qt};function J(e){return Vt[e]}function qe(e,t,n){if(n&&n.trim())return n;const a=J(e),r=a.bill.bannerText[t]||a.bill.bannerText[1];return a.bill.descriptionText.replace("{bannerText}",r)}function Gt(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function Zt(e){return e.replace(/\D/g,"").length>=6}function Jt({focusField:e,onFocused:t}={}){const n=y(w=>w.appLanguage),a=y(w=>w.personalInfo),r=y(w=>w.setPersonalInfo),l=J(n),[c,i]=f.useState(!1),[s,d]=f.useState(!1),p=c&&a.email.trim()&&!Gt(a.email),x=s&&a.phone.trim()&&!Zt(a.phone),h=f.useRef(null),b=f.useRef(null),v=f.useRef(null);return f.useEffect(()=>{if(e){const w=e==="name"?h:e==="email"?b:v;setTimeout(()=>{var u,k;(u=w.current)==null||u.click(),(k=w.current)==null||k.focus(),t==null||t()},100)}},[e,t]),o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{className:"form-control",children:[o.jsx("label",{className:"label",children:o.jsx("span",{className:"label-text font-medium",children:l.form.personalInfo.name})}),o.jsx("input",{ref:h,type:"text",name:"name",autoComplete:"name",placeholder:l.form.personalInfo.namePlaceholder,className:"input input-bordered w-full input-lg sm:input-md",value:a.name,onChange:w=>r({name:w.target.value})})]}),o.jsxs("div",{className:"form-control",children:[o.jsx("label",{className:"label",children:o.jsx("span",{className:"label-text font-medium",children:l.form.personalInfo.email})}),o.jsx("input",{ref:b,type:"email",name:"email",autoComplete:"email",placeholder:l.form.personalInfo.emailPlaceholder,className:`input input-bordered w-full input-lg sm:input-md ${p?"input-error":""}`,value:a.email,onChange:w=>r({email:w.target.value}),onBlur:()=>i(!0)}),p&&o.jsx("label",{className:"label",children:o.jsx("span",{className:"label-text-alt text-error",children:n==="de"?"Bitte gib eine gültige E-Mail-Adresse ein":"Please enter a valid email address"})})]}),o.jsxs("div",{className:"form-control",children:[o.jsx("label",{className:"label",children:o.jsx("span",{className:"label-text font-medium",children:l.form.personalInfo.phone})}),o.jsx("input",{ref:v,type:"tel",name:"phone",autoComplete:"tel",placeholder:l.form.personalInfo.phonePlaceholder,className:`input input-bordered w-full input-lg sm:input-md ${x?"input-error":""}`,value:a.phone,onChange:w=>r({phone:w.target.value}),onBlur:()=>d(!0)}),x&&o.jsx("label",{className:"label",children:o.jsx("span",{className:"label-text-alt text-error",children:n==="de"?"Bitte gib eine gültige Telefonnummer ein":"Please enter a valid phone number"})})]})]})}const Qt=1024,ce=new Map;let K=null,nt=null;function Ve(e,t){return K||(K=document.createElement("canvas"),nt=K.getContext("2d",{willReadFrequently:!0})),(K.width!==e||K.height!==t)&&(K.width=e,K.height=t),nt}function we(e){const t=ce.get(e);return t?Promise.resolve(t):new Promise((n,a)=>{const r=new Image;r.onload=()=>{if(ce.size>10){const l=ce.keys().next().value;l&&ce.delete(l)}ce.set(e,r),n(r)},r.onerror=()=>a(new Error("Failed to load image")),r.src=e})}function en(){ce.clear()}async function st(e,t=Qt){const n=await we(e),a=Math.max(n.width,n.height);if(a<=t)return e;const r=t/a,l=Math.round(n.width*r),c=Math.round(n.height*r),i=document.createElement("canvas"),s=i.getContext("2d");if(!s)throw new Error("Failed to get canvas context");return i.width=l,i.height=c,s.drawImage(n,0,0,l,c),i.toDataURL("image/jpeg",.9)}async function Ue(e,t,n,a=0){const[r,l]=await Promise.all([we(e),we(t)]),c=Ve(r.width,r.height);if(c.clearRect(0,0,r.width,r.height),n>0){const i=a*20;c.save(),c.globalAlpha=n,i>0&&(c.filter=`blur(${i}px)`),c.drawImage(l,0,0,r.width,r.height),c.restore()}return c.drawImage(r,0,0),K.toDataURL("image/png")}async function lt(e,t=.5,n=40){const a=await we(e),r=Ve(a.width,a.height);r.clearRect(0,0,a.width,a.height),r.drawImage(a,0,0);const l=r.getImageData(0,0,a.width,a.height),c=l.data,i=new Uint32Array(c.buffer),s=1+t*.8,d=1-t,p=n%360/360;for(let x=0;x<i.length;x++){const h=i[x],b=h&255,v=h>>8&255,w=h>>16&255,u=h>>24&255;if(u===0)continue;let T=(((77*b+150*v+29*w>>8)/255-.5)*s+.5)*255;T<0?T=0:T>255&&(T=255);const D=T/255,j=.12,[B,M,A]=ct(p,j,D),L=b*d+B*t|0,P=v*d+M*t|0,C=w*d+A*t|0;i[x]=u<<24|C<<16|P<<8|L}return r.putImageData(l,0,0),K.toDataURL("image/png")}function tn(e,t,n){e/=255,t/=255,n/=255;const a=Math.max(e,t,n),r=Math.min(e,t,n),l=(a+r)/2;let c=0,i=0;if(a!==r){const s=a-r;switch(i=l>.5?s/(2-a-r):s/(a+r),a){case e:c=((t-n)/s+(t<n?6:0))/6;break;case t:c=((n-e)/s+2)/6;break;case n:c=((e-t)/s+4)/6;break}}return[c,i,l]}function ct(e,t,n){if(t===0){const c=Math.round(n*255);return[c,c,c]}const a=(c,i,s)=>(s<0&&(s+=1),s>1&&(s-=1),s<1/6?c+(i-c)*6*s:s<1/2?i:s<2/3?c+(i-c)*(2/3-s)*6:c),r=n<.5?n*(1+t):n+t-n*t,l=2*n-r;return[Math.round(a(l,r,e+1/3)*255),Math.round(a(l,r,e)*255),Math.round(a(l,r,e-1/3)*255)]}const nn=29,an=5;async function dt(e,t){if(Math.abs(t-nn)<=an)return e;const n=await we(e),a=Ve(n.width,n.height);a.clearRect(0,0,n.width,n.height),a.drawImage(n,0,0);const r=a.getImageData(0,0,n.width,n.height),l=r.data,c=new Uint32Array(l.buffer),i=t%360/360,s=20/360,d=45/360,p=c.length;for(let x=0;x<p;x++){const h=c[x],b=h&255,v=h>>8&255,w=h>>16&255,u=h>>24&255;if(u===0)continue;const[k,T,D]=tn(b,v,w);if(T<.08||k<s||k>d)continue;const j=i,B=Math.min(T,.05),[M,A,L]=ct(j,B,D);c[x]=u<<24|L<<16|A<<8|M}return a.putImageData(r,0,0),K.toDataURL("image/png")}const rn="https://api.stability.ai/v1/generation",on="https://api.stability.ai/v2beta/stable-image/edit/remove-background",ut="stability_api_key";let he=null;function sn(e){he=e}function ln(){return he}function cn(){return he!==null}const dn={vintage:"portrait in the style of vintage currency engraving, fine line work, crosshatching, sepia tones, detailed stippling, classic bank note portrait style",engraved:"portrait as detailed intaglio engraving, currency bill style, fine parallel lines, high contrast, official government portrait",currency:"portrait rendered as US dollar bill engraving, official currency portrait style, green tint, fine line engraving technique"},at=[{width:1024,height:1024},{width:1152,height:896},{width:1216,height:832},{width:1344,height:768},{width:1536,height:640},{width:640,height:1536},{width:768,height:1344},{width:832,height:1216},{width:896,height:1152}];function un(e,t){const n=e/t;let a=at[0],r=1/0;for(const l of at){const c=l.width/l.height,i=Math.abs(n-c);i<r&&(r=i,a=l)}return a}function gn(e){return new Promise((t,n)=>{const a=new Image;a.onload=()=>{const r=un(a.width,a.height),l=document.createElement("canvas");l.width=r.width,l.height=r.height;const c=l.getContext("2d");if(!c){n(new Error("Failed to get canvas context"));return}const i=a.width/a.height,s=r.width/r.height;let d=0,p=0,x=a.width,h=a.height;i>s?(x=a.height*s,d=(a.width-x)/2):(h=a.width/s,p=(a.height-h)/2),c.drawImage(a,d,p,x,h,0,0,r.width,r.height),t(l.toDataURL("image/png"))},a.onerror=()=>n(new Error("Failed to load image")),a.src=e})}function gt(e){var c;const t=e.split(","),n=((c=t[0].match(/:(.*?);/))==null?void 0:c[1])||"image/png",a=atob(t[1]),r=a.length,l=new Uint8Array(r);for(let i=0;i<r;i++)l[i]=a.charCodeAt(i);return new Blob([l],{type:n})}function Se(){var t;const e=typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:ge&&ge.tagName.toUpperCase()==="SCRIPT"&&ge.src||new URL("index.cjs",document.baseURI).href}<"u"&&"sk-7mEKklrqaltdtgbX0VoZbkA8E1cl939Spn75jSIYRvp1BW0b"||typeof process<"u"&&((t=process.env)==null?void 0:t.NEXT_PUBLIC_STABILITY_API_KEY);return e&&e!=="your-api-key-here"?e:typeof localStorage<"u"?localStorage.getItem(ut):null}function mt(e){localStorage.setItem(ut,e)}function Te(){return he?!0:Se()!==null}async function mn(e){const t=Se();if(!t)throw new Error("No Stability AI API key configured");const{imageDataUrl:n,style:a,strength:r=.35}=e,l=await gn(n),c=gt(l),i=new FormData;i.append("init_image",c,"portrait.png"),i.append("init_image_mode","IMAGE_STRENGTH"),i.append("image_strength",String(1-r)),i.append("text_prompts[0][text]",dn[a]),i.append("text_prompts[0][weight]","1"),i.append("cfg_scale","7"),i.append("samples","1"),i.append("steps","30");const d=await fetch(`${rn}/stable-diffusion-xl-1024-v1-0/image-to-image`,{method:"POST",headers:{Authorization:`Bearer ${t}`,Accept:"application/json"},body:i});if(!d.ok){const x=await d.text();throw console.error("Stability AI error:",x),d.status===401?new Error("Invalid API key"):d.status===402?new Error("Insufficient credits"):d.status===429?new Error("Rate limit exceeded. Please try again later."):new Error(`API error: ${d.status}`)}const p=await d.json();if(!p.artifacts||p.artifacts.length===0)throw new Error("No image generated");return`data:image/png;base64,${p.artifacts[0].base64}`}async function pt(e){if(he){const c=await fetch(he,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({imageDataUrl:e})});if(!c.ok){const s=await c.json().catch(()=>({}));throw new Error(s.error||`API error: ${c.status}`)}return(await c.json()).imageDataUrl}const t=Se();if(!t)throw new Error("No Stability AI API key configured");const n=gt(e),a=new FormData;a.append("image",n,"image.png"),a.append("output_format","png");const r=await fetch(on,{method:"POST",headers:{Authorization:`Bearer ${t}`,Accept:"image/*"},body:a});if(!r.ok){const c=await r.text();throw console.error("Stability AI remove background error:",c),r.status===401?new Error("Invalid API key"):r.status===402?new Error("Insufficient credits"):r.status===429?new Error("Rate limit exceeded. Please try again later."):new Error(`API error: ${r.status}`)}const l=await r.blob();return new Promise((c,i)=>{const s=new FileReader;s.onload=()=>c(s.result),s.onerror=()=>i(new Error("Failed to read result")),s.readAsDataURL(l)})}function pn(){const[e,t]=f.useState(!1),[n,a]=f.useState(!1),[r,l]=f.useState(null),[c,i]=f.useState(()=>Te());f.useEffect(()=>{i(Te());const h=setTimeout(()=>{i(Te())},150);return()=>clearTimeout(h)},[]);const s=f.useCallback(()=>l(null),[]),d=f.useCallback(h=>{mt(h),i(!0),l(null)},[]),p=f.useCallback(async(h,b=.5,v=40)=>{t(!0),l(null);try{return await lt(h,b,v)}catch(w){const u=w instanceof Error?w.message:"Enhancement failed";throw l(u),w}finally{t(!1)}},[]),x=f.useCallback(async h=>{a(!0),l(null);try{return await pt(h)}catch(b){const v=b instanceof Error?b.message:"Background removal failed";throw l(v),b}finally{a(!1)}},[]);return{enhance:p,removeBg:x,isEnhancing:e,isRemovingBg:n,error:r,hasKey:c,setApiKey:d,clearError:s}}function ht({isOpen:e,onClose:t,onSubmit:n}){const a=y(d=>d.appLanguage),[r,l]=f.useState("");if(!e)return null;const c=d=>{d.preventDefault(),r.trim()&&(n(r.trim()),l(""),t())},s={de:{title:"Stability AI API Key",description:"Um die AI-Bildverbesserung zu nutzen, benötigst du einen Stability AI API Key. Du kannst ihn auf platform.stability.ai erhalten.",placeholder:"sk-...",submit:"Speichern",cancel:"Abbrechen",hint:"Der Key wird lokal in deinem Browser gespeichert."},en:{title:"Stability AI API Key",description:"To use AI image enhancement, you need a Stability AI API key. You can get one at platform.stability.ai.",placeholder:"sk-...",submit:"Save",cancel:"Cancel",hint:"The key is stored locally in your browser."}}[a];return o.jsxs("dialog",{className:"modal modal-open",children:[o.jsxs("div",{className:"modal-box",children:[o.jsx("h3",{className:"font-bold text-lg",children:s.title}),o.jsx("p",{className:"py-4 text-sm opacity-80",children:s.description}),o.jsxs("form",{onSubmit:c,children:[o.jsxs("div",{className:"form-control",children:[o.jsx("input",{type:"password",placeholder:s.placeholder,className:"input input-bordered w-full",value:r,onChange:d=>l(d.target.value),autoFocus:!0}),o.jsx("label",{className:"label",children:o.jsx("span",{className:"label-text-alt",children:s.hint})})]}),o.jsxs("div",{className:"modal-action",children:[o.jsx("button",{type:"button",className:"btn btn-ghost",onClick:t,children:s.cancel}),o.jsx("button",{type:"submit",className:"btn btn-primary",disabled:!r.trim(),children:s.submit})]})]})]}),o.jsx("form",{method:"dialog",className:"modal-backdrop",children:o.jsx("button",{onClick:t,children:"close"})})]})}function hn(){const e=y(g=>g.appLanguage),t=y(g=>g.portrait),n=y(g=>g.setPortrait),a=y(g=>g.setPortraitZoom),r=y(g=>g.setPortraitPan),l=y(g=>g.setPortraitRawImage),c=y(g=>g.setPortraitBgRemoved),i=y(g=>g.setPortraitBgOpacity),s=y(g=>g.setPortraitBgBlur),d=y(g=>g.setPortraitEngravingIntensity),{enhance:p,removeBg:x,isEnhancing:h,isRemovingBg:b,error:v,hasKey:w,setApiKey:u}=pn(),k=J(e),T=f.useRef(null),[D,j]=f.useState(!1),[B,M]=f.useState(!1),A=f.useRef(null),L=f.useRef(null),P=t.rawImage,C=t.bgRemovedImage,R=t.bgRemoved,q=t.bgOpacity,te=t.bgBlur,G=t.engravingIntensity;f.useEffect(()=>{t.original&&!t.rawImage&&l(t.original)},[t.original,t.rawImage,l]),f.useEffect(()=>()=>{A.current&&clearTimeout(A.current),L.current&&clearTimeout(L.current)},[]);const W=y(g=>g.voucherConfig.templateHue),Y=f.useRef(W),$=f.useCallback(async g=>{if(!g.type.startsWith("image/"))return;const I=new FileReader;I.onload=async N=>{var z;const S=(z=N.target)==null?void 0:z.result,X=await st(S);l(X),n(X),c(!1,null),d(0)},I.readAsDataURL(g)},[n,l,c,d]),ne=f.useCallback(g=>{g.preventDefault(),j(!1);const I=g.dataTransfer.files[0];I&&$(I)},[$]),Be=f.useCallback(g=>{g.preventDefault(),j(!0)},[]),fe=f.useCallback(g=>{g.preventDefault(),j(!1)},[]),Ne=()=>{var g;(g=T.current)==null||g.click()},be=g=>{var N;const I=(N=g.target.files)==null?void 0:N[0];I&&$(I)},ae=f.useCallback(async(g,I,N)=>{try{return await p(g,I,N)}catch(S){return console.error("Enhancement failed:",S),g}},[p]),se=f.useCallback(async g=>{try{const I=await x(g);return c(!0,I),I}catch(I){return console.error("Background removal failed:",I),g}},[x,c]),re=f.useCallback(async()=>{const g=y.getState(),I=g.portrait,N=g.voucherConfig.templateHue;if(!I.rawImage)return;let S;I.bgRemoved&&I.bgRemovedImage?S=await Ue(I.bgRemovedImage,I.rawImage,I.bgOpacity,I.bgBlur):S=I.rawImage,I.engravingIntensity>0&&(S=await ae(S,I.engravingIntensity,N)),n(S)},[ae,n]);f.useEffect(()=>{if(Y.current===W)return;Y.current=W;const g=y.getState().portrait;g.engravingIntensity>0&&g.rawImage&&(A.current&&clearTimeout(A.current),A.current=setTimeout(re,150))},[W,re]);const ye=async()=>{if(!P)return;if(!R&&!w){M(!0);return}if(!R){const I=await se(P),N=y.getState(),S=N.portrait,X=N.voucherConfig.templateHue;let z=await Ue(I,P,S.bgOpacity,S.bgBlur);S.engravingIntensity>0&&(z=await ae(z,S.engravingIntensity,X)),n(z)}else{c(!1,null);const I=y.getState(),N=I.portrait.engravingIntensity,S=I.voucherConfig.templateHue;if(N>0){const X=await ae(P,N,S);n(X)}else n(P)}},ve=g=>{d(g),A.current&&clearTimeout(A.current),P&&(A.current=setTimeout(re,150))},xe=async g=>{if(u(g),!P)return;const I=await se(P),N=y.getState(),S=N.portrait,X=N.voucherConfig.templateHue;let z=await Ue(I,P,S.bgOpacity,S.bgBlur);S.engravingIntensity>0&&(z=await ae(z,S.engravingIntensity,X)),n(z)},V=g=>{i(g),L.current&&clearTimeout(L.current),!(!P||!C)&&(L.current=setTimeout(re,150))},ke=g=>{s(g),L.current&&clearTimeout(L.current),!(!P||!C)&&(L.current=setTimeout(re,150))},Ie=()=>{n(null),l(null),c(!1,null),i(0),s(0),d(0),en()};return o.jsxs("div",{className:"space-y-4",children:[t.original?o.jsxs("div",{className:"flex flex-col space-y-4",children:[o.jsxs("div",{className:"flex justify-between items-center w-full",children:[o.jsx("span",{className:"text-sm font-medium text-base-content/70",children:e==="de"?"Portrait-Einstellungen":"Portrait settings"}),o.jsxs("button",{className:"btn btn-xs btn-ghost text-error",onClick:Ie,children:[o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),e==="de"?"Foto entfernen":"Remove photo"]})]}),o.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 w-full",children:[o.jsxs("div",{className:"form-control w-full",children:[o.jsxs("label",{className:"label",children:[o.jsx("span",{className:"label-text",children:k.form.portrait.zoom}),o.jsxs("span",{className:"label-text-alt",children:[Math.round(t.zoom*100),"%"]})]}),o.jsx("input",{type:"range",min:"0.5",max:"2",step:"0.05",value:t.zoom,onChange:g=>{const I=parseFloat(g.target.value);a(I),I<=1&&(t.panX!==0||t.panY!==0)&&r(0,0)},className:"range range-primary range-sm touch-pan-y"})]}),o.jsxs("div",{className:"form-control w-full",children:[o.jsxs("label",{className:"label",children:[o.jsxs("span",{className:"label-text flex items-center gap-2",children:[e==="de"?"Farbanpassung":"Color adjustment",h&&o.jsx("span",{className:"loading loading-spinner loading-xs"})]}),o.jsxs("span",{className:"label-text-alt",children:[Math.round(G*100),"%"]})]}),o.jsx("input",{type:"range",min:"0",max:"1",step:"0.05",value:G,onChange:g=>ve(parseFloat(g.target.value)),className:"range range-secondary range-sm touch-pan-y",disabled:h||!P})]})]}),R?o.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 w-full",children:[o.jsxs("div",{className:"form-control w-full",children:[o.jsxs("label",{className:"label",children:[o.jsx("span",{className:"label-text",children:e==="de"?"Hintergrund":"Background"}),o.jsxs("span",{className:"label-text-alt",children:[Math.round(q*100),"%"]})]}),o.jsx("input",{type:"range",min:"0",max:"1",step:"0.05",value:q,onChange:g=>V(parseFloat(g.target.value)),className:"range range-primary range-sm touch-pan-y"})]}),o.jsxs("div",{className:"form-control w-full",children:[o.jsxs("label",{className:"label",children:[o.jsx("span",{className:"label-text",children:e==="de"?"Unschärfe":"Blur"}),o.jsxs("span",{className:"label-text-alt",children:[Math.round(te*100),"%"]})]}),o.jsx("input",{type:"range",min:"0",max:"1",step:"0.05",value:te,onChange:g=>ke(parseFloat(g.target.value)),className:"range range-primary range-sm touch-pan-y",disabled:q===0})]})]}):o.jsx("div",{className:"form-control w-fit",children:o.jsxs("label",{className:"label cursor-pointer justify-start gap-3",children:[o.jsx("input",{type:"checkbox",className:`toggle toggle-primary ${b?"opacity-50":""}`,checked:R,onChange:ye,disabled:b||!P}),o.jsxs("span",{className:"label-text flex items-center gap-2",children:[b?o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"loading loading-spinner loading-xs"}),e==="de"?"Hintergrund wird entfernt...":"Removing background..."]}):e==="de"?"Hintergrund entfernen":"Remove background",!w&&o.jsx("span",{className:"badge badge-sm badge-outline",children:"API"})]})]})}),v&&o.jsxs("div",{className:"alert alert-warning text-sm py-2",children:[o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"stroke-current shrink-0 h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),o.jsx("span",{children:v})]})]}):o.jsxs("div",{className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${b?"border-primary bg-primary/10 pointer-events-none":D?"border-primary bg-primary/10":"border-base-300 hover:border-primary hover:bg-base-200"}`,onDrop:ne,onDragOver:Be,onDragLeave:fe,onClick:Ne,children:[o.jsx("input",{ref:T,type:"file",accept:"image/*",className:"hidden",onChange:be}),b?o.jsxs("div",{className:"flex flex-col items-center gap-2",children:[o.jsx("span",{className:"loading loading-spinner loading-lg text-primary"}),o.jsx("p",{className:"font-medium",children:e==="de"?"Hintergrund wird entfernt...":"Removing background..."})]}):o.jsxs("div",{className:"flex flex-col items-center gap-2",children:[o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-12 w-12 text-base-content/50",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})}),o.jsx("p",{className:"font-medium",children:k.form.portrait.upload}),o.jsx("p",{className:"text-sm text-base-content/60",children:k.form.portrait.dragDrop})]})]}),o.jsx(ht,{isOpen:B,onClose:()=>M(!1),onSubmit:xe})]})}function fn(){const e=y(i=>i.appLanguage),t=y(i=>i.voucherConfig.language),n=y(i=>i.voucherConfig.hours);y(i=>i.voucherConfig.templateHue);const a=y(i=>i.setBillLanguage),r=y(i=>i.setHours);y(i=>i.setTemplateHue);const l=J(e),c=[1,5,10];return o.jsxs("div",{className:"space-y-4",children:[o.jsx("div",{className:"form-control",children:o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("span",{className:"label-text font-medium",children:l.form.voucher.billLanguage}),o.jsxs("div",{className:"join border border-base-300 rounded-lg",children:[o.jsx("button",{className:`join-item btn btn-md sm:btn-sm ${t==="de"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>a("de"),children:l.form.voucher.billLanguageGerman}),o.jsx("button",{className:`join-item btn btn-md sm:btn-sm ${t==="en"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>a("en"),children:l.form.voucher.billLanguageEnglish})]})]})}),o.jsx("div",{className:"form-control",children:o.jsxs("div",{className:"flex items-center justify-between gap-2",children:[o.jsx("span",{className:"label-text font-medium",children:l.form.voucher.hours}),o.jsx("div",{className:"join border border-base-300 rounded-lg",children:c.map(i=>o.jsxs("button",{className:`join-item btn btn-md sm:btn-sm ${n===i?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>r(i),children:[i,o.jsxs("span",{className:"hidden sm:inline",children:[" ",i===1?l.form.voucher.hourLabel:l.form.voucher.hoursLabel]})]},i))})]})}),!1]})}const We=new Map,le=new Map;async function E(e){return We.has(e)?We.get(e):new Promise((t,n)=>{const a=new Image;a.crossOrigin="anonymous",a.onload=()=>{We.set(e,a),t(a)},a.onerror=n,a.src=e})}function ie(e,t,n,a){e.drawImage(t,0,0,n,a)}async function ft(e,t,n,a){if(t>=155&&t<=165)return E(e);const r=`${e}:${t}:${n}x${a}`;if(le.has(r))return E(le.get(r));const l=await E(e),c=document.createElement("canvas");c.width=n,c.height=a;const i=c.getContext("2d");if(!i)throw new Error("Failed to get canvas context");i.drawImage(l,0,0,n,a);const s=c.toDataURL("image/png"),d=await dt(s,t);if(le.size>20){const p=le.keys().next().value;p&&le.delete(p)}return le.set(r,d),E(d)}function bn(e,t,n,a,r,l="de"){e.save(),e.beginPath(),e.ellipse(t,n,a,r,0,0,Math.PI*2),e.closePath(),e.setLineDash([20,10]),e.strokeStyle="rgba(100, 100, 100, 0.4)",e.lineWidth=3,e.stroke(),e.restore()}function bt(e,t,n,a,r,l,c=1,i=0,s=0){e.save(),e.beginPath(),e.ellipse(n,a,r,l,0,0,Math.PI*2),e.closePath(),e.clip();const d=t.width/t.height,p=r/l,x=r*2,h=l*2;let b,v;d>p?(v=h,b=h*d):(b=x,v=x/d),b*=c,v*=c;const w=Math.max(0,(b-x)/2),u=Math.max(0,(v-h)/2),k=n-b/2+i*w,T=a-v/2+s*u;e.drawImage(t,k,T,b,v),e.restore()}function Ge(e,t,n,a="#2a3a2a"){e.save(),e.font=`${n.fontSize}px "Times New Roman", serif`,e.textAlign=n.align||"center",e.textBaseline="middle",e.fillStyle=a,n.maxWidth?e.fillText(t,n.x,n.y,n.maxWidth):e.fillText(t,n.x,n.y),e.restore()}function xt(e,t,n,a="#2a3a2a"){e.save(),e.font=`${n.fontSize}px "Times New Roman", serif`,e.textAlign=n.align||"center",e.textBaseline="top",e.fillStyle=a;const r=n.maxWidth||400,l=n.lineHeight||n.fontSize*1.4,c=t.split(" "),i=[];let s="";for(const x of c){const h=s?`${s} ${x}`:x;e.measureText(h).width>r&&s?(i.push(s),s=x):s=h}s&&i.push(s);const d=i.length*l;let p=n.y-d/2;for(const x of i)e.fillText(x,n.x,p),p+=l;e.restore()}function wt(e,t,n,a,r,l="#2a3a2a"){e.save(),e.font=`${r.fontSize}px "Times New Roman", serif`,e.textAlign=r.align||"center",e.textBaseline="middle",e.fillStyle=l;const c=r.lineHeight||r.fontSize*1.8,i=[t,n,a].filter(Boolean),s=(i.length-1)*c;let d=r.y-s/2;for(const p of i)p&&(e.fillText(p,r.x,d),d+=c);e.restore()}function xn(e,t,n,a="#2a3a2a"){e.save(),e.strokeStyle=a,e.lineWidth=Math.max(2,t.labelFontSize/16),e.beginPath(),e.moveTo(t.x-t.width/2,t.y),e.lineTo(t.x+t.width/2,t.y),e.stroke(),e.font=`${t.labelFontSize}px "Times New Roman", serif`,e.textAlign="center",e.textBaseline="top",e.fillStyle=a,e.fillText(n,t.x,t.y+t.labelFontSize*.3),e.restore()}async function yt(e,t,n,a,r,l,c,i,s,d=1,p=0,x=0,h=0,b=1,v="de"){const w=e.getContext("2d");if(!w)return;const u=document.createElement("canvas");u.width=i,u.height=s;const k=u.getContext("2d");if(!k)return;k.clearRect(0,0,i,s);const T=await ft(t,h,i,s);ie(k,T,i,s);const D=await E(n);if(ie(k,D,i,s),r)try{const M=await E(r);bt(k,M,c.portrait.x,c.portrait.y,c.portrait.radiusX,c.portrait.radiusY,d,p,x)}catch(M){console.error("Failed to load portrait:",M)}else bn(k,c.portrait.x,c.portrait.y,c.portrait.radiusX,c.portrait.radiusY,v);const j=await E(a);ie(k,j,i,s);const B=i/3633;Et(k,b,v,B),l&&Ge(k,l,c.namePlate),e.width=i,e.height=s,w.drawImage(u,0,0)}async function vt(e,t,n,a,r,l,c,i,s,d,p,x=0,h=1,b="de"){const v=e.getContext("2d");if(!v)return;const w=document.createElement("canvas");w.width=d,w.height=p;const u=w.getContext("2d");if(!u)return;u.clearRect(0,0,d,p);const k=await ft(t,x,d,p);ie(u,k,d,p);const T=await E(n);ie(u,T,d,p);const D=await E(a);ie(u,D,d,p);const j=d/3633;if(Et(u,h,b,j),s.contactInfo&&(r||l||c)&&wt(u,r,l,c,s.contactInfo),s.description&&i&&xt(u,i,s.description),r&&Ge(u,r,s.namePlate),s.signature){const B=b==="de"?"Unterschrift":"Signature";xn(u,s.signature,B)}e.width=d,e.height=p,v.drawImage(w,0,0)}const me=typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:ge&&ge.tagName.toUpperCase()==="SCRIPT"&&ge.src||new URL("index.cjs",document.baseURI).href}<"u"&&"/"||"/",_={background:`${me}templates/background.webp`,frontFrame:`${me}templates/front_frame.webp`,backFrame:`${me}templates/back_frame.webp`},pe={1:`${me}templates/1.png`,5:`${me}templates/5.png`,10:`${me}templates/10.png`},kt={de:{banner:{1:"EINE STUNDE",5:"FÜNF STUNDEN",10:"ZEHN STUNDEN"}},en:{banner:{1:"ONE HOUR",5:"FIVE HOURS",10:"TEN HOURS"}}},Q=3633,ee=1920,Le=.5,wn=Math.round(Q*Le),yn=Math.round(ee*Le),It=320,Tt=335,F={badges:{topLeft:{x:286,y:235},topRight:{x:3340,y:230},bottomLeft:{x:282,y:1665},bottomRight:{x:3345,y:1665}},banner:{centerX:1816,centerY:3820,radius:3610,fontSize:103,color:"#2a3a2a"}},Pe=new Map,oe=new Map,Fe=new Map,_e=new Map,Oe=new Map;function Pt(e,t,n,a,r,l,c){e.save(),e.font=`900 ${l}px "Times New Roman", Georgia, serif`,e.fillStyle=c,e.textAlign="center",e.textBaseline="middle";const s=e.measureText(t).width/r,d=-Math.PI/2-s/2,p=t.split(""),x=[];for(const b of p)x.push(e.measureText(b).width);let h=d;for(let b=0;b<p.length;b++){const v=p[b],w=x[b],u=h+w/2/r,k=n+r*Math.cos(u),T=a+r*Math.sin(u);e.save(),e.translate(k,T),e.rotate(u+Math.PI/2),e.fillText(v,0,0),e.restore(),h+=w/r}e.restore()}let U={background:null,frontFrame:null,backFrame:null,badges:{1:null,5:null,10:null}};async function vn(){const[e,t,n,a,r,l]=await Promise.all([E(_.background),E(_.frontFrame),E(_.backFrame),E(pe[1]),E(pe[5]),E(pe[10])]);U={background:e,frontFrame:t,backFrame:n,badges:{1:a,5:r,10:l}}}function kn(e,t){const n=Math.round(Q*e),a=Math.round(ee*e),r=document.createElement("canvas");r.width=n,r.height=a;const l=r.getContext("2d");if(!l)throw new Error("Failed to get canvas context");l.drawImage(t,0,0,n,a);const c=e<1?.8:.95;return r.toDataURL("image/jpeg",c)}function In(e,t){const n=Math.round(Q*e),a=Math.round(ee*e),r=document.createElement("canvas");r.width=n,r.height=a;const l=r.getContext("2d");if(!l)throw new Error("Failed to get canvas context");const c=It*e,i=Tt*e,s=F.badges,d=(p,x)=>{const h=x/2,b=p.x*e-h,v=p.y*e-h;l.drawImage(t,b,v,x,x)};return d(s.topLeft,c),d(s.topRight,c),d(s.bottomLeft,i),d(s.bottomRight,i),r.toDataURL("image/png")}function Et(e,t,n,a=1){const r=kt[n].banner[t];Pt(e,r,F.banner.centerX*a,F.banner.centerY*a,F.banner.radius*a,F.banner.fontSize*a,F.banner.color)}function Ct(e,t,n,a,r,l,c){const i=Math.round(Q*a),s=Math.round(ee*a),d=document.createElement("canvas");d.width=i,d.height=s;const p=d.getContext("2d");if(!p)throw new Error("Failed to get canvas context");p.drawImage(r,0,0,i,s);{const h=It*a,b=Tt*a,v=F.badges,w=(u,k)=>{const T=k/2,D=u.x*a-T,j=u.y*a-T;p.drawImage(c,D,j,k,k)};w(v.topLeft,h),w(v.topRight,h),w(v.bottomLeft,b),w(v.bottomRight,b)}if(p.drawImage(l,0,0,i,s),n==="front"){const h=kt[t].banner[e];Pt(p,h,F.banner.centerX*a,F.banner.centerY*a,F.banner.radius*a,F.banner.fontSize*a,F.banner.color)}const x=a<1?.8:.95;return d.toDataURL("image/jpeg",x)}async function St(e,t,n){const a=`${e}-${t}-${n}`;if(Pe.has(a))return Pe.get(a);const r=U.background||await E(_.background),l=n==="front"?U.frontFrame||await E(_.frontFrame):U.backFrame||await E(_.backFrame),c=U.badges[e]||await E(pe[e]),i=Ct(e,t,n,Le,r,l,c);return Pe.set(a,i),i}async function $e(e,t,n){const a=`${e}-${t}-${n}`;if(oe.has(a))return oe.get(a);const r=U.background||await E(_.background),l=n==="front"?U.frontFrame||await E(_.frontFrame):U.backFrame||await E(_.backFrame),c=U.badges[e]||await E(pe[e]),i=Ct(e,t,n,1,r,l,c);if(oe.size>4){const s=oe.keys().next().value;s&&oe.delete(s)}return oe.set(a,i),i}function Tn(){return{width:Q,height:ee}}function Pn(){Pe.clear(),oe.clear(),Fe.clear(),_e.clear(),Oe.clear()}async function Xe(e,t,n="front",a=Le){const r=`bg-${a}`;let l=Fe.get(r);if(!l){const p=U.background||await E(_.background);l=kn(a,p),Fe.set(r,l)}const c=`badges-${e}-${a}`;let i=_e.get(c);if(!i){const p=U.badges[e]||await E(pe[e]);i=In(a,p),_e.set(c,i)}const s=`${n}-${a}`;let d=Oe.get(s);if(!d){const p=n==="front"?U.frontFrame||await E(_.frontFrame):U.backFrame||await E(_.backFrame),x=Math.round(Q*a),h=Math.round(ee*a),b=document.createElement("canvas");b.width=x,b.height=h;const v=b.getContext("2d");if(!v)throw new Error("Failed to get canvas context");v.drawImage(p,0,0,x,h),d=b.toDataURL("image/png"),Oe.set(s,d)}return{background:l,badges:i,frame:d}}async function En(){const e=[1,5,10],t=["de","en"],n=["front","back"],a=[];for(const r of e)for(const l of t)for(const c of n)a.push(St(r,l,c));await Promise.all(a)}function Ze(e,t){return{front:"",back:"",width:Q,height:ee}}const je={front:{portrait:{x:1810,y:918,radiusX:570,radiusY:605},namePlate:{x:1816,y:1765,fontSize:85,maxWidth:898,align:"center"}},back:{portrait:{x:0,y:0,radiusX:0,radiusY:0},namePlate:{x:1816,y:1770,fontSize:85,maxWidth:898,align:"center"},contactInfo:{x:898,y:939,fontSize:93,lineHeight:165,align:"center"},description:{x:2721,y:939,fontSize:85,maxWidth:1177,lineHeight:124,align:"center"},signature:{x:1820,y:1445,width:950,height:145,labelFontSize:85}}},de=je,ue=je;function Je(e){return je}const Ke=.75;function Cn(e){const t=Je(),n=Ke,a=r=>({portrait:{x:r.portrait.x*n,y:r.portrait.y*n,radiusX:r.portrait.radiusX*n,radiusY:r.portrait.radiusY*n},namePlate:{x:r.namePlate.x*n,y:r.namePlate.y*n,fontSize:r.namePlate.fontSize*n,maxWidth:r.namePlate.maxWidth?r.namePlate.maxWidth*n:void 0,lineHeight:r.namePlate.lineHeight?r.namePlate.lineHeight*n:void 0,align:r.namePlate.align},contactInfo:r.contactInfo?{x:r.contactInfo.x*n,y:r.contactInfo.y*n,fontSize:r.contactInfo.fontSize*n,maxWidth:r.contactInfo.maxWidth?r.contactInfo.maxWidth*n:void 0,lineHeight:r.contactInfo.lineHeight?r.contactInfo.lineHeight*n:void 0,align:r.contactInfo.align}:void 0,description:r.description?{x:r.description.x*n,y:r.description.y*n,fontSize:r.description.fontSize*n,maxWidth:r.description.maxWidth?r.description.maxWidth*n:void 0,lineHeight:r.description.lineHeight?r.description.lineHeight*n:void 0,align:r.description.align}:void 0,signature:r.signature?{x:r.signature.x*n,y:r.signature.y*n,width:r.signature.width*n,height:r.signature.height*n,labelFontSize:r.signature.labelFontSize*n}:void 0});return{front:a(t.front),back:a(t.back)}}function Sn(e,t){const n=Ze();return{...n,width:Math.round(n.width*Ke),height:Math.round(n.height*Ke)}}function Ln(e,t){const[n,a]=f.useState(e);return f.useEffect(()=>{const r=setTimeout(()=>a(e),t);return()=>clearTimeout(r)},[e,t]),n}function jn({onPortraitClick:e,onFileDrop:t}={}){const n=y(m=>m.appLanguage),a=y(m=>m.voucherConfig.language),r=y(m=>m.voucherConfig.hours),l=y(m=>m.voucherConfig.description),c=y(m=>m.voucherConfig.templateHue),i=y(m=>m.personalInfo),s=y(m=>m.portrait),d=y(m=>m.currentSide),p=y(m=>m.flipSide),x=y(m=>m.setPortraitPan),h=Ln(c,150),b=J(n),v=f.useRef(null),w=f.useRef(null),u=f.useRef(null),[k,T]=f.useState(!1),[D,j]=f.useState(!1),[B,M]=f.useState(!1),[A,L]=f.useState(!1),P=f.useRef(null),C=Sn(),R=Cn(),q=s.useEnhanced&&s.enhanced?s.enhanced:s.original,te=qe(a,r,l),[G,W]=f.useState(""),[Y,$]=f.useState(""),[ne,Be]=f.useState(""),[fe,Ne]=f.useState(""),[be,ae]=f.useState(""),[se,re]=f.useState(""),[ye,ve]=f.useState(!0);f.useEffect(()=>{let m=!0;ve(!0);async function H(){const[O,Z]=await Promise.all([Xe(r,a,"front"),Xe(r,a,"back")]);m&&(W(O.background),$(O.badges),Be(O.frame),Ne(Z.background),ae(Z.badges),re(Z.frame),ve(!1))}return H(),()=>{m=!1}},[r,a]),f.useEffect(()=>{!v.current||!G||!Y||!ne||yt(v.current,G,Y,ne,q,i.name,R.front,C.width,C.height,s.zoom,s.panX,s.panY,h,r,a)},[C,G,Y,ne,q,i.name,R,s.zoom,s.panX,s.panY,h,r,a]),f.useEffect(()=>{!w.current||!fe||!be||!se||vt(w.current,fe,be,se,i.name,i.email,i.phone,te,R.back,C.width,C.height,h,r,a)},[C,fe,be,se,i,te,R,h,r,a]);const xe=()=>{T(!k),p()};f.useEffect(()=>{T(d==="back")},[d]);const V=f.useCallback((m,H)=>{if(!u.current||d!=="front")return!1;const O=u.current.getBoundingClientRect(),Z=O.width/C.width,He=O.height/C.height,De=(m-O.left)/Z,Ae=(H-O.top)/He,{x:Me,y:Yt,radiusX:zt,radiusY:Ft}=R.front.portrait,Qe=(De-Me)/zt,et=(Ae-Yt)/Ft;return Qe*Qe+et*et<=1},[d,C.width,C.height,R.front.portrait]),ke=f.useCallback((m,H)=>{!s.original||s.zoom<=1||!V(m,H)||(j(!0),P.current={x:m,y:H,panX:s.panX,panY:s.panY})},[s.original,s.zoom,s.panX,s.panY,V]),Ie=f.useCallback((m,H)=>{if(!D||!P.current||!u.current)return;const O=u.current.getBoundingClientRect(),Z=3/Math.max(O.width,O.height),He=(m-P.current.x)*Z,De=(H-P.current.y)*Z,Ae=Math.max(-1,Math.min(1,P.current.panX+He)),Me=Math.max(-1,Math.min(1,P.current.panY+De));x(Ae,Me)},[D,x]),g=f.useCallback(()=>{j(!1),P.current=null},[]),I=f.useCallback((m,H)=>{!s.original&&V(m,H)&&e&&e()},[s.original,V,e]),N=m=>{V(m.clientX,m.clientY)&&(m.preventDefault(),s.original&&s.zoom>1&&ke(m.clientX,m.clientY))},S=m=>{D||I(m.clientX,m.clientY)},X=m=>{Ie(m.clientX,m.clientY),M(V(m.clientX,m.clientY))},z=()=>g(),Ht=()=>{g(),M(!1)},Dt=m=>{if(m.touches.length===1){const H=m.touches[0];s.zoom>1&&V(H.clientX,H.clientY)&&ke(H.clientX,H.clientY)}},At=m=>{m.touches.length===1&&Ie(m.touches[0].clientX,m.touches[0].clientY)},Mt=()=>g(),Ut=d==="front"&&s.original&&s.zoom>1,Wt=C.width/C.height;return o.jsxs("div",{className:"space-y-4",children:[o.jsxs("div",{className:"flex justify-between items-center",children:[o.jsxs("div",{className:"join border border-base-300 rounded-lg",children:[o.jsx("button",{className:`join-item btn btn-md sm:btn-sm ${d==="front"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>d!=="front"&&xe(),children:b.preview.front}),o.jsx("button",{className:`join-item btn btn-md sm:btn-sm ${d==="back"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>d!=="back"&&xe(),children:b.preview.back})]}),o.jsxs("button",{className:"btn btn-ghost btn-md sm:btn-sm",onClick:xe,children:[o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:o.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),o.jsx("span",{className:"hidden sm:inline",children:b.preview.flip})]})]}),o.jsxs("div",{className:"relative w-full overflow-visible",style:{aspectRatio:Wt,perspective:"1500px"},children:[ye&&o.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-base-300 rounded-lg z-10",children:o.jsx("span",{className:"loading loading-spinner loading-lg text-primary"})}),o.jsxs("div",{ref:u,className:`relative w-full h-full shadow-lg ${B&&Ut?D?"cursor-grabbing":"cursor-grab":""} ${ye?"opacity-0":"opacity-100"} transition-opacity duration-300`,style:{transformStyle:"preserve-3d",transition:"transform 0.6s ease-in-out, opacity 0.3s ease-in-out",transform:k?"rotateY(180deg)":"rotateY(0deg)"},onClick:S,onMouseDown:N,onMouseMove:X,onMouseUp:z,onMouseLeave:Ht,onTouchStart:Dt,onTouchMove:At,onTouchEnd:Mt,children:[o.jsx("canvas",{ref:v,className:"absolute inset-0 w-full h-full",style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"}}),o.jsx("canvas",{ref:w,className:"absolute inset-0 w-full h-full",style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden",transform:"rotateY(180deg)"}}),!s.original&&d==="front"&&(e||t)&&o.jsx("div",{className:`absolute flex flex-col items-center justify-center cursor-pointer transition-colors duration-300 ease-in-out ${A?"bg-primary/20":"hover:bg-base-content/5"}`,style:{left:`${(R.front.portrait.x-R.front.portrait.radiusX)/C.width*100}%`,top:`${(R.front.portrait.y-R.front.portrait.radiusY)/C.height*100}%`,width:`${R.front.portrait.radiusX*2/C.width*100}%`,height:`${R.front.portrait.radiusY*2/C.height*100}%`,borderRadius:"50%",backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"},onClick:m=>{m.stopPropagation(),e==null||e()},onDragOver:m=>{m.preventDefault(),m.stopPropagation(),L(!0)},onDragLeave:m=>{m.preventDefault(),m.stopPropagation(),L(!1)},onDrop:m=>{m.preventDefault(),m.stopPropagation(),L(!1);const H=m.dataTransfer.files[0];H&&H.type.startsWith("image/")&&t&&t(H)},children:o.jsxs("button",{className:"btn btn-dash hover:btn-dash hover:border-base-content/60 flex flex-col items-center gap-1 h-auto py-3 px-4 bg-base-100/20 hover:bg-base-100/30",onClick:m=>{m.stopPropagation(),e==null||e()},children:[o.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-11 h-10 text-base-content/50",fill:"none",viewBox:"0 0 26 24",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsx("circle",{cx:"11",cy:"8",r:"4"}),o.jsx("path",{d:"M3 21c0-4 4-6 8-6s8 2 8 6"}),o.jsx("line",{x1:"22",y1:"4",x2:"22",y2:"10",strokeWidth:2}),o.jsx("line",{x1:"19",y1:"7",x2:"25",y2:"7",strokeWidth:2})]}),o.jsx("span",{className:"text-xs",children:n==="de"?"Foto hochladen":"Upload photo"})]})})]})]})]})}function Rn(){const e=f.useRef(null),t=f.useRef(null);return{frontCanvasRef:e,backCanvasRef:t}}const Bn=`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),g=require("react"),Ot=require("zustand"),$t=require("zustand/middleware"),Xt=require("jspdf");var ge=typeof document<"u"?document.currentScript:null;function Kt(){return(typeof navigator<"u"?navigator.language:"de").toLowerCase().startsWith("de")?"de":"en"}const Se=Kt(),nt={personalInfo:{name:"",email:"",phone:""},voucherConfig:{hours:1,description:"",language:Se,templateHue:29},portrait:{original:null,enhanced:null,useEnhanced:!1,zoom:1,panX:0,panY:0,rawImage:null,bgRemovedImage:null,bgRemoved:!1,bgOpacity:0,bgBlur:0,engravingIntensity:0},currentSide:"front",isEnhancing:!1,isExporting:!1,appLanguage:Se},v=Ot.create()($t.persist(e=>({...nt,setPersonalInfo:t=>e(n=>({personalInfo:{...n.personalInfo,...t}})),setVoucherConfig:t=>e(n=>({voucherConfig:{...n.voucherConfig,...t}})),setPortrait:(t,n=null)=>e(a=>({portrait:{...a.portrait,original:t,enhanced:n,useEnhanced:!1,zoom:a.portrait.original&&t?a.portrait.zoom:1,panX:a.portrait.original&&t?a.portrait.panX:0,panY:a.portrait.original&&t?a.portrait.panY:0}})),setEnhancedPortrait:t=>e(n=>({portrait:{...n.portrait,enhanced:t,useEnhanced:t!==null}})),toggleUseEnhanced:()=>e(t=>({portrait:{...t.portrait,useEnhanced:t.portrait.enhanced?!t.portrait.useEnhanced:!1}})),setPortraitZoom:t=>e(n=>({portrait:{...n.portrait,zoom:t}})),setPortraitPan:(t,n)=>e(a=>({portrait:{...a.portrait,panX:t,panY:n}})),setPortraitRawImage:t=>e(n=>({portrait:{...n.portrait,rawImage:t}})),setPortraitBgRemoved:(t,n)=>e(a=>({portrait:{...a.portrait,bgRemoved:t,bgRemovedImage:n!==void 0?n:a.portrait.bgRemovedImage}})),setPortraitBgOpacity:t=>e(n=>({portrait:{...n.portrait,bgOpacity:t}})),setPortraitBgBlur:t=>e(n=>({portrait:{...n.portrait,bgBlur:t}})),setPortraitEngravingIntensity:t=>e(n=>({portrait:{...n.portrait,engravingIntensity:t}})),setCurrentSide:t=>e({currentSide:t}),flipSide:()=>e(t=>({currentSide:t.currentSide==="front"?"back":"front"})),setIsEnhancing:t=>e({isEnhancing:t}),setIsExporting:t=>e({isExporting:t}),setAppLanguage:t=>e({appLanguage:t}),setBillLanguage:t=>e(n=>({voucherConfig:{...n.voucherConfig,language:t}})),setHours:t=>e(n=>({voucherConfig:{...n.voucherConfig,hours:t}})),setTemplateHue:t=>e(n=>({voucherConfig:{...n.voucherConfig,templateHue:t}})),reset:()=>e(nt)}),{name:"money-generator-storage",migrate:e=>{const t=e;return t!=null&&t.voucherConfig&&(t.voucherConfig.templateHue=29,t.voucherConfig.hours=1,t.voucherConfig.language=Se),t&&(t.appLanguage=Se),t},version:1,partialize:e=>({personalInfo:e.personalInfo,voucherConfig:{...e.voucherConfig,templateHue:29},appLanguage:e.appLanguage,portrait:{original:null,enhanced:null,useEnhanced:e.portrait.useEnhanced,zoom:e.portrait.zoom,panX:e.portrait.panX,panY:e.portrait.panY,rawImage:null,bgRemovedImage:null,bgRemoved:!1,bgOpacity:0,bgBlur:0,engravingIntensity:e.portrait.engravingIntensity},currentSide:"front",isEnhancing:!1,isExporting:!1})})),Vt={header:{title:"Money Generator",subtitle:"Erstelle deinen persönlichen Zeitgutschein"},form:{personalInfo:{title:"Persönliche Daten",name:"Name",namePlaceholder:"Dein Name",email:"E-Mail",emailPlaceholder:"deine@email.de",phone:"Telefon",phonePlaceholder:"+49 123 456789"},portrait:{title:"Portrait",upload:"Bild hochladen",dragDrop:"oder hierher ziehen",enhance:"Mit AI verbessern",enhancing:"Wird verbessert...",useOriginal:"Original verwenden",useEnhanced:"Verbessertes verwenden",zoom:"Zoom"},voucher:{title:"Gutschein",hours:"Stunden",hourLabel:"Stunde",hoursLabel:"Stunden",description:"Beschreibung",descriptionPlaceholder:"Was kann mit diesem Gutschein eingelöst werden?",billLanguage:"Schein-Sprache",billLanguageGerman:"Deutsch",billLanguageEnglish:"Englisch"},billColor:{title:"Scheinfarbe",label:"Farbton"}},preview:{front:"Vorderseite",back:"Rückseite",flip:"Umdrehen"},export:{button:"Als PDF herunterladen",exporting:"PDF wird erstellt...",success:"Download gestartet!"},bill:{descriptionText:"Für diesen Schein erhältst du {bannerText} meiner Zeit oder ein gleichwertiges Dankeschön",bannerText:{1:"eine Stunde",5:"fünf Stunden",10:"zehn Stunden"}}},qt={header:{title:"Money Generator",subtitle:"Create your personal time voucher"},form:{personalInfo:{title:"Personal Information",name:"Name",namePlaceholder:"Your name",email:"Email",emailPlaceholder:"your@email.com",phone:"Phone",phonePlaceholder:"+1 234 567890"},portrait:{title:"Portrait",upload:"Upload image",dragDrop:"or drag and drop",enhance:"Enhance with AI",enhancing:"Enhancing...",useOriginal:"Use original",useEnhanced:"Use enhanced",zoom:"Zoom"},voucher:{title:"Voucher",hours:"Hours",hourLabel:"hour",hoursLabel:"hours",description:"Description",descriptionPlaceholder:"What can be redeemed with this voucher?",billLanguage:"Bill Language",billLanguageGerman:"German",billLanguageEnglish:"English"},billColor:{title:"Bill Color",label:"Hue"}},preview:{front:"Front",back:"Back",flip:"Flip"},export:{button:"Download as PDF",exporting:"Creating PDF...",success:"Download started!"},bill:{descriptionText:"This voucher entitles you to {bannerText} of my time or an equivalent thank you",bannerText:{1:"one hour",5:"five hours",10:"ten hours"}}},Gt={de:Vt,en:qt};function J(e){return Gt[e]}function qe(e,t,n){if(n&&n.trim())return n;const a=J(e),r=a.bill.bannerText[t]||a.bill.bannerText[1];return a.bill.descriptionText.replace("{bannerText}",r)}function Zt(e){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e)}function Jt(e){return e.replace(/\D/g,"").length>=6}function Qt({focusField:e,onFocused:t}={}){const n=v(w=>w.appLanguage),a=v(w=>w.personalInfo),r=v(w=>w.setPersonalInfo),c=J(n),[l,o]=g.useState(!1),[i,u]=g.useState(!1),m=l&&a.email.trim()&&!Zt(a.email),x=i&&a.phone.trim()&&!Jt(a.phone),f=g.useRef(null),b=g.useRef(null),y=g.useRef(null);return g.useEffect(()=>{if(e){const w=e==="name"?f:e==="email"?b:y;setTimeout(()=>{var d,k;(d=w.current)==null||d.click(),(k=w.current)==null||k.focus(),t==null||t()},100)}},[e,t]),s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"form-control",children:[s.jsx("label",{className:"label",children:s.jsx("span",{className:"label-text font-medium",children:c.form.personalInfo.name})}),s.jsx("input",{ref:f,type:"text",name:"name",autoComplete:"name",placeholder:c.form.personalInfo.namePlaceholder,className:"input input-bordered w-full input-lg sm:input-md",value:a.name,onChange:w=>r({name:w.target.value})})]}),s.jsxs("div",{className:"form-control",children:[s.jsx("label",{className:"label",children:s.jsx("span",{className:"label-text font-medium",children:c.form.personalInfo.email})}),s.jsx("input",{ref:b,type:"email",name:"email",autoComplete:"email",placeholder:c.form.personalInfo.emailPlaceholder,className:`input input-bordered w-full input-lg sm:input-md ${m?"input-error":""}`,value:a.email,onChange:w=>r({email:w.target.value}),onBlur:()=>o(!0)}),m&&s.jsx("label",{className:"label",children:s.jsx("span",{className:"label-text-alt text-error",children:n==="de"?"Bitte gib eine gültige E-Mail-Adresse ein":"Please enter a valid email address"})})]}),s.jsxs("div",{className:"form-control",children:[s.jsx("label",{className:"label",children:s.jsx("span",{className:"label-text font-medium",children:c.form.personalInfo.phone})}),s.jsx("input",{ref:y,type:"tel",name:"phone",autoComplete:"tel",placeholder:c.form.personalInfo.phonePlaceholder,className:`input input-bordered w-full input-lg sm:input-md ${x?"input-error":""}`,value:a.phone,onChange:w=>r({phone:w.target.value}),onBlur:()=>u(!0)}),x&&s.jsx("label",{className:"label",children:s.jsx("span",{className:"label-text-alt text-error",children:n==="de"?"Bitte gib eine gültige Telefonnummer ein":"Please enter a valid phone number"})})]})]})}const en=1024,ce=new Map;let K=null,at=null;function Ge(e,t){return K||(K=document.createElement("canvas"),at=K.getContext("2d",{willReadFrequently:!0})),(K.width!==e||K.height!==t)&&(K.width=e,K.height=t),at}function ye(e){const t=ce.get(e);return t?Promise.resolve(t):new Promise((n,a)=>{const r=new Image;r.onload=()=>{if(ce.size>10){const c=ce.keys().next().value;c&&ce.delete(c)}ce.set(e,r),n(r)},r.onerror=()=>a(new Error("Failed to load image")),r.src=e})}function tn(){ce.clear()}async function lt(e,t=en){const n=await ye(e),a=Math.max(n.width,n.height);if(a<=t)return e;const r=t/a,c=Math.round(n.width*r),l=Math.round(n.height*r),o=document.createElement("canvas"),i=o.getContext("2d");if(!i)throw new Error("Failed to get canvas context");return o.width=c,o.height=l,i.drawImage(n,0,0,c,l),o.toDataURL("image/jpeg",.9)}async function We(e,t,n,a=0){const[r,c]=await Promise.all([ye(e),ye(t)]),l=Ge(r.width,r.height);if(l.clearRect(0,0,r.width,r.height),n>0){const o=a*20;l.save(),l.globalAlpha=n,o>0&&(l.filter=`blur(${o}px)`),l.drawImage(c,0,0,r.width,r.height),l.restore()}return l.drawImage(r,0,0),K.toDataURL("image/png")}async function ct(e,t=.5,n=40){const a=await ye(e),r=Ge(a.width,a.height);r.clearRect(0,0,a.width,a.height),r.drawImage(a,0,0);const c=r.getImageData(0,0,a.width,a.height),l=c.data,o=new Uint32Array(l.buffer),i=1+t*.8,u=1-t,m=n%360/360;for(let x=0;x<o.length;x++){const f=o[x],b=f&255,y=f>>8&255,w=f>>16&255,d=f>>24&255;if(d===0)continue;let I=(((77*b+150*y+29*w>>8)/255-.5)*i+.5)*255;I<0?I=0:I>255&&(I=255);const j=I/255,S=.12,[B,D,N]=ut(m,S,j),C=b*u+B*t|0,P=y*u+D*t|0,L=w*u+N*t|0;o[x]=d<<24|L<<16|P<<8|C}return r.putImageData(c,0,0),K.toDataURL("image/png")}function nn(e,t,n){e/=255,t/=255,n/=255;const a=Math.max(e,t,n),r=Math.min(e,t,n),c=(a+r)/2;let l=0,o=0;if(a!==r){const i=a-r;switch(o=c>.5?i/(2-a-r):i/(a+r),a){case e:l=((t-n)/i+(t<n?6:0))/6;break;case t:l=((n-e)/i+2)/6;break;case n:l=((e-t)/i+4)/6;break}}return[l,o,c]}function ut(e,t,n){if(t===0){const l=Math.round(n*255);return[l,l,l]}const a=(l,o,i)=>(i<0&&(i+=1),i>1&&(i-=1),i<1/6?l+(o-l)*6*i:i<1/2?o:i<2/3?l+(o-l)*(2/3-i)*6:l),r=n<.5?n*(1+t):n+t-n*t,c=2*n-r;return[Math.round(a(c,r,e+1/3)*255),Math.round(a(c,r,e)*255),Math.round(a(c,r,e-1/3)*255)]}const an=29,rn=5;async function dt(e,t){if(Math.abs(t-an)<=rn)return e;const n=await ye(e),a=Ge(n.width,n.height);a.clearRect(0,0,n.width,n.height),a.drawImage(n,0,0);const r=a.getImageData(0,0,n.width,n.height),c=r.data,l=new Uint32Array(c.buffer),o=t%360/360,i=20/360,u=45/360,m=l.length;for(let x=0;x<m;x++){const f=l[x],b=f&255,y=f>>8&255,w=f>>16&255,d=f>>24&255;if(d===0)continue;const[k,I,j]=nn(b,y,w);if(I<.08||k<i||k>u)continue;const S=o,B=Math.min(I,.05),[D,N,C]=ut(S,B,j);l[x]=d<<24|C<<16|N<<8|D}return a.putImageData(r,0,0),K.toDataURL("image/png")}const on="https://api.stability.ai/v1/generation",sn="https://api.stability.ai/v2beta/stable-image/edit/remove-background",gt="stability_api_key";let pe=null;function ln(e){pe=e}function cn(){return pe}function un(){return pe!==null}const dn={vintage:"portrait in the style of vintage currency engraving, fine line work, crosshatching, sepia tones, detailed stippling, classic bank note portrait style",engraved:"portrait as detailed intaglio engraving, currency bill style, fine parallel lines, high contrast, official government portrait",currency:"portrait rendered as US dollar bill engraving, official currency portrait style, green tint, fine line engraving technique"},rt=[{width:1024,height:1024},{width:1152,height:896},{width:1216,height:832},{width:1344,height:768},{width:1536,height:640},{width:640,height:1536},{width:768,height:1344},{width:832,height:1216},{width:896,height:1152}];function gn(e,t){const n=e/t;let a=rt[0],r=1/0;for(const c of rt){const l=c.width/c.height,o=Math.abs(n-l);o<r&&(r=o,a=c)}return a}function mn(e){return new Promise((t,n)=>{const a=new Image;a.onload=()=>{const r=gn(a.width,a.height),c=document.createElement("canvas");c.width=r.width,c.height=r.height;const l=c.getContext("2d");if(!l){n(new Error("Failed to get canvas context"));return}const o=a.width/a.height,i=r.width/r.height;let u=0,m=0,x=a.width,f=a.height;o>i?(x=a.height*i,u=(a.width-x)/2):(f=a.width/i,m=(a.height-f)/2),l.drawImage(a,u,m,x,f,0,0,r.width,r.height),t(c.toDataURL("image/png"))},a.onerror=()=>n(new Error("Failed to load image")),a.src=e})}function mt(e){var l;const t=e.split(","),n=((l=t[0].match(/:(.*?);/))==null?void 0:l[1])||"image/png",a=atob(t[1]),r=a.length,c=new Uint8Array(r);for(let o=0;o<r;o++)c[o]=a.charCodeAt(o);return new Blob([c],{type:n})}function Le(){var t;const e=typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:ge&&ge.tagName.toUpperCase()==="SCRIPT"&&ge.src||new URL("index.cjs",document.baseURI).href}<"u"&&"sk-7mEKklrqaltdtgbX0VoZbkA8E1cl939Spn75jSIYRvp1BW0b"||typeof process<"u"&&((t=process.env)==null?void 0:t.NEXT_PUBLIC_STABILITY_API_KEY);return e&&e!=="your-api-key-here"?e:typeof localStorage<"u"?localStorage.getItem(gt):null}function ht(e){localStorage.setItem(gt,e)}function Pe(){return pe?!0:Le()!==null}async function hn(e){const t=Le();if(!t)throw new Error("No Stability AI API key configured");const{imageDataUrl:n,style:a,strength:r=.35}=e,c=await mn(n),l=mt(c),o=new FormData;o.append("init_image",l,"portrait.png"),o.append("init_image_mode","IMAGE_STRENGTH"),o.append("image_strength",String(1-r)),o.append("text_prompts[0][text]",dn[a]),o.append("text_prompts[0][weight]","1"),o.append("cfg_scale","7"),o.append("samples","1"),o.append("steps","30");const u=await fetch(`${on}/stable-diffusion-xl-1024-v1-0/image-to-image`,{method:"POST",headers:{Authorization:`Bearer ${t}`,Accept:"application/json"},body:o});if(!u.ok){const x=await u.text();throw console.error("Stability AI error:",x),u.status===401?new Error("Invalid API key"):u.status===402?new Error("Insufficient credits"):u.status===429?new Error("Rate limit exceeded. Please try again later."):new Error(`API error: ${u.status}`)}const m=await u.json();if(!m.artifacts||m.artifacts.length===0)throw new Error("No image generated");return`data:image/png;base64,${m.artifacts[0].base64}`}async function pt(e){if(pe){const l=await fetch(pe,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({imageDataUrl:e})});if(!l.ok){const i=await l.json().catch(()=>({}));throw new Error(i.error||`API error: ${l.status}`)}return(await l.json()).imageDataUrl}const t=Le();if(!t)throw new Error("No Stability AI API key configured");const n=mt(e),a=new FormData;a.append("image",n,"image.png"),a.append("output_format","png");const r=await fetch(sn,{method:"POST",headers:{Authorization:`Bearer ${t}`,Accept:"image/*"},body:a});if(!r.ok){const l=await r.text();throw console.error("Stability AI remove background error:",l),r.status===401?new Error("Invalid API key"):r.status===402?new Error("Insufficient credits"):r.status===429?new Error("Rate limit exceeded. Please try again later."):new Error(`API error: ${r.status}`)}const c=await r.blob();return new Promise((l,o)=>{const i=new FileReader;i.onload=()=>l(i.result),i.onerror=()=>o(new Error("Failed to read result")),i.readAsDataURL(c)})}function pn(){const[e,t]=g.useState(!1),[n,a]=g.useState(!1),[r,c]=g.useState(null),[l,o]=g.useState(()=>Pe());g.useEffect(()=>{o(Pe());const f=setTimeout(()=>{o(Pe())},150);return()=>clearTimeout(f)},[]);const i=g.useCallback(()=>c(null),[]),u=g.useCallback(f=>{ht(f),o(!0),c(null)},[]),m=g.useCallback(async(f,b=.5,y=40)=>{t(!0),c(null);try{return await ct(f,b,y)}catch(w){const d=w instanceof Error?w.message:"Enhancement failed";throw c(d),w}finally{t(!1)}},[]),x=g.useCallback(async f=>{a(!0),c(null);try{return await pt(f)}catch(b){const y=b instanceof Error?b.message:"Background removal failed";throw c(y),b}finally{a(!1)}},[]);return{enhance:m,removeBg:x,isEnhancing:e,isRemovingBg:n,error:r,hasKey:l,setApiKey:u,clearError:i}}function ft({isOpen:e,onClose:t,onSubmit:n}){const a=v(u=>u.appLanguage),[r,c]=g.useState("");if(!e)return null;const l=u=>{u.preventDefault(),r.trim()&&(n(r.trim()),c(""),t())},i={de:{title:"Stability AI API Key",description:"Um die AI-Bildverbesserung zu nutzen, benötigst du einen Stability AI API Key. Du kannst ihn auf platform.stability.ai erhalten.",placeholder:"sk-...",submit:"Speichern",cancel:"Abbrechen",hint:"Der Key wird lokal in deinem Browser gespeichert."},en:{title:"Stability AI API Key",description:"To use AI image enhancement, you need a Stability AI API key. You can get one at platform.stability.ai.",placeholder:"sk-...",submit:"Save",cancel:"Cancel",hint:"The key is stored locally in your browser."}}[a];return s.jsxs("dialog",{className:"modal modal-open",children:[s.jsxs("div",{className:"modal-box",children:[s.jsx("h3",{className:"font-bold text-lg",children:i.title}),s.jsx("p",{className:"py-4 text-sm opacity-80",children:i.description}),s.jsxs("form",{onSubmit:l,children:[s.jsxs("div",{className:"form-control",children:[s.jsx("input",{type:"password",placeholder:i.placeholder,className:"input input-bordered w-full",value:r,onChange:u=>c(u.target.value),autoFocus:!0}),s.jsx("label",{className:"label",children:s.jsx("span",{className:"label-text-alt",children:i.hint})})]}),s.jsxs("div",{className:"modal-action",children:[s.jsx("button",{type:"button",className:"btn btn-ghost",onClick:t,children:i.cancel}),s.jsx("button",{type:"submit",className:"btn btn-primary",disabled:!r.trim(),children:i.submit})]})]})]}),s.jsx("form",{method:"dialog",className:"modal-backdrop",children:s.jsx("button",{onClick:t,children:"close"})})]})}function we({min:e,max:t,step:n,value:a,onChange:r,className:c="",disabled:l=!1}){const o=g.useRef(null),i=g.useRef(null),u=g.useRef(!1),[m,x]=g.useState(!1),f=g.useCallback(d=>{if(l)return;const k=d.touches[0];i.current={x:k.clientX,y:k.clientY,value:a},u.current=!1},[a,l]),b=g.useCallback(d=>{if(l||!i.current||!o.current)return;const k=d.touches[0],I=Math.abs(k.clientX-i.current.x),j=Math.abs(k.clientY-i.current.y);if(!u.current&&j>I&&j>10){i.current=null;return}if(!u.current&&I>j&&I>15&&(u.current=!0,x(!0)),u.current){d.preventDefault();const S=o.current.getBoundingClientRect(),B=Math.max(0,Math.min(1,(k.clientX-S.left)/S.width)),D=t-e,N=e+B*D,C=Math.round(N/n)*n,P=Math.max(e,Math.min(t,C));r(P)}},[l,e,t,n,r]),y=g.useCallback(()=>{i.current=null,u.current=!1,x(!1)},[]),w=g.useCallback(d=>{r(parseFloat(d.target.value))},[r]);return g.useEffect(()=>{const d=o.current;if(!d)return;const k=I=>{u.current&&I.preventDefault()};return d.addEventListener("touchmove",k,{passive:!1}),()=>{d.removeEventListener("touchmove",k)}},[]),s.jsx("input",{ref:o,type:"range",min:e,max:t,step:n,value:a,onChange:w,onTouchStart:f,onTouchMove:b,onTouchEnd:y,className:`${c} ${m?"scale-y-125":""}`,disabled:l,style:{touchAction:"pan-y"}})}function fn(){const e=v(p=>p.appLanguage),t=v(p=>p.portrait),n=v(p=>p.setPortrait),a=v(p=>p.setPortraitZoom),r=v(p=>p.setPortraitPan),c=v(p=>p.setPortraitRawImage),l=v(p=>p.setPortraitBgRemoved),o=v(p=>p.setPortraitBgOpacity),i=v(p=>p.setPortraitBgBlur),u=v(p=>p.setPortraitEngravingIntensity),{enhance:m,removeBg:x,isEnhancing:f,isRemovingBg:b,error:y,hasKey:w,setApiKey:d}=pn(),k=J(e),I=g.useRef(null),[j,S]=g.useState(!1),[B,D]=g.useState(!1),N=g.useRef(null),C=g.useRef(null),P=t.rawImage,L=t.bgRemovedImage,H=t.bgRemoved,V=t.bgOpacity,te=t.bgBlur,G=t.engravingIntensity;g.useEffect(()=>{t.original&&!t.rawImage&&c(t.original)},[t.original,t.rawImage,c]),g.useEffect(()=>()=>{N.current&&clearTimeout(N.current),C.current&&clearTimeout(C.current)},[]);const W=v(p=>p.voucherConfig.templateHue),Y=g.useRef(W),$=g.useCallback(async p=>{if(!p.type.startsWith("image/"))return;const T=new FileReader;T.onload=async M=>{var z;const R=(z=M.target)==null?void 0:z.result,X=await lt(R);c(X),n(X),l(!1,null),u(0)},T.readAsDataURL(p)},[n,c,l,u]),ne=g.useCallback(p=>{p.preventDefault(),S(!1);const T=p.dataTransfer.files[0];T&&$(T)},[$]),Ne=g.useCallback(p=>{p.preventDefault(),S(!0)},[]),fe=g.useCallback(p=>{p.preventDefault(),S(!1)},[]),He=()=>{var p;(p=I.current)==null||p.click()},be=p=>{var M;const T=(M=p.target.files)==null?void 0:M[0];T&&$(T)},ae=g.useCallback(async(p,T,M)=>{try{return await m(p,T,M)}catch(R){return console.error("Enhancement failed:",R),p}},[m]),se=g.useCallback(async p=>{try{const T=await x(p);return l(!0,T),T}catch(T){return console.error("Background removal failed:",T),p}},[x,l]),re=g.useCallback(async()=>{const p=v.getState(),T=p.portrait,M=p.voucherConfig.templateHue;if(!T.rawImage)return;let R;T.bgRemoved&&T.bgRemovedImage?R=await We(T.bgRemovedImage,T.rawImage,T.bgOpacity,T.bgBlur):R=T.rawImage,T.engravingIntensity>0&&(R=await ae(R,T.engravingIntensity,M)),n(R)},[ae,n]);g.useEffect(()=>{if(Y.current===W)return;Y.current=W;const p=v.getState().portrait;p.engravingIntensity>0&&p.rawImage&&(N.current&&clearTimeout(N.current),N.current=setTimeout(re,150))},[W,re]);const ve=async()=>{if(!P)return;if(!H&&!w){D(!0);return}if(!H){const T=await se(P),M=v.getState(),R=M.portrait,X=M.voucherConfig.templateHue;let z=await We(T,P,R.bgOpacity,R.bgBlur);R.engravingIntensity>0&&(z=await ae(z,R.engravingIntensity,X)),n(z)}else{l(!1,null);const T=v.getState(),M=T.portrait.engravingIntensity,R=T.voucherConfig.templateHue;if(M>0){const X=await ae(P,M,R);n(X)}else n(P)}},ke=p=>{u(p),N.current&&clearTimeout(N.current),P&&(N.current=setTimeout(re,150))},xe=async p=>{if(d(p),!P)return;const T=await se(P),M=v.getState(),R=M.portrait,X=M.voucherConfig.templateHue;let z=await We(T,P,R.bgOpacity,R.bgBlur);R.engravingIntensity>0&&(z=await ae(z,R.engravingIntensity,X)),n(z)},q=p=>{o(p),C.current&&clearTimeout(C.current),!(!P||!L)&&(C.current=setTimeout(re,150))},Ie=p=>{i(p),C.current&&clearTimeout(C.current),!(!P||!L)&&(C.current=setTimeout(re,150))},Te=()=>{n(null),c(null),l(!1,null),o(0),i(0),u(0),tn()};return s.jsxs("div",{className:"space-y-4",children:[t.original?s.jsxs("div",{className:"flex flex-col space-y-4",children:[s.jsxs("div",{className:"flex justify-between items-center w-full",children:[s.jsx("span",{className:"text-sm font-medium text-base-content/70",children:e==="de"?"Portrait-Einstellungen":"Portrait settings"}),s.jsxs("button",{className:"btn btn-xs btn-ghost text-error",onClick:Te,children:[s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})}),e==="de"?"Foto entfernen":"Remove photo"]})]}),s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 w-full",children:[s.jsxs("div",{className:"form-control w-full",children:[s.jsxs("label",{className:"label",children:[s.jsx("span",{className:"label-text",children:k.form.portrait.zoom}),s.jsxs("span",{className:"label-text-alt",children:[Math.round(t.zoom*100),"%"]})]}),s.jsx(we,{min:.5,max:2,step:.05,value:t.zoom,onChange:p=>{a(p),p<=1&&(t.panX!==0||t.panY!==0)&&r(0,0)},className:"range range-primary range-sm"})]}),s.jsxs("div",{className:"form-control w-full",children:[s.jsxs("label",{className:"label",children:[s.jsxs("span",{className:"label-text flex items-center gap-2",children:[e==="de"?"Farbanpassung":"Color adjustment",f&&s.jsx("span",{className:"loading loading-spinner loading-xs"})]}),s.jsxs("span",{className:"label-text-alt",children:[Math.round(G*100),"%"]})]}),s.jsx(we,{min:0,max:1,step:.05,value:G,onChange:ke,className:"range range-secondary range-sm",disabled:f||!P})]})]}),H?s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4 w-full",children:[s.jsxs("div",{className:"form-control w-full",children:[s.jsxs("label",{className:"label",children:[s.jsx("span",{className:"label-text",children:e==="de"?"Hintergrund":"Background"}),s.jsxs("span",{className:"label-text-alt",children:[Math.round(V*100),"%"]})]}),s.jsx(we,{min:0,max:1,step:.05,value:V,onChange:q,className:"range range-primary range-sm"})]}),s.jsxs("div",{className:"form-control w-full",children:[s.jsxs("label",{className:"label",children:[s.jsx("span",{className:"label-text",children:e==="de"?"Unschärfe":"Blur"}),s.jsxs("span",{className:"label-text-alt",children:[Math.round(te*100),"%"]})]}),s.jsx(we,{min:0,max:1,step:.05,value:te,onChange:Ie,className:"range range-primary range-sm",disabled:V===0})]})]}):s.jsx("div",{className:"form-control w-fit",children:s.jsxs("label",{className:"label cursor-pointer justify-start gap-3",children:[s.jsx("input",{type:"checkbox",className:`toggle toggle-primary ${b?"opacity-50":""}`,checked:H,onChange:ve,disabled:b||!P}),s.jsxs("span",{className:"label-text flex items-center gap-2",children:[b?s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"loading loading-spinner loading-xs"}),e==="de"?"Hintergrund wird entfernt...":"Removing background..."]}):e==="de"?"Hintergrund entfernen":"Remove background",!w&&s.jsx("span",{className:"badge badge-sm badge-outline",children:"API"})]})]})}),y&&s.jsxs("div",{className:"alert alert-warning text-sm py-2",children:[s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"stroke-current shrink-0 h-5 w-5",fill:"none",viewBox:"0 0 24 24",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),s.jsx("span",{children:y})]})]}):s.jsxs("div",{className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${b?"border-primary bg-primary/10 pointer-events-none":j?"border-primary bg-primary/10":"border-base-300 hover:border-primary hover:bg-base-200"}`,onDrop:ne,onDragOver:Ne,onDragLeave:fe,onClick:He,children:[s.jsx("input",{ref:I,type:"file",accept:"image/*",className:"hidden",onChange:be}),b?s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("span",{className:"loading loading-spinner loading-lg text-primary"}),s.jsx("p",{className:"font-medium",children:e==="de"?"Hintergrund wird entfernt...":"Removing background..."})]}):s.jsxs("div",{className:"flex flex-col items-center gap-2",children:[s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-12 w-12 text-base-content/50",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"})}),s.jsx("p",{className:"font-medium",children:k.form.portrait.upload}),s.jsx("p",{className:"text-sm text-base-content/60",children:k.form.portrait.dragDrop})]})]}),s.jsx(ft,{isOpen:B,onClose:()=>D(!1),onSubmit:xe})]})}function bn(){const e=v(o=>o.appLanguage),t=v(o=>o.voucherConfig.language),n=v(o=>o.voucherConfig.hours);v(o=>o.voucherConfig.templateHue);const a=v(o=>o.setBillLanguage),r=v(o=>o.setHours);v(o=>o.setTemplateHue);const c=J(e),l=[1,5,10];return s.jsxs("div",{className:"space-y-4",children:[s.jsx("div",{className:"form-control",children:s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"label-text font-medium",children:c.form.voucher.billLanguage}),s.jsxs("div",{className:"join border border-base-300 rounded-lg",children:[s.jsx("button",{className:`join-item btn btn-md sm:btn-sm ${t==="de"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>a("de"),children:c.form.voucher.billLanguageGerman}),s.jsx("button",{className:`join-item btn btn-md sm:btn-sm ${t==="en"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>a("en"),children:c.form.voucher.billLanguageEnglish})]})]})}),s.jsx("div",{className:"form-control",children:s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"label-text font-medium",children:c.form.voucher.hours}),s.jsx("div",{className:"join border border-base-300 rounded-lg",children:l.map(o=>s.jsxs("button",{className:`join-item btn btn-md sm:btn-sm ${n===o?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>r(o),children:[o,s.jsxs("span",{className:"hidden sm:inline",children:[" ",o===1?c.form.voucher.hourLabel:c.form.voucher.hoursLabel]})]},o))})]})}),!1]})}const Ye=new Map,le=new Map;async function E(e){return Ye.has(e)?Ye.get(e):new Promise((t,n)=>{const a=new Image;a.crossOrigin="anonymous",a.onload=()=>{Ye.set(e,a),t(a)},a.onerror=n,a.src=e})}function ie(e,t,n,a){e.drawImage(t,0,0,n,a)}async function bt(e,t,n,a){if(t>=155&&t<=165)return E(e);const r=`${e}:${t}:${n}x${a}`;if(le.has(r))return E(le.get(r));const c=await E(e),l=document.createElement("canvas");l.width=n,l.height=a;const o=l.getContext("2d");if(!o)throw new Error("Failed to get canvas context");o.drawImage(c,0,0,n,a);const i=l.toDataURL("image/png"),u=await dt(i,t);if(le.size>20){const m=le.keys().next().value;m&&le.delete(m)}return le.set(r,u),E(u)}function xn(e,t,n,a,r,c="de"){e.save(),e.beginPath(),e.ellipse(t,n,a,r,0,0,Math.PI*2),e.closePath(),e.setLineDash([20,10]),e.strokeStyle="rgba(100, 100, 100, 0.4)",e.lineWidth=3,e.stroke(),e.restore()}function xt(e,t,n,a,r,c,l=1,o=0,i=0){e.save(),e.beginPath(),e.ellipse(n,a,r,c,0,0,Math.PI*2),e.closePath(),e.clip();const u=t.width/t.height,m=r/c,x=r*2,f=c*2;let b,y;u>m?(y=f,b=f*u):(b=x,y=x/u),b*=l,y*=l;const w=Math.max(0,(b-x)/2),d=Math.max(0,(y-f)/2),k=n-b/2+o*w,I=a-y/2+i*d;e.drawImage(t,k,I,b,y),e.restore()}function Ze(e,t,n,a="#2a3a2a"){e.save(),e.font=`${n.fontSize}px "Times New Roman", serif`,e.textAlign=n.align||"center",e.textBaseline="middle",e.fillStyle=a,n.maxWidth?e.fillText(t,n.x,n.y,n.maxWidth):e.fillText(t,n.x,n.y),e.restore()}function wt(e,t,n,a="#2a3a2a"){e.save(),e.font=`${n.fontSize}px "Times New Roman", serif`,e.textAlign=n.align||"center",e.textBaseline="top",e.fillStyle=a;const r=n.maxWidth||400,c=n.lineHeight||n.fontSize*1.4,l=t.split(" "),o=[];let i="";for(const x of l){const f=i?`${i} ${x}`:x;e.measureText(f).width>r&&i?(o.push(i),i=x):i=f}i&&o.push(i);const u=o.length*c;let m=n.y-u/2;for(const x of o)e.fillText(x,n.x,m),m+=c;e.restore()}function yt(e,t,n,a,r,c="#2a3a2a"){e.save(),e.font=`${r.fontSize}px "Times New Roman", serif`,e.textAlign=r.align||"center",e.textBaseline="middle",e.fillStyle=c;const l=r.lineHeight||r.fontSize*1.8,o=[t,n,a].filter(Boolean),i=(o.length-1)*l;let u=r.y-i/2;for(const m of o)m&&(e.fillText(m,r.x,u),u+=l);e.restore()}function wn(e,t,n,a="#2a3a2a"){e.save(),e.strokeStyle=a,e.lineWidth=Math.max(2,t.labelFontSize/16),e.beginPath(),e.moveTo(t.x-t.width/2,t.y),e.lineTo(t.x+t.width/2,t.y),e.stroke(),e.font=`${t.labelFontSize}px "Times New Roman", serif`,e.textAlign="center",e.textBaseline="top",e.fillStyle=a,e.fillText(n,t.x,t.y+t.labelFontSize*.3),e.restore()}async function vt(e,t,n,a,r,c,l,o,i,u=1,m=0,x=0,f=0,b=1,y="de"){const w=e.getContext("2d");if(!w)return;const d=document.createElement("canvas");d.width=o,d.height=i;const k=d.getContext("2d");if(!k)return;k.clearRect(0,0,o,i);const I=await bt(t,f,o,i);ie(k,I,o,i);const j=await E(n);if(ie(k,j,o,i),r)try{const D=await E(r);xt(k,D,l.portrait.x,l.portrait.y,l.portrait.radiusX,l.portrait.radiusY,u,m,x)}catch(D){console.error("Failed to load portrait:",D)}else xn(k,l.portrait.x,l.portrait.y,l.portrait.radiusX,l.portrait.radiusY,y);const S=await E(a);ie(k,S,o,i);const B=o/3633;St(k,b,y,B),c&&Ze(k,c,l.namePlate),e.width=o,e.height=i,w.drawImage(d,0,0)}async function kt(e,t,n,a,r,c,l,o,i,u,m,x=0,f=1,b="de"){const y=e.getContext("2d");if(!y)return;const w=document.createElement("canvas");w.width=u,w.height=m;const d=w.getContext("2d");if(!d)return;d.clearRect(0,0,u,m);const k=await bt(t,x,u,m);ie(d,k,u,m);const I=await E(n);ie(d,I,u,m);const j=await E(a);ie(d,j,u,m);const S=u/3633;if(St(d,f,b,S),i.contactInfo&&(r||c||l)&&yt(d,r,c,l,i.contactInfo),i.description&&o&&wt(d,o,i.description),r&&Ze(d,r,i.namePlate),i.signature){const B=b==="de"?"Unterschrift":"Signature";wn(d,i.signature,B)}e.width=u,e.height=m,y.drawImage(w,0,0)}const me=typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:ge&&ge.tagName.toUpperCase()==="SCRIPT"&&ge.src||new URL("index.cjs",document.baseURI).href}<"u"&&"/"||"/",_={background:`${me}templates/background.webp`,frontFrame:`${me}templates/front_frame.webp`,backFrame:`${me}templates/back_frame.webp`},he={1:`${me}templates/1.png`,5:`${me}templates/5.png`,10:`${me}templates/10.png`},It={de:{banner:{1:"EINE STUNDE",5:"FÜNF STUNDEN",10:"ZEHN STUNDEN"}},en:{banner:{1:"ONE HOUR",5:"FIVE HOURS",10:"TEN HOURS"}}},Q=3633,ee=1920,Re=.5,yn=Math.round(Q*Re),vn=Math.round(ee*Re),Tt=320,Pt=335,F={badges:{topLeft:{x:286,y:235},topRight:{x:3340,y:230},bottomLeft:{x:282,y:1665},bottomRight:{x:3345,y:1665}},banner:{centerX:1816,centerY:3820,radius:3610,fontSize:103,color:"#2a3a2a"}},Ee=new Map,oe=new Map,_e=new Map,Oe=new Map,$e=new Map;function Et(e,t,n,a,r,c,l){e.save(),e.font=`900 ${c}px "Times New Roman", Georgia, serif`,e.fillStyle=l,e.textAlign="center",e.textBaseline="middle";const i=e.measureText(t).width/r,u=-Math.PI/2-i/2,m=t.split(""),x=[];for(const b of m)x.push(e.measureText(b).width);let f=u;for(let b=0;b<m.length;b++){const y=m[b],w=x[b],d=f+w/2/r,k=n+r*Math.cos(d),I=a+r*Math.sin(d);e.save(),e.translate(k,I),e.rotate(d+Math.PI/2),e.fillText(y,0,0),e.restore(),f+=w/r}e.restore()}let U={background:null,frontFrame:null,backFrame:null,badges:{1:null,5:null,10:null}};async function kn(){const[e,t,n,a,r,c]=await Promise.all([E(_.background),E(_.frontFrame),E(_.backFrame),E(he[1]),E(he[5]),E(he[10])]);U={background:e,frontFrame:t,backFrame:n,badges:{1:a,5:r,10:c}}}function In(e,t){const n=Math.round(Q*e),a=Math.round(ee*e),r=document.createElement("canvas");r.width=n,r.height=a;const c=r.getContext("2d");if(!c)throw new Error("Failed to get canvas context");c.drawImage(t,0,0,n,a);const l=e<1?.8:.95;return r.toDataURL("image/jpeg",l)}function Tn(e,t){const n=Math.round(Q*e),a=Math.round(ee*e),r=document.createElement("canvas");r.width=n,r.height=a;const c=r.getContext("2d");if(!c)throw new Error("Failed to get canvas context");const l=Tt*e,o=Pt*e,i=F.badges,u=(m,x)=>{const f=x/2,b=m.x*e-f,y=m.y*e-f;c.drawImage(t,b,y,x,x)};return u(i.topLeft,l),u(i.topRight,l),u(i.bottomLeft,o),u(i.bottomRight,o),r.toDataURL("image/png")}function St(e,t,n,a=1){const r=It[n].banner[t];Et(e,r,F.banner.centerX*a,F.banner.centerY*a,F.banner.radius*a,F.banner.fontSize*a,F.banner.color)}function Ct(e,t,n,a,r,c,l){const o=Math.round(Q*a),i=Math.round(ee*a),u=document.createElement("canvas");u.width=o,u.height=i;const m=u.getContext("2d");if(!m)throw new Error("Failed to get canvas context");m.drawImage(r,0,0,o,i);{const f=Tt*a,b=Pt*a,y=F.badges,w=(d,k)=>{const I=k/2,j=d.x*a-I,S=d.y*a-I;m.drawImage(l,j,S,k,k)};w(y.topLeft,f),w(y.topRight,f),w(y.bottomLeft,b),w(y.bottomRight,b)}if(m.drawImage(c,0,0,o,i),n==="front"){const f=It[t].banner[e];Et(m,f,F.banner.centerX*a,F.banner.centerY*a,F.banner.radius*a,F.banner.fontSize*a,F.banner.color)}const x=a<1?.8:.95;return u.toDataURL("image/jpeg",x)}async function Lt(e,t,n){const a=`${e}-${t}-${n}`;if(Ee.has(a))return Ee.get(a);const r=U.background||await E(_.background),c=n==="front"?U.frontFrame||await E(_.frontFrame):U.backFrame||await E(_.backFrame),l=U.badges[e]||await E(he[e]),o=Ct(e,t,n,Re,r,c,l);return Ee.set(a,o),o}async function Xe(e,t,n){const a=`${e}-${t}-${n}`;if(oe.has(a))return oe.get(a);const r=U.background||await E(_.background),c=n==="front"?U.frontFrame||await E(_.frontFrame):U.backFrame||await E(_.backFrame),l=U.badges[e]||await E(he[e]),o=Ct(e,t,n,1,r,c,l);if(oe.size>4){const i=oe.keys().next().value;i&&oe.delete(i)}return oe.set(a,o),o}function Pn(){return{width:Q,height:ee}}function En(){Ee.clear(),oe.clear(),_e.clear(),Oe.clear(),$e.clear()}async function Ke(e,t,n="front",a=Re){const r=`bg-${a}`;let c=_e.get(r);if(!c){const m=U.background||await E(_.background);c=In(a,m),_e.set(r,c)}const l=`badges-${e}-${a}`;let o=Oe.get(l);if(!o){const m=U.badges[e]||await E(he[e]);o=Tn(a,m),Oe.set(l,o)}const i=`${n}-${a}`;let u=$e.get(i);if(!u){const m=n==="front"?U.frontFrame||await E(_.frontFrame):U.backFrame||await E(_.backFrame),x=Math.round(Q*a),f=Math.round(ee*a),b=document.createElement("canvas");b.width=x,b.height=f;const y=b.getContext("2d");if(!y)throw new Error("Failed to get canvas context");y.drawImage(m,0,0,x,f),u=b.toDataURL("image/png"),$e.set(i,u)}return{background:c,badges:o,frame:u}}async function Sn(){const e=[1,5,10],t=["de","en"],n=["front","back"],a=[];for(const r of e)for(const c of t)for(const l of n)a.push(Lt(r,c,l));await Promise.all(a)}function Je(e,t){return{front:"",back:"",width:Q,height:ee}}const je={front:{portrait:{x:1810,y:918,radiusX:570,radiusY:605},namePlate:{x:1816,y:1765,fontSize:85,maxWidth:898,align:"center"}},back:{portrait:{x:0,y:0,radiusX:0,radiusY:0},namePlate:{x:1816,y:1770,fontSize:85,maxWidth:898,align:"center"},contactInfo:{x:898,y:939,fontSize:93,lineHeight:165,align:"center"},description:{x:2721,y:939,fontSize:85,maxWidth:1177,lineHeight:124,align:"center"},signature:{x:1820,y:1445,width:950,height:145,labelFontSize:85}}},ue=je,de=je;function Qe(e){return je}const Ve=.75;function Cn(e){const t=Qe(),n=Ve,a=r=>({portrait:{x:r.portrait.x*n,y:r.portrait.y*n,radiusX:r.portrait.radiusX*n,radiusY:r.portrait.radiusY*n},namePlate:{x:r.namePlate.x*n,y:r.namePlate.y*n,fontSize:r.namePlate.fontSize*n,maxWidth:r.namePlate.maxWidth?r.namePlate.maxWidth*n:void 0,lineHeight:r.namePlate.lineHeight?r.namePlate.lineHeight*n:void 0,align:r.namePlate.align},contactInfo:r.contactInfo?{x:r.contactInfo.x*n,y:r.contactInfo.y*n,fontSize:r.contactInfo.fontSize*n,maxWidth:r.contactInfo.maxWidth?r.contactInfo.maxWidth*n:void 0,lineHeight:r.contactInfo.lineHeight?r.contactInfo.lineHeight*n:void 0,align:r.contactInfo.align}:void 0,description:r.description?{x:r.description.x*n,y:r.description.y*n,fontSize:r.description.fontSize*n,maxWidth:r.description.maxWidth?r.description.maxWidth*n:void 0,lineHeight:r.description.lineHeight?r.description.lineHeight*n:void 0,align:r.description.align}:void 0,signature:r.signature?{x:r.signature.x*n,y:r.signature.y*n,width:r.signature.width*n,height:r.signature.height*n,labelFontSize:r.signature.labelFontSize*n}:void 0});return{front:a(t.front),back:a(t.back)}}function Ln(e,t){const n=Je();return{...n,width:Math.round(n.width*Ve),height:Math.round(n.height*Ve)}}function Rn(e,t){const[n,a]=g.useState(e);return g.useEffect(()=>{const r=setTimeout(()=>a(e),t);return()=>clearTimeout(r)},[e,t]),n}function jn({onPortraitClick:e,onFileDrop:t}={}){const n=v(h=>h.appLanguage),a=v(h=>h.voucherConfig.language),r=v(h=>h.voucherConfig.hours),c=v(h=>h.voucherConfig.description),l=v(h=>h.voucherConfig.templateHue),o=v(h=>h.personalInfo),i=v(h=>h.portrait),u=v(h=>h.currentSide),m=v(h=>h.flipSide),x=v(h=>h.setPortraitPan),f=Rn(l,150),b=J(n),y=g.useRef(null),w=g.useRef(null),d=g.useRef(null),[k,I]=g.useState(!1),[j,S]=g.useState(!1),[B,D]=g.useState(!1),[N,C]=g.useState(!1),P=g.useRef(null),L=Ln(),H=Cn(),V=i.useEnhanced&&i.enhanced?i.enhanced:i.original,te=qe(a,r,c),[G,W]=g.useState(""),[Y,$]=g.useState(""),[ne,Ne]=g.useState(""),[fe,He]=g.useState(""),[be,ae]=g.useState(""),[se,re]=g.useState(""),[ve,ke]=g.useState(!0);g.useEffect(()=>{let h=!0;ke(!0);async function A(){const[O,Z]=await Promise.all([Ke(r,a,"front"),Ke(r,a,"back")]);h&&(W(O.background),$(O.badges),Ne(O.frame),He(Z.background),ae(Z.badges),re(Z.frame),ke(!1))}return A(),()=>{h=!1}},[r,a]),g.useEffect(()=>{!y.current||!G||!Y||!ne||vt(y.current,G,Y,ne,V,o.name,H.front,L.width,L.height,i.zoom,i.panX,i.panY,f,r,a)},[L,G,Y,ne,V,o.name,H,i.zoom,i.panX,i.panY,f,r,a]),g.useEffect(()=>{!w.current||!fe||!be||!se||kt(w.current,fe,be,se,o.name,o.email,o.phone,te,H.back,L.width,L.height,f,r,a)},[L,fe,be,se,o,te,H,f,r,a]);const xe=()=>{I(!k),m()};g.useEffect(()=>{I(u==="back")},[u]);const q=g.useCallback((h,A)=>{if(!d.current||u!=="front")return!1;const O=d.current.getBoundingClientRect(),Z=O.width/L.width,De=O.height/L.height,Me=(h-O.left)/Z,Ae=(A-O.top)/De,{x:Ue,y:zt,radiusX:Ft,radiusY:_t}=H.front.portrait,et=(Me-Ue)/Ft,tt=(Ae-zt)/_t;return et*et+tt*tt<=1},[u,L.width,L.height,H.front.portrait]),Ie=g.useCallback((h,A)=>{!i.original||i.zoom<=1||!q(h,A)||(S(!0),P.current={x:h,y:A,panX:i.panX,panY:i.panY})},[i.original,i.zoom,i.panX,i.panY,q]),Te=g.useCallback((h,A)=>{if(!j||!P.current||!d.current)return;const O=d.current.getBoundingClientRect(),Z=3/Math.max(O.width,O.height),De=(h-P.current.x)*Z,Me=(A-P.current.y)*Z,Ae=Math.max(-1,Math.min(1,P.current.panX+De)),Ue=Math.max(-1,Math.min(1,P.current.panY+Me));x(Ae,Ue)},[j,x]),p=g.useCallback(()=>{S(!1),P.current=null},[]),T=g.useCallback((h,A)=>{!i.original&&q(h,A)&&e&&e()},[i.original,q,e]),M=h=>{q(h.clientX,h.clientY)&&(h.preventDefault(),i.original&&i.zoom>1&&Ie(h.clientX,h.clientY))},R=h=>{j||T(h.clientX,h.clientY)},X=h=>{Te(h.clientX,h.clientY),D(q(h.clientX,h.clientY))},z=()=>p(),Dt=()=>{p(),D(!1)},Mt=h=>{if(h.touches.length===1){const A=h.touches[0];i.zoom>1&&q(A.clientX,A.clientY)&&Ie(A.clientX,A.clientY)}},At=h=>{h.touches.length===1&&Te(h.touches[0].clientX,h.touches[0].clientY)},Ut=()=>p(),Wt=u==="front"&&i.original&&i.zoom>1,Yt=L.width/L.height;return s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"flex justify-between items-center",children:[s.jsxs("div",{className:"join border border-base-300 rounded-lg",children:[s.jsx("button",{className:`join-item btn btn-md sm:btn-sm ${u==="front"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>u!=="front"&&xe(),children:b.preview.front}),s.jsx("button",{className:`join-item btn btn-md sm:btn-sm ${u==="back"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>u!=="back"&&xe(),children:b.preview.back})]}),s.jsxs("button",{className:"btn btn-ghost btn-md sm:btn-sm",onClick:xe,children:[s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})}),s.jsx("span",{className:"hidden sm:inline",children:b.preview.flip})]})]}),s.jsxs("div",{className:"relative w-full overflow-visible",style:{aspectRatio:Yt,perspective:"1500px"},children:[ve&&s.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-base-300 rounded-lg z-10",children:s.jsx("span",{className:"loading loading-spinner loading-lg text-primary"})}),s.jsxs("div",{ref:d,className:`relative w-full h-full shadow-lg ${B&&Wt?j?"cursor-grabbing":"cursor-grab":""} ${ve?"opacity-0":"opacity-100"} transition-opacity duration-300`,style:{transformStyle:"preserve-3d",transition:"transform 0.6s ease-in-out, opacity 0.3s ease-in-out",transform:k?"rotateY(180deg)":"rotateY(0deg)"},onClick:R,onMouseDown:M,onMouseMove:X,onMouseUp:z,onMouseLeave:Dt,onTouchStart:Mt,onTouchMove:At,onTouchEnd:Ut,children:[s.jsx("canvas",{ref:y,className:"absolute inset-0 w-full h-full",style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"}}),s.jsx("canvas",{ref:w,className:"absolute inset-0 w-full h-full",style:{backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden",transform:"rotateY(180deg)"}}),!i.original&&u==="front"&&(e||t)&&s.jsx("div",{className:`absolute flex flex-col items-center justify-center cursor-pointer transition-colors duration-300 ease-in-out ${N?"bg-primary/20":"hover:bg-base-content/5"}`,style:{left:`${(H.front.portrait.x-H.front.portrait.radiusX)/L.width*100}%`,top:`${(H.front.portrait.y-H.front.portrait.radiusY)/L.height*100}%`,width:`${H.front.portrait.radiusX*2/L.width*100}%`,height:`${H.front.portrait.radiusY*2/L.height*100}%`,borderRadius:"50%",backfaceVisibility:"hidden",WebkitBackfaceVisibility:"hidden"},onClick:h=>{h.stopPropagation(),e==null||e()},onDragOver:h=>{h.preventDefault(),h.stopPropagation(),C(!0)},onDragLeave:h=>{h.preventDefault(),h.stopPropagation(),C(!1)},onDrop:h=>{h.preventDefault(),h.stopPropagation(),C(!1);const A=h.dataTransfer.files[0];A&&A.type.startsWith("image/")&&t&&t(A)},children:s.jsxs("button",{className:"btn btn-dash hover:btn-dash hover:border-base-content/60 flex flex-col items-center gap-1 h-auto py-3 px-4 bg-base-100/20 hover:bg-base-100/30",onClick:h=>{h.stopPropagation(),e==null||e()},children:[s.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",className:"w-11 h-10 text-base-content/50",fill:"none",viewBox:"0 0 26 24",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round",children:[s.jsx("circle",{cx:"11",cy:"8",r:"4"}),s.jsx("path",{d:"M3 21c0-4 4-6 8-6s8 2 8 6"}),s.jsx("line",{x1:"22",y1:"4",x2:"22",y2:"10",strokeWidth:2}),s.jsx("line",{x1:"19",y1:"7",x2:"25",y2:"7",strokeWidth:2})]}),s.jsx("span",{className:"text-xs",children:n==="de"?"Foto hochladen":"Upload photo"})]})})]})]})]})}function Bn(){const e=g.useRef(null),t=g.useRef(null);return{frontCanvasRef:e,backCanvasRef:t}}const Nn=`
|
|
2
2
|
// RGB to HSL conversion
|
|
3
3
|
function rgbToHsl(r, g, b) {
|
|
4
4
|
r /= 255;
|
|
@@ -373,4 +373,4 @@ self.onmessage = async (e) => {
|
|
|
373
373
|
});
|
|
374
374
|
}
|
|
375
375
|
};
|
|
376
|
-
`;let
|
|
376
|
+
`;let ze=null,ot=null;function Hn(){if(!ze){const e=new Blob([Nn],{type:"application/javascript"});ot=URL.createObjectURL(e),ze=new Worker(ot,{type:"module"})}return ze}async function Fe(e){const n=await(await fetch(e)).blob();return URL.createObjectURL(n)}function it(e,t){const n=new Uint8Array(e);let a="";for(let r=0;r<n.length;r++)a+=String.fromCharCode(n[r]);return`data:${t};base64,${btoa(a)}`}async function Rt(e){const{frontTemplateSrc:t,backTemplateSrc:n,templateWidth:a,templateHeight:r,layout:c,portrait:l,portraitZoom:o=1,portraitPanX:i=0,portraitPanY:u=0,templateHue:m=160,name:x,email:f,phone:b,description:y,language:w="de"}=e,[d,k]=await Promise.all([Fe(t),Fe(n)]);let I=null;return l&&(I=await Fe(l)),new Promise((j,S)=>{const B=Hn(),D=C=>{if(B.removeEventListener("message",D),B.removeEventListener("error",N),URL.revokeObjectURL(d),URL.revokeObjectURL(k),I&&URL.revokeObjectURL(I),C.data.type==="success")try{const{frontImageData:P,backImageData:L,width:H,height:V}=C.data;if(!P||!L||!H||!V){S(new Error("Invalid response from worker"));return}const te=it(P,"image/jpeg"),G=it(L,"image/jpeg"),W=H/96*25.4,Y=V/96*25.4,$=new Xt.jsPDF({orientation:W>Y?"landscape":"portrait",unit:"mm",format:[W,Y]});$.addImage(te,"JPEG",0,0,W,Y),$.addPage([W,Y]),$.addImage(G,"JPEG",0,0,W,Y);const ne=$.output("blob");j(ne)}catch(P){S(P)}else S(new Error(C.data.error))},N=C=>{B.removeEventListener("message",D),B.removeEventListener("error",N),URL.revokeObjectURL(d),URL.revokeObjectURL(k),I&&URL.revokeObjectURL(I),S(new Error(C.message))};B.addEventListener("message",D),B.addEventListener("error",N),B.postMessage({type:"generate",frontTemplateUrl:d,backTemplateUrl:k,portraitUrl:I,templateWidth:a,templateHeight:r,templateHue:m,portraitZoom:o,portraitPanX:i,portraitPanY:u,layout:{front:{portrait:c.front.portrait,namePlate:c.front.namePlate},back:{namePlate:c.back.namePlate,contactInfo:c.back.contactInfo,description:c.back.description,signature:c.back.signature}},name:x,email:f,phone:b,description:y,language:w})})}function jt(e,t){const n=URL.createObjectURL(e),a=document.createElement("a");a.href=n,a.download=t,document.body.appendChild(a),a.click(),document.body.removeChild(a),URL.revokeObjectURL(n)}async function Bt(e){const t=await Rt(e);jt(t,e.filename)}function Dn(){const e=v(d=>d.appLanguage),t=v(d=>d.voucherConfig.language),n=v(d=>d.voucherConfig.hours),a=v(d=>d.voucherConfig.description),r=v(d=>d.voucherConfig.templateHue),c=v(d=>d.personalInfo),l=v(d=>d.portrait),o=v(d=>d.isExporting),i=v(d=>d.setIsExporting),u=J(e),m=Je(),x=Qe(),f=l.useEnhanced&&l.enhanced?l.enhanced:l.original,b=qe(t,n,a),y=c.name.trim().length>0&&c.email.trim().length>0&&c.phone.trim().length>0&&l.original!==null,w=async()=>{if(!(!y||o)){i(!0);try{const[d,k]=await Promise.all([Xe(n,t,"front"),Xe(n,t,"back")]),I=`zeitgutschein-${n}h-${c.name.replace(/\s+/g,"-").toLowerCase()}.pdf`;await Bt({frontTemplateSrc:d,backTemplateSrc:k,templateWidth:m.width,templateHeight:m.height,layout:x,portrait:f,portraitZoom:l.zoom,portraitPanX:l.panX,portraitPanY:l.panY,templateHue:r,name:c.name,email:c.email,phone:c.phone,description:b,filename:I,language:t})}catch(d){console.error("PDF export failed:",d)}finally{i(!1)}}};return s.jsxs("button",{className:`btn btn-primary w-full btn-lg sm:btn-md ${y?"":"btn-disabled"}`,onClick:w,disabled:!y,"aria-busy":o,children:[o?s.jsx("span",{className:"loading loading-spinner loading-sm"}):s.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:s.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 10v6m0 0l-3-3m3 3l3-3m2 8H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})}),u.export.button]})}function Nt(){const e=v(a=>a.appLanguage),t=v(a=>a.setAppLanguage),n=a=>{t(a)};return s.jsxs("div",{className:"join",children:[s.jsx("button",{className:`join-item btn btn-sm ${e==="de"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>n("de"),children:"DE"}),s.jsx("button",{className:`join-item btn btn-sm ${e==="en"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>n("en"),children:"EN"})]})}function Mn(){const e=v(n=>n.appLanguage),t=J(e);return s.jsxs("div",{className:"navbar bg-currency-green text-currency-cream shadow-lg",children:[s.jsx("div",{className:"navbar-start",children:s.jsx("a",{className:"btn btn-ghost text-xl font-currency font-bold",children:t.header.title})}),s.jsx("div",{className:"navbar-center hidden sm:flex",children:s.jsx("span",{className:"text-sm opacity-80",children:t.header.subtitle})}),s.jsx("div",{className:"navbar-end",children:s.jsx(Nt,{})})]})}const Ce="/",An={id:"time-voucher-classic-de",name:"Zeitgutschein Classic",type:"time-voucher",category:"classic",images:{front:`${Ce}templates/front_hdpi_de.jpg`,back:`${Ce}templates/back_hdpi_de.jpg`,width:6144,height:4096},fields:[{id:"name",type:"text",label:{de:"Name",en:"Name"},required:!0,validation:{minLength:1,maxLength:50}},{id:"hours",type:"select",label:{de:"Stunden",en:"Hours"},required:!0,options:["1","5","10"]},{id:"portrait",type:"image",label:{de:"Portrait",en:"Portrait"},required:!1},{id:"email",type:"text",label:{de:"E-Mail",en:"Email"},required:!1},{id:"phone",type:"text",label:{de:"Telefon",en:"Phone"},required:!1},{id:"description",type:"textarea",label:{de:"Beschreibung",en:"Description"},required:!1,validation:{maxLength:200}}],layout:{front:{portrait:ue.front.portrait,name:ue.front.namePlate},back:{name:ue.back.namePlate,contactInfo:ue.back.contactInfo,description:ue.back.description}},languages:["de"]},Un={id:"time-voucher-classic-en",name:"Time Voucher Classic",type:"time-voucher",category:"classic",images:{front:`${Ce}templates/front_ldpi_en.png`,back:`${Ce}templates/back_ldpi_en.png`,width:1536,height:1024},fields:[{id:"name",type:"text",label:{de:"Name",en:"Name"},required:!0,validation:{minLength:1,maxLength:50}},{id:"hours",type:"select",label:{de:"Stunden",en:"Hours"},required:!0,options:["1","5","10"]},{id:"portrait",type:"image",label:{de:"Portrait",en:"Portrait"},required:!1},{id:"email",type:"text",label:{de:"E-Mail",en:"Email"},required:!1},{id:"phone",type:"text",label:{de:"Telefon",en:"Phone"},required:!1},{id:"description",type:"textarea",label:{de:"Beschreibung",en:"Description"},required:!1,validation:{maxLength:200}}],layout:{front:{portrait:de.front.portrait,name:de.front.namePlate},back:{name:de.back.namePlate,contactInfo:de.back.contactInfo,description:de.back.description}},languages:["en"]},st=[An,Un],Ht={async listTemplates(e){let t=[...st];return e!=null&&e.type&&(t=t.filter(n=>n.type===e.type)),e!=null&&e.category&&(t=t.filter(n=>n.category===e.category)),e!=null&&e.language&&(t=t.filter(n=>n.languages.includes(e.language))),t},async getTemplate(e){const t=st.find(n=>n.id===e);if(!t)throw new Error(`Template not found: ${e}`);return t}};function Wn(e){return e==="de"?"time-voucher-classic-de":"time-voucher-classic-en"}let Be=Ht;function Yn(e){Be=e}function zn(){return Be}async function Fn(e){return Be.listTemplates(e)}async function _n(e){return Be.getTemplate(e)}exports.ApiKeyModal=ft;exports.BillPreview=jn;exports.ExportButton=Dn;exports.Header=Mn;exports.LAYOUT_HDPI=ue;exports.LAYOUT_LDPI=de;exports.LanguageToggle=Nt;exports.PREVIEW_HEIGHT=vn;exports.PREVIEW_WIDTH=yn;exports.PersonalInfoForm=Qt;exports.PortraitUpload=fn;exports.TEMPLATE_HEIGHT=ee;exports.TEMPLATE_LAYOUT=je;exports.TEMPLATE_WIDTH=Q;exports.TouchSlider=we;exports.VoucherConfig=bn;exports.applyEngravingEffect=ct;exports.applyHueShift=dt;exports.clearCompositorCache=En;exports.composeTemplate=Lt;exports.composeTemplateFullRes=Xe;exports.downloadBlob=jt;exports.drawContactInfo=yt;exports.drawMultilineText=wt;exports.drawOvalPortrait=xt;exports.drawTemplate=ie;exports.drawText=Ze;exports.enhancePortrait=hn;exports.exportBillAsPDF=Bt;exports.formatDescription=qe;exports.generateBillPDF=Rt;exports.getApiKey=Le;exports.getDefaultTemplateId=Wn;exports.getLayout=Qe;exports.getRemoveBackgroundEndpoint=cn;exports.getTemplate=Je;exports.getTemplateById=_n;exports.getTemplateDimensions=Pn;exports.getTemplateLayers=Ke;exports.getTemplateProvider=zn;exports.hasApiKey=Pe;exports.hasCustomEndpoint=un;exports.listTemplates=Fn;exports.loadImage=E;exports.preloadAllTemplates=Sn;exports.preloadBaseImages=kn;exports.removeBackground=pt;exports.renderBackSide=kt;exports.renderFrontSide=vt;exports.resizeImage=lt;exports.setApiKey=ht;exports.setRemoveBackgroundEndpoint=ln;exports.setTemplateProvider=Yn;exports.staticTemplateProvider=Ht;exports.t=J;exports.useBillCanvasRefs=Bn;exports.useBillStore=v;
|
package/dist/index.d.ts
CHANGED
|
@@ -443,6 +443,23 @@ export declare interface TextConfig extends CanvasPosition {
|
|
|
443
443
|
align?: CanvasTextAlign;
|
|
444
444
|
}
|
|
445
445
|
|
|
446
|
+
/**
|
|
447
|
+
* A touch-friendly slider that prevents accidental value changes while scrolling.
|
|
448
|
+
* Uses a threshold-based approach: only activates slider if horizontal movement
|
|
449
|
+
* exceeds vertical movement significantly.
|
|
450
|
+
*/
|
|
451
|
+
export declare function TouchSlider({ min, max, step, value, onChange, className, disabled, }: TouchSliderProps): JSX.Element;
|
|
452
|
+
|
|
453
|
+
declare interface TouchSliderProps {
|
|
454
|
+
min: number;
|
|
455
|
+
max: number;
|
|
456
|
+
step: number;
|
|
457
|
+
value: number;
|
|
458
|
+
onChange: (value: number) => void;
|
|
459
|
+
className?: string;
|
|
460
|
+
disabled?: boolean;
|
|
461
|
+
}
|
|
462
|
+
|
|
446
463
|
declare interface Translations {
|
|
447
464
|
header: {
|
|
448
465
|
title: string;
|