(()=>{var se=Object.defineProperty;var ie=(t,e,n)=>e in t?se(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var w=(t,e)=>()=>(t&&(e=t(t=0)),e);var B=(t,e,n)=>ie(t,typeof e!="symbol"?e+"":e,n);function u(t,e){return z+t+(e?U+JSON.stringify(e):"")+Z}function G(t){let e=[],n=0;for(;n<t.length;){let r=t.indexOf(z,n);if(r<0){e.push(t.slice(n));break}r>n&&e.push(t.slice(n,r));let i=t.indexOf(Z,r),s=t.slice(r+1,i<0?t.length:i),o=s.indexOf(U);if(o<0)e.push({de:s});else{let f=JSON.parse(s.slice(o+1)),a={};for(let[c,l]of Object.entries(f))a[c]=typeof l=="number"?l:G(String(l));e.push({de:s.slice(0,o),values:a})}n=i<0?t.length:i+1}return e}var z,U,Z,L,M=w(()=>{"use strict";z="",U="",Z="";L="en-US"});function x(t){let e=new Uint8Array(128);for(let s=0;s<64;s++)e[le.charCodeAt(s)]=s;let n=t.replace(/=+$/,"").length,r=new Uint8ClampedArray(Math.floor(n*3/4)),i=0;for(let s=0;s<n;s+=4){let o=e[t.charCodeAt(s)]<<18|e[t.charCodeAt(s+1)]<<12|(s+2<n?e[t.charCodeAt(s+2)]:0)<<6|(s+3<n?e[t.charCodeAt(s+3)]:0);r[i++]=o>>16,i<r.length&&(r[i++]=o>>8&255),i<r.length&&(r[i++]=o&255)}return r}var le,R=w(()=>{"use strict";le="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"});function J(t){if(!t.startsWith("kzm1:"))return"format";let e=x(t.slice(5));if(e.length<8)return"damaged";let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0,!0),i=n.getUint32(4,!0);if(8+r*12+i*12!==e.length)return"damaged";let s=new Float32Array(r*3),o=new Uint32Array(i*3),f=8;for(let a=0;a<s.length;a++,f+=4)s[a]=n.getFloat32(f,!0);for(let a=0;a<o.length;a++,f+=4)o[a]=n.getUint32(f,!0);return o.some(a=>a>=r)?"damaged":{pos:s,tri:o}}var q=w(()=>{"use strict";R()});function v(t){let e=J(t);if(e==="format")throw new T(u("Unbekanntes Modellformat."));if(e==="damaged")throw new T(u("Die Modelldaten sind besch\xE4digt."));return e}var T,H=w(()=>{"use strict";M();R();q();T=class extends Error{}});M();function $(t,e,n,r,i){let s=1-i;return{x:s*s*s*t.x+3*s*s*i*e.x+3*s*i*i*n.x+i*i*i*r.x,y:s*s*s*t.y+3*s*s*i*e.y+3*s*i*i*n.y+i*i*i*r.y}}function oe(t,e,n,r){let i=Math.abs(n-e)||1,s=a=>{let c=i*1e-5,l=t(a-c),d=t(a+c);return{x:(d.x-l.x)/(2*c),y:(d.y-l.y)/(2*c)}},o=[],f=(a,c,l)=>{let d=t(a),h=t(c),g=(c-a)/3,p=s(a),k=s(c),P={x:d.x+p.x*g,y:d.y+p.y*g},j={x:h.x-k.x*g,y:h.y-k.y*g},I=0;for(let y=1;y<8;y++){let D=y/8,N=$(d,P,j,h,D),C=t(a+(c-a)*D);I=Math.max(I,Math.hypot(N.x-C.x,N.y-C.y))}if(I>r&&l<12){let y=(a+c)/2;f(a,y,l+1),f(y,c,l+1)}else o.push([P,j,h])};return f(e,n,0),o}var A=class{constructor(){B(this,"nodes",[])}get last(){return this.nodes[this.nodes.length-1]}same(e){let n=this.last;return!!n&&Math.hypot(n.x-e.x,n.y-e.y)<1e-7}line(e){this.same(e)||this.nodes.push({x:e.x,y:e.y})}cubic(e,n,r){if(!this.nodes.length)throw new Error("PathBuilder: kein Anfangspunkt");this.last.cout={x:e.x,y:e.y},this.nodes.push({x:r.x,y:r.y,cin:{x:n.x,y:n.y}})}curve(e,n,r,i){if(!(Math.abs(r-n)<1e-12)){this.line(e(n));for(let[s,o,f]of oe(e,n,r,i))this.cubic(s,o,f)}}arc(e,n,r,i,s){let o=l=>({x:e+r*Math.cos(l),y:n+r*Math.sin(l)});this.line(o(i));let f=Math.max(1,Math.ceil(Math.abs(s-i)/(Math.PI/2)-1e-9)),a=(s-i)/f,c=4/3*Math.tan(a/4)*r;for(let l=0;l<f;l++){let d=i+l*a,h=d+a,g=o(d),p=o(h);this.cubic({x:g.x-c*Math.sin(d),y:g.y+c*Math.cos(d)},{x:p.x+c*Math.sin(h),y:p.y-c*Math.cos(h)},p)}}close(){let e=this.nodes;if(e.length>1){let n=e[0],r=e[e.length-1];Math.hypot(n.x-r.x,n.y-r.y)<1e-6&&(r.cin&&(n.cin=r.cin),e.pop())}return{nodes:e,closed:!0}}};function _(t){let e=n=>({x:n.x,y:-n.y});return{closed:t.closed,nodes:t.nodes.map(n=>({...e(n),...n.cin?{cin:e(n.cin)}:{},...n.cout?{cout:e(n.cout)}:{}}))}}var ae=t=>t*Math.PI/180;function S(t){let e=t.module,n=ae(t.pressureAngle),r=Math.PI*e,i=t.kerf/2,s=Math.tan(n),o=Math.cos(n),f=Math.sin(n),a=r/2-t.backlash/2+2*i/o,c=e+i,l=-(1+t.clearance)*e+i,d=-(1+t.clearance)*e-t.back-i,g=-a/2+l*s+r/2,p=Math.max(0,Math.min(t.rootFillet*e-i,g/(1/o-s))),k=a-2*c*s,P=r-a-2*-l*s;return{m:e,alpha:n,pitch:r,d:i,ta:s,ca:o,sa:f,s:a,yTip:c,yRoot:l,yBack:d,rho:p,tipWidth:k,rootGap:P,length:t.teeth*r+2*i}}function ue(t){let e=S(t),n=new A,r=t.teeth*e.pitch;n.line({x:-e.d,y:e.yBack}),n.line({x:-e.d,y:e.yRoot});let i=e.yRoot+e.rho;for(let s=0;s<t.teeth;s++){let o=e.pitch/2+s*e.pitch,f=d=>o-e.s/2+d*e.ta,a=d=>o+e.s/2-d*e.ta,c=f(i)-e.rho/e.ca;e.rho>0?n.arc(c,i,e.rho,-Math.PI/2,-e.alpha):n.line({x:f(e.yRoot),y:e.yRoot}),n.line({x:f(e.yTip),y:e.yTip}),n.line({x:a(e.yTip),y:e.yTip});let l=a(i)+e.rho/e.ca;e.rho>0?n.arc(l,i,e.rho,Math.PI+e.alpha,3*Math.PI/2):n.line({x:a(e.yRoot),y:e.yRoot})}return n.line({x:r+e.d,y:e.yRoot}),n.line({x:r+e.d,y:e.yBack}),n.close()}var O=t=>t,b=(t,e=2)=>(Math.round(t*10**e)/10**e).toLocaleString(L,{maximumFractionDigits:e});function ce(t){let e=S(t);return{x:-(t.teeth*e.pitch)/2,y:-(e.yTip+e.yBack)/2}}var K={id:"rack",version:1,kind:"part",name:u("Zahnstange"),icon:"rack",tile:{group:"mech",text:t=>({name:t("Zahnstange"),desc:t("Gerade Zahnstange, die zum Zahnrad mit gleichem Modul passt."),keys:t("Zahnstange Linearantrieb Zahnrad|Suchw\xF6rter"),action:t("Zahnstange erstellen (passend zum Zahnrad, Parameter bleiben erhalten)")})},schema:[{key:"teeth",type:"int",label:u("Z\xE4hnezahl"),min:1,max:1e3,def:20},{key:"module",type:"length",label:u("Modul"),min:.3,max:20,def:2,title:u("Muss zum Modul des Zahnrads passen")},{key:"pressureAngle",type:"angle",label:u("Eingriffswinkel"),min:10,max:35,def:20,title:u("Muss zum Eingriffswinkel des Zahnrads passen")},{key:"backlash",type:"length",label:u("Flankenspiel"),min:0,max:3,def:.1,title:u("Spiel der Paarung auf der Teilungslinie; die Zahnstange wird um die H\xE4lfte d\xFCnner, das Rad um die andere H\xE4lfte")},{key:"kerf",type:"length",label:u("Schnittfuge (Kerf)"),min:0,max:2,def:.15,title:u("Breite des Laserschnitts: Die Kontur wird um die H\xE4lfte nach au\xDFen versetzt, damit die Zahnstange die Sollma\xDFe hat. Der Kerf des Layers wirkt beim Lasern zus\xE4tzlich.")},{key:"back",type:"length",label:u("R\xFCckenh\xF6he"),min:.5,max:500,def:6,title:u("Material unter dem Zahnfu\xDF")},{key:"rootFillet",type:"number",label:u("Fu\xDFrundung (\xD7 Modul)"),min:0,max:.45,def:.38,advanced:!0,title:u("Radius der Rundung im Zahnfu\xDF, Norm: 0,38")},{key:"clearance",type:"number",label:u("Kopfspiel (\xD7 Modul)"),min:.1,max:.5,def:.25,advanced:!0,title:u("Abstand zwischen Zahnkopf des Rads und Zahnfu\xDF der Stange, Norm: 0,25")}],validate(t){let e=O(t),n=[];e.backlash/2>=Math.PI*e.module/4&&n.push({key:"backlash",level:"error",msg:u("Flankenspiel zu gro\xDF f\xFCr dieses Modul.")});let r=S(e);return r.tipWidth<=.01*e.module&&n.push({key:"pressureAngle",level:"error",msg:u("Die Z\xE4hne laufen spitz zu: Eingriffswinkel verringern.")}),r.rootGap<=0&&n.push({key:"kerf",level:"error",msg:u("Die Schnittfuge ist breiter als die Zahnl\xFCcke.")}),n},generate(t){let e=O(t),n=S(e),r=ce(e),i=ue(e);i.nodes=i.nodes.map(o=>({x:o.x+r.x,y:o.y+r.y,...o.cin?{cin:{x:o.cin.x+r.x,y:o.cin.y+r.y}}:{},...o.cout?{cout:{x:o.cout.x+r.x,y:o.cout.y+r.y}}:{}}));let s=n.yTip-n.yBack;return{parts:[{key:"main",subs:[_(i)],at:{x:0,y:0}}],info:[[u("L\xE4nge"),`${b(n.length)} mm`],[u("H\xF6he"),`${b(s)} mm`],[u("Teilung"),`${b(n.pitch,3)} mm`],[u("Teilungslinie \xFCber Unterkante"),`${b(-n.yBack-n.d)} mm`],[u("Achse des Zahnrads \xFCber Unterkante"),u("{h} mm + halber Teilkreis",{h:b(-n.yBack-n.d)})]]}},label(t){let e=O(t);return u("Zahnstange z={z} m={m}",{z:e.teeth,m:b(e.module,3)})}};R();var Ce={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};M();function V(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619)>>>0;return"t"+e.toString(16).padStart(8,"0")}H();var W=new Map;function X(t,e){if(W.has(t))return!0;try{W.set(t,{data:e,mesh:v(e)})}catch{return!1}return he(t,e),!0}var de=t=>`mesh:${t}`,Y=null;function me(){return Y??(Y=new Promise((t,e)=>{if(typeof indexedDB>"u")return e(new Error("no indexedDB"));let n=indexedDB.open("laserwerk",1);n.onupgradeneeded=()=>n.result.createObjectStore("assets"),n.onsuccess=()=>t(n.result),n.onerror=()=>e(n.error)})),Y}function he(t,e){me().then(n=>n.transaction("assets","readwrite").objectStore("assets").put(e,de(t))).catch(()=>{})}var E=t=>({width:t.width,height:t.height,data:x(t.data)});function ge(t){let e={};return t.selection&&(e.selection=t.selection),t.image&&(e.image={...E(t.image),name:String(t.image.name??"")}),t.camera&&(e.camera={...E(t.camera),bed:t.camera.bed,...t.camera.empty?{empty:E(t.camera.empty)}:{}}),e}var Q=t=>{if(typeof t=="string")return t;let e={code:V(t.de)};return t.values&&(e.values=Object.fromEntries(Object.entries(t.values).map(([n,r])=>[n,typeof r=="number"?r:ne(r)]))),e},ne=t=>t.length===1?Q(t[0]):t.map(Q),m=t=>ne(G(t)),F=globalThis;F.structuredClone??(F.structuredClone=t=>JSON.parse(JSON.stringify(t)));function ee(t){return!t||t instanceof Promise?null:{...t.patch?{patch:t.patch}:{},...t.message!==void 0?{message:m(t.message)}:{},...t.state!==void 0?{state:t.state}:{},...t.view!==void 0?{view:t.view}:{},...t.select?{select:t.select}:{}}}var te=t=>t.type==="text"?{...t,text:m(t.text)}:t;function re(t){globalThis.plugin={...t.schema.some(e=>e.type==="data"&&e.resource)?{resource(e){if(e.kind==="model3d"&&!X(e.id,e.data))throw new Error("bad-model");return null}}:{},validate(e){return t.validate(e).map(n=>{let r=n.code?{code:n.code}:m(n.msg),i=typeof r=="object"&&!Array.isArray(r)?r:{code:"plugin-text",values:{text:r}};return{...n.key?{key:n.key}:{},level:n.level,...i}})},generate(e){let n=t.generate(e),r=t.poses?.(e,Number(e.thickness)||3)??null,i={};if(t.kind==="assembly")for(let s of n.parts)i[s.key]=m(t.label(e,s.key));return{parts:n.parts,info:n.info.map(([s,o])=>[m(s),m(o)]),label:m(t.label(e)),...n.distribute?{distribute:n.distribute}:{},...n.plan?{plan:{title:m(n.plan.title),lines:n.plan.lines,labels:n.plan.labels.map(s=>({...s,text:m(s.text)})),steps:n.plan.steps.map(m)}}:{},...t.kind==="assembly"?{labels:i}:{},...r?{poses:r}:{}}},...t.migrate?{migrate(e){return t.migrate(e.params,e.from)}}:{},...t.view?{view(e){let n=t.view(e);return{...n.autoText?{autoText:Object.fromEntries(Object.entries(n.autoText).map(([r,i])=>[r,m(i)]))}:{},...n.rows?{rows:Object.fromEntries(Object.entries(n.rows).map(([r,i])=>[r,i.map(m)]))}:{},...n.rowAuto?{rowAuto:Object.fromEntries(Object.entries(n.rowAuto).map(([r,i])=>[r,i.map(m)]))}:{}}}}:{},...t.onEvent?{onEvent(e){let n={action:e.action,inputs:ge(e.inputs??{})};return e.row!==void 0&&(n.row=e.row),e.surface&&(n.surface=e.surface),ee(t.onEvent(n,e.params))}}:{},...t.draw?{draw(e){let{params:n,...r}=e,i=t.draw(r,n);return i instanceof Promise?null:{...i,items:i.items.map(te),...i.fields?{fields:i.fields.map(s=>({...s,label:m(s.label),...s.title?{title:m(s.title)}:{}}))}:{},...i.layers?{layers:i.layers.map(s=>s.items?{...s,items:s.items.map(te)}:s)}:{}}}}:{},...t.onSurface?{onSurface(e){return ee(t.onSurface(e.event,e.surface,e.params))}}:{},...t.onChange?{onChange(e){let n=t.onChange(e.key,e.old,e.params);return!n||n instanceof Promise?null:{...n.patch?{patch:n.patch}:{},...n.ask?{ask:{question:m(n.ask.question),options:n.ask.options.map(r=>({label:m(r.label),patch:r.patch}))}}:{}}}}:{}}}re(K);})();
