@antontranelis/money-printer 1.0.8 → 1.0.9
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 +1 -1
- package/dist/index.d.ts +17 -0
- package/dist/index.js +335 -307
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),Ne=require("zustand"),Ce=require("zustand/middleware"),f=require("react"),Te=require("jspdf");var _=typeof document<"u"?document.currentScript:null;const ee={personalInfo:{name:"",email:"",phone:""},voucherConfig:{hours:1,description:"",language:"de"},portrait:{original:null,enhanced:null,useEnhanced:!1,zoom:1},currentSide:"front",isEnhancing:!1,isExporting:!1},v=Ne.create()(Ce.persist(e=>({...ee,setPersonalInfo:t=>e(n=>({personalInfo:{...n.personalInfo,...t}})),setVoucherConfig:t=>e(n=>({voucherConfig:{...n.voucherConfig,...t}})),setPortrait:(t,n=null)=>e(a=>({portrait:{original:t,enhanced:n,useEnhanced:!1,zoom:a.portrait.original&&t?a.portrait.zoom:1}})),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}})),setCurrentSide:t=>e({currentSide:t}),flipSide:()=>e(t=>({currentSide:t.currentSide==="front"?"back":"front"})),setIsEnhancing:t=>e({isEnhancing:t}),setIsExporting:t=>e({isExporting:t}),setLanguage:t=>e(n=>({voucherConfig:{...n.voucherConfig,language:t}})),setHours:t=>e(n=>({voucherConfig:{...n.voucherConfig,hours:t}})),reset:()=>e(ee)}),{name:"money-generator-storage",partialize:e=>({personalInfo:e.personalInfo,voucherConfig:e.voucherConfig,portrait:e.portrait})})),Ae={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?"}},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 {hours} {hourLabel} meiner Zeit oder ein gleichwertiges Dankeschön"}},Le={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?"}},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 {hours} {hourLabel} of my time or an equivalent thank you"}},Re={de:Ae,en:Le};function R(e){return Re[e]}function W(e,t,n){if(n&&n.trim())return n;const a=R(e),o=t===1?a.form.voucher.hourLabel:a.form.voucher.hoursLabel;return a.bill.descriptionText.replace("{hours}",t.toString()).replace("{hourLabel}",o)}function _e(){const e=v(o=>o.voucherConfig.language),t=v(o=>o.personalInfo),n=v(o=>o.setPersonalInfo),a=R(e);return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"form-control",children:[r.jsx("label",{className:"label",children:r.jsx("span",{className:"label-text font-medium",children:a.form.personalInfo.name})}),r.jsx("input",{type:"text",placeholder:a.form.personalInfo.namePlaceholder,className:"input input-bordered w-full",value:t.name,onChange:o=>n({name:o.target.value})})]}),r.jsxs("div",{className:"form-control",children:[r.jsx("label",{className:"label",children:r.jsx("span",{className:"label-text font-medium",children:a.form.personalInfo.email})}),r.jsx("input",{type:"email",placeholder:a.form.personalInfo.emailPlaceholder,className:"input input-bordered w-full",value:t.email,onChange:o=>n({email:o.target.value})})]}),r.jsxs("div",{className:"form-control",children:[r.jsx("label",{className:"label",children:r.jsx("span",{className:"label-text font-medium",children:a.form.personalInfo.phone})}),r.jsx("input",{type:"tel",placeholder:a.form.personalInfo.phonePlaceholder,className:"input input-bordered w-full",value:t.phone,onChange:o=>n({phone:o.target.value})})]})]})}async function ae(e,t=.5){return new Promise((n,a)=>{const o=new Image;o.onload=()=>{const i=document.createElement("canvas"),c=i.getContext("2d");if(!c){a(new Error("Failed to get canvas context"));return}i.width=o.width,i.height=o.height,c.drawImage(o,0,0);const l=c.getImageData(0,0,i.width,i.height),s=l.data,d=1+t*.8;for(let u=0;u<s.length;u+=4){const m=s[u],g=s[u+1],b=s[u+2];if(s[u+3]===0)continue;let I=(((.299*m+.587*g+.114*b)/255-.5)*d+.5)*255;I=Math.max(0,Math.min(255,I));const y=Math.min(255,I*.9+25),N=Math.min(255,I*.78+15),w=Math.min(255,I*.55+5);s[u]=Math.round(m*(1-t)+y*t),s[u+1]=Math.round(g*(1-t)+N*t),s[u+2]=Math.round(b*(1-t)+w*t)}c.putImageData(l,0,0),n(i.toDataURL("image/png"))},o.onerror=()=>a(new Error("Failed to load image")),o.src=e})}const De="https://api.stability.ai/v1/generation",Be="https://api.stability.ai/v2beta/stable-image/edit/remove-background",re="stability_api_key",Ue={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"},te=[{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 $e(e,t){const n=e/t;let a=te[0],o=1/0;for(const i of te){const c=i.width/i.height,l=Math.abs(n-c);l<o&&(o=l,a=i)}return a}function Me(e){return new Promise((t,n)=>{const a=new Image;a.onload=()=>{const o=$e(a.width,a.height),i=document.createElement("canvas");i.width=o.width,i.height=o.height;const c=i.getContext("2d");if(!c){n(new Error("Failed to get canvas context"));return}const l=a.width/a.height,s=o.width/o.height;let d=0,u=0,m=a.width,g=a.height;l>s?(m=a.height*s,d=(a.width-m)/2):(g=a.width/s,u=(a.height-g)/2),c.drawImage(a,d,u,m,g,0,0,o.width,o.height),t(i.toDataURL("image/png"))},a.onerror=()=>n(new Error("Failed to load image")),a.src=e})}function oe(e){var c;const t=e.split(","),n=((c=t[0].match(/:(.*?);/))==null?void 0:c[1])||"image/png",a=atob(t[1]),o=a.length,i=new Uint8Array(o);for(let l=0;l<o;l++)i[l]=a.charCodeAt(l);return new Blob([i],{type:n})}function F(){var t;const e=typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.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(re):null}function ie(e){localStorage.setItem(re,e)}function se(){return F()!==null}async function Fe(e){const t=F();if(!t)throw new Error("No Stability AI API key configured");const{imageDataUrl:n,style:a,strength:o=.35}=e,i=await Me(n),c=oe(i),l=new FormData;l.append("init_image",c,"portrait.png"),l.append("init_image_mode","IMAGE_STRENGTH"),l.append("image_strength",String(1-o)),l.append("text_prompts[0][text]",Ue[a]),l.append("text_prompts[0][weight]","1"),l.append("cfg_scale","7"),l.append("samples","1"),l.append("steps","30");const d=await fetch(`${De}/stable-diffusion-xl-1024-v1-0/image-to-image`,{method:"POST",headers:{Authorization:`Bearer ${t}`,Accept:"application/json"},body:l});if(!d.ok){const m=await d.text();throw console.error("Stability AI error:",m),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 u=await d.json();if(!u.artifacts||u.artifacts.length===0)throw new Error("No image generated");return`data:image/png;base64,${u.artifacts[0].base64}`}async function le(e){const t=F();if(!t)throw new Error("No Stability AI API key configured");const n=oe(e),a=new FormData;a.append("image",n,"image.png"),a.append("output_format","png");const o=await fetch(Be,{method:"POST",headers:{Authorization:`Bearer ${t}`,Accept:"image/*"},body:a});if(!o.ok){const c=await o.text();throw console.error("Stability AI remove background error:",c),o.status===401?new Error("Invalid API key"):o.status===402?new Error("Insufficient credits"):o.status===429?new Error("Rate limit exceeded. Please try again later."):new Error(`API error: ${o.status}`)}const i=await o.blob();return new Promise((c,l)=>{const s=new FileReader;s.onload=()=>c(s.result),s.onerror=()=>l(new Error("Failed to read result")),s.readAsDataURL(i)})}function ze(){const[e,t]=f.useState(!1),[n,a]=f.useState(!1),[o,i]=f.useState(null),[c,l]=f.useState(se()),s=f.useCallback(()=>i(null),[]),d=f.useCallback(g=>{ie(g),l(!0),i(null)},[]),u=f.useCallback(async(g,b=.5)=>{t(!0),i(null);try{return await ae(g,b)}catch(h){const E=h instanceof Error?h.message:"Enhancement failed";throw i(E),h}finally{t(!1)}},[]),m=f.useCallback(async g=>{a(!0),i(null);try{return await le(g)}catch(b){const h=b instanceof Error?b.message:"Background removal failed";throw i(h),b}finally{a(!1)}},[]);return{enhance:u,removeBg:m,isEnhancing:e,isRemovingBg:n,error:o,hasKey:c,setApiKey:d,clearError:s}}function ce({isOpen:e,onClose:t,onSubmit:n}){const a=v(d=>d.voucherConfig.language),[o,i]=f.useState("");if(!e)return null;const c=d=>{d.preventDefault(),o.trim()&&(n(o.trim()),i(""),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 r.jsxs("dialog",{className:"modal modal-open",children:[r.jsxs("div",{className:"modal-box",children:[r.jsx("h3",{className:"font-bold text-lg",children:s.title}),r.jsx("p",{className:"py-4 text-sm opacity-80",children:s.description}),r.jsxs("form",{onSubmit:c,children:[r.jsxs("div",{className:"form-control",children:[r.jsx("input",{type:"password",placeholder:s.placeholder,className:"input input-bordered w-full",value:o,onChange:d=>i(d.target.value),autoFocus:!0}),r.jsx("label",{className:"label",children:r.jsx("span",{className:"label-text-alt",children:s.hint})})]}),r.jsxs("div",{className:"modal-action",children:[r.jsx("button",{type:"button",className:"btn btn-ghost",onClick:t,children:s.cancel}),r.jsx("button",{type:"submit",className:"btn btn-primary",disabled:!o.trim(),children:s.submit})]})]})]}),r.jsx("form",{method:"dialog",className:"modal-backdrop",children:r.jsx("button",{onClick:t,children:"close"})})]})}function He(){const e=v(p=>p.voucherConfig.language),t=v(p=>p.portrait),n=v(p=>p.setPortrait),a=v(p=>p.setPortraitZoom),{enhance:o,removeBg:i,isEnhancing:c,isRemovingBg:l,error:s,hasKey:d,setApiKey:u}=ze(),m=R(e),g=f.useRef(null),[b,h]=f.useState(!1),[E,I]=f.useState(!1),[y,N]=f.useState(null),[w,P]=f.useState(null),[C,T]=f.useState(!1),[S,D]=f.useState(0),B=f.useRef(null);f.useEffect(()=>()=>{B.current&&clearTimeout(B.current)},[]);const H=f.useCallback(async p=>{if(!p.type.startsWith("image/"))return;const x=new FileReader;x.onload=async k=>{var Q;const J=(Q=k.target)==null?void 0:Q.result;N(J),n(J),T(!1),P(null),D(0)},x.readAsDataURL(p)},[n]),ve=f.useCallback(p=>{p.preventDefault(),h(!1);const x=p.dataTransfer.files[0];x&&H(x)},[H]),we=f.useCallback(p=>{p.preventDefault(),h(!0)},[]),ye=f.useCallback(p=>{p.preventDefault(),h(!1)},[]),Ie=()=>{var p;(p=g.current)==null||p.click()},ke=p=>{var k;const x=(k=p.target.files)==null?void 0:k[0];x&&H(x)},U=f.useCallback(async(p,x)=>{try{return await o(p,x)}catch(k){return console.error("Enhancement failed:",k),p}},[o]),X=f.useCallback(async p=>{try{const x=await i(p);return P(x),x}catch(x){return console.error("Background removal failed:",x),p}},[i]),je=async()=>{if(!y)return;if(!C&&!d){I(!0);return}const p=!C;if(T(p),p){const x=await X(y);if(S>0){const k=await U(x,S);n(k)}else n(x)}else if(P(null),S>0){const x=await U(y,S);n(x)}else n(y)},Pe=p=>{D(p),B.current&&clearTimeout(B.current),y&&(B.current=setTimeout(async()=>{const x=C&&w?w:y;if(p===0)n(x);else{const k=await U(x,p);n(k)}},150))},Ee=async p=>{if(u(p),!y)return;T(!0);const x=await X(y);if(S>0){const k=await U(x,S);n(k)}else n(x)},Se=()=>{n(null),N(null),P(null),T(!1),D(0)};return r.jsxs("div",{className:"space-y-4",children:[t.original?r.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"w-32 h-32 rounded-full overflow-hidden border-4 border-currency-gold shadow-lg",children:r.jsx("img",{src:t.original||"",alt:"Portrait",className:"w-full h-full object-cover",style:{transform:`scale(${t.zoom})`}})}),r.jsx("button",{className:"btn btn-circle btn-xs btn-error absolute -top-1 -right-1",onClick:Se,children:r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),r.jsxs("div",{className:"form-control w-full max-w-xs",children:[r.jsxs("label",{className:"label",children:[r.jsx("span",{className:"label-text",children:m.form.portrait.zoom}),r.jsxs("span",{className:"label-text-alt",children:[Math.round(t.zoom*100),"%"]})]}),r.jsx("input",{type:"range",min:"0.5",max:"2",step:"0.05",value:t.zoom,onChange:p=>a(parseFloat(p.target.value)),className:"range range-primary range-sm"})]}),r.jsxs("div",{className:"form-control w-full max-w-xs",children:[r.jsxs("label",{className:"label",children:[r.jsxs("span",{className:"label-text flex items-center gap-2",children:[e==="de"?"Gravur-Effekt":"Engraving effect",c&&r.jsx("span",{className:"loading loading-spinner loading-xs"})]}),r.jsxs("span",{className:"label-text-alt",children:[Math.round(S*100),"%"]})]}),r.jsx("input",{type:"range",min:"0",max:"1",step:"0.05",value:S,onChange:p=>Pe(parseFloat(p.target.value)),className:"range range-secondary range-sm",disabled:c})]}),r.jsx("div",{className:"form-control",children:r.jsxs("label",{className:"label cursor-pointer justify-start gap-3",children:[r.jsx("input",{type:"checkbox",className:`toggle toggle-primary ${l?"opacity-50":""}`,checked:C,onChange:je,disabled:l}),r.jsxs("span",{className:"label-text flex items-center gap-2",children:[l?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"loading loading-spinner loading-xs"}),e==="de"?"Hintergrund wird entfernt...":"Removing background..."]}):e==="de"?"Hintergrund entfernen":"Remove background",!d&&r.jsx("span",{className:"badge badge-sm badge-outline",children:"API"})]})]})}),s&&r.jsxs("div",{className:"alert alert-warning text-sm py-2",children:[r.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:r.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"})}),r.jsx("span",{children:s})]})]}):r.jsxs("div",{className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${l?"border-primary bg-primary/10 pointer-events-none":b?"border-primary bg-primary/10":"border-base-300 hover:border-primary hover:bg-base-200"}`,onDrop:ve,onDragOver:we,onDragLeave:ye,onClick:Ie,children:[r.jsx("input",{ref:g,type:"file",accept:"image/*",className:"hidden",onChange:ke}),l?r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("span",{className:"loading loading-spinner loading-lg text-primary"}),r.jsx("p",{className:"font-medium",children:e==="de"?"Hintergrund wird entfernt...":"Removing background..."})]}):r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.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:r.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"})}),r.jsx("p",{className:"font-medium",children:m.form.portrait.upload}),r.jsx("p",{className:"text-sm text-base-content/60",children:m.form.portrait.dragDrop})]})]}),r.jsx(ce,{isOpen:E,onClose:()=>I(!1),onSubmit:Ee})]})}function Ke(){return null}const j=typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href}<"u"&&"/"||"/",de={en:{1:{front:`${j}templates/front_ldpi_en.png`,back:`${j}templates/back_ldpi_en.png`,width:1536,height:1024},5:{front:`${j}templates/front_ldpi_en.png`,back:`${j}templates/back_ldpi_en.png`,width:1536,height:1024},10:{front:`${j}templates/front_ldpi_en.png`,back:`${j}templates/back_ldpi_en.png`,width:1536,height:1024}},de:{1:{front:`${j}templates/front_hdpi_de.webp`,back:`${j}templates/back_hdpi_de.webp`,width:6144,height:3200},5:{front:`${j}templates/front_hdpi_de.webp`,back:`${j}templates/back_hdpi_de.webp`,width:6144,height:3200},10:{front:`${j}templates/front_hdpi_de.webp`,back:`${j}templates/back_hdpi_de.webp`,width:6144,height:3200}}},A={front:{portrait:{x:768,y:490,radiusX:236,radiusY:258},namePlate:{x:768,y:848,fontSize:36,maxWidth:380,align:"center"}},back:{portrait:{x:0,y:0,radiusX:0,radiusY:0},namePlate:{x:768,y:832,fontSize:36,maxWidth:380,align:"center"},contactInfo:{x:380,y:500,fontSize:38,lineHeight:55,align:"center"},description:{x:1150,y:500,fontSize:38,maxWidth:480,lineHeight:42,align:"center"}}},L={front:{portrait:{x:3074,y:1530,radiusX:942,radiusY:1020},namePlate:{x:3072,y:2950,fontSize:144,maxWidth:1520,align:"center"}},back:{portrait:{x:0,y:0,radiusX:0,radiusY:0},namePlate:{x:3072,y:2930,fontSize:144,maxWidth:1520,align:"center"},contactInfo:{x:1520,y:1680,fontSize:160,lineHeight:280,align:"center"},description:{x:4600,y:1680,fontSize:145,maxWidth:2e3,lineHeight:210,align:"center"}}};function O(e){return e==="de"?L:A}function q(e,t){return de[e][t]}const K=new Map;async function $(e){return K.has(e)?K.get(e):new Promise((t,n)=>{const a=new Image;a.crossOrigin="anonymous",a.onload=()=>{K.set(e,a),t(a)},a.onerror=n,a.src=e})}function Y(e,t,n,a){e.drawImage(t,0,0,n,a)}function ue(e,t,n,a,o,i,c=1){e.save(),e.beginPath(),e.ellipse(n,a,o,i,0,0,Math.PI*2),e.closePath(),e.clip();const l=t.width/t.height,s=o/i,d=o*2,u=i*2;let m,g;l>s?(g=u,m=u*l):(m=d,g=d/l),m*=c,g*=c;const b=n-m/2,h=a-g/2;e.drawImage(t,b,h,m,g),e.restore()}function V(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 he(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 o=n.maxWidth||400,i=n.lineHeight||n.fontSize*1.4,c=t.split(" "),l=[];let s="";for(const m of c){const g=s?`${s} ${m}`:m;e.measureText(g).width>o&&s?(l.push(s),s=m):s=g}s&&l.push(s);const d=l.length*i;let u=n.y-d/2;for(const m of l)e.fillText(m,n.x,u),u+=i;e.restore()}function pe(e,t,n,a,o,i="#2a3a2a"){e.save(),e.font=`${o.fontSize}px "Times New Roman", serif`,e.textAlign=o.align||"center",e.textBaseline="middle",e.fillStyle=i;const c=o.lineHeight||o.fontSize*1.8,l=[t,n,a].filter(Boolean),s=(l.length-1)*c;let d=o.y-s/2;for(const u of l)u&&(e.fillText(u,o.x,d),d+=c);e.restore()}async function G(e,t,n,a,o,i,c,l=1){const s=e.getContext("2d");if(!s)return;e.width=i,e.height=c,s.clearRect(0,0,i,c);const d=await $(t);if(Y(s,d,i,c),n)try{const u=await $(n);ue(s,u,o.portrait.x,o.portrait.y,o.portrait.radiusX,o.portrait.radiusY,l)}catch(u){console.error("Failed to load portrait:",u)}a&&V(s,a,o.namePlate)}async function Z(e,t,n,a,o,i,c,l,s){const d=e.getContext("2d");if(!d)return;e.width=l,e.height=s,d.clearRect(0,0,l,s);const u=await $(t);Y(d,u,l,s),c.contactInfo&&(n||a||o)&&pe(d,n,a,o,c.contactInfo),c.description&&i&&he(d,i,c.description),n&&V(d,n,c.namePlate)}function We(){const e=v(w=>w.voucherConfig.language),t=v(w=>w.voucherConfig.hours),n=v(w=>w.voucherConfig.description),a=v(w=>w.personalInfo),o=v(w=>w.portrait),i=v(w=>w.currentSide),c=v(w=>w.flipSide),l=R(e),s=f.useRef(null),d=f.useRef(null),u=f.useRef(null),[m,g]=f.useState(!1),b=q(e,t),h=O(e),E=o.useEnhanced&&o.enhanced?o.enhanced:o.original,I=W(e,t,n);f.useEffect(()=>{s.current&&G(s.current,b.front,E,a.name,h.front,b.width,b.height,o.zoom)},[b,E,a.name,h,o.zoom]),f.useEffect(()=>{d.current&&Z(d.current,b.back,a.name,a.email,a.phone,I,h.back,b.width,b.height)},[b,a,I,h]);const y=()=>{g(!0),setTimeout(()=>{c(),g(!1)},150)},N=b.width/b.height;return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex justify-between items-center",children:[r.jsxs("div",{className:"tabs tabs-boxed bg-base-200",children:[r.jsx("button",{className:`tab ${i==="front"?"tab-active bg-primary text-primary-content font-semibold":""}`,onClick:()=>i!=="front"&&y(),children:l.preview.front}),r.jsx("button",{className:`tab ${i==="back"?"tab-active bg-primary text-primary-content font-semibold":""}`,onClick:()=>i!=="back"&&y(),children:l.preview.back})]}),r.jsxs("button",{className:"btn btn-ghost btn-sm",onClick:y,children:[r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.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"})}),l.preview.flip]})]}),r.jsxs("div",{ref:u,className:"relative w-full overflow-hidden shadow-lg",style:{aspectRatio:N},children:[r.jsx("canvas",{ref:s,className:`absolute inset-0 w-full h-full transition-all duration-300 ${i==="front"?m?"opacity-0 scale-95":"opacity-100 scale-100":"opacity-0 scale-95 pointer-events-none"}`}),r.jsx("canvas",{ref:d,className:`absolute inset-0 w-full h-full transition-all duration-300 ${i==="back"?m?"opacity-0 scale-95":"opacity-100 scale-100":"opacity-0 scale-95 pointer-events-none"}`})]})]})}function Oe(){const e=f.useRef(null),t=f.useRef(null);return{frontCanvasRef:e,backCanvasRef:t}}async function me(e){const{frontTemplateSrc:t,backTemplateSrc:n,templateWidth:a,templateHeight:o,layout:i,portrait:c,portraitZoom:l=1,name:s,email:d,phone:u,description:m}=e,g=document.createElement("canvas"),b=document.createElement("canvas");await Promise.all([G(g,t,c,s,i.front,a,o,l),Z(b,n,s,d,u,m,i.back,a,o)]);const h=new Te({orientation:"landscape",unit:"mm",format:"a4"}),E=297,I=210,y=10,N=a/o;let w=E-y*2,P=w/N;P>I-y*2&&(P=I-y*2,w=P*N);const C=(E-w)/2,T=(I-P)/2,S=g.toDataURL("image/jpeg",.95);h.addImage(S,"JPEG",C,T,w,P),h.addPage();const D=b.toDataURL("image/jpeg",.95);return h.addImage(D,"JPEG",C,T,w,P),h.output("blob")}function ge(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 fe(e){const t=await me(e);ge(t,e.filename)}function qe(){const e=v(h=>h.voucherConfig.language),t=v(h=>h.voucherConfig.hours),n=v(h=>h.voucherConfig.description),a=v(h=>h.personalInfo),o=v(h=>h.portrait),i=v(h=>h.isExporting),c=v(h=>h.setIsExporting),l=R(e),s=q(e,t),d=O(e),u=o.useEnhanced&&o.enhanced?o.enhanced:o.original,m=W(e,t,n),g=a.name.trim().length>0&&a.email.trim().length>0&&a.phone.trim().length>0&&o.original!==null,b=async()=>{if(!(!g||i)){c(!0);try{const h=`zeitgutschein-${t}h-${a.name.replace(/\s+/g,"-").toLowerCase()}.pdf`;await fe({frontTemplateSrc:s.front,backTemplateSrc:s.back,templateWidth:s.width,templateHeight:s.height,layout:d,portrait:u,portraitZoom:o.zoom,name:a.name,email:a.email,phone:a.phone,description:m,filename:h})}catch(h){console.error("PDF export failed:",h)}finally{c(!1)}}};return r.jsx("button",{className:`btn btn-primary flex-1 ${i?"loading":""}`,onClick:b,disabled:!g||i,children:i?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"loading loading-spinner loading-sm"}),l.export.exporting]}):r.jsxs(r.Fragment,{children:[r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.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"})}),l.export.button]})})}function be(){const e=v(a=>a.voucherConfig.language),t=v(a=>a.setLanguage),n=a=>{t(a)};return r.jsxs("div",{className:"join",children:[r.jsx("button",{className:`join-item btn btn-sm ${e==="de"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>n("de"),children:"DE"}),r.jsx("button",{className:`join-item btn btn-sm ${e==="en"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>n("en"),children:"EN"})]})}function Ye(){const e=v(n=>n.voucherConfig.language),t=R(e);return r.jsxs("div",{className:"navbar bg-currency-green text-currency-cream shadow-lg",children:[r.jsx("div",{className:"navbar-start",children:r.jsx("a",{className:"btn btn-ghost text-xl font-currency font-bold",children:t.header.title})}),r.jsx("div",{className:"navbar-center hidden sm:flex",children:r.jsx("span",{className:"text-sm opacity-80",children:t.header.subtitle})}),r.jsx("div",{className:"navbar-end",children:r.jsx(be,{})})]})}const M="/",Ve={id:"time-voucher-classic-de",name:"Zeitgutschein Classic",type:"time-voucher",category:"classic",images:{front:`${M}templates/front_hdpi_de.jpg`,back:`${M}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:L.front.portrait,name:L.front.namePlate},back:{name:L.back.namePlate,contactInfo:L.back.contactInfo,description:L.back.description}},languages:["de"]},Ge={id:"time-voucher-classic-en",name:"Time Voucher Classic",type:"time-voucher",category:"classic",images:{front:`${M}templates/front_ldpi_en.png`,back:`${M}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:A.front.portrait,name:A.front.namePlate},back:{name:A.back.namePlate,contactInfo:A.back.contactInfo,description:A.back.description}},languages:["en"]},ne=[Ve,Ge],xe={async listTemplates(e){let t=[...ne];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=ne.find(n=>n.id===e);if(!t)throw new Error(`Template not found: ${e}`);return t}};function Ze(e){return e==="de"?"time-voucher-classic-de":"time-voucher-classic-en"}let z=xe;function Xe(e){z=e}function Je(){return z}async function Qe(e){return z.listTemplates(e)}async function et(e){return z.getTemplate(e)}exports.ApiKeyModal=ce;exports.BillPreview=We;exports.ExportButton=qe;exports.Header=Ye;exports.LAYOUT_HDPI=L;exports.LAYOUT_LDPI=A;exports.LanguageToggle=be;exports.PersonalInfoForm=_e;exports.PortraitUpload=He;exports.TEMPLATES=de;exports.VoucherConfig=Ke;exports.applyEngravingEffect=ae;exports.downloadBlob=ge;exports.drawContactInfo=pe;exports.drawMultilineText=he;exports.drawOvalPortrait=ue;exports.drawTemplate=Y;exports.drawText=V;exports.enhancePortrait=Fe;exports.exportBillAsPDF=fe;exports.formatDescription=W;exports.generateBillPDF=me;exports.getApiKey=F;exports.getDefaultTemplateId=Ze;exports.getLayout=O;exports.getTemplate=q;exports.getTemplateById=et;exports.getTemplateProvider=Je;exports.hasApiKey=se;exports.listTemplates=Qe;exports.loadImage=$;exports.removeBackground=le;exports.renderBackSide=Z;exports.renderFrontSide=G;exports.setApiKey=ie;exports.setTemplateProvider=Xe;exports.staticTemplateProvider=xe;exports.t=R;exports.useBillCanvasRefs=Oe;exports.useBillStore=v;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react/jsx-runtime"),Ce=require("zustand"),Te=require("zustand/middleware"),f=require("react"),Re=require("jspdf");var _=typeof document<"u"?document.currentScript:null;const te={personalInfo:{name:"",email:"",phone:""},voucherConfig:{hours:1,description:"",language:"de"},portrait:{original:null,enhanced:null,useEnhanced:!1,zoom:1},currentSide:"front",isEnhancing:!1,isExporting:!1},v=Ce.create()(Te.persist(e=>({...te,setPersonalInfo:t=>e(n=>({personalInfo:{...n.personalInfo,...t}})),setVoucherConfig:t=>e(n=>({voucherConfig:{...n.voucherConfig,...t}})),setPortrait:(t,n=null)=>e(a=>({portrait:{original:t,enhanced:n,useEnhanced:!1,zoom:a.portrait.original&&t?a.portrait.zoom:1}})),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}})),setCurrentSide:t=>e({currentSide:t}),flipSide:()=>e(t=>({currentSide:t.currentSide==="front"?"back":"front"})),setIsEnhancing:t=>e({isEnhancing:t}),setIsExporting:t=>e({isExporting:t}),setLanguage:t=>e(n=>({voucherConfig:{...n.voucherConfig,language:t}})),setHours:t=>e(n=>({voucherConfig:{...n.voucherConfig,hours:t}})),reset:()=>e(te)}),{name:"money-generator-storage",partialize:e=>({personalInfo:e.personalInfo,voucherConfig:e.voucherConfig,portrait:e.portrait})})),Ae={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?"}},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 {hours} {hourLabel} meiner Zeit oder ein gleichwertiges Dankeschön"}},Le={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?"}},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 {hours} {hourLabel} of my time or an equivalent thank you"}},_e={de:Ae,en:Le};function L(e){return _e[e]}function W(e,t,n){if(n&&n.trim())return n;const a=L(e),o=t===1?a.form.voucher.hourLabel:a.form.voucher.hoursLabel;return a.bill.descriptionText.replace("{hours}",t.toString()).replace("{hourLabel}",o)}function De(){const e=v(o=>o.voucherConfig.language),t=v(o=>o.personalInfo),n=v(o=>o.setPersonalInfo),a=L(e);return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"form-control",children:[r.jsx("label",{className:"label",children:r.jsx("span",{className:"label-text font-medium",children:a.form.personalInfo.name})}),r.jsx("input",{type:"text",placeholder:a.form.personalInfo.namePlaceholder,className:"input input-bordered w-full",value:t.name,onChange:o=>n({name:o.target.value})})]}),r.jsxs("div",{className:"form-control",children:[r.jsx("label",{className:"label",children:r.jsx("span",{className:"label-text font-medium",children:a.form.personalInfo.email})}),r.jsx("input",{type:"email",placeholder:a.form.personalInfo.emailPlaceholder,className:"input input-bordered w-full",value:t.email,onChange:o=>n({email:o.target.value})})]}),r.jsxs("div",{className:"form-control",children:[r.jsx("label",{className:"label",children:r.jsx("span",{className:"label-text font-medium",children:a.form.personalInfo.phone})}),r.jsx("input",{type:"tel",placeholder:a.form.personalInfo.phonePlaceholder,className:"input input-bordered w-full",value:t.phone,onChange:o=>n({phone:o.target.value})})]})]})}async function re(e,t=.5){return new Promise((n,a)=>{const o=new Image;o.onload=()=>{const s=document.createElement("canvas"),c=s.getContext("2d");if(!c){a(new Error("Failed to get canvas context"));return}s.width=o.width,s.height=o.height,c.drawImage(o,0,0);const l=c.getImageData(0,0,s.width,s.height),i=l.data,d=1+t*.8;for(let u=0;u<i.length;u+=4){const m=i[u],g=i[u+1],b=i[u+2];if(i[u+3]===0)continue;let k=(((.299*m+.587*g+.114*b)/255-.5)*d+.5)*255;k=Math.max(0,Math.min(255,k));const y=Math.min(255,k*.9+25),N=Math.min(255,k*.78+15),w=Math.min(255,k*.55+5);i[u]=Math.round(m*(1-t)+y*t),i[u+1]=Math.round(g*(1-t)+N*t),i[u+2]=Math.round(b*(1-t)+w*t)}c.putImageData(l,0,0),n(s.toDataURL("image/png"))},o.onerror=()=>a(new Error("Failed to load image")),o.src=e})}const Be="https://api.stability.ai/v1/generation",$e="https://api.stability.ai/v2beta/stable-image/edit/remove-background",oe="stability_api_key";let D=null;function Ue(e){D=e}function Me(){return D}function Fe(){return D!==null}const ze={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"},ne=[{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 He(e,t){const n=e/t;let a=ne[0],o=1/0;for(const s of ne){const c=s.width/s.height,l=Math.abs(n-c);l<o&&(o=l,a=s)}return a}function Ke(e){return new Promise((t,n)=>{const a=new Image;a.onload=()=>{const o=He(a.width,a.height),s=document.createElement("canvas");s.width=o.width,s.height=o.height;const c=s.getContext("2d");if(!c){n(new Error("Failed to get canvas context"));return}const l=a.width/a.height,i=o.width/o.height;let d=0,u=0,m=a.width,g=a.height;l>i?(m=a.height*i,d=(a.width-m)/2):(g=a.width/i,u=(a.height-g)/2),c.drawImage(a,d,u,m,g,0,0,o.width,o.height),t(s.toDataURL("image/png"))},a.onerror=()=>n(new Error("Failed to load image")),a.src=e})}function ie(e){var c;const t=e.split(","),n=((c=t[0].match(/:(.*?);/))==null?void 0:c[1])||"image/png",a=atob(t[1]),o=a.length,s=new Uint8Array(o);for(let l=0;l<o;l++)s[l]=a.charCodeAt(l);return new Blob([s],{type:n})}function z(){var t;const e=typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.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(oe):null}function se(e){localStorage.setItem(oe,e)}function le(){return D?!0:z()!==null}async function Oe(e){const t=z();if(!t)throw new Error("No Stability AI API key configured");const{imageDataUrl:n,style:a,strength:o=.35}=e,s=await Ke(n),c=ie(s),l=new FormData;l.append("init_image",c,"portrait.png"),l.append("init_image_mode","IMAGE_STRENGTH"),l.append("image_strength",String(1-o)),l.append("text_prompts[0][text]",ze[a]),l.append("text_prompts[0][weight]","1"),l.append("cfg_scale","7"),l.append("samples","1"),l.append("steps","30");const d=await fetch(`${Be}/stable-diffusion-xl-1024-v1-0/image-to-image`,{method:"POST",headers:{Authorization:`Bearer ${t}`,Accept:"application/json"},body:l});if(!d.ok){const m=await d.text();throw console.error("Stability AI error:",m),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 u=await d.json();if(!u.artifacts||u.artifacts.length===0)throw new Error("No image generated");return`data:image/png;base64,${u.artifacts[0].base64}`}async function ce(e){if(D){const c=await fetch(D,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({imageDataUrl:e})});if(!c.ok){const i=await c.json().catch(()=>({}));throw new Error(i.error||`API error: ${c.status}`)}return(await c.json()).imageDataUrl}const t=z();if(!t)throw new Error("No Stability AI API key configured");const n=ie(e),a=new FormData;a.append("image",n,"image.png"),a.append("output_format","png");const o=await fetch($e,{method:"POST",headers:{Authorization:`Bearer ${t}`,Accept:"image/*"},body:a});if(!o.ok){const c=await o.text();throw console.error("Stability AI remove background error:",c),o.status===401?new Error("Invalid API key"):o.status===402?new Error("Insufficient credits"):o.status===429?new Error("Rate limit exceeded. Please try again later."):new Error(`API error: ${o.status}`)}const s=await o.blob();return new Promise((c,l)=>{const i=new FileReader;i.onload=()=>c(i.result),i.onerror=()=>l(new Error("Failed to read result")),i.readAsDataURL(s)})}function We(){const[e,t]=f.useState(!1),[n,a]=f.useState(!1),[o,s]=f.useState(null),[c,l]=f.useState(le()),i=f.useCallback(()=>s(null),[]),d=f.useCallback(g=>{se(g),l(!0),s(null)},[]),u=f.useCallback(async(g,b=.5)=>{t(!0),s(null);try{return await re(g,b)}catch(h){const E=h instanceof Error?h.message:"Enhancement failed";throw s(E),h}finally{t(!1)}},[]),m=f.useCallback(async g=>{a(!0),s(null);try{return await ce(g)}catch(b){const h=b instanceof Error?b.message:"Background removal failed";throw s(h),b}finally{a(!1)}},[]);return{enhance:u,removeBg:m,isEnhancing:e,isRemovingBg:n,error:o,hasKey:c,setApiKey:d,clearError:i}}function de({isOpen:e,onClose:t,onSubmit:n}){const a=v(d=>d.voucherConfig.language),[o,s]=f.useState("");if(!e)return null;const c=d=>{d.preventDefault(),o.trim()&&(n(o.trim()),s(""),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 r.jsxs("dialog",{className:"modal modal-open",children:[r.jsxs("div",{className:"modal-box",children:[r.jsx("h3",{className:"font-bold text-lg",children:i.title}),r.jsx("p",{className:"py-4 text-sm opacity-80",children:i.description}),r.jsxs("form",{onSubmit:c,children:[r.jsxs("div",{className:"form-control",children:[r.jsx("input",{type:"password",placeholder:i.placeholder,className:"input input-bordered w-full",value:o,onChange:d=>s(d.target.value),autoFocus:!0}),r.jsx("label",{className:"label",children:r.jsx("span",{className:"label-text-alt",children:i.hint})})]}),r.jsxs("div",{className:"modal-action",children:[r.jsx("button",{type:"button",className:"btn btn-ghost",onClick:t,children:i.cancel}),r.jsx("button",{type:"submit",className:"btn btn-primary",disabled:!o.trim(),children:i.submit})]})]})]}),r.jsx("form",{method:"dialog",className:"modal-backdrop",children:r.jsx("button",{onClick:t,children:"close"})})]})}function qe(){const e=v(p=>p.voucherConfig.language),t=v(p=>p.portrait),n=v(p=>p.setPortrait),a=v(p=>p.setPortraitZoom),{enhance:o,removeBg:s,isEnhancing:c,isRemovingBg:l,error:i,hasKey:d,setApiKey:u}=We(),m=L(e),g=f.useRef(null),[b,h]=f.useState(!1),[E,k]=f.useState(!1),[y,N]=f.useState(null),[w,P]=f.useState(null),[C,T]=f.useState(!1),[S,B]=f.useState(0),$=f.useRef(null);f.useEffect(()=>()=>{$.current&&clearTimeout($.current)},[]);const K=f.useCallback(async p=>{if(!p.type.startsWith("image/"))return;const x=new FileReader;x.onload=async I=>{var ee;const Q=(ee=I.target)==null?void 0:ee.result;N(Q),n(Q),T(!1),P(null),B(0)},x.readAsDataURL(p)},[n]),we=f.useCallback(p=>{p.preventDefault(),h(!1);const x=p.dataTransfer.files[0];x&&K(x)},[K]),ye=f.useCallback(p=>{p.preventDefault(),h(!0)},[]),ke=f.useCallback(p=>{p.preventDefault(),h(!1)},[]),Ie=()=>{var p;(p=g.current)==null||p.click()},je=p=>{var I;const x=(I=p.target.files)==null?void 0:I[0];x&&K(x)},U=f.useCallback(async(p,x)=>{try{return await o(p,x)}catch(I){return console.error("Enhancement failed:",I),p}},[o]),J=f.useCallback(async p=>{try{const x=await s(p);return P(x),x}catch(x){return console.error("Background removal failed:",x),p}},[s]),Pe=async()=>{if(!y)return;if(!C&&!d){k(!0);return}const p=!C;if(T(p),p){const x=await J(y);if(S>0){const I=await U(x,S);n(I)}else n(x)}else if(P(null),S>0){const x=await U(y,S);n(x)}else n(y)},Ee=p=>{B(p),$.current&&clearTimeout($.current),y&&($.current=setTimeout(async()=>{const x=C&&w?w:y;if(p===0)n(x);else{const I=await U(x,p);n(I)}},150))},Se=async p=>{if(u(p),!y)return;T(!0);const x=await J(y);if(S>0){const I=await U(x,S);n(I)}else n(x)},Ne=()=>{n(null),N(null),P(null),T(!1),B(0)};return r.jsxs("div",{className:"space-y-4",children:[t.original?r.jsxs("div",{className:"flex flex-col items-center space-y-4",children:[r.jsxs("div",{className:"relative",children:[r.jsx("div",{className:"w-32 h-32 rounded-full overflow-hidden border-4 border-currency-gold shadow-lg",children:r.jsx("img",{src:t.original||"",alt:"Portrait",className:"w-full h-full object-cover",style:{transform:`scale(${t.zoom})`}})}),r.jsx("button",{className:"btn btn-circle btn-xs btn-error absolute -top-1 -right-1",onClick:Ne,children:r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-4 w-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),r.jsxs("div",{className:"form-control w-full max-w-xs",children:[r.jsxs("label",{className:"label",children:[r.jsx("span",{className:"label-text",children:m.form.portrait.zoom}),r.jsxs("span",{className:"label-text-alt",children:[Math.round(t.zoom*100),"%"]})]}),r.jsx("input",{type:"range",min:"0.5",max:"2",step:"0.05",value:t.zoom,onChange:p=>a(parseFloat(p.target.value)),className:"range range-primary range-sm"})]}),r.jsxs("div",{className:"form-control w-full max-w-xs",children:[r.jsxs("label",{className:"label",children:[r.jsxs("span",{className:"label-text flex items-center gap-2",children:[e==="de"?"Gravur-Effekt":"Engraving effect",c&&r.jsx("span",{className:"loading loading-spinner loading-xs"})]}),r.jsxs("span",{className:"label-text-alt",children:[Math.round(S*100),"%"]})]}),r.jsx("input",{type:"range",min:"0",max:"1",step:"0.05",value:S,onChange:p=>Ee(parseFloat(p.target.value)),className:"range range-secondary range-sm",disabled:c})]}),r.jsx("div",{className:"form-control",children:r.jsxs("label",{className:"label cursor-pointer justify-start gap-3",children:[r.jsx("input",{type:"checkbox",className:`toggle toggle-primary ${l?"opacity-50":""}`,checked:C,onChange:Pe,disabled:l}),r.jsxs("span",{className:"label-text flex items-center gap-2",children:[l?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"loading loading-spinner loading-xs"}),e==="de"?"Hintergrund wird entfernt...":"Removing background..."]}):e==="de"?"Hintergrund entfernen":"Remove background",!d&&r.jsx("span",{className:"badge badge-sm badge-outline",children:"API"})]})]})}),i&&r.jsxs("div",{className:"alert alert-warning text-sm py-2",children:[r.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:r.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"})}),r.jsx("span",{children:i})]})]}):r.jsxs("div",{className:`border-2 border-dashed rounded-lg p-8 text-center cursor-pointer transition-colors ${l?"border-primary bg-primary/10 pointer-events-none":b?"border-primary bg-primary/10":"border-base-300 hover:border-primary hover:bg-base-200"}`,onDrop:we,onDragOver:ye,onDragLeave:ke,onClick:Ie,children:[r.jsx("input",{ref:g,type:"file",accept:"image/*",className:"hidden",onChange:je}),l?r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.jsx("span",{className:"loading loading-spinner loading-lg text-primary"}),r.jsx("p",{className:"font-medium",children:e==="de"?"Hintergrund wird entfernt...":"Removing background..."})]}):r.jsxs("div",{className:"flex flex-col items-center gap-2",children:[r.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:r.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"})}),r.jsx("p",{className:"font-medium",children:m.form.portrait.upload}),r.jsx("p",{className:"text-sm text-base-content/60",children:m.form.portrait.dragDrop})]})]}),r.jsx(de,{isOpen:E,onClose:()=>k(!1),onSubmit:Se})]})}function Ye(){return null}const j=typeof{url:typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href}<"u"&&"/"||"/",ue={en:{1:{front:`${j}templates/front_ldpi_en.png`,back:`${j}templates/back_ldpi_en.png`,width:1536,height:1024},5:{front:`${j}templates/front_ldpi_en.png`,back:`${j}templates/back_ldpi_en.png`,width:1536,height:1024},10:{front:`${j}templates/front_ldpi_en.png`,back:`${j}templates/back_ldpi_en.png`,width:1536,height:1024}},de:{1:{front:`${j}templates/front_hdpi_de.webp`,back:`${j}templates/back_hdpi_de.webp`,width:6144,height:3200},5:{front:`${j}templates/front_hdpi_de.webp`,back:`${j}templates/back_hdpi_de.webp`,width:6144,height:3200},10:{front:`${j}templates/front_hdpi_de.webp`,back:`${j}templates/back_hdpi_de.webp`,width:6144,height:3200}}},R={front:{portrait:{x:768,y:490,radiusX:236,radiusY:258},namePlate:{x:768,y:848,fontSize:36,maxWidth:380,align:"center"}},back:{portrait:{x:0,y:0,radiusX:0,radiusY:0},namePlate:{x:768,y:832,fontSize:36,maxWidth:380,align:"center"},contactInfo:{x:380,y:500,fontSize:38,lineHeight:55,align:"center"},description:{x:1150,y:500,fontSize:38,maxWidth:480,lineHeight:42,align:"center"}}},A={front:{portrait:{x:3074,y:1530,radiusX:942,radiusY:1020},namePlate:{x:3072,y:2950,fontSize:144,maxWidth:1520,align:"center"}},back:{portrait:{x:0,y:0,radiusX:0,radiusY:0},namePlate:{x:3072,y:2930,fontSize:144,maxWidth:1520,align:"center"},contactInfo:{x:1520,y:1680,fontSize:160,lineHeight:280,align:"center"},description:{x:4600,y:1680,fontSize:145,maxWidth:2e3,lineHeight:210,align:"center"}}};function q(e){return e==="de"?A:R}function Y(e,t){return ue[e][t]}const O=new Map;async function M(e){return O.has(e)?O.get(e):new Promise((t,n)=>{const a=new Image;a.crossOrigin="anonymous",a.onload=()=>{O.set(e,a),t(a)},a.onerror=n,a.src=e})}function V(e,t,n,a){e.drawImage(t,0,0,n,a)}function he(e,t,n,a,o,s,c=1){e.save(),e.beginPath(),e.ellipse(n,a,o,s,0,0,Math.PI*2),e.closePath(),e.clip();const l=t.width/t.height,i=o/s,d=o*2,u=s*2;let m,g;l>i?(g=u,m=u*l):(m=d,g=d/l),m*=c,g*=c;const b=n-m/2,h=a-g/2;e.drawImage(t,b,h,m,g),e.restore()}function G(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 pe(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 o=n.maxWidth||400,s=n.lineHeight||n.fontSize*1.4,c=t.split(" "),l=[];let i="";for(const m of c){const g=i?`${i} ${m}`:m;e.measureText(g).width>o&&i?(l.push(i),i=m):i=g}i&&l.push(i);const d=l.length*s;let u=n.y-d/2;for(const m of l)e.fillText(m,n.x,u),u+=s;e.restore()}function me(e,t,n,a,o,s="#2a3a2a"){e.save(),e.font=`${o.fontSize}px "Times New Roman", serif`,e.textAlign=o.align||"center",e.textBaseline="middle",e.fillStyle=s;const c=o.lineHeight||o.fontSize*1.8,l=[t,n,a].filter(Boolean),i=(l.length-1)*c;let d=o.y-i/2;for(const u of l)u&&(e.fillText(u,o.x,d),d+=c);e.restore()}async function Z(e,t,n,a,o,s,c,l=1){const i=e.getContext("2d");if(!i)return;e.width=s,e.height=c,i.clearRect(0,0,s,c);const d=await M(t);if(V(i,d,s,c),n)try{const u=await M(n);he(i,u,o.portrait.x,o.portrait.y,o.portrait.radiusX,o.portrait.radiusY,l)}catch(u){console.error("Failed to load portrait:",u)}a&&G(i,a,o.namePlate)}async function X(e,t,n,a,o,s,c,l,i){const d=e.getContext("2d");if(!d)return;e.width=l,e.height=i,d.clearRect(0,0,l,i);const u=await M(t);V(d,u,l,i),c.contactInfo&&(n||a||o)&&me(d,n,a,o,c.contactInfo),c.description&&s&&pe(d,s,c.description),n&&G(d,n,c.namePlate)}function Ve(){const e=v(w=>w.voucherConfig.language),t=v(w=>w.voucherConfig.hours),n=v(w=>w.voucherConfig.description),a=v(w=>w.personalInfo),o=v(w=>w.portrait),s=v(w=>w.currentSide),c=v(w=>w.flipSide),l=L(e),i=f.useRef(null),d=f.useRef(null),u=f.useRef(null),[m,g]=f.useState(!1),b=Y(e,t),h=q(e),E=o.useEnhanced&&o.enhanced?o.enhanced:o.original,k=W(e,t,n);f.useEffect(()=>{i.current&&Z(i.current,b.front,E,a.name,h.front,b.width,b.height,o.zoom)},[b,E,a.name,h,o.zoom]),f.useEffect(()=>{d.current&&X(d.current,b.back,a.name,a.email,a.phone,k,h.back,b.width,b.height)},[b,a,k,h]);const y=()=>{g(!0),setTimeout(()=>{c(),g(!1)},150)},N=b.width/b.height;return r.jsxs("div",{className:"space-y-4",children:[r.jsxs("div",{className:"flex justify-between items-center",children:[r.jsxs("div",{className:"tabs tabs-boxed bg-base-200",children:[r.jsx("button",{className:`tab ${s==="front"?"tab-active bg-primary text-primary-content font-semibold":""}`,onClick:()=>s!=="front"&&y(),children:l.preview.front}),r.jsx("button",{className:`tab ${s==="back"?"tab-active bg-primary text-primary-content font-semibold":""}`,onClick:()=>s!=="back"&&y(),children:l.preview.back})]}),r.jsxs("button",{className:"btn btn-ghost btn-sm",onClick:y,children:[r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.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"})}),l.preview.flip]})]}),r.jsxs("div",{ref:u,className:"relative w-full overflow-hidden shadow-lg",style:{aspectRatio:N},children:[r.jsx("canvas",{ref:i,className:`absolute inset-0 w-full h-full transition-all duration-300 ${s==="front"?m?"opacity-0 scale-95":"opacity-100 scale-100":"opacity-0 scale-95 pointer-events-none"}`}),r.jsx("canvas",{ref:d,className:`absolute inset-0 w-full h-full transition-all duration-300 ${s==="back"?m?"opacity-0 scale-95":"opacity-100 scale-100":"opacity-0 scale-95 pointer-events-none"}`})]})]})}function Ge(){const e=f.useRef(null),t=f.useRef(null);return{frontCanvasRef:e,backCanvasRef:t}}async function ge(e){const{frontTemplateSrc:t,backTemplateSrc:n,templateWidth:a,templateHeight:o,layout:s,portrait:c,portraitZoom:l=1,name:i,email:d,phone:u,description:m}=e,g=document.createElement("canvas"),b=document.createElement("canvas");await Promise.all([Z(g,t,c,i,s.front,a,o,l),X(b,n,i,d,u,m,s.back,a,o)]);const h=new Re({orientation:"landscape",unit:"mm",format:"a4"}),E=297,k=210,y=10,N=a/o;let w=E-y*2,P=w/N;P>k-y*2&&(P=k-y*2,w=P*N);const C=(E-w)/2,T=(k-P)/2,S=g.toDataURL("image/jpeg",.95);h.addImage(S,"JPEG",C,T,w,P),h.addPage();const B=b.toDataURL("image/jpeg",.95);return h.addImage(B,"JPEG",C,T,w,P),h.output("blob")}function fe(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 be(e){const t=await ge(e);fe(t,e.filename)}function Ze(){const e=v(h=>h.voucherConfig.language),t=v(h=>h.voucherConfig.hours),n=v(h=>h.voucherConfig.description),a=v(h=>h.personalInfo),o=v(h=>h.portrait),s=v(h=>h.isExporting),c=v(h=>h.setIsExporting),l=L(e),i=Y(e,t),d=q(e),u=o.useEnhanced&&o.enhanced?o.enhanced:o.original,m=W(e,t,n),g=a.name.trim().length>0&&a.email.trim().length>0&&a.phone.trim().length>0&&o.original!==null,b=async()=>{if(!(!g||s)){c(!0);try{const h=`zeitgutschein-${t}h-${a.name.replace(/\s+/g,"-").toLowerCase()}.pdf`;await be({frontTemplateSrc:i.front,backTemplateSrc:i.back,templateWidth:i.width,templateHeight:i.height,layout:d,portrait:u,portraitZoom:o.zoom,name:a.name,email:a.email,phone:a.phone,description:m,filename:h})}catch(h){console.error("PDF export failed:",h)}finally{c(!1)}}};return r.jsx("button",{className:`btn btn-primary flex-1 ${s?"loading":""}`,onClick:b,disabled:!g||s,children:s?r.jsxs(r.Fragment,{children:[r.jsx("span",{className:"loading loading-spinner loading-sm"}),l.export.exporting]}):r.jsxs(r.Fragment,{children:[r.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",className:"h-5 w-5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:r.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"})}),l.export.button]})})}function xe(){const e=v(a=>a.voucherConfig.language),t=v(a=>a.setLanguage),n=a=>{t(a)};return r.jsxs("div",{className:"join",children:[r.jsx("button",{className:`join-item btn btn-sm ${e==="de"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>n("de"),children:"DE"}),r.jsx("button",{className:`join-item btn btn-sm ${e==="en"?"btn-active btn-primary":"btn-ghost"}`,onClick:()=>n("en"),children:"EN"})]})}function Xe(){const e=v(n=>n.voucherConfig.language),t=L(e);return r.jsxs("div",{className:"navbar bg-currency-green text-currency-cream shadow-lg",children:[r.jsx("div",{className:"navbar-start",children:r.jsx("a",{className:"btn btn-ghost text-xl font-currency font-bold",children:t.header.title})}),r.jsx("div",{className:"navbar-center hidden sm:flex",children:r.jsx("span",{className:"text-sm opacity-80",children:t.header.subtitle})}),r.jsx("div",{className:"navbar-end",children:r.jsx(xe,{})})]})}const F="/",Je={id:"time-voucher-classic-de",name:"Zeitgutschein Classic",type:"time-voucher",category:"classic",images:{front:`${F}templates/front_hdpi_de.jpg`,back:`${F}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:A.front.portrait,name:A.front.namePlate},back:{name:A.back.namePlate,contactInfo:A.back.contactInfo,description:A.back.description}},languages:["de"]},Qe={id:"time-voucher-classic-en",name:"Time Voucher Classic",type:"time-voucher",category:"classic",images:{front:`${F}templates/front_ldpi_en.png`,back:`${F}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:R.front.portrait,name:R.front.namePlate},back:{name:R.back.namePlate,contactInfo:R.back.contactInfo,description:R.back.description}},languages:["en"]},ae=[Je,Qe],ve={async listTemplates(e){let t=[...ae];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=ae.find(n=>n.id===e);if(!t)throw new Error(`Template not found: ${e}`);return t}};function et(e){return e==="de"?"time-voucher-classic-de":"time-voucher-classic-en"}let H=ve;function tt(e){H=e}function nt(){return H}async function at(e){return H.listTemplates(e)}async function rt(e){return H.getTemplate(e)}exports.ApiKeyModal=de;exports.BillPreview=Ve;exports.ExportButton=Ze;exports.Header=Xe;exports.LAYOUT_HDPI=A;exports.LAYOUT_LDPI=R;exports.LanguageToggle=xe;exports.PersonalInfoForm=De;exports.PortraitUpload=qe;exports.TEMPLATES=ue;exports.VoucherConfig=Ye;exports.applyEngravingEffect=re;exports.downloadBlob=fe;exports.drawContactInfo=me;exports.drawMultilineText=pe;exports.drawOvalPortrait=he;exports.drawTemplate=V;exports.drawText=G;exports.enhancePortrait=Oe;exports.exportBillAsPDF=be;exports.formatDescription=W;exports.generateBillPDF=ge;exports.getApiKey=z;exports.getDefaultTemplateId=et;exports.getLayout=q;exports.getRemoveBackgroundEndpoint=Me;exports.getTemplate=Y;exports.getTemplateById=rt;exports.getTemplateProvider=nt;exports.hasApiKey=le;exports.hasCustomEndpoint=Fe;exports.listTemplates=at;exports.loadImage=M;exports.removeBackground=ce;exports.renderBackSide=X;exports.renderFrontSide=Z;exports.setApiKey=se;exports.setRemoveBackgroundEndpoint=Ue;exports.setTemplateProvider=tt;exports.staticTemplateProvider=ve;exports.t=L;exports.useBillCanvasRefs=Ge;exports.useBillStore=v;
|
package/dist/index.d.ts
CHANGED
|
@@ -110,6 +110,11 @@ export declare function getLayout(language: Language): {
|
|
|
110
110
|
back: TemplateLayout;
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
+
/**
|
|
114
|
+
* Get the current custom endpoint for background removal
|
|
115
|
+
*/
|
|
116
|
+
export declare function getRemoveBackgroundEndpoint(): string | null;
|
|
117
|
+
|
|
113
118
|
export declare function getTemplate(language: Language, hours: HourValue): TemplateConfig;
|
|
114
119
|
|
|
115
120
|
/**
|
|
@@ -124,6 +129,11 @@ export declare function getTemplateProvider(): TemplateProvider;
|
|
|
124
129
|
|
|
125
130
|
export declare function hasApiKey(): boolean;
|
|
126
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Check if a custom endpoint is configured (meaning no local API key is needed)
|
|
134
|
+
*/
|
|
135
|
+
export declare function hasCustomEndpoint(): boolean;
|
|
136
|
+
|
|
127
137
|
export declare function Header(): JSX.Element;
|
|
128
138
|
|
|
129
139
|
export declare type HourValue = 1 | 5 | 10;
|
|
@@ -201,6 +211,13 @@ export declare function renderFrontSide(canvas: HTMLCanvasElement, templateSrc:
|
|
|
201
211
|
|
|
202
212
|
export declare function setApiKey(key: string): void;
|
|
203
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Configure a custom endpoint for background removal.
|
|
216
|
+
* Use this to proxy requests through your own server to protect API keys.
|
|
217
|
+
* The endpoint should accept POST with { imageDataUrl: string } and return { imageDataUrl: string }
|
|
218
|
+
*/
|
|
219
|
+
export declare function setRemoveBackgroundEndpoint(endpoint: string | null): void;
|
|
220
|
+
|
|
204
221
|
/**
|
|
205
222
|
* Set a custom template provider
|
|
206
223
|
* Use this to switch to a CMS-based provider or other source
|