@nick-skriabin/glyph 0.1.68 → 0.1.69
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/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15,5 +15,5 @@ import ae,{createContext,forwardRef,useContext,useRef,useState,useEffect,useLayo
|
|
|
15
15
|
tell application "System Events"
|
|
16
16
|
set frontmost of (first process whose name is "qlmanage") to true
|
|
17
17
|
end tell
|
|
18
|
-
'`,()=>{});}function js(e){return new Promise((t,n)=>{let r=platform(),o,s;r==="linux"?(o="xdg-open",s=[e]):r==="win32"?(o="cmd",s=["/c","start",'""',e]):(o="open",s=[e]);let i=spawn(o,s,{detached:true,stdio:["ignore","ignore","ignore"]});i.unref(),i.on("error",c=>{n(new Error(`Failed to open preview: ${c.message}`));}),setTimeout(t,100);})}function Vs({src:e,width:t,height:n,unloadTrigger:r,style:o,focusedStyle:s,placeholderStyle:i,focusable:c=true,disabled:l=false,inline:f=true,placeholder:p,onStateChange:m,onError:y,autoLoad:C=false,autoSize:P=false,maxWidth:h,maxHeight:d}){let g=useContext(z),b=useContext(Q),T=useContext(de),F=useContext(bt),V=useContext(Oe),k=useRef(null),N=useRef(null),M=useRef(Math.floor(Math.random()*1e6)),j=useRef(null),[I,x]=useState(false),[w,S]=useState(false),[A,X]=useState("placeholder"),[$,_]=useState(null),[G,J]=useState(null),[D,W]=useState(null),B=useRef(null),ue=p||yn(e),re=Et(e),oe=useRef(r);useEffect(()=>{r!==void 0&&r!==oe.current&&A==="loaded"&&(B.current=null,W(null),X("placeholder")),oe.current=r;},[r,A]);let ee=useCallback(K=>{X(K),m?.(K);},[m]);useEffect(()=>{if(!(!g||!N.current||!k.current||!c))return g.register(N.current,k.current,false)},[g,c,I]),useEffect(()=>{!g||!N.current||g.setSkippable(N.current,!!l);},[g,l]),useEffect(()=>{if(!g||!N.current)return;let K=N.current;return S(g.focusedId===K),g.onFocusChange(Y=>{S(Y===K);})},[g,I]),useEffect(()=>{if(!(!T||!k.current))return J(T.getLayout(k.current)),T.subscribe(k.current,J)},[T,I]);let te=V?.getBounds().scrollOffset??0;useEffect(()=>{if(V){if(j.current===null){j.current=te;return}if(A!=="loaded"){j.current=te;return}te!==j.current&&(j.current=te,B.current=null,W(null),X("placeholder"));}},[V,te,A]),useEffect(()=>{if(!F||A!=="loaded"||!B.current||!G)return;let{data:K,cellWidth:Y,cellHeight:le}=B.current,be=M.current,fe=setTimeout(()=>{F.registerImage({id:be,data:K,x:G.innerX,y:G.innerY,width:Y,height:le});},0);return ()=>{clearTimeout(fe),F.unregisterImage(be);}},[F,A,G,V]);let E=useCallback(async()=>{if(A!=="loading"){ee("loading"),_(null);try{let K=await kr(e);if(f&&Ot()&&G){let le=Nt(K.data),be=K.data;if(le!=="png"){let Ie=Pr(K.data);if(!Ie){ee("preview"),await xn(K.localPath),ee("placeholder");return}be=Ie;}let fe=Wt(be),he,ye;if(P&&fe){let Ce=Math.ceil(fe.width/8),xe=Math.ceil(fe.height/16),pt=h??80,O=d??24;if(Ce>pt||xe>O){let U=pt/Ce,Z=O/xe,pe=Math.min(U,Z);Ce=Math.max(1,Math.round(Ce*pe)),xe=Math.max(1,Math.round(xe*pe));}he=Ce,ye=xe,W({width:Ce,height:xe});}else he=t??G.innerWidth,ye=n??G.innerHeight;if(he<=0||ye<=0)throw new Error("Image area too small");let Te=30,He=6;if(he>Te||ye>He){let Ie=Te/he,ke=He/ye,we=Math.min(Ie,ke);he=Math.max(1,Math.round(he*we)),ye=Math.max(1,Math.round(ye*we));}B.current={data:be,localPath:K.localPath,cellWidth:he,cellHeight:ye},ee("loaded");}else ee("preview"),await xn(K.localPath),ee("placeholder");}catch(K){let Y=K instanceof Error?K:new Error(String(K));_(Y.message),ee("error"),y?.(Y);}}},[e,A,f,G,t,n,P,h,d,ee,y]);useEffect(()=>{if(!b||!N.current||!c||l)return;let K=N.current,Y=le=>g?.focusedId!==K?false:le.name==="space"||le.name==="return"||le.name==="r"&&B.current?(E(),true):le.name==="escape"&&A==="loaded"?(B.current=null,W(null),ee("placeholder"),true):le.name==="escape"&&A==="placeholder"?(g?.blur(),true):false;return b.registerInputHandler(K,Y)},[b,g,c,l,I,E,A,ee]),useEffect(()=>{C&&A==="placeholder"&&G&&G.innerWidth>0&&E();},[C,A,G,E]),useEffect(()=>{let K=M.current;return ()=>{F?.unregisterImage(K);}},[F]);let L,a;switch(A){case "placeholder":a=re?"\u{1F310}":"\u{1F5BC}\uFE0F",L=`${a} ${ue}`;break;case "loading":a="\u23F3",L=`${a} Loading...`;break;case "loaded":L=null;break;case "preview":a="\u{1F441}\uFE0F",L=`${a} Previewing...`;break;case "error":a="\u274C",L=`${a} ${$||"Error"}`;break}let R=P&&D?D.width:t,v=P&&D?D.height:n,H={...{border:"round",borderColor:"blackBright",justifyContent:"center",alignItems:"center",...o,...R!==void 0?{width:R}:{},...v!==void 0?{height:v}:{}},...w?{borderColor:"cyan"}:{},...w&&s?s:{}},q={color:"blackBright",...i,...w?{color:"cyan"}:{}};return ae.createElement("box",{style:H,focusable:c,ref:K=>{K?(k.current=K,N.current=K.focusId,x(true)):(k.current=null,N.current=null,x(false));}},L!==null?ae.createElement("text",{style:q},L):null)}function Ws(e){let t=useContext(z),[n]=useState(()=>`focus-${Math.random().toString(36).slice(2,9)}`),r=t?t.focusedId===n:false;useEffect(()=>{if(!(!t||!e?.current))return e.current.focusId=n,t.register(n,e.current)},[t,n,e]);let o=useMemo(()=>()=>{t?.requestFocus(n);},[t,n]);return {focused:r,focus:o}}function qs(e={}){let{disabled:t,onFocus:n,onBlur:r,onKeyPress:o}=e,s=useContext(z),i=useContext(Q),c=useRef(null),l=useRef(null),[f,p]=useState(false),m=useRef(n),y=useRef(r),C=useRef(o);m.current=n,y.current=r,C.current=o;let P=useCallback(d=>{c.current=d,d?l.current=d.focusId??null:l.current=null;},[]);useEffect(()=>{if(!(!s||!l.current||!c.current))return s.register(l.current,c.current)},[s]),useEffect(()=>{!s||!l.current||s.setSkippable(l.current,!!t);},[s,t]),useEffect(()=>{if(!s||!l.current)return;let d=l.current,g=s.focusedId===d;return p(g),s.onFocusChange(b=>{let T=b===d;p(F=>(T&&!F?m.current?.():!T&&F&&y.current?.(),T));})},[s]),useEffect(()=>{if(!i||!l.current||t)return;let d=l.current,g=b=>s?.focusedId!==d?false:C.current?.(b)===true;return i.registerInputHandler(d,g)},[i,s,t]);let h=useCallback(()=>{s&&l.current&&s.requestFocus(l.current);},[s]);return {ref:P,isFocused:f,focus:h,focusId:l.current}}function Xs(){let e=useContext($e);if(!e)throw new Error("useApp must be used within a Glyph render tree");return {exit:e.exit,get columns(){return e.columns},get rows(){return e.rows}}}function Zs(){let e=useContext(z),t=useContext(de),[n,r]=useState([]),o=useRef(()=>{}),s=useCallback(()=>{if(!e)return;let c=(e.getActiveElements?.()??e.getRegisteredElements?.()??[]).map(({id:l,node:f})=>({id:l,node:f,layout:t?.getLayout(f)??f.layout,type:f.type}));c.sort((l,f)=>l.layout.y!==f.layout.y?l.layout.y-f.layout.y:l.layout.x-f.layout.x),r(c);},[e,t]);return o.current=s,useEffect(()=>{if(!e)return;s();let i=e.onFocusChange(()=>{s();}),c=setTimeout(s,50);return ()=>{i(),clearTimeout(c);}},[e,t,s]),e?{elements:n,focusedId:e.focusedId,requestFocus:e.requestFocus,focusNext:e.focusNext,focusPrev:e.focusPrev,refresh:()=>o.current()}:null}function ei(e){let t=[];for(let n of e)switch(n){case "9":t.push({type:"digit",char:n});break;case "a":t.push({type:"letter",char:n});break;case "*":t.push({type:"alphanumeric",char:n});break;default:t.push({type:"literal",char:n});break}return t}function ti(e,t){switch(t){case "digit":return /\d/.test(e);case "letter":return /[a-zA-Z]/.test(e);case "alphanumeric":return /[a-zA-Z0-9]/.test(e);case "literal":return true}}function me(e){let t=typeof e=="string"?{mask:e}:e,{mask:n,placeholder:r="_",showPlaceholder:o=false}=t,s=ei(n);return (i,c)=>{let l=[];for(let m of i)(m!==r&&!/[\s\-\(\)\/\.\:]/.test(m)||/[a-zA-Z0-9]/.test(m))&&/[a-zA-Z0-9]/.test(m)&&l.push(m);let f="",p=0;for(let m of s)if(m.type==="literal")(p<l.length||o)&&(f+=m.char);else if(p<l.length){let y=l[p];if(ti(y,m.type))f+=y,p++;else {p++;continue}}else o&&(f+=r);return f}}var ni={usPhone:me("(999) 999-9999"),intlPhone:me("+9 999 999 9999"),dateUS:me("99/99/9999"),dateEU:me("99/99/9999"),dateISO:me("9999-99-99"),time:me("99:99"),timeFull:me("99:99:99"),creditCard:me("9999 9999 9999 9999"),ssn:me("999-99-9999"),zip:me("99999"),zipPlus4:me("99999-9999"),ipv4:me("999.999.999.999"),mac:me("**:**:**:**:**:**")};export{Co as Box,$o as Button,ms as Checkbox,bs as DialogHost,qt as FocusScope,Vs as Image,Eo as Input,Rs as JumpNav,Ao as Keybind,en as List,Xo as Menu,jo as Portal,Qo as Progress,gs as Radio,zo as ScrollView,ds as Select,Mo as Spacer,ns as Spinner,ko as Text,fs as ToastHost,me as createMask,Qe as detectTerminalCapabilities,ni as masks,$t as parseAnsi,yo as render,Zr as stripAnsi,Ot as supportsInlineImages,Xs as useApp,xs as useDialog,Ws as useFocus,Zs as useFocusRegistry,qs as useFocusable,rt as useInput,Ge as useLayout,as as useToast};//# sourceMappingURL=index.js.map
|
|
18
|
+
'`,()=>{});}function js(e){return new Promise((t,n)=>{let r=platform(),o,s;r==="linux"?(o="xdg-open",s=[e]):r==="win32"?(o="cmd",s=["/c","start",'""',e]):(o="open",s=[e]);let i=spawn(o,s,{detached:true,stdio:["ignore","ignore","ignore"]});i.unref(),i.on("error",c=>{n(new Error(`Failed to open preview: ${c.message}`));}),setTimeout(t,100);})}function Vs({src:e,width:t,height:n,unloadTrigger:r,style:o,focusedStyle:s,placeholderStyle:i,focusable:c=true,disabled:l=false,inline:f=true,placeholder:p,onStateChange:m,onError:y,autoLoad:C=false,autoSize:P=false,maxWidth:h,maxHeight:d}){let g=useContext(z),b=useContext(Q),T=useContext(de),F=useContext(bt),V=useContext(Oe),k=useRef(null),N=useRef(null),M=useRef(Math.floor(Math.random()*1e6)),j=useRef(null),[I,x]=useState(false),[w,S]=useState(false),[A,X]=useState("placeholder"),[$,_]=useState(null),[G,J]=useState(null),[D,W]=useState(null),B=useRef(null),ue=p||yn(e),re=Et(e),oe=useRef(r);useEffect(()=>{r!==void 0&&r!==oe.current&&A==="loaded"&&(B.current=null,W(null),X("placeholder")),oe.current=r;},[r,A]);let ee=useCallback(K=>{X(K),m?.(K);},[m]);useEffect(()=>{if(!(!g||!N.current||!k.current||!c))return g.register(N.current,k.current,false)},[g,c,I]),useEffect(()=>{!g||!N.current||(g.setSkippable(N.current,!!l),l&&g.focusedId===N.current&&g.blur());},[g,l]),useEffect(()=>{if(!g||!N.current)return;let K=N.current;return S(g.focusedId===K),g.onFocusChange(Y=>{S(Y===K);})},[g,I]),useEffect(()=>{if(!(!T||!k.current))return J(T.getLayout(k.current)),T.subscribe(k.current,J)},[T,I]);let te=V?.getBounds().scrollOffset??0;useEffect(()=>{if(V){if(j.current===null){j.current=te;return}if(A!=="loaded"){j.current=te;return}te!==j.current&&(j.current=te,B.current=null,W(null),X("placeholder"));}},[V,te,A]),useEffect(()=>{if(!F||A!=="loaded"||!B.current||!G)return;let{data:K,cellWidth:Y,cellHeight:le}=B.current,be=M.current,fe=setTimeout(()=>{F.registerImage({id:be,data:K,x:G.innerX,y:G.innerY,width:Y,height:le});},0);return ()=>{clearTimeout(fe),F.unregisterImage(be);}},[F,A,G,V]);let E=useCallback(async()=>{if(A!=="loading"){ee("loading"),_(null);try{let K=await kr(e);if(f&&Ot()&&G){let le=Nt(K.data),be=K.data;if(le!=="png"){let Ie=Pr(K.data);if(!Ie){ee("preview"),await xn(K.localPath),ee("placeholder");return}be=Ie;}let fe=Wt(be),he,ye;if(P&&fe){let Ce=Math.ceil(fe.width/8),xe=Math.ceil(fe.height/16),pt=h??80,O=d??24;if(Ce>pt||xe>O){let U=pt/Ce,Z=O/xe,pe=Math.min(U,Z);Ce=Math.max(1,Math.round(Ce*pe)),xe=Math.max(1,Math.round(xe*pe));}he=Ce,ye=xe,W({width:Ce,height:xe});}else he=t??G.innerWidth,ye=n??G.innerHeight;if(he<=0||ye<=0)throw new Error("Image area too small");let Te=30,He=6;if(he>Te||ye>He){let Ie=Te/he,ke=He/ye,we=Math.min(Ie,ke);he=Math.max(1,Math.round(he*we)),ye=Math.max(1,Math.round(ye*we));}B.current={data:be,localPath:K.localPath,cellWidth:he,cellHeight:ye},ee("loaded");}else ee("preview"),await xn(K.localPath),ee("placeholder");}catch(K){let Y=K instanceof Error?K:new Error(String(K));_(Y.message),ee("error"),y?.(Y);}}},[e,A,f,G,t,n,P,h,d,ee,y]);useEffect(()=>{if(!b||!N.current||!c||l)return;let K=N.current,Y=le=>g?.focusedId!==K?false:le.name==="space"||le.name==="return"||le.name==="r"&&B.current?(E(),true):le.name==="escape"&&A==="loaded"?(B.current=null,W(null),ee("placeholder"),true):le.name==="escape"&&A==="placeholder"?(g?.blur(),true):false;return b.registerInputHandler(K,Y)},[b,g,c,l,I,E,A,ee]),useEffect(()=>{C&&A==="placeholder"&&G&&G.innerWidth>0&&E();},[C,A,G,E]),useEffect(()=>{let K=M.current;return ()=>{F?.unregisterImage(K);}},[F]);let L,a;switch(A){case "placeholder":a=re?"\u{1F310}":"\u{1F5BC}\uFE0F",L=`${a} ${ue}`;break;case "loading":a="\u23F3",L=`${a} Loading...`;break;case "loaded":L=null;break;case "preview":a="\u{1F441}\uFE0F",L=`${a} Previewing...`;break;case "error":a="\u274C",L=`${a} ${$||"Error"}`;break}let R=P&&D?D.width:t,v=P&&D?D.height:n,H={...{border:"round",borderColor:"blackBright",justifyContent:"center",alignItems:"center",...o,...R!==void 0?{width:R}:{},...v!==void 0?{height:v}:{}},...w?{borderColor:"cyan"}:{},...w&&s?s:{}},q={color:"blackBright",...i,...w?{color:"cyan"}:{}};return ae.createElement("box",{style:H,focusable:c,ref:K=>{K?(k.current=K,N.current=K.focusId,x(true)):(k.current=null,N.current=null,x(false));}},L!==null?ae.createElement("text",{style:q},L):null)}function Ws(e){let t=useContext(z),[n]=useState(()=>`focus-${Math.random().toString(36).slice(2,9)}`),r=t?t.focusedId===n:false;useEffect(()=>{if(!(!t||!e?.current))return e.current.focusId=n,t.register(n,e.current)},[t,n,e]);let o=useMemo(()=>()=>{t?.requestFocus(n);},[t,n]);return {focused:r,focus:o}}function qs(e={}){let{disabled:t,onFocus:n,onBlur:r,onKeyPress:o}=e,s=useContext(z),i=useContext(Q),c=useRef(null),l=useRef(null),[f,p]=useState(false),m=useRef(n),y=useRef(r),C=useRef(o);m.current=n,y.current=r,C.current=o;let P=useCallback(d=>{c.current=d,d?l.current=d.focusId??null:l.current=null;},[]);useEffect(()=>{if(!(!s||!l.current||!c.current))return s.register(l.current,c.current)},[s]),useEffect(()=>{!s||!l.current||(s.setSkippable(l.current,!!t),t&&s.focusedId===l.current&&s.blur());},[s,t]),useEffect(()=>{if(!s||!l.current)return;let d=l.current,g=s.focusedId===d;return p(g),s.onFocusChange(b=>{let T=b===d;p(F=>(T&&!F?m.current?.():!T&&F&&y.current?.(),T));})},[s]),useEffect(()=>{if(!i||!l.current||t)return;let d=l.current,g=b=>s?.focusedId!==d?false:C.current?.(b)===true;return i.registerInputHandler(d,g)},[i,s,t]);let h=useCallback(()=>{s&&l.current&&s.requestFocus(l.current);},[s]);return {ref:P,isFocused:f,focus:h,focusId:l.current}}function Xs(){let e=useContext($e);if(!e)throw new Error("useApp must be used within a Glyph render tree");return {exit:e.exit,get columns(){return e.columns},get rows(){return e.rows}}}function Zs(){let e=useContext(z),t=useContext(de),[n,r]=useState([]),o=useRef(()=>{}),s=useCallback(()=>{if(!e)return;let c=(e.getActiveElements?.()??e.getRegisteredElements?.()??[]).map(({id:l,node:f})=>({id:l,node:f,layout:t?.getLayout(f)??f.layout,type:f.type}));c.sort((l,f)=>l.layout.y!==f.layout.y?l.layout.y-f.layout.y:l.layout.x-f.layout.x),r(c);},[e,t]);return o.current=s,useEffect(()=>{if(!e)return;s();let i=e.onFocusChange(()=>{s();}),c=setTimeout(s,50);return ()=>{i(),clearTimeout(c);}},[e,t,s]),e?{elements:n,focusedId:e.focusedId,requestFocus:e.requestFocus,focusNext:e.focusNext,focusPrev:e.focusPrev,refresh:()=>o.current()}:null}function ei(e){let t=[];for(let n of e)switch(n){case "9":t.push({type:"digit",char:n});break;case "a":t.push({type:"letter",char:n});break;case "*":t.push({type:"alphanumeric",char:n});break;default:t.push({type:"literal",char:n});break}return t}function ti(e,t){switch(t){case "digit":return /\d/.test(e);case "letter":return /[a-zA-Z]/.test(e);case "alphanumeric":return /[a-zA-Z0-9]/.test(e);case "literal":return true}}function me(e){let t=typeof e=="string"?{mask:e}:e,{mask:n,placeholder:r="_",showPlaceholder:o=false}=t,s=ei(n);return (i,c)=>{let l=[];for(let m of i)(m!==r&&!/[\s\-\(\)\/\.\:]/.test(m)||/[a-zA-Z0-9]/.test(m))&&/[a-zA-Z0-9]/.test(m)&&l.push(m);let f="",p=0;for(let m of s)if(m.type==="literal")(p<l.length||o)&&(f+=m.char);else if(p<l.length){let y=l[p];if(ti(y,m.type))f+=y,p++;else {p++;continue}}else o&&(f+=r);return f}}var ni={usPhone:me("(999) 999-9999"),intlPhone:me("+9 999 999 9999"),dateUS:me("99/99/9999"),dateEU:me("99/99/9999"),dateISO:me("9999-99-99"),time:me("99:99"),timeFull:me("99:99:99"),creditCard:me("9999 9999 9999 9999"),ssn:me("999-99-9999"),zip:me("99999"),zipPlus4:me("99999-9999"),ipv4:me("999.999.999.999"),mac:me("**:**:**:**:**:**")};export{Co as Box,$o as Button,ms as Checkbox,bs as DialogHost,qt as FocusScope,Vs as Image,Eo as Input,Rs as JumpNav,Ao as Keybind,en as List,Xo as Menu,jo as Portal,Qo as Progress,gs as Radio,zo as ScrollView,ds as Select,Mo as Spacer,ns as Spinner,ko as Text,fs as ToastHost,me as createMask,Qe as detectTerminalCapabilities,ni as masks,$t as parseAnsi,yo as render,Zr as stripAnsi,Ot as supportsInlineImages,Xs as useApp,xs as useDialog,Ws as useFocus,Zs as useFocusRegistry,qs as useFocusable,rt as useInput,Ge as useLayout,as as useToast};//# sourceMappingURL=index.js.map
|
|
19
19
|
//# sourceMappingURL=index.js.map
|