3d-spinner 0.9.1 → 0.9.2
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/README.md +30 -7
- package/dist/cjs/animations/object-motion.cjs +1368 -0
- package/dist/cjs/animations/spin.cjs +1299 -0
- package/dist/cjs/engines/little-3d-engine/little-3d-engine.cjs +1324 -0
- package/dist/cjs/engines/little-3d-engine/loaders/obj.cjs +58 -0
- package/dist/cjs/engines/little-tween-engine/little-tween-engine.cjs +279 -0
- package/dist/cjs/index.cjs +120 -0
- package/dist/cjs/motion/motion.cjs +140 -0
- package/dist/cjs/motion/transitions.cjs +80 -0
- package/dist/engines/little-3d-engine/loaders/obj.d.ts +2 -2
- package/dist/engines/little-3d-engine/loaders/obj.js +2 -2
- package/dist/umd/spinner.global.js +2408 -0
- package/dist/umd/spinner.global.min.js +58 -0
- package/package.json +26 -11
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
var Spinner3D=(()=>{var me=Object.defineProperty;var Ft=Object.getOwnPropertyDescriptor;var Rt=Object.getOwnPropertyNames;var jt=Object.prototype.hasOwnProperty;var P=(n,e,t)=>()=>{if(t)throw t[0];try{return n&&(e=n(n=0)),e}catch(r){throw t=[r],r}};var Q=(n,e)=>{for(var t in e)me(n,t,{get:e[t],enumerable:!0})},Bt=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Rt(e))!jt.call(n,i)&&i!==t&&me(n,i,{get:()=>e[i],enumerable:!(r=Ft(e,i))||r.enumerable});return n};var kt=n=>Bt(me({},"__esModule",{value:!0}),n);function nt(n,e,t){return{x:n,y:e,z:t}}function O(n,e){return{x:n.x-e.x,y:n.y-e.y,z:n.z-e.z}}function z(n,e){return{x:n.y*e.z-n.z*e.y,y:n.z*e.x-n.x*e.z,z:n.x*e.y-n.y*e.x}}function L(n,e){return n.x*e.x+n.y*e.y+n.z*e.z}function A(n,e){return{x:n.x*e,y:n.y*e,z:n.z*e}}function M(n){let e=Math.hypot(n.x,n.y,n.z);return e===0?{x:0,y:0,z:0}:{x:n.x/e,y:n.y/e,z:n.z/e}}function T(n,e){let t=new Array(16);for(let r=0;r<4;r++)for(let i=0;i<4;i++){let o=0;for(let s=0;s<4;s++)o+=n[s*4+i]*e[r*4+s];t[r*4+i]=o}return t}function N(n,e,t){return[1,0,0,0,0,1,0,0,0,0,1,0,n,e,t,1]}function rt(n){return[n,0,0,0,0,n,0,0,0,0,n,0,0,0,0,1]}function X(n){let e=Math.cos(n),t=Math.sin(n);return[1,0,0,0,0,e,t,0,0,-t,e,0,0,0,0,1]}function Z(n){let e=Math.cos(n),t=Math.sin(n);return[e,0,-t,0,0,1,0,0,t,0,e,0,0,0,0,1]}function K(n){let e=Math.cos(n),t=Math.sin(n);return[e,t,0,0,-t,e,0,0,0,0,1,0,0,0,0,1]}function it(n,e,t,r){let i=1/Math.tan(n/2),o=1/(t-r);return[i/e,0,0,0,0,i,0,0,0,0,(r+t)*o,-1,0,0,2*r*t*o,0]}function ot(n,e){let t=n[0]*e.x+n[4]*e.y+n[8]*e.z+n[12],r=n[1]*e.x+n[5]*e.y+n[9]*e.z+n[13],i=n[2]*e.x+n[6]*e.y+n[10]*e.z+n[14],o=n[3]*e.x+n[7]*e.y+n[11]*e.z+n[15]||1;return{x:t/o,y:r/o,z:i/o}}function $(n,e){return{x:n[0]*e.x+n[4]*e.y+n[8]*e.z+n[12],y:n[1]*e.x+n[5]*e.y+n[9]*e.z+n[13],z:n[2]*e.x+n[6]*e.y+n[10]*e.z+n[14]}}var I=P(()=>{"use strict"});function V(n){let e=n.trim().replace("#",""),t=e.length===3?e.split("").map(i=>i+i).join(""):e,r=parseInt(t,16);return[r>>16&255,r>>8&255,r&255]}function j(n){let e=0;for(let s of n.faces)e+=Math.max(0,s.indices.length-2);let t=new Float32Array(e*9),r=new Float32Array(e*9),i=new Float32Array(e*9),o=0;for(let s of n.faces){let a=n.vertices[s.indices[0]],c=n.vertices[s.indices[1]],m=n.vertices[s.indices[2]],u=M(z(O(c,a),O(m,a))),[h,l,p]=V(s.color),d=h/255,x=l/255,b=p/255;for(let y=1;y<s.indices.length-1;y++){let g=[s.indices[0],s.indices[y],s.indices[y+1]];for(let v of g){let E=n.vertices[v];t[o]=E.x,t[o+1]=E.y,t[o+2]=E.z,r[o]=u.x,r[o+1]=u.y,r[o+2]=u.z,i[o]=d,i[o+1]=x,i[o+2]=b,o+=3}}}return{positions:t,normals:r,colors:i,count:t.length/3}}function de(n,e){return{x:(n.x+e.x)/2,y:(n.y+e.y)/2,z:(n.z+e.z)/2}}function J(n,e,t,r,i){let o=t/2,s=e.map(u=>u.map(h=>M(n[h]))),a=Math.max(0,Math.floor(r)-1);for(let u=0;u<a;u++){let h=[];for(let[l,p,d]of s){let x=M(de(l,p)),b=M(de(p,d)),y=M(de(d,l));h.push([l,x,y],[p,b,x],[d,y,b],[x,b,y])}s=h}let c=[],m=s.map((u,h)=>{let l=c.length;return c.push(A(u[0],o),A(u[1],o),A(u[2],o)),{indices:[l,l+1,l+2],color:i[h%i.length]}});return{vertices:c,faces:m}}var w=P(()=>{"use strict";I()});function Gt(n){return Math.min(1,Math.max(0,n))}function fe(n,e,t){let r=Math.max(0,L(n,t.toLight)),i=Gt(t.ambient+t.intensity*r),[o,s,a]=V(e);return`rgb(${Math.round(o*i)}, ${Math.round(s*i)}, ${Math.round(a*i)})`}var Nt,B,ee=P(()=>{"use strict";I();w();Nt={direction:{x:-.4,y:-.7,z:-.6},intensity:.85,ambient:.25};B=class{constructor(e){this.options={...Nt,...e},this.params={toLight:M(A(this.options.direction,-1)),intensity:this.options.intensity,ambient:this.options.ambient}}shade(e,t){return fe(e,t,this.params)}}});var at={};Q(at,{WebGLRenderer:()=>be});function st(n,e,t){let r=n.createShader(e);if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS))throw new Error(`3d-spinner: shader compile failed: ${n.getShaderInfoLog(r)}`);return r}function qt(n){let e=n.createProgram();if(n.attachShader(e,st(n,n.VERTEX_SHADER,Ht)),n.attachShader(e,st(n,n.FRAGMENT_SHADER,Wt)),n.linkProgram(e),!n.getProgramParameter(e,n.LINK_STATUS))throw new Error(`3d-spinner: program link failed: ${n.getProgramInfoLog(e)}`);return e}var Ht,Wt,be,ct=P(()=>{"use strict";w();D();Ht=`#version 300 es
|
|
2
|
+
in vec3 aPos;
|
|
3
|
+
in vec3 aNormal;
|
|
4
|
+
in vec3 aColor;
|
|
5
|
+
uniform mat4 uViewProj;
|
|
6
|
+
uniform mat4 uModel;
|
|
7
|
+
out vec3 vNormal;
|
|
8
|
+
out vec3 vColor;
|
|
9
|
+
void main() {
|
|
10
|
+
vNormal = mat3(uModel) * aNormal;
|
|
11
|
+
vColor = aColor;
|
|
12
|
+
gl_Position = uViewProj * uModel * vec4(aPos, 1.0);
|
|
13
|
+
}`,Wt=`#version 300 es
|
|
14
|
+
precision mediump float;
|
|
15
|
+
in vec3 vNormal;
|
|
16
|
+
in vec3 vColor;
|
|
17
|
+
uniform vec3 uToLight;
|
|
18
|
+
uniform float uIntensity;
|
|
19
|
+
uniform float uAmbient;
|
|
20
|
+
uniform float uOpacity;
|
|
21
|
+
out vec4 fragColor;
|
|
22
|
+
void main() {
|
|
23
|
+
float lambert = max(dot(normalize(vNormal), normalize(uToLight)), 0.0);
|
|
24
|
+
float brightness = clamp(uAmbient + uIntensity * lambert, 0.0, 1.0);
|
|
25
|
+
fragColor = vec4(vColor * brightness, uOpacity);
|
|
26
|
+
}`;be=class{constructor(e={}){this.cache=new Map;if(e.background){let[t,r,i]=V(e.background);this.clearColor=[t/255,r/255,i/255,1]}else this.clearColor=[0,0,0,0]}init(e){let t=e.getContext("webgl2");if(!t)throw new Error("3d-spinner: WebGL2 is not supported in this browser.");this.gl=t,this.program=qt(t),this.locations={aPos:t.getAttribLocation(this.program,"aPos"),aNormal:t.getAttribLocation(this.program,"aNormal"),aColor:t.getAttribLocation(this.program,"aColor"),uViewProj:t.getUniformLocation(this.program,"uViewProj"),uModel:t.getUniformLocation(this.program,"uModel"),uToLight:t.getUniformLocation(this.program,"uToLight"),uIntensity:t.getUniformLocation(this.program,"uIntensity"),uAmbient:t.getUniformLocation(this.program,"uAmbient"),uOpacity:t.getUniformLocation(this.program,"uOpacity")},t.enable(t.DEPTH_TEST),t.enable(t.CULL_FACE),t.cullFace(t.BACK),t.frontFace(t.CCW)}resize(){let e=this.gl;if(!e)return;let t=e.canvas;e.viewport(0,0,t.width,t.height)}buffers(e){let t=this.cache.get(e);if(t)return t;let r=this.gl,i=this.locations,o=j(e),s=r.createVertexArray();r.bindVertexArray(s);let a=(m,u)=>{if(m<0)return;let h=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,h),r.bufferData(r.ARRAY_BUFFER,u,r.STATIC_DRAW),r.enableVertexAttribArray(m),r.vertexAttribPointer(m,3,r.FLOAT,!1,0,0)};a(i.aPos,o.positions),a(i.aNormal,o.normals),a(i.aColor,o.colors),r.bindVertexArray(null);let c={vao:s,count:o.count};return this.cache.set(e,c),c}render(e){let t=this.gl,r=this.locations;if(!(!t||!this.program||!r)){t.clearColor(...this.clearColor),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT),t.useProgram(this.program),t.uniformMatrix4fv(r.uViewProj,!1,new Float32Array(e.viewProjection)),t.uniform3f(r.uToLight,e.light.toLight.x,e.light.toLight.y,e.light.toLight.z),t.uniform1f(r.uIntensity,e.light.intensity),t.uniform1f(r.uAmbient,e.light.ambient),t.disable(t.BLEND),t.depthMask(!0),t.cullFace(t.BACK);for(let i of e.items){if(i.transparency)continue;let o=this.buffers(i.mesh);t.uniformMatrix4fv(r.uModel,!1,new Float32Array(i.model)),t.uniform1f(r.uOpacity,1),t.bindVertexArray(o.vao),t.drawArrays(t.TRIANGLES,0,o.count)}t.enable(t.BLEND),t.blendFunc(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA),t.depthMask(!1);for(let i of e.items){let o=i.transparency;if(!o)continue;let s=this.buffers(i.mesh);if(t.uniformMatrix4fv(r.uModel,!1,new Float32Array(i.model)),t.bindVertexArray(s.vao),o.mode==="two-sided"){let a=k(o);t.cullFace(t.FRONT),t.uniform1f(r.uOpacity,a.back),t.drawArrays(t.TRIANGLES,0,s.count),t.cullFace(t.BACK),t.uniform1f(r.uOpacity,a.front),t.drawArrays(t.TRIANGLES,0,s.count)}else t.cullFace(t.BACK),t.uniform1f(r.uOpacity,C(o.opacity,.35)),t.drawArrays(t.TRIANGLES,0,s.count)}t.depthMask(!0),t.disable(t.BLEND),t.cullFace(t.BACK),t.bindVertexArray(null)}}destroy(){let e=this.gl;if(e){for(let t of this.cache.values())e.deleteVertexArray(t.vao);this.program&&e.deleteProgram(this.program)}this.cache.clear(),this.gl=void 0,this.program=void 0,this.locations=void 0}}});var ut={};Q(ut,{WebGPURenderer:()=>ye});var Yt,Qt,ne,ye,pt=P(()=>{"use strict";w();I();D();Yt=`
|
|
27
|
+
struct Uniforms {
|
|
28
|
+
viewProj: mat4x4<f32>,
|
|
29
|
+
model: mat4x4<f32>,
|
|
30
|
+
toLight: vec4<f32>,
|
|
31
|
+
params: vec4<f32>,
|
|
32
|
+
};
|
|
33
|
+
@group(0) @binding(0) var<uniform> u: Uniforms;
|
|
34
|
+
|
|
35
|
+
struct VSOut {
|
|
36
|
+
@builtin(position) position: vec4<f32>,
|
|
37
|
+
@location(0) normal: vec3<f32>,
|
|
38
|
+
@location(1) color: vec3<f32>,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
@vertex
|
|
42
|
+
fn vs(@location(0) pos: vec3<f32>, @location(1) normal: vec3<f32>, @location(2) color: vec3<f32>) -> VSOut {
|
|
43
|
+
var out: VSOut;
|
|
44
|
+
let m = mat3x3<f32>(u.model[0].xyz, u.model[1].xyz, u.model[2].xyz);
|
|
45
|
+
out.normal = m * normal;
|
|
46
|
+
out.color = color;
|
|
47
|
+
out.position = u.viewProj * u.model * vec4<f32>(pos, 1.0);
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@fragment
|
|
52
|
+
fn fs(in: VSOut) -> @location(0) vec4<f32> {
|
|
53
|
+
let lambert = max(dot(normalize(in.normal), normalize(u.toLight.xyz)), 0.0);
|
|
54
|
+
let brightness = clamp(u.params.y + u.params.x * lambert, 0.0, 1.0);
|
|
55
|
+
return vec4<f32>(in.color * brightness, u.params.z);
|
|
56
|
+
}
|
|
57
|
+
`,Qt=[1,0,0,0,0,1,0,0,0,0,.5,0,0,0,.5,1],ne=256,ye=class{constructor(e={}){this.uniformCapacity=0;this.depthSize="";this.destroyed=!1;this.cache=new Map;if(e.background){let[t,r,i]=V(e.background);this.clearValue={r:t/255,g:r/255,b:i/255,a:1},this.alphaMode="opaque"}else this.clearValue={r:0,g:0,b:0,a:0},this.alphaMode="premultiplied"}async init(e){let t=navigator.gpu;if(!t)throw new Error("3d-spinner: WebGPU is not supported in this browser.");let r=await t.requestAdapter();if(!r)throw new Error("3d-spinner: no WebGPU adapter is available.");let i=await r.requestDevice();if(this.destroyed){i.destroy?.();return}let o=e.getContext("webgpu");if(!o)throw new Error("3d-spinner: could not get a WebGPU canvas context.");let s=t.getPreferredCanvasFormat();o.configure({device:i,format:s,alphaMode:this.alphaMode});let a=i.createShaderModule({code:Yt}),c=globalThis.GPUShaderStage,m=i.createBindGroupLayout({entries:[{binding:0,visibility:c.VERTEX|c.FRAGMENT,buffer:{type:"uniform",hasDynamicOffset:!0,minBindingSize:160}}]}),u=d=>({arrayStride:12,attributes:[{shaderLocation:d,offset:0,format:"float32x3"}]}),h=i.createPipelineLayout({bindGroupLayouts:[m]}),l={color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}},p=(d,x)=>i.createRenderPipeline({layout:h,vertex:{module:a,entryPoint:"vs",buffers:[u(0),u(1),u(2)]},fragment:{module:a,entryPoint:"fs",targets:[{format:s,...x?{blend:l}:{}}]},primitive:{topology:"triangle-list",cullMode:d,frontFace:"ccw"},depthStencil:{format:"depth24plus",depthWriteEnabled:!x,depthCompare:"less"}});this.pipeline=p("back",!1),this.transparentBackPipeline=p("front",!0),this.transparentFrontPipeline=p("back",!0),this.canvas=e,this.device=i,this.context=o}resize(){this.ensureDepth()}ensureDepth(){let e=this.canvas;if(!this.device||!e)return;let t=Math.max(1,e.width),r=Math.max(1,e.height),i=`${t}x${r}`;i===this.depthSize&&this.depthTexture||(this.depthTexture?.destroy?.(),this.depthTexture=this.device.createTexture({size:{width:t,height:r},format:"depth24plus",usage:globalThis.GPUTextureUsage.RENDER_ATTACHMENT}),this.depthSize=i)}buffers(e){let t=this.cache.get(e);if(t)return t;let r=j(e),i=globalThis.GPUBufferUsage.VERTEX|globalThis.GPUBufferUsage.COPY_DST,o=a=>{let c=this.device.createBuffer({size:a.byteLength,usage:i});return this.device.queue.writeBuffer(c,0,a),c},s={position:o(r.positions),normal:o(r.normals),color:o(r.colors),count:r.count};return this.cache.set(e,s),s}ensureUniformCapacity(e){e<=this.uniformCapacity&&this.uniformBuffer||(this.uniformBuffer?.destroy?.(),this.uniformBuffer=this.device.createBuffer({size:Math.max(1,e)*ne,usage:globalThis.GPUBufferUsage.UNIFORM|globalThis.GPUBufferUsage.COPY_DST}),this.uniformCapacity=e)}render(e){if(this.destroyed||!this.device||!this.context||!this.pipeline||e.width===0||e.height===0||e.items.length===0)return;this.ensureDepth();let t=[];for(let c of e.items)c.transparency||t.push({item:c,opacity:1,pipeline:this.pipeline});for(let c of e.items){let m=c.transparency;if(m)if(m.mode==="two-sided"){let u=k(m);t.push({item:c,opacity:u.back,pipeline:this.transparentBackPipeline}),t.push({item:c,opacity:u.front,pipeline:this.transparentFrontPipeline})}else t.push({item:c,opacity:C(m.opacity,.35),pipeline:this.transparentFrontPipeline})}this.ensureUniformCapacity(t.length);let r=T(Qt,e.viewProjection),i=this.pipeline.getBindGroupLayout(0),o=this.device.createBindGroup({layout:i,entries:[{binding:0,resource:{buffer:this.uniformBuffer,offset:0,size:160}}]});t.forEach((c,m)=>{let u=new Float32Array(ne/4);u.set(r,0),u.set(c.item.model,16),u.set([e.light.toLight.x,e.light.toLight.y,e.light.toLight.z,0],32),u.set([e.light.intensity,e.light.ambient,c.opacity,0],36),this.device.queue.writeBuffer(this.uniformBuffer,m*ne,u)});let s=this.device.createCommandEncoder(),a=s.beginRenderPass({colorAttachments:[{view:this.context.getCurrentTexture().createView(),clearValue:this.clearValue,loadOp:"clear",storeOp:"store"}],depthStencilAttachment:{view:this.depthTexture.createView(),depthClearValue:1,depthLoadOp:"clear",depthStoreOp:"store"}});t.forEach((c,m)=>{let u=this.buffers(c.item.mesh);a.setPipeline(c.pipeline),a.setBindGroup(0,o,[m*ne]),a.setVertexBuffer(0,u.position),a.setVertexBuffer(1,u.normal),a.setVertexBuffer(2,u.color),a.draw(u.count)}),a.end(),this.device.queue.submit([s.finish()])}destroy(){this.destroyed=!0;for(let e of this.cache.values())e.position.destroy?.(),e.normal.destroy?.(),e.color.destroy?.();this.cache.clear(),this.uniformBuffer?.destroy?.(),this.depthTexture?.destroy?.(),this.device?.destroy?.(),this.device=void 0,this.context=void 0,this.pipeline=void 0,this.transparentBackPipeline=void 0,this.transparentFrontPipeline=void 0,this.uniformBuffer=void 0,this.depthTexture=void 0,this.canvas=void 0}}});var ht={};Q(ht,{Canvas2DRenderer:()=>xe});var xe,lt=P(()=>{"use strict";ee();I();D();xe=class{constructor(e={}){this.options=e;this.dpr=1}init(e){this.ctx=e.getContext("2d")??void 0}resize(e,t,r){this.dpr=r,this.ctx?.setTransform(r,0,0,r,0,0)}render(e){let t=this.ctx;if(!t)return;this.options.background?(t.fillStyle=this.options.background,t.fillRect(0,0,e.width,e.height)):t.clearRect(0,0,e.width,e.height);let r=[];for(let i of e.items){let o=i.mesh.vertices.map(a=>$(i.model,a)),s=i.transparency?.mode==="two-sided"?k(i.transparency):void 0;for(let a of i.mesh.faces){let c=o[a.indices[0]],m=o[a.indices[1]],u=o[a.indices[2]],h=M(z(O(m,c),O(u,c))),l=L(h,O(e.eye,c))>0,p=i.transparency;if(!l&&p?.mode!=="two-sided")continue;let d=1;p?.mode==="one-sided"?d=C(p.opacity,.35):s&&(d=l?s.front:s.back);let x=a.indices.map(y=>{let g=ot(e.viewProjection,o[y]);return{x:(g.x*.5+.5)*e.width,y:(1-(g.y*.5+.5))*e.height}}),b=0;for(let y of a.indices){let g=O(o[y],e.eye);b+=L(g,g)}b/=a.indices.length,r.push({points:x,color:fe(h,a.color,e.light),depth:b,opacity:d})}}r.sort((i,o)=>o.depth-i.depth);for(let i of r)if(!(i.points.length<3)){t.beginPath(),t.moveTo(i.points[0].x,i.points[0].y);for(let o=1;o<i.points.length;o++)t.lineTo(i.points[o].x,i.points[o].y);t.closePath(),t.fillStyle=i.color,t.strokeStyle=i.color,t.lineWidth=1,t.globalAlpha=i.opacity,t.fill(),t.stroke()}t.globalAlpha=1}destroy(){this.ctx=void 0}}});function C(n,e){return Math.max(0,Math.min(1,n??e))}function k(n){let e=C(n.frontOpacity??n.opacity,.56),t=n.opacity===void 0?.84:e*(2/3);return{front:e,back:C(n.backOpacity,t)}}function re(n,e){let t=[],r=[];for(let i of n)(i.transparency?r:t).push(i);return r.sort((i,o)=>{let s=i.model[12]-e.x,a=i.model[13]-e.y,c=i.model[14]-e.z,m=o.model[12]-e.x,u=o.model[13]-e.y,h=o.model[14]-e.z;return m*m+u*u+h*h-(s*s+a*a+c*c)}),t.concat(r)}async function mt(n,e={}){switch(n){case"webgl":return new(await Promise.resolve().then(()=>(ct(),at))).WebGLRenderer(e);case"webgpu":return new(await Promise.resolve().then(()=>(pt(),ut))).WebGPURenderer(e);default:return new(await Promise.resolve().then(()=>(lt(),ht))).Canvas2DRenderer(e)}}var D=P(()=>{"use strict"});var kn={};Q(kn,{Camera:()=>R,Light:()=>B,Little3dEngine:()=>F,LittleTweenEngine:()=>et,ObjectMotionAnimation:()=>$e,SpinAnimation:()=>Qe,centerAndScaleMesh:()=>Ct,circleMotion:()=>Pt,createSpinner:()=>_t,cross:()=>z,cube:()=>ie,cubeSphere:()=>Mt,cubic:()=>ve,dot:()=>L,ease:()=>ce,easeInBack:()=>ke,easeInBounce:()=>He,easeInCirc:()=>Re,easeInCubic:()=>oe,easeInElastic:()=>Ue,easeInExpo:()=>we,easeInOutBack:()=>_e,easeInOutBounce:()=>We,easeInOutCirc:()=>Be,easeInOutCubic:()=>Ie,easeInOutElastic:()=>Ge,easeInOutExpo:()=>Fe,easeInOutQuad:()=>Ee,easeInOutQuart:()=>Pe,easeInOutQuint:()=>Ve,easeInOutSine:()=>Se,easeInQuad:()=>U,easeInQuart:()=>se,easeInQuint:()=>ae,easeInSine:()=>ze,easeOutBack:()=>De,easeOutBounce:()=>_,easeOutCirc:()=>je,easeOutCubic:()=>W,easeOutElastic:()=>Ne,easeOutExpo:()=>q,easeOutQuad:()=>H,easeOutQuart:()=>Ce,easeOutQuint:()=>Le,easeOutSine:()=>Ae,easeTypes:()=>qe,enterFromObjectDirection:()=>yn,expandToTriangles:()=>j,figureEightMotion:()=>Vt,grow:()=>Xe,icosphere:()=>xt,leaveInObjectDirection:()=>xn,linear:()=>ge,normalize:()=>M,octaSphere:()=>gt,octahedron:()=>ft,orderRenderItems:()=>re,parseObj:()=>Bn,pyramid:()=>bt,quadratic:()=>Me,quartic:()=>Oe,quintic:()=>Te,scale:()=>A,shrink:()=>Ze,squareMotion:()=>Lt,subtract:()=>O,tetrahedron:()=>dt,transform:()=>te,uvSphere:()=>yt,vec3:()=>nt,wanderMotion:()=>wt});function tt(n){return Number.isNaN(n)?0:Math.min(1,Math.max(0,n))}function Dt(n,e,t){return n+(e-n)*t}function _t(n,e){if(!(n instanceof HTMLElement))throw new Error("3d-spinner: createSpinner requires a target HTMLElement.");let{animation:t}=e,r=e.type==="indeterminate";if(r&&e.periodMs!==void 0&&(!Number.isFinite(e.periodMs)||e.periodMs<=0))throw new RangeError("3d-spinner: periodMs must be a finite number greater than zero.");t.mount(n);let i=performance.now(),o=0,s=!1,a=!1,c=!1,m=!1,u=0,h=0,l=1/0;if(!r){let v=e;typeof v.progress=="number"&&(u=tt(v.progress),h=u),typeof v.timeout=="number"&&(l=Math.min(l,i+v.timeout)),v.until instanceof Date&&(l=Math.min(l,v.until.getTime()))}function p(v){if(!r)return v>=l&&(h=1),u=Dt(u,h,.12),Math.abs(h-u)<5e-4&&(u=h),u;let E=e,he=E.periodMs??2e3,Y=(v-i)/he;if((E.loop??"bounce")==="restart")return Y-Math.floor(Y);let le=Y-2*Math.floor(Y/2);return le<=1?le:2-le}function d(v){if(s)return;let E=p(v);!c&&(r||E>0)&&(t.enter(v),c=!0),!m&&c&&!r&&E>=1&&h>=1&&(t.exit(v),m=!0);let he=r?E:h;if(t.render(v,{progress:E,targetProgress:he,indeterminate:r}),m&&t.isFinished()){x();return}o=requestAnimationFrame(d)}function x(){s||(s=!0,o&&cancelAnimationFrame(o),o=0)}function b(v){r||(h=tt(v))}function y(){if(!(s||m)){if(!c){x();return}t.exit(performance.now()),m=!0}}function g(){a||(a=!0,x(),t.destroy())}return o=requestAnimationFrame(d),{setProgress:b,stop:y,destroy:g}}I();var Ut={position:{x:0,y:0,z:4},fov:55*Math.PI/180,near:.1,far:100},R=class{constructor(e){this.options={...Ut,...e}}toView(e){let{position:t}=this.options;return $(N(-t.x,-t.y,-t.z),e)}viewProjection(e){let{position:t,fov:r,near:i,far:o}=this.options,s=N(-t.x,-t.y,-t.z),a=it(r,e,i,o);return T(a,s)}toScreen(e,t,r){return{x:(e.x*.5+.5)*t,y:(1-(e.y*.5+.5))*r}}};ee();I();function te(n){return{position:n?.position??{x:0,y:0,z:0},rotation:n?.rotation??{x:0,y:0,z:0},scale:n?.scale??1}}D();ee();var Xt=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981","#ef4444"];function ie(n=1,e=Xt){let t=n/2,r=[{x:-t,y:-t,z:t},{x:t,y:-t,z:t},{x:t,y:t,z:t},{x:-t,y:t,z:t},{x:-t,y:-t,z:-t},{x:t,y:-t,z:-t},{x:t,y:t,z:-t},{x:-t,y:t,z:-t}],i=[{indices:[0,1,2,3],color:e[0%e.length]},{indices:[5,4,7,6],color:e[1%e.length]},{indices:[3,2,6,7],color:e[2%e.length]},{indices:[4,5,1,0],color:e[3%e.length]},{indices:[1,5,6,2],color:e[4%e.length]},{indices:[4,0,3,7],color:e[5%e.length]}];return{vertices:r,faces:i}}var Zt=["#3b82f6","#8b5cf6","#ec4899","#f59e0b"];function dt(n=1,e=Zt){let t=n/2,r=[{x:t,y:t,z:t},{x:t,y:-t,z:-t},{x:-t,y:t,z:-t},{x:-t,y:-t,z:t}],i=[{indices:[0,1,2],color:e[0%e.length]},{indices:[0,3,1],color:e[1%e.length]},{indices:[0,2,3],color:e[2%e.length]},{indices:[1,3,2],color:e[3%e.length]}];return{vertices:r,faces:i}}var Kt=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981","#ef4444","#06b6d4","#eab308"];function ft(n=1,e=Kt){let t=n/2,r=[{x:t,y:0,z:0},{x:-t,y:0,z:0},{x:0,y:t,z:0},{x:0,y:-t,z:0},{x:0,y:0,z:t},{x:0,y:0,z:-t}],i=[{indices:[4,0,2],color:e[0%e.length]},{indices:[4,2,1],color:e[1%e.length]},{indices:[4,1,3],color:e[2%e.length]},{indices:[4,3,0],color:e[3%e.length]},{indices:[5,2,0],color:e[4%e.length]},{indices:[5,1,2],color:e[5%e.length]},{indices:[5,3,1],color:e[6%e.length]},{indices:[5,0,3],color:e[7%e.length]}];return{vertices:r,faces:i}}var $t=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981"];function bt(n=1,e=$t){let t=n/2,r=[{x:-t,y:-t,z:t},{x:t,y:-t,z:t},{x:t,y:-t,z:-t},{x:-t,y:-t,z:-t},{x:0,y:t,z:0}],i=[{indices:[0,3,2,1],color:e[0%e.length]},{indices:[4,0,1],color:e[1%e.length]},{indices:[4,1,2],color:e[2%e.length]},{indices:[4,2,3],color:e[3%e.length]},{indices:[4,3,0],color:e[4%e.length]}];return{vertices:r,faces:i}}var Jt=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981","#ef4444"];function yt(n=1,e=1,t=Jt){let r=n/2,i=Math.max(1,Math.floor(e)),o=Math.max(4,i*4),s=Math.max(2,i*2),a=[{x:0,y:r,z:0}],c=(p,d)=>1+(p-1)*o+d;for(let p=1;p<s;p++){let d=Math.PI*p/s,x=r*Math.cos(d),b=r*Math.sin(d);for(let y=0;y<o;y++){let g=2*Math.PI*y/o;a.push({x:b*Math.cos(g),y:x,z:b*Math.sin(g)})}}let m=a.length;a.push({x:0,y:-r,z:0});let u=[],h=0,l=()=>t[h++%t.length];for(let p=0;p<o;p++)u.push({indices:[0,c(1,(p+1)%o),c(1,p)],color:l()});for(let p=1;p<s-1;p++)for(let d=0;d<o;d++){let x=(d+1)%o;u.push({indices:[c(p,d),c(p,x),c(p+1,x),c(p+1,d)],color:l()})}for(let p=0;p<o;p++)u.push({indices:[m,c(s-1,p),c(s-1,(p+1)%o)],color:l()});return{vertices:a,faces:u}}w();var en=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981","#ef4444"],S=(1+Math.sqrt(5))/2,tn=[{x:-1,y:S,z:0},{x:1,y:S,z:0},{x:-1,y:-S,z:0},{x:1,y:-S,z:0},{x:0,y:-1,z:S},{x:0,y:1,z:S},{x:0,y:-1,z:-S},{x:0,y:1,z:-S},{x:S,y:0,z:-1},{x:S,y:0,z:1},{x:-S,y:0,z:-1},{x:-S,y:0,z:1}],nn=[[0,11,5],[0,5,1],[0,1,7],[0,7,10],[0,10,11],[1,5,9],[5,11,4],[11,10,2],[10,7,6],[7,1,8],[3,9,4],[3,4,2],[3,2,6],[3,6,8],[3,8,9],[4,9,5],[2,4,11],[6,2,10],[8,6,7],[9,8,1]];function xt(n=1,e=1,t=en){return J(tn,nn,n,e,t)}w();var rn=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981","#ef4444"],on=[{x:1,y:0,z:0},{x:-1,y:0,z:0},{x:0,y:1,z:0},{x:0,y:-1,z:0},{x:0,y:0,z:1},{x:0,y:0,z:-1}],sn=[[4,0,2],[4,2,1],[4,1,3],[4,3,0],[5,2,0],[5,1,2],[5,3,1],[5,0,3]];function gt(n=1,e=1,t=rn){return J(on,sn,n,e,t)}var an=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981","#ef4444"],cn=[{normal:[0,0,1],right:[1,0,0],up:[0,1,0]},{normal:[0,0,-1],right:[-1,0,0],up:[0,1,0]},{normal:[1,0,0],right:[0,0,-1],up:[0,1,0]},{normal:[-1,0,0],right:[0,0,1],up:[0,1,0]},{normal:[0,1,0],right:[1,0,0],up:[0,0,-1]},{normal:[0,-1,0],right:[1,0,0],up:[0,0,1]}];function Mt(n=1,e=1,t=an){let r=n/2,i=Math.max(1,Math.floor(e)),o=[],s=[],a=0;for(let c of cn){let m=o.length;for(let h=0;h<=i;h++)for(let l=0;l<=i;l++){let p=-1+2*h/i,d=-1+2*l/i,x=c.normal[0]+p*c.right[0]+d*c.up[0],b=c.normal[1]+p*c.right[1]+d*c.up[1],y=c.normal[2]+p*c.right[2]+d*c.up[2],g=Math.hypot(x,b,y);o.push({x:x/g*r,y:b/g*r,z:y/g*r})}let u=(h,l)=>m+h*(i+1)+l;for(let h=0;h<i;h++)for(let l=0;l<i;l++)s.push({indices:[u(h,l),u(h+1,l),u(h+1,l+1),u(h,l+1)],color:t[a++%t.length]})}return{vertices:o,faces:s}}w();D();I();function un(n){let e=T(K(n.rotation.z),T(Z(n.rotation.y),X(n.rotation.x)));return T(N(n.position.x,n.position.y,n.position.z),T(e,rt(n.scale)))}var F=class{constructor(e={}){this.scene=[];this.cssWidth=0;this.cssHeight=0;this.ready=!1;this.generation=0;this.rafId=0;this.running=!1;this.camera=new R(e.camera),this.light=new B(e.light),this.backend=e.backend??"canvas2d",this.background=e.background}async mount(e){let t=document.createElement("canvas");t.style.display="block",t.style.width="100%",t.style.height="100%",e.appendChild(t),this.canvas=t,this.observer=new ResizeObserver(()=>this.resize()),this.observer.observe(t),this.resize();let r=this.generation,i=()=>{this.canvas===t&&(this.observer?.disconnect(),this.observer=void 0,t.remove(),this.canvas=void 0)};try{let o=await mt(this.backend,{background:this.background});if(r!==this.generation){o.destroy(),i();return}if(await o.init(t),r!==this.generation){o.destroy(),i();return}this.renderer=o,this.resize(),this.ready=!0}catch(o){throw i(),o}}add(e,t){let r={mesh:e,transform:te(t),transparency:t?.transparency,remove:()=>{let i=this.scene.indexOf(r);i>=0&&this.scene.splice(i,1)}};return this.scene.push(r),r}resize(){let e=this.canvas;if(!e)return;let t=window.devicePixelRatio||1;this.cssWidth=e.clientWidth||e.parentElement?.clientWidth||0,this.cssHeight=e.clientHeight||e.parentElement?.clientHeight||0,e.width=Math.max(1,Math.round(this.cssWidth*t)),e.height=Math.max(1,Math.round(this.cssHeight*t)),this.renderer?.resize(this.cssWidth,this.cssHeight,t)}render(){if(!this.ready||!this.renderer)return;let e=this.cssWidth,t=this.cssHeight;if(e===0||t===0)return;let r=this.scene.map(o=>({mesh:o.mesh,model:un(o.transform),transparency:o.transparency})),i=this.camera.options.position;this.renderer.render({items:re(r,i),viewProjection:this.camera.viewProjection(e/t),eye:i,light:this.light.params,width:e,height:t})}start(){if(this.running)return;this.running=!0;let e=()=>{this.running&&(this.render(),this.rafId=requestAnimationFrame(e))};this.rafId=requestAnimationFrame(e)}stop(){this.running=!1,this.rafId&&cancelAnimationFrame(this.rafId),this.rafId=0}destroy(){this.generation++,this.ready=!1,this.stop(),this.observer?.disconnect(),this.observer=void 0,this.renderer?.destroy(),this.renderer=void 0,this.canvas?.remove(),this.canvas=void 0}};function f(n,e){return Number.isNaN(n)?0:e?n:Math.min(1,Math.max(0,n))}function ge(n,e=!1){return f(n,e)}function Me(n,e=!1){return U(n,e)}function ve(n,e=!1){return oe(n,e)}function Oe(n,e=!1){return se(n,e)}function Te(n,e=!1){return ae(n,e)}function ze(n,e=!1){let t=f(n,e);return 1-Math.cos(t*Math.PI/2)}function Ae(n,e=!1){let t=f(n,e);return Math.sin(t*Math.PI/2)}function Se(n,e=!1){let t=f(n,e);return-(Math.cos(Math.PI*t)-1)/2}function U(n,e=!1){let t=f(n,e);return t*t}function H(n,e=!1){let t=f(n,e);return 1-(1-t)*(1-t)}function Ee(n,e=!1){let t=f(n,e);return t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2}function oe(n,e=!1){let t=f(n,e);return t*t*t}function W(n,e=!1){let t=f(n,e);return 1-Math.pow(1-t,3)}function Ie(n,e=!1){let t=f(n,e);return t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2}function se(n,e=!1){let t=f(n,e);return t*t*t*t}function Ce(n,e=!1){let t=f(n,e);return 1-Math.pow(1-t,4)}function Pe(n,e=!1){let t=f(n,e);return t<.5?8*t*t*t*t:1-Math.pow(-2*t+2,4)/2}function ae(n,e=!1){let t=f(n,e);return t*t*t*t*t}function Le(n,e=!1){let t=f(n,e);return 1-Math.pow(1-t,5)}function Ve(n,e=!1){let t=f(n,e);return t<.5?16*t*t*t*t*t:1-Math.pow(-2*t+2,5)/2}function we(n,e=!1){let t=f(n,e);return t===0?0:Math.pow(2,10*t-10)}function q(n,e=!1){let t=f(n,e);return t===1?1:1-Math.pow(2,-10*t)}function Fe(n,e=!1){let t=f(n,e);return t===0?0:t===1?1:t<.5?Math.pow(2,20*t-10)/2:(2-Math.pow(2,-20*t+10))/2}function Re(n,e=!1){let t=f(n,e);return 1-Math.sqrt(1-Math.pow(t,2))}function je(n,e=!1){let t=f(n,e);return Math.sqrt(1-Math.pow(t-1,2))}function Be(n,e=!1){let t=f(n,e);return t<.5?(1-Math.sqrt(1-Math.pow(2*t,2)))/2:(Math.sqrt(1-Math.pow(-2*t+2,2))+1)/2}function ke(n,e=!1){let t=f(n,e),r=1.70158;return(r+1)*t*t*t-r*t*t}function De(n,e=!1){let t=f(n,e),r=1.70158;return 1+(r+1)*Math.pow(t-1,3)+r*Math.pow(t-1,2)}function _e(n,e=!1){let t=f(n,e),i=1.70158*1.525;return t<.5?Math.pow(2*t,2)*((i+1)*2*t-i)/2:(Math.pow(2*t-2,2)*((i+1)*(t*2-2)+i)+2)/2}function Ue(n,e=!1){let t=f(n,e),r=2*Math.PI/3;return t===0?0:t===1?1:-Math.pow(2,10*t-10)*Math.sin((t*10-10.75)*r)}function Ne(n,e=!1){let t=f(n,e),r=2*Math.PI/3;return t===0?0:t===1?1:Math.pow(2,-10*t)*Math.sin((t*10-.75)*r)+1}function Ge(n,e=!1){let t=f(n,e),r=2*Math.PI/4.5;return t===0?0:t===1?1:t<.5?-(Math.pow(2,20*t-10)*Math.sin((20*t-11.125)*r))/2:Math.pow(2,-20*t+10)*Math.sin((20*t-11.125)*r)/2+1}function He(n,e=!1){let t=f(n,e);return 1-_(1-t,!0)}function _(n,e=!1){let t=f(n,e),r=7.5625,i=2.75;return t<1/i?r*t*t:t<2/i?(t-=1.5/i,r*t*t+.75):t<2.5/i?(t-=2.25/i,r*t*t+.9375):(t-=2.625/i,r*t*t+.984375)}function We(n,e=!1){let t=f(n,e);return t<.5?(1-_(1-2*t,!0))/2:(1+_(2*t-1,!0))/2}var qe={linear:ge,quadratic:Me,cubic:ve,quartic:Oe,quintic:Te,easeInSine:ze,easeOutSine:Ae,easeInOutSine:Se,easeInQuad:U,easeOutQuad:H,easeInOutQuad:Ee,easeInCubic:oe,easeOutCubic:W,easeInOutCubic:Ie,easeInQuart:se,easeOutQuart:Ce,easeInOutQuart:Pe,easeInQuint:ae,easeOutQuint:Le,easeInOutQuint:Ve,easeInExpo:we,easeOutExpo:q,easeInOutExpo:Fe,easeInCirc:Re,easeOutCirc:je,easeInOutCirc:Be,easeInBack:ke,easeOutBack:De,easeInOutBack:_e,easeInElastic:Ue,easeOutElastic:Ne,easeInOutElastic:Ge,easeInBounce:He,easeOutBounce:_,easeInOutBounce:We};function ce(n,e,t=!1){return qe[n](e,t)}function pn(n={}){return{popDurationMs:n.popDurationMs??500,overextend:n.overextend??.2,startSnapRatio:n.startSnapRatio??.2,loadingText:n.loadingText===void 0?"loading":n.loadingText,doneText:n.doneText??"done",doneFadeDurationMs:n.doneFadeDurationMs??2e3,removeOnComplete:n.removeOnComplete??!1}}function Ye(n,e,t){return t<=0?1:Math.min(1,Math.max(0,(n-e)/t))}var ue=class{constructor(e={}){this.phase="idle";this.phaseStart=0;this.activeProgress=0;this.popTarget=0;this.doneFadeStart=0;this.options=pn(e)}enter(e){this.phase==="idle"&&(this.phase="startPop",this.phaseStart=e,this.activeProgress=0,this.popTarget=0)}exit(e){this.phase!=="startPop"&&this.phase!=="active"||(this.phase="endPop",this.phaseStart=e)}isFinished(){return this.phase==="finished"}update(e,t,r){let{popDurationMs:i,overextend:o,startSnapRatio:s,loadingText:a,doneText:c,doneFadeDurationMs:m,removeOnComplete:u}=this.options,h=r??t;(this.phase==="startPop"||this.phase==="active")&&(this.activeProgress=t,this.phase==="startPop"&&(this.popTarget=Math.max(this.popTarget,h,t)));let l=0,p=null,d=0,x=!1;if(this.phase==="startPop"){let b=Ye(e,this.phaseStart,i),y=this.popTarget*(1+o);if(b<s){let g=s>0?b/s:1;l=y*q(g)}else{let g=s<1?(b-s)/(1-s):1;l=y+(this.activeProgress-y)*W(g)}b>=1&&(this.phase="active")}else if(this.phase==="active")l=this.activeProgress;else if(this.phase==="endPop"){let b=Ye(e,this.phaseStart,i),y=1+o;b<.5?l=1+(y-1)*H(b*2):l=y*(1-U((b-.5)*2)),b>=1&&(this.phase="done",this.doneFadeStart=e,l=0)}if(this.phase==="startPop"||this.phase==="active")a!==!1&&(p=a,d=.65);else if(this.phase==="endPop")p=c,d=.65;else if(this.phase==="done"){let b=Ye(e,this.doneFadeStart,m);b>=1?(u&&(x=!0),this.phase="finished"):(p=c,d=.65*(1-b))}return{scale:l,text:p,textOpacity:d,hidden:x}}};var hn=["position:absolute","inset:0","display:flex","align-items:center","justify-content:center","pointer-events:none","font:600 1.1rem/1.2 system-ui,sans-serif","letter-spacing:0.06em","text-transform:lowercase","color:rgba(255,255,255,0.65)","z-index:1"].join(";");function ln(n){return n?typeof n=="function"?n():n:ie()}function mn(n,e){if(e===void 0||Array.isArray(e)&&e.length===0)return n;let t=Array.isArray(e)?r=>e[r%e.length]:()=>e;return{vertices:n.vertices,faces:n.faces.map((r,i)=>({...r,color:t(i)}))}}var Qe=class{constructor(e={}){this.exited=!1;this.mesh=mn(ln(e.shape),e.color),this.spinX=e.spinX??7e-4,this.spinY=e.spinY??.0011,this.backend=e.backend,this.transparency=e.transparency,this.progress=e.progressAnimation?new ue(e.progressAnimation):void 0}mount(e){e.style.position="relative";let t=new F({backend:this.backend,camera:{position:{x:0,y:0,z:2.8}}});if(this.handle=t.add(this.mesh,{transparency:this.transparency}),this.engine=t,t.mount(e).catch(r=>{e.textContent=r instanceof Error?r.message:String(r)}),this.progress){let r=document.createElement("div");r.style.cssText=hn,r.setAttribute("aria-hidden","true"),r.hidden=!0,e.appendChild(r),this.label=r}}enter(e){this.progress?.enter(e)}exit(e){this.exited=!0,this.progress?.exit(e)}isFinished(){return this.progress?this.progress.isFinished():this.exited}render(e,t){if(!this.engine||!this.handle)return;let r=this.handle.transform.rotation;if(r.x=e*this.spinX,r.y=e*this.spinY,this.progress){let i=this.progress.update(e,t.progress,t.targetProgress);this.handle.transform.scale=i.hidden?0:i.scale,this.applyLabel(i)}else this.handle.transform.scale=1;this.engine.render()}destroy(){this.label?.remove(),this.label=void 0,this.engine?.destroy(),this.engine=void 0,this.handle=void 0}applyLabel(e){if(this.label){if(e.hidden||e.text==null){this.label.hidden=!0,this.label.textContent="";return}this.label.hidden=!1,this.label.textContent=e.text,this.label.style.opacity=String(e.textOpacity)}}};I();function vt(n,e){return{x:n.x+e.x,y:n.y+e.y,z:n.z+e.z}}function pe(n,e){return{x:n.x*e,y:n.y*e,z:n.z*e}}function Ot(n){return Math.hypot(n.x,n.y,n.z)}function dn(n){let e=Ot(n);return e<1e-6?{x:1,y:0,z:0}:pe(n,1/e)}function fn(n,e){return dn(e??n.direction??n.velocity??{x:1,y:0,z:0})}function bn(n){let t=n-1;return 1+(1.70158+1)*t*t*t+1.70158*t*t}function Tt(n,e,t){let r=n.velocity?Ot(n.velocity):0;if(n.velocity&&r>1e-6&&!e.direction)return n.velocity;let i=e.distance??3.5;return pe(fn(n,e.direction),i/t)}function yn(n={}){return e=>{let t=Math.max(1,e.durationMs),r=Tt(e,n,t),i=t-e.elapsedMs;return{position:vt(e.position,pe(r,-i))}}}function xn(n={}){return e=>{let t=Math.max(1,e.durationMs),r=Tt(e,n,t);return{position:vt(e.position,pe(r,e.elapsedMs))}}}function Xe(){return n=>({size:(n.size??1)*bn(n.delta)})}function Ze(){return n=>({size:(n.size??1)*(1-n.delta*n.delta)})}var gn=["position:absolute","inset:0","display:flex","align-items:center","justify-content:center","pointer-events:none","font:700 1.6rem/1 system-ui,sans-serif","letter-spacing:0.02em","color:rgba(255,255,255,0.9)","text-shadow:0 1px 10px rgba(0,0,0,0.6)","z-index:1"].join(";"),Mn={x:0,y:1,z:0},vn=2100,On=2100,Tn=26,zt=.7,zn=.12,Ke=8,An={"+x":n=>n,"-x":n=>({x:-n.x,y:n.y,z:-n.z}),"+z":n=>({x:n.z,y:n.y,z:-n.x}),"-z":n=>({x:-n.z,y:n.y,z:n.x}),"+y":n=>({x:n.y,y:-n.x,z:n.z}),"-y":n=>({x:-n.y,y:n.x,z:n.z})};function Sn(n,e){return{x:n.x+e.x,y:n.y+e.y,z:n.z+e.z}}function En(n){return typeof n=="function"?n():n}function In(n,e){return{vertices:n.vertices,faces:n.faces.map(t=>({...t,color:e}))}}function Cn(n,e){if(e==="+x")return n;let t=An[e];return{vertices:n.vertices.map(t),faces:n.faces}}function Ct(n,e){let t=1/0,r=1/0,i=1/0,o=-1/0,s=-1/0,a=-1/0;for(let p of n.vertices)t=Math.min(t,p.x),r=Math.min(r,p.y),i=Math.min(i,p.z),o=Math.max(o,p.x),s=Math.max(s,p.y),a=Math.max(a,p.z);let c=(t+o)/2,m=(r+s)/2,u=(i+a)/2,h=Math.max(o-t,s-r,a-i)||1,l=e/h;return{vertices:n.vertices.map(p=>({x:(p.x-c)*l,y:(p.y-m)*l,z:(p.z-u)*l})),faces:n.faces}}function Pn(n,e){let t=M(n),r=z(t,Mn);Math.hypot(r.x,r.y,r.z)<1e-4&&(r={x:0,y:0,z:1}),r=M(r);let i=z(r,t),o=Sn(A(i,Math.cos(e)),A(r,Math.sin(e))),s=M(z(t,o));return{x:Math.atan2(z(s,t).z,s.z),y:Math.asin(Math.max(-1,Math.min(1,-t.z))),z:Math.atan2(t.y,t.x)}}function At(n,e,t){return T(K(t),T(Z(e),X(n)))}function Ln(n){return Math.hypot(n[0],n[1])>1e-6?{x:Math.atan2(n[9],n[10]),y:Math.asin(Math.max(-1,Math.min(1,-n[8]))),z:Math.atan2(n[4],n[0])}:{x:Math.atan2(-n[6],n[5]),y:Math.asin(Math.max(-1,Math.min(1,-n[8]))),z:0}}function Vn(n,e){return Ln(T(At(n.x,n.y,n.z),At(e.x,e.y,e.z)))}function wn(n){return Math.max(0,Math.min(1,n))}function St(n,e){return A(O(n.positionAt(e+1),n.positionAt(e-1)),.5)}function Et(n,e){return Math.hypot(n.x,n.y,n.z)>1e-6?M(n):e}function It(n,e,t){return n?typeof n=="function"?{transition:n,durationMs:t}:{transition:n.transition,durationMs:Math.max(0,n.durationMs??t)}:{transition:e,durationMs:t}}var $e=class{constructor(e){this.handles=[];this.banks=[];this.headings=[];this.started=!1;this.finished=!1;this.introStart=0;this.outroStart=1/0;this.outroPosition={x:0,y:0,z:0};this.outroVelocity={x:0,y:0,z:0};this.outroDirection={x:1,y:0,z:0};let t=Ct(En(e.mesh),e.size??1),r=Cn(t,e.facing??"+x");this.mesh=In(r,e.color??"#cbd5e1"),this.motion=e.motion,this.backend=e.backend,this.transparency=e.transparency,this.labelText=e.label,this.tailCount=Math.max(0,Math.floor(e.tail?.count??0)),this.tailGap=Math.max(0,e.tail?.gapMs??0),this.intro=It(e.intro,Xe(),vn),this.outro=It(e.outro,Ze(),On);let i=e.rotation;this.rotationOffset={x:i?.x??0,y:i?.y??0,z:i?.z??0},this.rotationSpin={x:i?.spinX??0,y:i?.spinY??0,z:i?.spinZ??0},this.hasExtraRotation=this.rotationOffset.x!==0||this.rotationOffset.y!==0||this.rotationOffset.z!==0||this.rotationSpin.x!==0||this.rotationSpin.y!==0||this.rotationSpin.z!==0}mount(e){e.style.position="relative";let t=new F({backend:this.backend,camera:{position:{x:0,y:0,z:3}}});for(let i=0;i<=this.tailCount;i++)this.handles.push(t.add(this.mesh,{transparency:this.transparency})),this.banks.push(0),this.headings.push({x:1,y:0,z:0});this.engine=t,t.mount(e).catch(i=>{e.textContent=i instanceof Error?i.message:String(i)});let r=document.createElement("div");r.style.cssText=gn,r.setAttribute("role","status"),e.appendChild(r),this.label=r}enter(e){this.started||(this.started=!0,this.introStart=e)}exit(e){!this.started||this.outroStart!==1/0||(this.outroPosition=this.motion.positionAt(e),this.outroVelocity=St(this.motion,e),this.outroDirection=Et(this.outroVelocity,this.headings[0]),this.outroStart=e)}isFinished(){return this.finished}render(e,t){if(!(!this.engine||!this.label)){this.outroStart!==1/0&&e>=this.outroStart+this.outro.durationMs+this.tailCount*this.tailGap&&(this.finished=!0);for(let r=0;r<this.handles.length;r++){let i=this.handles[r].transform,o=e-r*this.tailGap,s=this.sampleAt(o);if(!s){i.scale=0;continue}i.scale=s.size;let a=s.orientation;if(!a){let c=O(this.positionAt(o+Ke)??s.position,s.position);Math.hypot(c.x,c.y,c.z)>1e-5&&(this.headings[r]=M(c));let m=this.aheadAt(o)??this.headings[r],u=Math.max(-zt,Math.min(zt,z(this.headings[r],m).y*Tn));this.banks[r]+=(u-this.banks[r])*zn,a=Pn(this.headings[r],this.banks[r])}this.hasExtraRotation&&(a=Vn(a,{x:this.rotationOffset.x+this.rotationSpin.x*o,y:this.rotationOffset.y+this.rotationSpin.y*o,z:this.rotationOffset.z+this.rotationSpin.z*o})),i.position.x=s.position.x,i.position.y=s.position.y,i.position.z=s.position.z,i.rotation.x=a.x,i.rotation.y=a.y,i.rotation.z=a.z}this.label.textContent=t.indeterminate?this.labelText??"":`${Math.round(t.progress*100)}%`,this.engine.render()}}destroy(){this.label?.remove(),this.label=void 0,this.engine?.destroy(),this.engine=void 0,this.handles.length=0}aheadAt(e){let t=this.positionAt(e+Ke),r=this.positionAt(e+2*Ke);if(!t||!r)return;let i=O(r,t);if(!(Math.hypot(i.x,i.y,i.z)<=1e-5))return M(i)}positionAt(e){return this.sampleAt(e)?.position}sampleAt(e){if(!(!this.started||e<this.introStart)){if(e<this.introStart+this.intro.durationMs)return this.transitionSample("intro",e,this.intro,this.introStart);if(this.outroStart!==1/0){if(e>this.outroStart+this.outro.durationMs)return;if(e>=this.outroStart)return this.transitionSample("outro",e,this.outro,this.outroStart)}return{position:this.motion.positionAt(e),size:1}}}transitionSample(e,t,r,i){let o=Math.max(0,t-i),s=r.durationMs===0?1:wn(o/r.durationMs),a=this.transitionInput(e,s,o,r.durationMs,i),c=r.transition(a);return this.applyTransitionOutput(a,c)}transitionInput(e,t,r,i,o){if(e==="intro"){let s=o+i,a=St(this.motion,s);return{delta:t,position:this.motion.positionAt(s),direction:Et(a,{x:1,y:0,z:0}),velocity:a,size:1,durationMs:i,elapsedMs:r,phase:e}}return{delta:t,position:this.outroPosition,direction:this.outroDirection,velocity:this.outroVelocity,size:1,durationMs:i,elapsedMs:r,phase:e}}applyTransitionOutput(e,t){return{position:t.position??e.position,size:t.size??e.size??1,orientation:t.orientation}}};function Pt(n={}){let e=n.radius??1.3,t=n.periodMs??3e3,r=n.tilt??.5,i=n.direction??1,o=Math.cos(r),s=Math.sin(r);return{positionAt(a){let c=i*a/t*Math.PI*2,m=e*Math.cos(c),u=e*Math.sin(c);return{x:m,y:u*o,z:u*s}}}}function Lt(n={}){let e=(n.size??2.4)/2,t=n.periodMs??4e3,r=n.tilt??.45,i=n.direction??1,o=Math.cos(r),s=Math.sin(r);return{positionAt(a){let c=i*a/t,m=(c-Math.floor(c))*4,u=Math.floor(m),h=m-u,l,p;return u===0?(l=-e+2*e*h,p=-e):u===1?(l=e,p=-e+2*e*h):u===2?(l=e-2*e*h,p=e):(l=-e,p=e-2*e*h),{x:l,y:p*o,z:p*s}}}}function Vt(n={}){let e=n.size??1,t=n.periodMs??3600;return{positionAt(r){let i=r/t*Math.PI*2;return{x:e*1.5*Math.sin(i),y:e*1*Math.sin(i)*Math.cos(i),z:e*1.05*Math.cos(i)}}}}function Fn(n){let e=n>>>0;return()=>{e=e+1831565813|0;let t=Math.imul(e^e>>>15,1|e);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}function Je(n,e,t){let r=[0,1,2].map(()=>({freq:.5+n()*1.4,phase:n()*Math.PI*2,weight:.5+n()})),i=r.reduce((o,s)=>o+s.weight,0);return o=>{let s=0;for(let a of r)s+=a.weight*Math.sin(e*a.freq*o+a.phase);return s/i*t}}function wt(n={}){let e=n.bounds?.x??1.4,t=n.bounds?.y??1,r=n.bounds?.z??.6,i=n.periodMs??9e3,o=n.seed??Math.random()*1e9|0,s=Fn(o),a=2*Math.PI/i,c=Je(s,a,e),m=Je(s,a,t),u=Je(s,a,r);return{positionAt(h){return{x:c(h),y:m(h),z:u(h)}}}}var Rn=["#3b82f6","#8b5cf6","#ec4899","#f59e0b","#10b981","#ef4444"];function jn(n,e){let t=parseInt(n,10);return t<0?e+t:t-1}function Bn(n,e={}){let t=e.colors??Rn,r=[],i=[];for(let o of n.split(`
|
|
58
|
+
`)){let s=o.trim();if(s===""||s.startsWith("#"))continue;let a=s.split(/\s+/),c=a[0];if(c==="v")r.push({x:parseFloat(a[1]),y:parseFloat(a[2]),z:parseFloat(a[3])});else if(c==="f"){let m=[];for(let u=1;u<a.length;u++){let h=a[u].split("/")[0];m.push(jn(h,r.length))}m.length>=3&&i.push({indices:m,color:t[i.length%t.length]})}}return{vertices:r,faces:i}}var et=class{constructor(e={}){this.type=e.type??"linear",this.overextend=e.overextend??!1}value(e,t=this.type,r=this.overextend){return ce(t,e,r)}};return kt(kn);})();
|
package/package.json
CHANGED
|
@@ -1,43 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "3d-spinner",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "A lightweight, zero-dependency 3D spinner, loader, and progress indicator for JavaScript.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "./dist/index.
|
|
6
|
+
"main": "./dist/cjs/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
|
+
"browser": "./dist/umd/spinner.global.js",
|
|
9
|
+
"unpkg": "./dist/umd/spinner.global.min.js",
|
|
10
|
+
"jsdelivr": "./dist/umd/spinner.global.min.js",
|
|
8
11
|
"types": "./dist/index.d.ts",
|
|
9
12
|
"exports": {
|
|
10
13
|
".": {
|
|
11
14
|
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.js"
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/cjs/index.cjs"
|
|
13
17
|
},
|
|
14
18
|
"./animations/spin": {
|
|
15
19
|
"types": "./dist/animations/spin.d.ts",
|
|
16
|
-
"import": "./dist/animations/spin.js"
|
|
20
|
+
"import": "./dist/animations/spin.js",
|
|
21
|
+
"require": "./dist/cjs/animations/spin.cjs"
|
|
17
22
|
},
|
|
18
23
|
"./animations/object-motion": {
|
|
19
24
|
"types": "./dist/animations/object-motion.d.ts",
|
|
20
|
-
"import": "./dist/animations/object-motion.js"
|
|
25
|
+
"import": "./dist/animations/object-motion.js",
|
|
26
|
+
"require": "./dist/cjs/animations/object-motion.cjs"
|
|
21
27
|
},
|
|
22
28
|
"./motion": {
|
|
23
29
|
"types": "./dist/motion/motion.d.ts",
|
|
24
|
-
"import": "./dist/motion/motion.js"
|
|
30
|
+
"import": "./dist/motion/motion.js",
|
|
31
|
+
"require": "./dist/cjs/motion/motion.cjs"
|
|
25
32
|
},
|
|
26
33
|
"./motion/transitions": {
|
|
27
34
|
"types": "./dist/motion/transitions.d.ts",
|
|
28
|
-
"import": "./dist/motion/transitions.js"
|
|
35
|
+
"import": "./dist/motion/transitions.js",
|
|
36
|
+
"require": "./dist/cjs/motion/transitions.cjs"
|
|
29
37
|
},
|
|
30
38
|
"./engines/little-3d-engine": {
|
|
31
39
|
"types": "./dist/engines/little-3d-engine/little-3d-engine.d.ts",
|
|
32
|
-
"import": "./dist/engines/little-3d-engine/little-3d-engine.js"
|
|
40
|
+
"import": "./dist/engines/little-3d-engine/little-3d-engine.js",
|
|
41
|
+
"require": "./dist/cjs/engines/little-3d-engine/little-3d-engine.cjs"
|
|
33
42
|
},
|
|
34
43
|
"./engines/little-3d-engine/loaders/obj": {
|
|
35
44
|
"types": "./dist/engines/little-3d-engine/loaders/obj.d.ts",
|
|
36
|
-
"import": "./dist/engines/little-3d-engine/loaders/obj.js"
|
|
45
|
+
"import": "./dist/engines/little-3d-engine/loaders/obj.js",
|
|
46
|
+
"require": "./dist/cjs/engines/little-3d-engine/loaders/obj.cjs"
|
|
37
47
|
},
|
|
38
48
|
"./engines/little-tween-engine": {
|
|
39
49
|
"types": "./dist/engines/little-tween-engine/little-tween-engine.d.ts",
|
|
40
|
-
"import": "./dist/engines/little-tween-engine/little-tween-engine.js"
|
|
50
|
+
"import": "./dist/engines/little-tween-engine/little-tween-engine.js",
|
|
51
|
+
"require": "./dist/cjs/engines/little-tween-engine/little-tween-engine.cjs"
|
|
41
52
|
}
|
|
42
53
|
},
|
|
43
54
|
"files": [
|
|
@@ -45,7 +56,10 @@
|
|
|
45
56
|
],
|
|
46
57
|
"scripts": {
|
|
47
58
|
"clean": "node -e \"fs.rmSync('dist', { recursive: true, force: true })\"",
|
|
48
|
-
"build": "
|
|
59
|
+
"build:esm": "tsc",
|
|
60
|
+
"build:cjs": "node scripts/build-cjs.mjs",
|
|
61
|
+
"build:umd": "node scripts/build-umd.mjs",
|
|
62
|
+
"build": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:umd",
|
|
49
63
|
"dev": "npx serve .",
|
|
50
64
|
"pretest": "npm run build",
|
|
51
65
|
"test": "node --test tests/*.test.mjs",
|
|
@@ -69,6 +83,7 @@
|
|
|
69
83
|
"url": "https://github.com/runelaang/3d-spinner/issues"
|
|
70
84
|
},
|
|
71
85
|
"devDependencies": {
|
|
86
|
+
"esbuild": "^0.28.1",
|
|
72
87
|
"typescript": "^5.7.0"
|
|
73
88
|
}
|
|
74
89
|
}
|