@tresjs/leches 0.1.0

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.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * name: @tresjs/leches
3
+ * version: v0.1.0
4
+ * (c) 2023
5
+ * description: Tasty GUI for Vue controls 🍰
6
+ * author: Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)
7
+ */
8
+ (function(z,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core"],n):(z=typeof globalThis<"u"?globalThis:z||self,n(z.tresleches={},z.Vue,z.VueUseCore))})(this,function(z,n,w){"use strict";const Ht="",Qt="";function B(i){return n.getCurrentScope()?(n.onScopeDispose(i),!0):!1}function C(i){return typeof i=="function"?i():n.unref(i)}const $=typeof window<"u",T=()=>{},A=R();function R(){var i;return $&&((i=window==null?void 0:window.navigator)==null?void 0:i.userAgent)&&/iP(ad|hone|od)/.test(window.navigator.userAgent)}function Y(...i){if(i.length!==1)return n.toRef(...i);const t=i[0];return typeof t=="function"?n.readonly(n.customRef(()=>({get:t,set:T}))):n.ref(t)}function O(i){var t;const e=C(i);return(t=e==null?void 0:e.$el)!=null?t:e}const H=$?window:void 0;function Q(...i){let t,e,s,o;if(typeof i[0]=="string"||Array.isArray(i[0])?([e,s,o]=i,t=H):[t,e,s,o]=i,!t)return T;Array.isArray(e)||(e=[e]),Array.isArray(s)||(s=[s]);const r=[],a=()=>{r.forEach(c=>c()),r.length=0},l=(c,h,d,u)=>(c.addEventListener(h,d,u),()=>c.removeEventListener(h,d,u)),x=n.watch(()=>[O(t),C(o)],([c,h])=>{a(),c&&r.push(...e.flatMap(d=>s.map(u=>l(c,d,u,h))))},{immediate:!0,flush:"post"}),y=()=>{x(),a()};return B(y),y}var Z=Object.defineProperty,W=Object.defineProperties,U=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable,D=(i,t,e)=>t in i?Z(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e,J=(i,t)=>{for(var e in t||(t={}))K.call(t,e)&&D(i,e,t[e]);if(I)for(var e of I(t))G.call(t,e)&&D(i,e,t[e]);return i},v=(i,t)=>W(i,U(t));const tt=n.defineComponent({name:"UseDraggable",props:["storageKey","storageType","initialValue","exact","preventDefault","stopPropagation","pointerTypes","as","handle","axis"],setup(i,{slots:t}){const e=n.ref(),s=n.computed(()=>{var x;return(x=i.handle)!=null?x:e.value}),o=i.storageKey&&w.useStorage(i.storageKey,C(i.initialValue)||{x:0,y:0},w.isClient?i.storageType==="session"?sessionStorage:localStorage:void 0),r=o||i.initialValue||{x:0,y:0},a=x=>{o&&(o.value.x=x.x,o.value.y=x.y)},l=n.reactive(w.useDraggable(e,v(J({},i),{handle:s,initialValue:r,onEnd:a})));return()=>{if(t.default)return n.h(i.as||"div",{ref:e,style:`touch-action:none;${l.style}`},t.default(l))}}});function q(i){const t=window.getComputedStyle(i);if(t.overflowX==="scroll"||t.overflowY==="scroll"||t.overflowX==="auto"&&i.clientHeight<i.scrollHeight||t.overflowY==="auto"&&i.clientWidth<i.scrollWidth)return!0;{const e=i.parentNode;return!e||e.tagName==="BODY"?!1:q(e)}}function et(i){const t=i||window.event,e=t.target;return q(e)?!1:t.touches.length>1?!0:(t.preventDefault&&t.preventDefault(),!1)}function st(i,t=!1){const e=n.ref(t);let s=null,o;n.watch(Y(i),l=>{if(l){const x=l;o=x.style.overflow,e.value&&(x.style.overflow="hidden")}},{immediate:!0});const r=()=>{const l=C(i);!l||e.value||(A&&(s=Q(l,"touchmove",x=>{et(x)},{passive:!1})),l.style.overflow="hidden",e.value=!0)},a=()=>{const l=C(i);!l||!e.value||(A&&(s==null||s()),l.style.overflow=o,e.value=!1)};return B(a),n.computed({get(){return e.value},set(l){l?r():a()}})}function nt(){let i=!1;const t=n.ref(!1);return(e,s)=>{if(t.value=s.value,i)return;i=!0;const o=st(e,s.value);n.watch(t,r=>o.value=r)}}nt();const it=Symbol("CONTROLS_CONTEXT_KEY"),E=n.reactive({controls:[]});function ot(){return E}function j(i){return Object.entries(i).map(([t,e])=>!n.isRef(e)&&e.value?{...e,label:e.label||t,value:e.value,type:typeof e.value.value,visible:!0}:{label:e.label||t,value:e,type:n.isRef(e)?typeof e.value:typeof e,visible:!0})}function rt(i){const t=n.inject(it,{});let e=[];if(typeof i!="string")if(n.isReactive(i)){const s=n.toRefs(i);e=j(s)}else e=j(i);return E.controls=[...E.controls,...e],t}/**
9
+ * @license
10
+ * Copyright 2010-2023 Three.js Authors
11
+ * SPDX-License-Identifier: MIT
12
+ */const P="152";function V(i,t,e){return Math.max(t,Math.min(e,i))}class k{constructor(t=0,e=0){k.prototype.isVector2=!0,this.x=t,this.y=e}get width(){return this.x}set width(t){this.x=t}get height(){return this.y}set height(t){this.y=t}set(t,e){return this.x=t,this.y=e,this}setScalar(t){return this.x=t,this.y=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y)}copy(t){return this.x=t.x,this.y=t.y,this}add(t){return this.x+=t.x,this.y+=t.y,this}addScalar(t){return this.x+=t,this.y+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this}subScalar(t){return this.x-=t,this.y-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}multiplyScalar(t){return this.x*=t,this.y*=t,this}divide(t){return this.x/=t.x,this.y/=t.y,this}divideScalar(t){return this.multiplyScalar(1/t)}applyMatrix3(t){const e=this.x,s=this.y,o=t.elements;return this.x=o[0]*e+o[3]*s+o[6],this.y=o[1]*e+o[4]*s+o[7],this}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this}roundToZero(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this}negate(){return this.x=-this.x,this.y=-this.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}lengthSq(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)}normalize(){return this.divideScalar(this.length()||1)}angle(){return Math.atan2(-this.y,-this.x)+Math.PI}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(V(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y;return e*e+s*s}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this}equals(t){return t.x===this.x&&t.y===this.y}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this}rotateAround(t,e){const s=Math.cos(e),o=Math.sin(e),r=this.x-t.x,a=this.y-t.y;return this.x=r*s-a*o+t.x,this.y=r*o+a*s+t.y,this}random(){return this.x=Math.random(),this.y=Math.random(),this}*[Symbol.iterator](){yield this.x,yield this.y}}class ht{constructor(t=0,e=0,s=0,o=1){this.isQuaternion=!0,this._x=t,this._y=e,this._z=s,this._w=o}static slerpFlat(t,e,s,o,r,a,l){let x=s[o+0],y=s[o+1],c=s[o+2],h=s[o+3];const d=r[a+0],u=r[a+1],_=r[a+2],f=r[a+3];if(l===0){t[e+0]=x,t[e+1]=y,t[e+2]=c,t[e+3]=h;return}if(l===1){t[e+0]=d,t[e+1]=u,t[e+2]=_,t[e+3]=f;return}if(h!==f||x!==d||y!==u||c!==_){let p=1-l;const m=x*d+y*u+c*_+h*f,g=m>=0?1:-1,X=1-m*m;if(X>Number.EPSILON){const M=Math.sqrt(X),F=Math.atan2(M,m*g);p=Math.sin(p*F)/M,l=Math.sin(l*F)/M}const S=l*g;if(x=x*p+d*S,y=y*p+u*S,c=c*p+_*S,h=h*p+f*S,p===1-l){const M=1/Math.sqrt(x*x+y*y+c*c+h*h);x*=M,y*=M,c*=M,h*=M}}t[e]=x,t[e+1]=y,t[e+2]=c,t[e+3]=h}static multiplyQuaternionsFlat(t,e,s,o,r,a){const l=s[o],x=s[o+1],y=s[o+2],c=s[o+3],h=r[a],d=r[a+1],u=r[a+2],_=r[a+3];return t[e]=l*_+c*h+x*u-y*d,t[e+1]=x*_+c*d+y*h-l*u,t[e+2]=y*_+c*u+l*d-x*h,t[e+3]=c*_-l*h-x*d-y*u,t}get x(){return this._x}set x(t){this._x=t,this._onChangeCallback()}get y(){return this._y}set y(t){this._y=t,this._onChangeCallback()}get z(){return this._z}set z(t){this._z=t,this._onChangeCallback()}get w(){return this._w}set w(t){this._w=t,this._onChangeCallback()}set(t,e,s,o){return this._x=t,this._y=e,this._z=s,this._w=o,this._onChangeCallback(),this}clone(){return new this.constructor(this._x,this._y,this._z,this._w)}copy(t){return this._x=t.x,this._y=t.y,this._z=t.z,this._w=t.w,this._onChangeCallback(),this}setFromEuler(t,e){const s=t._x,o=t._y,r=t._z,a=t._order,l=Math.cos,x=Math.sin,y=l(s/2),c=l(o/2),h=l(r/2),d=x(s/2),u=x(o/2),_=x(r/2);switch(a){case"XYZ":this._x=d*c*h+y*u*_,this._y=y*u*h-d*c*_,this._z=y*c*_+d*u*h,this._w=y*c*h-d*u*_;break;case"YXZ":this._x=d*c*h+y*u*_,this._y=y*u*h-d*c*_,this._z=y*c*_-d*u*h,this._w=y*c*h+d*u*_;break;case"ZXY":this._x=d*c*h-y*u*_,this._y=y*u*h+d*c*_,this._z=y*c*_+d*u*h,this._w=y*c*h-d*u*_;break;case"ZYX":this._x=d*c*h-y*u*_,this._y=y*u*h+d*c*_,this._z=y*c*_-d*u*h,this._w=y*c*h+d*u*_;break;case"YZX":this._x=d*c*h+y*u*_,this._y=y*u*h+d*c*_,this._z=y*c*_-d*u*h,this._w=y*c*h-d*u*_;break;case"XZY":this._x=d*c*h-y*u*_,this._y=y*u*h-d*c*_,this._z=y*c*_+d*u*h,this._w=y*c*h+d*u*_;break;default:console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: "+a)}return e!==!1&&this._onChangeCallback(),this}setFromAxisAngle(t,e){const s=e/2,o=Math.sin(s);return this._x=t.x*o,this._y=t.y*o,this._z=t.z*o,this._w=Math.cos(s),this._onChangeCallback(),this}setFromRotationMatrix(t){const e=t.elements,s=e[0],o=e[4],r=e[8],a=e[1],l=e[5],x=e[9],y=e[2],c=e[6],h=e[10],d=s+l+h;if(d>0){const u=.5/Math.sqrt(d+1);this._w=.25/u,this._x=(c-x)*u,this._y=(r-y)*u,this._z=(a-o)*u}else if(s>l&&s>h){const u=2*Math.sqrt(1+s-l-h);this._w=(c-x)/u,this._x=.25*u,this._y=(o+a)/u,this._z=(r+y)/u}else if(l>h){const u=2*Math.sqrt(1+l-s-h);this._w=(r-y)/u,this._x=(o+a)/u,this._y=.25*u,this._z=(x+c)/u}else{const u=2*Math.sqrt(1+h-s-l);this._w=(a-o)/u,this._x=(r+y)/u,this._y=(x+c)/u,this._z=.25*u}return this._onChangeCallback(),this}setFromUnitVectors(t,e){let s=t.dot(e)+1;return s<Number.EPSILON?(s=0,Math.abs(t.x)>Math.abs(t.z)?(this._x=-t.y,this._y=t.x,this._z=0,this._w=s):(this._x=0,this._y=-t.z,this._z=t.y,this._w=s)):(this._x=t.y*e.z-t.z*e.y,this._y=t.z*e.x-t.x*e.z,this._z=t.x*e.y-t.y*e.x,this._w=s),this.normalize()}angleTo(t){return 2*Math.acos(Math.abs(V(this.dot(t),-1,1)))}rotateTowards(t,e){const s=this.angleTo(t);if(s===0)return this;const o=Math.min(1,e/s);return this.slerp(t,o),this}identity(){return this.set(0,0,0,1)}invert(){return this.conjugate()}conjugate(){return this._x*=-1,this._y*=-1,this._z*=-1,this._onChangeCallback(),this}dot(t){return this._x*t._x+this._y*t._y+this._z*t._z+this._w*t._w}lengthSq(){return this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w}length(){return Math.sqrt(this._x*this._x+this._y*this._y+this._z*this._z+this._w*this._w)}normalize(){let t=this.length();return t===0?(this._x=0,this._y=0,this._z=0,this._w=1):(t=1/t,this._x=this._x*t,this._y=this._y*t,this._z=this._z*t,this._w=this._w*t),this._onChangeCallback(),this}multiply(t){return this.multiplyQuaternions(this,t)}premultiply(t){return this.multiplyQuaternions(t,this)}multiplyQuaternions(t,e){const s=t._x,o=t._y,r=t._z,a=t._w,l=e._x,x=e._y,y=e._z,c=e._w;return this._x=s*c+a*l+o*y-r*x,this._y=o*c+a*x+r*l-s*y,this._z=r*c+a*y+s*x-o*l,this._w=a*c-s*l-o*x-r*y,this._onChangeCallback(),this}slerp(t,e){if(e===0)return this;if(e===1)return this.copy(t);const s=this._x,o=this._y,r=this._z,a=this._w;let l=a*t._w+s*t._x+o*t._y+r*t._z;if(l<0?(this._w=-t._w,this._x=-t._x,this._y=-t._y,this._z=-t._z,l=-l):this.copy(t),l>=1)return this._w=a,this._x=s,this._y=o,this._z=r,this;const x=1-l*l;if(x<=Number.EPSILON){const u=1-e;return this._w=u*a+e*this._w,this._x=u*s+e*this._x,this._y=u*o+e*this._y,this._z=u*r+e*this._z,this.normalize(),this._onChangeCallback(),this}const y=Math.sqrt(x),c=Math.atan2(y,l),h=Math.sin((1-e)*c)/y,d=Math.sin(e*c)/y;return this._w=a*h+this._w*d,this._x=s*h+this._x*d,this._y=o*h+this._y*d,this._z=r*h+this._z*d,this._onChangeCallback(),this}slerpQuaternions(t,e,s){return this.copy(t).slerp(e,s)}random(){const t=Math.random(),e=Math.sqrt(1-t),s=Math.sqrt(t),o=2*Math.PI*Math.random(),r=2*Math.PI*Math.random();return this.set(e*Math.cos(o),s*Math.sin(r),s*Math.cos(r),e*Math.sin(o))}equals(t){return t._x===this._x&&t._y===this._y&&t._z===this._z&&t._w===this._w}fromArray(t,e=0){return this._x=t[e],this._y=t[e+1],this._z=t[e+2],this._w=t[e+3],this._onChangeCallback(),this}toArray(t=[],e=0){return t[e]=this._x,t[e+1]=this._y,t[e+2]=this._z,t[e+3]=this._w,t}fromBufferAttribute(t,e){return this._x=t.getX(e),this._y=t.getY(e),this._z=t.getZ(e),this._w=t.getW(e),this}toJSON(){return this.toArray()}_onChange(t){return this._onChangeCallback=t,this}_onChangeCallback(){}*[Symbol.iterator](){yield this._x,yield this._y,yield this._z,yield this._w}}class b{constructor(t=0,e=0,s=0){b.prototype.isVector3=!0,this.x=t,this.y=e,this.z=s}set(t,e,s){return s===void 0&&(s=this.z),this.x=t,this.y=e,this.z=s,this}setScalar(t){return this.x=t,this.y=t,this.z=t,this}setX(t){return this.x=t,this}setY(t){return this.y=t,this}setZ(t){return this.z=t,this}setComponent(t,e){switch(t){case 0:this.x=e;break;case 1:this.y=e;break;case 2:this.z=e;break;default:throw new Error("index is out of range: "+t)}return this}getComponent(t){switch(t){case 0:return this.x;case 1:return this.y;case 2:return this.z;default:throw new Error("index is out of range: "+t)}}clone(){return new this.constructor(this.x,this.y,this.z)}copy(t){return this.x=t.x,this.y=t.y,this.z=t.z,this}add(t){return this.x+=t.x,this.y+=t.y,this.z+=t.z,this}addScalar(t){return this.x+=t,this.y+=t,this.z+=t,this}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this}addScaledVector(t,e){return this.x+=t.x*e,this.y+=t.y*e,this.z+=t.z*e,this}sub(t){return this.x-=t.x,this.y-=t.y,this.z-=t.z,this}subScalar(t){return this.x-=t,this.y-=t,this.z-=t,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this}multiply(t){return this.x*=t.x,this.y*=t.y,this.z*=t.z,this}multiplyScalar(t){return this.x*=t,this.y*=t,this.z*=t,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this.z=t.z*e.z,this}applyEuler(t){return this.applyQuaternion(L.setFromEuler(t))}applyAxisAngle(t,e){return this.applyQuaternion(L.setFromAxisAngle(t,e))}applyMatrix3(t){const e=this.x,s=this.y,o=this.z,r=t.elements;return this.x=r[0]*e+r[3]*s+r[6]*o,this.y=r[1]*e+r[4]*s+r[7]*o,this.z=r[2]*e+r[5]*s+r[8]*o,this}applyNormalMatrix(t){return this.applyMatrix3(t).normalize()}applyMatrix4(t){const e=this.x,s=this.y,o=this.z,r=t.elements,a=1/(r[3]*e+r[7]*s+r[11]*o+r[15]);return this.x=(r[0]*e+r[4]*s+r[8]*o+r[12])*a,this.y=(r[1]*e+r[5]*s+r[9]*o+r[13])*a,this.z=(r[2]*e+r[6]*s+r[10]*o+r[14])*a,this}applyQuaternion(t){const e=this.x,s=this.y,o=this.z,r=t.x,a=t.y,l=t.z,x=t.w,y=x*e+a*o-l*s,c=x*s+l*e-r*o,h=x*o+r*s-a*e,d=-r*e-a*s-l*o;return this.x=y*x+d*-r+c*-l-h*-a,this.y=c*x+d*-a+h*-r-y*-l,this.z=h*x+d*-l+y*-a-c*-r,this}project(t){return this.applyMatrix4(t.matrixWorldInverse).applyMatrix4(t.projectionMatrix)}unproject(t){return this.applyMatrix4(t.projectionMatrixInverse).applyMatrix4(t.matrixWorld)}transformDirection(t){const e=this.x,s=this.y,o=this.z,r=t.elements;return this.x=r[0]*e+r[4]*s+r[8]*o,this.y=r[1]*e+r[5]*s+r[9]*o,this.z=r[2]*e+r[6]*s+r[10]*o,this.normalize()}divide(t){return this.x/=t.x,this.y/=t.y,this.z/=t.z,this}divideScalar(t){return this.multiplyScalar(1/t)}min(t){return this.x=Math.min(this.x,t.x),this.y=Math.min(this.y,t.y),this.z=Math.min(this.z,t.z),this}max(t){return this.x=Math.max(this.x,t.x),this.y=Math.max(this.y,t.y),this.z=Math.max(this.z,t.z),this}clamp(t,e){return this.x=Math.max(t.x,Math.min(e.x,this.x)),this.y=Math.max(t.y,Math.min(e.y,this.y)),this.z=Math.max(t.z,Math.min(e.z,this.z)),this}clampScalar(t,e){return this.x=Math.max(t,Math.min(e,this.x)),this.y=Math.max(t,Math.min(e,this.y)),this.z=Math.max(t,Math.min(e,this.z)),this}clampLength(t,e){const s=this.length();return this.divideScalar(s||1).multiplyScalar(Math.max(t,Math.min(e,s)))}floor(){return this.x=Math.floor(this.x),this.y=Math.floor(this.y),this.z=Math.floor(this.z),this}ceil(){return this.x=Math.ceil(this.x),this.y=Math.ceil(this.y),this.z=Math.ceil(this.z),this}round(){return this.x=Math.round(this.x),this.y=Math.round(this.y),this.z=Math.round(this.z),this}roundToZero(){return this.x=this.x<0?Math.ceil(this.x):Math.floor(this.x),this.y=this.y<0?Math.ceil(this.y):Math.floor(this.y),this.z=this.z<0?Math.ceil(this.z):Math.floor(this.z),this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}dot(t){return this.x*t.x+this.y*t.y+this.z*t.z}lengthSq(){return this.x*this.x+this.y*this.y+this.z*this.z}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}manhattanLength(){return Math.abs(this.x)+Math.abs(this.y)+Math.abs(this.z)}normalize(){return this.divideScalar(this.length()||1)}setLength(t){return this.normalize().multiplyScalar(t)}lerp(t,e){return this.x+=(t.x-this.x)*e,this.y+=(t.y-this.y)*e,this.z+=(t.z-this.z)*e,this}lerpVectors(t,e,s){return this.x=t.x+(e.x-t.x)*s,this.y=t.y+(e.y-t.y)*s,this.z=t.z+(e.z-t.z)*s,this}cross(t){return this.crossVectors(this,t)}crossVectors(t,e){const s=t.x,o=t.y,r=t.z,a=e.x,l=e.y,x=e.z;return this.x=o*x-r*l,this.y=r*a-s*x,this.z=s*l-o*a,this}projectOnVector(t){const e=t.lengthSq();if(e===0)return this.set(0,0,0);const s=t.dot(this)/e;return this.copy(t).multiplyScalar(s)}projectOnPlane(t){return N.copy(this).projectOnVector(t),this.sub(N)}reflect(t){return this.sub(N.copy(t).multiplyScalar(2*this.dot(t)))}angleTo(t){const e=Math.sqrt(this.lengthSq()*t.lengthSq());if(e===0)return Math.PI/2;const s=this.dot(t)/e;return Math.acos(V(s,-1,1))}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,s=this.y-t.y,o=this.z-t.z;return e*e+s*s+o*o}manhattanDistanceTo(t){return Math.abs(this.x-t.x)+Math.abs(this.y-t.y)+Math.abs(this.z-t.z)}setFromSpherical(t){return this.setFromSphericalCoords(t.radius,t.phi,t.theta)}setFromSphericalCoords(t,e,s){const o=Math.sin(e)*t;return this.x=o*Math.sin(s),this.y=Math.cos(e)*t,this.z=o*Math.cos(s),this}setFromCylindrical(t){return this.setFromCylindricalCoords(t.radius,t.theta,t.y)}setFromCylindricalCoords(t,e,s){return this.x=t*Math.sin(e),this.y=s,this.z=t*Math.cos(e),this}setFromMatrixPosition(t){const e=t.elements;return this.x=e[12],this.y=e[13],this.z=e[14],this}setFromMatrixScale(t){const e=this.setFromMatrixColumn(t,0).length(),s=this.setFromMatrixColumn(t,1).length(),o=this.setFromMatrixColumn(t,2).length();return this.x=e,this.y=s,this.z=o,this}setFromMatrixColumn(t,e){return this.fromArray(t.elements,e*4)}setFromMatrix3Column(t,e){return this.fromArray(t.elements,e*3)}setFromEuler(t){return this.x=t._x,this.y=t._y,this.z=t._z,this}setFromColor(t){return this.x=t.r,this.y=t.g,this.z=t.b,this}equals(t){return t.x===this.x&&t.y===this.y&&t.z===this.z}fromArray(t,e=0){return this.x=t[e],this.y=t[e+1],this.z=t[e+2],this}toArray(t=[],e=0){return t[e]=this.x,t[e+1]=this.y,t[e+2]=this.z,t}fromBufferAttribute(t,e){return this.x=t.getX(e),this.y=t.getY(e),this.z=t.getZ(e),this}random(){return this.x=Math.random(),this.y=Math.random(),this.z=Math.random(),this}randomDirection(){const t=(Math.random()-.5)*2,e=Math.random()*Math.PI*2,s=Math.sqrt(1-t**2);return this.x=s*Math.cos(e),this.y=s*Math.sin(e),this.z=t,this}*[Symbol.iterator](){yield this.x,yield this.y,yield this.z}}const N=new b,L=new ht;typeof __THREE_DEVTOOLS__<"u"&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register",{detail:{revision:P}})),typeof window<"u"&&(window.__THREE__?console.warn("WARNING: Multiple instances of Three.js being imported."):window.__THREE__=P);const lt={class:"flex justify-between gap-4 items-center mb-2"},at={class:"text-gray-500 w-1/3"},ct=["value","min","max","step"],ut=n.defineComponent({__name:"NumberControl",props:{label:null,control:null},emits:["change"],setup(i,{emit:t}){const e=i;function s(c){const{target:h}=c;t("change",h.valueAsNumber)}const o=w.useMouse(),r=n.ref(0),a=n.ref(!1),l=c=>{r.value=c.clientX,a.value=!0},x=()=>{a.value=!1},y=c=>Math.floor(Math.abs(c)/10);return n.watch(o.x,c=>{if(a.value){const h=c-r.value,d=y(h);h>0?t("change",e.control.value+1+d):h<0&&t("change",e.control.value-1+d),e.control.min!==void 0&&e.control.value<e.control.min&&t("change",e.control.min),e.control.max!==void 0&&e.control.value>e.control.max&&t("change",e.control.max),r.value=c}}),(c,h)=>(n.openBlock(),n.createElementBlock("div",lt,[n.createElementVNode("label",at,n.toDisplayString(i.label),1),n.createElementVNode("input",{value:i.control.value,class:n.normalizeClass(["p-2 w-1/3 rounded text-right text-xs text-gray-400 bg-gray-100 focus:border-gray-200 outline-none border-none font-sans",{"cursor-ew-resize":a.value}]),type:"number",min:i.control.min,max:i.control.max,step:i.control.step,onInput:s,onMousedown:l,onMouseup:x},null,42,ct)]))}}),yt={class:"flex justify-between gap-4 items-center mb-2 min-h-32px"},xt={class:"text-gray-500 w-1/3"},dt=["value"],_t=n.defineComponent({__name:"TextControl",props:{label:null,control:null},emits:["change"],setup(i,{emit:t}){function e(s){t("change",s)}return(s,o)=>(n.openBlock(),n.createElementBlock("div",yt,[n.createElementVNode("label",xt,n.toDisplayString(i.label),1),n.createElementVNode("input",{value:i.control.value,type:"string",class:"p-2 w-2/3 rounded text-right text-xs text-gray-400 bg-gray-100 focus:border-gray-200 outline-none border-none font-sans",onChange:e},null,40,dt)]))}}),mt={class:"flex justify-start gap-2 items-center mb-2 min-h-32px"},ft={class:"text-gray-500 w-1/3"},pt=["id","checked"],gt=["for"],zt={class:"i-ic:baseline-check text-light"},Mt=n.defineComponent({__name:"BooleanControl",props:{label:null,control:null},emits:["change"],setup(i,{emit:t}){function e(s){const{target:o}=s;t("change",o.checked)}return(s,o)=>(n.openBlock(),n.createElementBlock("div",mt,[n.createElementVNode("label",ft,n.toDisplayString(i.label),1),n.createElementVNode("input",{id:i.control.label,checked:i.control.value,class:"hidden",type:"checkbox",onInput:e},null,40,pt),n.createElementVNode("label",{for:i.control.label,class:"inline-flex items-center cursor-pointer"},[n.createElementVNode("span",{class:n.normalizeClass([{"bg-dark-500":i.control.value,"bg-gray-200":!i.control.value},"w-4 h-4 flex justify-center items-center rounded border border-gray-300 mr-2 transition-colors duration-200"])},[n.withDirectives(n.createElementVNode("i",zt,null,512),[[n.vShow,i.control.value]])],2)],8,gt)]))}}),wt={class:"relative flex justify-between gap-4 items-center mb-2"},bt={class:"text-gray-500 w-1/3"},Ct=["value","min","max","step"],kt=["value","min","max","step"],St=n.defineComponent({__name:"SliderControl",props:{label:null,control:null},emits:["change"],setup(i,{emit:t}){const e=i;function s(h){const{target:d}=h;t("change",d.valueAsNumber)}const o=n.computed(()=>({backgroundImage:`linear-gradient(to right, #333 0% ${100*(e.control.value-(e.control.min||0))/((e.control.max||100)-(e.control.min||0))}%, #e2e2e2 0%)`})),r=w.useMouse(),a=n.ref(0),l=n.ref(!1),x=h=>{a.value=h.clientX,l.value=!0},y=()=>{l.value=!1},c=h=>Math.floor(Math.abs(h)/10);return n.watch(r.x,h=>{if(l.value){const d=h-a.value,u=c(d);d>0?t("change",e.control.value+1+u):d<0&&t("change",e.control.value-1+u),e.control.min!==void 0&&e.control.value<e.control.min&&t("change",e.control.min),e.control.max!==void 0&&e.control.value>e.control.max&&t("change",e.control.max),a.value=h}}),(h,d)=>(n.openBlock(),n.createElementBlock("div",wt,[n.createElementVNode("label",bt,n.toDisplayString(i.label),1),n.createElementVNode("input",{value:i.control.value,class:"w-1/2 h-0.75 bg-dark-200 rounded-full appearance-none",style:n.normalizeStyle(n.unref(o)),type:"range",min:i.control.min,max:i.control.max,step:i.control.step,onInput:s},null,44,Ct),n.createElementVNode("input",{value:i.control.value,class:n.normalizeClass(["p-2 w-1/4 rounded text-right text-xs text-gray-400 bg-gray-100 focus:border-gray-200 outline-none border-none font-sans",{"cursor-ew-resize":l.value}]),type:"number",min:i.control.min,max:i.control.max,step:i.control.step,onInput:s,onMousedown:x,onMouseup:y},null,42,kt)]))}}),Zt="",Et=((i,t)=>{const e=i.__vccOpts||i;for(const[s,o]of t)e[s]=o;return e})(St,[["__scopeId","data-v-546d47fc"]]),Vt={class:"flex justify-between gap-4 items-center mb-2"},Nt={class:"text-gray-500 w-1/3"},Bt=["value"],$t=["value"],Tt=n.defineComponent({__name:"ColorControl",props:{label:null,control:null},emits:["change"],setup(i,{emit:t}){function e(s){const{target:o}=s;t("change",o.value)}return(s,o)=>(n.openBlock(),n.createElementBlock("div",Vt,[n.createElementVNode("label",Nt,n.toDisplayString(i.label),1),n.createElementVNode("input",{value:i.control.value,type:"color",onInput:e},null,40,Bt),n.createElementVNode("input",{value:i.control.value,class:"p-2 w-2/3 rounded text-right text-xs text-gray-400 bg-gray-100 focus:border-gray-200 outline-none border-none font-sans",type:"text",onInput:e},null,40,$t)]))}}),Ut="";function At(i){return typeof i=="number"?[i,i,i]:i instanceof b?[i.x,i.y,i.z]:i}const It={class:"flex justify-between gap-2 items-center mb-2"},Dt={class:"text-gray-500 w-1/3"},qt={class:"w-2/3 flex justify-between gap-1"},jt={key:0,class:"font-bold px-0.5 py-1 text-0.65rem text-gray-300"},Pt=["value","onInput","onMousedown","onMouseup"],Lt=n.defineComponent({__name:"VectorControl",props:{label:null,control:null},emits:["change"],setup(i,{emit:t}){const e=i,s=w.useMouse(),o=n.ref(0),r=n.ref(!1),a=n.ref(0),l=(_,f)=>{a.value=f,o.value=_.clientX,r.value=!0},x=(_,f)=>{a.value=f,r.value=!1},y=_=>Math.floor(Math.abs(_)/10),c=n.computed(()=>At(e.control.value)),h=n.computed(()=>Object.keys(e.control.value)),d=n.computed(()=>e.control.value instanceof k||e.control.value instanceof b);function u(_,f){const{value:p}=e.control,{target:m}=_;a.value=f,p[d.value?h.value[a.value]:a.value]=parseInt(m.value,10),t("change",p)}return n.watch(s.x,_=>{if(r.value){const f=_-o.value,p=y(f),{value:m}=e.control,g=d.value?h.value[a.value]:a.value;f>0?m[g]+=1+p:f<0&&(m[g]-=1+p),e.control.min!==void 0&&m<e.control.min&&(m[g]=e.control.min),e.control.max!==void 0&&m>e.control.max&&(m[g]=e.control.max),t("change",m),o.value=_}}),(_,f)=>(n.openBlock(),n.createElementBlock("div",It,[n.createElementVNode("label",Dt,n.toDisplayString(i.label),1),n.createElementVNode("div",qt,[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(c),(p,m)=>(n.openBlock(),n.createElementBlock("div",{key:i.label+m,class:"flex items-center w-1/3 bg-gray-100 rounded"},[n.unref(h)[m]&&n.unref(d)?(n.openBlock(),n.createElementBlock("span",jt,n.toDisplayString(n.unref(h)[m]),1)):n.createCommentVNode("",!0),n.createElementVNode("input",{type:"text",class:n.normalizeClass(["w-full pl-0 p-1 text-right text-0.65rem text-gray-400 bg-transparent focus:border-gray-200 outline-none border-none font-sans",{"cursor-ew-resize":r.value}]),value:n.unref(c)[m].toFixed(2),onInput:g=>u(g,m),onMousedown:g=>l(g,m),onMouseup:g=>x(g,m)},null,42,Pt)]))),128))])]))}}),Xt=n.defineComponent({__name:"ControlInput",props:{control:null},emits:["change"],setup(i,{emit:t}){const e=i,s=n.computed(()=>e.control.type==="number"&&(e.control.step||e.control.max||e.control.min)),o=n.computed(()=>{const l=/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$|^0x([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/;return e.control.type==="color"||l.test(e.control.value)}),r=n.computed(()=>e.control.value instanceof Array||e.control.value instanceof k||e.control.value instanceof b);function a(l){t("change",l)}return(l,x)=>i.control.visible?(n.openBlock(),n.createElementBlock(n.Fragment,{key:0},[n.unref(o)?(n.openBlock(),n.createBlock(Tt,{key:0,label:i.control.label,control:i.control,onChange:a},null,8,["label","control"])):n.unref(r)?(n.openBlock(),n.createBlock(Lt,{key:1,label:i.control.label,control:i.control,onChange:a},null,8,["label","control"])):i.control.type==="boolean"?(n.openBlock(),n.createBlock(Mt,{key:2,label:i.control.label,control:i.control,onChange:a},null,8,["label","control"])):n.unref(s)?n.unref(s)?(n.openBlock(),n.createBlock(Et,{key:4,label:i.control.label,control:i.control,onChange:a},null,8,["label","control"])):(n.openBlock(),n.createBlock(_t,{key:5,label:i.control.label,control:i.control,onChange:a},null,8,["label","control"])):(n.openBlock(),n.createBlock(ut,{key:3,label:i.control.label,control:i.control,onChange:a},null,8,["label","control"]))],64)):n.createCommentVNode("",!0)}}),Ft={class:"bg-white shadow-xl rounded border-4 border-solid border-black"},Rt=[n.createElementVNode("i",{class:"h-4 w-4 p-1.5 flex items-center line-height-0 rounded-full bg-gray-100 text-xs"},"🍰",-1),n.createElementVNode("div",null,[n.createElementVNode("i",{class:"i-ic-baseline-drag-indicator"}),n.createElementVNode("i",{class:"i-ic-baseline-drag-indicator"}),n.createElementVNode("i",{class:"i-ic-baseline-drag-indicator"})],-1),n.createElementVNode("div",null,null,-1)],Yt={class:"p-4"},Ot=n.defineComponent({__name:"TresLeches",setup(i){const{width:t}=w.useWindowSize(),e=280,s=n.ref(null),o=ot();function r(a,l){l.value=a}return(a,l)=>(n.openBlock(),n.createBlock(n.unref(tt),{"initial-value":{x:n.unref(t)-e-20,y:10},class:"fixed select-none z-24 w-280px font-sans text-xs",handle:s.value},{default:n.withCtx(()=>[n.createElementVNode("div",Ft,[n.createElementVNode("header",{ref_key:"handle",ref:s,class:"relative cursor-grabbing p-4 flex justify-between text-gray-200 relative"},Rt,512),n.createElementVNode("div",Yt,[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(n.unref(o).controls,x=>(n.openBlock(),n.createBlock(Xt,{key:x.label,control:x,onChange:y=>r(y,x)},null,8,["control","onChange"]))),128))])])]),_:1},8,["initial-value","handle"]))}});z.TresLeches=Ot,z.useControls=rt,Object.defineProperty(z,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ export * from './normalize';
@@ -0,0 +1,17 @@
1
+ import { Vector3, Color, ColorRepresentation } from 'three';
2
+ export type SizeFlexibleParams = number[] | {
3
+ width: number;
4
+ height: number;
5
+ };
6
+ export interface Vector2PropInterface {
7
+ x?: number;
8
+ y?: number;
9
+ width?: number;
10
+ height?: number;
11
+ }
12
+ export interface Vector3PropInterface extends Vector2PropInterface {
13
+ z?: number;
14
+ }
15
+ export type VectorFlexibleParams = Vector3 | number[] | Vector3PropInterface | number;
16
+ export declare function normalizeVectorFlexibleParam(value: VectorFlexibleParams): Array<number>;
17
+ export declare function normalizeColor(value: Color | Array<number> | string | number | ColorRepresentation): Color;
package/dist/vite.svg ADDED
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@tresjs/leches",
3
+ "description": "Tasty GUI for Vue controls 🍰",
4
+ "version": "0.1.0",
5
+ "type": "module",
6
+ "author": "Alvaro Saburido <hola@alvarosaburido.dev> (https://github.com/alvarosabu/)",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "license": "MIT",
11
+ "main": "./dist/tresleches.umd.cjs",
12
+ "module": "./dist/tresleches.js",
13
+ "types": "./dist/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/tresleches.js",
17
+ "require": "./dist/tresleches.umd.cjs"
18
+ },
19
+ "./styles": "./dist/style.css",
20
+ "./*": "./dist/tresleches.js"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "keywords": [
26
+ "vue",
27
+ "gui",
28
+ "pane",
29
+ "controls"
30
+ ],
31
+ "scripts": {
32
+ "dev": "vite",
33
+ "build": "vue-tsc && vite build",
34
+ "preview": "vite preview",
35
+ "playground": "cd playground && npm run dev",
36
+ "test": "vitest",
37
+ "test:ci": "vitest run",
38
+ "test:ui": "vitest --ui",
39
+ "release": "release-it",
40
+ "coverage": "vitest run --coverage",
41
+ "lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue",
42
+ "story:dev": "histoire dev",
43
+ "story:build": "histoire build",
44
+ "story:preview": "histoire preview"
45
+ },
46
+ "dependencies": {
47
+ "@types/three": "^0.151.0",
48
+ "@vueuse/components": "^10.1.0",
49
+ "@vueuse/shared": "^10.1.0",
50
+ "kolorist": "^1.8.0",
51
+ "pathe": "^1.1.0",
52
+ "rollup-plugin-analyzer": "^4.0.0",
53
+ "rollup-plugin-visualizer": "^5.9.0",
54
+ "three": "^0.152.2",
55
+ "vite-plugin-banner": "^0.7.0",
56
+ "vite-plugin-dts": "^2.3.0",
57
+ "vue": "^3.2.47"
58
+ },
59
+ "devDependencies": {
60
+ "@alvarosabu/prettier-config": "^1.3.0",
61
+ "@histoire/plugin-vue": "^0.16.1",
62
+ "@iconify-json/ic": "^1.1.13",
63
+ "@release-it/conventional-changelog": "^5.1.1",
64
+ "@typescript-eslint/eslint-plugin": "^5.59.1",
65
+ "@vitejs/plugin-vue": "^4.2.1",
66
+ "@vitest/ui": "^0.30.1",
67
+ "@vueuse/core": "^10.1.0",
68
+ "eslint": "^8.39.0",
69
+ "eslint-config-prettier": "^8.8.0",
70
+ "eslint-plugin-vue": "^9.11.0",
71
+ "histoire": "^0.16.1",
72
+ "prettier": "^2.8.8",
73
+ "release-it": "^15.10.1",
74
+ "typescript": "^5.0.4",
75
+ "unocss": "^0.51.8",
76
+ "vite": "^4.3.3",
77
+ "vitest": "^0.30.1",
78
+ "vue-tsc": "^1.6.0"
79
+ }
80
+ }