tgui-core 6.0.0 → 6.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.
- package/dist/common/css.d.ts +11 -0
- package/dist/common/css.js +1 -0
- package/dist/common/math.js +1 -1
- package/dist/common/timer.d.ts +1 -5
- package/dist/common/timer.js +1 -1
- package/dist/common/ui.js +1 -1
- package/dist/components/Input.js +1 -1
- package/dist/components/RestrictedInput.js +1 -1
- package/dist/components/TextArea.js +1 -1
- package/package.json +1 -1
- package/styles/components/ProgressBar.scss +2 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the value of a CSS variable from the document's root element and caches it.
|
|
3
|
+
* Returns empty string if the variable is not defined or has an empty value.
|
|
4
|
+
*/
|
|
5
|
+
export declare function getCssVariableValue(variableName: string): string;
|
|
6
|
+
/**
|
|
7
|
+
* Cleans up calculated with `getCssVariableValue` cache
|
|
8
|
+
* Use it only if there is too many variables changed
|
|
9
|
+
* For example, on theme changing
|
|
10
|
+
*/
|
|
11
|
+
export declare function clearCssVariableValueCache(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e={};function t(t){if(t in e)return e[t];let r=getComputedStyle(document.documentElement).getPropertyValue(`--${t}`).trim();return e[t]=r,r||""}function r(){e={}}export{r as clearCssVariableValueCache,t as getCssVariableValue};
|
package/dist/common/math.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
import{getCssVariableValue as n}from"./css.js";function e(n,e,t){return n<e?e:n>t?t:n}function t(n){return n<0?0:n>1?1:n}function r(n,e=0,t=100){return(n-e)/(t-e)}function u(n,e){return Number.parseFloat((Math.round(n*10**e+1e-4*(n>=0?1:-1))/10**e).toFixed(e))}function o(n,e=0){return Number(n).toFixed(Math.max(e,0))}function i(n,e){return e&&n>=e[0]&&n<=e[1]}function f(n,e){for(let t of Object.keys(e))if(i(n,e[t]))return t}function a(n){return Math.floor(n)!==n&&n.toString().split(".")[1].length||0}function c(n){return"number"==typeof n&&Number.isFinite(n)&&!Number.isNaN(n)}function m(n){return 180/Math.PI*n}function s(e,t){let r=Math.round(e/(Number.parseFloat(n("font-size"))||12)*1e6)/1e6;return"number"===t?r:`${r}rem`}export{e as clamp,t as clamp01,i as inRange,c as isSafeNumber,f as keyOfMatchingRange,a as numberOfDecimalDigits,s as pxToRem,m as rad2deg,u as round,r as scale,o as toFixed};
|
package/dist/common/timer.d.ts
CHANGED
|
@@ -16,8 +16,4 @@ export declare function throttle<F extends (...args: any[]) => any>(fn: F, time:
|
|
|
16
16
|
* @param {number} time
|
|
17
17
|
*/
|
|
18
18
|
export declare function sleep(time: number): Promise<void>;
|
|
19
|
-
|
|
20
|
-
* Prevent input parent change event from being called too often
|
|
21
|
-
* @param dTime Debounce time, default is 250
|
|
22
|
-
*/
|
|
23
|
-
export declare function inputDebounce(dTime?: number): (onChange: () => void) => void;
|
|
19
|
+
export declare function inputDebounce(id: string, dTime?: number): (onChange: () => void) => void;
|
package/dist/common/timer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(t,n,u=!1){let o;return(...e)=>{let i=u&&!o;clearTimeout(o),o=setTimeout(function(){o=null,u||t(...e)},n),i&&t(...e)}}function t(e,t){let n,u;return function o(...i){let r=Date.now();u&&clearTimeout(u),!n||r-n>=t?(e(...i),n=r):u=setTimeout(()=>o(...i),t-(r-(n??0)))}}function n(e){return new Promise(t=>setTimeout(t,e))}function
|
|
1
|
+
function e(t,n,u=!1){let o;return(...e)=>{let i=u&&!o;clearTimeout(o),o=setTimeout(function(){o=null,u||t(...e)},n),i&&t(...e)}}function t(e,t){let n,u;return function o(...i){let r=Date.now();u&&clearTimeout(u),!n||r-n>=t?(e(...i),n=r):u=setTimeout(()=>o(...i),t-(r-(n??0)))}}function n(e){return new Promise(t=>setTimeout(t,e))}let u=new Map;function o(t,n=250){let i=u.get(t);return i||(i=e(e=>e(),n),u.set(t,i)),i}export{e as debounce,o as inputDebounce,n as sleep,t as throttle};
|
package/dist/common/ui.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CSS_COLORS as t}from"./constants.js";import{
|
|
1
|
+
import{CSS_COLORS as t}from"./constants.js";import{getCssVariableValue as o}from"./css.js";import{classes as e}from"./react.js";let n=t=>{let e=Number.parseFloat(o("font-size"))||12;return"string"==typeof t?t.endsWith("px")?`${Number.parseFloat(t)/e}rem`:t:"number"==typeof t?`${t}rem`:void 0},i=t=>"string"==typeof t?n(t):"number"==typeof t?n(.5*t):void 0;function r(o){return"string"==typeof o&&t.includes(o)}let l=t=>(o,e)=>{("number"==typeof e||"string"==typeof e)&&(o[t]=e)},p=(t,o)=>(e,n)=>{("number"==typeof n||"string"==typeof n)&&(e[t]=o(n))},a=(t,o)=>(e,n)=>{n&&(e[t]=o)},g=(t,o,e)=>(n,i)=>{if("number"==typeof i||"string"==typeof i)for(let r=0;r<e.length;r++)n[t+e[r]]=o(i)},m=t=>(o,e)=>{r(e)||(o[t]=e)},f={align:l("textAlign"),backgroundColor:m("backgroundColor"),bottom:p("bottom",n),color:m("color"),fontFamily:l("fontFamily"),fontSize:p("fontSize",n),fontWeight:l("fontWeight"),g:p("gap",i),gc:p("columnGap",i),gr:p("rowGap",i),height:p("height",n),left:p("left",n),lineHeight:(t,o)=>{"number"==typeof o?t.lineHeight=o:"string"==typeof o&&(t.lineHeight=n(o))},m:g("margin",i,["Top","Bottom","Left","Right"]),maxHeight:p("maxHeight",n),maxWidth:p("maxWidth",n),mb:p("marginBottom",i),minHeight:p("minHeight",n),minWidth:p("minWidth",n),ml:p("marginLeft",i),mr:p("marginRight",i),mt:p("marginTop",i),mx:g("margin",i,["Left","Right"]),my:g("margin",i,["Top","Bottom"]),opacity:l("opacity"),overflow:l("overflow"),overflowX:l("overflowX"),overflowY:l("overflowY"),p:g("padding",i,["Top","Bottom","Left","Right"]),pb:p("paddingBottom",i),pl:p("paddingLeft",i),position:l("position"),pr:p("paddingRight",i),pt:p("paddingTop",i),px:g("padding",i,["Left","Right"]),py:g("padding",i,["Top","Bottom"]),right:p("right",n),textAlign:l("textAlign"),textColor:m("color"),top:p("top",n),verticalAlign:l("verticalAlign"),width:p("width",n)},s={bold:a("fontWeight","bold"),fillPositionedParent:(t,o)=>{o&&(t.position="absolute",t.top=0,t.bottom=0,t.left=0,t.right=0)},inline:a("display","inline-block"),italic:a("fontStyle","italic"),nowrap:a("whiteSpace","nowrap"),preserveWhitespace:a("whiteSpace","pre-wrap")};function u(t){let o={},e={};for(let n in t){if("style"===n)continue;let i=t[n],r=f[n]||s[n];r?r(e,i):o[n]=i}return o.style={...e,...t.style},o}function c(t){let o=t.textColor||t.color,{backgroundColor:n}=t;return e([r(o)&&`color-${o}`,r(n)&&`color-bg-${n}`])}function h(t){let o={};if(!t)return o;for(let e of t.split(" ")){let[t,n]=e.split("-");if(t)if(t in f){if(""===n)continue;let e=Number(n);!Number.isNaN(e)&&Number.isFinite(e)?o[t]=e:o[t]=n}else t in s?o[t]=!0:console.warn(`Unknown prop ${t}`)}return o}let d=["onClick","onAuxClick","onContextMenu","onDoubleClick","onKeyDown","onKeyUp","onMouseDown","onMouseEnter","onMouseLeave","onMouseMove","onMouseOver","onMouseUp","onScroll","onWheel","onDrag","onDragEnd","onDragEnter","onDragExit","onDragLeave","onDragOver","onDragStart","onDrop"];export{s as booleanStyleMap,c as computeBoxClassName,u as computeBoxProps,h as computeTwClass,d as eventHandlers,i as halfUnit,f as stringStyleMap,n as unit};
|
package/dist/components/Input.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{KEY as t,isEscape as r}from"../common/keys.js";import{classes as n}from"../common/react.js";import{inputDebounce as u}from"../common/timer.js";import{computeBoxClassName as o,computeBoxProps as m}from"../common/ui.js";import{useEffect as c,
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{KEY as t,isEscape as r}from"../common/keys.js";import{classes as n}from"../common/react.js";import{inputDebounce as u}from"../common/timer.js";import{computeBoxClassName as o,computeBoxProps as m}from"../common/ui.js";import{useEffect as c,useId as l,useRef as a,useState as p}from"react";function i(i){let{autoFocus:f,autoSelect:s,className:d,disabled:g,expensive:v,fluid:T,maxLength:y,monospace:b,onBlur:j,onChange:I,onEnter:h,onEscape:k,onKeyDown:x,placeholder:C,ref:D,selfClear:E,alwaysUpdate:w,spellcheck:B=!1,value:K,...L}=i,N=a(null),q=D??N,[z,A]=p(K??""),F=l();c(()=>{let e;return(f||s)&&(e=setTimeout(()=>{q.current?.focus(),s&&q.current?.select()},1)),()=>clearTimeout(e)},[]),c(()=>{(q.current&&document.activeElement!==q.current&&K!==z||w)&&A(K??"")},[K]);let G=m(L),H=n(["Input",g&&"Input--disabled",T&&"Input--fluid",b&&"Input--monospace",o(L),d]);return e("input",{...G,autoComplete:"off",className:H,disabled:g,maxLength:y,onBlur:()=>j?.(z),onChange:function(e){let t=e.currentTarget.value;A(t),v?u(F,"number"==typeof v?v:250)(()=>I?.(t,e)):I?.(t,e)},onKeyDown:function(e){if(x?.(e),e.key===t.Enter){e.preventDefault(),h?.(e.currentTarget.value,e),E&&A(""),e.currentTarget.blur();return}r(e.key)&&(e.preventDefault(),k?.(e.currentTarget.value,e),e.currentTarget.blur())},placeholder:C,ref:q,spellCheck:B,type:"text",value:z})}export{i as Input};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{KEY as t,isEscape as r}from"../common/keys.js";import{classes as n}from"../common/react.js";import{inputDebounce as u}from"../common/timer.js";import{computeBoxClassName as o,computeBoxProps as i}from"../common/ui.js";import{useEffect as m,
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{KEY as t,isEscape as r}from"../common/keys.js";import{classes as n}from"../common/react.js";import{inputDebounce as u}from"../common/timer.js";import{computeBoxClassName as o,computeBoxProps as i}from"../common/ui.js";import{useEffect as m,useId as c,useRef as l,useState as f}from"react";function p(p){let{allowFloats:a,autoFocus:s,autoSelect:d,className:v,disabled:y,expensive:b,fluid:I,maxValue:j=1e4,minValue:k=0,monospace:D,onBlur:x,onChange:C,onEnter:R,onEscape:g,onKeyDown:h,onValidationChange:E,value:N,...T}=p,w=l(null),[B,K]=f(N??k),[M,q]=f(!0),z=c();function A(e,t){C&&(b?u(z,"number"==typeof b?b:250)(()=>C?.(e,t)):C(e,t))}m(()=>{let e;return(s||d)&&(e=setTimeout(()=>{w.current?.focus(),d&&w.current?.select()},1)),()=>clearTimeout(e)},[]),m(()=>{if(w.current){let e=w.current.validity.valid;M!==e&&(q(e),E?.(e))}},[B]),m(()=>{w.current&&document.activeElement!==w.current&&N!==B&&K(N??k)},[N]);let F=i(T),G=n(["Input","RestrictedInput",y&&"Input--disabled",I&&"Input--fluid",D&&"Input--monospace",o(T),v,!M&&"RestrictedInput--invalid"]);return e("input",{...F,autoComplete:"off",className:G,disabled:y,max:j,min:k,onBlur:function(e){x?.(B)},onChange:function(e){let t=Number(e.target.value);K(t),A(t,e)},onKeyDown:function(e){if(h?.(e),e.key===t.Enter){e.preventDefault(),R?.(B,e),w.current?.blur();return}if(r(e.key)){e.preventDefault(),g?.(B,e),w.current?.blur();return}if(e.key===t.Minus){e.preventDefault();let t=-1*B;K(t),A(t,e);return}},ref:w,spellCheck:!1,step:a?"any":"1",type:"number",value:B})}export{p as RestrictedInput};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{KEY as r,isEscape as t}from"../common/keys.js";import{classes as n}from"../common/react.js";import{computeBoxClassName as u,computeBoxProps as o}from"../common/ui.js";import{inputDebounce as a}from"../common/timer.js";import{useEffect as c,
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{KEY as r,isEscape as t}from"../common/keys.js";import{classes as n}from"../common/react.js";import{computeBoxClassName as u,computeBoxProps as o}from"../common/ui.js";import{inputDebounce as a}from"../common/timer.js";import{useEffect as c,useId as l,useRef as m,useState as i}from"react";function s(s){let{autoFocus:f,autoSelect:g,className:p,disabled:T,dontUseTabForIndent:y,expensive:b,fluid:v,maxLength:d,monospace:k,onBlur:$,onChange:h,onEnter:x,onEscape:j,onKeyDown:D,placeholder:E,ref:I,selfClear:K,spellcheck:C=!1,userMarkup:A,value:w,...B}=s,L=m(null),N=I??L,[q,z]=i(w??""),F=l();c(()=>{(f||g)&&setTimeout(()=>{N.current?.focus(),g&&N.current?.select()},1)},[]),c(()=>{N.current&&document.activeElement!==N.current&&w!==q&&z(w??"")},[w]);let G=o(B),H=n(["Input","TextArea",v&&"Input--fluid",k&&"Input--monospace",T&&"Input--disabled",u(B),p]);return e("textarea",{...G,autoComplete:"off",className:H,maxLength:d,onBlur:function(e){$?.(q)},onChange:function(e){let r=e.currentTarget.value;z(r),h&&(b?a(F,"number"==typeof b?b:250)(()=>h?.(r,e)):h(r,e))},onKeyDown:function(e){if(D?.(e),e.key===r.Enter&&!e.shiftKey){e.preventDefault(),x?.(e.currentTarget.value,e),K&&z(""),e.currentTarget.blur();return}if(t(e.key)){j?.(e.currentTarget.value,e),e.currentTarget.blur();return}if(!y&&e.key===r.Tab){e.preventDefault();let{value:r,selectionStart:t,selectionEnd:n}=e.currentTarget;z(`${r.substring(0,t)} ${r.substring(n)}`),e.currentTarget.selectionEnd=t+1,h?.(e.currentTarget.value,e);return}if(A&&(e.ctrlKey||e.metaKey)&&A[e.key]){e.preventDefault();let{selectionStart:r,selectionEnd:t,value:n}=e.currentTarget,u=A[e.key];z(`${n.substring(0,r)}${u}${n.substring(r,t)}${u}${n.substring(t)}`),e.currentTarget.selectionEnd=t+2*u.length,h?.(e.currentTarget.value,e);return}},placeholder:E,ref:N,spellCheck:C,value:q})}export{s as TextArea};
|
package/package.json
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
min-height: var(--button-height);
|
|
9
9
|
padding: 0 var(--space-m);
|
|
10
10
|
background-color: var(--progress-bar-background);
|
|
11
|
-
border: var(--border-thickness-tiny) solid
|
|
11
|
+
border: var(--border-thickness-tiny) solid;
|
|
12
|
+
border-color: var(--progress-bar-color);
|
|
12
13
|
border-radius: var(--progress-bar-border-radius);
|
|
13
14
|
transition: border-color var(--progress-bar-transition) ease-out;
|
|
14
15
|
|