(()=>{var me=Object.defineProperty;var he=(t,e,n)=>e in t?me(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var I=(t,e)=>()=>(t&&(e=t(t=0)),e);var _=(t,e,n)=>he(t,typeof e!="symbol"?e+"":e,n);function l(t,e){return L+t+(e?$+JSON.stringify(e):"")+q}function j(t){let e=[],n=0;for(;n<t.length;){let r=t.indexOf(L,n);if(r<0){e.push(t.slice(n));break}r>n&&e.push(t.slice(n,r));let s=t.indexOf(q,r),i=t.slice(r+1,s<0?t.length:s),o=i.indexOf($);if(o<0)e.push({de:i});else{let u=JSON.parse(i.slice(o+1)),a={};for(let[c,f]of Object.entries(u))a[c]=typeof f=="number"?f:j(String(f));e.push({de:i.slice(0,o),values:a})}n=s<0?t.length:s+1}return e}var L,$,q,D,S=I(()=>{"use strict";L="",$="",q="";D="en-US"});function A(t){let e=new Uint8Array(128);for(let i=0;i<64;i++)e[ye.charCodeAt(i)]=i;let n=t.replace(/=+$/,"").length,r=new Uint8ClampedArray(Math.floor(n*3/4)),s=0;for(let i=0;i<n;i+=4){let o=e[t.charCodeAt(i)]<<18|e[t.charCodeAt(i+1)]<<12|(i+2<n?e[t.charCodeAt(i+2)]:0)<<6|(i+3<n?e[t.charCodeAt(i+3)]:0);r[s++]=o>>16,s<r.length&&(r[s++]=o>>8&255),s<r.length&&(r[s++]=o&255)}return r}var ye,O=I(()=>{"use strict";ye="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"});function te(t){if(!t.startsWith("kzm1:"))return"format";let e=A(t.slice(5));if(e.length<8)return"damaged";let n=new DataView(e.buffer,e.byteOffset,e.byteLength),r=n.getUint32(0,!0),s=n.getUint32(4,!0);if(8+r*12+s*12!==e.length)return"damaged";let i=new Float32Array(r*3),o=new Uint32Array(s*3),u=8;for(let a=0;a<i.length;a++,u+=4)i[a]=n.getFloat32(u,!0);for(let a=0;a<o.length;a++,u+=4)o[a]=n.getUint32(u,!0);return o.some(a=>a>=r)?"damaged":{pos:i,tri:o}}var ne=I(()=>{"use strict";O()});function re(t){let e=te(t);if(e==="format")throw new E(l("Unbekanntes Modellformat."));if(e==="damaged")throw new E(l("Die Modelldaten sind besch\xE4digt."));return e}var E,se=I(()=>{"use strict";S();O();ne();E=class extends Error{}});S();function K(t,e,n,r,s){let i=1-s;return{x:i*i*i*t.x+3*i*i*s*e.x+3*i*s*s*n.x+s*s*s*r.x,y:i*i*i*t.y+3*i*i*s*e.y+3*i*s*s*n.y+s*s*s*r.y}}function pe(t,e,n,r){let s=Math.abs(n-e)||1,i=a=>{let c=s*1e-5,f=t(a-c),d=t(a+c);return{x:(d.x-f.x)/(2*c),y:(d.y-f.y)/(2*c)}},o=[],u=(a,c,f)=>{let d=t(a),p=t(c),y=(c-a)/3,x=i(a),w=i(c),T={x:d.x+x.x*y,y:d.y+x.y*y},g={x:p.x-w.x*y,y:p.y-w.y*y},b=0;for(let h=1;h<8;h++){let P=h/8,R=K(d,T,g,p,P),k=t(a+(c-a)*P);b=Math.max(b,Math.hypot(R.x-k.x,R.y-k.y))}if(b>r&&f<12){let h=(a+c)/2;u(a,h,f+1),u(h,c,f+1)}else o.push([T,g,p])};return u(e,n,0),o}var M=class{constructor(){_(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,s){if(!(Math.abs(r-n)<1e-12)){this.line(e(n));for(let[i,o,u]of pe(e,n,r,s))this.cubic(i,o,u)}}arc(e,n,r,s,i){let o=f=>({x:e+r*Math.cos(f),y:n+r*Math.sin(f)});this.line(o(s));let u=Math.max(1,Math.ceil(Math.abs(i-s)/(Math.PI/2)-1e-9)),a=(i-s)/u,c=4/3*Math.tan(a/4)*r;for(let f=0;f<u;f++){let d=s+f*a,p=d+a,y=o(d),x=o(p);this.cubic({x:y.x-c*Math.sin(d),y:y.y+c*Math.cos(d)},{x:x.x+c*Math.sin(p),y:x.y-c*Math.cos(p)},x)}}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 V(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)}:{}}))}}S();var W=(t,e=2)=>(Math.round(t*10**e)/10**e).toLocaleString(D,{maximumFractionDigits:e});function J(t="",e="",n="round",r=6){let s=o=>o+t,i=o=>e?`${o} (${e})`:o;return[{key:s("boreType"),type:"enum",label:i(l("Bohrung")),def:n,options:[["none",l("Keine")],["round",l("Rund")],["dflat",l("D-Profil (abgeflacht)")],["key",l("Mit Passfedernut")]]},{key:s("boreDia"),type:"length",label:i(l("Bohrungsdurchmesser")),min:.5,max:2e3,def:r,showIf:{ne:[s("boreType"),"none"]}},{key:s("boreFlat"),type:"length",label:i(l("Ma\xDF \xFCber Abflachung")),min:.1,max:2e3,def:Math.round(r*.917*10)/10,showIf:{eq:[s("boreType"),"dflat"]},title:l("Abstand von der Abflachung zur gegen\xFCberliegenden Seite der Bohrung")},{key:s("keyWidth"),type:"length",label:i(l("Nutbreite")),min:.1,max:200,def:2,showIf:{eq:[s("boreType"),"key"]}},{key:s("keyDepth"),type:"length",label:i(l("Nuttiefe")),min:.1,max:200,def:1,showIf:{eq:[s("boreType"),"key"]},title:l("Tiefe der Nut \xFCber den Bohrungsrand hinaus")}]}var F=(t,e)=>({type:String(t["boreType"+e]),dia:Number(t["boreDia"+e]),flat:Number(t["boreFlat"+e]),keyWidth:Number(t["keyWidth"+e]),keyDepth:Number(t["keyDepth"+e])});function ge(t,e=""){let n=F(t,e);return n.type==="none"?0:n.type==="key"?n.dia/2+n.keyDepth:n.dia/2}function Z(t,e,n=""){let r=F(t,n),s=e/2,i=r.dia/2-s;if(r.type==="none"||i<=0)return null;let o=new M;if(r.type==="dflat"){let u=r.flat-r.dia/2-s,a=Math.atan2(u,Math.sqrt(Math.max(0,i*i-u*u)));return o.arc(0,0,i,a,-Math.PI-a),o.close()}if(r.type==="key"){let u=(r.keyWidth-e)/2,a=r.dia/2+r.keyDepth-s,c=Math.atan2(Math.sqrt(Math.max(0,i*i-u*u)),u);return o.arc(0,0,i,c,c-2*Math.PI+(Math.PI-2*c)),o.line({x:-u,y:a}),o.line({x:u,y:a}),o.close()}return o.arc(0,0,i,0,2*Math.PI),o.close()}function v(t,e,n,r,s="",i=!0){let o=F(t,s),u=[];if(o.type==="none")return u;let a=n-ge(t,s);return a<=0?u.push({key:"boreDia"+s,level:"error",msg:i?l("Die Bohrung ist gr\xF6\xDFer als der Fu\xDFkreis."):l("Die Bohrung reicht \xFCber den Rand.")}):a<r&&u.push({key:"boreDia"+s,level:"warn",msg:i?l("Nur {w} mm Material zwischen Bohrung und Zahnfu\xDF.",{w:W(a)}):l("Nur {w} mm Material zwischen Bohrung und Rand.",{w:W(a)})}),o.type==="dflat"&&(o.flat<=o.dia/2||o.flat>=o.dia)&&u.push({key:"boreFlat"+s,level:"error",msg:l("Das Ma\xDF \xFCber der Abflachung muss zwischen Radius und Durchmesser der Bohrung liegen.")}),o.type==="key"&&o.keyWidth>=o.dia&&u.push({key:"keyWidth"+s,level:"error",msg:l("Die Nut ist breiter als die Bohrung.")}),o.dia/2-e/2<=0&&u.push({key:"boreDia"+s,level:"error",msg:l("Bohrung kleiner als die Schnittfuge.")}),u}var B={gt2_2:{pitch:2,pld:.254,depth:.764,width:1.494},gt2_3:{pitch:3,pld:.381,depth:1.169,width:2.31},gt2_5:{pitch:5,pld:.5715,depth:1.969,width:3.952},htd_3:{pitch:3,pld:.381,depth:1.289,width:2.27},htd_5:{pitch:5,pld:.5715,depth:2.199,width:3.781}};function Y(t){let e=B[t.profile];return t.teeth*e.pitch/Math.PI-2*e.pld}function X(t){let e=B[t.profile],n=t.kerf/2,r=Y(t)/2+n,s=(e.width+t.play)/2-n,i=e.depth,o=i>=s,u=o?s:(s*s+i*i)/(2*i),a=r-i+u,c=2*Math.PI/t.teeth,f=g=>{let b=s+g,h=Math.sqrt(Math.max(0,(r-g)**2-b*b)),P=o&&h>=a;if(!P){let k=r-g,z=u+g;h=(a*a+k*k-z*z)/(2*a),b=Math.sqrt(Math.max(0,k*k-h*h))}let R=2*Math.atan2(h,b)-Math.PI+c;return{tip:g,fx:b,fy:h,wall:P,land:R}},d=f(Math.min(.05*e.pitch,s/2)+n);if(d.land<0&&f(0).land>0){let g=0,b=d.tip;for(let h=0;h<40;h++){let P=(g+b)/2;f(P).land>.1*c?g=P:b=P}d=f(g)}let{tip:p,fx:y,fy:x,wall:w,land:T}=d;return{R:r,rw:s,rg:u,yc:a,tip:p,fx:y,fy:x,wall:w,land:T,depth:i,step:c}}function be(t){let e=X(t),n=new M,r=Math.atan2(e.fy,-e.fx),s=e.wall?0:Math.atan2(e.yc-e.fy,e.fx),i=e.wall?Math.PI:Math.atan2(e.fy-e.yc,-e.fx);i<0&&(i+=2*Math.PI);for(let o=0;o<t.teeth;o++){let u=-o*e.step,a=(f,d)=>({x:f*Math.cos(u)-d*Math.sin(u),y:f*Math.sin(u)+d*Math.cos(u)}),c=(f,d,p,y,x)=>{let w=a(f,d);n.arc(w.x,w.y,p,y+u,x+u)};c(-e.fx,e.fy,e.tip,r,s),e.wall&&n.line(a(-e.rw,e.yc)),c(0,e.yc,e.rg,i,3*Math.PI-i),e.wall&&n.line(a(e.rw,e.fy)),c(e.fx,e.fy,e.tip,Math.PI-s,Math.PI-r),c(0,0,e.R,Math.PI-r,r-e.step)}return n.close()}var N=t=>t,G=(t,e=2)=>(Math.round(t*10**e)/10**e).toLocaleString(D,{maximumFractionDigits:e}),H={gt2_2:"GT2 2 mm",gt2_3:"GT2 3 mm",gt2_5:"GT2 5 mm",htd_3:"HTD 3M",htd_5:"HTD 5M"},Q={id:"pulley",version:1,kind:"part",name:l("Riemenscheibe"),icon:"pulley",tile:{group:"mech",text:t=>({name:t("Riemenscheibe"),desc:t("Zahnriemenscheibe f\xFCr GT2- oder HTD-Riemen, mit Bordscheiben."),keys:t("Riemen Zahnriemen GT2 HTD Pulley|Suchw\xF6rter"),action:t("Riemenscheibe erstellen (GT2, HTD; Parameter bleiben erhalten)")})},schema:[{key:"profile",type:"enum",label:l("Riemenprofil"),def:"gt2_2",options:Object.entries(H)},{key:"teeth",type:"int",label:l("Z\xE4hnezahl"),min:8,max:400,def:20},{key:"play",type:"length",label:l("Spiel der Zahnl\xFCcke"),min:-.5,max:1,def:0,title:l("Macht jede Zahnl\xFCcke breiter, damit der Riemen leicht einl\xE4uft")},{key:"kerf",type:"length",label:l("Schnittfuge (Kerf)"),min:0,max:2,def:.15,title:l("Breite des Laserschnitts: Die Kontur wird um die H\xE4lfte nach au\xDFen versetzt, damit die Scheibe die Sollma\xDFe hat. Der Kerf des Layers wirkt beim Lasern zus\xE4tzlich.")},...J("","","round",5)],validate(t){let e=N(t),n=[],r=X(e);return r.rw<=.05?n.push({key:"play",level:"error",msg:l("Die Zahnl\xFCcke ist zu schmal.")}):r.land<=0?n.push({key:"teeth",level:"error",msg:l("Zu wenige Z\xE4hne f\xFCr dieses Profil: Die L\xFCcken \xFCberlappen sich.")}):r.land*r.R<.15&&n.push({key:"teeth",level:"warn",msg:l("Sehr schmale Z\xE4hne ({w} mm): Bei so wenigen Z\xE4hnen besser weniger Spiel oder ein kleineres Profil.",{w:G(r.land*r.R)})}),n.push(...v(t,e.kerf,r.R-r.depth,1)),n},generate(t){let e=N(t),n=[be(e)],r=Z(t,e.kerf);r&&n.push(r);let s=B[e.profile];return{parts:[{key:"main",subs:n.map(V),at:{x:0,y:0}}],info:[[l("Au\xDFendurchmesser"),`\u2300 ${G(Y(e))} mm`],[l("Wirkdurchmesser"),`\u2300 ${G(e.teeth*s.pitch/Math.PI)} mm`],[l("Riemenweg je Umdrehung"),`${G(e.teeth*s.pitch)} mm`]]}},label(t){let e=N(t);return l("Riemenscheibe {profile} z={z}",{profile:H[e.profile]??e.profile,z:e.teeth})}};O();var Ze={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};S();function ee(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")}se();var ie=new Map;function ae(t,e){if(ie.has(t))return!0;try{ie.set(t,{data:e,mesh:re(e)})}catch{return!1}return ke(t,e),!0}var Pe=t=>`mesh:${t}`,oe=null;function we(){return oe??(oe=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)})),oe}function ke(t,e){we().then(n=>n.transaction("assets","readwrite").objectStore("assets").put(e,Pe(t))).catch(()=>{})}var C=t=>({width:t.width,height:t.height,data:A(t.data)});function Me(t){let e={};return t.selection&&(e.selection=t.selection),t.image&&(e.image={...C(t.image),name:String(t.image.name??"")}),t.camera&&(e.camera={...C(t.camera),bed:t.camera.bed,...t.camera.empty?{empty:C(t.camera.empty)}:{}}),e}var ue=t=>{if(typeof t=="string")return t;let e={code:ee(t.de)};return t.values&&(e.values=Object.fromEntries(Object.entries(t.values).map(([n,r])=>[n,typeof r=="number"?r:fe(r)]))),e},fe=t=>t.length===1?ue(t[0]):t.map(ue),m=t=>fe(j(t)),U=globalThis;U.structuredClone??(U.structuredClone=t=>JSON.parse(JSON.stringify(t)));function le(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 ce=t=>t.type==="text"?{...t,text:m(t.text)}:t;function de(t){globalThis.plugin={...t.schema.some(e=>e.type==="data"&&e.resource)?{resource(e){if(e.kind==="model3d"&&!ae(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),s=typeof r=="object"&&!Array.isArray(r)?r:{code:"plugin-text",values:{text:r}};return{...n.key?{key:n.key}:{},level:n.level,...s}})},generate(e){let n=t.generate(e),r=t.poses?.(e,Number(e.thickness)||3)??null,s={};if(t.kind==="assembly")for(let i of n.parts)s[i.key]=m(t.label(e,i.key));return{parts:n.parts,info:n.info.map(([i,o])=>[m(i),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(i=>({...i,text:m(i.text)})),steps:n.plan.steps.map(m)}}:{},...t.kind==="assembly"?{labels:s}:{},...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,s])=>[r,m(s)]))}:{},...n.rows?{rows:Object.fromEntries(Object.entries(n.rows).map(([r,s])=>[r,s.map(m)]))}:{},...n.rowAuto?{rowAuto:Object.fromEntries(Object.entries(n.rowAuto).map(([r,s])=>[r,s.map(m)]))}:{}}}}:{},...t.onEvent?{onEvent(e){let n={action:e.action,inputs:Me(e.inputs??{})};return e.row!==void 0&&(n.row=e.row),e.surface&&(n.surface=e.surface),le(t.onEvent(n,e.params))}}:{},...t.draw?{draw(e){let{params:n,...r}=e,s=t.draw(r,n);return s instanceof Promise?null:{...s,items:s.items.map(ce),...s.fields?{fields:s.fields.map(i=>({...i,label:m(i.label),...i.title?{title:m(i.title)}:{}}))}:{},...s.layers?{layers:s.layers.map(i=>i.items?{...i,items:i.items.map(ce)}:i)}:{}}}}:{},...t.onSurface?{onSurface(e){return le(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}))}}:{}}}}:{}}}de(Q);})();
