(()=>{var Se=Object.defineProperty;var Re=(e,t,n)=>t in e?Se(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var z=(e,t)=>()=>(e&&(t=e(e=0)),t);var Y=(e,t,n)=>Re(e,typeof t!="symbol"?t+"":t,n);function a(e,t){return X+e+(t?Q+JSON.stringify(t):"")+ee}function L(e){let t=[],n=0;for(;n<e.length;){let s=e.indexOf(X,n);if(s<0){t.push(e.slice(n));break}s>n&&t.push(e.slice(n,s));let r=e.indexOf(ee,s),i=e.slice(s+1,r<0?e.length:r),o=i.indexOf(Q);if(o<0)t.push({de:i});else{let l=JSON.parse(i.slice(o+1)),u={};for(let[f,c]of Object.entries(l))u[f]=typeof c=="number"?c:L(String(c));t.push({de:i.slice(0,o),values:u})}n=r<0?e.length:r+1}return t}var X,Q,ee,B,D=z(()=>{"use strict";X="",Q="",ee="";B="en-US"});function E(e){let t=new Uint8Array(128);for(let i=0;i<64;i++)t[De.charCodeAt(i)]=i;let n=e.replace(/=+$/,"").length,s=new Uint8ClampedArray(Math.floor(n*3/4)),r=0;for(let i=0;i<n;i+=4){let o=t[e.charCodeAt(i)]<<18|t[e.charCodeAt(i+1)]<<12|(i+2<n?t[e.charCodeAt(i+2)]:0)<<6|(i+3<n?t[e.charCodeAt(i+3)]:0);s[r++]=o>>16,r<s.length&&(s[r++]=o>>8&255),r<s.length&&(s[r++]=o&255)}return s}var De,C=z(()=>{"use strict";De="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"});function me(e){if(!e.startsWith("kzm1:"))return"format";let t=E(e.slice(5));if(t.length<8)return"damaged";let n=new DataView(t.buffer,t.byteOffset,t.byteLength),s=n.getUint32(0,!0),r=n.getUint32(4,!0);if(8+s*12+r*12!==t.length)return"damaged";let i=new Float32Array(s*3),o=new Uint32Array(r*3),l=8;for(let u=0;u<i.length;u++,l+=4)i[u]=n.getFloat32(l,!0);for(let u=0;u<o.length;u++,l+=4)o[u]=n.getUint32(l,!0);return o.some(u=>u>=s)?"damaged":{pos:i,tri:o}}var fe=z(()=>{"use strict";C()});function de(e){let t=me(e);if(t==="format")throw new U(a("Unbekanntes Modellformat."));if(t==="damaged")throw new U(a("Die Modelldaten sind besch\xE4digt."));return t}var U,he=z(()=>{"use strict";D();C();fe();U=class extends Error{}});D();function te(e,t,n,s,r){let i=1-r;return{x:i*i*i*e.x+3*i*i*r*t.x+3*i*r*r*n.x+r*r*r*s.x,y:i*i*i*e.y+3*i*i*r*t.y+3*i*r*r*n.y+r*r*r*s.y}}function Te(e,t,n,s){let r=Math.abs(n-t)||1,i=u=>{let f=r*1e-5,c=e(u-f),m=e(u+f);return{x:(m.x-c.x)/(2*f),y:(m.y-c.y)/(2*f)}},o=[],l=(u,f,c)=>{let m=e(u),d=e(f),g=(f-u)/3,b=i(u),w=i(f),$={x:m.x+b.x*g,y:m.y+b.y*g},O={x:d.x-w.x*g,y:d.y-w.y*g},M=0;for(let y=1;y<8;y++){let A=y/8,I=te(m,$,O,d,A),F=e(u+(f-u)*A);M=Math.max(M,Math.hypot(I.x-F.x,I.y-F.y))}if(M>s&&c<12){let y=(u+f)/2;l(u,y,c+1),l(y,f,c+1)}else o.push([$,O,d])};return l(t,n,0),o}var T=class{constructor(){Y(this,"nodes",[])}get last(){return this.nodes[this.nodes.length-1]}same(t){let n=this.last;return!!n&&Math.hypot(n.x-t.x,n.y-t.y)<1e-7}line(t){this.same(t)||this.nodes.push({x:t.x,y:t.y})}cubic(t,n,s){if(!this.nodes.length)throw new Error("PathBuilder: kein Anfangspunkt");this.last.cout={x:t.x,y:t.y},this.nodes.push({x:s.x,y:s.y,cin:{x:n.x,y:n.y}})}curve(t,n,s,r){if(!(Math.abs(s-n)<1e-12)){this.line(t(n));for(let[i,o,l]of Te(t,n,s,r))this.cubic(i,o,l)}}arc(t,n,s,r,i){let o=c=>({x:t+s*Math.cos(c),y:n+s*Math.sin(c)});this.line(o(r));let l=Math.max(1,Math.ceil(Math.abs(i-r)/(Math.PI/2)-1e-9)),u=(i-r)/l,f=4/3*Math.tan(u/4)*s;for(let c=0;c<l;c++){let m=r+c*u,d=m+u,g=o(m),b=o(d);this.cubic({x:g.x-f*Math.sin(m),y:g.y+f*Math.cos(m)},{x:b.x+f*Math.sin(d),y:b.y-f*Math.cos(d)},b)}}close(){let t=this.nodes;if(t.length>1){let n=t[0],s=t[t.length-1];Math.hypot(n.x-s.x,n.y-s.y)<1e-6&&(s.cin&&(n.cin=s.cin),t.pop())}return{nodes:t,closed:!0}}};function ne(e){let t=n=>({x:n.x,y:-n.y});return{closed:e.closed,nodes:e.nodes.map(n=>({...t(n),...n.cin?{cin:t(n.cin)}:{},...n.cout?{cout:t(n.cout)}:{}}))}}D();var re=(e,t=2)=>(Math.round(e*10**t)/10**t).toLocaleString(B,{maximumFractionDigits:t});function se(e="",t="",n="round",s=6){let r=o=>o+e,i=o=>t?`${o} (${t})`:o;return[{key:r("boreType"),type:"enum",label:i(a("Bohrung")),def:n,options:[["none",a("Keine")],["round",a("Rund")],["dflat",a("D-Profil (abgeflacht)")],["key",a("Mit Passfedernut")]]},{key:r("boreDia"),type:"length",label:i(a("Bohrungsdurchmesser")),min:.5,max:2e3,def:s,showIf:{ne:[r("boreType"),"none"]}},{key:r("boreFlat"),type:"length",label:i(a("Ma\xDF \xFCber Abflachung")),min:.1,max:2e3,def:Math.round(s*.917*10)/10,showIf:{eq:[r("boreType"),"dflat"]},title:a("Abstand von der Abflachung zur gegen\xFCberliegenden Seite der Bohrung")},{key:r("keyWidth"),type:"length",label:i(a("Nutbreite")),min:.1,max:200,def:2,showIf:{eq:[r("boreType"),"key"]}},{key:r("keyDepth"),type:"length",label:i(a("Nuttiefe")),min:.1,max:200,def:1,showIf:{eq:[r("boreType"),"key"]},title:a("Tiefe der Nut \xFCber den Bohrungsrand hinaus")}]}var _=(e,t)=>({type:String(e["boreType"+t]),dia:Number(e["boreDia"+t]),flat:Number(e["boreFlat"+t]),keyWidth:Number(e["keyWidth"+t]),keyDepth:Number(e["keyDepth"+t])});function Ie(e,t=""){let n=_(e,t);return n.type==="none"?0:n.type==="key"?n.dia/2+n.keyDepth:n.dia/2}function ie(e,t,n=""){let s=_(e,n),r=t/2,i=s.dia/2-r;if(s.type==="none"||i<=0)return null;let o=new T;if(s.type==="dflat"){let l=s.flat-s.dia/2-r,u=Math.atan2(l,Math.sqrt(Math.max(0,i*i-l*l)));return o.arc(0,0,i,u,-Math.PI-u),o.close()}if(s.type==="key"){let l=(s.keyWidth-t)/2,u=s.dia/2+s.keyDepth-r,f=Math.atan2(Math.sqrt(Math.max(0,i*i-l*l)),l);return o.arc(0,0,i,f,f-2*Math.PI+(Math.PI-2*f)),o.line({x:-l,y:u}),o.line({x:l,y:u}),o.close()}return o.arc(0,0,i,0,2*Math.PI),o.close()}function oe(e,t,n,s,r="",i=!0){let o=_(e,r),l=[];if(o.type==="none")return l;let u=n-Ie(e,r);return u<=0?l.push({key:"boreDia"+r,level:"error",msg:i?a("Die Bohrung ist gr\xF6\xDFer als der Fu\xDFkreis."):a("Die Bohrung reicht \xFCber den Rand.")}):u<s&&l.push({key:"boreDia"+r,level:"warn",msg:i?a("Nur {w} mm Material zwischen Bohrung und Zahnfu\xDF.",{w:re(u)}):a("Nur {w} mm Material zwischen Bohrung und Rand.",{w:re(u)})}),o.type==="dflat"&&(o.flat<=o.dia/2||o.flat>=o.dia)&&l.push({key:"boreFlat"+r,level:"error",msg:a("Das Ma\xDF \xFCber der Abflachung muss zwischen Radius und Durchmesser der Bohrung liegen.")}),o.type==="key"&&o.keyWidth>=o.dia&&l.push({key:"keyWidth"+r,level:"error",msg:a("Die Nut ist breiter als die Bohrung.")}),o.dia/2-t/2<=0&&l.push({key:"boreDia"+r,level:"error",msg:a("Bohrung kleiner als die Schnittfuge.")}),l}var v=.004,ae=e=>Math.tan(e)-e,Fe=e=>e*Math.PI/180;function ue(e){let t=e.teeth,n=e.module,s=Fe(e.pressureAngle),r=n*t/2,i=r*Math.cos(s),o=e.kerf/2,l=Math.PI*n,u=Math.tan(s),f=Math.cos(s),c=e.profileShift*n,m=h=>l/4+(h-c)*u+e.backlash/4-o/f,d=c-(1+e.clearance)*n+o,g=Math.max(0,e.rootFillet*n-o),b=d+g,w=l/2-m(b)+g/f,O=(l-2*m(0))/(2*r),M=h=>O+ae(s)-ae(Math.acos(Math.min(1,i/h))),y=h=>{let N=w+r*h,S=b,P=Math.hypot(N,S)||1,x=N+g*N/P,R=r+S+g*S/P,G=x*Math.cos(h)-R*Math.sin(h),j=x*Math.sin(h)+R*Math.cos(h);return{x:G,y:j}},A=-w/r,I=(b/u-w)/r,F=h=>({R:Math.hypot(h.x,h.y),th:Math.PI/2-Math.atan2(h.y,h.x)}),J=-(b-g*Math.sin(s))>r*Math.sin(s)**2+1e-12,Z=I;if(J){let h=P=>{let x=F(y(P));return x.R<i?-1:x.th-M(x.R)},S=A;for(let P=1;P<=400;P++){let x=A+(I-A)*P/400;if(h(x)>=0){let R=S,G=x;for(let j=0;j<60;j++){let K=(R+G)/2;h(K)>=0?G=K:R=K}Z=(R+G)/2;break}S=x}}let Me=Math.max(i,F(y(Z)).R),H=r+(1+e.profileShift)*n+o,Ae=r+d;return{z:t,m:n,alpha:s,r,rb:i,ra:H,rf:Ae,flankAngle:M,rFlank:Me,tipAngle:M(H),undercut:J,fillet:y,phiRoot:A,phiFlank:Z,rootAngle:w/r}}function Ge(e){let t=new T,n=Math.PI*2/e.z,s=Math.sqrt(Math.max(0,(e.rFlank/e.rb)**2-1)),r=Math.sqrt(Math.max(0,(e.ra/e.rb)**2-1)),i=c=>{let m=e.rb*Math.sqrt(1+c*c);return{R:m,th:e.flankAngle(m)}},o=c=>{let m=e.fillet(c);return{R:Math.hypot(m.x,m.y),th:Math.PI/2-Math.atan2(m.y,m.x)}},l=(c,m,d)=>{let g=Math.PI/2-c*n-m*d.th;return{x:d.R*Math.cos(g),y:d.R*Math.sin(g)}},u=c=>Math.PI/2-c*n,f=n/2;for(let c=0;c<e.z;c++){let m=u(c);e.rootAngle<f&&t.arc(0,0,e.rf,m+f,m+e.rootAngle),t.curve(d=>l(c,-1,o(d)),e.phiRoot,e.phiFlank,v),t.curve(d=>l(c,-1,i(d)),s,r,v),t.arc(0,0,e.ra,m+e.tipAngle,m-e.tipAngle),t.curve(d=>l(c,1,i(d)),r,s,v),t.curve(d=>l(c,1,o(d)),e.phiFlank,e.phiRoot,v),e.rootAngle<f&&t.arc(0,0,e.rf,m-e.rootAngle,m-f)}return t.close()}var W=e=>e,k=(e,t=2)=>(Math.round(e*10**t)/10**t).toLocaleString(B,{maximumFractionDigits:t}),le={id:"gear",version:1,kind:"part",name:a("Zahnrad"),icon:"gear",tile:{group:"mech",text:e=>({name:e("Zahnrad"),desc:e("Evolventen-Zahnrad mit Modul, Z\xE4hnezahl, Bohrung und Speichen; Parameter bleiben \xE4nderbar."),keys:e("Zahnrad Z\xE4hne Getriebe Evolvente Modul|Suchw\xF6rter"),action:e("Zahnrad erstellen (Evolventenverzahnung, Parameter bleiben erhalten)")})},schema:[{key:"teeth",type:"int",label:a("Z\xE4hnezahl"),min:5,max:400,def:24},{key:"module",type:"length",label:a("Modul"),min:.3,max:20,def:2,title:a("Teilkreisdurchmesser geteilt durch Z\xE4hnezahl; Zahnr\xE4der, die ineinandergreifen, brauchen dasselbe Modul")},{key:"pressureAngle",type:"angle",label:a("Eingriffswinkel"),min:10,max:35,def:20,title:a("\xDCblich sind 20\xB0; ineinandergreifende R\xE4der brauchen denselben Winkel")},{key:"backlash",type:"length",label:a("Flankenspiel"),min:0,max:3,def:.1,title:a("Spiel der Zahnradpaarung auf dem Teilkreis; jedes Rad wird um die H\xE4lfte d\xFCnner")},{key:"kerf",type:"length",label:a("Schnittfuge (Kerf)"),min:0,max:2,def:.15,title:a("Breite des Laserschnitts: Die Kontur wird um die H\xE4lfte nach au\xDFen versetzt, damit das Rad die Sollma\xDFe hat. Der Kerf des Layers wirkt beim Lasern zus\xE4tzlich.")},...se(),{key:"profileShift",type:"number",label:a("Profilverschiebung x"),min:-.8,max:1,def:0,advanced:!0,title:a("Positiv macht die Z\xE4hne am Fu\xDF kr\xE4ftiger und vermeidet Unterschnitt; der Achsabstand \xE4ndert sich dann um x\xB7Modul")},{key:"rootFillet",type:"number",label:a("Fu\xDFrundung (\xD7 Modul)"),min:0,max:.45,def:.38,advanced:!0,title:a("Radius der Werkzeugkopfrundung, Norm: 0,38")},{key:"clearance",type:"number",label:a("Kopfspiel (\xD7 Modul)"),min:.1,max:.5,def:.25,advanced:!0,title:a("Abstand zwischen Zahnkopf und Fu\xDFkreis des Gegenrads, Norm: 0,25")}],validate(e){let t=W(e),n=[],s=t.module;if(t.profileShift*s-(1+t.clearance)*s+t.rootFillet*s>=-1e-6&&n.push({key:"profileShift",level:"error",msg:a("Profilverschiebung zu gro\xDF f\xFCr Kopfspiel und Fu\xDFrundung.")}),t.backlash/2>=Math.PI*s/4&&n.push({key:"backlash",level:"error",msg:a("Flankenspiel zu gro\xDF f\xFCr dieses Modul.")}),n.length)return n;let r=ue(t),i=2*r.tipAngle*r.ra;if(i<=.01*s?n.push({key:"profileShift",level:"error",msg:a("Die Z\xE4hne laufen spitz zu: Profilverschiebung verringern oder Eingriffswinkel \xE4ndern.")}):i<.25*s&&n.push({key:"profileShift",level:"warn",msg:a("Sehr schmale Zahnk\xF6pfe ({w} mm).",{w:k(i)})}),r.rFlank>=r.ra)n.push({key:"teeth",level:"error",msg:a("Zu wenige Z\xE4hne: Der Unterschnitt nimmt die ganze Flanke weg. Mehr Z\xE4hne oder positive Profilverschiebung w\xE4hlen.")});else if(r.undercut){let o=1-t.teeth*Math.sin(r.alpha)**2/2;n.push({key:"teeth",level:"warn",msg:a("Unterschnitt: Der Zahnfu\xDF wird freigeschnitten und schw\xE4cher. Ab Profilverschiebung {x} entf\xE4llt er.",{x:k(o)})})}return n.push(...oe(e,t.kerf,r.rf,Math.max(1,s))),n},generate(e){let t=W(e),n=ue(t),s=[Ge(n)],r=ie(e,t.kerf);r&&s.push(r);let i=t.module,o=[[a("Teilkreis"),`\u2300 ${k(2*n.r)} mm`],[a("Kopfkreis"),`\u2300 ${k(2*n.ra)} mm`],[a("Fu\xDFkreis"),`\u2300 ${k(2*n.rf)} mm`],[a("Grundkreis"),`\u2300 ${k(2*n.rb)} mm`],[a("Zahndicke am Kopf"),`${k(2*n.tipAngle*n.ra)} mm`],[a("Achsabstand"),`${k(i,3)} \xD7 (z\u2081 + z\u2082) / 2${t.profileShift?` + (x\u2081 + x\u2082) \xD7 ${k(i,3)}`:""}`]];return{parts:[{key:"main",subs:s.map(ne),at:{x:0,y:0}}],info:o}},label(e){let t=W(e);return a("Zahnrad z={z} m={m}",{z:t.teeth,m:k(t.module,3)})}};C();var ut={callMs:{validate:1e4,generate:3e4,view:2e3,onChange:2e3,onEvent:1e4,resource:2e4,draw:3e4,onSurface:5e3,open:3e4,close:2e3,apply:3e4,migrate:2e3},askOptions:3,memoryBytes:512*1024*1024,codeBytes:8*1024*1024,outputBytes:32*1024*1024,parts:2e3,nodes:5e5,issues:200,info:40,text:400,range:1e5,items:2e4,points:1e6,tris:2e6,layers:4,sideFields:8,highlight:64,regionCells:4e6,stateBytes:1024*1024,imagePixels:16e6,imageSide:8e3,objects:5e3};D();function ce(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619)>>>0;return"t"+t.toString(16).padStart(8,"0")}he();var pe=new Map;function be(e,t){if(pe.has(e))return!0;try{pe.set(e,{data:t,mesh:de(t)})}catch{return!1}return je(e,t),!0}var Oe=e=>`mesh:${e}`,ge=null;function Ne(){return ge??(ge=new Promise((e,t)=>{if(typeof indexedDB>"u")return t(new Error("no indexedDB"));let n=indexedDB.open("laserwerk",1);n.onupgradeneeded=()=>n.result.createObjectStore("assets"),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})),ge}function je(e,t){Ne().then(n=>n.transaction("assets","readwrite").objectStore("assets").put(t,Oe(e))).catch(()=>{})}var q=e=>({width:e.width,height:e.height,data:E(e.data)});function ze(e){let t={};return e.selection&&(t.selection=e.selection),e.image&&(t.image={...q(e.image),name:String(e.image.name??"")}),e.camera&&(t.camera={...q(e.camera),bed:e.camera.bed,...e.camera.empty?{empty:q(e.camera.empty)}:{}}),t}var ye=e=>{if(typeof e=="string")return e;let t={code:ce(e.de)};return e.values&&(t.values=Object.fromEntries(Object.entries(e.values).map(([n,s])=>[n,typeof s=="number"?s:Pe(s)]))),t},Pe=e=>e.length===1?ye(e[0]):e.map(ye),p=e=>Pe(L(e)),V=globalThis;V.structuredClone??(V.structuredClone=e=>JSON.parse(JSON.stringify(e)));function xe(e){return!e||e instanceof Promise?null:{...e.patch?{patch:e.patch}:{},...e.message!==void 0?{message:p(e.message)}:{},...e.state!==void 0?{state:e.state}:{},...e.view!==void 0?{view:e.view}:{},...e.select?{select:e.select}:{}}}var ke=e=>e.type==="text"?{...e,text:p(e.text)}:e;function we(e){globalThis.plugin={...e.schema.some(t=>t.type==="data"&&t.resource)?{resource(t){if(t.kind==="model3d"&&!be(t.id,t.data))throw new Error("bad-model");return null}}:{},validate(t){return e.validate(t).map(n=>{let s=n.code?{code:n.code}:p(n.msg),r=typeof s=="object"&&!Array.isArray(s)?s:{code:"plugin-text",values:{text:s}};return{...n.key?{key:n.key}:{},level:n.level,...r}})},generate(t){let n=e.generate(t),s=e.poses?.(t,Number(t.thickness)||3)??null,r={};if(e.kind==="assembly")for(let i of n.parts)r[i.key]=p(e.label(t,i.key));return{parts:n.parts,info:n.info.map(([i,o])=>[p(i),p(o)]),label:p(e.label(t)),...n.distribute?{distribute:n.distribute}:{},...n.plan?{plan:{title:p(n.plan.title),lines:n.plan.lines,labels:n.plan.labels.map(i=>({...i,text:p(i.text)})),steps:n.plan.steps.map(p)}}:{},...e.kind==="assembly"?{labels:r}:{},...s?{poses:s}:{}}},...e.migrate?{migrate(t){return e.migrate(t.params,t.from)}}:{},...e.view?{view(t){let n=e.view(t);return{...n.autoText?{autoText:Object.fromEntries(Object.entries(n.autoText).map(([s,r])=>[s,p(r)]))}:{},...n.rows?{rows:Object.fromEntries(Object.entries(n.rows).map(([s,r])=>[s,r.map(p)]))}:{},...n.rowAuto?{rowAuto:Object.fromEntries(Object.entries(n.rowAuto).map(([s,r])=>[s,r.map(p)]))}:{}}}}:{},...e.onEvent?{onEvent(t){let n={action:t.action,inputs:ze(t.inputs??{})};return t.row!==void 0&&(n.row=t.row),t.surface&&(n.surface=t.surface),xe(e.onEvent(n,t.params))}}:{},...e.draw?{draw(t){let{params:n,...s}=t,r=e.draw(s,n);return r instanceof Promise?null:{...r,items:r.items.map(ke),...r.fields?{fields:r.fields.map(i=>({...i,label:p(i.label),...i.title?{title:p(i.title)}:{}}))}:{},...r.layers?{layers:r.layers.map(i=>i.items?{...i,items:i.items.map(ke)}:i)}:{}}}}:{},...e.onSurface?{onSurface(t){return xe(e.onSurface(t.event,t.surface,t.params))}}:{},...e.onChange?{onChange(t){let n=e.onChange(t.key,t.old,t.params);return!n||n instanceof Promise?null:{...n.patch?{patch:n.patch}:{},...n.ask?{ask:{question:p(n.ask.question),options:n.ask.options.map(s=>({label:p(s.label),patch:s.patch}))}}:{}}}}:{}}}we(le);})();
