@nice2dev/ui-ai 1.0.10 → 1.0.12
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/NiceAccessibilityAI.d.ts.map +1 -1
- package/dist/NiceChartAI.d.ts.map +1 -1
- package/dist/NiceDataLabeler.d.ts.map +1 -1
- package/dist/NiceModelInference.d.ts.map +1 -1
- package/dist/index.cjs +543 -543
- package/dist/index.mjs +2818 -2783
- package/dist/style.css +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),
|
|
2
|
-
`);n=P.pop()??"";for(const h of P){const d=h.trim();if(!(!d||d===":")){if(d.startsWith("data:")){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react");class Be{constructor(a={},t){this.timestamps=[],this.tokenCount=0,this.warningEmitted=!1,this.config={maxRequestsPerMinute:a.maxRequestsPerMinute??30,maxTokensPerSession:a.maxTokensPerSession??1e4,warnThresholdPercent:a.warnThresholdPercent??80},this.onWarning=t}canRequest(){return this.pruneOldTimestamps(),!(this.timestamps.length>=this.config.maxRequestsPerMinute||this.tokenCount>=this.config.maxTokensPerSession)}recordRequest(){return this.canRequest()?(this.timestamps.push(Date.now()),!0):!1}recordTokens(a){this.tokenCount+=a,this.checkWarning()}getStatus(){this.pruneOldTimestamps();const a=this.config.maxTokensPerSession>0?this.tokenCount/this.config.maxTokensPerSession*100:0,t=this.config.maxRequestsPerMinute>0?this.timestamps.length/this.config.maxRequestsPerMinute*100:0;return{requestsThisMinute:this.timestamps.length,tokensThisSession:this.tokenCount,isLimited:!this.canRequest(),isWarning:a>=this.config.warnThresholdPercent||t>=this.config.warnThresholdPercent}}reset(){this.timestamps=[],this.tokenCount=0,this.warningEmitted=!1}pruneOldTimestamps(){const a=Date.now()-6e4;this.timestamps=this.timestamps.filter(t=>t>a)}checkWarning(){var t;if(this.warningEmitted)return;this.getStatus().isWarning&&(this.warningEmitted=!0,(t=this.onWarning)==null||t.call(this))}}const Fe=o.createContext(null);function ja({config:i,rateLimits:a,enabled:t=!0,onRateLimitWarning:r,children:n}){const s=o.useRef(null);s.current||(s.current=new Be(a,r));const m=o.useCallback(()=>s.current.getStatus(),[]),c=o.useMemo(()=>({config:i,enabled:t,rateLimiter:s.current,getRateLimitStatus:m}),[i,t,m]);return e.jsx(Fe.Provider,{value:c,children:n})}function X(){return o.useContext(Fe)}async function*Je(i,a){var s,m,c,g,f,j,w,N,S;const t=(s=i.body)==null?void 0:s.getReader();if(!t)throw new Error("Response body is not readable");const r=new TextDecoder;let n="";try{for(;!(a!=null&&a.aborted);){const{done:$,value:k}=await t.read();if($)break;n+=r.decode(k,{stream:!0});const P=n.split(`
|
|
2
|
+
`);n=P.pop()??"";for(const h of P){const d=h.trim();if(!(!d||d===":")){if(d.startsWith("data:")){const v=d.slice(5).trim();if(v==="[DONE]"){yield{token:"",done:!0};return}try{const C=JSON.parse(v),p=((g=(c=(m=C.choices)==null?void 0:m[0])==null?void 0:c.delta)==null?void 0:g.content)??"",_=((j=(f=C.choices)==null?void 0:f[0])==null?void 0:j.finish_reason)==="stop";(p||_)&&(yield{token:p,done:_,usage:C.usage})}catch{v&&(yield{token:v,done:!1})}continue}try{const v=JSON.parse(d),C=v.text??v.content??v.token??"";C&&(yield{token:C,done:!1})}catch{d&&(yield{token:d,done:!1})}}}}if(n.trim()){const $=n.trim();if($.startsWith("data:")){const k=$.slice(5).trim();if(k&&k!=="[DONE]")try{const h=((S=(N=(w=JSON.parse(k).choices)==null?void 0:w[0])==null?void 0:N.delta)==null?void 0:S.content)??"";h&&(yield{token:h,done:!0})}catch{yield{token:k,done:!0}}}}}finally{t.releaseLock()}}async function qe(i){var t,r,n,s;const a=await i.json();if((n=(r=(t=a.choices)==null?void 0:t[0])==null?void 0:r.message)!=null&&n.content)return{text:a.choices[0].message.content,usage:a.usage};if((s=a.message)!=null&&s.content)return{text:a.message.content};if(typeof a.text=="string")return{text:a.text};if(typeof a.content=="string")return{text:a.content};if(typeof a.response=="string")return{text:a.response};throw new Error("Unrecognized AI response format")}const ie=new Map;function $e(i,a){const t=a?{...i,fieldValue:void 0,formContext:void 0}:i;return JSON.stringify(t)}function ka(i,a){const t=[],r=a.systemPrompt??"You are a helpful assistant providing concise contextual hints for form fields. Keep responses short (1-3 sentences). Be specific and actionable.";t.push({role:"system",content:r});const n=[];if(i.fieldLabel&&n.push(`Field: "${i.fieldLabel}"`),i.fieldType&&n.push(`Type: ${i.fieldType}`),!a.privacyMode&&i.fieldValue!==void 0){const m=typeof i.fieldValue=="string"?i.fieldValue:JSON.stringify(i.fieldValue);n.push(`Current value: ${m}`)}i.validationRules&&Object.keys(i.validationRules).length>0&&n.push(`Validation: ${JSON.stringify(i.validationRules)}`),i.schema&&Object.keys(i.schema).length>0&&n.push(`Schema: ${JSON.stringify(i.schema)}`),!a.privacyMode&&i.formContext&&Object.keys(i.formContext).length>0&&n.push(`Form context: ${JSON.stringify(i.formContext)}`),i.customPrompt&&n.push(i.customPrompt);const s=n.length>0?`Provide a helpful hint for this field:
|
|
3
3
|
${n.join(`
|
|
4
|
-
`)}`:"Provide a helpful suggestion.";return
|
|
5
|
-
Parse this description and return suggested values for each field as JSON: { ${
|
|
6
|
-
`))??[],s=(
|
|
4
|
+
`)}`:"Provide a helpful suggestion.";return t.push({role:"user",content:s}),t}function V(i={},a={}){i=i??{},a=a??{};const{debounceMs:t=500,disabled:r=!1}=a,n=X(),[s,m]=o.useState(""),[c,g]=o.useState(!1),[f,j]=o.useState(null),[w,N]=o.useState(!1),S=o.useRef(null),$=o.useRef(0),k=o.useCallback(async()=>{var y,A,R;if(!n||!n.enabled||r)return;const{config:d,rateLimiter:v}=n;if(!v.recordRequest()){j("Rate limit exceeded. Please wait before requesting another hint.");return}const C=$e(i,d.privacyMode??!1),p=ie.get(C);if(p){m(p),g(!1),j(null),N(!1);return}(y=S.current)==null||y.abort();const _=new AbortController;S.current=_,g(!0),j(null),m(""),N(!1);const b=ka(i,d),u=d.stream!==!1;try{const l={"Content-Type":"application/json",...d.headers};d.apiKey&&(l.Authorization=`Bearer ${d.apiKey}`);const x=JSON.stringify({model:d.model??"gpt-3.5-turbo",messages:b,temperature:d.temperature??.7,max_tokens:d.maxTokens??256,stream:u}),M=await fetch(d.endpoint,{method:"POST",headers:l,body:x,signal:_.signal});if(!M.ok){const z=await M.text().catch(()=>M.statusText);throw new Error(`AI request failed (${M.status}): ${z}`)}if(u){N(!0);let z="";for await(const D of Je(M,_.signal))if(_.signal.aborted||(z+=D.token,m(z),(A=D.usage)!=null&&A.completion_tokens&&v.recordTokens(D.usage.completion_tokens),D.done))break;if(z.length>0){const D=Math.ceil(z.length/4);v.recordTokens(D)}ie.set(C,z)}else{const z=await qe(M);m(z.text),ie.set(C,z.text),(R=z.usage)!=null&&R.completion_tokens?v.recordTokens(z.usage.completion_tokens):v.recordTokens(Math.ceil(z.text.length/4))}}catch(l){if(l instanceof DOMException&&l.name==="AbortError")return;j(l instanceof Error?l.message:"AI hint request failed")}finally{_.signal.aborted||(g(!1),N(!1))}},[n,i,r]);o.useEffect(()=>{if(!n||!n.enabled||r)return;const d=setTimeout(k,t);return()=>clearTimeout(d)},[i==null?void 0:i.fieldLabel,i==null?void 0:i.fieldType,i==null?void 0:i.fieldValue,i==null?void 0:i.customPrompt,t,r,n==null?void 0:n.enabled,$.current]),o.useEffect(()=>()=>{var d;(d=S.current)==null||d.abort()},[]);const P=o.useCallback(()=>{var d;(d=S.current)==null||d.abort(),g(!1),N(!1)},[]),h=o.useCallback(()=>{if(n){const d=$e(i,n.config.privacyMode??!1);ie.delete(d)}$.current+=1,k()},[n,i,k]);return!n||!n.enabled?{text:"",loading:!1,error:null,streaming:!1,abort:()=>{},refresh:()=>{},hint:null,fetchHint:async()=>{}}:{text:s,loading:c,error:f,streaming:w,abort:P,refresh:h,hint:s?{content:s}:null,fetchHint:async()=>{await k()}}}function Na(){return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"16",height:"16",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[e.jsx("path",{d:"M12 3l1.5 5.5L19 10l-5.5 1.5L12 17l-1.5-5.5L5 10l5.5-1.5z"}),e.jsx("path",{d:"M19 15l.5 2 2 .5-2 .5-.5 2-.5-2-2-.5 2-.5z"}),e.jsx("path",{d:"M5 19l.5 1.5 1.5.5-1.5.5-.5 1.5-.5-1.5-1.5-.5 1.5-.5z"})]})}function Ca(i,a){if(i!=="auto"||!a)return i==="auto"?"top":i;const t=a.top,r=window.innerHeight-a.bottom,n=a.left,s=window.innerWidth-a.right,m=Math.max(t,r,n,s);return m===t?"top":m===r?"bottom":m===s?"right":"left"}function Sa(i){const a={position:"absolute",zIndex:9999,minWidth:200,maxWidth:320,padding:"8px 12px",borderRadius:8,fontSize:13,lineHeight:1.5,backgroundColor:"var(--ntd-ai-bg, #1e1e2e)",color:"var(--ntd-ai-fg, #cdd6f4)",border:"1px solid var(--ntd-ai-border, #45475a)",boxShadow:"0 4px 16px var(--nice-overlay-25, rgba(0, 0, 0, 0.25))",wordWrap:"break-word"};switch(i){case"top":return{...a,bottom:"100%",left:"50%",transform:"translateX(-50%)",marginBottom:6};case"bottom":return{...a,top:"100%",left:"50%",transform:"translateX(-50%)",marginTop:6};case"left":return{...a,right:"100%",top:"50%",transform:"translateY(-50%)",marginRight:6};case"right":return{...a,left:"100%",top:"50%",transform:"translateY(-50%)",marginLeft:6};default:return{...a,bottom:"100%",left:"50%",transform:"translateX(-50%)",marginBottom:6}}}const ke=o.forwardRef(({context:i,position:a="auto",debounceMs:t=500,showOnHover:r=!1,triggerIcon:n,className:s,style:m},c)=>{var C;const g=X(),[f,j]=o.useState(!1),[w,N]=o.useState(!1),S=o.useRef(null),$=o.useRef(null),k=V(i,{debounceMs:t,disabled:!w});o.useEffect(()=>{if(!f)return;const p=_=>{var u,y;const b=_.target;(u=S.current)!=null&&u.contains(b)||(y=$.current)!=null&&y.contains(b)||(j(!1),N(!1))};return document.addEventListener("mousedown",p),()=>document.removeEventListener("mousedown",p)},[f]),o.useEffect(()=>{if(!f)return;const p=_=>{_.key==="Escape"&&(j(!1),N(!1),k.abort())};return document.addEventListener("keydown",p),()=>document.removeEventListener("keydown",p)},[f,k]);const P=o.useCallback(p=>{if(p.stopPropagation(),r)return;const _=!f;j(_),N(_)},[f,r]),h=o.useCallback(()=>{r&&(j(!0),N(!0))},[r]),d=o.useCallback(()=>{r&&(j(!1),N(!1))},[r]);if(!g||!g.enabled)return null;const v=Ca(a,((C=S.current)==null?void 0:C.getBoundingClientRect())??null);return e.jsxs("span",{ref:c,className:s,style:{position:"relative",display:"inline-flex",...m},onMouseEnter:h,onMouseLeave:d,children:[e.jsx("button",{ref:S,type:"button",onClick:P,"aria-label":"AI hint","aria-expanded":f,className:"ntd-ai-trigger",style:{display:"inline-flex",alignItems:"center",justifyContent:"center",border:"none",background:"transparent",cursor:"pointer",padding:2,borderRadius:4,color:"var(--ntd-ai-trigger-color, #a78bfa)",opacity:.7,transition:"opacity 0.2s, transform 0.2s"},children:n??e.jsx(Na,{})}),f&&e.jsxs("div",{ref:$,role:"tooltip",className:"ntd-ai-popover",style:Sa(v),children:[k.loading&&!k.text&&e.jsxs("div",{className:"ntd-ai-loading",style:{display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{style:{display:"inline-block",width:12,height:12,border:"2px solid var(--ntd-ai-border, #45475a)",borderTopColor:"var(--ntd-ai-trigger-color, #a78bfa)",borderRadius:"50%",animation:"ntd-ai-spin 0.8s linear infinite"}}),e.jsx("span",{style:{opacity:.6},children:"Thinking..."})]}),k.text&&e.jsxs("div",{className:"ntd-ai-content",children:[k.text,k.streaming&&e.jsx("span",{className:"ntd-ai-cursor",style:{display:"inline-block",width:2,height:"1em",backgroundColor:"var(--ntd-ai-trigger-color, #a78bfa)",marginLeft:1,animation:"ntd-ai-blink 0.8s step-end infinite",verticalAlign:"text-bottom"}})]}),k.error&&e.jsx("div",{className:"ntd-ai-error",style:{color:"var(--ntd-ai-error, #f38ba8)"},children:k.error}),k.text&&!k.streaming&&e.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:4,marginTop:6,paddingTop:6,borderTop:"1px solid var(--ntd-ai-border, #45475a)"},children:[e.jsx("button",{type:"button",onClick:()=>k.refresh(),className:"ntd-ai-action",style:{fontSize:11,padding:"2px 6px",border:"1px solid var(--ntd-ai-border, #45475a)",borderRadius:4,background:"transparent",color:"inherit",cursor:"pointer"},children:"↻ Refresh"}),e.jsx("button",{type:"button",onClick:()=>{var p;(p=navigator.clipboard)==null||p.writeText(k.text)},className:"ntd-ai-action",style:{fontSize:11,padding:"2px 6px",border:"1px solid var(--ntd-ai-border, #45475a)",borderRadius:4,background:"transparent",color:"inherit",cursor:"pointer"},children:"⎘ Copy"})]})]})]})});ke.displayName="NiceAIHintBubble";function Ne(i,a,t){return{fieldLabel:i,fieldType:"text",fieldValue:a,validationRules:{...(t==null?void 0:t.maxLength)!=null?{maxLength:t.maxLength}:{},...t!=null&&t.pattern?{pattern:t.pattern}:{}},customPrompt:t!=null&&t.placeholder?`Placeholder: "${t.placeholder}". Suggest content or correct grammar.`:"Suggest content, correct grammar, or auto-complete the text."}}function Ce(i,a,t){return{fieldLabel:i,fieldType:"number",fieldValue:a,validationRules:{...(t==null?void 0:t.min)!=null?{min:t.min}:{},...(t==null?void 0:t.max)!=null?{max:t.max}:{},...(t==null?void 0:t.step)!=null?{step:t.step}:{}},customPrompt:t!=null&&t.unit?`Unit: ${t.unit}. Suggest a reasonable value or range for this field.`:"Suggest a reasonable value or range for this field based on the label and constraints."}}function Se(i,a,t){return{fieldLabel:i,fieldType:t!=null&&t.multiple?"multi-select":"select",fieldValue:a,schema:t!=null&&t.options?{availableOptions:t.options.slice(0,20).map(r=>r.label)}:{},customPrompt:"Suggest the most likely selection. Explain why this option is recommended."}}function Te(i,a,t){const r=a instanceof Date?a.toISOString().split("T")[0]:a;return{fieldLabel:i,fieldType:"date",fieldValue:r,validationRules:{...t!=null&&t.min?{min:t.min}:{},...t!=null&&t.max?{max:t.max}:{},...t!=null&&t.disableWeekends?{noWeekends:!0}:{}},customPrompt:'Suggest a date. For example: "next business day", "end of month", "in 2 weeks". Explain your suggestion briefly.'}}function Ae(i,a,t){return{fieldLabel:i,fieldType:"color",fieldValue:a,schema:t!=null&&t.palette?{currentPalette:t.palette}:{},customPrompt:t!=null&&t.industry?`Industry: ${t.industry}. Suggest a color palette (3-5 hex colors) suitable for this context.`:"Suggest a color or palette of colors that works well for this context. Provide hex values."}}function Ta(i,a){return{fieldLabel:i,fieldType:"data-grid",schema:{...a!=null&&a.columns?{columns:a.columns}:{},...(a==null?void 0:a.rowCount)!=null?{totalRows:a.rowCount}:{}},formContext:{...a!=null&&a.currentFilters?{filters:a.currentFilters}:{},...a!=null&&a.currentSorts?{sorts:a.currentSorts}:{}},customPrompt:"Suggest column configuration, useful filters, or highlight potential data anomalies."}}function Aa(i,a){return{fieldLabel:i,fieldType:"chart",schema:{...a!=null&&a.currentType?{chartType:a.currentType}:{},...(a==null?void 0:a.seriesCount)!=null?{series:a.seriesCount}:{},...(a==null?void 0:a.pointCount)!=null?{dataPoints:a.pointCount}:{}},customPrompt:a!=null&&a.dataDescription?`Data: ${a.dataDescription}. Suggest the best chart type and labeling strategy.`:"Suggest the most effective chart type for this data. Explain your recommendation."}}function Ue(i,a){return{fieldLabel:"Form auto-fill",fieldType:"form",schema:{fields:a},customPrompt:`User description: "${i}"
|
|
5
|
+
Parse this description and return suggested values for each field as JSON: { ${a.map(t=>`"${t.label}": "value"`).join(", ")} }`}}function He(i,a,t,r,n){return{fieldLabel:i,fieldType:a,fieldValue:t,validationRules:n==null?void 0:n.rules,customPrompt:`Current validation error: "${r}". Provide a friendly, specific error message with an example of a valid value. Do NOT say "field is required" — instead explain what the user should enter.`}}function Ra(i,a,t){const r=o.useMemo(()=>Ne(i,a,t),[i,a,t==null?void 0:t.placeholder,t==null?void 0:t.maxLength,t==null?void 0:t.pattern]);return V(r,t)}function Ma(i,a,t){const r=o.useMemo(()=>Ce(i,a,t),[i,a,t==null?void 0:t.min,t==null?void 0:t.max,t==null?void 0:t.step,t==null?void 0:t.unit]);return V(r,t)}function Pa(i,a,t){const r=o.useMemo(()=>Se(i,a,t),[i,a,t==null?void 0:t.multiple]);return V(r,t)}function $a(i,a,t){const r=o.useMemo(()=>Te(i,a,t),[i,a,t==null?void 0:t.min,t==null?void 0:t.max,t==null?void 0:t.disableWeekends]);return V(r,t)}function Ia(i,a,t){const r=o.useMemo(()=>Ae(i,a,t),[i,a,t==null?void 0:t.industry]);return V(r,t)}function za(i,a,t,r,n){const s=o.useMemo(()=>r?He(i,a,t,r,n):{fieldLabel:i,fieldType:a},[i,a,t,r]);return V(s,{...n,disabled:!r||(n==null?void 0:n.disabled)})}function La(i,a,t){const r=o.useMemo(()=>i?Ue(i,a):{fieldLabel:"Form"},[i,a]);return V(r,{...t,disabled:!i||(t==null?void 0:t.disabled)})}function We(i,a,t){const n=(a==null?void 0:a.split(`
|
|
6
|
+
`))??[],s=(t==null?void 0:t.cursorLine)!=null?n.slice(Math.max(0,t.cursorLine-8),t.cursorLine+3).join(`
|
|
7
7
|
`):n.slice(0,8*2).join(`
|
|
8
|
-
`);return{fieldLabel:`Code editor (${
|
|
9
|
-
Provide a concise inline completion or improvement hint for the code near the cursor. Limit response to ${(
|
|
10
|
-
Return the ${(t==null?void 0:t.limit)??5} most semantically relevant icon names from the available set as a JSON array of strings, ordered by relevance. Prefer specific over generic names.`}}function Ot(a,t,i){const r=c.useMemo(()=>We(a,t,i),[a,t,i==null?void 0:i.cursorLine,i==null?void 0:i.cursorCol,i==null?void 0:i.framework]);return V(r,i)}function Et(a,t,i){const r=c.useMemo(()=>Ge(a,t,i),[a,t,i==null?void 0:i.mode,i==null?void 0:i.locale]);return V(r,i)}function Dt(a,t){const i=c.useMemo(()=>Ve(a,t),[a,t==null?void 0:t.bpm,t==null?void 0:t.key,t==null?void 0:t.duration,t==null?void 0:t.mode]);return V(i,t)}function Ft(a,t){const i=c.useMemo(()=>Ke(a,t),[a,t==null?void 0:t.meshCount,t==null?void 0:t.triangleCount,t==null?void 0:t.targetDevice,t==null?void 0:t.mode]);return V(i,t)}function Bt(a,t){const i=c.useMemo(()=>Ye(a,t),[a,t==null?void 0:t.width,t==null?void 0:t.height,t==null?void 0:t.mode,t==null?void 0:t.targetStyle]);return V(i,t)}function Jt(a,t){const i=c.useMemo(()=>Xe(a,t),[a,t==null?void 0:t.limit,t==null?void 0:t.style]);return V(i,{...t,disabled:!a||(t==null?void 0:t.disabled)})}function Qe(a,t){var s;const i=(t==null?void 0:t.mode)??"npc-decision",r=(t==null?void 0:t.genre)??"fantasy",n={"npc-decision":`You are an AI game director. The NPC "${a}" must make a decision. Available BT nodes: ${JSON.stringify((t==null?void 0:t.btStatus)??[])}. Game state: ${JSON.stringify((t==null?void 0:t.gameState)??{})}. Return the name of the BT node to activate next, and one sentence of reasoning.`,dialogue:`You are a ${r} RPG writer. Write a short in-character dialogue line for NPC "${a}". Game state: ${JSON.stringify((t==null?void 0:t.gameState)??{})}. Max 2 sentences, no narrative descriptions.`,"procedural-level":`You are a ${r} game designer. Suggest a procedural level layout for a zone containing "${a}". Describe room count, enemy placement, loot, and one unique mechanic. Keep it under 150 words.`,"quest-description":`You are a ${r} quest designer. Write a compelling quest description involving "${a}". Include: objective, giver NPC, rewards, and a short flavour paragraph. Keep it under 120 words.`,"item-description":`You are a ${r} lore writer. Write a short item description for an item related to "${a}". Include: item name, rarity, flavour text, and one special property. Keep it under 80 words.`};return{fieldLabel:a,fieldType:`game-engine:${i}`,fieldValue:t==null?void 0:t.gameState,customPrompt:n[i],schema:{genre:r,mode:i,btNodes:(s=t==null?void 0:t.btStatus)==null?void 0:s.map(p=>p.node)}}}function qt(a,t){const i=c.useMemo(()=>Qe(a,t),[a,t==null?void 0:t.mode,t==null?void 0:t.genre,JSON.stringify(t==null?void 0:t.btStatus),JSON.stringify(t==null?void 0:t.gameState)]);return V(i,t)}function Ze(a,t,i){const r=(i==null?void 0:i.mode)??"layout",n=(i==null?void 0:i.diagramType)??"flowchart",s={layout:`You are a diagram layout optimizer. Given this ${n} with ${a.length} nodes and ${t.length} edges, suggest optimal positions for each node to minimize edge crossings and improve readability. Return JSON: { suggestions: [{ id: string, x: number, y: number, reason: string }] }. Consider flow direction (top-to-bottom or left-to-right) and grouping related nodes.`,structure:`You are a diagram analyst. Analyze this ${n} structure. Identify: 1) Missing connections, 2) Potential bottlenecks, 3) Orphan nodes, 4) Cycles or loops. Return JSON: { issues: [{ type: string, description: string, nodeIds: string[] }], score: number }`,simplify:`You are a diagram simplifier. Suggest how to simplify this ${n} while preserving meaning. Identify: nodes that could be merged, redundant edges, or overly complex branches. Return JSON: { simplifications: [{ action: 'merge'|'remove'|'group', ids: string[], reason: string }] }`,group:`You are a diagram organizer. Suggest logical groupings for nodes in this ${n}. Consider semantic relationships, data flow patterns, and visual clustering. Return JSON: { groups: [{ name: string, nodeIds: string[], color?: string }] }`},p=a.map(g=>{var f;return{id:g.id,type:g.type,label:(f=g.label)==null?void 0:f.slice(0,30),pos:[Math.round(g.x),Math.round(g.y)]}}),o=t.map(g=>({id:g.id,src:g.source,tgt:g.target}));return{fieldLabel:`Diagram (${n})`,fieldType:`diagram:${r}`,fieldValue:JSON.stringify({nodes:p,edges:o}),schema:{diagramType:n,mode:r,nodeCount:a.length,edgeCount:t.length,containerSize:i==null?void 0:i.containerSize},customPrompt:s[r]}}function Ut(a,t,i){const r=c.useMemo(()=>Ze(a,t,i),[JSON.stringify(a),JSON.stringify(t),i==null?void 0:i.mode,i==null?void 0:i.diagramType]);return V(r,{...i,disabled:a.length===0||(i==null?void 0:i.disabled)})}function et(a,t){const i=(t==null?void 0:t.mode)??"generate",r=(t==null?void 0:t.presentationType)??"business",n=(t==null?void 0:t.duration)??15,s=Math.ceil(n/2),p={generate:`You are a presentation designer. Create a ${r} presentation outline based on: "${a}". Target audience: ${(t==null?void 0:t.audience)??"general"}. Duration: ${n} minutes (~${s} slides). Return JSON: { title: string, slides: [{ title: string, layout: 'title'|'content'|'two-column'|'chart'|'image', bullets?: string[], chartType?: string, speakerNotes?: string }] }. Include: clear slide titles, 3-5 bullet points per content slide, and brief speaker notes.`,summarize:`You are a presentation optimizer. Summarize this presentation to be more concise: "${a}". Reduce slide count by 30% while preserving key messages. Return JSON: { summary: string, reducedSlides: [{ title: string, keyPoints: string[] }] }`,expand:`You are a presentation expert. Expand this brief outline into a detailed presentation: "${a}". Add supporting details, examples, and transitions. Target: ${s} slides. Return JSON: { slides: [{ title: string, content: string, transitions?: string, animations?: string[] }] }`,improve:`You are a presentation coach. Review and improve this presentation structure: "${a}". Suggest: better flow, stronger opening/closing, clearer data visualization. Return JSON: { improvements: [{ slide: number, issue: string, suggestion: string }], score: number }`};return{fieldLabel:`Presentation (${r})`,fieldType:`presentation:${i}`,fieldValue:a,schema:{presentationType:r,mode:i,duration:n,slideCount:s,audience:t==null?void 0:t.audience,hasData:(t==null?void 0:t.dataContext)!=null},customPrompt:p[i]}}function Ht(a,t){const i=c.useMemo(()=>et(a,t),[a,t==null?void 0:t.mode,t==null?void 0:t.presentationType,t==null?void 0:t.duration,t==null?void 0:t.audience]);return V(i,{...t,disabled:!a||(t==null?void 0:t.disabled)})}function tt(a,t){var n;const i=(t==null?void 0:t.mode)??"all",r={alignment:"Analyze element alignment on this slide. Suggest adjustments to create visual harmony. Return JSON: { suggestions: [{ elementIndex: number, issue: string, fixX?: number, fixY?: number }] }",contrast:"Analyze color contrast and readability. Suggest improvements for accessibility (WCAG AA). Return JSON: { suggestions: [{ area: string, currentContrast: number, suggestedFix: string }] }",spacing:"Analyze whitespace and element spacing. Apply the rule of thirds and consistent margins. Return JSON: { suggestions: [{ elementIndex: number, issue: string, suggestedMargin: number }] }",typography:"Analyze typography: hierarchy, font sizes, line heights, readability. Return JSON: { suggestions: [{ area: string, issue: string, suggestedFontSize?: number }] }",all:"Perform a complete design review of this slide. Check alignment, contrast, spacing, and typography. Return JSON: { score: number, suggestions: [{ category: string, issue: string, fix: string }] }. Prioritize issues by impact on visual clarity."};return{fieldLabel:a.title??"Slide Design",fieldType:`slide-design:${i}`,fieldValue:JSON.stringify(a),schema:{mode:i,hasElements:(((n=a.elements)==null?void 0:n.length)??0)>0,layout:a.layout,brandColors:t==null?void 0:t.brandColors},customPrompt:r[i]}}function Wt(a,t){const i=c.useMemo(()=>tt(a,t),[JSON.stringify(a),t==null?void 0:t.mode,JSON.stringify(t==null?void 0:t.brandColors)]);return V(i,t)}function Gt(a,t,i){const r=c.forwardRef((n,s)=>{const{aiEnabled:p=!0,aiPosition:o="right",aiPrompt:g,aiDebounceMs:f=500,aiShowOnHover:j=!1,aiTriggerIcon:w,...N}=n,S=c.useMemo(()=>{const $=t(N);return g&&($.customPrompt=g),$},[N,g]);return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsx(a,{...N,ref:s}),p&&e.jsx(ke,{context:S,position:o,debounceMs:f,showOnHover:j,triggerIcon:w})]})});return r.displayName=i??`withAIHint(${a.displayName??a.name??"Component"})`,r}function Vt(a){return Ne(a.label??"Text",a.value,{placeholder:a.placeholder,maxLength:a.maxLength})}function Kt(a){return Ce(a.label??"Number",a.value,{min:a.min,max:a.max,step:a.step})}function Yt(a){return Se(a.label??"Select",a.value,{options:a.options,multiple:a.multiple})}function Xt(a){return Te(a.label??"Date",a.value,{min:a.min,max:a.max})}function Qt(a){return Ae(a.label??"Color",a.value)}const Zt={id:crypto.randomUUID(),name:"New ML Project",type:"classification",status:"draft",datasets:[],experiments:[],models:[],createdAt:new Date,updatedAt:new Date},Ie={classification:[{id:"logistic-regression",name:"Logistic Regression"},{id:"random-forest",name:"Random Forest"},{id:"gradient-boosting",name:"Gradient Boosting"},{id:"svm",name:"Support Vector Machine"},{id:"neural-network",name:"Neural Network"},{id:"xgboost",name:"XGBoost"}],regression:[{id:"linear-regression",name:"Linear Regression"},{id:"ridge",name:"Ridge Regression"},{id:"lasso",name:"Lasso Regression"},{id:"random-forest-reg",name:"Random Forest"},{id:"gradient-boosting-reg",name:"Gradient Boosting"}],clustering:[{id:"kmeans",name:"K-Means"},{id:"dbscan",name:"DBSCAN"},{id:"hierarchical",name:"Hierarchical Clustering"}]},ze={classification:["accuracy","precision","recall","f1-score","auc-roc"],regression:["mse","rmse","mae","r2"],clustering:["silhouette","calinski-harabasz","davies-bouldin"]},ei=({project:a,onProjectChange:t,onExperimentRun:i,onModelDeploy:r,className:n=""})=>{var R;const[s,p]=c.useState(a||Zt),[o,g]=c.useState("data"),[f,j]=c.useState(null),[w,N]=c.useState(null),[S,$]=c.useState(null),[k,P]=c.useState(!1),[h,d]=c.useState({algorithm:"",hyperparameters:{},preprocessing:[]}),y=c.useCallback(l=>{const x={...s,...l,updatedAt:new Date};p(x),t==null||t(x)},[s,t]),C=async l=>{for(const x of Array.from(l)){const M={id:crypto.randomUUID(),name:x.name.replace(/\.[^.]+$/,""),type:"tabular",source:{type:"file",uri:x.name},size:x.size,rowCount:0,columns:[],splits:[{name:"train",ratio:.8,rowCount:0},{name:"validation",ratio:.1,rowCount:0},{name:"test",ratio:.1,rowCount:0}],createdAt:new Date};if(x.name.endsWith(".csv")){const D=(await x.text()).split(`
|
|
11
|
-
`),J=D[0].split(",").map(H=>H.trim());M.rowCount=D.length-1,M.columns=J.map(H=>({name:H,type:"text",nullable:!0,unique:0,missing:0})),M.splits=M.splits.map(H=>({...H,rowCount:Math.floor(M.rowCount*H.ratio)}))}y({datasets:[...s.datasets,M]})}},m=l=>{y({datasets:s.datasets.filter(x=>x.id!==l)}),f===l&&j(null)},_=async()=>{if(!h.algorithm||!f)return;const l={id:crypto.randomUUID(),name:`Experiment ${s.experiments.length+1}`,status:"pending",config:h,metrics:[],artifacts:[],logs:[]};if(y({experiments:[...s.experiments,l]}),P(!1),i){y({experiments:s.experiments.map(x=>x.id===l.id?{...x,status:"running",startedAt:new Date}:x)});try{await i(l);const x=(ze[s.type]||ze.classification).map(M=>({name:M,value:Math.random()*.3+.7,split:"validation"}));y({experiments:s.experiments.map(M=>M.id===l.id?{...M,status:"completed",completedAt:new Date,metrics:x}:M)})}catch{y({experiments:s.experiments.map(x=>x.id===l.id?{...x,status:"failed"}:x)})}}},b=l=>{const x=s.experiments.find(z=>z.id===l);if(!x)return;const M={id:crypto.randomUUID(),name:`Model from ${x.name}`,version:"1.0.0",algorithm:x.config.algorithm,experimentId:l,status:"registered",metrics:x.metrics,size:Math.floor(Math.random()*100)*1024*1024,artifacts:[],deployments:[],createdAt:new Date};y({models:[...s.models,M]})},u=async l=>{const x=s.models.find(z=>z.id===l);if(!x||!r)return;const M=await r(x);y({models:s.models.map(z=>z.id===l?{...z,status:"production",deployments:[...z.deployments,M]}:z)})},v=l=>l<1024?`${l} B`:l<1024*1024?`${(l/1024).toFixed(1)} KB`:l<1024*1024*1024?`${(l/1024/1024).toFixed(1)} MB`:`${(l/1024/1024/1024).toFixed(1)} GB`,A=l=>{switch(l){case"completed":case"production":case"running":return"status-badge--success";case"pending":case"staging":return"status-badge--warning";case"failed":return"status-badge--error";default:return""}};return e.jsxs("div",{className:`nice-ml-studio ${n}`,children:[e.jsxs("header",{className:"ml-studio__header",children:[e.jsxs("div",{className:"header__info",children:[e.jsx("input",{type:"text",value:s.name,onChange:l=>y({name:l.target.value}),className:"project-name-input"}),e.jsxs("select",{value:s.type,onChange:l=>y({type:l.target.value}),className:"project-type-select",children:[e.jsx("option",{value:"classification",children:"Classification"}),e.jsx("option",{value:"regression",children:"Regression"}),e.jsx("option",{value:"clustering",children:"Clustering"}),e.jsx("option",{value:"object-detection",children:"Object Detection"}),e.jsx("option",{value:"nlp",children:"NLP"}),e.jsx("option",{value:"time-series",children:"Time Series"})]})]}),e.jsx("div",{className:"header__tabs",children:["data","experiments","models","deploy"].map(l=>e.jsx("button",{className:`tab-button ${o===l?"tab-button--active":""}`,onClick:()=>g(l),children:l.charAt(0).toUpperCase()+l.slice(1)},l))})]}),e.jsxs("div",{className:"ml-studio__content",children:[o==="data"&&e.jsxs("div",{className:"data-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h2",{children:"Datasets"}),e.jsxs("label",{className:"upload-button",children:[e.jsx("input",{type:"file",multiple:!0,accept:".csv,.json,.parquet",onChange:l=>l.target.files&&C(l.target.files),hidden:!0}),"+ Upload Dataset"]})]}),e.jsx("div",{className:"datasets-grid",children:s.datasets.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx("span",{className:"icon",children:"📊"}),e.jsx("p",{children:"No datasets uploaded yet"}),e.jsx("p",{className:"hint",children:"Upload CSV, JSON, or Parquet files to get started"})]}):s.datasets.map(l=>e.jsxs("div",{className:`dataset-card ${f===l.id?"dataset-card--selected":""}`,onClick:()=>j(l.id),children:[e.jsxs("div",{className:"card-header",children:[e.jsx("span",{className:"dataset-icon",children:"📁"}),e.jsx("h3",{children:l.name}),e.jsx("button",{className:"remove-button",onClick:x=>{x.stopPropagation(),m(l.id)},children:"×"})]}),e.jsxs("div",{className:"card-stats",children:[e.jsxs("span",{children:[l.rowCount.toLocaleString()," rows"]}),e.jsxs("span",{children:[l.columns.length," columns"]}),e.jsx("span",{children:v(l.size)})]}),e.jsx("div",{className:"splits-bar",children:l.splits.map(x=>e.jsx("div",{className:`split split--${x.name}`,style:{width:`${x.ratio*100}%`},title:`${x.name}: ${(x.ratio*100).toFixed(0)}%`},x.name))})]},l.id))}),f&&e.jsx("div",{className:"dataset-details",children:(()=>{const l=s.datasets.find(x=>x.id===f);return l?e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:"Columns"}),e.jsxs("table",{className:"columns-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Type"}),e.jsx("th",{children:"Missing"}),e.jsx("th",{children:"Unique"})]})}),e.jsx("tbody",{children:l.columns.map(x=>e.jsxs("tr",{children:[e.jsx("td",{children:x.name}),e.jsx("td",{children:e.jsxs("select",{value:x.type,onChange:M=>{y({datasets:s.datasets.map(z=>z.id===l.id?{...z,columns:z.columns.map(D=>D.name===x.name?{...D,type:M.target.value}:D)}:z)})},children:[e.jsx("option",{value:"numeric",children:"Numeric"}),e.jsx("option",{value:"categorical",children:"Categorical"}),e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"datetime",children:"DateTime"}),e.jsx("option",{value:"boolean",children:"Boolean"})]})}),e.jsx("td",{children:x.missing}),e.jsx("td",{children:x.unique})]},x.name))})]})]}):null})()})]}),o==="experiments"&&e.jsxs("div",{className:"experiments-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h2",{children:"Experiments"}),e.jsx("button",{className:"primary-button",onClick:()=>P(!0),disabled:s.datasets.length===0,children:"+ New Experiment"})]}),k&&e.jsxs("div",{className:"new-experiment-form",children:[e.jsx("h3",{children:"Configure Experiment"}),e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{children:["Dataset",e.jsxs("select",{value:f||"",onChange:l=>j(l.target.value),children:[e.jsx("option",{value:"",children:"Select dataset..."}),s.datasets.map(l=>e.jsx("option",{value:l.id,children:l.name},l.id))]})]}),e.jsxs("label",{children:["Algorithm",e.jsxs("select",{value:h.algorithm,onChange:l=>d({...h,algorithm:l.target.value}),children:[e.jsx("option",{value:"",children:"Select algorithm..."}),(Ie[s.type]||Ie.classification).map(l=>e.jsx("option",{value:l.id,children:l.name},l.id))]})]}),f&&e.jsxs("label",{children:["Target Column",e.jsxs("select",{value:h.targetColumn||"",onChange:l=>d({...h,targetColumn:l.target.value}),children:[e.jsx("option",{value:"",children:"Select target..."}),(R=s.datasets.find(l=>l.id===f))==null?void 0:R.columns.map(l=>e.jsx("option",{value:l.name,children:l.name},l.name))]})]})]}),e.jsxs("div",{className:"form-actions",children:[e.jsx("button",{className:"secondary-button",onClick:()=>P(!1),children:"Cancel"}),e.jsx("button",{className:"primary-button",onClick:_,disabled:!h.algorithm||!f,children:"Run Experiment"})]})]}),e.jsx("div",{className:"experiments-list",children:s.experiments.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx("span",{className:"icon",children:"🧪"}),e.jsx("p",{children:"No experiments yet"}),e.jsx("p",{className:"hint",children:"Create an experiment to train and evaluate models"})]}):s.experiments.map(l=>e.jsxs("div",{className:`experiment-card ${w===l.id?"experiment-card--selected":""}`,onClick:()=>N(l.id),children:[e.jsxs("div",{className:"card-header",children:[e.jsx("h3",{children:l.name}),e.jsx("span",{className:`status-badge ${A(l.status)}`,children:l.status})]}),e.jsxs("div",{className:"card-meta",children:[e.jsxs("span",{children:["Algorithm: ",l.config.algorithm]}),l.duration&&e.jsxs("span",{children:["Duration: ",Math.round(l.duration),"s"]})]}),l.metrics.length>0&&e.jsx("div",{className:"metrics-row",children:l.metrics.slice(0,3).map(x=>e.jsxs("div",{className:"metric-item",children:[e.jsx("span",{className:"metric-name",children:x.name}),e.jsxs("span",{className:"metric-value",children:[(x.value*100).toFixed(1),"%"]})]},x.name))}),l.status==="completed"&&e.jsx("button",{className:"action-button",onClick:x=>{x.stopPropagation(),b(l.id)},children:"Register Model"})]},l.id))})]}),o==="models"&&e.jsxs("div",{className:"models-panel",children:[e.jsx("div",{className:"panel-header",children:e.jsx("h2",{children:"Models"})}),e.jsx("div",{className:"models-list",children:s.models.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx("span",{className:"icon",children:"🤖"}),e.jsx("p",{children:"No models registered yet"}),e.jsx("p",{className:"hint",children:"Complete experiments and register models"})]}):s.models.map(l=>e.jsxs("div",{className:`model-card ${S===l.id?"model-card--selected":""}`,onClick:()=>$(l.id),children:[e.jsxs("div",{className:"card-header",children:[e.jsx("h3",{children:l.name}),e.jsx("span",{className:`status-badge ${A(l.status)}`,children:l.status})]}),e.jsxs("div",{className:"card-meta",children:[e.jsxs("span",{children:["Algorithm: ",l.algorithm]}),e.jsxs("span",{children:["Version: ",l.version]}),e.jsxs("span",{children:["Size: ",v(l.size)]})]}),l.metrics.length>0&&e.jsx("div",{className:"metrics-row",children:l.metrics.slice(0,3).map(x=>e.jsxs("div",{className:"metric-item",children:[e.jsx("span",{className:"metric-name",children:x.name}),e.jsxs("span",{className:"metric-value",children:[(x.value*100).toFixed(1),"%"]})]},x.name))}),e.jsxs("div",{className:"card-actions",children:[e.jsx("button",{className:"action-button",children:"Download"}),e.jsx("button",{className:"action-button action-button--primary",onClick:x=>{x.stopPropagation(),u(l.id)},disabled:l.status==="production",children:l.status==="production"?"Deployed":"Deploy"})]})]},l.id))})]}),o==="deploy"&&e.jsxs("div",{className:"deploy-panel",children:[e.jsx("div",{className:"panel-header",children:e.jsx("h2",{children:"Deployments"})}),e.jsx("div",{className:"deployments-list",children:s.models.filter(l=>l.deployments.length>0).length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx("span",{className:"icon",children:"🚀"}),e.jsx("p",{children:"No deployments yet"}),e.jsx("p",{className:"hint",children:"Deploy a model to create inference endpoints"})]}):s.models.filter(l=>l.deployments.length>0).flatMap(l=>l.deployments.map(x=>({model:l,deployment:x}))).map(({model:l,deployment:x})=>e.jsxs("div",{className:"deployment-card",children:[e.jsxs("div",{className:"card-header",children:[e.jsx("h3",{children:x.name}),e.jsx("span",{className:`status-badge ${A(x.status)}`,children:x.status})]}),e.jsxs("div",{className:"card-meta",children:[e.jsxs("span",{children:["Model: ",l.name]}),e.jsxs("span",{children:["Endpoint: ",x.endpoint]})]}),e.jsxs("div",{className:"resources-info",children:[e.jsxs("span",{children:["CPU: ",x.resources.cpu," cores"]}),e.jsxs("span",{children:["Memory: ",x.resources.memory," GB"]}),e.jsxs("span",{children:["Replicas: ",x.resources.replicas]})]})]},x.id))})]})]})]})},ti={id:crypto.randomUUID(),name:"New Labeling Project",type:"classification",dataType:"image",status:"setup",labelSchema:{classes:[],attributes:[]},items:[],collaborators:[],statistics:{totalItems:0,labeled:0,reviewed:0,approved:0,byClass:[]},createdAt:new Date},Le=["#ef4444","#f97316","#f59e0b","#84cc16","#22c55e","#14b8a6","#06b6d4","#3b82f6","#6366f1","#8b5cf6","#a855f7","#d946ef","#ec4899","#f43f5e"],ii=({project:a,onProjectChange:t,onLabelSave:i,onExport:r,className:n=""})=>{var Q;const[s,p]=c.useState(a||ti),[o,g]=c.useState("label"),[f,j]=c.useState(0),[w,N]=c.useState(null),[S,$]=c.useState("select"),[k,P]=c.useState(!1),[h,d]=c.useState(null),[y,C]=c.useState(1),[m,_]=c.useState(!1),[b,u]=c.useState("all"),v=c.useRef(null),A=c.useRef(null),R=s.items[f];c.useEffect(()=>{a&&p(a)},[a]);const l=c.useCallback(T=>{const L={...s,...T};L.statistics={totalItems:L.items.length,labeled:L.items.filter(E=>E.status!=="pending").length,reviewed:L.items.filter(E=>E.status==="review"||E.status==="approved").length,approved:L.items.filter(E=>E.status==="approved").length,byClass:L.labelSchema.classes.map(E=>({classId:E.id,count:L.items.flatMap(O=>O.labels).filter(O=>O.classId===E.id).length}))},p(L),t==null||t(L)},[s,t]),x=()=>{const T={id:crypto.randomUUID(),name:`Class ${s.labelSchema.classes.length+1}`,color:Le[s.labelSchema.classes.length%Le.length],shortcut:String(s.labelSchema.classes.length+1)};l({labelSchema:{...s.labelSchema,classes:[...s.labelSchema.classes,T]}})},M=T=>{l({labelSchema:{...s.labelSchema,classes:s.labelSchema.classes.filter(L=>L.id!==T)},items:s.items.map(L=>({...L,labels:L.labels.filter(E=>E.classId!==T)}))})},z=(T,L)=>{l({labelSchema:{...s.labelSchema,classes:s.labelSchema.classes.map(E=>E.id===T?{...E,...L}:E)}})},D=(T,L)=>{if(!R)return;const E={id:crypto.randomUUID(),classId:T,type:s.type==="classification"?"class":s.type==="bounding-box"?"bbox":"class",data:L||{},createdBy:"current-user",createdAt:new Date},O={...R,labels:[...R.labels,E],status:"labeled"};l({items:s.items.map(F=>F.id===R.id?O:F)}),i==null||i(O)},J=T=>{if(!R)return;const L={...R,labels:R.labels.filter(E=>E.id!==T),status:R.labels.length<=1?"pending":"labeled"};l({items:s.items.map(E=>E.id===R.id?L:E)})},H=T=>{var F;if(S!=="bbox"||!w)return;const L=(F=v.current)==null?void 0:F.getBoundingClientRect();if(!L)return;const E=(T.clientX-L.left)/y,O=(T.clientY-L.top)/y;P(!0),d({x:E,y:O,width:0,height:0})},Y=T=>{var F;if(!k||!h)return;const L=(F=v.current)==null?void 0:F.getBoundingClientRect();if(!L)return;const E=(T.clientX-L.left)/y,O=(T.clientY-L.top)/y;d({...h,width:E-h.x,height:O-h.y})},I=()=>{!k||!h||!w||(P(!1),Math.abs(h.width)>10&&Math.abs(h.height)>10&&D(w,{x:h.width<0?h.x+h.width:h.x,y:h.height<0?h.y+h.height:h.y,width:Math.abs(h.width),height:Math.abs(h.height)}),d(null))},B=T=>{const L=b==="all"?s.items:s.items.filter(O=>O.status===b),E=L.findIndex(O=>O.id===(R==null?void 0:R.id));if(T==="prev"&&E>0){const O=L[E-1];j(s.items.findIndex(F=>F.id===O.id))}else if(T==="next"&&E<L.length-1){const O=L[E+1];j(s.items.findIndex(F=>F.id===O.id))}},q=()=>{if(!R)return;const T={...R,status:"approved"};l({items:s.items.map(L=>L.id===R.id?T:L)}),B("next")},W=()=>{if(!R)return;const T={...R,status:"rejected"};l({items:s.items.map(L=>L.id===R.id?T:L)}),B("next")},U=async T=>{r&&await r(T)};c.useEffect(()=>{const T=L=>{const E=L.key,O=s.labelSchema.classes.find(F=>F.shortcut===E);O&&(s.type==="classification"?(D(O.id),B("next")):N(O.id)),L.key==="ArrowLeft"||L.key==="a"?B("prev"):(L.key==="ArrowRight"||L.key==="d")&&B("next"),L.key==="Enter"?q():L.key==="Backspace"&&W()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[R,s.labelSchema.classes,s.type]);const K=T=>{switch(T){case"approved":return"#22c55e";case"labeled":return"#3b82f6";case"review":return"#f59e0b";case"rejected":return"#ef4444";default:return"#6b7280"}};return e.jsxs("div",{className:`nice-data-labeler ${n}`,children:[e.jsxs("header",{className:"labeler__header",children:[e.jsxs("div",{className:"header__info",children:[e.jsx("input",{type:"text",value:s.name,onChange:T=>l({name:T.target.value}),className:"project-name-input"}),e.jsxs("div",{className:"progress-bar",children:[e.jsx("div",{className:"progress-fill",style:{width:`${s.statistics.labeled/Math.max(s.statistics.totalItems,1)*100}%`}}),e.jsxs("span",{className:"progress-text",children:[s.statistics.labeled," / ",s.statistics.totalItems," labeled"]})]})]}),e.jsx("div",{className:"header__tabs",children:["label","schema","review","export"].map(T=>e.jsx("button",{className:`tab-button ${o===T?"tab-button--active":""}`,onClick:()=>g(T),children:T.charAt(0).toUpperCase()+T.slice(1)},T))}),e.jsx("button",{className:"shortcuts-button",onClick:()=>_(!m),children:"⌨️ Shortcuts"})]}),e.jsxs("div",{className:"labeler__content",children:[o==="label"&&e.jsxs("div",{className:"label-panel",children:[e.jsxs("div",{className:"label-toolbar",children:[e.jsxs("div",{className:"tool-group",children:[e.jsx("button",{className:`tool-button ${S==="select"?"tool-button--active":""}`,onClick:()=>$("select"),children:"↖️ Select"}),(s.type==="bounding-box"||s.type==="multi-label")&&e.jsx("button",{className:`tool-button ${S==="bbox"?"tool-button--active":""}`,onClick:()=>$("bbox"),children:"⬜ Box"}),s.type==="polygon"&&e.jsx("button",{className:`tool-button ${S==="polygon"?"tool-button--active":""}`,onClick:()=>$("polygon"),children:"⬡ Polygon"})]}),e.jsxs("div",{className:"zoom-group",children:[e.jsx("button",{onClick:()=>C(Math.max(.25,y-.25)),children:"-"}),e.jsxs("span",{children:[Math.round(y*100),"%"]}),e.jsx("button",{onClick:()=>C(Math.min(4,y+.25)),children:"+"})]}),e.jsxs("div",{className:"navigation-group",children:[e.jsx("button",{onClick:()=>B("prev"),disabled:f===0,children:"← Prev"}),e.jsxs("span",{children:[f+1," / ",s.items.length]}),e.jsx("button",{onClick:()=>B("next"),disabled:f>=s.items.length-1,children:"Next →"})]})]}),e.jsxs("div",{className:"label-workspace",children:[e.jsx("div",{className:"canvas-container",ref:A,children:R?e.jsxs(e.Fragment,{children:[R.data.type==="image"&&e.jsxs(e.Fragment,{children:[e.jsx("img",{src:R.data.url,alt:"Labeling item",className:"labeling-image",style:{transform:`scale(${y})`}}),e.jsx("canvas",{ref:v,className:"labeling-canvas",onMouseDown:H,onMouseMove:Y,onMouseUp:I,onMouseLeave:I,style:{transform:`scale(${y})`,cursor:S==="bbox"?"crosshair":"default"}}),e.jsxs("div",{className:"annotations-overlay",style:{transform:`scale(${y})`},children:[R.labels.filter(T=>T.type==="bbox"&&T.data.x!==void 0).map(T=>{const L=s.labelSchema.classes.find(E=>E.id===T.classId);return e.jsxs("div",{className:"bbox-annotation",style:{left:T.data.x,top:T.data.y,width:T.data.width,height:T.data.height,borderColor:(L==null?void 0:L.color)||"#ff0000"},children:[e.jsx("span",{className:"bbox-label",style:{backgroundColor:(L==null?void 0:L.color)||"#ff0000"},children:L==null?void 0:L.name}),e.jsx("button",{className:"bbox-remove",onClick:()=>J(T.id),children:"×"})]},T.id)}),h&&e.jsx("div",{className:"bbox-drawing",style:{left:h.width<0?h.x+h.width:h.x,top:h.height<0?h.y+h.height:h.y,width:Math.abs(h.width),height:Math.abs(h.height),borderColor:(Q=s.labelSchema.classes.find(T=>T.id===w))==null?void 0:Q.color}})]})]}),R.data.type==="text"&&e.jsx("div",{className:"text-labeling",children:e.jsx("p",{className:"text-content",children:R.data.text})})]}):e.jsxs("div",{className:"empty-state",children:[e.jsx("span",{className:"icon",children:"📋"}),e.jsx("p",{children:"No items to label"})]})}),e.jsxs("aside",{className:"class-sidebar",children:[e.jsx("h3",{children:"Classes"}),e.jsx("div",{className:"class-list",children:s.labelSchema.classes.map(T=>e.jsxs("button",{className:`class-button ${w===T.id?"class-button--active":""}`,style:{borderLeftColor:T.color},onClick:()=>{s.type==="classification"?(D(T.id),B("next")):N(T.id)},children:[e.jsx("span",{className:"class-color",style:{backgroundColor:T.color}}),e.jsx("span",{className:"class-name",children:T.name}),T.shortcut&&e.jsx("span",{className:"class-shortcut",children:T.shortcut})]},T.id))}),R&&R.labels.length>0&&e.jsxs("div",{className:"current-labels",children:[e.jsx("h4",{children:"Labels"}),R.labels.map(T=>{const L=s.labelSchema.classes.find(E=>E.id===T.classId);return e.jsxs("div",{className:"label-item",children:[e.jsx("span",{className:"label-color",style:{backgroundColor:L==null?void 0:L.color}}),e.jsx("span",{className:"label-name",children:L==null?void 0:L.name}),e.jsx("button",{onClick:()=>J(T.id),children:"×"})]},T.id)})]}),o==="label"&&R&&e.jsxs("div",{className:"label-actions",children:[e.jsx("button",{className:"approve-button",onClick:q,children:"✓ Approve"}),e.jsx("button",{className:"reject-button",onClick:W,children:"✗ Reject"})]})]})]})]}),o==="schema"&&e.jsxs("div",{className:"schema-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h2",{children:"Label Schema"}),e.jsx("button",{className:"primary-button",onClick:x,children:"+ Add Class"})]}),e.jsxs("div",{className:"schema-settings",children:[e.jsxs("label",{children:["Labeling Type",e.jsxs("select",{value:s.type,onChange:T=>l({type:T.target.value}),children:[e.jsx("option",{value:"classification",children:"Single Classification"}),e.jsx("option",{value:"multi-label",children:"Multi-Label Classification"}),e.jsx("option",{value:"bounding-box",children:"Bounding Box"}),e.jsx("option",{value:"polygon",children:"Polygon"}),e.jsx("option",{value:"segmentation",children:"Segmentation"}),e.jsx("option",{value:"ner",children:"Named Entity Recognition"})]})]}),e.jsxs("label",{children:["Data Type",e.jsxs("select",{value:s.dataType,onChange:T=>l({dataType:T.target.value}),children:[e.jsx("option",{value:"image",children:"Image"}),e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"audio",children:"Audio"}),e.jsx("option",{value:"video",children:"Video"})]})]})]}),e.jsx("div",{className:"classes-list",children:s.labelSchema.classes.map((T,L)=>e.jsxs("div",{className:"class-editor",children:[e.jsx("input",{type:"color",value:T.color,onChange:E=>z(T.id,{color:E.target.value}),className:"color-picker"}),e.jsx("input",{type:"text",value:T.name,onChange:E=>z(T.id,{name:E.target.value}),className:"class-name-input",placeholder:"Class name"}),e.jsx("input",{type:"text",value:T.shortcut||"",onChange:E=>z(T.id,{shortcut:E.target.value}),className:"shortcut-input",placeholder:"Key",maxLength:1}),e.jsx("button",{className:"remove-class-button",onClick:()=>M(T.id),children:"🗑️"})]},T.id))}),e.jsxs("div",{className:"guidelines-section",children:[e.jsx("h3",{children:"Labeling Guidelines"}),e.jsx("textarea",{value:s.guidelines||"",onChange:T=>l({guidelines:T.target.value}),placeholder:"Enter labeling guidelines for annotators...",rows:6})]})]}),o==="review"&&e.jsxs("div",{className:"review-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h2",{children:"Review Labels"}),e.jsx("div",{className:"filter-group",children:e.jsxs("select",{value:b,onChange:T=>u(T.target.value),children:[e.jsx("option",{value:"all",children:"All Items"}),e.jsx("option",{value:"labeled",children:"Labeled"}),e.jsx("option",{value:"review",children:"Needs Review"}),e.jsx("option",{value:"approved",children:"Approved"}),e.jsx("option",{value:"rejected",children:"Rejected"})]})})]}),e.jsx("div",{className:"items-grid",children:s.items.filter(T=>b==="all"||T.status===b).map((T,L)=>{var E;return e.jsxs("div",{className:`item-card ${f===s.items.indexOf(T)?"item-card--active":""}`,onClick:()=>{j(s.items.indexOf(T)),g("label")},children:[T.data.type==="image"&&e.jsx("img",{src:T.data.url,alt:`Item ${L+1}`,className:"item-thumbnail"}),T.data.type==="text"&&e.jsxs("p",{className:"item-text-preview",children:[(E=T.data.text)==null?void 0:E.slice(0,100),"..."]}),e.jsxs("div",{className:"item-footer",children:[e.jsx("span",{className:"status-dot",style:{backgroundColor:K(T.status)}}),e.jsxs("span",{children:[T.labels.length," labels"]})]})]},T.id)})})]}),o==="export"&&e.jsxs("div",{className:"export-panel",children:[e.jsx("div",{className:"panel-header",children:e.jsx("h2",{children:"Export Labels"})}),e.jsxs("div",{className:"export-stats",children:[e.jsxs("div",{className:"stat-card",children:[e.jsx("span",{className:"stat-value",children:s.statistics.totalItems}),e.jsx("span",{className:"stat-label",children:"Total Items"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("span",{className:"stat-value",children:s.statistics.labeled}),e.jsx("span",{className:"stat-label",children:"Labeled"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("span",{className:"stat-value",children:s.statistics.approved}),e.jsx("span",{className:"stat-label",children:"Approved"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("span",{className:"stat-value",children:s.labelSchema.classes.length}),e.jsx("span",{className:"stat-label",children:"Classes"})]})]}),e.jsxs("div",{className:"export-formats",children:[e.jsx("h3",{children:"Export Format"}),e.jsxs("div",{className:"format-grid",children:[e.jsxs("button",{className:"format-button",onClick:()=>U("coco"),children:[e.jsx("span",{className:"format-icon",children:"📦"}),e.jsx("span",{className:"format-name",children:"COCO JSON"}),e.jsx("span",{className:"format-desc",children:"Common format for object detection"})]}),e.jsxs("button",{className:"format-button",onClick:()=>U("voc"),children:[e.jsx("span",{className:"format-icon",children:"📄"}),e.jsx("span",{className:"format-name",children:"Pascal VOC"}),e.jsx("span",{className:"format-desc",children:"XML format for bounding boxes"})]}),e.jsxs("button",{className:"format-button",onClick:()=>U("yolo"),children:[e.jsx("span",{className:"format-icon",children:"⚡"}),e.jsx("span",{className:"format-name",children:"YOLO"}),e.jsx("span",{className:"format-desc",children:"Text format for YOLO models"})]}),e.jsxs("button",{className:"format-button",onClick:()=>U("csv"),children:[e.jsx("span",{className:"format-icon",children:"📊"}),e.jsx("span",{className:"format-name",children:"CSV"}),e.jsx("span",{className:"format-desc",children:"Tabular format for classification"})]})]})]}),e.jsxs("div",{className:"class-distribution",children:[e.jsx("h3",{children:"Class Distribution"}),e.jsx("div",{className:"distribution-bars",children:s.statistics.byClass.map(T=>{const L=s.labelSchema.classes.find(O=>O.id===T.classId),E=T.count/Math.max(s.statistics.labeled,1)*100;return e.jsxs("div",{className:"distribution-row",children:[e.jsx("span",{className:"class-name",style:{color:L==null?void 0:L.color},children:L==null?void 0:L.name}),e.jsx("div",{className:"bar-container",children:e.jsx("div",{className:"bar-fill",style:{width:`${E}%`,backgroundColor:L==null?void 0:L.color}})}),e.jsx("span",{className:"count",children:T.count})]},T.classId)})})]})]})]}),m&&e.jsx("div",{className:"shortcuts-modal",children:e.jsxs("div",{className:"modal-content",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Keyboard Shortcuts"}),e.jsx("button",{onClick:()=>_(!1),children:"×"})]}),e.jsxs("div",{className:"shortcuts-list",children:[e.jsxs("div",{className:"shortcut-item",children:[e.jsx("span",{className:"keys",children:"← / A"}),e.jsx("span",{className:"description",children:"Previous item"})]}),e.jsxs("div",{className:"shortcut-item",children:[e.jsx("span",{className:"keys",children:"→ / D"}),e.jsx("span",{className:"description",children:"Next item"})]}),e.jsxs("div",{className:"shortcut-item",children:[e.jsx("span",{className:"keys",children:"Enter"}),e.jsx("span",{className:"description",children:"Approve item"})]}),e.jsxs("div",{className:"shortcut-item",children:[e.jsx("span",{className:"keys",children:"Backspace"}),e.jsx("span",{className:"description",children:"Reject item"})]}),s.labelSchema.classes.map(T=>T.shortcut&&e.jsxs("div",{className:"shortcut-item",children:[e.jsx("span",{className:"keys",children:T.shortcut}),e.jsxs("span",{className:"description",children:["Label as ",T.name]})]},T.id))]})]})})]})},ai={id:crypto.randomUUID(),name:"Model Endpoint",modelId:"",modelVersion:"1.0.0",status:"stopped",url:"",authentication:{type:"api-key"},metrics:{requestsTotal:0,requestsPerSecond:0,latencyP50:0,latencyP95:0,latencyP99:0,errorRate:0,successRate:100},logs:[]},ri=({endpoint:a,onInference:t,showMetrics:i=!0,showLogs:r=!0,className:n=""})=>{const[s,p]=c.useState(a||ai),[o,g]=c.useState("test"),[f,j]=c.useState("text"),[w,N]=c.useState(""),[S,$]=c.useState("{}"),[k,P]=c.useState(null),[h,d]=c.useState({temperature:.7,topK:50,topP:.9,maxTokens:256,threshold:.5}),[y,C]=c.useState(null),[m,_]=c.useState(!1),[b,u]=c.useState(null),[v,A]=c.useState([]),[R,l]=c.useState(null),x=c.useRef(null),M=I=>{var q;const B=(q=I.target.files)==null?void 0:q[0];if(B){const W=new FileReader;W.onload=U=>{var K;P((K=U.target)==null?void 0:K.result)},W.readAsDataURL(B)}},z=async()=>{if(!t){u("No inference handler provided");return}_(!0),u(null),C(null);const I=[];switch(f){case"text":I.push({type:"text",data:w});break;case"image":k&&I.push({type:"image",data:k});break;case"json":try{I.push({type:"json",data:JSON.parse(S)})}catch{u("Invalid JSON input"),_(!1);return}break;case"tabular":try{I.push({type:"tabular",data:JSON.parse(S)})}catch{u("Invalid tabular data"),_(!1);return}break}const B={inputs:I,parameters:h};try{const q=Date.now(),W=await t(B),U=Date.now()-q;C(W),p(K=>({...K,metrics:{...K.metrics,requestsTotal:K.metrics.requestsTotal+1,latencyP50:(K.metrics.latencyP50+U)/2},logs:[{timestamp:new Date,requestId:W.requestId,duration:U,status:"success",inputSize:JSON.stringify(I).length,outputSize:JSON.stringify(W.predictions).length},...K.logs.slice(0,99)]}))}catch(q){const W=q instanceof Error?q.message:"Inference failed";u(W),p(U=>({...U,metrics:{...U.metrics,requestsTotal:U.metrics.requestsTotal+1,errorRate:(U.metrics.errorRate*U.metrics.requestsTotal+1)/(U.metrics.requestsTotal+1)},logs:[{timestamp:new Date,requestId:crypto.randomUUID(),duration:0,status:"error",inputSize:JSON.stringify(I).length,outputSize:0,error:W},...U.logs.slice(0,99)]}))}finally{_(!1)}},D=async I=>{if(t){l(0),A([]);for(let B=0;B<I.length;B++){const q={inputs:[I[B]],parameters:h};try{const W=await t(q);A(U=>[...U,W])}catch(W){console.error("Batch item failed:",W)}l((B+1)/I.length*100)}l(null)}},J=I=>I<1e3?`${I.toFixed(0)}ms`:`${(I/1e3).toFixed(2)}s`,H=I=>I.toLocaleTimeString(),Y=(I,B)=>e.jsxs("div",{className:"prediction-item",children:[I.label&&e.jsxs("div",{className:"prediction-label",children:[e.jsx("span",{className:"label-name",children:I.label}),I.confidence!==void 0&&e.jsxs("span",{className:"confidence-badge",style:{backgroundColor:`hsl(${I.confidence*120}, 70%, 40%)`},children:[(I.confidence*100).toFixed(1),"%"]})]}),I.score!==void 0&&e.jsxs("div",{className:"prediction-score",children:[e.jsx("span",{className:"score-label",children:"Score:"}),e.jsx("span",{className:"score-value",children:I.score.toFixed(4)})]}),I.text&&e.jsx("div",{className:"prediction-text",children:e.jsx("pre",{children:I.text})}),I.bbox&&e.jsx("div",{className:"prediction-bbox",children:e.jsxs("span",{children:["Box: (",I.bbox.x,", ",I.bbox.y,") - ",I.bbox.width,"×",I.bbox.height]})}),I.raw!==void 0&&I.raw!==null&&e.jsxs("details",{className:"raw-output",children:[e.jsx("summary",{children:"Raw Output"}),e.jsx("pre",{children:JSON.stringify(I.raw,null,2)})]})]},B);return e.jsxs("div",{className:`nice-model-inference ${n}`,children:[e.jsxs("header",{className:"inference__header",children:[e.jsxs("div",{className:"header__info",children:[e.jsx("h2",{children:s.name}),e.jsx("span",{className:`status-badge status-badge--${s.status}`,children:s.status})]}),e.jsxs("div",{className:"header__tabs",children:[e.jsx("button",{className:`tab-button ${o==="test"?"tab-button--active":""}`,onClick:()=>g("test"),children:"Test"}),e.jsx("button",{className:`tab-button ${o==="batch"?"tab-button--active":""}`,onClick:()=>g("batch"),children:"Batch"}),i&&e.jsx("button",{className:`tab-button ${o==="metrics"?"tab-button--active":""}`,onClick:()=>g("metrics"),children:"Metrics"}),r&&e.jsx("button",{className:`tab-button ${o==="logs"?"tab-button--active":""}`,onClick:()=>g("logs"),children:"Logs"})]})]}),e.jsxs("div",{className:"inference__content",children:[o==="test"&&e.jsxs("div",{className:"test-panel",children:[e.jsxs("div",{className:"input-section",children:[e.jsx("div",{className:"input-type-selector",children:["text","image","json","tabular"].map(I=>e.jsx("button",{className:`type-button ${f===I?"type-button--active":""}`,onClick:()=>j(I),children:I.charAt(0).toUpperCase()+I.slice(1)},I))}),e.jsxs("div",{className:"input-area",children:[f==="text"&&e.jsx("textarea",{value:w,onChange:I=>N(I.target.value),placeholder:"Enter text input...",rows:6,className:"text-input"}),f==="image"&&e.jsx("div",{className:"image-input",children:k?e.jsxs("div",{className:"image-preview",children:[e.jsx("img",{src:k,alt:"Input preview"}),e.jsx("button",{className:"clear-button",onClick:()=>P(null),children:"Clear"})]}):e.jsxs("label",{className:"upload-zone",children:[e.jsx("input",{ref:x,type:"file",accept:"image/*",onChange:M,hidden:!0}),e.jsx("span",{className:"upload-icon",children:"🖼️"}),e.jsx("span",{children:"Click or drag to upload image"})]})}),(f==="json"||f==="tabular")&&e.jsx("textarea",{value:S,onChange:I=>$(I.target.value),placeholder:f==="json"?`{
|
|
8
|
+
`);return{fieldLabel:`Code editor (${i})`,fieldType:"code-editor",fieldValue:s||a,schema:{language:i,...t!=null&&t.framework?{framework:t.framework}:{},...(t==null?void 0:t.cursorLine)!=null?{cursorLine:t.cursorLine,cursorCol:t.cursorCol}:{}},customPrompt:`Language: ${i}${t!=null&&t.framework?`, framework: ${t.framework}`:""}.
|
|
9
|
+
Provide a concise inline completion or improvement hint for the code near the cursor. Limit response to ${(t==null?void 0:t.maxSuggestLines)??5} lines of code. If unsure, suggest the most idiomatic approach for this language/framework.`}}function Ge(i,a,t){var s;const r=(t==null?void 0:t.mode)??"grammar",n={seo:"Analyze this HTML for SEO: missing meta tags, heading hierarchy (h1→h2→h3), keyword density, image alt attributes. Return a prioritized list of improvements.",accessibility:"Audit this HTML for WCAG 2.1 AA issues: missing aria labels, alt text, heading structure, color contrast hints, keyboard navigation. List specific fixes.",grammar:"Fix grammar, punctuation, and writing style in the visible text content. Return the corrected text only (no HTML tags in response).",cleanup:"Clean up malformed, redundant, or overly nested HTML. Simplify structure while preserving semantics and content."};return{fieldLabel:i,fieldType:"html-editor",fieldValue:a==null?void 0:a.slice(0,2e3),schema:{mode:r,...(s=t==null?void 0:t.targetKeywords)!=null&&s.length?{targetKeywords:t.targetKeywords}:{},...t!=null&&t.locale?{locale:t.locale}:{}},customPrompt:n[r]}}function Ve(i,a){const t=(a==null?void 0:a.mode)??"tag",r=`"${i}"`+((a==null?void 0:a.bpm)!=null?`, BPM: ${a.bpm}`:"")+(a!=null&&a.key?`, Key: ${a.key}`:"")+(a!=null&&a.genre?`, Genre: ${a.genre}`:"")+((a==null?void 0:a.duration)!=null?`, Duration: ${a.duration}s`:""),n={tag:`Audio: ${r}. Suggest genre tags, mood descriptors and playlist categories. Return as JSON array of strings.`,bpm:`Audio: ${r}. Suggest likely BPM range and musical key based on metadata. Return as JSON: { bpm: number, key: string }.`,mix:`Track: ${r}. Suggest EQ curve (JSON array of {freq, gain, q}), compression settings, and 2-3 compatible tracks for mixing.`,transcribe:"Return a transcription of the spoken audio content as JSON: { transcript: string, language: string, confidence: number }."};return{fieldLabel:`Audio: ${i}`,fieldType:"audio",schema:{mode:t,...(a==null?void 0:a.bpm)!=null?{bpm:a.bpm}:{},...a!=null&&a.key?{key:a.key}:{},...(a==null?void 0:a.duration)!=null?{duration:a.duration}:{},...a!=null&&a.genre?{genre:a.genre}:{}},customPrompt:n[t]}}function Ke(i,a){var s;const t=(a==null?void 0:a.mode)??"material",r=(a==null?void 0:a.targetDevice)??"web",n={material:`Scene "${i}", ${(a==null?void 0:a.meshCount)??"?"} meshes. Materials: ${((s=a==null?void 0:a.materials)==null?void 0:s.join(", "))||"none"}. Suggest PBR properties (roughness, metalness, baseColor) and texture maps for each material.`,optimize:`Scene "${i}", triangles: ${(a==null?void 0:a.triangleCount)??"?"}, target: ${r}. Identify budget issues and suggest LOD levels, mesh merging, and texture atlas strategy.`,lighting:`Scene "${i}", target: ${r}. Suggest a complete lighting setup (types, intensity, color, shadow settings) for realistic rendering.`,animation:`Rig in scene "${i}". Suggest animation approach (FK/IK, bone count), keyframe timing and easing curves for natural movement.`};return{fieldLabel:`3D scene: ${i}`,fieldType:"3d-scene",schema:{mode:t,...(a==null?void 0:a.meshCount)!=null?{meshes:a.meshCount}:{},...(a==null?void 0:a.triangleCount)!=null?{triangles:a.triangleCount}:{},...a!=null&&a.targetDevice?{target:a.targetDevice}:{}},customPrompt:n[t]}}function Ye(i,a){const t=(a==null?void 0:a.mode)??"palette",r=(a==null?void 0:a.width)!=null?`${a.width}×${a.height??"?"}px`:"unknown dimensions",n={filter:`Image "${i}" (${r}). Suggest CSS/SVG filter parameters (brightness, contrast, saturate, hue-rotate, blur) as JSON: { brightness, contrast, saturate, hueRotate, blur }.`,palette:`Image "${i}". Extract or suggest a harmonious 5-color palette as JSON: { primary, secondary, accent, background, text }.`,upscale:`Image "${i}" at ${r}. Recommend upscaling strategy: model (ESRGAN/RealSR/SRCNN), scale factor, and expected quality gain.`,"style-transfer":`Image "${i}", target style: "${(a==null?void 0:a.targetStyle)??"artistic"}". Suggest style-transfer settings as JSON: { contentWeight, styleWeight, iterations, patchSize }.`};return{fieldLabel:`Graphics: ${i}`,fieldType:"graphics",schema:{mode:t,...(a==null?void 0:a.width)!=null?{width:a.width,height:a.height}:{},...a!=null&&a.targetStyle?{targetStyle:a.targetStyle}:{}},customPrompt:n[t]}}function Xe(i,a){var t;return{fieldLabel:"Icon search",fieldType:"icon-picker",fieldValue:i,schema:{...a!=null&&a.style?{iconStyle:a.style}:{},...(a==null?void 0:a.limit)!=null?{maxResults:a.limit}:{},...(t=a==null?void 0:a.availableIcons)!=null&&t.length?{sampleIcons:a.availableIcons.slice(0,30)}:{}},customPrompt:`User query: "${i}"
|
|
10
|
+
Return the ${(a==null?void 0:a.limit)??5} most semantically relevant icon names from the available set as a JSON array of strings, ordered by relevance. Prefer specific over generic names.`}}function Oa(i,a,t){const r=o.useMemo(()=>We(i,a,t),[i,a,t==null?void 0:t.cursorLine,t==null?void 0:t.cursorCol,t==null?void 0:t.framework]);return V(r,t)}function Ea(i,a,t){const r=o.useMemo(()=>Ge(i,a,t),[i,a,t==null?void 0:t.mode,t==null?void 0:t.locale]);return V(r,t)}function Da(i,a){const t=o.useMemo(()=>Ve(i,a),[i,a==null?void 0:a.bpm,a==null?void 0:a.key,a==null?void 0:a.duration,a==null?void 0:a.mode]);return V(t,a)}function Ba(i,a){const t=o.useMemo(()=>Ke(i,a),[i,a==null?void 0:a.meshCount,a==null?void 0:a.triangleCount,a==null?void 0:a.targetDevice,a==null?void 0:a.mode]);return V(t,a)}function Fa(i,a){const t=o.useMemo(()=>Ye(i,a),[i,a==null?void 0:a.width,a==null?void 0:a.height,a==null?void 0:a.mode,a==null?void 0:a.targetStyle]);return V(t,a)}function Ja(i,a){const t=o.useMemo(()=>Xe(i,a),[i,a==null?void 0:a.limit,a==null?void 0:a.style]);return V(t,{...a,disabled:!i||(a==null?void 0:a.disabled)})}function Qe(i,a){var s;const t=(a==null?void 0:a.mode)??"npc-decision",r=(a==null?void 0:a.genre)??"fantasy",n={"npc-decision":`You are an AI game director. The NPC "${i}" must make a decision. Available BT nodes: ${JSON.stringify((a==null?void 0:a.btStatus)??[])}. Game state: ${JSON.stringify((a==null?void 0:a.gameState)??{})}. Return the name of the BT node to activate next, and one sentence of reasoning.`,dialogue:`You are a ${r} RPG writer. Write a short in-character dialogue line for NPC "${i}". Game state: ${JSON.stringify((a==null?void 0:a.gameState)??{})}. Max 2 sentences, no narrative descriptions.`,"procedural-level":`You are a ${r} game designer. Suggest a procedural level layout for a zone containing "${i}". Describe room count, enemy placement, loot, and one unique mechanic. Keep it under 150 words.`,"quest-description":`You are a ${r} quest designer. Write a compelling quest description involving "${i}". Include: objective, giver NPC, rewards, and a short flavour paragraph. Keep it under 120 words.`,"item-description":`You are a ${r} lore writer. Write a short item description for an item related to "${i}". Include: item name, rarity, flavour text, and one special property. Keep it under 80 words.`};return{fieldLabel:i,fieldType:`game-engine:${t}`,fieldValue:a==null?void 0:a.gameState,customPrompt:n[t],schema:{genre:r,mode:t,btNodes:(s=a==null?void 0:a.btStatus)==null?void 0:s.map(m=>m.node)}}}function qa(i,a){const t=o.useMemo(()=>Qe(i,a),[i,a==null?void 0:a.mode,a==null?void 0:a.genre,JSON.stringify(a==null?void 0:a.btStatus),JSON.stringify(a==null?void 0:a.gameState)]);return V(t,a)}function Ze(i,a,t){const r=(t==null?void 0:t.mode)??"layout",n=(t==null?void 0:t.diagramType)??"flowchart",s={layout:`You are a diagram layout optimizer. Given this ${n} with ${i.length} nodes and ${a.length} edges, suggest optimal positions for each node to minimize edge crossings and improve readability. Return JSON: { suggestions: [{ id: string, x: number, y: number, reason: string }] }. Consider flow direction (top-to-bottom or left-to-right) and grouping related nodes.`,structure:`You are a diagram analyst. Analyze this ${n} structure. Identify: 1) Missing connections, 2) Potential bottlenecks, 3) Orphan nodes, 4) Cycles or loops. Return JSON: { issues: [{ type: string, description: string, nodeIds: string[] }], score: number }`,simplify:`You are a diagram simplifier. Suggest how to simplify this ${n} while preserving meaning. Identify: nodes that could be merged, redundant edges, or overly complex branches. Return JSON: { simplifications: [{ action: 'merge'|'remove'|'group', ids: string[], reason: string }] }`,group:`You are a diagram organizer. Suggest logical groupings for nodes in this ${n}. Consider semantic relationships, data flow patterns, and visual clustering. Return JSON: { groups: [{ name: string, nodeIds: string[], color?: string }] }`},m=i.map(g=>{var f;return{id:g.id,type:g.type,label:(f=g.label)==null?void 0:f.slice(0,30),pos:[Math.round(g.x),Math.round(g.y)]}}),c=a.map(g=>({id:g.id,src:g.source,tgt:g.target}));return{fieldLabel:`Diagram (${n})`,fieldType:`diagram:${r}`,fieldValue:JSON.stringify({nodes:m,edges:c}),schema:{diagramType:n,mode:r,nodeCount:i.length,edgeCount:a.length,containerSize:t==null?void 0:t.containerSize},customPrompt:s[r]}}function Ua(i,a,t){const r=o.useMemo(()=>Ze(i,a,t),[JSON.stringify(i),JSON.stringify(a),t==null?void 0:t.mode,t==null?void 0:t.diagramType]);return V(r,{...t,disabled:i.length===0||(t==null?void 0:t.disabled)})}function ea(i,a){const t=(a==null?void 0:a.mode)??"generate",r=(a==null?void 0:a.presentationType)??"business",n=(a==null?void 0:a.duration)??15,s=Math.ceil(n/2),m={generate:`You are a presentation designer. Create a ${r} presentation outline based on: "${i}". Target audience: ${(a==null?void 0:a.audience)??"general"}. Duration: ${n} minutes (~${s} slides). Return JSON: { title: string, slides: [{ title: string, layout: 'title'|'content'|'two-column'|'chart'|'image', bullets?: string[], chartType?: string, speakerNotes?: string }] }. Include: clear slide titles, 3-5 bullet points per content slide, and brief speaker notes.`,summarize:`You are a presentation optimizer. Summarize this presentation to be more concise: "${i}". Reduce slide count by 30% while preserving key messages. Return JSON: { summary: string, reducedSlides: [{ title: string, keyPoints: string[] }] }`,expand:`You are a presentation expert. Expand this brief outline into a detailed presentation: "${i}". Add supporting details, examples, and transitions. Target: ${s} slides. Return JSON: { slides: [{ title: string, content: string, transitions?: string, animations?: string[] }] }`,improve:`You are a presentation coach. Review and improve this presentation structure: "${i}". Suggest: better flow, stronger opening/closing, clearer data visualization. Return JSON: { improvements: [{ slide: number, issue: string, suggestion: string }], score: number }`};return{fieldLabel:`Presentation (${r})`,fieldType:`presentation:${t}`,fieldValue:i,schema:{presentationType:r,mode:t,duration:n,slideCount:s,audience:a==null?void 0:a.audience,hasData:(a==null?void 0:a.dataContext)!=null},customPrompt:m[t]}}function Ha(i,a){const t=o.useMemo(()=>ea(i,a),[i,a==null?void 0:a.mode,a==null?void 0:a.presentationType,a==null?void 0:a.duration,a==null?void 0:a.audience]);return V(t,{...a,disabled:!i||(a==null?void 0:a.disabled)})}function aa(i,a){var n;const t=(a==null?void 0:a.mode)??"all",r={alignment:"Analyze element alignment on this slide. Suggest adjustments to create visual harmony. Return JSON: { suggestions: [{ elementIndex: number, issue: string, fixX?: number, fixY?: number }] }",contrast:"Analyze color contrast and readability. Suggest improvements for accessibility (WCAG AA). Return JSON: { suggestions: [{ area: string, currentContrast: number, suggestedFix: string }] }",spacing:"Analyze whitespace and element spacing. Apply the rule of thirds and consistent margins. Return JSON: { suggestions: [{ elementIndex: number, issue: string, suggestedMargin: number }] }",typography:"Analyze typography: hierarchy, font sizes, line heights, readability. Return JSON: { suggestions: [{ area: string, issue: string, suggestedFontSize?: number }] }",all:"Perform a complete design review of this slide. Check alignment, contrast, spacing, and typography. Return JSON: { score: number, suggestions: [{ category: string, issue: string, fix: string }] }. Prioritize issues by impact on visual clarity."};return{fieldLabel:i.title??"Slide Design",fieldType:`slide-design:${t}`,fieldValue:JSON.stringify(i),schema:{mode:t,hasElements:(((n=i.elements)==null?void 0:n.length)??0)>0,layout:i.layout,brandColors:a==null?void 0:a.brandColors},customPrompt:r[t]}}function Wa(i,a){const t=o.useMemo(()=>aa(i,a),[JSON.stringify(i),a==null?void 0:a.mode,JSON.stringify(a==null?void 0:a.brandColors)]);return V(t,a)}function Ga(i,a,t){const r=o.forwardRef((n,s)=>{const{aiEnabled:m=!0,aiPosition:c="right",aiPrompt:g,aiDebounceMs:f=500,aiShowOnHover:j=!1,aiTriggerIcon:w,...N}=n,S=o.useMemo(()=>{const $=a(N);return g&&($.customPrompt=g),$},[N,g]);return e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4},children:[e.jsx(i,{...N,ref:s}),m&&e.jsx(ke,{context:S,position:c,debounceMs:f,showOnHover:j,triggerIcon:w})]})});return r.displayName=t??`withAIHint(${i.displayName??i.name??"Component"})`,r}function Va(i){return Ne(i.label??"Text",i.value,{placeholder:i.placeholder,maxLength:i.maxLength})}function Ka(i){return Ce(i.label??"Number",i.value,{min:i.min,max:i.max,step:i.step})}function Ya(i){return Se(i.label??"Select",i.value,{options:i.options,multiple:i.multiple})}function Xa(i){return Te(i.label??"Date",i.value,{min:i.min,max:i.max})}function Qa(i){return Ae(i.label??"Color",i.value)}const Za={id:crypto.randomUUID(),name:"New ML Project",type:"classification",status:"draft",datasets:[],experiments:[],models:[],createdAt:new Date,updatedAt:new Date},Ie={classification:[{id:"logistic-regression",name:"Logistic Regression"},{id:"random-forest",name:"Random Forest"},{id:"gradient-boosting",name:"Gradient Boosting"},{id:"svm",name:"Support Vector Machine"},{id:"neural-network",name:"Neural Network"},{id:"xgboost",name:"XGBoost"}],regression:[{id:"linear-regression",name:"Linear Regression"},{id:"ridge",name:"Ridge Regression"},{id:"lasso",name:"Lasso Regression"},{id:"random-forest-reg",name:"Random Forest"},{id:"gradient-boosting-reg",name:"Gradient Boosting"}],clustering:[{id:"kmeans",name:"K-Means"},{id:"dbscan",name:"DBSCAN"},{id:"hierarchical",name:"Hierarchical Clustering"}]},ze={classification:["accuracy","precision","recall","f1-score","auc-roc"],regression:["mse","rmse","mae","r2"],clustering:["silhouette","calinski-harabasz","davies-bouldin"]},et=({project:i,onProjectChange:a,onExperimentRun:t,onModelDeploy:r,className:n=""})=>{var R;const[s,m]=o.useState(i||Za),[c,g]=o.useState("data"),[f,j]=o.useState(null),[w,N]=o.useState(null),[S,$]=o.useState(null),[k,P]=o.useState(!1),[h,d]=o.useState({algorithm:"",hyperparameters:{},preprocessing:[]}),v=o.useCallback(l=>{const x={...s,...l,updatedAt:new Date};m(x),a==null||a(x)},[s,a]),C=async l=>{for(const x of Array.from(l)){const M={id:crypto.randomUUID(),name:x.name.replace(/\.[^.]+$/,""),type:"tabular",source:{type:"file",uri:x.name},size:x.size,rowCount:0,columns:[],splits:[{name:"train",ratio:.8,rowCount:0},{name:"validation",ratio:.1,rowCount:0},{name:"test",ratio:.1,rowCount:0}],createdAt:new Date};if(x.name.endsWith(".csv")){const D=(await x.text()).split(`
|
|
11
|
+
`),J=D[0].split(",").map(H=>H.trim());M.rowCount=D.length-1,M.columns=J.map(H=>({name:H,type:"text",nullable:!0,unique:0,missing:0})),M.splits=M.splits.map(H=>({...H,rowCount:Math.floor(M.rowCount*H.ratio)}))}v({datasets:[...s.datasets,M]})}},p=l=>{v({datasets:s.datasets.filter(x=>x.id!==l)}),f===l&&j(null)},_=async()=>{if(!h.algorithm||!f)return;const l={id:crypto.randomUUID(),name:`Experiment ${s.experiments.length+1}`,status:"pending",config:h,metrics:[],artifacts:[],logs:[]};if(v({experiments:[...s.experiments,l]}),P(!1),t){v({experiments:s.experiments.map(x=>x.id===l.id?{...x,status:"running",startedAt:new Date}:x)});try{await t(l);const x=(ze[s.type]||ze.classification).map(M=>({name:M,value:Math.random()*.3+.7,split:"validation"}));v({experiments:s.experiments.map(M=>M.id===l.id?{...M,status:"completed",completedAt:new Date,metrics:x}:M)})}catch{v({experiments:s.experiments.map(x=>x.id===l.id?{...x,status:"failed"}:x)})}}},b=l=>{const x=s.experiments.find(z=>z.id===l);if(!x)return;const M={id:crypto.randomUUID(),name:`Model from ${x.name}`,version:"1.0.0",algorithm:x.config.algorithm,experimentId:l,status:"registered",metrics:x.metrics,size:Math.floor(Math.random()*100)*1024*1024,artifacts:[],deployments:[],createdAt:new Date};v({models:[...s.models,M]})},u=async l=>{const x=s.models.find(z=>z.id===l);if(!x||!r)return;const M=await r(x);v({models:s.models.map(z=>z.id===l?{...z,status:"production",deployments:[...z.deployments,M]}:z)})},y=l=>l<1024?`${l} B`:l<1024*1024?`${(l/1024).toFixed(1)} KB`:l<1024*1024*1024?`${(l/1024/1024).toFixed(1)} MB`:`${(l/1024/1024/1024).toFixed(1)} GB`,A=l=>{switch(l){case"completed":case"production":case"running":return"status-badge--success";case"pending":case"staging":return"status-badge--warning";case"failed":return"status-badge--error";default:return""}};return e.jsxs("div",{className:`nice-ml-studio ${n}`,children:[e.jsxs("header",{className:"ml-studio__header",children:[e.jsxs("div",{className:"header__info",children:[e.jsx("input",{type:"text",value:s.name,onChange:l=>v({name:l.target.value}),className:"project-name-input"}),e.jsxs("select",{value:s.type,onChange:l=>v({type:l.target.value}),className:"project-type-select",children:[e.jsx("option",{value:"classification",children:"Classification"}),e.jsx("option",{value:"regression",children:"Regression"}),e.jsx("option",{value:"clustering",children:"Clustering"}),e.jsx("option",{value:"object-detection",children:"Object Detection"}),e.jsx("option",{value:"nlp",children:"NLP"}),e.jsx("option",{value:"time-series",children:"Time Series"})]})]}),e.jsx("div",{className:"header__tabs",children:["data","experiments","models","deploy"].map(l=>e.jsx("button",{className:`tab-button ${c===l?"tab-button--active":""}`,onClick:()=>g(l),children:l.charAt(0).toUpperCase()+l.slice(1)},l))})]}),e.jsxs("div",{className:"ml-studio__content",children:[c==="data"&&e.jsxs("div",{className:"data-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h2",{children:"Datasets"}),e.jsxs("label",{className:"upload-button",children:[e.jsx("input",{type:"file",multiple:!0,accept:".csv,.json,.parquet",onChange:l=>l.target.files&&C(l.target.files),hidden:!0}),"+ Upload Dataset"]})]}),e.jsx("div",{className:"datasets-grid",children:s.datasets.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx("span",{className:"icon",children:"📊"}),e.jsx("p",{children:"No datasets uploaded yet"}),e.jsx("p",{className:"hint",children:"Upload CSV, JSON, or Parquet files to get started"})]}):s.datasets.map(l=>e.jsxs("div",{className:`dataset-card ${f===l.id?"dataset-card--selected":""}`,onClick:()=>j(l.id),children:[e.jsxs("div",{className:"card-header",children:[e.jsx("span",{className:"dataset-icon",children:"📁"}),e.jsx("h3",{children:l.name}),e.jsx("button",{className:"remove-button",onClick:x=>{x.stopPropagation(),p(l.id)},children:"×"})]}),e.jsxs("div",{className:"card-stats",children:[e.jsxs("span",{children:[l.rowCount.toLocaleString()," rows"]}),e.jsxs("span",{children:[l.columns.length," columns"]}),e.jsx("span",{children:y(l.size)})]}),e.jsx("div",{className:"splits-bar",children:l.splits.map(x=>e.jsx("div",{className:`split split--${x.name}`,style:{width:`${x.ratio*100}%`},title:`${x.name}: ${(x.ratio*100).toFixed(0)}%`},x.name))})]},l.id))}),f&&e.jsx("div",{className:"dataset-details",children:(()=>{const l=s.datasets.find(x=>x.id===f);return l?e.jsxs(e.Fragment,{children:[e.jsx("h3",{children:"Columns"}),e.jsxs("table",{className:"columns-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Name"}),e.jsx("th",{children:"Type"}),e.jsx("th",{children:"Missing"}),e.jsx("th",{children:"Unique"})]})}),e.jsx("tbody",{children:l.columns.map(x=>e.jsxs("tr",{children:[e.jsx("td",{children:x.name}),e.jsx("td",{children:e.jsxs("select",{value:x.type,onChange:M=>{v({datasets:s.datasets.map(z=>z.id===l.id?{...z,columns:z.columns.map(D=>D.name===x.name?{...D,type:M.target.value}:D)}:z)})},children:[e.jsx("option",{value:"numeric",children:"Numeric"}),e.jsx("option",{value:"categorical",children:"Categorical"}),e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"datetime",children:"DateTime"}),e.jsx("option",{value:"boolean",children:"Boolean"})]})}),e.jsx("td",{children:x.missing}),e.jsx("td",{children:x.unique})]},x.name))})]})]}):null})()})]}),c==="experiments"&&e.jsxs("div",{className:"experiments-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h2",{children:"Experiments"}),e.jsx("button",{className:"primary-button",onClick:()=>P(!0),disabled:s.datasets.length===0,children:"+ New Experiment"})]}),k&&e.jsxs("div",{className:"new-experiment-form",children:[e.jsx("h3",{children:"Configure Experiment"}),e.jsxs("div",{className:"form-grid",children:[e.jsxs("label",{children:["Dataset",e.jsxs("select",{value:f||"",onChange:l=>j(l.target.value),children:[e.jsx("option",{value:"",children:"Select dataset..."}),s.datasets.map(l=>e.jsx("option",{value:l.id,children:l.name},l.id))]})]}),e.jsxs("label",{children:["Algorithm",e.jsxs("select",{value:h.algorithm,onChange:l=>d({...h,algorithm:l.target.value}),children:[e.jsx("option",{value:"",children:"Select algorithm..."}),(Ie[s.type]||Ie.classification).map(l=>e.jsx("option",{value:l.id,children:l.name},l.id))]})]}),f&&e.jsxs("label",{children:["Target Column",e.jsxs("select",{value:h.targetColumn||"",onChange:l=>d({...h,targetColumn:l.target.value}),children:[e.jsx("option",{value:"",children:"Select target..."}),(R=s.datasets.find(l=>l.id===f))==null?void 0:R.columns.map(l=>e.jsx("option",{value:l.name,children:l.name},l.name))]})]})]}),e.jsxs("div",{className:"form-actions",children:[e.jsx("button",{className:"secondary-button",onClick:()=>P(!1),children:"Cancel"}),e.jsx("button",{className:"primary-button",onClick:_,disabled:!h.algorithm||!f,children:"Run Experiment"})]})]}),e.jsx("div",{className:"experiments-list",children:s.experiments.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx("span",{className:"icon",children:"🧪"}),e.jsx("p",{children:"No experiments yet"}),e.jsx("p",{className:"hint",children:"Create an experiment to train and evaluate models"})]}):s.experiments.map(l=>e.jsxs("div",{className:`experiment-card ${w===l.id?"experiment-card--selected":""}`,onClick:()=>N(l.id),children:[e.jsxs("div",{className:"card-header",children:[e.jsx("h3",{children:l.name}),e.jsx("span",{className:`status-badge ${A(l.status)}`,children:l.status})]}),e.jsxs("div",{className:"card-meta",children:[e.jsxs("span",{children:["Algorithm: ",l.config.algorithm]}),l.duration&&e.jsxs("span",{children:["Duration: ",Math.round(l.duration),"s"]})]}),l.metrics.length>0&&e.jsx("div",{className:"metrics-row",children:l.metrics.slice(0,3).map(x=>e.jsxs("div",{className:"metric-item",children:[e.jsx("span",{className:"metric-name",children:x.name}),e.jsxs("span",{className:"metric-value",children:[(x.value*100).toFixed(1),"%"]})]},x.name))}),l.status==="completed"&&e.jsx("button",{className:"action-button",onClick:x=>{x.stopPropagation(),b(l.id)},children:"Register Model"})]},l.id))})]}),c==="models"&&e.jsxs("div",{className:"models-panel",children:[e.jsx("div",{className:"panel-header",children:e.jsx("h2",{children:"Models"})}),e.jsx("div",{className:"models-list",children:s.models.length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx("span",{className:"icon",children:"🤖"}),e.jsx("p",{children:"No models registered yet"}),e.jsx("p",{className:"hint",children:"Complete experiments and register models"})]}):s.models.map(l=>e.jsxs("div",{className:`model-card ${S===l.id?"model-card--selected":""}`,onClick:()=>$(l.id),children:[e.jsxs("div",{className:"card-header",children:[e.jsx("h3",{children:l.name}),e.jsx("span",{className:`status-badge ${A(l.status)}`,children:l.status})]}),e.jsxs("div",{className:"card-meta",children:[e.jsxs("span",{children:["Algorithm: ",l.algorithm]}),e.jsxs("span",{children:["Version: ",l.version]}),e.jsxs("span",{children:["Size: ",y(l.size)]})]}),l.metrics.length>0&&e.jsx("div",{className:"metrics-row",children:l.metrics.slice(0,3).map(x=>e.jsxs("div",{className:"metric-item",children:[e.jsx("span",{className:"metric-name",children:x.name}),e.jsxs("span",{className:"metric-value",children:[(x.value*100).toFixed(1),"%"]})]},x.name))}),e.jsxs("div",{className:"card-actions",children:[e.jsx("button",{className:"action-button",children:"Download"}),e.jsx("button",{className:"action-button action-button--primary",onClick:x=>{x.stopPropagation(),u(l.id)},disabled:l.status==="production",children:l.status==="production"?"Deployed":"Deploy"})]})]},l.id))})]}),c==="deploy"&&e.jsxs("div",{className:"deploy-panel",children:[e.jsx("div",{className:"panel-header",children:e.jsx("h2",{children:"Deployments"})}),e.jsx("div",{className:"deployments-list",children:s.models.filter(l=>l.deployments.length>0).length===0?e.jsxs("div",{className:"empty-state",children:[e.jsx("span",{className:"icon",children:"🚀"}),e.jsx("p",{children:"No deployments yet"}),e.jsx("p",{className:"hint",children:"Deploy a model to create inference endpoints"})]}):s.models.filter(l=>l.deployments.length>0).flatMap(l=>l.deployments.map(x=>({model:l,deployment:x}))).map(({model:l,deployment:x})=>e.jsxs("div",{className:"deployment-card",children:[e.jsxs("div",{className:"card-header",children:[e.jsx("h3",{children:x.name}),e.jsx("span",{className:`status-badge ${A(x.status)}`,children:x.status})]}),e.jsxs("div",{className:"card-meta",children:[e.jsxs("span",{children:["Model: ",l.name]}),e.jsxs("span",{children:["Endpoint: ",x.endpoint]})]}),e.jsxs("div",{className:"resources-info",children:[e.jsxs("span",{children:["CPU: ",x.resources.cpu," cores"]}),e.jsxs("span",{children:["Memory: ",x.resources.memory," GB"]}),e.jsxs("span",{children:["Replicas: ",x.resources.replicas]})]})]},x.id))})]})]})]})},at={id:crypto.randomUUID(),name:"New Labeling Project",type:"classification",dataType:"image",status:"setup",labelSchema:{classes:[],attributes:[]},items:[],collaborators:[],statistics:{totalItems:0,labeled:0,reviewed:0,approved:0,byClass:[]},createdAt:new Date},Le=["var(--nice-danger, #ef4444)","var(--nice-warning, #f97316)","var(--nice-warning, #f59e0b)","var(--nice-success, #84cc16)","var(--nice-success, #22c55e)","var(--nice-info, #14b8a6)","var(--nice-info, #06b6d4)","var(--nice-primary, #3b82f6)","var(--nice-info, #6366f1)","var(--nice-accent, #8b5cf6)","var(--nice-accent, #a855f7)","var(--nice-accent-pink, #d946ef)","var(--nice-accent-pink, #ec4899)","var(--nice-danger, #f43f5e)"],tt=({project:i,onProjectChange:a,onLabelSave:t,onExport:r,className:n=""})=>{var Q;const[s,m]=o.useState(i||at),[c,g]=o.useState("label"),[f,j]=o.useState(0),[w,N]=o.useState(null),[S,$]=o.useState("select"),[k,P]=o.useState(!1),[h,d]=o.useState(null),[v,C]=o.useState(1),[p,_]=o.useState(!1),[b,u]=o.useState("all"),y=o.useRef(null),A=o.useRef(null),R=s.items[f];o.useEffect(()=>{i&&m(i)},[i]);const l=o.useCallback(T=>{const L={...s,...T};L.statistics={totalItems:L.items.length,labeled:L.items.filter(E=>E.status!=="pending").length,reviewed:L.items.filter(E=>E.status==="review"||E.status==="approved").length,approved:L.items.filter(E=>E.status==="approved").length,byClass:L.labelSchema.classes.map(E=>({classId:E.id,count:L.items.flatMap(O=>O.labels).filter(O=>O.classId===E.id).length}))},m(L),a==null||a(L)},[s,a]),x=()=>{const T={id:crypto.randomUUID(),name:`Class ${s.labelSchema.classes.length+1}`,color:Le[s.labelSchema.classes.length%Le.length],shortcut:String(s.labelSchema.classes.length+1)};l({labelSchema:{...s.labelSchema,classes:[...s.labelSchema.classes,T]}})},M=T=>{l({labelSchema:{...s.labelSchema,classes:s.labelSchema.classes.filter(L=>L.id!==T)},items:s.items.map(L=>({...L,labels:L.labels.filter(E=>E.classId!==T)}))})},z=(T,L)=>{l({labelSchema:{...s.labelSchema,classes:s.labelSchema.classes.map(E=>E.id===T?{...E,...L}:E)}})},D=(T,L)=>{if(!R)return;const E={id:crypto.randomUUID(),classId:T,type:s.type==="classification"?"class":s.type==="bounding-box"?"bbox":"class",data:L||{},createdBy:"current-user",createdAt:new Date},O={...R,labels:[...R.labels,E],status:"labeled"};l({items:s.items.map(B=>B.id===R.id?O:B)}),t==null||t(O)},J=T=>{if(!R)return;const L={...R,labels:R.labels.filter(E=>E.id!==T),status:R.labels.length<=1?"pending":"labeled"};l({items:s.items.map(E=>E.id===R.id?L:E)})},H=T=>{var B;if(S!=="bbox"||!w)return;const L=(B=y.current)==null?void 0:B.getBoundingClientRect();if(!L)return;const E=(T.clientX-L.left)/v,O=(T.clientY-L.top)/v;P(!0),d({x:E,y:O,width:0,height:0})},Y=T=>{var B;if(!k||!h)return;const L=(B=y.current)==null?void 0:B.getBoundingClientRect();if(!L)return;const E=(T.clientX-L.left)/v,O=(T.clientY-L.top)/v;d({...h,width:E-h.x,height:O-h.y})},I=()=>{!k||!h||!w||(P(!1),Math.abs(h.width)>10&&Math.abs(h.height)>10&&D(w,{x:h.width<0?h.x+h.width:h.x,y:h.height<0?h.y+h.height:h.y,width:Math.abs(h.width),height:Math.abs(h.height)}),d(null))},F=T=>{const L=b==="all"?s.items:s.items.filter(O=>O.status===b),E=L.findIndex(O=>O.id===(R==null?void 0:R.id));if(T==="prev"&&E>0){const O=L[E-1];j(s.items.findIndex(B=>B.id===O.id))}else if(T==="next"&&E<L.length-1){const O=L[E+1];j(s.items.findIndex(B=>B.id===O.id))}},q=()=>{if(!R)return;const T={...R,status:"approved"};l({items:s.items.map(L=>L.id===R.id?T:L)}),F("next")},W=()=>{if(!R)return;const T={...R,status:"rejected"};l({items:s.items.map(L=>L.id===R.id?T:L)}),F("next")},U=async T=>{r&&await r(T)};o.useEffect(()=>{const T=L=>{const E=L.key,O=s.labelSchema.classes.find(B=>B.shortcut===E);O&&(s.type==="classification"?(D(O.id),F("next")):N(O.id)),L.key==="ArrowLeft"||L.key==="a"?F("prev"):(L.key==="ArrowRight"||L.key==="d")&&F("next"),L.key==="Enter"?q():L.key==="Backspace"&&W()};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[R,s.labelSchema.classes,s.type]);const K=T=>{switch(T){case"approved":return"var(--nice-success, #22c55e)";case"labeled":return"var(--nice-primary, #3b82f6)";case"review":return"var(--nice-warning, #f59e0b)";case"rejected":return"var(--nice-danger, #ef4444)";default:return"var(--nice-text-secondary, #6b7280)"}};return e.jsxs("div",{className:`nice-data-labeler ${n}`,children:[e.jsxs("header",{className:"labeler__header",children:[e.jsxs("div",{className:"header__info",children:[e.jsx("input",{type:"text",value:s.name,onChange:T=>l({name:T.target.value}),className:"project-name-input"}),e.jsxs("div",{className:"progress-bar",children:[e.jsx("div",{className:"progress-fill",style:{width:`${s.statistics.labeled/Math.max(s.statistics.totalItems,1)*100}%`}}),e.jsxs("span",{className:"progress-text",children:[s.statistics.labeled," / ",s.statistics.totalItems," labeled"]})]})]}),e.jsx("div",{className:"header__tabs",children:["label","schema","review","export"].map(T=>e.jsx("button",{className:`tab-button ${c===T?"tab-button--active":""}`,onClick:()=>g(T),children:T.charAt(0).toUpperCase()+T.slice(1)},T))}),e.jsx("button",{className:"shortcuts-button",onClick:()=>_(!p),children:"⌨️ Shortcuts"})]}),e.jsxs("div",{className:"labeler__content",children:[c==="label"&&e.jsxs("div",{className:"label-panel",children:[e.jsxs("div",{className:"label-toolbar",children:[e.jsxs("div",{className:"tool-group",children:[e.jsx("button",{className:`tool-button ${S==="select"?"tool-button--active":""}`,onClick:()=>$("select"),children:"↖️ Select"}),(s.type==="bounding-box"||s.type==="multi-label")&&e.jsx("button",{className:`tool-button ${S==="bbox"?"tool-button--active":""}`,onClick:()=>$("bbox"),children:"⬜ Box"}),s.type==="polygon"&&e.jsx("button",{className:`tool-button ${S==="polygon"?"tool-button--active":""}`,onClick:()=>$("polygon"),children:"⬡ Polygon"})]}),e.jsxs("div",{className:"zoom-group",children:[e.jsx("button",{onClick:()=>C(Math.max(.25,v-.25)),children:"-"}),e.jsxs("span",{children:[Math.round(v*100),"%"]}),e.jsx("button",{onClick:()=>C(Math.min(4,v+.25)),children:"+"})]}),e.jsxs("div",{className:"navigation-group",children:[e.jsx("button",{onClick:()=>F("prev"),disabled:f===0,children:"← Prev"}),e.jsxs("span",{children:[f+1," / ",s.items.length]}),e.jsx("button",{onClick:()=>F("next"),disabled:f>=s.items.length-1,children:"Next →"})]})]}),e.jsxs("div",{className:"label-workspace",children:[e.jsx("div",{className:"canvas-container",ref:A,children:R?e.jsxs(e.Fragment,{children:[R.data.type==="image"&&e.jsxs(e.Fragment,{children:[e.jsx("img",{src:R.data.url,alt:"Labeling item",className:"labeling-image",style:{transform:`scale(${v})`}}),e.jsx("canvas",{ref:y,className:"labeling-canvas",onMouseDown:H,onMouseMove:Y,onMouseUp:I,onMouseLeave:I,style:{transform:`scale(${v})`,cursor:S==="bbox"?"crosshair":"default"}}),e.jsxs("div",{className:"annotations-overlay",style:{transform:`scale(${v})`},children:[R.labels.filter(T=>T.type==="bbox"&&T.data.x!==void 0).map(T=>{const L=s.labelSchema.classes.find(E=>E.id===T.classId);return e.jsxs("div",{className:"bbox-annotation",style:{left:T.data.x,top:T.data.y,width:T.data.width,height:T.data.height,borderColor:(L==null?void 0:L.color)||"var(--nice-danger, #ff0000)"},children:[e.jsx("span",{className:"bbox-label",style:{backgroundColor:(L==null?void 0:L.color)||"var(--nice-danger, #ff0000)"},children:L==null?void 0:L.name}),e.jsx("button",{className:"bbox-remove",onClick:()=>J(T.id),children:"×"})]},T.id)}),h&&e.jsx("div",{className:"bbox-drawing",style:{left:h.width<0?h.x+h.width:h.x,top:h.height<0?h.y+h.height:h.y,width:Math.abs(h.width),height:Math.abs(h.height),borderColor:(Q=s.labelSchema.classes.find(T=>T.id===w))==null?void 0:Q.color}})]})]}),R.data.type==="text"&&e.jsx("div",{className:"text-labeling",children:e.jsx("p",{className:"text-content",children:R.data.text})})]}):e.jsxs("div",{className:"empty-state",children:[e.jsx("span",{className:"icon",children:"📋"}),e.jsx("p",{children:"No items to label"})]})}),e.jsxs("aside",{className:"class-sidebar",children:[e.jsx("h3",{children:"Classes"}),e.jsx("div",{className:"class-list",children:s.labelSchema.classes.map(T=>e.jsxs("button",{className:`class-button ${w===T.id?"class-button--active":""}`,style:{borderLeftColor:T.color},onClick:()=>{s.type==="classification"?(D(T.id),F("next")):N(T.id)},children:[e.jsx("span",{className:"class-color",style:{backgroundColor:T.color}}),e.jsx("span",{className:"class-name",children:T.name}),T.shortcut&&e.jsx("span",{className:"class-shortcut",children:T.shortcut})]},T.id))}),R&&R.labels.length>0&&e.jsxs("div",{className:"current-labels",children:[e.jsx("h4",{children:"Labels"}),R.labels.map(T=>{const L=s.labelSchema.classes.find(E=>E.id===T.classId);return e.jsxs("div",{className:"label-item",children:[e.jsx("span",{className:"label-color",style:{backgroundColor:L==null?void 0:L.color}}),e.jsx("span",{className:"label-name",children:L==null?void 0:L.name}),e.jsx("button",{onClick:()=>J(T.id),children:"×"})]},T.id)})]}),c==="label"&&R&&e.jsxs("div",{className:"label-actions",children:[e.jsx("button",{className:"approve-button",onClick:q,children:"✓ Approve"}),e.jsx("button",{className:"reject-button",onClick:W,children:"✗ Reject"})]})]})]})]}),c==="schema"&&e.jsxs("div",{className:"schema-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h2",{children:"Label Schema"}),e.jsx("button",{className:"primary-button",onClick:x,children:"+ Add Class"})]}),e.jsxs("div",{className:"schema-settings",children:[e.jsxs("label",{children:["Labeling Type",e.jsxs("select",{value:s.type,onChange:T=>l({type:T.target.value}),children:[e.jsx("option",{value:"classification",children:"Single Classification"}),e.jsx("option",{value:"multi-label",children:"Multi-Label Classification"}),e.jsx("option",{value:"bounding-box",children:"Bounding Box"}),e.jsx("option",{value:"polygon",children:"Polygon"}),e.jsx("option",{value:"segmentation",children:"Segmentation"}),e.jsx("option",{value:"ner",children:"Named Entity Recognition"})]})]}),e.jsxs("label",{children:["Data Type",e.jsxs("select",{value:s.dataType,onChange:T=>l({dataType:T.target.value}),children:[e.jsx("option",{value:"image",children:"Image"}),e.jsx("option",{value:"text",children:"Text"}),e.jsx("option",{value:"audio",children:"Audio"}),e.jsx("option",{value:"video",children:"Video"})]})]})]}),e.jsx("div",{className:"classes-list",children:s.labelSchema.classes.map((T,L)=>e.jsxs("div",{className:"class-editor",children:[e.jsx("input",{type:"color",value:T.color,onChange:E=>z(T.id,{color:E.target.value}),className:"color-picker"}),e.jsx("input",{type:"text",value:T.name,onChange:E=>z(T.id,{name:E.target.value}),className:"class-name-input",placeholder:"Class name"}),e.jsx("input",{type:"text",value:T.shortcut||"",onChange:E=>z(T.id,{shortcut:E.target.value}),className:"shortcut-input",placeholder:"Key",maxLength:1}),e.jsx("button",{className:"remove-class-button",onClick:()=>M(T.id),children:"🗑️"})]},T.id))}),e.jsxs("div",{className:"guidelines-section",children:[e.jsx("h3",{children:"Labeling Guidelines"}),e.jsx("textarea",{value:s.guidelines||"",onChange:T=>l({guidelines:T.target.value}),placeholder:"Enter labeling guidelines for annotators...",rows:6})]})]}),c==="review"&&e.jsxs("div",{className:"review-panel",children:[e.jsxs("div",{className:"panel-header",children:[e.jsx("h2",{children:"Review Labels"}),e.jsx("div",{className:"filter-group",children:e.jsxs("select",{value:b,onChange:T=>u(T.target.value),children:[e.jsx("option",{value:"all",children:"All Items"}),e.jsx("option",{value:"labeled",children:"Labeled"}),e.jsx("option",{value:"review",children:"Needs Review"}),e.jsx("option",{value:"approved",children:"Approved"}),e.jsx("option",{value:"rejected",children:"Rejected"})]})})]}),e.jsx("div",{className:"items-grid",children:s.items.filter(T=>b==="all"||T.status===b).map((T,L)=>{var E;return e.jsxs("div",{className:`item-card ${f===s.items.indexOf(T)?"item-card--active":""}`,onClick:()=>{j(s.items.indexOf(T)),g("label")},children:[T.data.type==="image"&&e.jsx("img",{src:T.data.url,alt:`Item ${L+1}`,className:"item-thumbnail"}),T.data.type==="text"&&e.jsxs("p",{className:"item-text-preview",children:[(E=T.data.text)==null?void 0:E.slice(0,100),"..."]}),e.jsxs("div",{className:"item-footer",children:[e.jsx("span",{className:"status-dot",style:{backgroundColor:K(T.status)}}),e.jsxs("span",{children:[T.labels.length," labels"]})]})]},T.id)})})]}),c==="export"&&e.jsxs("div",{className:"export-panel",children:[e.jsx("div",{className:"panel-header",children:e.jsx("h2",{children:"Export Labels"})}),e.jsxs("div",{className:"export-stats",children:[e.jsxs("div",{className:"stat-card",children:[e.jsx("span",{className:"stat-value",children:s.statistics.totalItems}),e.jsx("span",{className:"stat-label",children:"Total Items"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("span",{className:"stat-value",children:s.statistics.labeled}),e.jsx("span",{className:"stat-label",children:"Labeled"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("span",{className:"stat-value",children:s.statistics.approved}),e.jsx("span",{className:"stat-label",children:"Approved"})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("span",{className:"stat-value",children:s.labelSchema.classes.length}),e.jsx("span",{className:"stat-label",children:"Classes"})]})]}),e.jsxs("div",{className:"export-formats",children:[e.jsx("h3",{children:"Export Format"}),e.jsxs("div",{className:"format-grid",children:[e.jsxs("button",{className:"format-button",onClick:()=>U("coco"),children:[e.jsx("span",{className:"format-icon",children:"📦"}),e.jsx("span",{className:"format-name",children:"COCO JSON"}),e.jsx("span",{className:"format-desc",children:"Common format for object detection"})]}),e.jsxs("button",{className:"format-button",onClick:()=>U("voc"),children:[e.jsx("span",{className:"format-icon",children:"📄"}),e.jsx("span",{className:"format-name",children:"Pascal VOC"}),e.jsx("span",{className:"format-desc",children:"XML format for bounding boxes"})]}),e.jsxs("button",{className:"format-button",onClick:()=>U("yolo"),children:[e.jsx("span",{className:"format-icon",children:"⚡"}),e.jsx("span",{className:"format-name",children:"YOLO"}),e.jsx("span",{className:"format-desc",children:"Text format for YOLO models"})]}),e.jsxs("button",{className:"format-button",onClick:()=>U("csv"),children:[e.jsx("span",{className:"format-icon",children:"📊"}),e.jsx("span",{className:"format-name",children:"CSV"}),e.jsx("span",{className:"format-desc",children:"Tabular format for classification"})]})]})]}),e.jsxs("div",{className:"class-distribution",children:[e.jsx("h3",{children:"Class Distribution"}),e.jsx("div",{className:"distribution-bars",children:s.statistics.byClass.map(T=>{const L=s.labelSchema.classes.find(O=>O.id===T.classId),E=T.count/Math.max(s.statistics.labeled,1)*100;return e.jsxs("div",{className:"distribution-row",children:[e.jsx("span",{className:"class-name",style:{color:L==null?void 0:L.color},children:L==null?void 0:L.name}),e.jsx("div",{className:"bar-container",children:e.jsx("div",{className:"bar-fill",style:{width:`${E}%`,backgroundColor:L==null?void 0:L.color}})}),e.jsx("span",{className:"count",children:T.count})]},T.classId)})})]})]})]}),p&&e.jsx("div",{className:"shortcuts-modal",children:e.jsxs("div",{className:"modal-content",children:[e.jsxs("div",{className:"modal-header",children:[e.jsx("h3",{children:"Keyboard Shortcuts"}),e.jsx("button",{onClick:()=>_(!1),children:"×"})]}),e.jsxs("div",{className:"shortcuts-list",children:[e.jsxs("div",{className:"shortcut-item",children:[e.jsx("span",{className:"keys",children:"← / A"}),e.jsx("span",{className:"description",children:"Previous item"})]}),e.jsxs("div",{className:"shortcut-item",children:[e.jsx("span",{className:"keys",children:"→ / D"}),e.jsx("span",{className:"description",children:"Next item"})]}),e.jsxs("div",{className:"shortcut-item",children:[e.jsx("span",{className:"keys",children:"Enter"}),e.jsx("span",{className:"description",children:"Approve item"})]}),e.jsxs("div",{className:"shortcut-item",children:[e.jsx("span",{className:"keys",children:"Backspace"}),e.jsx("span",{className:"description",children:"Reject item"})]}),s.labelSchema.classes.map(T=>T.shortcut&&e.jsxs("div",{className:"shortcut-item",children:[e.jsx("span",{className:"keys",children:T.shortcut}),e.jsxs("span",{className:"description",children:["Label as ",T.name]})]},T.id))]})]})})]})},it={id:crypto.randomUUID(),name:"Model Endpoint",modelId:"",modelVersion:"1.0.0",status:"stopped",url:"",authentication:{type:"api-key"},metrics:{requestsTotal:0,requestsPerSecond:0,latencyP50:0,latencyP95:0,latencyP99:0,errorRate:0,successRate:100},logs:[]},rt=({endpoint:i,onInference:a,showMetrics:t=!0,showLogs:r=!0,className:n=""})=>{const[s,m]=o.useState(i||it),[c,g]=o.useState("test"),[f,j]=o.useState("text"),[w,N]=o.useState(""),[S,$]=o.useState("{}"),[k,P]=o.useState(null),[h,d]=o.useState({temperature:.7,topK:50,topP:.9,maxTokens:256,threshold:.5}),[v,C]=o.useState(null),[p,_]=o.useState(!1),[b,u]=o.useState(null),[y,A]=o.useState([]),[R,l]=o.useState(null),x=o.useRef(null),M=I=>{var q;const F=(q=I.target.files)==null?void 0:q[0];if(F){const W=new FileReader;W.onload=U=>{var K;P((K=U.target)==null?void 0:K.result)},W.readAsDataURL(F)}},z=async()=>{if(!a){u("No inference handler provided");return}_(!0),u(null),C(null);const I=[];switch(f){case"text":I.push({type:"text",data:w});break;case"image":k&&I.push({type:"image",data:k});break;case"json":try{I.push({type:"json",data:JSON.parse(S)})}catch{u("Invalid JSON input"),_(!1);return}break;case"tabular":try{I.push({type:"tabular",data:JSON.parse(S)})}catch{u("Invalid tabular data"),_(!1);return}break}const F={inputs:I,parameters:h};try{const q=Date.now(),W=await a(F),U=Date.now()-q;C(W),m(K=>({...K,metrics:{...K.metrics,requestsTotal:K.metrics.requestsTotal+1,latencyP50:(K.metrics.latencyP50+U)/2},logs:[{timestamp:new Date,requestId:W.requestId,duration:U,status:"success",inputSize:JSON.stringify(I).length,outputSize:JSON.stringify(W.predictions).length},...K.logs.slice(0,99)]}))}catch(q){const W=q instanceof Error?q.message:"Inference failed";u(W),m(U=>({...U,metrics:{...U.metrics,requestsTotal:U.metrics.requestsTotal+1,errorRate:(U.metrics.errorRate*U.metrics.requestsTotal+1)/(U.metrics.requestsTotal+1)},logs:[{timestamp:new Date,requestId:crypto.randomUUID(),duration:0,status:"error",inputSize:JSON.stringify(I).length,outputSize:0,error:W},...U.logs.slice(0,99)]}))}finally{_(!1)}},D=async I=>{if(a){l(0),A([]);for(let F=0;F<I.length;F++){const q={inputs:[I[F]],parameters:h};try{const W=await a(q);A(U=>[...U,W])}catch(W){console.error("Batch item failed:",W)}l((F+1)/I.length*100)}l(null)}},J=I=>I<1e3?`${I.toFixed(0)}ms`:`${(I/1e3).toFixed(2)}s`,H=I=>I.toLocaleTimeString(),Y=(I,F)=>e.jsxs("div",{className:"prediction-item",children:[I.label&&e.jsxs("div",{className:"prediction-label",children:[e.jsx("span",{className:"label-name",children:I.label}),I.confidence!==void 0&&e.jsxs("span",{className:"confidence-badge",style:{backgroundColor:`hsl(${I.confidence*120}, 70%, 40%)`},children:[(I.confidence*100).toFixed(1),"%"]})]}),I.score!==void 0&&e.jsxs("div",{className:"prediction-score",children:[e.jsx("span",{className:"score-label",children:"Score:"}),e.jsx("span",{className:"score-value",children:I.score.toFixed(4)})]}),I.text&&e.jsx("div",{className:"prediction-text",children:e.jsx("pre",{children:I.text})}),I.bbox&&e.jsx("div",{className:"prediction-bbox",children:e.jsxs("span",{children:["Box: (",I.bbox.x,", ",I.bbox.y,") - ",I.bbox.width,"×",I.bbox.height]})}),I.raw!==void 0&&I.raw!==null&&e.jsxs("details",{className:"raw-output",children:[e.jsx("summary",{children:"Raw Output"}),e.jsx("pre",{children:JSON.stringify(I.raw,null,2)})]})]},F);return e.jsxs("div",{className:`nice-model-inference ${n}`,children:[e.jsxs("header",{className:"inference__header",children:[e.jsxs("div",{className:"header__info",children:[e.jsx("h2",{children:s.name}),e.jsx("span",{className:`status-badge status-badge--${s.status}`,children:s.status})]}),e.jsxs("div",{className:"header__tabs",children:[e.jsx("button",{className:`tab-button ${c==="test"?"tab-button--active":""}`,onClick:()=>g("test"),children:"Test"}),e.jsx("button",{className:`tab-button ${c==="batch"?"tab-button--active":""}`,onClick:()=>g("batch"),children:"Batch"}),t&&e.jsx("button",{className:`tab-button ${c==="metrics"?"tab-button--active":""}`,onClick:()=>g("metrics"),children:"Metrics"}),r&&e.jsx("button",{className:`tab-button ${c==="logs"?"tab-button--active":""}`,onClick:()=>g("logs"),children:"Logs"})]})]}),e.jsxs("div",{className:"inference__content",children:[c==="test"&&e.jsxs("div",{className:"test-panel",children:[e.jsxs("div",{className:"input-section",children:[e.jsx("div",{className:"input-type-selector",children:["text","image","json","tabular"].map(I=>e.jsx("button",{className:`type-button ${f===I?"type-button--active":""}`,onClick:()=>j(I),children:I.charAt(0).toUpperCase()+I.slice(1)},I))}),e.jsxs("div",{className:"input-area",children:[f==="text"&&e.jsx("textarea",{value:w,onChange:I=>N(I.target.value),placeholder:"Enter text input...",rows:6,className:"text-input"}),f==="image"&&e.jsx("div",{className:"image-input",children:k?e.jsxs("div",{className:"image-preview",children:[e.jsx("img",{src:k,alt:"Input preview"}),e.jsx("button",{className:"clear-button",onClick:()=>P(null),children:"Clear"})]}):e.jsxs("label",{className:"upload-zone",children:[e.jsx("input",{ref:x,type:"file",accept:"image/*",onChange:M,hidden:!0}),e.jsx("span",{className:"upload-icon",children:"🖼️"}),e.jsx("span",{children:"Click or drag to upload image"})]})}),(f==="json"||f==="tabular")&&e.jsx("textarea",{value:S,onChange:I=>$(I.target.value),placeholder:f==="json"?`{
|
|
12
12
|
"key": "value"
|
|
13
13
|
}`:`[
|
|
14
14
|
{"col1": "value1", "col2": "value2"}
|
|
15
|
-
]`,rows:10,className:"json-input"})]}),e.jsxs("div",{className:"parameters-section",children:[e.jsx("h4",{children:"Parameters"}),e.jsxs("div",{className:"parameters-grid",children:[e.jsxs("label",{children:["Temperature",e.jsx("input",{type:"number",value:h.temperature,onChange:I=>d({...h,temperature:parseFloat(I.target.value)}),min:"0",max:"2",step:"0.1"})]}),e.jsxs("label",{children:["Top K",e.jsx("input",{type:"number",value:h.topK,onChange:I=>d({...h,topK:parseInt(I.target.value)}),min:"1",max:"100"})]}),e.jsxs("label",{children:["Top P",e.jsx("input",{type:"number",value:h.topP,onChange:I=>d({...h,topP:parseFloat(I.target.value)}),min:"0",max:"1",step:"0.05"})]}),e.jsxs("label",{children:["Threshold",e.jsx("input",{type:"number",value:h.threshold,onChange:I=>d({...h,threshold:parseFloat(I.target.value)}),min:"0",max:"1",step:"0.05"})]})]})]}),e.jsx("button",{className:"run-button",onClick:z,disabled:
|
|
16
|
-
`);
|
|
17
|
-
`);
|
|
18
|
-
`);
|
|
15
|
+
]`,rows:10,className:"json-input"})]}),e.jsxs("div",{className:"parameters-section",children:[e.jsx("h4",{children:"Parameters"}),e.jsxs("div",{className:"parameters-grid",children:[e.jsxs("label",{children:["Temperature",e.jsx("input",{type:"number",value:h.temperature,onChange:I=>d({...h,temperature:parseFloat(I.target.value)}),min:"0",max:"2",step:"0.1"})]}),e.jsxs("label",{children:["Top K",e.jsx("input",{type:"number",value:h.topK,onChange:I=>d({...h,topK:parseInt(I.target.value)}),min:"1",max:"100"})]}),e.jsxs("label",{children:["Top P",e.jsx("input",{type:"number",value:h.topP,onChange:I=>d({...h,topP:parseFloat(I.target.value)}),min:"0",max:"1",step:"0.05"})]}),e.jsxs("label",{children:["Threshold",e.jsx("input",{type:"number",value:h.threshold,onChange:I=>d({...h,threshold:parseFloat(I.target.value)}),min:"0",max:"1",step:"0.05"})]})]})]}),e.jsx("button",{className:"run-button",onClick:z,disabled:p||!w&&!k&&S==="{}",children:p?"Running...":"Run Inference"})]}),e.jsxs("div",{className:"output-section",children:[e.jsx("h3",{children:"Output"}),b&&e.jsxs("div",{className:"error-message",children:[e.jsx("span",{className:"error-icon",children:"⚠️"}),b]}),v&&e.jsxs("div",{className:"result-container",children:[e.jsxs("div",{className:"result-meta",children:[e.jsxs("span",{children:["Request ID: ",v.requestId]}),e.jsxs("span",{children:["Latency: ",J(v.latency)]}),e.jsxs("span",{children:["Model: ",v.modelVersion]})]}),e.jsx("div",{className:"predictions-list",children:v.predictions.map((I,F)=>Y(I,F))})]}),!b&&!v&&e.jsxs("div",{className:"empty-output",children:[e.jsx("span",{className:"icon",children:"📤"}),e.jsx("p",{children:"Run inference to see results"})]})]})]}),c==="batch"&&e.jsxs("div",{className:"batch-panel",children:[e.jsxs("div",{className:"batch-upload",children:[e.jsx("h3",{children:"Batch Inference"}),e.jsx("p",{className:"hint",children:"Upload a file with multiple inputs for batch processing"}),e.jsxs("label",{className:"upload-zone",children:[e.jsx("input",{type:"file",accept:".json,.csv,.txt",onChange:async I=>{var q;const F=(q=I.target.files)==null?void 0:q[0];if(F){const W=await F.text();try{const U=JSON.parse(W);if(Array.isArray(U)){const K=U.map(Q=>({type:"json",data:Q}));D(K)}}catch{u("Invalid batch file format")}}},hidden:!0}),e.jsx("span",{className:"upload-icon",children:"📁"}),e.jsx("span",{children:"Upload JSON array file"})]})]}),R!==null&&e.jsxs("div",{className:"batch-progress",children:[e.jsx("div",{className:"progress-bar",children:e.jsx("div",{className:"progress-fill",style:{width:`${R}%`}})}),e.jsxs("span",{children:[Math.round(R),"%"]})]}),y.length>0&&e.jsxs("div",{className:"batch-results",children:[e.jsxs("h3",{children:["Results (",y.length,")"]}),e.jsx("div",{className:"results-list",children:y.map((I,F)=>e.jsxs("div",{className:"batch-result-item",children:[e.jsxs("span",{className:"result-index",children:["#",F+1]}),I.predictions.map((q,W)=>e.jsxs("span",{className:"result-prediction",children:[q.label,": ",(q.confidence||q.score||0*100).toFixed(1),"%"]},W))]},F))})]})]}),c==="metrics"&&t&&e.jsxs("div",{className:"metrics-panel",children:[e.jsxs("div",{className:"metrics-grid",children:[e.jsxs("div",{className:"metric-card",children:[e.jsx("span",{className:"metric-value",children:s.metrics.requestsTotal}),e.jsx("span",{className:"metric-label",children:"Total Requests"})]}),e.jsxs("div",{className:"metric-card",children:[e.jsx("span",{className:"metric-value",children:s.metrics.requestsPerSecond.toFixed(1)}),e.jsx("span",{className:"metric-label",children:"Requests/sec"})]}),e.jsxs("div",{className:"metric-card",children:[e.jsx("span",{className:"metric-value",children:J(s.metrics.latencyP50)}),e.jsx("span",{className:"metric-label",children:"P50 Latency"})]}),e.jsxs("div",{className:"metric-card",children:[e.jsx("span",{className:"metric-value",children:J(s.metrics.latencyP95)}),e.jsx("span",{className:"metric-label",children:"P95 Latency"})]}),e.jsxs("div",{className:"metric-card",children:[e.jsx("span",{className:"metric-value",children:J(s.metrics.latencyP99)}),e.jsx("span",{className:"metric-label",children:"P99 Latency"})]}),e.jsxs("div",{className:"metric-card",children:[e.jsxs("span",{className:"metric-value",children:[s.metrics.successRate.toFixed(1),"%"]}),e.jsx("span",{className:"metric-label",children:"Success Rate"})]}),e.jsxs("div",{className:"metric-card",children:[e.jsxs("span",{className:"metric-value",children:[(s.metrics.errorRate*100).toFixed(2),"%"]}),e.jsx("span",{className:"metric-label",children:"Error Rate"})]})]}),e.jsxs("div",{className:"latency-histogram",children:[e.jsx("h3",{children:"Latency Distribution"}),e.jsx("div",{className:"histogram-bars",children:[10,25,50,75,90,95,99].map(I=>e.jsxs("div",{className:"histogram-bar",children:[e.jsx("div",{className:"bar-fill",style:{height:`${Math.min(100,s.metrics.latencyP50*I/100)}px`}}),e.jsxs("span",{className:"percentile-label",children:["P",I]})]},I))})]})]}),c==="logs"&&r&&e.jsxs("div",{className:"logs-panel",children:[e.jsxs("div",{className:"logs-header",children:[e.jsx("h3",{children:"Request Logs"}),e.jsx("button",{className:"clear-logs-button",onClick:()=>m(I=>({...I,logs:[]})),children:"Clear Logs"})]}),e.jsx("div",{className:"logs-table",children:e.jsxs("table",{children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Time"}),e.jsx("th",{children:"Request ID"}),e.jsx("th",{children:"Duration"}),e.jsx("th",{children:"Status"}),e.jsx("th",{children:"Input Size"}),e.jsx("th",{children:"Output Size"})]})}),e.jsx("tbody",{children:s.logs.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"empty-logs",children:"No logs yet"})}):s.logs.map((I,F)=>e.jsxs("tr",{className:`log-row log-row--${I.status}`,children:[e.jsx("td",{children:H(I.timestamp)}),e.jsx("td",{className:"request-id",children:I.requestId.slice(0,8)}),e.jsx("td",{children:J(I.duration)}),e.jsx("td",{children:e.jsx("span",{className:`status-badge status-badge--${I.status}`,children:I.status})}),e.jsxs("td",{children:[I.inputSize," B"]}),e.jsxs("td",{children:[I.outputSize," B"]})]},F))})]})})]})]})]})};class te{constructor(a){this.abortController=null,this.config={timeout:3e4,maxRetries:3,retryDelay:1e3,...a}}async healthCheck(){try{return(await this.chat({messages:[{role:"user",content:"Hi"}],maxTokens:5})).choices.length>0}catch{return!1}}async fetchWithRetry(a,t,r=this.config.maxRetries){let n=null;for(let s=0;s<=r;s++)try{this.abortController=new AbortController;const m=setTimeout(()=>{var g;return(g=this.abortController)==null?void 0:g.abort()},this.config.timeout),c=await fetch(a,{...t,signal:this.abortController.signal});if(clearTimeout(m),c.ok)return c;if(c.status>=400&&c.status<500){const g=await c.text();throw new Error(`API Error ${c.status}: ${g}`)}n=new Error(`HTTP ${c.status}`)}catch(m){n=m,s<r&&await this.delay(this.config.retryDelay*(s+1))}throw n??new Error("Request failed after retries")}delay(a){return new Promise(t=>setTimeout(t,a))}async parseSSEStream(a,t,r,n){var g;const s=(g=a.body)==null?void 0:g.getReader();if(!s){n==null||n(new Error("No response body"));return}const m=new TextDecoder;let c="";try{for(;;){const{done:f,value:j}=await s.read();if(f)break;c+=m.decode(j,{stream:!0});const w=c.split(`
|
|
16
|
+
`);c=w.pop()||"";for(const N of w)if(N.startsWith("data: ")){const S=N.slice(6).trim();if(S==="[DONE]"){r==null||r();return}try{const $=JSON.parse(S);t(this.normalizeStreamChunk($))}catch{}}}r==null||r()}catch(f){n==null||n(f)}finally{s.releaseLock()}}}class ta extends te{constructor(a){super(a),this.type="openai",this.name="OpenAI",this.baseUrl=a.baseUrl||"https://api.openai.com/v1"}async chat(a){const r=await(await this.fetchWithRetry(`${this.baseUrl}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`,...this.config.headers},body:JSON.stringify(this.buildRequestBody(a))})).json();return this.normalizeResponse(r,a)}async chatStream(a,t,r,n){try{const s=await this.fetchWithRetry(`${this.baseUrl}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`,...this.config.headers},body:JSON.stringify({...this.buildRequestBody(a),stream:!0})});await this.parseSSEStream(s,t,r,n)}catch(s){n==null||n(s)}}async listModels(){return((await(await this.fetchWithRetry(`${this.baseUrl}/models`,{method:"GET",headers:{Authorization:`Bearer ${this.config.apiKey}`,...this.config.headers}})).json()).data||[]).filter(r=>r.id.includes("gpt")).map(r=>r.id)}buildRequestBody(a){return{model:a.model||this.config.model||"gpt-4o-mini",messages:a.messages,temperature:a.temperature??.7,max_tokens:a.maxTokens??1024,top_p:a.topP,frequency_penalty:a.frequencyPenalty,presence_penalty:a.presencePenalty,stop:a.stop,functions:a.functions,function_call:a.functionCall}}normalizeResponse(a,t){const r=a;return{id:r.id,model:r.model,choices:r.choices.map(n=>({index:n.index,message:n.message,finishReason:n.finish_reason})),usage:{promptTokens:r.usage.prompt_tokens,completionTokens:r.usage.completion_tokens,totalTokens:r.usage.total_tokens},estimatedCost:this.estimateCost(r.model,r.usage.prompt_tokens,r.usage.completion_tokens)}}normalizeStreamChunk(a){const t=a;return{id:t.id,choices:t.choices.map(r=>({index:r.index,delta:r.delta,finishReason:r.finish_reason}))}}estimateCost(a,t,r){const n={"gpt-4o":{input:2.5,output:10},"gpt-4o-mini":{input:.15,output:.6},"gpt-4-turbo":{input:10,output:30},"gpt-4":{input:30,output:60},"gpt-3.5-turbo":{input:.5,output:1.5}},s=Object.keys(n).find(c=>a.includes(c)),m=s?n[s]:n["gpt-4o-mini"];return t/1e6*m.input+r/1e6*m.output}}class ia extends te{constructor(a){super(a),this.type="anthropic",this.name="Anthropic Claude",this.baseUrl=a.baseUrl||"https://api.anthropic.com/v1"}async chat(a){const r=await(await this.fetchWithRetry(`${this.baseUrl}/messages`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey,"anthropic-version":"2023-06-01",...this.config.headers},body:JSON.stringify(this.buildRequestBody(a))})).json();return this.normalizeResponse(r)}async chatStream(a,t,r,n){try{const s=await this.fetchWithRetry(`${this.baseUrl}/messages`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey,"anthropic-version":"2023-06-01",...this.config.headers},body:JSON.stringify({...this.buildRequestBody(a),stream:!0})});await this.parseAnthropicStream(s,t,r,n)}catch(s){n==null||n(s)}}buildRequestBody(a){const t=a.messages.find(n=>n.role==="system"),r=a.messages.filter(n=>n.role!=="system");return{model:a.model||this.config.model||"claude-3-5-sonnet-20241022",max_tokens:a.maxTokens??1024,system:t==null?void 0:t.content,messages:r.map(n=>({role:n.role==="assistant"?"assistant":"user",content:n.content})),temperature:a.temperature??.7}}normalizeResponse(a){const t=a,r=t.content.find(n=>n.type==="text");return{id:t.id,model:t.model,choices:[{index:0,message:{role:"assistant",content:(r==null?void 0:r.text)||""},finishReason:t.stop_reason==="end_turn"?"stop":"length"}],usage:{promptTokens:t.usage.input_tokens,completionTokens:t.usage.output_tokens,totalTokens:t.usage.input_tokens+t.usage.output_tokens},estimatedCost:this.estimateCost(t.model,t.usage.input_tokens,t.usage.output_tokens)}}normalizeStreamChunk(a){var r;const t=a;return{id:"",choices:[{index:t.index||0,delta:{content:((r=t.delta)==null?void 0:r.text)||""},finishReason:t.type==="message_stop"?"stop":null}]}}async parseAnthropicStream(a,t,r,n){var g;const s=(g=a.body)==null?void 0:g.getReader();if(!s){n==null||n(new Error("No response body"));return}const m=new TextDecoder;let c="";try{for(;;){const{done:f,value:j}=await s.read();if(f)break;c+=m.decode(j,{stream:!0});const w=c.split(`
|
|
17
|
+
`);c=w.pop()||"";for(const N of w)if(N.startsWith("data: "))try{const S=JSON.parse(N.slice(6));if(S.type==="content_block_delta")t(this.normalizeStreamChunk(S));else if(S.type==="message_stop"){r==null||r();return}}catch{}}r==null||r()}catch(f){n==null||n(f)}finally{s.releaseLock()}}estimateCost(a,t,r){const n={"claude-3-5-sonnet":{input:3,output:15},"claude-3-5-haiku":{input:.25,output:1.25},"claude-3-opus":{input:15,output:75},"claude-3-sonnet":{input:3,output:15},"claude-3-haiku":{input:.25,output:1.25}},s=Object.keys(n).find(c=>a.includes(c)),m=s?n[s]:n["claude-3-5-sonnet"];return t/1e6*m.input+r/1e6*m.output}}class ra extends te{constructor(a){if(super(a),this.type="azure-openai",this.name="Azure OpenAI",!a.baseUrl||!a.deployment)throw new Error("Azure OpenAI requires baseUrl and deployment")}async chat(a){const t=`${this.config.baseUrl}/openai/deployments/${this.config.deployment}/chat/completions?api-version=${this.config.apiVersion||"2024-02-01"}`,n=await(await this.fetchWithRetry(t,{method:"POST",headers:{"Content-Type":"application/json","api-key":this.config.apiKey,...this.config.headers},body:JSON.stringify(this.buildRequestBody(a))})).json();return this.normalizeResponse(n)}async chatStream(a,t,r,n){const s=`${this.config.baseUrl}/openai/deployments/${this.config.deployment}/chat/completions?api-version=${this.config.apiVersion||"2024-02-01"}`;try{const m=await this.fetchWithRetry(s,{method:"POST",headers:{"Content-Type":"application/json","api-key":this.config.apiKey,...this.config.headers},body:JSON.stringify({...this.buildRequestBody(a),stream:!0})});await this.parseSSEStream(m,t,r,n)}catch(m){n==null||n(m)}}buildRequestBody(a){return{messages:a.messages,temperature:a.temperature??.7,max_tokens:a.maxTokens??1024,top_p:a.topP,frequency_penalty:a.frequencyPenalty,presence_penalty:a.presencePenalty,stop:a.stop}}normalizeResponse(a){const t=a;return{id:t.id,model:t.model,choices:t.choices.map(r=>({index:r.index,message:r.message,finishReason:r.finish_reason})),usage:{promptTokens:t.usage.prompt_tokens,completionTokens:t.usage.completion_tokens,totalTokens:t.usage.total_tokens}}}normalizeStreamChunk(a){const t=a;return{id:t.id,choices:t.choices.map(r=>({index:r.index,delta:r.delta,finishReason:r.finish_reason}))}}}class na extends te{constructor(a){super(a),this.type="ollama",this.name="Ollama (Local)",this.baseUrl=a.baseUrl||"http://localhost:11434"}async chat(a){const r=await(await this.fetchWithRetry(`${this.baseUrl}/api/chat`,{method:"POST",headers:{"Content-Type":"application/json",...this.config.headers},body:JSON.stringify({model:a.model||this.config.model||"llama3",messages:a.messages,stream:!1,options:{temperature:a.temperature??.7,num_predict:a.maxTokens??1024}})})).json();return this.normalizeResponse(r)}async chatStream(a,t,r,n){try{const s=await this.fetchWithRetry(`${this.baseUrl}/api/chat`,{method:"POST",headers:{"Content-Type":"application/json",...this.config.headers},body:JSON.stringify({model:a.model||this.config.model||"llama3",messages:a.messages,stream:!0,options:{temperature:a.temperature??.7,num_predict:a.maxTokens??1024}})});await this.parseOllamaStream(s,t,r,n)}catch(s){n==null||n(s)}}async listModels(){try{return((await(await this.fetchWithRetry(`${this.baseUrl}/api/tags`,{method:"GET"})).json()).models||[]).map(r=>r.name)}catch{return[]}}normalizeResponse(a){const t=a;return{id:`ollama-${Date.now()}`,model:t.model,choices:[{index:0,message:t.message,finishReason:t.done?"stop":null}],usage:{promptTokens:t.prompt_eval_count||0,completionTokens:t.eval_count||0,totalTokens:(t.prompt_eval_count||0)+(t.eval_count||0)},estimatedCost:0}}normalizeStreamChunk(a){var r;const t=a;return{id:`ollama-${Date.now()}`,choices:[{index:0,delta:{content:((r=t.message)==null?void 0:r.content)||""},finishReason:t.done?"stop":null}]}}async parseOllamaStream(a,t,r,n){var g;const s=(g=a.body)==null?void 0:g.getReader();if(!s){n==null||n(new Error("No response body"));return}const m=new TextDecoder;let c="";try{for(;;){const{done:f,value:j}=await s.read();if(f)break;c+=m.decode(j,{stream:!0});const w=c.split(`
|
|
18
|
+
`);c=w.pop()||"";for(const N of w)if(N.trim())try{const S=JSON.parse(N);if(t(this.normalizeStreamChunk(S)),S.done){r==null||r();return}}catch{}}r==null||r()}catch(f){n==null||n(f)}finally{s.releaseLock()}}}class sa extends te{constructor(a){super(a),this.type="groq",this.name="Groq",this.baseUrl=a.baseUrl||"https://api.groq.com/openai/v1"}async chat(a){const r=await(await this.fetchWithRetry(`${this.baseUrl}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`,...this.config.headers},body:JSON.stringify({model:a.model||this.config.model||"llama-3.1-70b-versatile",messages:a.messages,temperature:a.temperature??.7,max_tokens:a.maxTokens??1024})})).json();return this.normalizeResponse(r)}async chatStream(a,t,r,n){try{const s=await this.fetchWithRetry(`${this.baseUrl}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.config.apiKey}`,...this.config.headers},body:JSON.stringify({model:a.model||this.config.model||"llama-3.1-70b-versatile",messages:a.messages,temperature:a.temperature??.7,max_tokens:a.maxTokens??1024,stream:!0})});await this.parseSSEStream(s,t,r,n)}catch(s){n==null||n(s)}}normalizeResponse(a){const t=a;return{id:t.id,model:t.model,choices:t.choices.map(r=>({index:r.index,message:r.message,finishReason:r.finish_reason})),usage:{promptTokens:t.usage.prompt_tokens,completionTokens:t.usage.completion_tokens,totalTokens:t.usage.total_tokens},estimatedCost:0}}normalizeStreamChunk(a){const t=a;return{id:t.id,choices:t.choices.map(r=>({index:r.index,delta:r.delta,finishReason:r.finish_reason}))}}}function ae(i){switch(i.type){case"openai":return new ta(i);case"anthropic":return new ia(i);case"azure-openai":return new ra(i);case"ollama":return new na(i);case"groq":return new sa(i);default:throw new Error(`Unsupported provider type: ${i.type}`)}}function G(i){const a=i.endpoint.toLowerCase();let t="custom";a.includes("openai.com")?t="openai":a.includes("anthropic.com")?t="anthropic":a.includes("azure.com")||a.includes("openai.azure.com")?t="azure-openai":a.includes("localhost:11434")||a.includes("ollama")?t="ollama":a.includes("groq.com")&&(t="groq");const r=new URL(i.endpoint),n=`${r.protocol}//${r.host}`;return ae({type:t,apiKey:i.apiKey,baseUrl:n,model:i.model,headers:i.headers})}function Z(i,a){for(const n of i.variables)if(n.required&&!(n.name in a)&&!n.default)throw new Error(`Missing required variable: ${n.name}`);const t={};for(const n of i.variables)t[n.name]=a[n.name]??n.default;const r=n=>n.replace(/\{\{(\w+)\}\}/g,(s,m)=>{const c=t[m];return c===void 0?`{{${m}}}`:typeof c=="object"?JSON.stringify(c,null,2):String(c)});return{system:r(i.system),user:r(i.user),metadata:{templateId:i.id,variables:t,timestamp:Date.now()}}}const re={id:"data-grid-filter",name:"DataGrid Natural Language Filter",description:"Convert natural language queries to DataGrid filter configurations",category:"data-query",system:`You are a filter query generator for a data grid component.
|
|
19
19
|
Given column definitions and a natural language query, generate a JSON filter configuration.
|
|
20
20
|
|
|
21
21
|
Available filter operators:
|
|
@@ -116,7 +116,7 @@ Generate the form configuration:`,variables:[{name:"description",description:"Na
|
|
|
116
116
|
{ "id": "message", "type": "textarea", "label": "Message", "required": true }
|
|
117
117
|
],
|
|
118
118
|
"layout": { "columns": 1 }
|
|
119
|
-
}`}],suggestedTemperature:.5,maxTokens:2048},
|
|
119
|
+
}`}],suggestedTemperature:.5,maxTokens:2048},ce={id:"chart-config",name:"Chart Configuration Generator",description:"Generate chart configuration from data description",category:"chart-config",system:`You are a data visualization expert. Generate chart configurations from descriptions.
|
|
120
120
|
|
|
121
121
|
Available chart types:
|
|
122
122
|
- line, area, bar, column
|
|
@@ -156,7 +156,7 @@ Available data fields: {{data}}
|
|
|
156
156
|
Context: {{context}}
|
|
157
157
|
{{/if}}
|
|
158
158
|
|
|
159
|
-
Generate the chart configuration:`,variables:[{name:"request",description:"Natural language chart request",required:!0,type:"string"},{name:"data",description:"Available data fields",required:!1,type:"json"},{name:"context",description:"Additional context",required:!1,type:"string"}],suggestedTemperature:.4,maxTokens:1024},
|
|
159
|
+
Generate the chart configuration:`,variables:[{name:"request",description:"Natural language chart request",required:!0,type:"string"},{name:"data",description:"Available data fields",required:!1,type:"json"},{name:"context",description:"Additional context",required:!1,type:"string"}],suggestedTemperature:.4,maxTokens:1024},oe={id:"code-completion",name:"Code Completion",description:"Complete code based on context",category:"code-completion",system:`You are an expert programmer. Complete the code based on context.
|
|
160
160
|
|
|
161
161
|
Rules:
|
|
162
162
|
- Match the existing code style
|
|
@@ -283,7 +283,7 @@ Output JSON:
|
|
|
283
283
|
{{#if industry}}Industry: {{industry}}{{/if}}
|
|
284
284
|
{{#if style}}Style preference: {{style}}{{/if}}
|
|
285
285
|
|
|
286
|
-
Generate the complete theme:`,variables:[{name:"primaryColor",description:"Primary brand color (hex)",required:!0,type:"string"},{name:"secondaryColor",description:"Secondary brand color (hex)",required:!1,type:"string"},{name:"accentColor",description:"Accent color (hex)",required:!1,type:"string"},{name:"industry",description:"Industry (healthcare, finance, etc.)",required:!1,type:"string"},{name:"style",description:"Style preference (modern, classic, playful)",required:!1,type:"string"}],suggestedTemperature:.5,maxTokens:2048},
|
|
286
|
+
Generate the complete theme:`,variables:[{name:"primaryColor",description:"Primary brand color (hex)",required:!0,type:"string"},{name:"secondaryColor",description:"Secondary brand color (hex)",required:!1,type:"string"},{name:"accentColor",description:"Accent color (hex)",required:!1,type:"string"},{name:"industry",description:"Industry (healthcare, finance, etc.)",required:!1,type:"string"},{name:"style",description:"Style preference (modern, classic, playful)",required:!1,type:"string"}],suggestedTemperature:.5,maxTokens:2048},ye={id:"accessibility-checker",name:"Accessibility Checker",description:"Check and fix accessibility issues in HTML/JSX",category:"accessibility",system:`You are a web accessibility expert (WCAG 2.1 AA/AAA certified).
|
|
287
287
|
Analyze code for accessibility issues and provide fixes.
|
|
288
288
|
|
|
289
289
|
Check for:
|
|
@@ -352,7 +352,7 @@ Format output as structured JSON:
|
|
|
352
352
|
|
|
353
353
|
{{#if context}}Context: {{context}}{{/if}}
|
|
354
354
|
|
|
355
|
-
Provide summary and insights:`,variables:[{name:"data",description:"Data to summarize (JSON or CSV)",required:!0,type:"string"},{name:"context",description:"Business context",required:!1,type:"string"}],suggestedTemperature:.4,maxTokens:1024},he={[re.id]:re,[ne.id]:ne,[se.id]:se,[oe.id]:oe,[ce.id]:ce,[le.id]:le,[de.id]:de,[ue.id]:ue,[ve.id]:ve,[_e.id]:_e,[we.id]:we};function ni(a){return he[a]}function si(a){return Object.values(he).filter(t=>t.category===a)}function oi(){return Object.keys(he)}class Re{constructor(){this.records=new Map}async save(t,i){const r=this.records.get(t)||[];this.records.set(t,[...r,...i])}async load(t,i,r){const n=this.records.get(t)||[];return!i&&!r?n:n.filter(s=>!(i&&s.timestamp<i.getTime()||r&&s.timestamp>r.getTime()))}async clear(t,i){if(!i)this.records.delete(t);else{const r=this.records.get(t)||[];this.records.set(t,r.filter(n=>n.timestamp>=i.getTime()))}}}class ot{constructor(){this.prefix="nice2dev-ai-cost:"}async save(t,i){if(typeof window>"u")return;const r=`${this.prefix}${t}`,s=[...JSON.parse(localStorage.getItem(r)||"[]"),...i],p=Date.now()-30*24*60*60*1e3,o=s.filter(g=>g.timestamp>p);localStorage.setItem(r,JSON.stringify(o))}async load(t,i,r){if(typeof window>"u")return[];const n=`${this.prefix}${t}`,s=JSON.parse(localStorage.getItem(n)||"[]");return!i&&!r?s:s.filter(p=>!(i&&p.timestamp<i.getTime()||r&&p.timestamp>r.getTime()))}async clear(t,i){if(typeof window>"u")return;const r=`${this.prefix}${t}`;if(!i)localStorage.removeItem(r);else{const n=JSON.parse(localStorage.getItem(r)||"[]");localStorage.setItem(r,JSON.stringify(n.filter(s=>s.timestamp>=i.getTime())))}}}class ct{constructor(t,i){this.pendingRecords=[],this.flushTimer=null,this.alertCallbacks=[],this.minuteCounter=new Map,this.dayCounter=new Map,this.storage=t||new Re,this.budgetConfig={monthlyBudget:100,dailyBudget:10,maxTokensPerRequest:4096,maxRequestsPerMinute:30,maxRequestsPerDay:1e3,alertThresholds:[50,80,90,100],...i}}async recordUsage(t,i){const r={...i,id:this.generateId(),timestamp:Date.now()};this.pendingRecords.push(r),this.updateCounters(t),this.scheduleFlush(t);const n=await this.getBudgetStatus(t);this.checkAlerts(t,n)}async canMakeRequest(t){const i=await this.getBudgetStatus(t);return i.isOverBudget?{allowed:!1,reason:"Budget exceeded"}:this.budgetConfig.maxRequestsPerMinute&&i.requestsThisMinute>=this.budgetConfig.maxRequestsPerMinute?{allowed:!1,reason:"Rate limit exceeded (per minute)"}:this.budgetConfig.maxRequestsPerDay&&i.requestsToday>=this.budgetConfig.maxRequestsPerDay?{allowed:!1,reason:"Daily request limit exceeded"}:{allowed:!0}}async getBudgetStatus(t){const i=new Date,r=new Date(i.getFullYear(),i.getMonth(),i.getDate()),n=new Date(i.getFullYear(),i.getMonth(),1),s=await this.storage.load(t,r),p=await this.storage.load(t,n),o=s.reduce(($,k)=>$+k.estimatedCost,0),g=p.reduce(($,k)=>$+k.estimatedCost,0),f=this.budgetConfig.dailyBudget||1/0,j=this.budgetConfig.monthlyBudget||1/0,w=f?o/f*100:0,N=j?g/j*100:0,S=[];for(const $ of this.budgetConfig.alertThresholds||[])w>=$&&S.push(`Daily budget ${$}% used`),N>=$&&S.push(`Monthly budget ${$}% used`);return{dailyUsed:o,dailyRemaining:Math.max(0,f-o),dailyPercent:w,monthlyUsed:g,monthlyRemaining:Math.max(0,j-g),monthlyPercent:N,requestsToday:s.length,requestsThisMinute:this.getMinuteCount(t),isOverBudget:o>=f||g>=j,alerts:S}}async getUsageStats(t,i,r){const n=await this.storage.load(t,i,r),s={totalRequests:n.length,totalTokens:0,totalPromptTokens:0,totalCompletionTokens:0,totalCost:0,averageLatency:0,errorCount:0,cacheHitRate:0,byModel:{},byFeature:{},byDay:{}};let p=0,o=0;for(const g of n){s.totalTokens+=g.totalTokens,s.totalPromptTokens+=g.promptTokens,s.totalCompletionTokens+=g.completionTokens,s.totalCost+=g.estimatedCost,p+=g.latencyMs,g.error&&s.errorCount++,g.cached&&o++,s.byModel[g.model]||(s.byModel[g.model]={requests:0,tokens:0,cost:0}),s.byModel[g.model].requests++,s.byModel[g.model].tokens+=g.totalTokens,s.byModel[g.model].cost+=g.estimatedCost;const f=g.feature||"unknown";s.byFeature[f]||(s.byFeature[f]={requests:0,tokens:0,cost:0}),s.byFeature[f].requests++,s.byFeature[f].tokens+=g.totalTokens,s.byFeature[f].cost+=g.estimatedCost;const j=new Date(g.timestamp).toISOString().split("T")[0];s.byDay[j]||(s.byDay[j]={requests:0,tokens:0,cost:0}),s.byDay[j].requests++,s.byDay[j].tokens+=g.totalTokens,s.byDay[j].cost+=g.estimatedCost}return n.length>0&&(s.averageLatency=p/n.length,s.cacheHitRate=o/n.length),s}onAlert(t){return this.alertCallbacks.push(t),()=>{const i=this.alertCallbacks.indexOf(t);i>=0&&this.alertCallbacks.splice(i,1)}}setBudgetConfig(t){this.budgetConfig={...this.budgetConfig,...t}}async clearUsage(t,i){await this.storage.clear(t,i)}generateId(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}updateCounters(t){const i=Date.now(),r=i-6e4,n=this.minuteCounter.get(t)||[];n.push(i),this.minuteCounter.set(t,n.filter(o=>o>r));const s=new Date().toISOString().split("T")[0],p=`${t}:${s}`;this.dayCounter.set(p,(this.dayCounter.get(p)||0)+1)}getMinuteCount(t){const r=Date.now()-6e4;return(this.minuteCounter.get(t)||[]).filter(s=>s>r).length}scheduleFlush(t){this.flushTimer||(this.flushTimer=setTimeout(async()=>{this.flushTimer=null,this.pendingRecords.length>0&&(await this.storage.save(t,this.pendingRecords),this.pendingRecords=[])},1e3))}checkAlerts(t,i){if(i.alerts.length!==0)for(const r of i.alerts)for(const n of this.alertCallbacks)try{n(r,i)}catch{}}}function ci(a,t){const i=c.useRef(null),[r,n]=c.useState(null),[s,p]=c.useState(null),[o,g]=c.useState(!0);c.useEffect(()=>{const N=typeof window<"u"?new ot:new Re;i.current=new ct(N,t);const S=i.current.onAlert($=>{console.warn(`[AI Cost Alert] ${$}`)});return()=>{S()}},[]);const f=c.useCallback(async()=>{if(i.current){g(!0);try{const[N,S]=await Promise.all([i.current.getBudgetStatus(a),i.current.getUsageStats(a)]);n(N),p(S)}finally{g(!1)}}},[a]);c.useEffect(()=>{f()},[f]);const j=c.useCallback(async N=>{i.current&&(await i.current.recordUsage(a,N),await f())},[a,f]),w=c.useCallback(async()=>i.current?i.current.canMakeRequest(a):{allowed:!0},[a]);return{status:r,stats:s,loading:o,recordUsage:j,canMakeRequest:w,refresh:f}}class li{constructor(t=100,i=36e5){this.cache=new Map,this.maxSize=t,this.ttl=i}hashRequest(t){const i=JSON.stringify({messages:t.messages,model:t.model,temperature:t.temperature});let r=0;for(let n=0;n<i.length;n++){const s=i.charCodeAt(n);r=(r<<5)-r+s,r=r&r}return r.toString(36)}get(t){const i=this.hashRequest(t),r=this.cache.get(i);return r?Date.now()-r.timestamp>this.ttl?(this.cache.delete(i),null):r.response:null}set(t,i){const r=this.hashRequest(t);if(this.cache.size>=this.maxSize){const n=this.cache.keys().next().value;n&&this.cache.delete(n)}this.cache.set(r,{request:r,response:i,timestamp:Date.now()})}clear(){this.cache.clear()}}class lt{constructor(t,i){this.backupProviders=[],this.circuitBreakers=new Map,this.primaryProvider=t,this.config={strategies:["retry","failover","cache","graceful-degrade"],maxRetries:3,retryDelay:1e3,backoffMultiplier:2,backupProviders:[],cacheTTL:36e5,offlineConfig:void 0,circuitBreakerThreshold:5,circuitBreakerResetTime:6e4,onFallback:void 0,...i},this.cache=new li(100,this.config.cacheTTL);for(const r of this.config.backupProviders||[])this.backupProviders.push(te(r));this.config.offlineConfig&&(this.offlineProvider=te(this.config.offlineConfig))}async chat(t){if(this.isCircuitOpen(this.primaryProvider.type))return this.executeWithFallback(t,new Error("Circuit breaker open"));try{const i=await this.primaryProvider.chat(t);return this.cache.set(t,i),this.resetCircuitBreaker(this.primaryProvider.type),i}catch(i){return this.recordFailure(this.primaryProvider.type),this.executeWithFallback(t,i)}}async executeWithFallback(t,i){var r,n;for(const s of this.config.strategies)try{const p=await this.executeStrategy(s,t,i);if(p)return(n=(r=this.config).onFallback)==null||n.call(r,s,i),p}catch{}throw new Error(`All fallback strategies failed. Original error: ${i.message}`)}async executeStrategy(t,i,r){switch(t){case"retry":return this.retryStrategy(i);case"failover":return this.failoverStrategy(i);case"cache":return this.cacheStrategy(i);case"offline":return this.offlineStrategy(i);case"graceful-degrade":return this.gracefulDegradeStrategy(i,r);case"circuit-breaker":return this.openCircuitBreaker(this.primaryProvider.type),null;default:return null}}async retryStrategy(t){let i=this.config.retryDelay;for(let r=0;r<this.config.maxRetries;r++){await this.delay(i);try{const n=await this.primaryProvider.chat(t);return this.cache.set(t,n),n}catch{i*=this.config.backoffMultiplier}}return null}async failoverStrategy(t){for(const i of this.backupProviders)if(!this.isCircuitOpen(i.type))try{const r=await i.chat(t);return this.cache.set(t,r),r}catch{this.recordFailure(i.type)}return null}cacheStrategy(t){const i=this.cache.get(t);return i?{...i,id:`cached-${i.id}`}:null}async offlineStrategy(t){if(!this.offlineProvider)return null;try{return await this.offlineProvider.chat(t)}catch{return null}}gracefulDegradeStrategy(t,i){const r=[...t.messages].reverse().find(n=>n.role==="user");return{id:`degraded-${Date.now()}`,model:"fallback",choices:[{index:0,message:{role:"assistant",content:this.generateDegradedResponse((r==null?void 0:r.content)||"",i)},finishReason:"stop"}],usage:{promptTokens:0,completionTokens:0,totalTokens:0}}}generateDegradedResponse(t,i){return t.toLowerCase().includes("filter")||t.toLowerCase().includes("show")?JSON.stringify({filters:[],logic:"and"}):t.toLowerCase().includes("form")||t.toLowerCase().includes("create")?JSON.stringify({title:"Form",fields:[{id:"field1",type:"text",label:"Field 1"}]}):t.toLowerCase().includes("chart")||t.toLowerCase().includes("graph")?JSON.stringify({type:"bar",title:"Chart",data:{source:"data"}}):`I'm sorry, I couldn't process your request at this time. The service is temporarily unavailable. Please try again later or contact support. (Error: ${i.message.substring(0,50)})`}isCircuitOpen(t){const i=this.circuitBreakers.get(t);return i&&i.isOpen?Date.now()-i.lastFailure>this.config.circuitBreakerResetTime?(this.resetCircuitBreaker(t),!1):!0:!1}recordFailure(t){const i=this.circuitBreakers.get(t)||{failures:0,lastFailure:0,isOpen:!1};i.failures++,i.lastFailure=Date.now(),i.failures>=this.config.circuitBreakerThreshold&&(i.isOpen=!0),this.circuitBreakers.set(t,i)}openCircuitBreaker(t){this.circuitBreakers.set(t,{failures:this.config.circuitBreakerThreshold,lastFailure:Date.now(),isOpen:!0})}resetCircuitBreaker(t){this.circuitBreakers.delete(t)}delay(t){return new Promise(i=>setTimeout(i,t))}addBackupProvider(t){this.backupProviders.push(t)}setOfflineProvider(t){this.offlineProvider=t}clearCache(){this.cache.clear()}resetAllCircuitBreakers(){this.circuitBreakers.clear()}getCircuitBreakerStatus(){const t={};for(const[i,r]of this.circuitBreakers)t[i]={...r};return t}async healthCheck(){const t={};t[this.primaryProvider.type]=await this.primaryProvider.healthCheck();for(const i of this.backupProviders)t[`backup-${i.type}`]=await i.healthCheck();return this.offlineProvider&&(t.offline=await this.offlineProvider.healthCheck()),t}}function dt(a,t){const i=te(a);return new lt(i,t)}function di(a,t){const i={strategies:["retry","failover","cache","graceful-degrade"],maxRetries:3,retryDelay:1e3,backoffMultiplier:2,backupProviders:t?[t]:[],circuitBreakerThreshold:5,circuitBreakerResetTime:6e4};return typeof window>"u"&&(i.offlineConfig={type:"ollama",model:"llama3"}),dt(a,i)}function ut(a){const{columns:t,config:i,onFilterGenerated:r,onSortGenerated:n,onError:s}=a,p=X(),[o,g]=c.useState(!1),[f,j]=c.useState(null),[w,N]=c.useState(null),[S,$]=c.useState([]),k=c.useRef(null),P=i||(p==null?void 0:p.config),h=c.useMemo(()=>t.map(m=>({id:m.id,label:m.label,type:m.type,...m.options?{options:m.options}:{}})),[t]),d=c.useCallback(async m=>{var b;if(!P){const u="AI not configured. Provide config or wrap in NiceAIProvider.";return s==null||s(u),{type:"filter",error:u}}g(!0),j(m);const _=performance.now();(b=k.current)==null||b.abort(),k.current=new AbortController;try{const u=G(P),v=m.toLowerCase(),A=v.includes("sort")||v.includes("order")||v.includes("arrange")||v.includes("by highest")||v.includes("by lowest"),R=v.includes("show")||v.includes("find")||v.includes("filter")||v.includes("where")||v.includes("with")||v.includes("only")||!A,l={type:"combined"};if(R){const x=Z(re,{columns:h,query:m}),M=await u.chat({messages:[{role:"system",content:x.system},{role:"user",content:x.user}],temperature:.2,maxTokens:512}),z=ui(M);z&&(l.filterConfig=z,l.type="filter",r==null||r(z))}if(A){const x=Z(ne,{columns:h,query:m}),M=await u.chat({messages:[{role:"system",content:x.system},{role:"user",content:x.user}],temperature:.1,maxTokens:256}),z=mi(M);z&&(l.sortConfig=z,l.type=l.filterConfig?"combined":"sort",n==null||n(z))}return l.latencyMs=performance.now()-_,N(l),$(x=>[...x.slice(-9),{query:m,result:l}]),l}catch(u){const v=u instanceof Error?u.message:"AI request failed",A={type:"filter",error:v,latencyMs:performance.now()-_};return N(A),s==null||s(v),A}finally{g(!1)}},[P,h,r,n,s]),y=c.useCallback(()=>{j(null),N(null)},[]),C=c.useCallback(()=>{var m;(m=k.current)==null||m.abort(),g(!1)},[]);return c.useEffect(()=>()=>{var m;(m=k.current)==null||m.abort()},[]),{processQuery:d,loading:o,lastQuery:f,lastResult:w,history:S,clearResults:y,abort:C,isConfigured:!!P}}function ui(a){var t,i,r;try{const n=((i=(t=a.choices[0])==null?void 0:t.message)==null?void 0:i.content)||"",p=((r=(n.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,n])[1])==null?void 0:r.trim())||n,o=JSON.parse(p);if(o.filters&&Array.isArray(o.filters))return{filters:o.filters,logic:o.logic||"and",confidence:o.confidence,explanation:o.explanation}}catch{}return null}function mi(a){var t,i,r;try{const n=((i=(t=a.choices[0])==null?void 0:t.message)==null?void 0:i.content)||"",p=((r=(n.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,n])[1])==null?void 0:r.trim())||n,o=JSON.parse(p);if(o.sort&&Array.isArray(o.sort))return{sort:o.sort,confidence:o.confidence}}catch{}return null}function pi({columns:a,config:t,onFilter:i,onSort:r,placeholder:n='Ask AI to filter or sort data... (e.g., "show orders from last week")',showHistory:s=!0,showSuggestions:p=!0,className:o,style:g}){const[f,j]=c.useState(""),[w,N]=c.useState(!1),S=c.useRef(null),{processQuery:$,loading:k,lastResult:P,history:h,isConfigured:d}=ut({columns:a,config:t,onFilterGenerated:i,onSortGenerated:r}),y=c.useMemo(()=>{if(!p||a.length===0)return[];const u=[],v=a.filter(x=>x.type==="string");v.length>0&&u.push(`Show ${v[0].label}s containing "example"`);const A=a.filter(x=>x.type==="number");A.length>0&&(u.push(`${A[0].label} greater than 100`),u.push(`Sort by highest ${A[0].label}`));const R=a.filter(x=>x.type==="date");R.length>0&&(u.push(`${R[0].label} in the last 7 days`),u.push(`Sort by newest ${R[0].label}`));const l=a.filter(x=>{var M;return x.type==="enum"&&((M=x.options)==null?void 0:M.length)});return l.length>0&&l[0].options&&u.push(`Where ${l[0].label} is ${l[0].options[0]}`),u.slice(0,5)},[a,p]),C=async()=>{!f.trim()||k||(await $(f.trim()),N(!1))},m=u=>{u.key==="Enter"?(u.preventDefault(),C()):u.key==="Escape"&&N(!1)},_=u=>{var v;j(u),N(!1),(v=S.current)==null||v.focus()},b=u=>{j(u),N(!1),$(u)};return d?e.jsxs("div",{className:`nice-datagrid-ai ${o||""}`,style:g,children:[e.jsxs("div",{className:"nice-datagrid-ai__input-wrapper",children:[e.jsx("span",{className:"nice-datagrid-ai__icon",children:e.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor",children:e.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.94-.49-7-3.85-7-7.93s3.05-7.44 7-7.93v15.86zm2-15.86c1.03.13 2 .45 2.87.93H13v-.93zM13 7h5.24c.25.31.48.65.68 1H13V7zm0 3h6.74c.08.33.15.66.19 1H13v-1zm0 9.93V19h2.87c-.87.48-1.84.8-2.87.93zM18.24 17H13v-1h5.92c-.2.35-.43.69-.68 1zm1.5-3H13v-1h6.93c-.04.34-.11.67-.19 1z"})})}),e.jsx("input",{ref:S,type:"text",value:f,onChange:u=>j(u.target.value),onKeyDown:m,onFocus:()=>N(!0),onBlur:()=>setTimeout(()=>N(!1),200),placeholder:n,className:"nice-datagrid-ai__input",disabled:k,"aria-label":"AI query input"}),k?e.jsx("span",{className:"nice-datagrid-ai__spinner"}):e.jsx("button",{type:"button",onClick:C,className:"nice-datagrid-ai__submit",disabled:!f.trim(),"aria-label":"Submit query",children:e.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor",children:e.jsx("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})})})]}),w&&(y.length>0||s&&h.length>0)&&e.jsxs("div",{className:"nice-datagrid-ai__dropdown",children:[p&&y.length>0&&e.jsxs("div",{className:"nice-datagrid-ai__section",children:[e.jsx("div",{className:"nice-datagrid-ai__section-title",children:"Suggestions"}),y.map((u,v)=>e.jsxs("button",{type:"button",className:"nice-datagrid-ai__item",onClick:()=>_(u),children:[e.jsx("span",{className:"nice-datagrid-ai__item-icon",children:"💡"}),u]},v))]}),s&&h.length>0&&e.jsxs("div",{className:"nice-datagrid-ai__section",children:[e.jsx("div",{className:"nice-datagrid-ai__section-title",children:"Recent"}),h.slice(-5).reverse().map((u,v)=>e.jsxs("button",{type:"button",className:"nice-datagrid-ai__item",onClick:()=>b(u.query),children:[e.jsx("span",{className:"nice-datagrid-ai__item-icon",children:"🕐"}),u.query,u.result.error&&e.jsx("span",{className:"nice-datagrid-ai__item-error",children:"⚠️"})]},v))]})]}),P&&!P.error&&e.jsxs("div",{className:"nice-datagrid-ai__result",children:[P.filterConfig&&e.jsxs("span",{className:"nice-datagrid-ai__badge nice-datagrid-ai__badge--filter",children:[P.filterConfig.filters.length," filter",P.filterConfig.filters.length!==1?"s":""," applied"]}),P.sortConfig&&e.jsxs("span",{className:"nice-datagrid-ai__badge nice-datagrid-ai__badge--sort",children:["Sorted by ",P.sortConfig.sort.map(u=>u.column).join(", ")]}),P.latencyMs&&e.jsxs("span",{className:"nice-datagrid-ai__latency",children:[Math.round(P.latencyMs),"ms"]})]}),(P==null?void 0:P.error)&&e.jsx("div",{className:"nice-datagrid-ai__error",children:P.error}),e.jsx("style",{children:`
|
|
355
|
+
Provide summary and insights:`,variables:[{name:"data",description:"Data to summarize (JSON or CSV)",required:!0,type:"string"},{name:"context",description:"Business context",required:!1,type:"string"}],suggestedTemperature:.4,maxTokens:1024},he={[re.id]:re,[ne.id]:ne,[se.id]:se,[ce.id]:ce,[oe.id]:oe,[le.id]:le,[de.id]:de,[ue.id]:ue,[ye.id]:ye,[_e.id]:_e,[we.id]:we};function nt(i){return he[i]}function st(i){return Object.values(he).filter(a=>a.category===i)}function ct(){return Object.keys(he)}class Re{constructor(){this.records=new Map}async save(a,t){const r=this.records.get(a)||[];this.records.set(a,[...r,...t])}async load(a,t,r){const n=this.records.get(a)||[];return!t&&!r?n:n.filter(s=>!(t&&s.timestamp<t.getTime()||r&&s.timestamp>r.getTime()))}async clear(a,t){if(!t)this.records.delete(a);else{const r=this.records.get(a)||[];this.records.set(a,r.filter(n=>n.timestamp>=t.getTime()))}}}class ca{constructor(){this.prefix="nice2dev-ai-cost:"}async save(a,t){if(typeof window>"u")return;const r=`${this.prefix}${a}`,s=[...JSON.parse(localStorage.getItem(r)||"[]"),...t],m=Date.now()-30*24*60*60*1e3,c=s.filter(g=>g.timestamp>m);localStorage.setItem(r,JSON.stringify(c))}async load(a,t,r){if(typeof window>"u")return[];const n=`${this.prefix}${a}`,s=JSON.parse(localStorage.getItem(n)||"[]");return!t&&!r?s:s.filter(m=>!(t&&m.timestamp<t.getTime()||r&&m.timestamp>r.getTime()))}async clear(a,t){if(typeof window>"u")return;const r=`${this.prefix}${a}`;if(!t)localStorage.removeItem(r);else{const n=JSON.parse(localStorage.getItem(r)||"[]");localStorage.setItem(r,JSON.stringify(n.filter(s=>s.timestamp>=t.getTime())))}}}class oa{constructor(a,t){this.pendingRecords=[],this.flushTimer=null,this.alertCallbacks=[],this.minuteCounter=new Map,this.dayCounter=new Map,this.storage=a||new Re,this.budgetConfig={monthlyBudget:100,dailyBudget:10,maxTokensPerRequest:4096,maxRequestsPerMinute:30,maxRequestsPerDay:1e3,alertThresholds:[50,80,90,100],...t}}async recordUsage(a,t){const r={...t,id:this.generateId(),timestamp:Date.now()};this.pendingRecords.push(r),this.updateCounters(a),this.scheduleFlush(a);const n=await this.getBudgetStatus(a);this.checkAlerts(a,n)}async canMakeRequest(a){const t=await this.getBudgetStatus(a);return t.isOverBudget?{allowed:!1,reason:"Budget exceeded"}:this.budgetConfig.maxRequestsPerMinute&&t.requestsThisMinute>=this.budgetConfig.maxRequestsPerMinute?{allowed:!1,reason:"Rate limit exceeded (per minute)"}:this.budgetConfig.maxRequestsPerDay&&t.requestsToday>=this.budgetConfig.maxRequestsPerDay?{allowed:!1,reason:"Daily request limit exceeded"}:{allowed:!0}}async getBudgetStatus(a){const t=new Date,r=new Date(t.getFullYear(),t.getMonth(),t.getDate()),n=new Date(t.getFullYear(),t.getMonth(),1),s=await this.storage.load(a,r),m=await this.storage.load(a,n),c=s.reduce(($,k)=>$+k.estimatedCost,0),g=m.reduce(($,k)=>$+k.estimatedCost,0),f=this.budgetConfig.dailyBudget||1/0,j=this.budgetConfig.monthlyBudget||1/0,w=f?c/f*100:0,N=j?g/j*100:0,S=[];for(const $ of this.budgetConfig.alertThresholds||[])w>=$&&S.push(`Daily budget ${$}% used`),N>=$&&S.push(`Monthly budget ${$}% used`);return{dailyUsed:c,dailyRemaining:Math.max(0,f-c),dailyPercent:w,monthlyUsed:g,monthlyRemaining:Math.max(0,j-g),monthlyPercent:N,requestsToday:s.length,requestsThisMinute:this.getMinuteCount(a),isOverBudget:c>=f||g>=j,alerts:S}}async getUsageStats(a,t,r){const n=await this.storage.load(a,t,r),s={totalRequests:n.length,totalTokens:0,totalPromptTokens:0,totalCompletionTokens:0,totalCost:0,averageLatency:0,errorCount:0,cacheHitRate:0,byModel:{},byFeature:{},byDay:{}};let m=0,c=0;for(const g of n){s.totalTokens+=g.totalTokens,s.totalPromptTokens+=g.promptTokens,s.totalCompletionTokens+=g.completionTokens,s.totalCost+=g.estimatedCost,m+=g.latencyMs,g.error&&s.errorCount++,g.cached&&c++,s.byModel[g.model]||(s.byModel[g.model]={requests:0,tokens:0,cost:0}),s.byModel[g.model].requests++,s.byModel[g.model].tokens+=g.totalTokens,s.byModel[g.model].cost+=g.estimatedCost;const f=g.feature||"unknown";s.byFeature[f]||(s.byFeature[f]={requests:0,tokens:0,cost:0}),s.byFeature[f].requests++,s.byFeature[f].tokens+=g.totalTokens,s.byFeature[f].cost+=g.estimatedCost;const j=new Date(g.timestamp).toISOString().split("T")[0];s.byDay[j]||(s.byDay[j]={requests:0,tokens:0,cost:0}),s.byDay[j].requests++,s.byDay[j].tokens+=g.totalTokens,s.byDay[j].cost+=g.estimatedCost}return n.length>0&&(s.averageLatency=m/n.length,s.cacheHitRate=c/n.length),s}onAlert(a){return this.alertCallbacks.push(a),()=>{const t=this.alertCallbacks.indexOf(a);t>=0&&this.alertCallbacks.splice(t,1)}}setBudgetConfig(a){this.budgetConfig={...this.budgetConfig,...a}}async clearUsage(a,t){await this.storage.clear(a,t)}generateId(){return`${Date.now()}-${Math.random().toString(36).substr(2,9)}`}updateCounters(a){const t=Date.now(),r=t-6e4,n=this.minuteCounter.get(a)||[];n.push(t),this.minuteCounter.set(a,n.filter(c=>c>r));const s=new Date().toISOString().split("T")[0],m=`${a}:${s}`;this.dayCounter.set(m,(this.dayCounter.get(m)||0)+1)}getMinuteCount(a){const r=Date.now()-6e4;return(this.minuteCounter.get(a)||[]).filter(s=>s>r).length}scheduleFlush(a){this.flushTimer||(this.flushTimer=setTimeout(async()=>{this.flushTimer=null,this.pendingRecords.length>0&&(await this.storage.save(a,this.pendingRecords),this.pendingRecords=[])},1e3))}checkAlerts(a,t){if(t.alerts.length!==0)for(const r of t.alerts)for(const n of this.alertCallbacks)try{n(r,t)}catch{}}}function ot(i,a){const t=o.useRef(null),[r,n]=o.useState(null),[s,m]=o.useState(null),[c,g]=o.useState(!0);o.useEffect(()=>{const N=typeof window<"u"?new ca:new Re;t.current=new oa(N,a);const S=t.current.onAlert($=>{console.warn(`[AI Cost Alert] ${$}`)});return()=>{S()}},[]);const f=o.useCallback(async()=>{if(t.current){g(!0);try{const[N,S]=await Promise.all([t.current.getBudgetStatus(i),t.current.getUsageStats(i)]);n(N),m(S)}finally{g(!1)}}},[i]);o.useEffect(()=>{f()},[f]);const j=o.useCallback(async N=>{t.current&&(await t.current.recordUsage(i,N),await f())},[i,f]),w=o.useCallback(async()=>t.current?t.current.canMakeRequest(i):{allowed:!0},[i]);return{status:r,stats:s,loading:c,recordUsage:j,canMakeRequest:w,refresh:f}}class lt{constructor(a=100,t=36e5){this.cache=new Map,this.maxSize=a,this.ttl=t}hashRequest(a){const t=JSON.stringify({messages:a.messages,model:a.model,temperature:a.temperature});let r=0;for(let n=0;n<t.length;n++){const s=t.charCodeAt(n);r=(r<<5)-r+s,r=r&r}return r.toString(36)}get(a){const t=this.hashRequest(a),r=this.cache.get(t);return r?Date.now()-r.timestamp>this.ttl?(this.cache.delete(t),null):r.response:null}set(a,t){const r=this.hashRequest(a);if(this.cache.size>=this.maxSize){const n=this.cache.keys().next().value;n&&this.cache.delete(n)}this.cache.set(r,{request:r,response:t,timestamp:Date.now()})}clear(){this.cache.clear()}}class la{constructor(a,t){this.backupProviders=[],this.circuitBreakers=new Map,this.primaryProvider=a,this.config={strategies:["retry","failover","cache","graceful-degrade"],maxRetries:3,retryDelay:1e3,backoffMultiplier:2,backupProviders:[],cacheTTL:36e5,offlineConfig:void 0,circuitBreakerThreshold:5,circuitBreakerResetTime:6e4,onFallback:void 0,...t},this.cache=new lt(100,this.config.cacheTTL);for(const r of this.config.backupProviders||[])this.backupProviders.push(ae(r));this.config.offlineConfig&&(this.offlineProvider=ae(this.config.offlineConfig))}async chat(a){if(this.isCircuitOpen(this.primaryProvider.type))return this.executeWithFallback(a,new Error("Circuit breaker open"));try{const t=await this.primaryProvider.chat(a);return this.cache.set(a,t),this.resetCircuitBreaker(this.primaryProvider.type),t}catch(t){return this.recordFailure(this.primaryProvider.type),this.executeWithFallback(a,t)}}async executeWithFallback(a,t){var r,n;for(const s of this.config.strategies)try{const m=await this.executeStrategy(s,a,t);if(m)return(n=(r=this.config).onFallback)==null||n.call(r,s,t),m}catch{}throw new Error(`All fallback strategies failed. Original error: ${t.message}`)}async executeStrategy(a,t,r){switch(a){case"retry":return this.retryStrategy(t);case"failover":return this.failoverStrategy(t);case"cache":return this.cacheStrategy(t);case"offline":return this.offlineStrategy(t);case"graceful-degrade":return this.gracefulDegradeStrategy(t,r);case"circuit-breaker":return this.openCircuitBreaker(this.primaryProvider.type),null;default:return null}}async retryStrategy(a){let t=this.config.retryDelay;for(let r=0;r<this.config.maxRetries;r++){await this.delay(t);try{const n=await this.primaryProvider.chat(a);return this.cache.set(a,n),n}catch{t*=this.config.backoffMultiplier}}return null}async failoverStrategy(a){for(const t of this.backupProviders)if(!this.isCircuitOpen(t.type))try{const r=await t.chat(a);return this.cache.set(a,r),r}catch{this.recordFailure(t.type)}return null}cacheStrategy(a){const t=this.cache.get(a);return t?{...t,id:`cached-${t.id}`}:null}async offlineStrategy(a){if(!this.offlineProvider)return null;try{return await this.offlineProvider.chat(a)}catch{return null}}gracefulDegradeStrategy(a,t){const r=[...a.messages].reverse().find(n=>n.role==="user");return{id:`degraded-${Date.now()}`,model:"fallback",choices:[{index:0,message:{role:"assistant",content:this.generateDegradedResponse((r==null?void 0:r.content)||"",t)},finishReason:"stop"}],usage:{promptTokens:0,completionTokens:0,totalTokens:0}}}generateDegradedResponse(a,t){return a.toLowerCase().includes("filter")||a.toLowerCase().includes("show")?JSON.stringify({filters:[],logic:"and"}):a.toLowerCase().includes("form")||a.toLowerCase().includes("create")?JSON.stringify({title:"Form",fields:[{id:"field1",type:"text",label:"Field 1"}]}):a.toLowerCase().includes("chart")||a.toLowerCase().includes("graph")?JSON.stringify({type:"bar",title:"Chart",data:{source:"data"}}):`I'm sorry, I couldn't process your request at this time. The service is temporarily unavailable. Please try again later or contact support. (Error: ${t.message.substring(0,50)})`}isCircuitOpen(a){const t=this.circuitBreakers.get(a);return t&&t.isOpen?Date.now()-t.lastFailure>this.config.circuitBreakerResetTime?(this.resetCircuitBreaker(a),!1):!0:!1}recordFailure(a){const t=this.circuitBreakers.get(a)||{failures:0,lastFailure:0,isOpen:!1};t.failures++,t.lastFailure=Date.now(),t.failures>=this.config.circuitBreakerThreshold&&(t.isOpen=!0),this.circuitBreakers.set(a,t)}openCircuitBreaker(a){this.circuitBreakers.set(a,{failures:this.config.circuitBreakerThreshold,lastFailure:Date.now(),isOpen:!0})}resetCircuitBreaker(a){this.circuitBreakers.delete(a)}delay(a){return new Promise(t=>setTimeout(t,a))}addBackupProvider(a){this.backupProviders.push(a)}setOfflineProvider(a){this.offlineProvider=a}clearCache(){this.cache.clear()}resetAllCircuitBreakers(){this.circuitBreakers.clear()}getCircuitBreakerStatus(){const a={};for(const[t,r]of this.circuitBreakers)a[t]={...r};return a}async healthCheck(){const a={};a[this.primaryProvider.type]=await this.primaryProvider.healthCheck();for(const t of this.backupProviders)a[`backup-${t.type}`]=await t.healthCheck();return this.offlineProvider&&(a.offline=await this.offlineProvider.healthCheck()),a}}function da(i,a){const t=ae(i);return new la(t,a)}function dt(i,a){const t={strategies:["retry","failover","cache","graceful-degrade"],maxRetries:3,retryDelay:1e3,backoffMultiplier:2,backupProviders:a?[a]:[],circuitBreakerThreshold:5,circuitBreakerResetTime:6e4};return typeof window>"u"&&(t.offlineConfig={type:"ollama",model:"llama3"}),da(i,t)}function ua(i){const{columns:a,config:t,onFilterGenerated:r,onSortGenerated:n,onError:s}=i,m=X(),[c,g]=o.useState(!1),[f,j]=o.useState(null),[w,N]=o.useState(null),[S,$]=o.useState([]),k=o.useRef(null),P=t||(m==null?void 0:m.config),h=o.useMemo(()=>a.map(p=>({id:p.id,label:p.label,type:p.type,...p.options?{options:p.options}:{}})),[a]),d=o.useCallback(async p=>{var b;if(!P){const u="AI not configured. Provide config or wrap in NiceAIProvider.";return s==null||s(u),{type:"filter",error:u}}g(!0),j(p);const _=performance.now();(b=k.current)==null||b.abort(),k.current=new AbortController;try{const u=G(P),y=p.toLowerCase(),A=y.includes("sort")||y.includes("order")||y.includes("arrange")||y.includes("by highest")||y.includes("by lowest"),R=y.includes("show")||y.includes("find")||y.includes("filter")||y.includes("where")||y.includes("with")||y.includes("only")||!A,l={type:"combined"};if(R){const x=Z(re,{columns:h,query:p}),M=await u.chat({messages:[{role:"system",content:x.system},{role:"user",content:x.user}],temperature:.2,maxTokens:512}),z=ut(M);z&&(l.filterConfig=z,l.type="filter",r==null||r(z))}if(A){const x=Z(ne,{columns:h,query:p}),M=await u.chat({messages:[{role:"system",content:x.system},{role:"user",content:x.user}],temperature:.1,maxTokens:256}),z=pt(M);z&&(l.sortConfig=z,l.type=l.filterConfig?"combined":"sort",n==null||n(z))}return l.latencyMs=performance.now()-_,N(l),$(x=>[...x.slice(-9),{query:p,result:l}]),l}catch(u){const y=u instanceof Error?u.message:"AI request failed",A={type:"filter",error:y,latencyMs:performance.now()-_};return N(A),s==null||s(y),A}finally{g(!1)}},[P,h,r,n,s]),v=o.useCallback(()=>{j(null),N(null)},[]),C=o.useCallback(()=>{var p;(p=k.current)==null||p.abort(),g(!1)},[]);return o.useEffect(()=>()=>{var p;(p=k.current)==null||p.abort()},[]),{processQuery:d,loading:c,lastQuery:f,lastResult:w,history:S,clearResults:v,abort:C,isConfigured:!!P}}function ut(i){var a,t,r;try{const n=((t=(a=i.choices[0])==null?void 0:a.message)==null?void 0:t.content)||"",m=((r=(n.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,n])[1])==null?void 0:r.trim())||n,c=JSON.parse(m);if(c.filters&&Array.isArray(c.filters))return{filters:c.filters,logic:c.logic||"and",confidence:c.confidence,explanation:c.explanation}}catch{}return null}function pt(i){var a,t,r;try{const n=((t=(a=i.choices[0])==null?void 0:a.message)==null?void 0:t.content)||"",m=((r=(n.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,n])[1])==null?void 0:r.trim())||n,c=JSON.parse(m);if(c.sort&&Array.isArray(c.sort))return{sort:c.sort,confidence:c.confidence}}catch{}return null}function mt({columns:i,config:a,onFilter:t,onSort:r,placeholder:n='Ask AI to filter or sort data... (e.g., "show orders from last week")',showHistory:s=!0,showSuggestions:m=!0,className:c,style:g}){const[f,j]=o.useState(""),[w,N]=o.useState(!1),S=o.useRef(null),{processQuery:$,loading:k,lastResult:P,history:h,isConfigured:d}=ua({columns:i,config:a,onFilterGenerated:t,onSortGenerated:r}),v=o.useMemo(()=>{if(!m||i.length===0)return[];const u=[],y=i.filter(x=>x.type==="string");y.length>0&&u.push(`Show ${y[0].label}s containing "example"`);const A=i.filter(x=>x.type==="number");A.length>0&&(u.push(`${A[0].label} greater than 100`),u.push(`Sort by highest ${A[0].label}`));const R=i.filter(x=>x.type==="date");R.length>0&&(u.push(`${R[0].label} in the last 7 days`),u.push(`Sort by newest ${R[0].label}`));const l=i.filter(x=>{var M;return x.type==="enum"&&((M=x.options)==null?void 0:M.length)});return l.length>0&&l[0].options&&u.push(`Where ${l[0].label} is ${l[0].options[0]}`),u.slice(0,5)},[i,m]),C=async()=>{!f.trim()||k||(await $(f.trim()),N(!1))},p=u=>{u.key==="Enter"?(u.preventDefault(),C()):u.key==="Escape"&&N(!1)},_=u=>{var y;j(u),N(!1),(y=S.current)==null||y.focus()},b=u=>{j(u),N(!1),$(u)};return d?e.jsxs("div",{className:`nice-datagrid-ai ${c||""}`,style:g,children:[e.jsxs("div",{className:"nice-datagrid-ai__input-wrapper",children:[e.jsx("span",{className:"nice-datagrid-ai__icon",children:e.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor",children:e.jsx("path",{d:"M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.94-.49-7-3.85-7-7.93s3.05-7.44 7-7.93v15.86zm2-15.86c1.03.13 2 .45 2.87.93H13v-.93zM13 7h5.24c.25.31.48.65.68 1H13V7zm0 3h6.74c.08.33.15.66.19 1H13v-1zm0 9.93V19h2.87c-.87.48-1.84.8-2.87.93zM18.24 17H13v-1h5.92c-.2.35-.43.69-.68 1zm1.5-3H13v-1h6.93c-.04.34-.11.67-.19 1z"})})}),e.jsx("input",{ref:S,type:"text",value:f,onChange:u=>j(u.target.value),onKeyDown:p,onFocus:()=>N(!0),onBlur:()=>setTimeout(()=>N(!1),200),placeholder:n,className:"nice-datagrid-ai__input",disabled:k,"aria-label":"AI query input"}),k?e.jsx("span",{className:"nice-datagrid-ai__spinner"}):e.jsx("button",{type:"button",onClick:C,className:"nice-datagrid-ai__submit",disabled:!f.trim(),"aria-label":"Submit query",children:e.jsx("svg",{viewBox:"0 0 24 24",width:"16",height:"16",fill:"currentColor",children:e.jsx("path",{d:"M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"})})})]}),w&&(v.length>0||s&&h.length>0)&&e.jsxs("div",{className:"nice-datagrid-ai__dropdown",children:[m&&v.length>0&&e.jsxs("div",{className:"nice-datagrid-ai__section",children:[e.jsx("div",{className:"nice-datagrid-ai__section-title",children:"Suggestions"}),v.map((u,y)=>e.jsxs("button",{type:"button",className:"nice-datagrid-ai__item",onClick:()=>_(u),children:[e.jsx("span",{className:"nice-datagrid-ai__item-icon",children:"💡"}),u]},y))]}),s&&h.length>0&&e.jsxs("div",{className:"nice-datagrid-ai__section",children:[e.jsx("div",{className:"nice-datagrid-ai__section-title",children:"Recent"}),h.slice(-5).reverse().map((u,y)=>e.jsxs("button",{type:"button",className:"nice-datagrid-ai__item",onClick:()=>b(u.query),children:[e.jsx("span",{className:"nice-datagrid-ai__item-icon",children:"🕐"}),u.query,u.result.error&&e.jsx("span",{className:"nice-datagrid-ai__item-error",children:"⚠️"})]},y))]})]}),P&&!P.error&&e.jsxs("div",{className:"nice-datagrid-ai__result",children:[P.filterConfig&&e.jsxs("span",{className:"nice-datagrid-ai__badge nice-datagrid-ai__badge--filter",children:[P.filterConfig.filters.length," filter",P.filterConfig.filters.length!==1?"s":""," applied"]}),P.sortConfig&&e.jsxs("span",{className:"nice-datagrid-ai__badge nice-datagrid-ai__badge--sort",children:["Sorted by ",P.sortConfig.sort.map(u=>u.column).join(", ")]}),P.latencyMs&&e.jsxs("span",{className:"nice-datagrid-ai__latency",children:[Math.round(P.latencyMs),"ms"]})]}),(P==null?void 0:P.error)&&e.jsx("div",{className:"nice-datagrid-ai__error",children:P.error}),e.jsx("style",{children:`
|
|
356
356
|
.nice-datagrid-ai {
|
|
357
357
|
position: relative;
|
|
358
358
|
font-family: var(--nice-font-family, system-ui, sans-serif);
|
|
@@ -365,8 +365,8 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
365
365
|
.nice-datagrid-ai__input-wrapper {
|
|
366
366
|
display: flex;
|
|
367
367
|
align-items: center;
|
|
368
|
-
gap: 8px;
|
|
369
|
-
padding: 8px 12px;
|
|
368
|
+
gap: var(--nice-space-2, 8px);
|
|
369
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
370
370
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
371
371
|
border-radius: var(--nice-border-radius, 8px);
|
|
372
372
|
background: var(--nice-input-bg, #fff);
|
|
@@ -403,7 +403,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
403
403
|
width: 28px;
|
|
404
404
|
height: 28px;
|
|
405
405
|
border: none;
|
|
406
|
-
border-radius: 6px;
|
|
406
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
407
407
|
background: var(--nice-primary, #0066cc);
|
|
408
408
|
color: white;
|
|
409
409
|
cursor: pointer;
|
|
@@ -428,7 +428,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
428
428
|
height: 16px;
|
|
429
429
|
border: 2px solid var(--nice-border-color, #e0e0e0);
|
|
430
430
|
border-top-color: var(--nice-primary, #0066cc);
|
|
431
|
-
border-radius: 50
|
|
431
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
432
432
|
animation: nice-spin 0.8s linear infinite;
|
|
433
433
|
}
|
|
434
434
|
|
|
@@ -441,18 +441,18 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
441
441
|
top: 100%;
|
|
442
442
|
left: 0;
|
|
443
443
|
right: 0;
|
|
444
|
-
margin-top: 4px;
|
|
444
|
+
margin-top: var(--nice-space-1, 4px);
|
|
445
445
|
background: var(--nice-dropdown-bg, #fff);
|
|
446
446
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
447
447
|
border-radius: var(--nice-border-radius, 8px);
|
|
448
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
448
|
+
box-shadow: 0 4px 12px var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
|
|
449
449
|
z-index: 100;
|
|
450
450
|
max-height: 300px;
|
|
451
451
|
overflow-y: auto;
|
|
452
452
|
}
|
|
453
453
|
|
|
454
454
|
.nice-datagrid-ai__section {
|
|
455
|
-
padding: 8px 0;
|
|
455
|
+
padding: var(--nice-space-2, 8px) 0;
|
|
456
456
|
}
|
|
457
457
|
|
|
458
458
|
.nice-datagrid-ai__section:not(:last-child) {
|
|
@@ -460,7 +460,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
460
460
|
}
|
|
461
461
|
|
|
462
462
|
.nice-datagrid-ai__section-title {
|
|
463
|
-
padding: 4px 12px;
|
|
463
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-3, 12px);
|
|
464
464
|
font-size: 11px;
|
|
465
465
|
font-weight: 600;
|
|
466
466
|
text-transform: uppercase;
|
|
@@ -470,9 +470,9 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
470
470
|
.nice-datagrid-ai__item {
|
|
471
471
|
display: flex;
|
|
472
472
|
align-items: center;
|
|
473
|
-
gap: 8px;
|
|
473
|
+
gap: var(--nice-space-2, 8px);
|
|
474
474
|
width: 100%;
|
|
475
|
-
padding: 8px 12px;
|
|
475
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
476
476
|
border: none;
|
|
477
477
|
background: transparent;
|
|
478
478
|
text-align: left;
|
|
@@ -496,8 +496,8 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
496
496
|
|
|
497
497
|
.nice-datagrid-ai__result {
|
|
498
498
|
display: flex;
|
|
499
|
-
gap: 8px;
|
|
500
|
-
margin-top: 8px;
|
|
499
|
+
gap: var(--nice-space-2, 8px);
|
|
500
|
+
margin-top: var(--nice-space-2, 8px);
|
|
501
501
|
flex-wrap: wrap;
|
|
502
502
|
align-items: center;
|
|
503
503
|
}
|
|
@@ -505,8 +505,8 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
505
505
|
.nice-datagrid-ai__badge {
|
|
506
506
|
display: inline-flex;
|
|
507
507
|
align-items: center;
|
|
508
|
-
padding: 4px 8px;
|
|
509
|
-
border-radius: 4px;
|
|
508
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-2, 8px);
|
|
509
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
510
510
|
font-size: 12px;
|
|
511
511
|
font-weight: 500;
|
|
512
512
|
}
|
|
@@ -527,47 +527,47 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
527
527
|
}
|
|
528
528
|
|
|
529
529
|
.nice-datagrid-ai__error {
|
|
530
|
-
margin-top: 8px;
|
|
531
|
-
padding: 8px 12px;
|
|
530
|
+
margin-top: var(--nice-space-2, 8px);
|
|
531
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
532
532
|
background: var(--nice-error-light, #ffebee);
|
|
533
533
|
color: var(--nice-error, #c62828);
|
|
534
|
-
border-radius: 4px;
|
|
534
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
535
535
|
font-size: 13px;
|
|
536
536
|
}
|
|
537
|
-
`})]}):e.jsx("div",{className:`nice-datagrid-ai nice-datagrid-ai--disabled ${
|
|
537
|
+
`})]}):e.jsx("div",{className:`nice-datagrid-ai nice-datagrid-ai--disabled ${c||""}`,style:g,children:e.jsx("input",{type:"text",placeholder:"AI not configured",disabled:!0,className:"nice-datagrid-ai__input"})})}function pa(i={}){const{config:a,schema:t,context:r,onFormGenerated:n,onError:s}=i,m=X(),[c,g]=o.useState(!1),[f,j]=o.useState(null),[w,N]=o.useState(null),[S,$]=o.useState([]),k=o.useRef(null),P=a||(m==null?void 0:m.config),h=o.useCallback(async p=>{var b,u,y;if(!P){const A="AI not configured. Provide config or wrap in NiceAIProvider.";return s==null||s(A),{error:A}}g(!0),j(p);const _=performance.now();(b=k.current)==null||b.abort(),k.current=new AbortController;try{const A=G(P),R=Z(se,{description:p,schema:t?JSON.stringify(t,null,2):void 0,context:r}),l=await A.chat({messages:[{role:"system",content:R.system},{role:"user",content:R.user}],temperature:.5,maxTokens:2048}),x=ht(l),M={config:x||void 0,rawResponse:(y=(u=l.choices[0])==null?void 0:u.message)==null?void 0:y.content,latencyMs:performance.now()-_,error:x?void 0:"Failed to parse form configuration"};return x&&(n==null||n(x)),N(M),$(z=>[...z.slice(-9),{description:p,result:M}]),M}catch(A){const R=A instanceof Error?A.message:"AI request failed",l={error:R,latencyMs:performance.now()-_};return N(l),s==null||s(R),l}finally{g(!1)}},[P,t,r,n,s]),d=o.useCallback(async p=>{if(!(w!=null&&w.config))return{error:"No form to refine. Generate a form first."};const _=`
|
|
538
538
|
Modify this existing form based on the following instructions:
|
|
539
539
|
|
|
540
540
|
Current form: ${JSON.stringify(w.config,null,2)}
|
|
541
541
|
|
|
542
|
-
Instructions: ${
|
|
543
|
-
`;return h(_)},[w,h]),
|
|
542
|
+
Instructions: ${p}
|
|
543
|
+
`;return h(_)},[w,h]),v=o.useCallback(()=>{j(null),N(null)},[]),C=o.useCallback(()=>{var p;(p=k.current)==null||p.abort(),g(!1)},[]);return o.useEffect(()=>()=>{var p;(p=k.current)==null||p.abort()},[]),{generateForm:h,refineForm:d,loading:c,lastDescription:f,lastResult:w,history:S,clearResults:v,abort:C,isConfigured:!!P}}function ht(i){var a,t,r;try{const n=((t=(a=i.choices[0])==null?void 0:a.message)==null?void 0:t.content)||"",m=((r=(n.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,n])[1])==null?void 0:r.trim())||n,c=JSON.parse(m);if(c.fields&&Array.isArray(c.fields))return{title:c.title,description:c.description,fields:c.fields,layout:c.layout,submitLabel:c.submitLabel,validation:c.validation}}catch{}return null}function gt({config:i,schema:a,context:t,onGenerate:r,placeholder:n='Describe the form you want to create... (e.g., "Contact form with name, email, subject, and message")',showExamples:s=!0,showPreview:m=!0,className:c,style:g,renderForm:f}){const[j,w]=o.useState(""),[N,S]=o.useState(!1),$=o.useRef(null),{generateForm:k,loading:P,lastResult:h,isConfigured:d}=pa({config:i,schema:a,context:t,onFormGenerated:r}),v=["Simple contact form with name, email, and message","User registration with email validation and password confirmation","Product feedback survey with rating scale and comments","Event RSVP with name, attending status, and dietary restrictions","Job application with personal info, experience, and file upload","Newsletter subscription with email and preferences"],C=async()=>{!j.trim()||P||await k(j.trim())},p=u=>{var y;w(u),S(!1),(y=$.current)==null||y.focus()},_=u=>{u.key==="Enter"&&(u.ctrlKey||u.metaKey)&&(u.preventDefault(),C())},b=u=>{w(u.target.value),u.target.style.height="auto",u.target.style.height=Math.min(u.target.scrollHeight,200)+"px"};return d?e.jsxs("div",{className:`nice-form-builder-ai ${c||""}`,style:g,children:[e.jsxs("div",{className:"nice-form-builder-ai__input-section",children:[e.jsxs("label",{className:"nice-form-builder-ai__label",children:[e.jsx("span",{className:"nice-form-builder-ai__label-icon",children:"✨"}),"Describe your form"]}),e.jsxs("div",{className:"nice-form-builder-ai__input-wrapper",children:[e.jsx("textarea",{ref:$,value:j,onChange:b,onKeyDown:_,placeholder:n,className:"nice-form-builder-ai__textarea",disabled:P,rows:2}),e.jsxs("div",{className:"nice-form-builder-ai__actions",children:[s&&e.jsxs("div",{className:"nice-form-builder-ai__examples-wrapper",children:[e.jsx("button",{type:"button",onClick:()=>S(!N),className:"nice-form-builder-ai__btn nice-form-builder-ai__btn--secondary",children:"Examples"}),N&&e.jsx("div",{className:"nice-form-builder-ai__dropdown",children:v.map((u,y)=>e.jsx("button",{type:"button",className:"nice-form-builder-ai__dropdown-item",onClick:()=>p(u),children:u},y))})]}),e.jsx("button",{type:"button",onClick:C,disabled:!j.trim()||P,className:"nice-form-builder-ai__btn nice-form-builder-ai__btn--primary",children:P?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"nice-form-builder-ai__spinner"}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"🚀"}),"Generate Form"]})})]})]}),e.jsxs("p",{className:"nice-form-builder-ai__hint",children:["Press ",e.jsx("kbd",{children:"Ctrl"}),"+",e.jsx("kbd",{children:"Enter"})," to generate"]})]}),h&&e.jsx("div",{className:"nice-form-builder-ai__result",children:h.error?e.jsxs("div",{className:"nice-form-builder-ai__error",children:[e.jsx("strong",{children:"Error:"})," ",h.error]}):h.config&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-form-builder-ai__result-header",children:[e.jsxs("h3",{className:"nice-form-builder-ai__result-title",children:["Generated Form: ",h.config.title||"Untitled"]}),h.latencyMs&&e.jsxs("span",{className:"nice-form-builder-ai__latency",children:[Math.round(h.latencyMs),"ms"]}),e.jsx("button",{type:"button",onClick:()=>r==null?void 0:r(h.config),className:"nice-form-builder-ai__btn nice-form-builder-ai__btn--success",children:"Use This Form"})]}),h.config.description&&e.jsx("p",{className:"nice-form-builder-ai__result-description",children:h.config.description}),m&&e.jsx("div",{className:"nice-form-builder-ai__preview",children:f?f(h.config):e.jsx(ft,{config:h.config})}),e.jsxs("details",{className:"nice-form-builder-ai__json",children:[e.jsx("summary",{children:"View JSON Configuration"}),e.jsx("pre",{children:JSON.stringify(h.config,null,2)})]})]})}),e.jsx("style",{children:`
|
|
544
544
|
.nice-form-builder-ai {
|
|
545
545
|
font-family: var(--nice-font-family, system-ui, sans-serif);
|
|
546
546
|
}
|
|
547
547
|
|
|
548
548
|
.nice-form-builder-ai--disabled {
|
|
549
|
-
padding: 20px;
|
|
549
|
+
padding: var(--nice-space-5, 20px);
|
|
550
550
|
background: var(--nice-disabled-bg, #f5f5f5);
|
|
551
|
-
border-radius: 8px;
|
|
551
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
552
552
|
color: var(--nice-text-muted, #666);
|
|
553
553
|
}
|
|
554
554
|
|
|
555
555
|
.nice-form-builder-ai__input-section {
|
|
556
|
-
margin-bottom: 20px;
|
|
556
|
+
margin-bottom: var(--nice-space-5, 20px);
|
|
557
557
|
}
|
|
558
558
|
|
|
559
559
|
.nice-form-builder-ai__label {
|
|
560
560
|
display: flex;
|
|
561
561
|
align-items: center;
|
|
562
|
-
gap: 8px;
|
|
563
|
-
margin-bottom: 8px;
|
|
562
|
+
gap: var(--nice-space-2, 8px);
|
|
563
|
+
margin-bottom: var(--nice-space-2, 8px);
|
|
564
564
|
font-weight: 600;
|
|
565
565
|
color: var(--nice-text-color, #333);
|
|
566
566
|
}
|
|
567
567
|
|
|
568
568
|
.nice-form-builder-ai__input-wrapper {
|
|
569
569
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
570
|
-
border-radius: 8px;
|
|
570
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
571
571
|
overflow: hidden;
|
|
572
572
|
background: var(--nice-input-bg, #fff);
|
|
573
573
|
}
|
|
@@ -580,7 +580,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
580
580
|
.nice-form-builder-ai__textarea {
|
|
581
581
|
width: 100%;
|
|
582
582
|
min-height: 60px;
|
|
583
|
-
padding: 12px;
|
|
583
|
+
padding: var(--nice-space-3, 12px);
|
|
584
584
|
border: none;
|
|
585
585
|
background: transparent;
|
|
586
586
|
font-size: 14px;
|
|
@@ -591,8 +591,8 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
591
591
|
|
|
592
592
|
.nice-form-builder-ai__actions {
|
|
593
593
|
display: flex;
|
|
594
|
-
gap: 8px;
|
|
595
|
-
padding: 8px 12px;
|
|
594
|
+
gap: var(--nice-space-2, 8px);
|
|
595
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
596
596
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
597
597
|
border-top: 1px solid var(--nice-border-color, #e0e0e0);
|
|
598
598
|
}
|
|
@@ -600,10 +600,10 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
600
600
|
.nice-form-builder-ai__btn {
|
|
601
601
|
display: inline-flex;
|
|
602
602
|
align-items: center;
|
|
603
|
-
gap: 6px;
|
|
604
|
-
padding: 8px 16px;
|
|
603
|
+
gap: var(--nice-space-1-5, 6px);
|
|
604
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-4, 16px);
|
|
605
605
|
border: none;
|
|
606
|
-
border-radius: 6px;
|
|
606
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
607
607
|
font-size: 14px;
|
|
608
608
|
font-weight: 500;
|
|
609
609
|
cursor: pointer;
|
|
@@ -643,19 +643,19 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
643
643
|
position: absolute;
|
|
644
644
|
bottom: 100%;
|
|
645
645
|
left: 0;
|
|
646
|
-
margin-bottom: 4px;
|
|
646
|
+
margin-bottom: var(--nice-space-1, 4px);
|
|
647
647
|
min-width: 300px;
|
|
648
648
|
background: white;
|
|
649
649
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
650
|
-
border-radius: 8px;
|
|
651
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
650
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
651
|
+
box-shadow: 0 4px 12px var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
|
|
652
652
|
z-index: 100;
|
|
653
653
|
}
|
|
654
654
|
|
|
655
655
|
.nice-form-builder-ai__dropdown-item {
|
|
656
656
|
display: block;
|
|
657
657
|
width: 100%;
|
|
658
|
-
padding: 10px 12px;
|
|
658
|
+
padding: var(--nice-space-2-5, 10px) var(--nice-space-3, 12px);
|
|
659
659
|
border: none;
|
|
660
660
|
background: transparent;
|
|
661
661
|
text-align: left;
|
|
@@ -670,15 +670,15 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
670
670
|
}
|
|
671
671
|
|
|
672
672
|
.nice-form-builder-ai__hint {
|
|
673
|
-
margin-top: 8px;
|
|
673
|
+
margin-top: var(--nice-space-2, 8px);
|
|
674
674
|
font-size: 12px;
|
|
675
675
|
color: var(--nice-text-muted, #666);
|
|
676
676
|
}
|
|
677
677
|
|
|
678
678
|
.nice-form-builder-ai__hint kbd {
|
|
679
|
-
padding: 2px 6px;
|
|
679
|
+
padding: var(--nice-space-0-5, 2px) var(--nice-space-1-5, 6px);
|
|
680
680
|
background: var(--nice-bg-subtle, #f0f0f0);
|
|
681
|
-
border-radius: 4px;
|
|
681
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
682
682
|
font-family: monospace;
|
|
683
683
|
font-size: 11px;
|
|
684
684
|
}
|
|
@@ -689,7 +689,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
689
689
|
height: 14px;
|
|
690
690
|
border: 2px solid currentColor;
|
|
691
691
|
border-top-color: transparent;
|
|
692
|
-
border-radius: 50
|
|
692
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
693
693
|
animation: nice-spin 0.8s linear infinite;
|
|
694
694
|
}
|
|
695
695
|
|
|
@@ -698,17 +698,17 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
698
698
|
}
|
|
699
699
|
|
|
700
700
|
.nice-form-builder-ai__result {
|
|
701
|
-
padding: 20px;
|
|
701
|
+
padding: var(--nice-space-5, 20px);
|
|
702
702
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
703
|
-
border-radius: 8px;
|
|
703
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
704
704
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
705
705
|
}
|
|
706
706
|
|
|
707
707
|
.nice-form-builder-ai__result-header {
|
|
708
708
|
display: flex;
|
|
709
709
|
align-items: center;
|
|
710
|
-
gap: 12px;
|
|
711
|
-
margin-bottom: 12px;
|
|
710
|
+
gap: var(--nice-space-3, 12px);
|
|
711
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
712
712
|
}
|
|
713
713
|
|
|
714
714
|
.nice-form-builder-ai__result-title {
|
|
@@ -724,20 +724,20 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
724
724
|
}
|
|
725
725
|
|
|
726
726
|
.nice-form-builder-ai__result-description {
|
|
727
|
-
margin: 0 0 16px;
|
|
727
|
+
margin: 0 0 var(--nice-space-4, 16px);
|
|
728
728
|
color: var(--nice-text-muted, #666);
|
|
729
729
|
}
|
|
730
730
|
|
|
731
731
|
.nice-form-builder-ai__preview {
|
|
732
|
-
padding: 20px;
|
|
732
|
+
padding: var(--nice-space-5, 20px);
|
|
733
733
|
background: white;
|
|
734
|
-
border-radius: 8px;
|
|
734
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
735
735
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
736
|
-
margin-bottom: 16px;
|
|
736
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
737
737
|
}
|
|
738
738
|
|
|
739
739
|
.nice-form-builder-ai__json {
|
|
740
|
-
margin-top: 16px;
|
|
740
|
+
margin-top: var(--nice-space-4, 16px);
|
|
741
741
|
}
|
|
742
742
|
|
|
743
743
|
.nice-form-builder-ai__json summary {
|
|
@@ -747,21 +747,21 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
747
747
|
}
|
|
748
748
|
|
|
749
749
|
.nice-form-builder-ai__json pre {
|
|
750
|
-
margin: 8px 0 0;
|
|
751
|
-
padding: 12px;
|
|
750
|
+
margin: var(--nice-space-2, 8px) 0 0;
|
|
751
|
+
padding: var(--nice-space-3, 12px);
|
|
752
752
|
background: var(--nice-code-bg, #f5f5f5);
|
|
753
|
-
border-radius: 6px;
|
|
753
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
754
754
|
font-size: 12px;
|
|
755
755
|
overflow-x: auto;
|
|
756
756
|
}
|
|
757
757
|
|
|
758
758
|
.nice-form-builder-ai__error {
|
|
759
|
-
padding: 12px;
|
|
759
|
+
padding: var(--nice-space-3, 12px);
|
|
760
760
|
background: var(--nice-error-light, #ffebee);
|
|
761
761
|
color: var(--nice-error, #c62828);
|
|
762
|
-
border-radius: 6px;
|
|
762
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
763
763
|
}
|
|
764
|
-
`})]}):e.jsx("div",{className:`nice-form-builder-ai nice-form-builder-ai--disabled ${
|
|
764
|
+
`})]}):e.jsx("div",{className:`nice-form-builder-ai nice-form-builder-ai--disabled ${c||""}`,style:g,children:e.jsx("p",{children:"AI not configured. Please provide config or wrap in NiceAIProvider."})})}function ft({config:i}){var r,n;const a=s=>{var c,g;const m={id:s.id,placeholder:s.placeholder,required:s.required,disabled:!0};switch(s.type){case"textarea":case"richtext":case"markdown":return e.jsx("textarea",{...m,rows:3,className:"nice-form-preview__input nice-form-preview__textarea"});case"select":case"multiselect":return e.jsxs("select",{...m,className:"nice-form-preview__input nice-form-preview__select",children:[e.jsxs("option",{value:"",children:["Select ",s.label,"..."]}),(c=s.options)==null?void 0:c.map(f=>e.jsx("option",{value:f.value,children:f.label},f.value))]});case"radio":return e.jsx("div",{className:"nice-form-preview__radio-group",children:(g=s.options)==null?void 0:g.map(f=>e.jsxs("label",{className:"nice-form-preview__radio",children:[e.jsx("input",{type:"radio",name:s.id,value:f.value,disabled:!0}),f.label]},f.value))});case"checkbox":return e.jsxs("label",{className:"nice-form-preview__checkbox",children:[e.jsx("input",{type:"checkbox",disabled:!0}),s.label]});case"file":case"image":return e.jsx("input",{type:"file",...m,className:"nice-form-preview__input"});case"date":return e.jsx("input",{type:"date",...m,className:"nice-form-preview__input"});case"time":return e.jsx("input",{type:"time",...m,className:"nice-form-preview__input"});case"datetime":return e.jsx("input",{type:"datetime-local",...m,className:"nice-form-preview__input"});case"number":case"currency":case"percentage":return e.jsx("input",{type:"number",...m,className:"nice-form-preview__input"});case"email":return e.jsx("input",{type:"email",...m,className:"nice-form-preview__input"});case"phone":return e.jsx("input",{type:"tel",...m,className:"nice-form-preview__input"});case"url":return e.jsx("input",{type:"url",...m,className:"nice-form-preview__input"});case"password":return e.jsx("input",{type:"password",...m,className:"nice-form-preview__input"});case"color":return e.jsx("input",{type:"color",...m,className:"nice-form-preview__input nice-form-preview__color"});case"slider":case"rating":return e.jsx("input",{type:"range",...m,className:"nice-form-preview__input"});default:return e.jsx("input",{type:"text",...m,className:"nice-form-preview__input"})}},t=((r=i.layout)==null?void 0:r.columns)||1;return e.jsxs("form",{className:"nice-form-preview",style:{"--columns":t},children:[(n=i.layout)!=null&&n.sections?i.layout.sections.map((s,m)=>e.jsxs("fieldset",{className:"nice-form-preview__section",children:[s.title&&e.jsx("legend",{children:s.title}),s.description&&e.jsx("p",{className:"nice-form-preview__section-desc",children:s.description}),e.jsx("div",{className:"nice-form-preview__grid",children:s.fields.map(c=>{const g=i.fields.find(f=>f.id===c);return g?e.jsxs("div",{className:"nice-form-preview__field",children:[g.type!=="checkbox"&&e.jsxs("label",{className:"nice-form-preview__label",children:[g.label,g.required&&e.jsx("span",{className:"nice-form-preview__required",children:"*"})]}),a(g)]},g.id):null})})]},m)):e.jsx("div",{className:"nice-form-preview__grid",children:i.fields.map(s=>e.jsxs("div",{className:"nice-form-preview__field",children:[s.type!=="checkbox"&&e.jsxs("label",{className:"nice-form-preview__label",children:[s.label,s.required&&e.jsx("span",{className:"nice-form-preview__required",children:"*"})]}),a(s)]},s.id))}),e.jsx("div",{className:"nice-form-preview__submit",children:e.jsx("button",{type:"button",disabled:!0,className:"nice-form-preview__submit-btn",children:i.submitLabel||"Submit"})}),e.jsx("style",{children:`
|
|
765
765
|
.nice-form-preview {
|
|
766
766
|
--columns: 1;
|
|
767
767
|
}
|
|
@@ -769,23 +769,23 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
769
769
|
.nice-form-preview__grid {
|
|
770
770
|
display: grid;
|
|
771
771
|
grid-template-columns: repeat(var(--columns), 1fr);
|
|
772
|
-
gap: 16px;
|
|
772
|
+
gap: var(--nice-space-4, 16px);
|
|
773
773
|
}
|
|
774
774
|
|
|
775
775
|
.nice-form-preview__section {
|
|
776
|
-
margin-bottom: 24px;
|
|
777
|
-
padding: 16px;
|
|
776
|
+
margin-bottom: var(--nice-space-6, 24px);
|
|
777
|
+
padding: var(--nice-space-4, 16px);
|
|
778
778
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
779
|
-
border-radius: 8px;
|
|
779
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
780
780
|
}
|
|
781
781
|
|
|
782
782
|
.nice-form-preview__section legend {
|
|
783
783
|
font-weight: 600;
|
|
784
|
-
padding: 0 8px;
|
|
784
|
+
padding: 0 var(--nice-space-2, 8px);
|
|
785
785
|
}
|
|
786
786
|
|
|
787
787
|
.nice-form-preview__section-desc {
|
|
788
|
-
margin: 0 0 12px;
|
|
788
|
+
margin: 0 0 var(--nice-space-3, 12px);
|
|
789
789
|
font-size: 13px;
|
|
790
790
|
color: var(--nice-text-muted, #666);
|
|
791
791
|
}
|
|
@@ -793,7 +793,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
793
793
|
.nice-form-preview__field {
|
|
794
794
|
display: flex;
|
|
795
795
|
flex-direction: column;
|
|
796
|
-
gap: 6px;
|
|
796
|
+
gap: var(--nice-space-1-5, 6px);
|
|
797
797
|
}
|
|
798
798
|
|
|
799
799
|
.nice-form-preview__label {
|
|
@@ -804,13 +804,13 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
804
804
|
|
|
805
805
|
.nice-form-preview__required {
|
|
806
806
|
color: var(--nice-error, #c62828);
|
|
807
|
-
margin-left: 4px;
|
|
807
|
+
margin-left: var(--nice-space-1, 4px);
|
|
808
808
|
}
|
|
809
809
|
|
|
810
810
|
.nice-form-preview__input {
|
|
811
|
-
padding: 10px 12px;
|
|
811
|
+
padding: var(--nice-space-2-5, 10px) var(--nice-space-3, 12px);
|
|
812
812
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
813
|
-
border-radius: 6px;
|
|
813
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
814
814
|
font-size: 14px;
|
|
815
815
|
background: var(--nice-input-bg, #fff);
|
|
816
816
|
}
|
|
@@ -825,74 +825,74 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
825
825
|
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
|
|
826
826
|
background-repeat: no-repeat;
|
|
827
827
|
background-position: right 12px center;
|
|
828
|
-
padding-right: 32px;
|
|
828
|
+
padding-right: var(--nice-space-8, 32px);
|
|
829
829
|
}
|
|
830
830
|
|
|
831
831
|
.nice-form-preview__color {
|
|
832
832
|
width: 60px;
|
|
833
833
|
height: 36px;
|
|
834
|
-
padding: 2px;
|
|
834
|
+
padding: var(--nice-space-0-5, 2px);
|
|
835
835
|
}
|
|
836
836
|
|
|
837
837
|
.nice-form-preview__radio-group {
|
|
838
838
|
display: flex;
|
|
839
839
|
flex-direction: column;
|
|
840
|
-
gap: 8px;
|
|
840
|
+
gap: var(--nice-space-2, 8px);
|
|
841
841
|
}
|
|
842
842
|
|
|
843
843
|
.nice-form-preview__radio,
|
|
844
844
|
.nice-form-preview__checkbox {
|
|
845
845
|
display: flex;
|
|
846
846
|
align-items: center;
|
|
847
|
-
gap: 8px;
|
|
847
|
+
gap: var(--nice-space-2, 8px);
|
|
848
848
|
font-size: 14px;
|
|
849
849
|
cursor: pointer;
|
|
850
850
|
}
|
|
851
851
|
|
|
852
852
|
.nice-form-preview__submit {
|
|
853
|
-
margin-top: 24px;
|
|
854
|
-
padding-top: 16px;
|
|
853
|
+
margin-top: var(--nice-space-6, 24px);
|
|
854
|
+
padding-top: var(--nice-space-4, 16px);
|
|
855
855
|
border-top: 1px solid var(--nice-border-color, #e0e0e0);
|
|
856
856
|
}
|
|
857
857
|
|
|
858
858
|
.nice-form-preview__submit-btn {
|
|
859
|
-
padding: 12px 24px;
|
|
859
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-6, 24px);
|
|
860
860
|
background: var(--nice-primary, #0066cc);
|
|
861
861
|
color: white;
|
|
862
862
|
border: none;
|
|
863
|
-
border-radius: 6px;
|
|
863
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
864
864
|
font-size: 14px;
|
|
865
865
|
font-weight: 500;
|
|
866
866
|
cursor: not-allowed;
|
|
867
867
|
opacity: 0.7;
|
|
868
868
|
}
|
|
869
|
-
`})]})}function
|
|
869
|
+
`})]})}function ma(i={}){const{config:a,dataFields:t,context:r,onChartGenerated:n,onError:s}=i,m=X(),[c,g]=o.useState(!1),[f,j]=o.useState(null),[w,N]=o.useState(null),[S,$]=o.useState([]),k=o.useRef(null),P=a||(m==null?void 0:m.config),h=o.useMemo(()=>{if(t)return t.map(_=>{var b;return{name:_.name,type:_.type,label:_.label||_.name,...(b=_.sampleValues)!=null&&b.length?{samples:_.sampleValues.slice(0,3)}:{}}})},[t]),d=o.useCallback(async _=>{var u,y,A;if(!P){const R="AI not configured. Provide config or wrap in NiceAIProvider.";return s==null||s(R),{error:R}}g(!0),j(_);const b=performance.now();(u=k.current)==null||u.abort(),k.current=new AbortController;try{const R=G(P),l=Z(ce,{request:_,data:h?JSON.stringify(h,null,2):void 0,context:r}),x=await R.chat({messages:[{role:"system",content:l.system},{role:"user",content:l.user}],temperature:.4,maxTokens:1024}),M=xt(x),z={config:M||void 0,rawResponse:(A=(y=x.choices[0])==null?void 0:y.message)==null?void 0:A.content,latencyMs:performance.now()-b,error:M?void 0:"Failed to parse chart configuration",suggestions:bt(M)};return M&&(n==null||n(M)),N(z),$(D=>[...D.slice(-9),{request:_,result:z}]),z}catch(R){const l=R instanceof Error?R.message:"AI request failed",x={error:l,latencyMs:performance.now()-b};return N(x),s==null||s(l),x}finally{g(!1)}},[P,h,r,n,s]),v=o.useCallback(async()=>w!=null&&w.config?{line:["area","bar","scatter"],area:["line","bar","column"],bar:["column","line","pie"],column:["bar","line","area"],pie:["donut","bar","treemap"],donut:["pie","funnel","gauge"],scatter:["bubble","line","heatmap"],bubble:["scatter","treemap"],heatmap:["treemap","bar"],treemap:["pie","heatmap","bar"],funnel:["bar","donut"],radar:["bar","polar"],polar:["radar","pie"],gauge:["donut","bar"],candlestick:["line","area"],sankey:["funnel","bar"]}[w.config.type]||[]:[],[w]),C=o.useCallback(()=>{j(null),N(null)},[]),p=o.useCallback(()=>{var _;(_=k.current)==null||_.abort(),g(!1)},[]);return o.useEffect(()=>()=>{var _;(_=k.current)==null||_.abort()},[]),{generateChart:d,suggestAlternatives:v,loading:c,lastRequest:f,lastResult:w,history:S,clearResults:C,abort:p,isConfigured:!!P}}function xt(i){var a,t,r;try{const n=((t=(a=i.choices[0])==null?void 0:a.message)==null?void 0:t.content)||"",m=((r=(n.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,n])[1])==null?void 0:r.trim())||n,c=JSON.parse(m);if(c.type)return{type:c.type,title:c.title,subtitle:c.subtitle,data:c.data||{},xAxis:c.xAxis,yAxis:c.yAxis,options:c.options}}catch{}return null}function bt(i){var t;if(!i)return[];const a=[];return(i.type==="line"||i.type==="bar")&&(a.push("Add trend line for forecasting"),a.push("Stack series for comparison")),(i.type==="pie"||i.type==="donut")&&(a.push("Convert to bar chart for better comparison"),a.push("Add data labels for percentages")),(t=i.options)!=null&&t.animation||a.push("Enable animations for better UX"),a.slice(0,3)}function vt({config:i,dataFields:a,context:t,onGenerate:r,placeholder:n='Describe the chart you want... (e.g., "Show monthly sales as a line chart")',showTypeSelector:s=!0,showPreview:m=!0,className:c,style:g,renderChart:f}){var y;const[j,w]=o.useState(""),[N,S]=o.useState(null),$=o.useRef(null),{generateChart:k,suggestAlternatives:P,loading:h,lastResult:d,isConfigured:v}=ma({config:i,dataFields:a,context:t,onChartGenerated:r}),C=[{type:"line",icon:"📈",label:"Line"},{type:"bar",icon:"📊",label:"Bar"},{type:"pie",icon:"🥧",label:"Pie"},{type:"area",icon:"📉",label:"Area"},{type:"scatter",icon:"⚬",label:"Scatter"},{type:"donut",icon:"🍩",label:"Donut"},{type:"heatmap",icon:"🔥",label:"Heatmap"},{type:"funnel",icon:"⏬",label:"Funnel"},{type:"gauge",icon:"⏱️",label:"Gauge"},{type:"radar",icon:"🎯",label:"Radar"}],p=async()=>{if(!j.trim()||h)return;const A=N?`Create a ${N} chart: ${j}`:j;await k(A)},_=A=>{A.key==="Enter"&&(A.preventDefault(),p())},b=A=>{S(N===A?null:A)},u=async A=>{if(!(d!=null&&d.config))return;const R={...d.config,type:A};r==null||r(R)};return v?e.jsxs("div",{className:`nice-chart-ai ${c||""}`,style:g,children:[s&&e.jsx("div",{className:"nice-chart-ai__types",children:C.map(({type:A,icon:R,label:l})=>e.jsxs("button",{type:"button",className:`nice-chart-ai__type ${N===A?"nice-chart-ai__type--selected":""}`,onClick:()=>b(A),title:l,children:[e.jsx("span",{className:"nice-chart-ai__type-icon",children:R}),e.jsx("span",{className:"nice-chart-ai__type-label",children:l})]},A))}),e.jsxs("div",{className:"nice-chart-ai__input-wrapper",children:[e.jsx("span",{className:"nice-chart-ai__icon",children:"📊"}),e.jsx("input",{ref:$,type:"text",value:j,onChange:A=>w(A.target.value),onKeyDown:_,placeholder:n,className:"nice-chart-ai__input",disabled:h}),h?e.jsx("span",{className:"nice-chart-ai__spinner"}):e.jsx("button",{type:"button",onClick:p,className:"nice-chart-ai__submit",disabled:!j.trim(),children:"Generate"})]}),a&&a.length>0&&e.jsxs("div",{className:"nice-chart-ai__fields",children:[e.jsx("span",{className:"nice-chart-ai__fields-label",children:"Available fields:"}),a.map(A=>e.jsx("span",{className:"nice-chart-ai__field-badge",title:A.type,children:A.label||A.name},A.name))]}),d&&e.jsx("div",{className:"nice-chart-ai__result",children:d.error?e.jsx("div",{className:"nice-chart-ai__error",children:d.error}):d.config&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-chart-ai__result-header",children:[e.jsxs("div",{className:"nice-chart-ai__result-info",children:[e.jsxs("span",{className:"nice-chart-ai__chart-type",children:[(y=C.find(A=>A.type===d.config.type))==null?void 0:y.icon,d.config.type.charAt(0).toUpperCase()+d.config.type.slice(1)," ","Chart"]}),d.config.title&&e.jsx("span",{className:"nice-chart-ai__chart-title",children:d.config.title})]}),d.latencyMs&&e.jsxs("span",{className:"nice-chart-ai__latency",children:[Math.round(d.latencyMs),"ms"]}),e.jsx("button",{type:"button",onClick:()=>r==null?void 0:r(d.config),className:"nice-chart-ai__use-btn",children:"Use This Chart"})]}),e.jsxs("div",{className:"nice-chart-ai__alternatives",children:[e.jsx("span",{children:"Try also:"}),C.filter(A=>A.type!==d.config.type).slice(0,4).map(({type:A,icon:R})=>e.jsx("button",{type:"button",className:"nice-chart-ai__alternative",onClick:()=>u(A),title:`Convert to ${A}`,children:R},A))]}),m&&e.jsx("div",{className:"nice-chart-ai__preview",children:f?f(d.config):e.jsx(yt,{config:d.config})}),e.jsxs("details",{className:"nice-chart-ai__json",children:[e.jsx("summary",{children:"View Configuration"}),e.jsx("pre",{children:JSON.stringify(d.config,null,2)})]})]})}),e.jsx("style",{children:`
|
|
870
870
|
.nice-chart-ai {
|
|
871
871
|
font-family: var(--nice-font-family, system-ui, sans-serif);
|
|
872
872
|
}
|
|
873
873
|
|
|
874
874
|
.nice-chart-ai--disabled {
|
|
875
|
-
padding: 20px;
|
|
875
|
+
padding: var(--nice-space-5, 20px);
|
|
876
876
|
background: var(--nice-disabled-bg, #f5f5f5);
|
|
877
|
-
border-radius: 8px;
|
|
877
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
878
878
|
color: var(--nice-text-muted, #666);
|
|
879
879
|
}
|
|
880
880
|
|
|
881
881
|
.nice-chart-ai__types {
|
|
882
882
|
display: flex;
|
|
883
883
|
flex-wrap: wrap;
|
|
884
|
-
gap: 8px;
|
|
885
|
-
margin-bottom: 12px;
|
|
884
|
+
gap: var(--nice-space-2, 8px);
|
|
885
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
886
886
|
}
|
|
887
887
|
|
|
888
888
|
.nice-chart-ai__type {
|
|
889
889
|
display: flex;
|
|
890
890
|
flex-direction: column;
|
|
891
891
|
align-items: center;
|
|
892
|
-
gap: 4px;
|
|
893
|
-
padding: 8px 12px;
|
|
892
|
+
gap: var(--nice-space-1, 4px);
|
|
893
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
894
894
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
895
|
-
border-radius: 8px;
|
|
895
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
896
896
|
background: var(--nice-bg-secondary, #fff);
|
|
897
897
|
cursor: pointer;
|
|
898
898
|
transition: all 0.2s;
|
|
@@ -919,10 +919,10 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
919
919
|
.nice-chart-ai__input-wrapper {
|
|
920
920
|
display: flex;
|
|
921
921
|
align-items: center;
|
|
922
|
-
gap: 8px;
|
|
923
|
-
padding: 10px 14px;
|
|
922
|
+
gap: var(--nice-space-2, 8px);
|
|
923
|
+
padding: var(--nice-space-2-5, 10px) var(--nice-space-3-5, 14px);
|
|
924
924
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
925
|
-
border-radius: 8px;
|
|
925
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
926
926
|
background: var(--nice-input-bg, #fff);
|
|
927
927
|
}
|
|
928
928
|
|
|
@@ -944,11 +944,11 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
944
944
|
}
|
|
945
945
|
|
|
946
946
|
.nice-chart-ai__submit {
|
|
947
|
-
padding: 8px 16px;
|
|
947
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-4, 16px);
|
|
948
948
|
background: var(--nice-primary, #0066cc);
|
|
949
949
|
color: white;
|
|
950
950
|
border: none;
|
|
951
|
-
border-radius: 6px;
|
|
951
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
952
952
|
font-weight: 500;
|
|
953
953
|
cursor: pointer;
|
|
954
954
|
transition: background 0.2s;
|
|
@@ -968,7 +968,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
968
968
|
height: 20px;
|
|
969
969
|
border: 2px solid var(--nice-border-color, #e0e0e0);
|
|
970
970
|
border-top-color: var(--nice-primary, #0066cc);
|
|
971
|
-
border-radius: 50
|
|
971
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
972
972
|
animation: nice-spin 0.8s linear infinite;
|
|
973
973
|
}
|
|
974
974
|
|
|
@@ -979,8 +979,8 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
979
979
|
.nice-chart-ai__fields {
|
|
980
980
|
display: flex;
|
|
981
981
|
flex-wrap: wrap;
|
|
982
|
-
gap: 6px;
|
|
983
|
-
margin-top: 10px;
|
|
982
|
+
gap: var(--nice-space-1-5, 6px);
|
|
983
|
+
margin-top: var(--nice-space-2-5, 10px);
|
|
984
984
|
align-items: center;
|
|
985
985
|
}
|
|
986
986
|
|
|
@@ -990,42 +990,42 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
990
990
|
}
|
|
991
991
|
|
|
992
992
|
.nice-chart-ai__field-badge {
|
|
993
|
-
padding: 4px 8px;
|
|
993
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-2, 8px);
|
|
994
994
|
background: var(--nice-bg-subtle, #f0f0f0);
|
|
995
|
-
border-radius: 4px;
|
|
995
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
996
996
|
font-size: 12px;
|
|
997
997
|
color: var(--nice-text-color, #333);
|
|
998
998
|
}
|
|
999
999
|
|
|
1000
1000
|
.nice-chart-ai__result {
|
|
1001
|
-
margin-top: 20px;
|
|
1002
|
-
padding: 16px;
|
|
1001
|
+
margin-top: var(--nice-space-5, 20px);
|
|
1002
|
+
padding: var(--nice-space-4, 16px);
|
|
1003
1003
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
1004
|
-
border-radius: 8px;
|
|
1004
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1005
1005
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1006
1006
|
}
|
|
1007
1007
|
|
|
1008
1008
|
.nice-chart-ai__result-header {
|
|
1009
1009
|
display: flex;
|
|
1010
1010
|
align-items: center;
|
|
1011
|
-
gap: 12px;
|
|
1012
|
-
margin-bottom: 12px;
|
|
1011
|
+
gap: var(--nice-space-3, 12px);
|
|
1012
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
1013
1013
|
}
|
|
1014
1014
|
|
|
1015
1015
|
.nice-chart-ai__result-info {
|
|
1016
1016
|
flex: 1;
|
|
1017
1017
|
display: flex;
|
|
1018
1018
|
align-items: center;
|
|
1019
|
-
gap: 8px;
|
|
1019
|
+
gap: var(--nice-space-2, 8px);
|
|
1020
1020
|
}
|
|
1021
1021
|
|
|
1022
1022
|
.nice-chart-ai__chart-type {
|
|
1023
1023
|
display: flex;
|
|
1024
1024
|
align-items: center;
|
|
1025
|
-
gap: 6px;
|
|
1026
|
-
padding: 4px 10px;
|
|
1025
|
+
gap: var(--nice-space-1-5, 6px);
|
|
1026
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-2-5, 10px);
|
|
1027
1027
|
background: var(--nice-primary-light, rgba(0, 102, 204, 0.1));
|
|
1028
|
-
border-radius: 6px;
|
|
1028
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1029
1029
|
font-weight: 500;
|
|
1030
1030
|
color: var(--nice-primary, #0066cc);
|
|
1031
1031
|
}
|
|
@@ -1040,11 +1040,11 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1040
1040
|
}
|
|
1041
1041
|
|
|
1042
1042
|
.nice-chart-ai__use-btn {
|
|
1043
|
-
padding: 8px 16px;
|
|
1043
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-4, 16px);
|
|
1044
1044
|
background: var(--nice-success, #2e7d32);
|
|
1045
1045
|
color: white;
|
|
1046
1046
|
border: none;
|
|
1047
|
-
border-radius: 6px;
|
|
1047
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1048
1048
|
font-weight: 500;
|
|
1049
1049
|
cursor: pointer;
|
|
1050
1050
|
}
|
|
@@ -1052,8 +1052,8 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1052
1052
|
.nice-chart-ai__alternatives {
|
|
1053
1053
|
display: flex;
|
|
1054
1054
|
align-items: center;
|
|
1055
|
-
gap: 8px;
|
|
1056
|
-
margin-bottom: 16px;
|
|
1055
|
+
gap: var(--nice-space-2, 8px);
|
|
1056
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1057
1057
|
font-size: 13px;
|
|
1058
1058
|
color: var(--nice-text-muted, #666);
|
|
1059
1059
|
}
|
|
@@ -1065,7 +1065,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1065
1065
|
width: 32px;
|
|
1066
1066
|
height: 32px;
|
|
1067
1067
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1068
|
-
border-radius: 6px;
|
|
1068
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1069
1069
|
background: white;
|
|
1070
1070
|
font-size: 16px;
|
|
1071
1071
|
cursor: pointer;
|
|
@@ -1078,15 +1078,15 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1078
1078
|
}
|
|
1079
1079
|
|
|
1080
1080
|
.nice-chart-ai__preview {
|
|
1081
|
-
padding: 20px;
|
|
1081
|
+
padding: var(--nice-space-5, 20px);
|
|
1082
1082
|
background: white;
|
|
1083
|
-
border-radius: 8px;
|
|
1083
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1084
1084
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1085
1085
|
min-height: 200px;
|
|
1086
1086
|
}
|
|
1087
1087
|
|
|
1088
1088
|
.nice-chart-ai__json {
|
|
1089
|
-
margin-top: 12px;
|
|
1089
|
+
margin-top: var(--nice-space-3, 12px);
|
|
1090
1090
|
}
|
|
1091
1091
|
|
|
1092
1092
|
.nice-chart-ai__json summary {
|
|
@@ -1096,21 +1096,21 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1096
1096
|
}
|
|
1097
1097
|
|
|
1098
1098
|
.nice-chart-ai__json pre {
|
|
1099
|
-
margin: 8px 0 0;
|
|
1100
|
-
padding: 12px;
|
|
1099
|
+
margin: var(--nice-space-2, 8px) 0 0;
|
|
1100
|
+
padding: var(--nice-space-3, 12px);
|
|
1101
1101
|
background: var(--nice-code-bg, #f5f5f5);
|
|
1102
|
-
border-radius: 6px;
|
|
1102
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1103
1103
|
font-size: 12px;
|
|
1104
1104
|
overflow-x: auto;
|
|
1105
1105
|
}
|
|
1106
1106
|
|
|
1107
1107
|
.nice-chart-ai__error {
|
|
1108
|
-
padding: 12px;
|
|
1108
|
+
padding: var(--nice-space-3, 12px);
|
|
1109
1109
|
background: var(--nice-error-light, #ffebee);
|
|
1110
1110
|
color: var(--nice-error, #c62828);
|
|
1111
|
-
border-radius: 6px;
|
|
1111
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1112
1112
|
}
|
|
1113
|
-
`})]}):e.jsx("div",{className:`nice-chart-ai nice-chart-ai--disabled ${
|
|
1113
|
+
`})]}):e.jsx("div",{className:`nice-chart-ai nice-chart-ai--disabled ${c||""}`,style:g,children:e.jsx("p",{children:"AI not configured. Please provide config or wrap in NiceAIProvider."})})}function yt({config:i}){var t;const a=()=>{switch(i.type){case"bar":case"column":return e.jsxs("svg",{viewBox:"0 0 200 100",className:"nice-chart-preview__svg",children:[e.jsx("rect",{x:"20",y:"60",width:"25",height:"30",fill:"var(--nice-success, #4caf50)",rx:"2"}),e.jsx("rect",{x:"55",y:"40",width:"25",height:"50",fill:"var(--nice-primary, #2196f3)",rx:"2"}),e.jsx("rect",{x:"90",y:"20",width:"25",height:"70",fill:"var(--nice-warning, #ff9800)",rx:"2"}),e.jsx("rect",{x:"125",y:"50",width:"25",height:"40",fill:"var(--nice-accent, #9c27b0)",rx:"2"}),e.jsx("rect",{x:"160",y:"30",width:"25",height:"60",fill:"var(--nice-accent-pink, #e91e63)",rx:"2"})]});case"line":case"area":return e.jsxs("svg",{viewBox:"0 0 200 100",className:"nice-chart-preview__svg",children:[e.jsx("path",{d:"M 20 70 Q 50 30, 80 50 T 140 40 T 180 60",fill:"none",stroke:"var(--nice-primary, #2196f3)",strokeWidth:"3",strokeLinecap:"round"}),i.type==="area"&&e.jsx("path",{d:"M 20 70 Q 50 30, 80 50 T 140 40 T 180 60 V 90 H 20 Z",fill:"rgba(33, 150, 243, 0.2)"}),e.jsx("circle",{cx:"20",cy:"70",r:"4",fill:"var(--nice-primary, #2196f3)"}),e.jsx("circle",{cx:"80",cy:"50",r:"4",fill:"var(--nice-primary, #2196f3)"}),e.jsx("circle",{cx:"140",cy:"40",r:"4",fill:"var(--nice-primary, #2196f3)"}),e.jsx("circle",{cx:"180",cy:"60",r:"4",fill:"var(--nice-primary, #2196f3)"})]});case"pie":case"donut":{const r=i.type==="donut"?35:40,n=i.type==="donut"?20:0;return e.jsxs("svg",{viewBox:"0 0 100 100",className:"nice-chart-preview__svg",children:[e.jsx("circle",{cx:"50",cy:"50",r,fill:"var(--nice-success, #4caf50)"}),e.jsx("path",{d:"M 50 50 L 50 10 A 40 40 0 0 1 90 50 Z",fill:"var(--nice-primary, #2196f3)"}),e.jsx("path",{d:"M 50 50 L 90 50 A 40 40 0 0 1 70 85 Z",fill:"var(--nice-warning, #ff9800)"}),e.jsx("path",{d:"M 50 50 L 70 85 A 40 40 0 0 1 30 85 Z",fill:"var(--nice-accent, #9c27b0)"}),i.type==="donut"&&e.jsx("circle",{cx:"50",cy:"50",r:n,fill:"white"})]})}case"scatter":return e.jsxs("svg",{viewBox:"0 0 200 100",className:"nice-chart-preview__svg",children:[e.jsx("circle",{cx:"30",cy:"70",r:"5",fill:"var(--nice-primary, #2196f3)"}),e.jsx("circle",{cx:"50",cy:"40",r:"7",fill:"var(--nice-success, #4caf50)"}),e.jsx("circle",{cx:"80",cy:"60",r:"4",fill:"var(--nice-warning, #ff9800)"}),e.jsx("circle",{cx:"110",cy:"30",r:"6",fill:"var(--nice-primary, #2196f3)"}),e.jsx("circle",{cx:"140",cy:"50",r:"5",fill:"var(--nice-accent, #9c27b0)"}),e.jsx("circle",{cx:"170",cy:"45",r:"8",fill:"var(--nice-success, #4caf50)"})]});case"gauge":return e.jsxs("svg",{viewBox:"0 0 100 60",className:"nice-chart-preview__svg",children:[e.jsx("path",{d:"M 10 50 A 40 40 0 0 1 90 50",fill:"none",stroke:"var(--nice-border, #e0e0e0)",strokeWidth:"8",strokeLinecap:"round"}),e.jsx("path",{d:"M 10 50 A 40 40 0 0 1 60 15",fill:"none",stroke:"var(--nice-success, #4caf50)",strokeWidth:"8",strokeLinecap:"round"}),e.jsx("text",{x:"50",y:"50",textAnchor:"middle",fontSize:"14",fontWeight:"bold",children:"75%"})]});default:return e.jsxs("div",{className:"nice-chart-preview__placeholder",children:[e.jsx("span",{className:"nice-chart-preview__icon",children:"📊"}),e.jsxs("span",{children:[i.type.charAt(0).toUpperCase()+i.type.slice(1)," Chart"]})]})}};return e.jsxs("div",{className:"nice-chart-preview",children:[i.title&&e.jsx("div",{className:"nice-chart-preview__title",children:i.title}),i.subtitle&&e.jsx("div",{className:"nice-chart-preview__subtitle",children:i.subtitle}),e.jsx("div",{className:"nice-chart-preview__chart",children:a()}),((t=i.options)==null?void 0:t.legend)&&e.jsxs("div",{className:"nice-chart-preview__legend",children:[e.jsxs("span",{className:"nice-chart-preview__legend-item",children:[e.jsx("span",{style:{background:"var(--nice-success, #4caf50)"}}),"Series 1"]}),e.jsxs("span",{className:"nice-chart-preview__legend-item",children:[e.jsx("span",{style:{background:"var(--nice-primary, #2196f3)"}}),"Series 2"]}),e.jsxs("span",{className:"nice-chart-preview__legend-item",children:[e.jsx("span",{style:{background:"var(--nice-warning, #ff9800)"}}),"Series 3"]})]}),e.jsx("style",{children:`
|
|
1114
1114
|
.nice-chart-preview {
|
|
1115
1115
|
text-align: center;
|
|
1116
1116
|
}
|
|
@@ -1118,13 +1118,13 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1118
1118
|
.nice-chart-preview__title {
|
|
1119
1119
|
font-size: 16px;
|
|
1120
1120
|
font-weight: 600;
|
|
1121
|
-
margin-bottom: 4px;
|
|
1121
|
+
margin-bottom: var(--nice-space-1, 4px);
|
|
1122
1122
|
}
|
|
1123
1123
|
|
|
1124
1124
|
.nice-chart-preview__subtitle {
|
|
1125
1125
|
font-size: 13px;
|
|
1126
1126
|
color: var(--nice-text-muted, #666);
|
|
1127
|
-
margin-bottom: 16px;
|
|
1127
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1128
1128
|
}
|
|
1129
1129
|
|
|
1130
1130
|
.nice-chart-preview__chart {
|
|
@@ -1143,7 +1143,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1143
1143
|
display: flex;
|
|
1144
1144
|
flex-direction: column;
|
|
1145
1145
|
align-items: center;
|
|
1146
|
-
gap: 8px;
|
|
1146
|
+
gap: var(--nice-space-2, 8px);
|
|
1147
1147
|
color: var(--nice-text-muted, #666);
|
|
1148
1148
|
}
|
|
1149
1149
|
|
|
@@ -1154,33 +1154,33 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1154
1154
|
.nice-chart-preview__legend {
|
|
1155
1155
|
display: flex;
|
|
1156
1156
|
justify-content: center;
|
|
1157
|
-
gap: 16px;
|
|
1158
|
-
margin-top: 16px;
|
|
1157
|
+
gap: var(--nice-space-4, 16px);
|
|
1158
|
+
margin-top: var(--nice-space-4, 16px);
|
|
1159
1159
|
font-size: 12px;
|
|
1160
1160
|
}
|
|
1161
1161
|
|
|
1162
1162
|
.nice-chart-preview__legend-item {
|
|
1163
1163
|
display: flex;
|
|
1164
1164
|
align-items: center;
|
|
1165
|
-
gap: 6px;
|
|
1165
|
+
gap: var(--nice-space-1-5, 6px);
|
|
1166
1166
|
}
|
|
1167
1167
|
|
|
1168
1168
|
.nice-chart-preview__legend-item span {
|
|
1169
1169
|
display: inline-block;
|
|
1170
1170
|
width: 12px;
|
|
1171
1171
|
height: 12px;
|
|
1172
|
-
border-radius: 2px;
|
|
1172
|
+
border-radius: var(--nice-radius-sm, 2px);
|
|
1173
1173
|
}
|
|
1174
|
-
`})]})}function
|
|
1175
|
-
`),I=Y[x.line]||"",
|
|
1174
|
+
`})]})}function ha(i={}){const{config:a,language:t="typescript",context:r,maxSuggestions:n=3,debounceMs:s=300,onSuggestion:m,onError:c}=i,g=X(),[f,j]=o.useState(!1),[w,N]=o.useState([]),[S,$]=o.useState(-1),k=o.useRef(null),P=o.useRef(null),h=a||(g==null?void 0:g.config),d=o.useCallback(async(l,x)=>{var z,D,J;if(!h)return{suggestions:[],error:"AI not configured"};j(!0),(z=k.current)==null||z.abort(),k.current=new AbortController;const M=performance.now();try{const H=G(h),Y=l.split(`
|
|
1175
|
+
`),I=Y[x.line]||"",F=I.substring(0,x.column),q=I.substring(x.column),W=Y.slice(Math.max(0,x.line-20),x.line).join(`
|
|
1176
1176
|
`),U=Y.slice(x.line+1,x.line+10).join(`
|
|
1177
|
-
`),K=Z(
|
|
1178
|
-
`).filter(
|
|
1177
|
+
`),K=Z(oe,{language:t,code_context:W,prefix:F,suffix:q,context_after:U,context:r}),Q=await H.chat({messages:[{role:"system",content:K.system},{role:"user",content:K.user}],temperature:.2,maxTokens:512}),T=_t(Q,x,n),L={suggestions:T,rawResponse:(J=(D=Q.choices[0])==null?void 0:D.message)==null?void 0:J.content,latencyMs:performance.now()-M};return N(T),$(T.length>0?0:-1),m==null||m(T),L}catch(H){const Y=H instanceof Error?H.message:"Completion failed";return c==null||c(Y),{suggestions:[],error:Y,latencyMs:performance.now()-M}}finally{j(!1)}},[h,t,r,n,m,c]),v=o.useCallback((l,x)=>{P.current&&clearTimeout(P.current),P.current=setTimeout(()=>{d(l,x)},s)},[d,s]),C=o.useCallback(async l=>{if(!h)return null;j(!0);try{const M=await G(h).chat({messages:[{role:"system",content:`You are a code explanation assistant. Explain the following ${t} code clearly and concisely. Return JSON with: { "summary": string, "details": string, "complexity": "low"|"medium"|"high", "suggestions": string[] }`},{role:"user",content:l}],temperature:.3,maxTokens:1024});return wt(M)}catch{return null}finally{j(!1)}},[h,t]),p=o.useCallback(async l=>{if(!h)return[];j(!0);try{const M=await G(h).chat({messages:[{role:"system",content:`You are a code refactoring assistant. Analyze the following ${t} code and suggest improvements. Return JSON array with: [{ "title": string, "description": string, "before": string, "after": string, "type": "extract-function"|"rename"|"simplify"|"optimize"|"security"|"style" }]`},{role:"user",content:l}],temperature:.4,maxTokens:2048});return jt(M)}catch{return[]}finally{j(!1)}},[h,t]),_=o.useCallback(async(l,x)=>{var M,z;if(!h)return null;j(!0);try{const D=G(h),J=x||kt(t);return((z=(M=(await D.chat({messages:[{role:"system",content:`You are a testing expert. Generate comprehensive unit tests for the following ${t} code using ${J}. Include edge cases and error scenarios. Return only the test code.`},{role:"user",content:l}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:M.message)==null?void 0:z.content)||null}catch{return null}finally{j(!1)}},[h,t]),b=o.useCallback(async(l,x)=>{var M,z;if(!h)return null;j(!0);try{const D=G(h),J=x||Nt(t);return((z=(M=(await D.chat({messages:[{role:"system",content:`Generate ${J} documentation for the following ${t} code. Include descriptions for parameters, return values, and examples where appropriate. Return only the documented code.`},{role:"user",content:l}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:M.message)==null?void 0:z.content)||null}catch{return null}finally{j(!1)}},[h,t]),u=o.useCallback((l=S)=>{const x=w[l];return N([]),$(-1),x},[w,S]),y=o.useCallback(()=>{N([]),$(-1)},[]),A=o.useCallback(l=>{w.length!==0&&$(x=>l==="up"?x<=0?w.length-1:x-1:x>=w.length-1?0:x+1)},[w.length]),R=o.useCallback(()=>{var l;(l=k.current)==null||l.abort(),P.current&&clearTimeout(P.current),j(!1)},[]);return o.useEffect(()=>()=>{var l;(l=k.current)==null||l.abort(),P.current&&clearTimeout(P.current)},[]),{getCompletions:d,getCompletionsDebounced:v,suggestions:w,activeSuggestion:S,acceptSuggestion:u,dismissSuggestions:y,navigateSuggestions:A,explainCode:C,suggestRefactoring:p,generateTests:_,generateDocs:b,loading:f,abort:R,isConfigured:!!h}}function _t(i,a,t){var r,n;try{return(((n=(r=i.choices[0])==null?void 0:r.message)==null?void 0:n.content)||"").split(`
|
|
1178
|
+
`).filter(c=>c.trim()).slice(0,t).map((c,g)=>({id:`suggestion-${Date.now()}-${g}`,text:c.trim(),type:"inline",preview:c.trim().slice(0,50),confidence:.8-g*.1,insertPosition:a}))}catch{return[]}}function wt(i){var a,t;try{const r=((t=(a=i.choices[0])==null?void 0:a.message)==null?void 0:t.content)||"",n=r.match(/\{[\s\S]*\}/);return n?JSON.parse(n[0]):{summary:r}}catch{return null}}function jt(i){var a,t;try{const n=(((t=(a=i.choices[0])==null?void 0:a.message)==null?void 0:t.content)||"").match(/\[[\s\S]*\]/);if(n)return JSON.parse(n[0])}catch{}return[]}function kt(i){return{javascript:"Jest",typescript:"Jest",python:"pytest",java:"JUnit 5",csharp:"xUnit",go:"testing",rust:"cargo test",ruby:"RSpec",php:"PHPUnit",swift:"XCTest",kotlin:"JUnit 5",dart:"flutter_test"}[i]||"unit test"}function Nt(i){return{javascript:"jsdoc",typescript:"tsdoc",python:"docstring",java:"javadoc",kotlin:"javadoc"}[i]||"jsdoc"}function Ct({code:i="",language:a="typescript",config:t,onChange:r,onAcceptSuggestion:n,showToolbar:s=!0,enableInlineSuggestions:m=!0,placeholder:c="Start typing code...",className:g,style:f,renderEditor:j}){const[w,N]=o.useState(i),[S,$]=o.useState(null),[k,P]=o.useState(null),[h,d]=o.useState([]),[v,C]=o.useState(null),[p,_]=o.useState(null),b=o.useRef(null),{getCompletionsDebounced:u,suggestions:y,activeSuggestion:A,acceptSuggestion:R,dismissSuggestions:l,navigateSuggestions:x,explainCode:M,suggestRefactoring:z,generateTests:D,generateDocs:J,loading:H,isConfigured:Y}=ha({config:t,language:a}),I=O=>{if(N(O),r==null||r(O),m&&b.current){const B=St(b.current);u(O,B)}},F=O=>{if(y.length>0)if(O.key==="ArrowUp")O.preventDefault(),x("up");else if(O.key==="ArrowDown")O.preventDefault(),x("down");else if(O.key==="Tab"||O.key==="Enter"){if(A>=0){O.preventDefault();const B=R(A);B&&(q(B),n==null||n(B))}}else O.key==="Escape"&&l()},q=O=>{if(!b.current)return;const B=b.current,ee=B.selectionStart,Me=w.slice(0,ee)+O.text+w.slice(ee);N(Me),r==null||r(Me);const Pe=ee+O.text.length;setTimeout(()=>{B.focus(),B.setSelectionRange(Pe,Pe)},0)},W=async()=>{const O=S||w;if(!O.trim())return;_("explain");const B=await M(O);P(B)},U=async()=>{const O=S||w;if(!O.trim())return;_("refactor");const B=await z(O);d(B)},K=async()=>{if(!w.trim())return;_("tests");const O=await D(w);C(O)},Q=async()=>{if(!w.trim())return;_("docs");const O=await J(w);C(O)},T=O=>{const B=w.replace(O.before,O.after);N(B),r==null||r(B),_(null)},L=()=>{v&&navigator.clipboard.writeText(v)},E=()=>{if(b.current){const O=b.current.selectionStart,B=b.current.selectionEnd;$(O!==B?w.slice(O,B):null)}};return Y?j?e.jsx("div",{className:`nice-code-editor-ai ${g||""}`,style:f,children:j({code:w,onChange:I,suggestions:y,onAccept:O=>{const B=R(O);B&&(n==null||n(B))}})}):e.jsxs("div",{className:`nice-code-editor-ai ${g||""}`,style:f,children:[s&&e.jsxs("div",{className:"nice-code-editor-ai__toolbar",children:[e.jsx("span",{className:"nice-code-editor-ai__lang-badge",children:a}),e.jsxs("div",{className:"nice-code-editor-ai__actions",children:[e.jsx("button",{type:"button",onClick:W,disabled:H||!w.trim(),title:"Explain code",children:"💡 Explain"}),e.jsx("button",{type:"button",onClick:U,disabled:H||!w.trim(),title:"Suggest refactoring",children:"🔧 Refactor"}),e.jsx("button",{type:"button",onClick:K,disabled:H||!w.trim(),title:"Generate tests",children:"🧪 Tests"}),e.jsx("button",{type:"button",onClick:Q,disabled:H||!w.trim(),title:"Generate docs",children:"📝 Docs"})]}),H&&e.jsx("span",{className:"nice-code-editor-ai__loading",children:"Processing..."})]}),e.jsxs("div",{className:"nice-code-editor-ai__editor-wrapper",children:[e.jsx("textarea",{ref:b,value:w,onChange:O=>I(O.target.value),onKeyDown:F,onSelect:E,placeholder:c,className:"nice-code-editor-ai__textarea",spellCheck:!1}),y.length>0&&e.jsxs("div",{className:"nice-code-editor-ai__suggestions",children:[y.map((O,B)=>e.jsxs("div",{className:`nice-code-editor-ai__suggestion ${B===A?"nice-code-editor-ai__suggestion--active":""}`,onClick:()=>{const ee=R(B);ee&&(q(ee),n==null||n(ee))},children:[e.jsx("span",{className:"nice-code-editor-ai__suggestion-text",children:O.text}),e.jsxs("span",{className:"nice-code-editor-ai__suggestion-confidence",children:[Math.round(O.confidence*100),"%"]})]},O.id)),e.jsx("div",{className:"nice-code-editor-ai__suggestions-hint",children:"↑↓ navigate • Tab accept • Esc dismiss"})]})]}),p&&e.jsxs("div",{className:"nice-code-editor-ai__panel",children:[e.jsxs("div",{className:"nice-code-editor-ai__panel-header",children:[e.jsxs("span",{children:[p==="explain"&&"💡 Explanation",p==="refactor"&&"🔧 Refactoring Suggestions",p==="tests"&&"🧪 Generated Tests",p==="docs"&&"📝 Generated Documentation"]}),e.jsx("button",{type:"button",onClick:()=>_(null),children:"✕"})]}),e.jsxs("div",{className:"nice-code-editor-ai__panel-content",children:[p==="explain"&&k&&e.jsxs("div",{className:"nice-code-editor-ai__explanation",children:[e.jsx("div",{className:"nice-code-editor-ai__explanation-summary",children:k.summary}),k.details&&e.jsx("div",{className:"nice-code-editor-ai__explanation-details",children:k.details}),k.complexity&&e.jsxs("span",{className:`nice-code-editor-ai__complexity nice-code-editor-ai__complexity--${k.complexity}`,children:["Complexity: ",k.complexity]}),k.suggestions&&k.suggestions.length>0&&e.jsx("ul",{className:"nice-code-editor-ai__explanation-suggestions",children:k.suggestions.map((O,B)=>e.jsx("li",{children:O},B))})]}),p==="refactor"&&h.length>0&&e.jsx("div",{className:"nice-code-editor-ai__refactorings",children:h.map((O,B)=>e.jsxs("div",{className:"nice-code-editor-ai__refactoring",children:[e.jsxs("div",{className:"nice-code-editor-ai__refactoring-header",children:[e.jsx("span",{className:"nice-code-editor-ai__refactoring-title",children:O.title}),e.jsx("span",{className:`nice-code-editor-ai__refactoring-type nice-code-editor-ai__refactoring-type--${O.type}`,children:O.type})]}),e.jsx("p",{className:"nice-code-editor-ai__refactoring-desc",children:O.description}),e.jsxs("div",{className:"nice-code-editor-ai__refactoring-diff",children:[e.jsxs("div",{className:"nice-code-editor-ai__refactoring-before",children:[e.jsx("span",{children:"Before:"}),e.jsx("pre",{children:O.before})]}),e.jsxs("div",{className:"nice-code-editor-ai__refactoring-after",children:[e.jsx("span",{children:"After:"}),e.jsx("pre",{children:O.after})]})]}),e.jsx("button",{type:"button",className:"nice-code-editor-ai__refactoring-apply",onClick:()=>T(O),children:"Apply"})]},B))}),(p==="tests"||p==="docs")&&v&&e.jsxs("div",{className:"nice-code-editor-ai__generated",children:[e.jsx("pre",{children:v}),e.jsx("button",{type:"button",onClick:L,children:"📋 Copy"})]})]})]}),e.jsx("style",{children:`
|
|
1179
1179
|
.nice-code-editor-ai {
|
|
1180
1180
|
font-family: var(--nice-font-family, system-ui, sans-serif);
|
|
1181
1181
|
display: flex;
|
|
1182
1182
|
flex-direction: column;
|
|
1183
|
-
gap: 8px;
|
|
1183
|
+
gap: var(--nice-space-2, 8px);
|
|
1184
1184
|
}
|
|
1185
1185
|
|
|
1186
1186
|
.nice-code-editor-ai--disabled {
|
|
@@ -1190,16 +1190,16 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1190
1190
|
.nice-code-editor-ai__toolbar {
|
|
1191
1191
|
display: flex;
|
|
1192
1192
|
align-items: center;
|
|
1193
|
-
gap: 12px;
|
|
1194
|
-
padding: 8px 12px;
|
|
1193
|
+
gap: var(--nice-space-3, 12px);
|
|
1194
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
1195
1195
|
background: var(--nice-bg-secondary, #f5f5f5);
|
|
1196
|
-
border-radius: 8px;
|
|
1196
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1197
1197
|
}
|
|
1198
1198
|
|
|
1199
1199
|
.nice-code-editor-ai__lang-badge {
|
|
1200
|
-
padding: 4px 10px;
|
|
1200
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-2-5, 10px);
|
|
1201
1201
|
background: var(--nice-primary-light, rgba(0, 102, 204, 0.1));
|
|
1202
|
-
border-radius: 4px;
|
|
1202
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
1203
1203
|
font-size: 12px;
|
|
1204
1204
|
font-weight: 500;
|
|
1205
1205
|
text-transform: uppercase;
|
|
@@ -1208,14 +1208,14 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1208
1208
|
|
|
1209
1209
|
.nice-code-editor-ai__actions {
|
|
1210
1210
|
display: flex;
|
|
1211
|
-
gap: 8px;
|
|
1211
|
+
gap: var(--nice-space-2, 8px);
|
|
1212
1212
|
flex: 1;
|
|
1213
1213
|
}
|
|
1214
1214
|
|
|
1215
1215
|
.nice-code-editor-ai__actions button {
|
|
1216
|
-
padding: 6px 12px;
|
|
1216
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-3, 12px);
|
|
1217
1217
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1218
|
-
border-radius: 6px;
|
|
1218
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1219
1219
|
background: white;
|
|
1220
1220
|
font-size: 13px;
|
|
1221
1221
|
cursor: pointer;
|
|
@@ -1250,9 +1250,9 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1250
1250
|
.nice-code-editor-ai__textarea {
|
|
1251
1251
|
width: 100%;
|
|
1252
1252
|
min-height: 300px;
|
|
1253
|
-
padding: 16px;
|
|
1253
|
+
padding: var(--nice-space-4, 16px);
|
|
1254
1254
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1255
|
-
border-radius: 8px;
|
|
1255
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1256
1256
|
font-family: 'Fira Code', 'JetBrains Mono', monospace;
|
|
1257
1257
|
font-size: 14px;
|
|
1258
1258
|
line-height: 1.5;
|
|
@@ -1273,10 +1273,10 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1273
1273
|
right: 16px;
|
|
1274
1274
|
background: white;
|
|
1275
1275
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1276
|
-
border-radius: 8px;
|
|
1277
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
1276
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1277
|
+
box-shadow: 0 4px 12px var(--nice-overlay-15, rgba(0, 0, 0, 0.15));
|
|
1278
1278
|
z-index: 100;
|
|
1279
|
-
margin-top: 4px;
|
|
1279
|
+
margin-top: var(--nice-space-1, 4px);
|
|
1280
1280
|
overflow: hidden;
|
|
1281
1281
|
}
|
|
1282
1282
|
|
|
@@ -1284,7 +1284,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1284
1284
|
display: flex;
|
|
1285
1285
|
align-items: center;
|
|
1286
1286
|
justify-content: space-between;
|
|
1287
|
-
padding: 10px 12px;
|
|
1287
|
+
padding: var(--nice-space-2-5, 10px) var(--nice-space-3, 12px);
|
|
1288
1288
|
cursor: pointer;
|
|
1289
1289
|
border-bottom: 1px solid var(--nice-border-light, #f0f0f0);
|
|
1290
1290
|
}
|
|
@@ -1313,7 +1313,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1313
1313
|
}
|
|
1314
1314
|
|
|
1315
1315
|
.nice-code-editor-ai__suggestions-hint {
|
|
1316
|
-
padding: 8px 12px;
|
|
1316
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
1317
1317
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
1318
1318
|
font-size: 11px;
|
|
1319
1319
|
color: var(--nice-text-muted, #666);
|
|
@@ -1322,7 +1322,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1322
1322
|
|
|
1323
1323
|
.nice-code-editor-ai__panel {
|
|
1324
1324
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1325
|
-
border-radius: 8px;
|
|
1325
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1326
1326
|
overflow: hidden;
|
|
1327
1327
|
}
|
|
1328
1328
|
|
|
@@ -1330,7 +1330,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1330
1330
|
display: flex;
|
|
1331
1331
|
justify-content: space-between;
|
|
1332
1332
|
align-items: center;
|
|
1333
|
-
padding: 12px 16px;
|
|
1333
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-4, 16px);
|
|
1334
1334
|
background: var(--nice-bg-secondary, #f5f5f5);
|
|
1335
1335
|
font-weight: 500;
|
|
1336
1336
|
}
|
|
@@ -1348,7 +1348,7 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1348
1348
|
}
|
|
1349
1349
|
|
|
1350
1350
|
.nice-code-editor-ai__panel-content {
|
|
1351
|
-
padding: 16px;
|
|
1351
|
+
padding: var(--nice-space-4, 16px);
|
|
1352
1352
|
max-height: 400px;
|
|
1353
1353
|
overflow-y: auto;
|
|
1354
1354
|
}
|
|
@@ -1356,19 +1356,19 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1356
1356
|
.nice-code-editor-ai__explanation-summary {
|
|
1357
1357
|
font-size: 15px;
|
|
1358
1358
|
line-height: 1.6;
|
|
1359
|
-
margin-bottom: 12px;
|
|
1359
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
1360
1360
|
}
|
|
1361
1361
|
|
|
1362
1362
|
.nice-code-editor-ai__explanation-details {
|
|
1363
1363
|
font-size: 14px;
|
|
1364
1364
|
color: var(--nice-text-muted, #666);
|
|
1365
|
-
margin-bottom: 12px;
|
|
1365
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
1366
1366
|
}
|
|
1367
1367
|
|
|
1368
1368
|
.nice-code-editor-ai__complexity {
|
|
1369
1369
|
display: inline-block;
|
|
1370
|
-
padding: 4px 10px;
|
|
1371
|
-
border-radius: 4px;
|
|
1370
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-2-5, 10px);
|
|
1371
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
1372
1372
|
font-size: 12px;
|
|
1373
1373
|
font-weight: 500;
|
|
1374
1374
|
}
|
|
@@ -1389,22 +1389,22 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1389
1389
|
}
|
|
1390
1390
|
|
|
1391
1391
|
.nice-code-editor-ai__explanation-suggestions {
|
|
1392
|
-
margin-top: 12px;
|
|
1393
|
-
padding-left: 20px;
|
|
1392
|
+
margin-top: var(--nice-space-3, 12px);
|
|
1393
|
+
padding-left: var(--nice-space-5, 20px);
|
|
1394
1394
|
}
|
|
1395
1395
|
|
|
1396
1396
|
.nice-code-editor-ai__refactoring {
|
|
1397
|
-
padding: 16px;
|
|
1397
|
+
padding: var(--nice-space-4, 16px);
|
|
1398
1398
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
1399
|
-
border-radius: 8px;
|
|
1400
|
-
margin-bottom: 12px;
|
|
1399
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1400
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
1401
1401
|
}
|
|
1402
1402
|
|
|
1403
1403
|
.nice-code-editor-ai__refactoring-header {
|
|
1404
1404
|
display: flex;
|
|
1405
1405
|
justify-content: space-between;
|
|
1406
1406
|
align-items: center;
|
|
1407
|
-
margin-bottom: 8px;
|
|
1407
|
+
margin-bottom: var(--nice-space-2, 8px);
|
|
1408
1408
|
}
|
|
1409
1409
|
|
|
1410
1410
|
.nice-code-editor-ai__refactoring-title {
|
|
@@ -1412,8 +1412,8 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1412
1412
|
}
|
|
1413
1413
|
|
|
1414
1414
|
.nice-code-editor-ai__refactoring-type {
|
|
1415
|
-
padding: 2px 8px;
|
|
1416
|
-
border-radius: 4px;
|
|
1415
|
+
padding: var(--nice-space-0-5, 2px) var(--nice-space-2, 8px);
|
|
1416
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
1417
1417
|
font-size: 11px;
|
|
1418
1418
|
background: var(--nice-bg-secondary, #e0e0e0);
|
|
1419
1419
|
}
|
|
@@ -1421,14 +1421,14 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1421
1421
|
.nice-code-editor-ai__refactoring-desc {
|
|
1422
1422
|
font-size: 14px;
|
|
1423
1423
|
color: var(--nice-text-muted, #666);
|
|
1424
|
-
margin-bottom: 12px;
|
|
1424
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
1425
1425
|
}
|
|
1426
1426
|
|
|
1427
1427
|
.nice-code-editor-ai__refactoring-diff {
|
|
1428
1428
|
display: grid;
|
|
1429
1429
|
grid-template-columns: 1fr 1fr;
|
|
1430
|
-
gap: 12px;
|
|
1431
|
-
margin-bottom: 12px;
|
|
1430
|
+
gap: var(--nice-space-3, 12px);
|
|
1431
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
1432
1432
|
}
|
|
1433
1433
|
|
|
1434
1434
|
.nice-code-editor-ai__refactoring-before,
|
|
@@ -1439,75 +1439,75 @@ Provide summary and insights:`,variables:[{name:"data",description:"Data to summ
|
|
|
1439
1439
|
.nice-code-editor-ai__refactoring-before span,
|
|
1440
1440
|
.nice-code-editor-ai__refactoring-after span {
|
|
1441
1441
|
display: block;
|
|
1442
|
-
margin-bottom: 4px;
|
|
1442
|
+
margin-bottom: var(--nice-space-1, 4px);
|
|
1443
1443
|
color: var(--nice-text-muted, #666);
|
|
1444
1444
|
}
|
|
1445
1445
|
|
|
1446
1446
|
.nice-code-editor-ai__refactoring-before pre,
|
|
1447
1447
|
.nice-code-editor-ai__refactoring-after pre {
|
|
1448
|
-
padding: 8px;
|
|
1448
|
+
padding: var(--nice-space-2, 8px);
|
|
1449
1449
|
background: var(--nice-code-bg, #1e1e1e);
|
|
1450
1450
|
color: var(--nice-code-color, #d4d4d4);
|
|
1451
|
-
border-radius: 4px;
|
|
1451
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
1452
1452
|
font-size: 12px;
|
|
1453
1453
|
overflow-x: auto;
|
|
1454
1454
|
}
|
|
1455
1455
|
|
|
1456
1456
|
.nice-code-editor-ai__refactoring-apply {
|
|
1457
|
-
padding: 6px 16px;
|
|
1457
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-4, 16px);
|
|
1458
1458
|
background: var(--nice-primary, #0066cc);
|
|
1459
1459
|
color: white;
|
|
1460
1460
|
border: none;
|
|
1461
|
-
border-radius: 6px;
|
|
1461
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1462
1462
|
font-weight: 500;
|
|
1463
1463
|
cursor: pointer;
|
|
1464
1464
|
}
|
|
1465
1465
|
|
|
1466
1466
|
.nice-code-editor-ai__generated pre {
|
|
1467
|
-
padding: 16px;
|
|
1467
|
+
padding: var(--nice-space-4, 16px);
|
|
1468
1468
|
background: var(--nice-code-bg, #1e1e1e);
|
|
1469
1469
|
color: var(--nice-code-color, #d4d4d4);
|
|
1470
|
-
border-radius: 8px;
|
|
1470
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1471
1471
|
font-family: 'Fira Code', monospace;
|
|
1472
1472
|
font-size: 13px;
|
|
1473
1473
|
overflow-x: auto;
|
|
1474
|
-
margin-bottom: 12px;
|
|
1474
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
1475
1475
|
}
|
|
1476
1476
|
|
|
1477
1477
|
.nice-code-editor-ai__generated button {
|
|
1478
|
-
padding: 8px 16px;
|
|
1478
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-4, 16px);
|
|
1479
1479
|
background: var(--nice-bg-secondary, #f5f5f5);
|
|
1480
1480
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1481
|
-
border-radius: 6px;
|
|
1481
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1482
1482
|
cursor: pointer;
|
|
1483
1483
|
}
|
|
1484
|
-
`})]}):e.jsxs("div",{className:`nice-code-editor-ai nice-code-editor-ai--disabled ${g||""}`,style:f,children:[e.jsx("p",{children:"AI not configured. Please provide config or wrap in NiceAIProvider."}),e.jsx("textarea",{value:w,onChange:O=>I(O.target.value),placeholder:
|
|
1485
|
-
`);return{line:
|
|
1486
|
-
`),x=Z(le,{description:_,context:l}),M=await R.chat({messages:[{role:"system",content:x.system},{role:"user",content:x.user}],temperature:.5,maxTokens:2048}),z=Oe(M),D={workflow:z||void 0,rawResponse:(A=(
|
|
1484
|
+
`})]}):e.jsxs("div",{className:`nice-code-editor-ai nice-code-editor-ai--disabled ${g||""}`,style:f,children:[e.jsx("p",{children:"AI not configured. Please provide config or wrap in NiceAIProvider."}),e.jsx("textarea",{value:w,onChange:O=>I(O.target.value),placeholder:c,className:"nice-code-editor-ai__textarea"})]})}function St(i){const t=i.value.substring(0,i.selectionStart).split(`
|
|
1485
|
+
`);return{line:t.length-1,column:t[t.length-1].length}}function ga(i={}){const{config:a,context:t,existingRoles:r,existingVariables:n,onWorkflowGenerated:s,onError:m}=i,c=X(),[g,f]=o.useState(!1),[j,w]=o.useState(null),[N,S]=o.useState([]),$=o.useRef(null),k=a||(c==null?void 0:c.config),P=o.useCallback(async _=>{var u,y,A;if(!k){const R="AI not configured";return m==null||m(R),{error:R}}f(!0);const b=performance.now();(u=$.current)==null||u.abort(),$.current=new AbortController;try{const R=G(k),l=[t,r!=null&&r.length?`Available roles: ${r.join(", ")}`:"",n!=null&&n.length?`Existing variables: ${n.join(", ")}`:""].filter(Boolean).join(`
|
|
1486
|
+
`),x=Z(le,{description:_,context:l}),M=await R.chat({messages:[{role:"system",content:x.system},{role:"user",content:x.user}],temperature:.5,maxTokens:2048}),z=Oe(M),D={workflow:z||void 0,rawResponse:(A=(y=M.choices[0])==null?void 0:y.message)==null?void 0:A.content,latencyMs:performance.now()-b,error:z?void 0:"Failed to generate workflow",suggestions:At(z)};return z&&(s==null||s(z)),w(D),S(J=>[...J.slice(-9),{request:_,result:D}]),D}catch(R){const l=R instanceof Error?R.message:"Workflow generation failed",x={error:l,latencyMs:performance.now()-b};return w(x),m==null||m(l),x}finally{f(!1)}},[k,t,r,n,s,m]),h=o.useCallback(async _=>{if(!k)return{error:"AI not configured"};f(!0);const b=performance.now();try{const y=await G(k).chat({messages:[{role:"system",content:"You are a workflow optimization expert. Analyze the following BPMN workflow and suggest improvements for efficiency, clarity, and error handling. Return the optimized workflow in JSON format with the same structure."},{role:"user",content:JSON.stringify(_,null,2)}],temperature:.4,maxTokens:2048});return{workflow:Oe(y)||void 0,latencyMs:performance.now()-b}}catch(u){return{error:u instanceof Error?u.message:"Optimization failed"}}finally{f(!1)}},[k]),d=o.useCallback(async(_,b)=>{var u,y;if(!k)return[];f(!0);try{const A=G(k),R=_.nodes.find(z=>z.id===b),M=(((y=(u=(await A.chat({messages:[{role:"system",content:'Given the current workflow state, suggest 2-3 possible next steps after the specified node. Return JSON array of nodes: [{ "id": string, "type": string, "label": string, "description": string }]'},{role:"user",content:`Workflow: ${_.name}
|
|
1487
1487
|
Current node: ${(R==null?void 0:R.label)||b}
|
|
1488
|
-
Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxTokens:512})).choices[0])==null?void 0:u.message)==null?void 0:
|
|
1488
|
+
Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxTokens:512})).choices[0])==null?void 0:u.message)==null?void 0:y.content)||"").match(/\[[\s\S]*\]/);if(M)return JSON.parse(M[0])}catch{}finally{f(!1)}return[]},[k]),v=o.useCallback(async _=>{var b,u;if(!k)return[];f(!0);try{const l=(((u=(b=(await G(k).chat({messages:[{role:"system",content:'Analyze the BPMN workflow for potential issues. Check for: dead ends, unreachable nodes, missing error handling, infinite loops, unclear conditions, missing assignments. Return JSON array of issues: [{ "severity": "error"|"warning"|"info", "message": string, "nodeId": string? }]'},{role:"user",content:JSON.stringify(_,null,2)}],temperature:.3,maxTokens:1024})).choices[0])==null?void 0:b.message)==null?void 0:u.content)||"").match(/\[[\s\S]*\]/);if(l)return JSON.parse(l[0]).map(M=>`[${M.severity}] ${M.message}`)}catch{}finally{f(!1)}return[]},[k]),C=o.useCallback(()=>{w(null)},[]),p=o.useCallback(()=>{var _;(_=$.current)==null||_.abort(),f(!1)},[]);return o.useEffect(()=>()=>{var _;(_=$.current)==null||_.abort()},[]),{generateWorkflow:P,optimizeWorkflow:h,suggestNextStep:d,validateWorkflow:v,loading:g,lastResult:j,history:N,clearResults:C,abort:p,isConfigured:!!k}}function Oe(i){var a,t,r;try{const n=((t=(a=i.choices[0])==null?void 0:a.message)==null?void 0:t.content)||"",m=((r=(n.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,n])[1])==null?void 0:r.trim())||n,c=JSON.parse(m);if(c.nodes&&Array.isArray(c.nodes)){const g=c.nodes.map((f,j)=>({...f,id:f.id||`node_${j}`,position:f.position||Tt(j,c.nodes.length)}));return{id:c.id||`workflow_${Date.now()}`,name:c.name||"Generated Workflow",description:c.description,version:c.version||"1.0",nodes:g,edges:c.edges||[],lanes:c.lanes,variables:c.variables,metadata:c.metadata}}}catch{}return null}function Tt(i,a){const s=Math.floor(i/5);return{x:100+i%5*200,y:100+s*100}}function At(i){if(!i)return[];const a=[];return i.nodes.some(s=>s.type==="event-error")||a.push("Add error boundary events for critical tasks"),!i.nodes.some(s=>s.type==="gateway-parallel")&&i.nodes.length>5&&a.push("Consider parallel gateways for independent tasks"),(!i.lanes||i.lanes.length===0)&&a.push("Add swimlanes to clarify responsibilities"),i.nodes.some(s=>s.type==="event-timer")||a.push("Add timer events for SLA monitoring"),a.slice(0,3)}const Rt=["Employee onboarding process with HR approval","Purchase order approval with budget check","Customer support ticket escalation workflow","Document review and approval process","Leave request with manager and HR approval"];function Mt({config:i,context:a,roles:t,onGenerate:r,placeholder:n='Describe the workflow process... (e.g., "Leave request with manager approval")',showExamples:s=!0,showPreview:m=!0,className:c,style:g,renderWorkflow:f}){const[j,w]=o.useState(""),[N,S]=o.useState([]),$=o.useRef(null),{generateWorkflow:k,validateWorkflow:P,loading:h,lastResult:d,isConfigured:v}=ga({config:i,context:a,existingRoles:t,onWorkflowGenerated:r}),C=async()=>{!j.trim()||h||await k(j)},p=u=>{var y;w(u),(y=$.current)==null||y.focus()},_=async()=>{if(!(d!=null&&d.workflow))return;const u=await P(d.workflow);S(u)},b=()=>{if(!(d!=null&&d.workflow))return;const u=$t(d.workflow),y=new Blob([u],{type:"application/xml"}),A=URL.createObjectURL(y),R=document.createElement("a");R.href=A,R.download=`${d.workflow.name.replace(/\s+/g,"_")}.bpmn`,R.click(),URL.revokeObjectURL(A)};return v?e.jsxs("div",{className:`nice-workflow-ai ${c||""}`,style:g,children:[e.jsxs("div",{className:"nice-workflow-ai__input-section",children:[e.jsx("textarea",{ref:$,value:j,onChange:u=>w(u.target.value),placeholder:n,className:"nice-workflow-ai__input",rows:3,disabled:h}),e.jsx("button",{type:"button",onClick:C,className:"nice-workflow-ai__submit",disabled:h||!j.trim(),children:h?e.jsx("span",{className:"nice-workflow-ai__spinner"}):"🔄 Generate Workflow"})]}),s&&e.jsxs("div",{className:"nice-workflow-ai__examples",children:[e.jsx("span",{className:"nice-workflow-ai__examples-label",children:"Try:"}),Rt.slice(0,3).map((u,y)=>e.jsx("button",{type:"button",className:"nice-workflow-ai__example",onClick:()=>p(u),children:u},y))]}),d&&e.jsx("div",{className:"nice-workflow-ai__result",children:d.error?e.jsx("div",{className:"nice-workflow-ai__error",children:d.error}):d.workflow&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-workflow-ai__result-header",children:[e.jsxs("div",{className:"nice-workflow-ai__workflow-info",children:[e.jsx("span",{className:"nice-workflow-ai__workflow-name",children:d.workflow.name}),d.workflow.description&&e.jsx("span",{className:"nice-workflow-ai__workflow-desc",children:d.workflow.description})]}),e.jsxs("div",{className:"nice-workflow-ai__result-meta",children:[e.jsxs("span",{className:"nice-workflow-ai__stat",children:[d.workflow.nodes.length," nodes"]}),e.jsxs("span",{className:"nice-workflow-ai__stat",children:[d.workflow.edges.length," connections"]}),d.latencyMs&&e.jsxs("span",{className:"nice-workflow-ai__latency",children:[Math.round(d.latencyMs),"ms"]})]})]}),e.jsxs("div",{className:"nice-workflow-ai__actions",children:[e.jsx("button",{type:"button",onClick:()=>r==null?void 0:r(d.workflow),children:"✅ Use Workflow"}),e.jsx("button",{type:"button",onClick:_,children:"🔍 Validate"}),e.jsx("button",{type:"button",onClick:b,children:"📥 Export BPMN"})]}),N.length>0&&e.jsxs("div",{className:"nice-workflow-ai__validation",children:[e.jsx("div",{className:"nice-workflow-ai__validation-title",children:"Validation Issues:"}),e.jsx("ul",{children:N.map((u,y)=>e.jsx("li",{className:`nice-workflow-ai__issue nice-workflow-ai__issue--${u.startsWith("[error]")?"error":u.startsWith("[warning]")?"warning":"info"}`,children:u},y))})]}),m&&e.jsx("div",{className:"nice-workflow-ai__preview",children:f?f(d.workflow):e.jsx(Pt,{workflow:d.workflow})}),d.suggestions&&d.suggestions.length>0&&e.jsxs("div",{className:"nice-workflow-ai__suggestions",children:[e.jsx("span",{className:"nice-workflow-ai__suggestions-title",children:"💡 Suggestions:"}),e.jsx("ul",{children:d.suggestions.map((u,y)=>e.jsx("li",{children:u},y))})]}),e.jsxs("details",{className:"nice-workflow-ai__json",children:[e.jsx("summary",{children:"View JSON Definition"}),e.jsx("pre",{children:JSON.stringify(d.workflow,null,2)})]})]})}),e.jsx("style",{children:`
|
|
1489
1489
|
.nice-workflow-ai {
|
|
1490
1490
|
font-family: var(--nice-font-family, system-ui, sans-serif);
|
|
1491
1491
|
}
|
|
1492
1492
|
|
|
1493
1493
|
.nice-workflow-ai--disabled {
|
|
1494
|
-
padding: 20px;
|
|
1494
|
+
padding: var(--nice-space-5, 20px);
|
|
1495
1495
|
background: var(--nice-disabled-bg, #f5f5f5);
|
|
1496
|
-
border-radius: 8px;
|
|
1496
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1497
1497
|
color: var(--nice-text-muted, #666);
|
|
1498
1498
|
}
|
|
1499
1499
|
|
|
1500
1500
|
.nice-workflow-ai__input-section {
|
|
1501
1501
|
display: flex;
|
|
1502
|
-
gap: 12px;
|
|
1503
|
-
margin-bottom: 12px;
|
|
1502
|
+
gap: var(--nice-space-3, 12px);
|
|
1503
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
1504
1504
|
}
|
|
1505
1505
|
|
|
1506
1506
|
.nice-workflow-ai__input {
|
|
1507
1507
|
flex: 1;
|
|
1508
|
-
padding: 12px;
|
|
1508
|
+
padding: var(--nice-space-3, 12px);
|
|
1509
1509
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1510
|
-
border-radius: 8px;
|
|
1510
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1511
1511
|
font-size: 14px;
|
|
1512
1512
|
resize: vertical;
|
|
1513
1513
|
min-height: 80px;
|
|
@@ -1523,11 +1523,11 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1523
1523
|
display: flex;
|
|
1524
1524
|
align-items: center;
|
|
1525
1525
|
justify-content: center;
|
|
1526
|
-
padding: 12px 24px;
|
|
1526
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-6, 24px);
|
|
1527
1527
|
background: var(--nice-primary, #0066cc);
|
|
1528
1528
|
color: white;
|
|
1529
1529
|
border: none;
|
|
1530
|
-
border-radius: 8px;
|
|
1530
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1531
1531
|
font-weight: 500;
|
|
1532
1532
|
cursor: pointer;
|
|
1533
1533
|
white-space: nowrap;
|
|
@@ -1546,9 +1546,9 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1546
1546
|
.nice-workflow-ai__spinner {
|
|
1547
1547
|
width: 20px;
|
|
1548
1548
|
height: 20px;
|
|
1549
|
-
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
1549
|
+
border: 2px solid var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3));
|
|
1550
1550
|
border-top-color: white;
|
|
1551
|
-
border-radius: 50
|
|
1551
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
1552
1552
|
animation: nice-spin 0.8s linear infinite;
|
|
1553
1553
|
}
|
|
1554
1554
|
|
|
@@ -1559,9 +1559,9 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1559
1559
|
.nice-workflow-ai__examples {
|
|
1560
1560
|
display: flex;
|
|
1561
1561
|
flex-wrap: wrap;
|
|
1562
|
-
gap: 8px;
|
|
1562
|
+
gap: var(--nice-space-2, 8px);
|
|
1563
1563
|
align-items: center;
|
|
1564
|
-
margin-bottom: 16px;
|
|
1564
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1565
1565
|
}
|
|
1566
1566
|
|
|
1567
1567
|
.nice-workflow-ai__examples-label {
|
|
@@ -1570,9 +1570,9 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1570
1570
|
}
|
|
1571
1571
|
|
|
1572
1572
|
.nice-workflow-ai__example {
|
|
1573
|
-
padding: 6px 12px;
|
|
1573
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-3, 12px);
|
|
1574
1574
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1575
|
-
border-radius: 16px;
|
|
1575
|
+
border-radius: var(--nice-radius-xl, 16px);
|
|
1576
1576
|
background: white;
|
|
1577
1577
|
font-size: 12px;
|
|
1578
1578
|
cursor: pointer;
|
|
@@ -1585,9 +1585,9 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1585
1585
|
}
|
|
1586
1586
|
|
|
1587
1587
|
.nice-workflow-ai__result {
|
|
1588
|
-
padding: 20px;
|
|
1588
|
+
padding: var(--nice-space-5, 20px);
|
|
1589
1589
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
1590
|
-
border-radius: 8px;
|
|
1590
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1591
1591
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1592
1592
|
}
|
|
1593
1593
|
|
|
@@ -1595,13 +1595,13 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1595
1595
|
display: flex;
|
|
1596
1596
|
justify-content: space-between;
|
|
1597
1597
|
align-items: flex-start;
|
|
1598
|
-
margin-bottom: 16px;
|
|
1598
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1599
1599
|
}
|
|
1600
1600
|
|
|
1601
1601
|
.nice-workflow-ai__workflow-info {
|
|
1602
1602
|
display: flex;
|
|
1603
1603
|
flex-direction: column;
|
|
1604
|
-
gap: 4px;
|
|
1604
|
+
gap: var(--nice-space-1, 4px);
|
|
1605
1605
|
}
|
|
1606
1606
|
|
|
1607
1607
|
.nice-workflow-ai__workflow-name {
|
|
@@ -1616,15 +1616,15 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1616
1616
|
|
|
1617
1617
|
.nice-workflow-ai__result-meta {
|
|
1618
1618
|
display: flex;
|
|
1619
|
-
gap: 12px;
|
|
1619
|
+
gap: var(--nice-space-3, 12px);
|
|
1620
1620
|
font-size: 12px;
|
|
1621
1621
|
color: var(--nice-text-muted, #666);
|
|
1622
1622
|
}
|
|
1623
1623
|
|
|
1624
1624
|
.nice-workflow-ai__stat {
|
|
1625
|
-
padding: 4px 8px;
|
|
1625
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-2, 8px);
|
|
1626
1626
|
background: var(--nice-bg-secondary, #e0e0e0);
|
|
1627
|
-
border-radius: 4px;
|
|
1627
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
1628
1628
|
}
|
|
1629
1629
|
|
|
1630
1630
|
.nice-workflow-ai__latency {
|
|
@@ -1633,14 +1633,14 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1633
1633
|
|
|
1634
1634
|
.nice-workflow-ai__actions {
|
|
1635
1635
|
display: flex;
|
|
1636
|
-
gap: 8px;
|
|
1637
|
-
margin-bottom: 16px;
|
|
1636
|
+
gap: var(--nice-space-2, 8px);
|
|
1637
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1638
1638
|
}
|
|
1639
1639
|
|
|
1640
1640
|
.nice-workflow-ai__actions button {
|
|
1641
|
-
padding: 8px 16px;
|
|
1641
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-4, 16px);
|
|
1642
1642
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1643
|
-
border-radius: 6px;
|
|
1643
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1644
1644
|
background: white;
|
|
1645
1645
|
font-size: 13px;
|
|
1646
1646
|
cursor: pointer;
|
|
@@ -1659,24 +1659,24 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1659
1659
|
}
|
|
1660
1660
|
|
|
1661
1661
|
.nice-workflow-ai__validation {
|
|
1662
|
-
margin-bottom: 16px;
|
|
1663
|
-
padding: 12px;
|
|
1662
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1663
|
+
padding: var(--nice-space-3, 12px);
|
|
1664
1664
|
background: var(--nice-warning-light, #fff3e0);
|
|
1665
|
-
border-radius: 6px;
|
|
1665
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1666
1666
|
}
|
|
1667
1667
|
|
|
1668
1668
|
.nice-workflow-ai__validation-title {
|
|
1669
1669
|
font-weight: 500;
|
|
1670
|
-
margin-bottom: 8px;
|
|
1670
|
+
margin-bottom: var(--nice-space-2, 8px);
|
|
1671
1671
|
}
|
|
1672
1672
|
|
|
1673
1673
|
.nice-workflow-ai__validation ul {
|
|
1674
1674
|
margin: 0;
|
|
1675
|
-
padding-left: 20px;
|
|
1675
|
+
padding-left: var(--nice-space-5, 20px);
|
|
1676
1676
|
}
|
|
1677
1677
|
|
|
1678
1678
|
.nice-workflow-ai__issue {
|
|
1679
|
-
margin-bottom: 4px;
|
|
1679
|
+
margin-bottom: var(--nice-space-1, 4px);
|
|
1680
1680
|
font-size: 13px;
|
|
1681
1681
|
}
|
|
1682
1682
|
|
|
@@ -1693,35 +1693,35 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1693
1693
|
}
|
|
1694
1694
|
|
|
1695
1695
|
.nice-workflow-ai__preview {
|
|
1696
|
-
padding: 20px;
|
|
1696
|
+
padding: var(--nice-space-5, 20px);
|
|
1697
1697
|
background: white;
|
|
1698
|
-
border-radius: 8px;
|
|
1698
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1699
1699
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1700
|
-
margin-bottom: 16px;
|
|
1700
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1701
1701
|
overflow-x: auto;
|
|
1702
1702
|
}
|
|
1703
1703
|
|
|
1704
1704
|
.nice-workflow-ai__suggestions {
|
|
1705
|
-
margin-bottom: 16px;
|
|
1706
|
-
padding: 12px;
|
|
1705
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1706
|
+
padding: var(--nice-space-3, 12px);
|
|
1707
1707
|
background: var(--nice-info-light, #e3f2fd);
|
|
1708
|
-
border-radius: 6px;
|
|
1708
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1709
1709
|
}
|
|
1710
1710
|
|
|
1711
1711
|
.nice-workflow-ai__suggestions-title {
|
|
1712
1712
|
font-weight: 500;
|
|
1713
|
-
margin-bottom: 8px;
|
|
1713
|
+
margin-bottom: var(--nice-space-2, 8px);
|
|
1714
1714
|
display: block;
|
|
1715
1715
|
}
|
|
1716
1716
|
|
|
1717
1717
|
.nice-workflow-ai__suggestions ul {
|
|
1718
1718
|
margin: 0;
|
|
1719
|
-
padding-left: 20px;
|
|
1719
|
+
padding-left: var(--nice-space-5, 20px);
|
|
1720
1720
|
font-size: 13px;
|
|
1721
1721
|
}
|
|
1722
1722
|
|
|
1723
1723
|
.nice-workflow-ai__json {
|
|
1724
|
-
margin-top: 12px;
|
|
1724
|
+
margin-top: var(--nice-space-3, 12px);
|
|
1725
1725
|
}
|
|
1726
1726
|
|
|
1727
1727
|
.nice-workflow-ai__json summary {
|
|
@@ -1731,22 +1731,22 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1731
1731
|
}
|
|
1732
1732
|
|
|
1733
1733
|
.nice-workflow-ai__json pre {
|
|
1734
|
-
margin: 8px 0 0;
|
|
1735
|
-
padding: 12px;
|
|
1734
|
+
margin: var(--nice-space-2, 8px) 0 0;
|
|
1735
|
+
padding: var(--nice-space-3, 12px);
|
|
1736
1736
|
background: var(--nice-code-bg, #1e1e1e);
|
|
1737
1737
|
color: var(--nice-code-color, #d4d4d4);
|
|
1738
|
-
border-radius: 6px;
|
|
1738
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1739
1739
|
font-size: 12px;
|
|
1740
1740
|
overflow-x: auto;
|
|
1741
1741
|
}
|
|
1742
1742
|
|
|
1743
1743
|
.nice-workflow-ai__error {
|
|
1744
|
-
padding: 12px;
|
|
1744
|
+
padding: var(--nice-space-3, 12px);
|
|
1745
1745
|
background: var(--nice-error-light, #ffebee);
|
|
1746
1746
|
color: var(--nice-error, #c62828);
|
|
1747
|
-
border-radius: 6px;
|
|
1747
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
1748
1748
|
}
|
|
1749
|
-
`})]}):e.jsx("div",{className:`nice-workflow-ai nice-workflow-ai--disabled ${
|
|
1749
|
+
`})]}):e.jsx("div",{className:`nice-workflow-ai nice-workflow-ai--disabled ${c||""}`,style:g,children:e.jsx("p",{children:"AI not configured. Please provide config or wrap in NiceAIProvider."})})}function Pt({workflow:i}){const a=r=>({start:"▶️",end:"⏹️",task:"📋",userTask:"👤",serviceTask:"⚙️",scriptTask:"📜","gateway-exclusive":"◇","gateway-parallel":"✚","gateway-inclusive":"○","event-timer":"⏰","event-message":"✉️","event-error":"⚠️"})[r]||"📋",t=r=>r==="start"?"var(--nice-success, #4caf50)":r==="end"?"var(--nice-danger, #f44336)":r.startsWith("gateway")?"var(--nice-warning, #ff9800)":r.startsWith("event")?"var(--nice-accent, #9c27b0)":"var(--nice-primary, #2196f3)";return e.jsxs("div",{className:"workflow-preview",children:[e.jsxs("div",{className:"workflow-preview__diagram",children:[i.nodes.map(r=>{var n,s;return e.jsxs("div",{className:`workflow-preview__node workflow-preview__node--${r.type.split("-")[0]}`,style:{left:(n=r.position)==null?void 0:n.x,top:(s=r.position)==null?void 0:s.y,borderColor:t(r.type)},children:[e.jsx("span",{className:"workflow-preview__node-icon",children:a(r.type)}),e.jsx("span",{className:"workflow-preview__node-label",children:r.label})]},r.id)}),e.jsxs("svg",{className:"workflow-preview__connections",children:[i.edges.map(r=>{const n=i.nodes.find(j=>j.id===r.source),s=i.nodes.find(j=>j.id===r.target);if(!(n!=null&&n.position)||!(s!=null&&s.position))return null;const m=n.position.x+60,c=n.position.y+20,g=s.position.x,f=s.position.y+20;return e.jsxs("g",{children:[e.jsx("line",{x1:m,y1:c,x2:g,y2:f,stroke:"var(--nice-text-secondary, #666)",strokeWidth:"2",markerEnd:"url(#arrowhead)"}),r.label&&e.jsx("text",{x:(m+g)/2,y:(c+f)/2-5,fontSize:"10",fill:"var(--nice-text-secondary, #666)",textAnchor:"middle",children:r.label})]},r.id)}),e.jsx("defs",{children:e.jsx("marker",{id:"arrowhead",markerWidth:"10",markerHeight:"7",refX:"9",refY:"3.5",orient:"auto",children:e.jsx("polygon",{points:"0 0, 10 3.5, 0 7",fill:"var(--nice-text-secondary, #666)"})})})]})]}),i.lanes&&i.lanes.length>0&&e.jsxs("div",{className:"workflow-preview__lanes",children:[e.jsx("span",{className:"workflow-preview__lanes-title",children:"Swimlanes:"}),i.lanes.map(r=>e.jsx("span",{className:"workflow-preview__lane",children:r.name},r.id))]}),e.jsx("style",{children:`
|
|
1750
1750
|
.workflow-preview {
|
|
1751
1751
|
min-height: 200px;
|
|
1752
1752
|
}
|
|
@@ -1754,26 +1754,26 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1754
1754
|
.workflow-preview__diagram {
|
|
1755
1755
|
position: relative;
|
|
1756
1756
|
min-height: 300px;
|
|
1757
|
-
padding: 20px;
|
|
1757
|
+
padding: var(--nice-space-5, 20px);
|
|
1758
1758
|
}
|
|
1759
1759
|
|
|
1760
1760
|
.workflow-preview__node {
|
|
1761
1761
|
position: absolute;
|
|
1762
1762
|
display: flex;
|
|
1763
1763
|
align-items: center;
|
|
1764
|
-
gap: 8px;
|
|
1765
|
-
padding: 10px 16px;
|
|
1764
|
+
gap: var(--nice-space-2, 8px);
|
|
1765
|
+
padding: var(--nice-space-2-5, 10px) var(--nice-space-4, 16px);
|
|
1766
1766
|
background: white;
|
|
1767
1767
|
border: 2px solid;
|
|
1768
|
-
border-radius: 8px;
|
|
1768
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1769
1769
|
font-size: 13px;
|
|
1770
1770
|
white-space: nowrap;
|
|
1771
|
-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
1771
|
+
box-shadow: 0 2px 4px var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
|
|
1772
1772
|
}
|
|
1773
1773
|
|
|
1774
1774
|
.workflow-preview__node--start,
|
|
1775
1775
|
.workflow-preview__node--end {
|
|
1776
|
-
border-radius: 50
|
|
1776
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
1777
1777
|
width: 40px;
|
|
1778
1778
|
height: 40px;
|
|
1779
1779
|
padding: 0;
|
|
@@ -1817,10 +1817,10 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1817
1817
|
|
|
1818
1818
|
.workflow-preview__lanes {
|
|
1819
1819
|
display: flex;
|
|
1820
|
-
gap: 8px;
|
|
1820
|
+
gap: var(--nice-space-2, 8px);
|
|
1821
1821
|
align-items: center;
|
|
1822
|
-
margin-top: 16px;
|
|
1823
|
-
padding-top: 16px;
|
|
1822
|
+
margin-top: var(--nice-space-4, 16px);
|
|
1823
|
+
padding-top: var(--nice-space-4, 16px);
|
|
1824
1824
|
border-top: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1825
1825
|
}
|
|
1826
1826
|
|
|
@@ -1830,52 +1830,52 @@ Existing nodes: ${_.nodes.map(z=>z.label).join(", ")}`}],temperature:.6,maxToken
|
|
|
1830
1830
|
}
|
|
1831
1831
|
|
|
1832
1832
|
.workflow-preview__lane {
|
|
1833
|
-
padding: 4px 12px;
|
|
1833
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-3, 12px);
|
|
1834
1834
|
background: var(--nice-bg-subtle, #f0f0f0);
|
|
1835
|
-
border-radius: 4px;
|
|
1835
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
1836
1836
|
font-size: 12px;
|
|
1837
1837
|
}
|
|
1838
|
-
`})]})}function $i
|
|
1839
|
-
`),r=
|
|
1838
|
+
`})]})}function $t(i){const a={start:"bpmn:startEvent",end:"bpmn:endEvent",task:"bpmn:task",userTask:"bpmn:userTask",serviceTask:"bpmn:serviceTask",scriptTask:"bpmn:scriptTask","gateway-exclusive":"bpmn:exclusiveGateway","gateway-parallel":"bpmn:parallelGateway","gateway-inclusive":"bpmn:inclusiveGateway"},t=i.nodes.map(n=>` <${a[n.type]||"bpmn:task"} id="${n.id}" name="${ge(n.label)}" />`).join(`
|
|
1839
|
+
`),r=i.edges.map(n=>` <bpmn:sequenceFlow id="${n.id}" sourceRef="${n.source}" targetRef="${n.target}"${n.label?` name="${ge(n.label)}"`:""} />`).join(`
|
|
1840
1840
|
`);return`<?xml version="1.0" encoding="UTF-8"?>
|
|
1841
1841
|
<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
|
1842
1842
|
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
|
|
1843
|
-
id="${
|
|
1843
|
+
id="${i.id}"
|
|
1844
1844
|
targetNamespace="http://nice2dev.com/bpmn">
|
|
1845
|
-
<bpmn:process id="Process_${
|
|
1846
|
-
${
|
|
1845
|
+
<bpmn:process id="Process_${i.id}" name="${ge(i.name)}" isExecutable="true">
|
|
1846
|
+
${t}
|
|
1847
1847
|
${r}
|
|
1848
1848
|
</bpmn:process>
|
|
1849
|
-
</bpmn:definitions>`}function ge(
|
|
1850
|
-
`):void 0,l=Z(de,{description:
|
|
1851
|
-
Existing sections: ${
|
|
1852
|
-
Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.message)==null?void 0:u.content)==null?void 0:
|
|
1849
|
+
</bpmn:definitions>`}function ge(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function fa(i={}){const{config:a,dataSources:t,context:r,onReportGenerated:n,onError:s}=i,m=X(),[c,g]=o.useState(!1),[f,j]=o.useState(null),[w,N]=o.useState([]),S=o.useRef(null),$=a||(m==null?void 0:m.config),k=o.useCallback(async p=>{var b,u,y;if(!$){const A="AI not configured";return s==null||s(A),{error:A}}g(!0);const _=performance.now();(b=S.current)==null||b.abort(),S.current=new AbortController;try{const A=G($),R=t?t.map(D=>`- ${D.name} (${D.id}): ${D.fields.join(", ")}`).join(`
|
|
1850
|
+
`):void 0,l=Z(de,{description:p,data_sources:R,context:r}),x=await A.chat({messages:[{role:"system",content:l.system},{role:"user",content:l.user}],temperature:.5,maxTokens:2048}),M=It(x),z={layout:M||void 0,rawResponse:(y=(u=x.choices[0])==null?void 0:u.message)==null?void 0:y.content,latencyMs:performance.now()-_,error:M?void 0:"Failed to generate report layout",suggestions:zt(M)};return M&&(n==null||n(M)),j(z),N(D=>[...D.slice(-9),{request:p,result:z}]),z}catch(A){const R=A instanceof Error?A.message:"Report generation failed",l={error:R,latencyMs:performance.now()-_};return j(l),s==null||s(R),l}finally{g(!1)}},[$,t,r,n,s]),P=o.useCallback(async p=>{var _,b;if(!$)return[];g(!0);try{const R=(((b=(_=(await G($).chat({messages:[{role:"system",content:"Given the existing report layout, suggest 2-3 additional sections that would enhance it. Return JSON array of sections with: id, type, title, order, config."},{role:"user",content:`Report: ${p.name}
|
|
1851
|
+
Existing sections: ${p.sections.map(l=>l.type).join(", ")}`}],temperature:.6,maxTokens:1024})).choices[0])==null?void 0:_.message)==null?void 0:b.content)||"").match(/\[[\s\S]*\]/);if(R)return JSON.parse(R[0])}catch{}finally{g(!1)}return[]},[$]),h=o.useCallback(async p=>{var _,b;if(!$)return null;g(!0);try{return((b=(_=(await G($).chat({messages:[{role:"system",content:"Generate a concise executive summary (2-3 paragraphs) based on the provided data. Highlight key metrics, trends, and actionable insights."},{role:"user",content:JSON.stringify(p,null,2)}],temperature:.5,maxTokens:512})).choices[0])==null?void 0:_.message)==null?void 0:b.content)||null}catch{return null}finally{g(!1)}},[$]),d=o.useCallback(async(p,_)=>{var b,u,y;if(!$)return"bar";try{const A=G($),R=p.slice(0,5),x=(y=(u=(b=(await A.chat({messages:[{role:"system",content:"Based on the data sample and description, recommend the best chart type. Return only the chart type: line, bar, pie, donut, area, column, scatter, combo, gauge, or heatmap."},{role:"user",content:`Data: ${JSON.stringify(R)}
|
|
1852
|
+
Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.message)==null?void 0:u.content)==null?void 0:y.toLowerCase().trim();return["line","bar","pie","donut","area","column","scatter","combo","gauge","heatmap"].find(z=>x==null?void 0:x.includes(z))||"bar"}catch{return"bar"}},[$]),v=o.useCallback(()=>{j(null)},[]),C=o.useCallback(()=>{var p;(p=S.current)==null||p.abort(),g(!1)},[]);return o.useEffect(()=>()=>{var p;(p=S.current)==null||p.abort()},[]),{generateReport:k,suggestSections:P,generateSummary:h,suggestChartType:d,loading:c,lastResult:f,history:w,clearResults:v,abort:C,isConfigured:!!$}}function It(i){var a,t,r;try{const n=((t=(a=i.choices[0])==null?void 0:a.message)==null?void 0:t.content)||"",m=((r=(n.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,n])[1])==null?void 0:r.trim())||n,c=JSON.parse(m);if(c.sections&&Array.isArray(c.sections)){const g=c.sections.map((f,j)=>({...f,id:f.id||`section_${j}`,order:f.order??j,config:f.config||{}}));return{id:c.id||`report_${Date.now()}`,name:c.name||"Generated Report",description:c.description,orientation:c.orientation||"portrait",pageSize:c.pageSize||"A4",margins:c.margins||{top:20,right:20,bottom:20,left:20},sections:g,dataSources:c.dataSources,parameters:c.parameters,styles:c.styles}}}catch{}return null}function zt(i){if(!i)return[];const a=[],t=new Set(i.sections.map(r=>r.type));return t.has("summary")||a.push("Add an executive summary for quick insights"),t.has("kpi")||a.push("Include KPI cards for key metrics"),t.has("chart")||a.push("Add visualizations to make data more accessible"),t.has("footer")||a.push("Add a footer with page numbers and date"),i.sections.length>5&&!t.has("toc")&&a.push("Consider adding a table of contents"),a.slice(0,3)}const Lt=[{icon:"📊",name:"Sales Report",prompt:"Monthly sales report with revenue KPIs, sales by region chart, and top products table"},{icon:"📈",name:"Financial Summary",prompt:"Quarterly financial summary with P&L, cash flow chart, and expense breakdown"},{icon:"👥",name:"HR Dashboard",prompt:"Employee report with headcount KPIs, department breakdown, and turnover trends"},{icon:"📦",name:"Inventory Report",prompt:"Inventory status report with stock levels, low stock alerts, and turnover analysis"},{icon:"🎯",name:"KPI Dashboard",prompt:"Executive KPI dashboard with performance metrics, trends, and target comparison"}];function Ot({config:i,dataSources:a,context:t,onGenerate:r,placeholder:n='Describe the report you need... (e.g., "Monthly sales report with KPIs and charts")',showTemplates:s=!0,showPreview:m=!0,className:c,style:g,renderReport:f}){const[j,w]=o.useState(""),N=o.useRef(null),{generateReport:S,loading:$,lastResult:k,isConfigured:P}=fa({config:i,dataSources:a,context:t,onReportGenerated:r}),h=async()=>{!j.trim()||$||await S(j)},d=C=>{var p;w(C.prompt),(p=N.current)==null||p.focus()},v=()=>{if(!(k!=null&&k.layout))return;const C=JSON.stringify(k.layout,null,2),p=new Blob([C],{type:"application/json"}),_=URL.createObjectURL(p),b=document.createElement("a");b.href=_,b.download=`${k.layout.name.replace(/\s+/g,"_")}.json`,b.click(),URL.revokeObjectURL(_)};return P?e.jsxs("div",{className:`nice-report-ai ${c||""}`,style:g,children:[s&&e.jsx("div",{className:"nice-report-ai__templates",children:Lt.map((C,p)=>e.jsxs("button",{type:"button",className:"nice-report-ai__template",onClick:()=>d(C),children:[e.jsx("span",{className:"nice-report-ai__template-icon",children:C.icon}),e.jsx("span",{className:"nice-report-ai__template-name",children:C.name})]},p))}),e.jsxs("div",{className:"nice-report-ai__input-section",children:[e.jsx("textarea",{ref:N,value:j,onChange:C=>w(C.target.value),placeholder:n,className:"nice-report-ai__input",rows:3,disabled:$}),e.jsx("button",{type:"button",onClick:h,className:"nice-report-ai__submit",disabled:$||!j.trim(),children:$?e.jsx("span",{className:"nice-report-ai__spinner"}):"📄 Generate Report"})]}),a&&a.length>0&&e.jsxs("div",{className:"nice-report-ai__datasources",children:[e.jsx("span",{className:"nice-report-ai__datasources-label",children:"Available data:"}),a.map(C=>e.jsx("span",{className:"nice-report-ai__datasource",children:C.name},C.id))]}),k&&e.jsx("div",{className:"nice-report-ai__result",children:k.error?e.jsx("div",{className:"nice-report-ai__error",children:k.error}):k.layout&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"nice-report-ai__result-header",children:[e.jsxs("div",{className:"nice-report-ai__report-info",children:[e.jsx("span",{className:"nice-report-ai__report-name",children:k.layout.name}),k.layout.description&&e.jsx("span",{className:"nice-report-ai__report-desc",children:k.layout.description})]}),e.jsxs("div",{className:"nice-report-ai__result-meta",children:[e.jsxs("span",{className:"nice-report-ai__stat",children:[k.layout.sections.length," sections"]}),e.jsxs("span",{className:"nice-report-ai__stat",children:[k.layout.pageSize," ",k.layout.orientation]}),k.latencyMs&&e.jsxs("span",{className:"nice-report-ai__latency",children:[Math.round(k.latencyMs),"ms"]})]})]}),e.jsxs("div",{className:"nice-report-ai__actions",children:[e.jsx("button",{type:"button",onClick:()=>r==null?void 0:r(k.layout),children:"✅ Use Report"}),e.jsx("button",{type:"button",onClick:v,children:"📥 Export JSON"})]}),e.jsxs("div",{className:"nice-report-ai__sections",children:[e.jsx("div",{className:"nice-report-ai__sections-title",children:"Report Structure:"}),e.jsx("div",{className:"nice-report-ai__sections-list",children:k.layout.sections.map((C,p)=>e.jsxs("div",{className:"nice-report-ai__section",children:[e.jsx("span",{className:"nice-report-ai__section-number",children:p+1}),e.jsx("span",{className:"nice-report-ai__section-icon",children:xa(C.type)}),e.jsx("span",{className:"nice-report-ai__section-type",children:C.type}),C.title&&e.jsx("span",{className:"nice-report-ai__section-title",children:C.title})]},C.id))})]}),m&&e.jsx("div",{className:"nice-report-ai__preview",children:f?f(k.layout):e.jsx(Et,{layout:k.layout})}),k.suggestions&&k.suggestions.length>0&&e.jsxs("div",{className:"nice-report-ai__suggestions",children:[e.jsx("span",{className:"nice-report-ai__suggestions-title",children:"💡 Suggestions:"}),e.jsx("ul",{children:k.suggestions.map((C,p)=>e.jsx("li",{children:C},p))})]}),e.jsxs("details",{className:"nice-report-ai__json",children:[e.jsx("summary",{children:"View JSON Definition"}),e.jsx("pre",{children:JSON.stringify(k.layout,null,2)})]})]})}),e.jsx("style",{children:`
|
|
1853
1853
|
.nice-report-ai {
|
|
1854
1854
|
font-family: var(--nice-font-family, system-ui, sans-serif);
|
|
1855
1855
|
}
|
|
1856
1856
|
|
|
1857
1857
|
.nice-report-ai--disabled {
|
|
1858
|
-
padding: 20px;
|
|
1858
|
+
padding: var(--nice-space-5, 20px);
|
|
1859
1859
|
background: var(--nice-disabled-bg, #f5f5f5);
|
|
1860
|
-
border-radius: 8px;
|
|
1860
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1861
1861
|
color: var(--nice-text-muted, #666);
|
|
1862
1862
|
}
|
|
1863
1863
|
|
|
1864
1864
|
.nice-report-ai__templates {
|
|
1865
1865
|
display: flex;
|
|
1866
1866
|
flex-wrap: wrap;
|
|
1867
|
-
gap: 8px;
|
|
1868
|
-
margin-bottom: 16px;
|
|
1867
|
+
gap: var(--nice-space-2, 8px);
|
|
1868
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1869
1869
|
}
|
|
1870
1870
|
|
|
1871
1871
|
.nice-report-ai__template {
|
|
1872
1872
|
display: flex;
|
|
1873
1873
|
flex-direction: column;
|
|
1874
1874
|
align-items: center;
|
|
1875
|
-
gap: 4px;
|
|
1876
|
-
padding: 12px 16px;
|
|
1875
|
+
gap: var(--nice-space-1, 4px);
|
|
1876
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-4, 16px);
|
|
1877
1877
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1878
|
-
border-radius: 8px;
|
|
1878
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1879
1879
|
background: white;
|
|
1880
1880
|
cursor: pointer;
|
|
1881
1881
|
transition: all 0.2s;
|
|
@@ -1899,15 +1899,15 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
1899
1899
|
|
|
1900
1900
|
.nice-report-ai__input-section {
|
|
1901
1901
|
display: flex;
|
|
1902
|
-
gap: 12px;
|
|
1903
|
-
margin-bottom: 12px;
|
|
1902
|
+
gap: var(--nice-space-3, 12px);
|
|
1903
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
1904
1904
|
}
|
|
1905
1905
|
|
|
1906
1906
|
.nice-report-ai__input {
|
|
1907
1907
|
flex: 1;
|
|
1908
|
-
padding: 12px;
|
|
1908
|
+
padding: var(--nice-space-3, 12px);
|
|
1909
1909
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1910
|
-
border-radius: 8px;
|
|
1910
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1911
1911
|
font-size: 14px;
|
|
1912
1912
|
resize: vertical;
|
|
1913
1913
|
min-height: 80px;
|
|
@@ -1923,11 +1923,11 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
1923
1923
|
display: flex;
|
|
1924
1924
|
align-items: center;
|
|
1925
1925
|
justify-content: center;
|
|
1926
|
-
padding: 12px 24px;
|
|
1926
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-6, 24px);
|
|
1927
1927
|
background: var(--nice-primary, #0066cc);
|
|
1928
1928
|
color: white;
|
|
1929
1929
|
border: none;
|
|
1930
|
-
border-radius: 8px;
|
|
1930
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1931
1931
|
font-weight: 500;
|
|
1932
1932
|
cursor: pointer;
|
|
1933
1933
|
white-space: nowrap;
|
|
@@ -1946,9 +1946,9 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
1946
1946
|
.nice-report-ai__spinner {
|
|
1947
1947
|
width: 20px;
|
|
1948
1948
|
height: 20px;
|
|
1949
|
-
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
1949
|
+
border: 2px solid var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3));
|
|
1950
1950
|
border-top-color: white;
|
|
1951
|
-
border-radius: 50
|
|
1951
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
1952
1952
|
animation: nice-spin 0.8s linear infinite;
|
|
1953
1953
|
}
|
|
1954
1954
|
|
|
@@ -1959,9 +1959,9 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
1959
1959
|
.nice-report-ai__datasources {
|
|
1960
1960
|
display: flex;
|
|
1961
1961
|
flex-wrap: wrap;
|
|
1962
|
-
gap: 8px;
|
|
1962
|
+
gap: var(--nice-space-2, 8px);
|
|
1963
1963
|
align-items: center;
|
|
1964
|
-
margin-bottom: 16px;
|
|
1964
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1965
1965
|
}
|
|
1966
1966
|
|
|
1967
1967
|
.nice-report-ai__datasources-label {
|
|
@@ -1970,16 +1970,16 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
1970
1970
|
}
|
|
1971
1971
|
|
|
1972
1972
|
.nice-report-ai__datasource {
|
|
1973
|
-
padding: 4px 12px;
|
|
1973
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-3, 12px);
|
|
1974
1974
|
background: var(--nice-bg-subtle, #f0f0f0);
|
|
1975
|
-
border-radius: 4px;
|
|
1975
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
1976
1976
|
font-size: 12px;
|
|
1977
1977
|
}
|
|
1978
1978
|
|
|
1979
1979
|
.nice-report-ai__result {
|
|
1980
|
-
padding: 20px;
|
|
1980
|
+
padding: var(--nice-space-5, 20px);
|
|
1981
1981
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
1982
|
-
border-radius: 8px;
|
|
1982
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
1983
1983
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
1984
1984
|
}
|
|
1985
1985
|
|
|
@@ -1987,13 +1987,13 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
1987
1987
|
display: flex;
|
|
1988
1988
|
justify-content: space-between;
|
|
1989
1989
|
align-items: flex-start;
|
|
1990
|
-
margin-bottom: 16px;
|
|
1990
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
1991
1991
|
}
|
|
1992
1992
|
|
|
1993
1993
|
.nice-report-ai__report-info {
|
|
1994
1994
|
display: flex;
|
|
1995
1995
|
flex-direction: column;
|
|
1996
|
-
gap: 4px;
|
|
1996
|
+
gap: var(--nice-space-1, 4px);
|
|
1997
1997
|
}
|
|
1998
1998
|
|
|
1999
1999
|
.nice-report-ai__report-name {
|
|
@@ -2008,15 +2008,15 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
2008
2008
|
|
|
2009
2009
|
.nice-report-ai__result-meta {
|
|
2010
2010
|
display: flex;
|
|
2011
|
-
gap: 12px;
|
|
2011
|
+
gap: var(--nice-space-3, 12px);
|
|
2012
2012
|
font-size: 12px;
|
|
2013
2013
|
color: var(--nice-text-muted, #666);
|
|
2014
2014
|
}
|
|
2015
2015
|
|
|
2016
2016
|
.nice-report-ai__stat {
|
|
2017
|
-
padding: 4px 8px;
|
|
2017
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-2, 8px);
|
|
2018
2018
|
background: var(--nice-bg-secondary, #e0e0e0);
|
|
2019
|
-
border-radius: 4px;
|
|
2019
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
2020
2020
|
}
|
|
2021
2021
|
|
|
2022
2022
|
.nice-report-ai__latency {
|
|
@@ -2025,14 +2025,14 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
2025
2025
|
|
|
2026
2026
|
.nice-report-ai__actions {
|
|
2027
2027
|
display: flex;
|
|
2028
|
-
gap: 8px;
|
|
2029
|
-
margin-bottom: 16px;
|
|
2028
|
+
gap: var(--nice-space-2, 8px);
|
|
2029
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2030
2030
|
}
|
|
2031
2031
|
|
|
2032
2032
|
.nice-report-ai__actions button {
|
|
2033
|
-
padding: 8px 16px;
|
|
2033
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-4, 16px);
|
|
2034
2034
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2035
|
-
border-radius: 6px;
|
|
2035
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2036
2036
|
background: white;
|
|
2037
2037
|
font-size: 13px;
|
|
2038
2038
|
cursor: pointer;
|
|
@@ -2051,27 +2051,27 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
2051
2051
|
}
|
|
2052
2052
|
|
|
2053
2053
|
.nice-report-ai__sections {
|
|
2054
|
-
margin-bottom: 16px;
|
|
2054
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2055
2055
|
}
|
|
2056
2056
|
|
|
2057
2057
|
.nice-report-ai__sections-title {
|
|
2058
2058
|
font-weight: 500;
|
|
2059
|
-
margin-bottom: 8px;
|
|
2059
|
+
margin-bottom: var(--nice-space-2, 8px);
|
|
2060
2060
|
}
|
|
2061
2061
|
|
|
2062
2062
|
.nice-report-ai__sections-list {
|
|
2063
2063
|
display: flex;
|
|
2064
2064
|
flex-direction: column;
|
|
2065
|
-
gap: 4px;
|
|
2065
|
+
gap: var(--nice-space-1, 4px);
|
|
2066
2066
|
}
|
|
2067
2067
|
|
|
2068
2068
|
.nice-report-ai__section {
|
|
2069
2069
|
display: flex;
|
|
2070
2070
|
align-items: center;
|
|
2071
|
-
gap: 8px;
|
|
2072
|
-
padding: 8px 12px;
|
|
2071
|
+
gap: var(--nice-space-2, 8px);
|
|
2072
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
2073
2073
|
background: white;
|
|
2074
|
-
border-radius: 6px;
|
|
2074
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2075
2075
|
border: 1px solid var(--nice-border-light, #f0f0f0);
|
|
2076
2076
|
}
|
|
2077
2077
|
|
|
@@ -2082,7 +2082,7 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
2082
2082
|
align-items: center;
|
|
2083
2083
|
justify-content: center;
|
|
2084
2084
|
background: var(--nice-primary-light, rgba(0, 102, 204, 0.1));
|
|
2085
|
-
border-radius: 50
|
|
2085
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
2086
2086
|
font-size: 12px;
|
|
2087
2087
|
font-weight: 600;
|
|
2088
2088
|
color: var(--nice-primary, #0066cc);
|
|
@@ -2104,35 +2104,35 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
2104
2104
|
}
|
|
2105
2105
|
|
|
2106
2106
|
.nice-report-ai__preview {
|
|
2107
|
-
padding: 20px;
|
|
2107
|
+
padding: var(--nice-space-5, 20px);
|
|
2108
2108
|
background: white;
|
|
2109
|
-
border-radius: 8px;
|
|
2109
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2110
2110
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2111
|
-
margin-bottom: 16px;
|
|
2111
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2112
2112
|
overflow-x: auto;
|
|
2113
2113
|
}
|
|
2114
2114
|
|
|
2115
2115
|
.nice-report-ai__suggestions {
|
|
2116
|
-
margin-bottom: 16px;
|
|
2117
|
-
padding: 12px;
|
|
2116
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2117
|
+
padding: var(--nice-space-3, 12px);
|
|
2118
2118
|
background: var(--nice-info-light, #e3f2fd);
|
|
2119
|
-
border-radius: 6px;
|
|
2119
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2120
2120
|
}
|
|
2121
2121
|
|
|
2122
2122
|
.nice-report-ai__suggestions-title {
|
|
2123
2123
|
font-weight: 500;
|
|
2124
|
-
margin-bottom: 8px;
|
|
2124
|
+
margin-bottom: var(--nice-space-2, 8px);
|
|
2125
2125
|
display: block;
|
|
2126
2126
|
}
|
|
2127
2127
|
|
|
2128
2128
|
.nice-report-ai__suggestions ul {
|
|
2129
2129
|
margin: 0;
|
|
2130
|
-
padding-left: 20px;
|
|
2130
|
+
padding-left: var(--nice-space-5, 20px);
|
|
2131
2131
|
font-size: 13px;
|
|
2132
2132
|
}
|
|
2133
2133
|
|
|
2134
2134
|
.nice-report-ai__json {
|
|
2135
|
-
margin-top: 12px;
|
|
2135
|
+
margin-top: var(--nice-space-3, 12px);
|
|
2136
2136
|
}
|
|
2137
2137
|
|
|
2138
2138
|
.nice-report-ai__json summary {
|
|
@@ -2142,49 +2142,49 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
2142
2142
|
}
|
|
2143
2143
|
|
|
2144
2144
|
.nice-report-ai__json pre {
|
|
2145
|
-
margin: 8px 0 0;
|
|
2146
|
-
padding: 12px;
|
|
2145
|
+
margin: var(--nice-space-2, 8px) 0 0;
|
|
2146
|
+
padding: var(--nice-space-3, 12px);
|
|
2147
2147
|
background: var(--nice-code-bg, #1e1e1e);
|
|
2148
2148
|
color: var(--nice-code-color, #d4d4d4);
|
|
2149
|
-
border-radius: 6px;
|
|
2149
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2150
2150
|
font-size: 12px;
|
|
2151
2151
|
overflow-x: auto;
|
|
2152
2152
|
}
|
|
2153
2153
|
|
|
2154
2154
|
.nice-report-ai__error {
|
|
2155
|
-
padding: 12px;
|
|
2155
|
+
padding: var(--nice-space-3, 12px);
|
|
2156
2156
|
background: var(--nice-error-light, #ffebee);
|
|
2157
2157
|
color: var(--nice-error, #c62828);
|
|
2158
|
-
border-radius: 6px;
|
|
2158
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2159
2159
|
}
|
|
2160
|
-
`})]}):e.jsx("div",{className:`nice-report-ai nice-report-ai--disabled ${
|
|
2160
|
+
`})]}):e.jsx("div",{className:`nice-report-ai nice-report-ai--disabled ${c||""}`,style:g,children:e.jsx("p",{children:"AI not configured. Please provide config or wrap in NiceAIProvider."})})}function xa(i){return{header:"📑",summary:"📝",kpi:"📈",table:"📋",chart:"📊",text:"📄",image:"🖼️",divider:"➖",spacer:"⬜",pageBreak:"📃",footer:"📜",toc:"📚",customBlock:"🧩"}[i]||"📄"}function Et({layout:i}){return e.jsxs("div",{className:"report-preview",style:{aspectRatio:i.orientation==="landscape"?"1.414":"0.707",maxWidth:i.orientation==="landscape"?"100%":"60%"},children:[e.jsx("div",{className:"report-preview__paper",children:i.sections.map(a=>e.jsxs("div",{className:`report-preview__section report-preview__section--${a.type}`,children:[e.jsx("span",{className:"report-preview__section-icon",children:xa(a.type)}),e.jsx("span",{className:"report-preview__section-label",children:a.title||a.type})]},a.id))}),e.jsx("style",{children:`
|
|
2161
2161
|
.report-preview {
|
|
2162
2162
|
display: flex;
|
|
2163
2163
|
justify-content: center;
|
|
2164
|
-
padding: 20px;
|
|
2164
|
+
padding: var(--nice-space-5, 20px);
|
|
2165
2165
|
background: var(--nice-bg-subtle, #f0f0f0);
|
|
2166
|
-
border-radius: 8px;
|
|
2166
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2167
2167
|
}
|
|
2168
2168
|
|
|
2169
2169
|
.report-preview__paper {
|
|
2170
2170
|
width: 100%;
|
|
2171
2171
|
max-width: 300px;
|
|
2172
|
-
padding: 20px;
|
|
2172
|
+
padding: var(--nice-space-5, 20px);
|
|
2173
2173
|
background: white;
|
|
2174
2174
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2175
|
-
border-radius: 4px;
|
|
2176
|
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
2175
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
2176
|
+
box-shadow: 0 2px 8px var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
|
|
2177
2177
|
display: flex;
|
|
2178
2178
|
flex-direction: column;
|
|
2179
|
-
gap: 8px;
|
|
2179
|
+
gap: var(--nice-space-2, 8px);
|
|
2180
2180
|
}
|
|
2181
2181
|
|
|
2182
2182
|
.report-preview__section {
|
|
2183
2183
|
display: flex;
|
|
2184
2184
|
align-items: center;
|
|
2185
|
-
gap: 8px;
|
|
2186
|
-
padding: 8px 12px;
|
|
2187
|
-
border-radius: 4px;
|
|
2185
|
+
gap: var(--nice-space-2, 8px);
|
|
2186
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
2187
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
2188
2188
|
font-size: 12px;
|
|
2189
2189
|
}
|
|
2190
2190
|
|
|
@@ -2236,45 +2236,45 @@ Purpose: ${_}`}],temperature:.3,maxTokens:20})).choices[0])==null?void 0:b.messa
|
|
|
2236
2236
|
text-overflow: ellipsis;
|
|
2237
2237
|
white-space: nowrap;
|
|
2238
2238
|
}
|
|
2239
|
-
`})]})}function
|
|
2239
|
+
`})]})}function ba(i={}){const{config:a,generateDarkMode:t=!0,onThemeGenerated:r,onError:n}=i,s=X(),[m,c]=o.useState(!1),[g,f]=o.useState(null),j=o.useRef(null),w=a||(s==null?void 0:s.config),N=o.useCallback(async d=>{var C,p,_,b;if(!w){const u="AI not configured";return n==null||n(u),{error:u}}c(!0);const v=performance.now();(C=j.current)==null||C.abort(),j.current=new AbortController;try{const u=G(w);let y="";switch(d.type){case"description":y=d.value;break;case"brand":y=`Create a theme for "${d.value.name}"${d.value.industry?` in the ${d.value.industry} industry`:""}${(p=d.value.keywords)!=null&&p.length?`. Keywords: ${d.value.keywords.join(", ")}`:""}`;break;case"colors":y=`Create a theme based on primary color ${d.value.primary}${d.value.secondary?` and secondary color ${d.value.secondary}`:""}`;break;case"image":y="Extract colors and create a theme from the provided image palette";break}const A=Z(ue,{description:y,generate_dark_mode:t?"true":"false"}),R=await u.chat({messages:[{role:"system",content:A.system},{role:"user",content:A.user}],temperature:.6,maxTokens:2048}),l=Ee(R),x={theme:l.light||void 0,darkTheme:l.dark||void 0,rawResponse:(b=(_=R.choices[0])==null?void 0:_.message)==null?void 0:b.content,latencyMs:performance.now()-v,error:l.light?void 0:"Failed to generate theme",suggestions:Dt(l.light)};return l.light&&(r==null||r(l.light,l.dark??void 0)),f(x),x}catch(u){const y=u instanceof Error?u.message:"Theme generation failed",A={error:y,latencyMs:performance.now()-v};return f(A),n==null||n(y),A}finally{c(!1)}},[w,t,r,n]),S=o.useCallback(async(d,v)=>{if(!w)return null;c(!0);try{const p=await G(w).chat({messages:[{role:"system",content:"Adjust the theme based on the user's request. Return the complete adjusted theme in JSON format."},{role:"user",content:`Current theme:
|
|
2240
2240
|
${JSON.stringify(d,null,2)}
|
|
2241
2241
|
|
|
2242
|
-
Adjustments: ${
|
|
2243
|
-
/* Typography */`),Object.entries(d.typography).forEach(([C,
|
|
2244
|
-
/* Spacing */`),Object.entries(d.spacing).forEach(([C,
|
|
2245
|
-
/* Border Radius */`),Object.entries(d.borderRadius).forEach(([C,
|
|
2246
|
-
/* Shadows */`),Object.entries(d.shadows).forEach(([C,
|
|
2247
|
-
/* Animations */`),Object.entries(d.animations).forEach(([C,
|
|
2248
|
-
${
|
|
2242
|
+
Adjustments: ${v}`}],temperature:.4,maxTokens:2048});return Ee(p).light||null}catch{return null}finally{c(!1)}},[w]),$=o.useCallback(d=>{const v=[];return v.push(" /* Colors */"),Object.entries(d.colors).forEach(([C,p])=>{v.push(` --nice-${xe(C)}: ${p};`)}),v.push(`
|
|
2243
|
+
/* Typography */`),Object.entries(d.typography).forEach(([C,p])=>{v.push(` --nice-${xe(C)}: ${p};`)}),v.push(`
|
|
2244
|
+
/* Spacing */`),Object.entries(d.spacing).forEach(([C,p])=>{v.push(` --nice-spacing-${C}: ${p};`)}),v.push(`
|
|
2245
|
+
/* Border Radius */`),Object.entries(d.borderRadius).forEach(([C,p])=>{v.push(` --nice-radius-${C}: ${p};`)}),v.push(`
|
|
2246
|
+
/* Shadows */`),Object.entries(d.shadows).forEach(([C,p])=>{v.push(` --nice-shadow-${C}: ${p};`)}),v.push(`
|
|
2247
|
+
/* Animations */`),Object.entries(d.animations).forEach(([C,p])=>{v.push(` --nice-${xe(C)}: ${p};`)}),`:root {
|
|
2248
|
+
${v.join(`
|
|
2249
2249
|
`)}
|
|
2250
|
-
}`},[]),k=
|
|
2251
|
-
module.exports = ${JSON.stringify(
|
|
2250
|
+
}`},[]),k=o.useCallback(d=>{const v={theme:{extend:{colors:{primary:{DEFAULT:d.colors.primary,light:d.colors.primaryLight,dark:d.colors.primaryDark},secondary:{DEFAULT:d.colors.secondary,light:d.colors.secondaryLight,dark:d.colors.secondaryDark},accent:d.colors.accent,success:d.colors.success,warning:d.colors.warning,error:d.colors.error,info:d.colors.info},fontFamily:{sans:[d.typography.fontFamily],mono:[d.typography.fontFamilyMono]},borderRadius:d.borderRadius,boxShadow:d.shadows}}};return`// tailwind.config.js
|
|
2251
|
+
module.exports = ${JSON.stringify(v,null,2)}`},[]),P=o.useCallback(()=>{f(null)},[]),h=o.useCallback(()=>{var d;(d=j.current)==null||d.abort(),c(!1)},[]);return o.useEffect(()=>()=>{var d;(d=j.current)==null||d.abort()},[]),{generateTheme:N,adjustTheme:S,toCSSVariables:$,toTailwindConfig:k,loading:m,lastResult:g,clearResults:P,abort:h,isConfigured:!!w}}function Ee(i){var a,t,r;try{const n=((t=(a=i.choices[0])==null?void 0:a.message)==null?void 0:t.content)||"",m=((r=(n.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,n])[1])==null?void 0:r.trim())||n,c=JSON.parse(m);if(c.light||c.theme)return{light:fe(c.light||c.theme),dark:c.dark?fe(c.dark):null};if(c.colors)return{light:fe(c),dark:null}}catch{}return{light:null,dark:null}}function fe(i){return{id:i.id||`theme_${Date.now()}`,name:i.name||"Generated Theme",description:i.description,mode:i.mode||"light",colors:{primary:"var(--nice-primary, #0066cc)",primaryLight:"#4d94db",primaryDark:"#004499",secondary:"var(--nice-text-secondary, #6c757d)",secondaryLight:"var(--nice-text-muted, #9ca3af)",secondaryDark:"var(--nice-text-secondary, #4b5563)",accent:"#ff6b35",background:"var(--nice-bg, #fff)",surface:"var(--nice-bg-secondary, #f8f9fa)",text:"var(--nice-text, #212529)",textMuted:"var(--nice-text-secondary, #6c757d)",textInverse:"var(--nice-bg, #fff)",border:"var(--nice-border, #dee2e6)",success:"var(--nice-success, #28a745)",warning:"var(--nice-warning, #ffc107)",error:"var(--nice-danger, #dc3545)",info:"var(--nice-info, #17a2b8)",...i.colors},typography:{fontFamily:"system-ui, -apple-system, sans-serif",fontFamilyMono:"ui-monospace, monospace",fontSizeBase:"16px",fontSizeXs:"12px",fontSizeSm:"14px",fontSizeMd:"16px",fontSizeLg:"18px",fontSizeXl:"20px",fontSize2xl:"24px",fontSize3xl:"30px",fontWeightLight:300,fontWeightNormal:400,fontWeightMedium:500,fontWeightSemibold:600,fontWeightBold:700,lineHeightTight:1.25,lineHeightNormal:1.5,lineHeightRelaxed:1.75,letterSpacing:"normal",...i.typography},spacing:{xs:"4px",sm:"8px",md:"16px",lg:"24px",xl:"32px","2xl":"48px","3xl":"64px","4xl":"80px",...i.spacing},borderRadius:{none:"0",sm:"4px",md:"8px",lg:"12px",xl:"16px",full:"9999px",...i.borderRadius},shadows:{none:"none",sm:"0 1px 2px var(--nice-overlay-5, rgba(0, 0, 0, 0.05))",md:"0 4px 6px var(--nice-overlay-10, rgba(0, 0, 0, 0.1))",lg:"0 10px 15px var(--nice-overlay-10, rgba(0, 0, 0, 0.1))",xl:"0 20px 25px var(--nice-overlay-10, rgba(0, 0, 0, 0.1))",...i.shadows},animations:{durationFast:"150ms",durationNormal:"300ms",durationSlow:"500ms",easeIn:"cubic-bezier(0.4, 0, 1, 1)",easeOut:"cubic-bezier(0, 0, 0.2, 1)",easeInOut:"cubic-bezier(0.4, 0, 0.2, 1)",...i.animations},components:i.components,cssVariables:i.cssVariables}}function Dt(i){if(!i)return[];const a=[];return a.push("Verify WCAG contrast ratios for text on background"),a.push("Test the theme in both light and dark environments"),a.push("Ensure button and input styles are consistent"),a.slice(0,3)}function xe(i){return i.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}const Bt=[{icon:"🏢",name:"Corporate",prompt:"Professional corporate theme with blue and gray tones"},{icon:"🎨",name:"Creative",prompt:"Vibrant creative agency theme with bold colors"},{icon:"🌿",name:"Natural",prompt:"Organic natural theme with earth tones and greens"},{icon:"🌙",name:"Dark Pro",prompt:"Modern dark theme for developer tools"},{icon:"🍬",name:"Playful",prompt:"Fun playful theme with candy colors for kids"},{icon:"💎",name:"Luxury",prompt:"Elegant luxury brand theme with gold accents"}];function Ft({config:i,generateDarkMode:a=!0,onGenerate:t,showPresets:r=!0,showPreview:n=!0,className:s,style:m}){const[c,g]=o.useState("description"),[f,j]=o.useState(""),[w,N]=o.useState(""),[S,$]=o.useState(""),[k,P]=o.useState("var(--nice-primary, #0066cc)"),[h,d]=o.useState("light"),{generateTheme:v,toCSSVariables:C,toTailwindConfig:p,loading:_,lastResult:b,isConfigured:u}=ba({config:i,generateDarkMode:a,onThemeGenerated:t}),y=async()=>{if(_)return;let M;switch(c){case"brand":if(!w.trim())return;M={type:"brand",value:{name:w,industry:S||void 0}};break;case"colors":M={type:"colors",value:{primary:k}};break;default:if(!f.trim())return;M={type:"description",value:f}}await v(M)},A=M=>{g("description"),j(M.prompt)},R=()=>{if(!(b!=null&&b.theme))return;const M=C(b.theme),z=new Blob([M],{type:"text/css"}),D=URL.createObjectURL(z),J=document.createElement("a");J.href=D,J.download=`${b.theme.name.replace(/\s+/g,"-").toLowerCase()}.css`,J.click(),URL.revokeObjectURL(D)},l=()=>{if(!(b!=null&&b.theme))return;const M=p(b.theme),z=new Blob([M],{type:"text/javascript"}),D=URL.createObjectURL(z),J=document.createElement("a");J.href=D,J.download="tailwind.config.js",J.click(),URL.revokeObjectURL(D)},x=h==="dark"&&(b!=null&&b.darkTheme)?b.darkTheme:b==null?void 0:b.theme;return u?e.jsxs("div",{className:`nice-theme-ai ${s||""}`,style:m,children:[r&&e.jsx("div",{className:"nice-theme-ai__presets",children:Bt.map((M,z)=>e.jsxs("button",{type:"button",className:"nice-theme-ai__preset",onClick:()=>A(M),children:[e.jsx("span",{className:"nice-theme-ai__preset-icon",children:M.icon}),e.jsx("span",{className:"nice-theme-ai__preset-name",children:M.name})]},z))}),e.jsxs("div",{className:"nice-theme-ai__tabs",children:[e.jsx("button",{type:"button",className:`nice-theme-ai__tab ${c==="description"?"nice-theme-ai__tab--active":""}`,onClick:()=>g("description"),children:"📝 Description"}),e.jsx("button",{type:"button",className:`nice-theme-ai__tab ${c==="brand"?"nice-theme-ai__tab--active":""}`,onClick:()=>g("brand"),children:"🏷️ Brand"}),e.jsx("button",{type:"button",className:`nice-theme-ai__tab ${c==="colors"?"nice-theme-ai__tab--active":""}`,onClick:()=>g("colors"),children:"🎨 Colors"})]}),e.jsxs("div",{className:"nice-theme-ai__input-section",children:[c==="description"&&e.jsx("textarea",{value:f,onChange:M=>j(M.target.value),placeholder:"Describe the theme you want... (e.g., 'Modern tech startup with blue and green')",className:"nice-theme-ai__textarea",rows:3,disabled:_}),c==="brand"&&e.jsxs("div",{className:"nice-theme-ai__brand-inputs",children:[e.jsx("input",{type:"text",value:w,onChange:M=>N(M.target.value),placeholder:"Brand name",className:"nice-theme-ai__input",disabled:_}),e.jsx("input",{type:"text",value:S,onChange:M=>$(M.target.value),placeholder:"Industry (optional)",className:"nice-theme-ai__input",disabled:_})]}),c==="colors"&&e.jsx("div",{className:"nice-theme-ai__color-input",children:e.jsxs("label",{children:["Primary Color:",e.jsx("input",{type:"color",value:k,onChange:M=>P(M.target.value),className:"nice-theme-ai__color-picker",disabled:_}),e.jsx("span",{className:"nice-theme-ai__color-value",children:k})]})}),e.jsx("button",{type:"button",onClick:y,className:"nice-theme-ai__submit",disabled:_,children:_?e.jsx("span",{className:"nice-theme-ai__spinner"}):"✨ Generate Theme"})]}),b&&x&&e.jsxs("div",{className:"nice-theme-ai__result",children:[e.jsxs("div",{className:"nice-theme-ai__result-header",children:[e.jsxs("div",{className:"nice-theme-ai__theme-info",children:[e.jsx("span",{className:"nice-theme-ai__theme-name",children:x.name}),x.description&&e.jsx("span",{className:"nice-theme-ai__theme-desc",children:x.description})]}),e.jsxs("div",{className:"nice-theme-ai__actions",children:[b.darkTheme&&e.jsxs("div",{className:"nice-theme-ai__mode-toggle",children:[e.jsx("button",{type:"button",className:h==="light"?"active":"",onClick:()=>d("light"),children:"☀️"}),e.jsx("button",{type:"button",className:h==="dark"?"active":"",onClick:()=>d("dark"),children:"🌙"})]}),e.jsx("button",{type:"button",onClick:R,children:"📥 CSS"}),e.jsx("button",{type:"button",onClick:l,children:"📥 Tailwind"})]})]}),n&&e.jsx(Jt,{theme:x}),e.jsxs("div",{className:"nice-theme-ai__palette",children:[e.jsx("div",{className:"nice-theme-ai__palette-title",children:"Color Palette"}),e.jsx("div",{className:"nice-theme-ai__colors",children:Object.entries(x.colors).map(([M,z])=>e.jsxs("div",{className:"nice-theme-ai__color",children:[e.jsx("div",{className:"nice-theme-ai__color-swatch",style:{backgroundColor:z}}),e.jsx("span",{className:"nice-theme-ai__color-name",children:M}),e.jsx("span",{className:"nice-theme-ai__color-hex",children:z})]},M))})]}),e.jsxs("div",{className:"nice-theme-ai__typography",children:[e.jsx("div",{className:"nice-theme-ai__typography-title",children:"Typography"}),e.jsxs("div",{style:{fontFamily:x.typography.fontFamily},children:[e.jsx("p",{style:{fontSize:x.typography.fontSize3xl,fontWeight:x.typography.fontWeightBold},children:"Heading 1"}),e.jsx("p",{style:{fontSize:x.typography.fontSizeLg},children:"Body text: The quick brown fox jumps over the lazy dog."}),e.jsx("p",{style:{fontFamily:x.typography.fontFamilyMono,fontSize:x.typography.fontSizeSm},children:'const code = "Monospace font"'})]})]})]}),e.jsx("style",{children:`
|
|
2252
2252
|
.nice-theme-ai {
|
|
2253
2253
|
font-family: var(--nice-font-family, system-ui, sans-serif);
|
|
2254
2254
|
}
|
|
2255
2255
|
|
|
2256
2256
|
.nice-theme-ai--disabled {
|
|
2257
|
-
padding: 20px;
|
|
2257
|
+
padding: var(--nice-space-5, 20px);
|
|
2258
2258
|
background: var(--nice-disabled-bg, #f5f5f5);
|
|
2259
|
-
border-radius: 8px;
|
|
2259
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2260
2260
|
color: var(--nice-text-muted, #666);
|
|
2261
2261
|
}
|
|
2262
2262
|
|
|
2263
2263
|
.nice-theme-ai__presets {
|
|
2264
2264
|
display: flex;
|
|
2265
2265
|
flex-wrap: wrap;
|
|
2266
|
-
gap: 8px;
|
|
2267
|
-
margin-bottom: 16px;
|
|
2266
|
+
gap: var(--nice-space-2, 8px);
|
|
2267
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2268
2268
|
}
|
|
2269
2269
|
|
|
2270
2270
|
.nice-theme-ai__preset {
|
|
2271
2271
|
display: flex;
|
|
2272
2272
|
flex-direction: column;
|
|
2273
2273
|
align-items: center;
|
|
2274
|
-
gap: 4px;
|
|
2275
|
-
padding: 12px 16px;
|
|
2274
|
+
gap: var(--nice-space-1, 4px);
|
|
2275
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-4, 16px);
|
|
2276
2276
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2277
|
-
border-radius: 8px;
|
|
2277
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2278
2278
|
background: white;
|
|
2279
2279
|
cursor: pointer;
|
|
2280
2280
|
transition: all 0.2s;
|
|
@@ -2297,15 +2297,15 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2297
2297
|
|
|
2298
2298
|
.nice-theme-ai__tabs {
|
|
2299
2299
|
display: flex;
|
|
2300
|
-
gap: 4px;
|
|
2301
|
-
margin-bottom: 12px;
|
|
2300
|
+
gap: var(--nice-space-1, 4px);
|
|
2301
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
2302
2302
|
}
|
|
2303
2303
|
|
|
2304
2304
|
.nice-theme-ai__tab {
|
|
2305
|
-
padding: 8px 16px;
|
|
2305
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-4, 16px);
|
|
2306
2306
|
border: none;
|
|
2307
2307
|
background: var(--nice-bg-subtle, #f5f5f5);
|
|
2308
|
-
border-radius: 6px;
|
|
2308
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2309
2309
|
font-size: 13px;
|
|
2310
2310
|
cursor: pointer;
|
|
2311
2311
|
transition: all 0.2s;
|
|
@@ -2323,15 +2323,15 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2323
2323
|
.nice-theme-ai__input-section {
|
|
2324
2324
|
display: flex;
|
|
2325
2325
|
flex-direction: column;
|
|
2326
|
-
gap: 12px;
|
|
2327
|
-
margin-bottom: 16px;
|
|
2326
|
+
gap: var(--nice-space-3, 12px);
|
|
2327
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2328
2328
|
}
|
|
2329
2329
|
|
|
2330
2330
|
.nice-theme-ai__textarea,
|
|
2331
2331
|
.nice-theme-ai__input {
|
|
2332
|
-
padding: 12px;
|
|
2332
|
+
padding: var(--nice-space-3, 12px);
|
|
2333
2333
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2334
|
-
border-radius: 8px;
|
|
2334
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2335
2335
|
font-size: 14px;
|
|
2336
2336
|
}
|
|
2337
2337
|
|
|
@@ -2343,7 +2343,7 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2343
2343
|
|
|
2344
2344
|
.nice-theme-ai__brand-inputs {
|
|
2345
2345
|
display: flex;
|
|
2346
|
-
gap: 12px;
|
|
2346
|
+
gap: var(--nice-space-3, 12px);
|
|
2347
2347
|
}
|
|
2348
2348
|
|
|
2349
2349
|
.nice-theme-ai__brand-inputs .nice-theme-ai__input {
|
|
@@ -2353,13 +2353,13 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2353
2353
|
.nice-theme-ai__color-input {
|
|
2354
2354
|
display: flex;
|
|
2355
2355
|
align-items: center;
|
|
2356
|
-
gap: 12px;
|
|
2356
|
+
gap: var(--nice-space-3, 12px);
|
|
2357
2357
|
}
|
|
2358
2358
|
|
|
2359
2359
|
.nice-theme-ai__color-input label {
|
|
2360
2360
|
display: flex;
|
|
2361
2361
|
align-items: center;
|
|
2362
|
-
gap: 8px;
|
|
2362
|
+
gap: var(--nice-space-2, 8px);
|
|
2363
2363
|
}
|
|
2364
2364
|
|
|
2365
2365
|
.nice-theme-ai__color-picker {
|
|
@@ -2367,7 +2367,7 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2367
2367
|
height: 32px;
|
|
2368
2368
|
padding: 0;
|
|
2369
2369
|
border: none;
|
|
2370
|
-
border-radius: 4px;
|
|
2370
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
2371
2371
|
cursor: pointer;
|
|
2372
2372
|
}
|
|
2373
2373
|
|
|
@@ -2378,11 +2378,11 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2378
2378
|
}
|
|
2379
2379
|
|
|
2380
2380
|
.nice-theme-ai__submit {
|
|
2381
|
-
padding: 12px 24px;
|
|
2381
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-6, 24px);
|
|
2382
2382
|
background: var(--nice-primary, #0066cc);
|
|
2383
2383
|
color: white;
|
|
2384
2384
|
border: none;
|
|
2385
|
-
border-radius: 8px;
|
|
2385
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2386
2386
|
font-weight: 500;
|
|
2387
2387
|
cursor: pointer;
|
|
2388
2388
|
align-self: flex-start;
|
|
@@ -2400,9 +2400,9 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2400
2400
|
display: inline-block;
|
|
2401
2401
|
width: 16px;
|
|
2402
2402
|
height: 16px;
|
|
2403
|
-
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
2403
|
+
border: 2px solid var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3));
|
|
2404
2404
|
border-top-color: white;
|
|
2405
|
-
border-radius: 50
|
|
2405
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
2406
2406
|
animation: nice-spin 0.8s linear infinite;
|
|
2407
2407
|
}
|
|
2408
2408
|
|
|
@@ -2411,9 +2411,9 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2411
2411
|
}
|
|
2412
2412
|
|
|
2413
2413
|
.nice-theme-ai__result {
|
|
2414
|
-
padding: 20px;
|
|
2414
|
+
padding: var(--nice-space-5, 20px);
|
|
2415
2415
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
2416
|
-
border-radius: 8px;
|
|
2416
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2417
2417
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2418
2418
|
}
|
|
2419
2419
|
|
|
@@ -2421,13 +2421,13 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2421
2421
|
display: flex;
|
|
2422
2422
|
justify-content: space-between;
|
|
2423
2423
|
align-items: center;
|
|
2424
|
-
margin-bottom: 16px;
|
|
2424
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2425
2425
|
}
|
|
2426
2426
|
|
|
2427
2427
|
.nice-theme-ai__theme-info {
|
|
2428
2428
|
display: flex;
|
|
2429
2429
|
flex-direction: column;
|
|
2430
|
-
gap: 4px;
|
|
2430
|
+
gap: var(--nice-space-1, 4px);
|
|
2431
2431
|
}
|
|
2432
2432
|
|
|
2433
2433
|
.nice-theme-ai__theme-name {
|
|
@@ -2442,13 +2442,13 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2442
2442
|
|
|
2443
2443
|
.nice-theme-ai__actions {
|
|
2444
2444
|
display: flex;
|
|
2445
|
-
gap: 8px;
|
|
2445
|
+
gap: var(--nice-space-2, 8px);
|
|
2446
2446
|
}
|
|
2447
2447
|
|
|
2448
2448
|
.nice-theme-ai__actions button {
|
|
2449
|
-
padding: 6px 12px;
|
|
2449
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-3, 12px);
|
|
2450
2450
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2451
|
-
border-radius: 6px;
|
|
2451
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2452
2452
|
background: white;
|
|
2453
2453
|
font-size: 12px;
|
|
2454
2454
|
cursor: pointer;
|
|
@@ -2460,7 +2460,7 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2460
2460
|
|
|
2461
2461
|
.nice-theme-ai__mode-toggle {
|
|
2462
2462
|
display: flex;
|
|
2463
|
-
border-radius: 6px;
|
|
2463
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2464
2464
|
overflow: hidden;
|
|
2465
2465
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2466
2466
|
}
|
|
@@ -2468,7 +2468,7 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2468
2468
|
.nice-theme-ai__mode-toggle button {
|
|
2469
2469
|
border: none;
|
|
2470
2470
|
border-radius: 0;
|
|
2471
|
-
padding: 6px 10px;
|
|
2471
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-2-5, 10px);
|
|
2472
2472
|
}
|
|
2473
2473
|
|
|
2474
2474
|
.nice-theme-ai__mode-toggle button.active {
|
|
@@ -2477,32 +2477,32 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2477
2477
|
}
|
|
2478
2478
|
|
|
2479
2479
|
.nice-theme-ai__palette {
|
|
2480
|
-
margin-top: 20px;
|
|
2480
|
+
margin-top: var(--nice-space-5, 20px);
|
|
2481
2481
|
}
|
|
2482
2482
|
|
|
2483
2483
|
.nice-theme-ai__palette-title,
|
|
2484
2484
|
.nice-theme-ai__typography-title {
|
|
2485
2485
|
font-weight: 600;
|
|
2486
|
-
margin-bottom: 12px;
|
|
2486
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
2487
2487
|
}
|
|
2488
2488
|
|
|
2489
2489
|
.nice-theme-ai__colors {
|
|
2490
2490
|
display: grid;
|
|
2491
2491
|
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
|
|
2492
|
-
gap: 12px;
|
|
2492
|
+
gap: var(--nice-space-3, 12px);
|
|
2493
2493
|
}
|
|
2494
2494
|
|
|
2495
2495
|
.nice-theme-ai__color {
|
|
2496
2496
|
display: flex;
|
|
2497
2497
|
flex-direction: column;
|
|
2498
|
-
gap: 4px;
|
|
2498
|
+
gap: var(--nice-space-1, 4px);
|
|
2499
2499
|
}
|
|
2500
2500
|
|
|
2501
2501
|
.nice-theme-ai__color-swatch {
|
|
2502
2502
|
width: 100%;
|
|
2503
2503
|
height: 40px;
|
|
2504
|
-
border-radius: 6px;
|
|
2505
|
-
border: 1px solid rgba(0, 0, 0, 0.1);
|
|
2504
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2505
|
+
border: 1px solid var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
|
|
2506
2506
|
}
|
|
2507
2507
|
|
|
2508
2508
|
.nice-theme-ai__color-name {
|
|
@@ -2517,40 +2517,40 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2517
2517
|
}
|
|
2518
2518
|
|
|
2519
2519
|
.nice-theme-ai__typography {
|
|
2520
|
-
margin-top: 20px;
|
|
2520
|
+
margin-top: var(--nice-space-5, 20px);
|
|
2521
2521
|
}
|
|
2522
|
-
`})]}):e.jsx("div",{className:`nice-theme-ai nice-theme-ai--disabled ${s||""}`,style:
|
|
2522
|
+
`})]}):e.jsx("div",{className:`nice-theme-ai nice-theme-ai--disabled ${s||""}`,style:m,children:e.jsx("p",{children:"AI not configured. Please provide config or wrap in NiceAIProvider."})})}function Jt({theme:i}){return e.jsxs("div",{className:"theme-preview",style:{"--preview-primary":i.colors.primary,"--preview-bg":i.colors.background,"--preview-surface":i.colors.surface,"--preview-text":i.colors.text,"--preview-border":i.colors.border,"--preview-radius":i.borderRadius.md,fontFamily:i.typography.fontFamily},children:[e.jsxs("div",{className:"theme-preview__header",children:[e.jsx("span",{style:{color:i.colors.primary,fontWeight:i.typography.fontWeightBold},children:i.name}),e.jsxs("div",{className:"theme-preview__dots",children:[e.jsx("span",{style:{background:i.colors.error}}),e.jsx("span",{style:{background:i.colors.warning}}),e.jsx("span",{style:{background:i.colors.success}})]})]}),e.jsxs("div",{className:"theme-preview__content",children:[e.jsx("button",{style:{background:i.colors.primary,color:i.colors.textInverse,borderRadius:i.borderRadius.md,padding:`${i.spacing.sm} ${i.spacing.md}`},children:"Primary Button"}),e.jsx("button",{style:{background:i.colors.secondary,color:i.colors.textInverse,borderRadius:i.borderRadius.md,padding:`${i.spacing.sm} ${i.spacing.md}`},children:"Secondary"}),e.jsx("input",{type:"text",placeholder:"Input field",readOnly:!0,style:{border:`1px solid ${i.colors.border}`,borderRadius:i.borderRadius.md,padding:i.spacing.sm,background:i.colors.surface}})]}),e.jsx("style",{children:`
|
|
2523
2523
|
.theme-preview {
|
|
2524
2524
|
background: var(--preview-bg);
|
|
2525
2525
|
border: 1px solid var(--preview-border);
|
|
2526
2526
|
border-radius: var(--preview-radius);
|
|
2527
|
-
padding: 16px;
|
|
2528
|
-
margin-bottom: 16px;
|
|
2527
|
+
padding: var(--nice-space-4, 16px);
|
|
2528
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2529
2529
|
}
|
|
2530
2530
|
|
|
2531
2531
|
.theme-preview__header {
|
|
2532
2532
|
display: flex;
|
|
2533
2533
|
justify-content: space-between;
|
|
2534
2534
|
align-items: center;
|
|
2535
|
-
margin-bottom: 16px;
|
|
2536
|
-
padding-bottom: 12px;
|
|
2535
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2536
|
+
padding-bottom: var(--nice-space-3, 12px);
|
|
2537
2537
|
border-bottom: 1px solid var(--preview-border);
|
|
2538
2538
|
}
|
|
2539
2539
|
|
|
2540
2540
|
.theme-preview__dots {
|
|
2541
2541
|
display: flex;
|
|
2542
|
-
gap: 6px;
|
|
2542
|
+
gap: var(--nice-space-1-5, 6px);
|
|
2543
2543
|
}
|
|
2544
2544
|
|
|
2545
2545
|
.theme-preview__dots span {
|
|
2546
2546
|
width: 12px;
|
|
2547
2547
|
height: 12px;
|
|
2548
|
-
border-radius: 50
|
|
2548
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
2549
2549
|
}
|
|
2550
2550
|
|
|
2551
2551
|
.theme-preview__content {
|
|
2552
2552
|
display: flex;
|
|
2553
|
-
gap: 12px;
|
|
2553
|
+
gap: var(--nice-space-3, 12px);
|
|
2554
2554
|
flex-wrap: wrap;
|
|
2555
2555
|
}
|
|
2556
2556
|
|
|
@@ -2565,7 +2565,7 @@ module.exports = ${JSON.stringify(y,null,2)}`},[]),P=c.useCallback(()=>{f(null)}
|
|
|
2565
2565
|
cursor: text;
|
|
2566
2566
|
width: 150px;
|
|
2567
2567
|
}
|
|
2568
|
-
`})]})}function
|
|
2568
|
+
`})]})}function va(i={}){const{config:a,targetDevice:t="responsive",onLayoutGenerated:r,onError:n}=i,s=X(),[m,c]=o.useState(!1),[g,f]=o.useState(null),j=o.useRef(null),w=a||(s==null?void 0:s.config),N=o.useCallback(async(h,d)=>{var C,p,_;if(!w){const b="AI not configured";return n==null||n(b),{error:b}}c(!0);const v=performance.now();(C=j.current)==null||C.abort(),j.current=new AbortController;try{const b=G(w),u=`You are a UI layout expert. Generate a responsive layout based on the description.
|
|
2569
2569
|
Return JSON with this structure:
|
|
2570
2570
|
{
|
|
2571
2571
|
"id": "unique_id",
|
|
@@ -2600,9 +2600,9 @@ Return JSON with this structure:
|
|
|
2600
2600
|
"xl": "1280px",
|
|
2601
2601
|
"2xl": "1536px"
|
|
2602
2602
|
}
|
|
2603
|
-
}`,
|
|
2603
|
+
}`,y=await b.chat({messages:[{role:"system",content:u},{role:"user",content:`Create a ${t} layout: ${h}${d?` (type: ${d})`:""}`}],temperature:.5,maxTokens:2048}),A=qt(y),R={layout:A||void 0,rawResponse:(_=(p=y.choices[0])==null?void 0:p.message)==null?void 0:_.content,latencyMs:performance.now()-v,error:A?void 0:"Failed to generate layout",suggestions:Ut(A)};return A&&(r==null||r(A)),f(R),R}catch(b){const u=b instanceof Error?b.message:"Layout generation failed",y={error:u,latencyMs:performance.now()-v};return f(y),n==null||n(u),y}finally{c(!1)}},[w,t,r,n]),S=o.useCallback(h=>{let d=`.${h.id} {
|
|
2604
2604
|
`;if(d+=` display: ${h.container.direction==="grid"?"grid":"flex"};
|
|
2605
|
-
`,h.container.direction==="grid"){if(h.container.gridColumns){const
|
|
2605
|
+
`,h.container.direction==="grid"){if(h.container.gridColumns){const v=typeof h.container.gridColumns=="number"?`repeat(${h.container.gridColumns}, 1fr)`:h.container.gridColumns;d+=` grid-template-columns: ${v};
|
|
2606
2606
|
`}h.container.gridRows&&(d+=` grid-template-rows: ${h.container.gridRows};
|
|
2607
2607
|
`)}else d+=` flex-direction: ${h.container.direction};
|
|
2608
2608
|
`,h.container.wrap&&(d+=` flex-wrap: wrap;
|
|
@@ -2612,59 +2612,59 @@ Return JSON with this structure:
|
|
|
2612
2612
|
`),h.container.justify&&(d+=` justify-content: ${{start:"flex-start",end:"flex-end",center:"center",between:"space-between",around:"space-around",evenly:"space-evenly"}[h.container.justify]||h.container.justify};
|
|
2613
2613
|
`),d+=`}
|
|
2614
2614
|
|
|
2615
|
-
`,h.regions.forEach(
|
|
2616
|
-
`,(C=
|
|
2617
|
-
`),(
|
|
2618
|
-
`),(_=
|
|
2619
|
-
`),(b=
|
|
2620
|
-
`),(u=
|
|
2621
|
-
`),(v
|
|
2615
|
+
`,h.regions.forEach(v=>{var C,p,_,b,u,y;d+=`.${h.id}__${v.id} {
|
|
2616
|
+
`,(C=v.position)!=null&&C.gridColumn&&(d+=` grid-column: ${v.position.gridColumn};
|
|
2617
|
+
`),(p=v.position)!=null&&p.gridRow&&(d+=` grid-row: ${v.position.gridRow};
|
|
2618
|
+
`),(_=v.size)!=null&&_.width&&(d+=` width: ${v.size.width};
|
|
2619
|
+
`),(b=v.size)!=null&&b.height&&(d+=` height: ${v.size.height};
|
|
2620
|
+
`),(u=v.size)!=null&&u.minWidth&&(d+=` min-width: ${v.size.minWidth};
|
|
2621
|
+
`),(y=v.size)!=null&&y.maxWidth&&(d+=` max-width: ${v.size.maxWidth};
|
|
2622
2622
|
`),d+=`}
|
|
2623
2623
|
|
|
2624
|
-
`}),h.breakpoints&&Object.entries(h.breakpoints).forEach(([
|
|
2625
|
-
`,
|
|
2624
|
+
`}),h.breakpoints&&Object.entries(h.breakpoints).forEach(([v,C])=>{const p=h.regions.filter(_=>{var b;return(b=_.responsive)==null?void 0:b[v]});p.length>0&&(d+=`@media (max-width: ${C}) {
|
|
2625
|
+
`,p.forEach(_=>{var u,y;const b=_.responsive[v];d+=` .${h.id}__${_.id} {
|
|
2626
2626
|
`,(u=b.size)!=null&&u.width&&(d+=` width: ${b.size.width};
|
|
2627
|
-
`),(
|
|
2627
|
+
`),(y=b.size)!=null&&y.height&&(d+=` height: ${b.size.height};
|
|
2628
2628
|
`),d+=` }
|
|
2629
2629
|
`}),d+=`}
|
|
2630
2630
|
|
|
2631
|
-
`)}),d},[]),$=
|
|
2631
|
+
`)}),d},[]),$=o.useCallback(h=>{const d=h.regions.map(v=>` <div className="${h.id}__${v.id}">{/* ${v.type} */}</div>`).join(`
|
|
2632
2632
|
`);return`import React from 'react';
|
|
2633
2633
|
import './${h.id}.css';
|
|
2634
2634
|
|
|
2635
|
-
export function ${
|
|
2635
|
+
export function ${ya(h.name)}() {
|
|
2636
2636
|
return (
|
|
2637
2637
|
<div className="${h.id}">
|
|
2638
2638
|
${d}
|
|
2639
2639
|
</div>
|
|
2640
2640
|
);
|
|
2641
|
-
}`},[]),k=
|
|
2641
|
+
}`},[]),k=o.useCallback(()=>{f(null)},[]),P=o.useCallback(()=>{var h;(h=j.current)==null||h.abort(),c(!1)},[]);return o.useEffect(()=>()=>{var h;(h=j.current)==null||h.abort()},[]),{generateLayout:N,toCSS:S,toReactComponent:$,loading:m,lastResult:g,clearResults:k,abort:P,isConfigured:!!w}}function qt(i){var a,t,r;try{const n=((t=(a=i.choices[0])==null?void 0:a.message)==null?void 0:t.content)||"",m=((r=(n.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,n])[1])==null?void 0:r.trim())||n,c=JSON.parse(m);if(c.regions||c.container)return{id:c.id||`layout_${Date.now()}`,name:c.name||"Generated Layout",description:c.description,type:c.type||"dashboard",container:{direction:"grid",gap:"16px",padding:"20px",gridColumns:12,...c.container},regions:c.regions||[],breakpoints:c.breakpoints||{xs:"320px",sm:"640px",md:"768px",lg:"1024px",xl:"1280px","2xl":"1536px"},cssGrid:c.cssGrid,cssVariables:c.cssVariables}}catch{}return null}function Ut(i){if(!i)return[];const a=[],t=new Set(i.regions.map(r=>r.type));return t.has("header")||a.push("Consider adding a header region for navigation"),!t.has("sidebar")&&i.type==="dashboard"&&a.push("Add a sidebar for dashboard navigation"),i.regions.some(r=>!r.responsive)&&a.push("Add responsive breakpoints for mobile compatibility"),a.slice(0,3)}function ya(i){return i.replace(/[^a-zA-Z0-9]+(.)/g,(a,t)=>t.toUpperCase()).replace(/^./,a=>a.toUpperCase())}const Ht=[{type:"dashboard",icon:"📊",label:"Dashboard"},{type:"form",icon:"📝",label:"Form"},{type:"list",icon:"📋",label:"List"},{type:"detail",icon:"📄",label:"Detail"},{type:"landing",icon:"🏠",label:"Landing"},{type:"settings",icon:"⚙️",label:"Settings"},{type:"wizard",icon:"🧙",label:"Wizard"},{type:"split",icon:"↔️",label:"Split"},{type:"grid",icon:"⊞",label:"Grid"},{type:"kanban",icon:"📌",label:"Kanban"}];function Wt({config:i,targetDevice:a="responsive",onGenerate:t,showTypeSelector:r=!0,showPreview:n=!0,className:s,style:m,renderLayout:c}){const[g,f]=o.useState(""),[j,w]=o.useState(null),{generateLayout:N,toCSS:S,toReactComponent:$,loading:k,lastResult:P,isConfigured:h}=va({config:i,targetDevice:a,onLayoutGenerated:t}),d=async()=>{!g.trim()||k||await N(g,j||void 0)},v=()=>{if(!(P!=null&&P.layout))return;const p=S(P.layout),_=new Blob([p],{type:"text/css"}),b=URL.createObjectURL(_),u=document.createElement("a");u.href=b,u.download=`${P.layout.id}.css`,u.click(),URL.revokeObjectURL(b)},C=()=>{if(!(P!=null&&P.layout))return;const p=$(P.layout),_=new Blob([p],{type:"text/javascript"}),b=URL.createObjectURL(_),u=document.createElement("a");u.href=b,u.download=`${ya(P.layout.name)}.tsx`,u.click(),URL.revokeObjectURL(b)};return h?e.jsxs("div",{className:`nice-layout-ai ${s||""}`,style:m,children:[r&&e.jsx("div",{className:"nice-layout-ai__types",children:Ht.map(({type:p,icon:_,label:b})=>e.jsxs("button",{type:"button",className:`nice-layout-ai__type ${j===p?"nice-layout-ai__type--selected":""}`,onClick:()=>w(j===p?null:p),children:[e.jsx("span",{className:"nice-layout-ai__type-icon",children:_}),e.jsx("span",{className:"nice-layout-ai__type-label",children:b})]},p))}),e.jsxs("div",{className:"nice-layout-ai__input-section",children:[e.jsx("textarea",{value:g,onChange:p=>f(p.target.value),placeholder:"Describe the layout you need... (e.g., 'Admin dashboard with sidebar navigation and header')",className:"nice-layout-ai__input",rows:3,disabled:k}),e.jsx("button",{type:"button",onClick:d,className:"nice-layout-ai__submit",disabled:k||!g.trim(),children:k?e.jsx("span",{className:"nice-layout-ai__spinner"}):"🎨 Generate Layout"})]}),P&&P.layout&&e.jsxs("div",{className:"nice-layout-ai__result",children:[e.jsxs("div",{className:"nice-layout-ai__result-header",children:[e.jsxs("div",{className:"nice-layout-ai__layout-info",children:[e.jsx("span",{className:"nice-layout-ai__layout-name",children:P.layout.name}),e.jsx("span",{className:"nice-layout-ai__layout-type",children:P.layout.type})]}),e.jsxs("div",{className:"nice-layout-ai__actions",children:[e.jsx("button",{type:"button",onClick:()=>t==null?void 0:t(P.layout),children:"✅ Use Layout"}),e.jsx("button",{type:"button",onClick:v,children:"📥 CSS"}),e.jsx("button",{type:"button",onClick:C,children:"📥 React"})]})]}),e.jsxs("div",{className:"nice-layout-ai__regions",children:[e.jsx("div",{className:"nice-layout-ai__regions-title",children:"Regions:"}),e.jsx("div",{className:"nice-layout-ai__regions-list",children:P.layout.regions.map(p=>e.jsx("span",{className:`nice-layout-ai__region nice-layout-ai__region--${p.type}`,children:p.type},p.id))})]}),n&&e.jsx("div",{className:"nice-layout-ai__preview",children:c?c(P.layout):e.jsx(Gt,{layout:P.layout})}),e.jsxs("details",{className:"nice-layout-ai__json",children:[e.jsx("summary",{children:"View JSON Definition"}),e.jsx("pre",{children:JSON.stringify(P.layout,null,2)})]})]}),e.jsx("style",{children:`
|
|
2642
2642
|
.nice-layout-ai {
|
|
2643
2643
|
font-family: var(--nice-font-family, system-ui, sans-serif);
|
|
2644
2644
|
}
|
|
2645
2645
|
|
|
2646
2646
|
.nice-layout-ai--disabled {
|
|
2647
|
-
padding: 20px;
|
|
2647
|
+
padding: var(--nice-space-5, 20px);
|
|
2648
2648
|
background: var(--nice-disabled-bg, #f5f5f5);
|
|
2649
|
-
border-radius: 8px;
|
|
2649
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2650
2650
|
color: var(--nice-text-muted, #666);
|
|
2651
2651
|
}
|
|
2652
2652
|
|
|
2653
2653
|
.nice-layout-ai__types {
|
|
2654
2654
|
display: flex;
|
|
2655
2655
|
flex-wrap: wrap;
|
|
2656
|
-
gap: 8px;
|
|
2657
|
-
margin-bottom: 16px;
|
|
2656
|
+
gap: var(--nice-space-2, 8px);
|
|
2657
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2658
2658
|
}
|
|
2659
2659
|
|
|
2660
2660
|
.nice-layout-ai__type {
|
|
2661
2661
|
display: flex;
|
|
2662
2662
|
flex-direction: column;
|
|
2663
2663
|
align-items: center;
|
|
2664
|
-
gap: 4px;
|
|
2665
|
-
padding: 8px 12px;
|
|
2664
|
+
gap: var(--nice-space-1, 4px);
|
|
2665
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-3, 12px);
|
|
2666
2666
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2667
|
-
border-radius: 8px;
|
|
2667
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2668
2668
|
background: white;
|
|
2669
2669
|
cursor: pointer;
|
|
2670
2670
|
transition: all 0.2s;
|
|
@@ -2690,15 +2690,15 @@ ${d}
|
|
|
2690
2690
|
|
|
2691
2691
|
.nice-layout-ai__input-section {
|
|
2692
2692
|
display: flex;
|
|
2693
|
-
gap: 12px;
|
|
2694
|
-
margin-bottom: 16px;
|
|
2693
|
+
gap: var(--nice-space-3, 12px);
|
|
2694
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2695
2695
|
}
|
|
2696
2696
|
|
|
2697
2697
|
.nice-layout-ai__input {
|
|
2698
2698
|
flex: 1;
|
|
2699
|
-
padding: 12px;
|
|
2699
|
+
padding: var(--nice-space-3, 12px);
|
|
2700
2700
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2701
|
-
border-radius: 8px;
|
|
2701
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2702
2702
|
font-size: 14px;
|
|
2703
2703
|
resize: vertical;
|
|
2704
2704
|
}
|
|
@@ -2709,11 +2709,11 @@ ${d}
|
|
|
2709
2709
|
}
|
|
2710
2710
|
|
|
2711
2711
|
.nice-layout-ai__submit {
|
|
2712
|
-
padding: 12px 24px;
|
|
2712
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-6, 24px);
|
|
2713
2713
|
background: var(--nice-primary, #0066cc);
|
|
2714
2714
|
color: white;
|
|
2715
2715
|
border: none;
|
|
2716
|
-
border-radius: 8px;
|
|
2716
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2717
2717
|
font-weight: 500;
|
|
2718
2718
|
cursor: pointer;
|
|
2719
2719
|
white-space: nowrap;
|
|
@@ -2727,9 +2727,9 @@ ${d}
|
|
|
2727
2727
|
display: inline-block;
|
|
2728
2728
|
width: 16px;
|
|
2729
2729
|
height: 16px;
|
|
2730
|
-
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
2730
|
+
border: 2px solid var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3));
|
|
2731
2731
|
border-top-color: white;
|
|
2732
|
-
border-radius: 50
|
|
2732
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
2733
2733
|
animation: nice-spin 0.8s linear infinite;
|
|
2734
2734
|
}
|
|
2735
2735
|
|
|
@@ -2738,9 +2738,9 @@ ${d}
|
|
|
2738
2738
|
}
|
|
2739
2739
|
|
|
2740
2740
|
.nice-layout-ai__result {
|
|
2741
|
-
padding: 20px;
|
|
2741
|
+
padding: var(--nice-space-5, 20px);
|
|
2742
2742
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
2743
|
-
border-radius: 8px;
|
|
2743
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2744
2744
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2745
2745
|
}
|
|
2746
2746
|
|
|
@@ -2748,13 +2748,13 @@ ${d}
|
|
|
2748
2748
|
display: flex;
|
|
2749
2749
|
justify-content: space-between;
|
|
2750
2750
|
align-items: center;
|
|
2751
|
-
margin-bottom: 16px;
|
|
2751
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2752
2752
|
}
|
|
2753
2753
|
|
|
2754
2754
|
.nice-layout-ai__layout-info {
|
|
2755
2755
|
display: flex;
|
|
2756
2756
|
align-items: center;
|
|
2757
|
-
gap: 12px;
|
|
2757
|
+
gap: var(--nice-space-3, 12px);
|
|
2758
2758
|
}
|
|
2759
2759
|
|
|
2760
2760
|
.nice-layout-ai__layout-name {
|
|
@@ -2763,22 +2763,22 @@ ${d}
|
|
|
2763
2763
|
}
|
|
2764
2764
|
|
|
2765
2765
|
.nice-layout-ai__layout-type {
|
|
2766
|
-
padding: 4px 10px;
|
|
2766
|
+
padding: var(--nice-space-1, 4px) var(--nice-space-2-5, 10px);
|
|
2767
2767
|
background: var(--nice-primary-light, rgba(0, 102, 204, 0.1));
|
|
2768
|
-
border-radius: 4px;
|
|
2768
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
2769
2769
|
font-size: 12px;
|
|
2770
2770
|
color: var(--nice-primary, #0066cc);
|
|
2771
2771
|
}
|
|
2772
2772
|
|
|
2773
2773
|
.nice-layout-ai__actions {
|
|
2774
2774
|
display: flex;
|
|
2775
|
-
gap: 8px;
|
|
2775
|
+
gap: var(--nice-space-2, 8px);
|
|
2776
2776
|
}
|
|
2777
2777
|
|
|
2778
2778
|
.nice-layout-ai__actions button {
|
|
2779
|
-
padding: 6px 12px;
|
|
2779
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-3, 12px);
|
|
2780
2780
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2781
|
-
border-radius: 6px;
|
|
2781
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2782
2782
|
background: white;
|
|
2783
2783
|
font-size: 12px;
|
|
2784
2784
|
cursor: pointer;
|
|
@@ -2791,23 +2791,23 @@ ${d}
|
|
|
2791
2791
|
}
|
|
2792
2792
|
|
|
2793
2793
|
.nice-layout-ai__regions {
|
|
2794
|
-
margin-bottom: 16px;
|
|
2794
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2795
2795
|
}
|
|
2796
2796
|
|
|
2797
2797
|
.nice-layout-ai__regions-title {
|
|
2798
2798
|
font-weight: 500;
|
|
2799
|
-
margin-bottom: 8px;
|
|
2799
|
+
margin-bottom: var(--nice-space-2, 8px);
|
|
2800
2800
|
}
|
|
2801
2801
|
|
|
2802
2802
|
.nice-layout-ai__regions-list {
|
|
2803
2803
|
display: flex;
|
|
2804
2804
|
flex-wrap: wrap;
|
|
2805
|
-
gap: 8px;
|
|
2805
|
+
gap: var(--nice-space-2, 8px);
|
|
2806
2806
|
}
|
|
2807
2807
|
|
|
2808
2808
|
.nice-layout-ai__region {
|
|
2809
|
-
padding: 6px 12px;
|
|
2810
|
-
border-radius: 6px;
|
|
2809
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-3, 12px);
|
|
2810
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2811
2811
|
font-size: 12px;
|
|
2812
2812
|
font-weight: 500;
|
|
2813
2813
|
}
|
|
@@ -2840,10 +2840,10 @@ ${d}
|
|
|
2840
2840
|
}
|
|
2841
2841
|
|
|
2842
2842
|
.nice-layout-ai__preview {
|
|
2843
|
-
margin-bottom: 16px;
|
|
2844
|
-
padding: 20px;
|
|
2843
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
2844
|
+
padding: var(--nice-space-5, 20px);
|
|
2845
2845
|
background: white;
|
|
2846
|
-
border-radius: 8px;
|
|
2846
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2847
2847
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
2848
2848
|
}
|
|
2849
2849
|
|
|
@@ -2854,15 +2854,15 @@ ${d}
|
|
|
2854
2854
|
}
|
|
2855
2855
|
|
|
2856
2856
|
.nice-layout-ai__json pre {
|
|
2857
|
-
margin: 8px 0 0;
|
|
2858
|
-
padding: 12px;
|
|
2857
|
+
margin: var(--nice-space-2, 8px) 0 0;
|
|
2858
|
+
padding: var(--nice-space-3, 12px);
|
|
2859
2859
|
background: var(--nice-code-bg, #1e1e1e);
|
|
2860
2860
|
color: var(--nice-code-color, #d4d4d4);
|
|
2861
|
-
border-radius: 6px;
|
|
2861
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2862
2862
|
font-size: 12px;
|
|
2863
2863
|
overflow-x: auto;
|
|
2864
2864
|
}
|
|
2865
|
-
`})]}):e.jsx("div",{className:`nice-layout-ai nice-layout-ai--disabled ${s||""}`,style:
|
|
2865
|
+
`})]}):e.jsx("div",{className:`nice-layout-ai nice-layout-ai--disabled ${s||""}`,style:m,children:e.jsx("p",{children:"AI not configured. Please provide config or wrap in NiceAIProvider."})})}function Gt({layout:i}){const a=t=>({header:"var(--nice-primary-bg, #e3f2fd)",sidebar:"var(--nice-success-bg, #e8f5e9)",aside:"var(--nice-success-bg, #e8f5e9)",main:"var(--nice-warning-bg, #fff3e0)",content:"var(--nice-warning-bg, #fff3e0)",footer:"var(--nice-bg-secondary, #f5f5f5)",nav:"var(--nice-accent-bg, #fce4ec)"})[t]||"var(--nice-bg-secondary, #f5f5f5)";return e.jsx("div",{className:"layout-preview",style:{display:i.container.direction==="grid"?"grid":"flex",flexDirection:i.container.direction==="column"?"column":"row",gridTemplateColumns:i.container.direction==="grid"&&i.container.gridColumns?typeof i.container.gridColumns=="number"?`repeat(${i.container.gridColumns}, 1fr)`:i.container.gridColumns:void 0,gap:i.container.gap||"8px",minHeight:"300px"},children:i.regions.map(t=>{var r,n,s,m,c,g;return e.jsx("div",{className:"layout-preview__region",style:{gridColumn:(r=t.position)==null?void 0:r.gridColumn,gridRow:(n=t.position)==null?void 0:n.gridRow,width:(s=t.size)==null?void 0:s.width,height:((m=t.size)==null?void 0:m.height)||"80px",minWidth:(c=t.size)==null?void 0:c.minWidth,maxWidth:(g=t.size)==null?void 0:g.maxWidth,background:a(t.type),borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"12px",fontWeight:500,color:"var(--nice-text-secondary, #666)",border:"1px dashed var(--nice-border, #ccc)"},children:t.type},t.id)})})}function _a(i={}){const{config:a,wcagLevel:t="AA",onAuditComplete:r,onError:n}=i,s=X(),[m,c]=o.useState(!1),[g,f]=o.useState(null),j=o.useRef(null),w=a||(s==null?void 0:s.config),N=o.useCallback(async(d,v)=>{var C;if(!w){const p="AI not configured";return n==null||n(p),je("html",t,p)}c(!0),(C=j.current)==null||C.abort(),j.current=new AbortController;try{const p=G(w),_=`You are a WCAG accessibility expert. Analyze the provided HTML code for accessibility issues at WCAG ${t} level.
|
|
2866
2866
|
|
|
2867
2867
|
Return JSON with this exact structure:
|
|
2868
2868
|
{
|
|
@@ -2896,10 +2896,10 @@ Focus on:
|
|
|
2896
2896
|
7. Heading hierarchy
|
|
2897
2897
|
8. Landmark regions
|
|
2898
2898
|
9. Semantic HTML usage
|
|
2899
|
-
10. Language attributes`,b=await
|
|
2900
|
-
${
|
|
2899
|
+
10. Language attributes`,b=await p.chat({messages:[{role:"system",content:_},{role:"user",content:`Analyze this HTML for accessibility:
|
|
2900
|
+
${v?`Context: ${v}
|
|
2901
2901
|
|
|
2902
|
-
`:""}${d}`}],temperature:.3,maxTokens:4096}),u=
|
|
2902
|
+
`:""}${d}`}],temperature:.3,maxTokens:4096}),u=Vt(b,"html",t);return f(u),r==null||r(u),u}catch(p){const _=p instanceof Error?p.message:"Audit failed";return n==null||n(_),je("html",t,_)}finally{c(!1)}},[w,t,r,n]),S=o.useCallback((d,v)=>{const C=me(pe(d)),p=me(pe(v)),_=(Math.max(C,p)+.05)/(Math.min(C,p)+.05),b={foreground:d,background:v,ratio:Math.round(_*100)/100,passesAA:_>=4.5,passesAALarge:_>=3,passesAAA:_>=7,passesAAALarge:_>=4.5};return b.passesAA||(b.suggestions=Yt(d,v,4.5)),b},[]),$=o.useCallback(async d=>{var v,C;if(!w)return n==null||n("AI not configured"),[];try{const y=(((C=(v=(await G(w).chat({messages:[{role:"system",content:`Analyze the HTML for ARIA attribute issues.
|
|
2903
2903
|
Return JSON array:
|
|
2904
2904
|
[{
|
|
2905
2905
|
"element": "<button>...",
|
|
@@ -2910,90 +2910,90 @@ Return JSON array:
|
|
|
2910
2910
|
"issues": ["Missing aria-label"],
|
|
2911
2911
|
"suggestions": ["Add aria-label='Submit form'"]
|
|
2912
2912
|
}]`},{role:"user",content:`Validate ARIA in:
|
|
2913
|
-
${d}`}],temperature:.2,maxTokens:2048})).choices[0])==null?void 0:
|
|
2913
|
+
${d}`}],temperature:.2,maxTokens:2048})).choices[0])==null?void 0:v.message)==null?void 0:C.content)||"").match(/\[[\s\S]*\]/);if(y)return JSON.parse(y[0])}catch{}return[]},[w,n]),k=o.useCallback(async d=>{var v,C;if(!w)return n==null||n("AI not configured"),d;try{const b=((C=(v=(await G(w).chat({messages:[{role:"system",content:`You are an accessibility expert. Improve the HTML to be fully WCAG ${t} compliant.
|
|
2914
2914
|
Add proper ARIA attributes, semantic HTML, keyboard handlers, focus management.
|
|
2915
2915
|
Return only the improved HTML code.`},{role:"user",content:`Make this accessible:
|
|
2916
|
-
${d}`}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:
|
|
2916
|
+
${d}`}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:v.message)==null?void 0:C.content)||"",u=b.match(/```(?:html)?\s*([\s\S]*?)```/);return u?u[1].trim():b.trim()}catch{return d}},[w,t,n]),P=o.useCallback(()=>{f(null)},[]),h=o.useCallback(()=>{var d;(d=j.current)==null||d.abort(),c(!1)},[]);return o.useEffect(()=>()=>{var d;(d=j.current)==null||d.abort()},[]),{analyzeHTML:N,checkContrast:S,validateARIA:$,suggestAccessibleCode:k,loading:m,lastAudit:g,clearAudit:P,abort:h,isConfigured:!!w}}function je(i,a,t){return{timestamp:new Date,target:i,wcagLevel:a,issues:t?[{id:"error",category:"semantic-html",severity:"critical",wcagCriteria:"N/A",wcagLevel:"A",title:"Audit Error",description:t,impact:"Audit could not complete",suggestion:"Try again or check configuration"}]:[],score:t?0:100,summary:{critical:t?1:0,serious:0,moderate:0,minor:0,passed:0},recommendations:[]}}function Vt(i,a,t){var r,n,s;try{const m=((n=(r=i.choices[0])==null?void 0:r.message)==null?void 0:n.content)||"",g=((s=(m.match(/```(?:json)?\s*([\s\S]*?)```/)||[null,m])[1])==null?void 0:s.trim())||m,f=JSON.parse(g),j=(f.issues||[]).map((N,S)=>({id:N.id||`issue_${S}`,category:N.category||"semantic-html",severity:N.severity||"moderate",wcagCriteria:N.wcagCriteria||"N/A",wcagLevel:N.wcagLevel||"A",title:N.title||"Unknown Issue",description:N.description||"",element:N.element,selector:N.selector,impact:N.impact||"",suggestion:N.suggestion||"",codeExample:N.codeExample})),w={critical:j.filter(N=>N.severity==="critical").length,serious:j.filter(N=>N.severity==="serious").length,moderate:j.filter(N=>N.severity==="moderate").length,minor:j.filter(N=>N.severity==="minor").length,passed:0};return{timestamp:new Date,target:a,wcagLevel:t,issues:j,score:f.score??Kt(w),summary:w,recommendations:f.recommendations||[]}}catch{return je(a,t,"Failed to parse audit results")}}function Kt(i){const a=i.critical*25+i.serious*15+i.moderate*5+i.minor*2;return Math.max(0,100-a)}function pe(i){const a=i.replace("#","");return a.length===3?{r:parseInt(a[0]+a[0],16),g:parseInt(a[1]+a[1],16),b:parseInt(a[2]+a[2],16)}:{r:parseInt(a.slice(0,2),16),g:parseInt(a.slice(2,4),16),b:parseInt(a.slice(4,6),16)}}function me(i){const[a,t,r]=[i.r,i.g,i.b].map(n=>(n/=255,n<=.03928?n/12.92:Math.pow((n+.055)/1.055,2.4)));return .2126*a+.7152*t+.0722*r}function Yt(i,a,t){const r=[],n=pe(i),s=pe(a),m={r:Math.max(0,n.r-40),g:Math.max(0,n.g-40),b:Math.max(0,n.b-40)},c=`#${m.r.toString(16).padStart(2,"0")}${m.g.toString(16).padStart(2,"0")}${m.b.toString(16).padStart(2,"0")}`,g=me(m),f=me(s);(Math.max(g,f)+.05)/(Math.min(g,f)+.05)>=t&&r.push(`Try darker foreground: ${c}`);const w={r:Math.min(255,s.r+40),g:Math.min(255,s.g+40),b:Math.min(255,s.b+40)},N=`#${w.r.toString(16).padStart(2,"0")}${w.g.toString(16).padStart(2,"0")}${w.b.toString(16).padStart(2,"0")}`;return r.push(`Try lighter background: ${N}`),r}const be={critical:{bg:"var(--nice-danger-bg, #ffebee)",color:"var(--nice-danger-dark, #c62828)",icon:"🚫"},serious:{bg:"var(--nice-warning-bg, #fff3e0)",color:"var(--nice-warning-dark, #e65100)",icon:"⚠️"},moderate:{bg:"var(--nice-warning-bg, #fff8e1)",color:"var(--nice-warning-dark, #f57f17)",icon:"⚡"},minor:{bg:"var(--nice-primary-bg, #e3f2fd)",color:"var(--nice-primary-dark, #1565c0)",icon:"ℹ️"}};function Xt({config:i,wcagLevel:a="AA",onAuditComplete:t,showContrastChecker:r=!0,className:n,style:s,renderIssue:m}){const[c,g]=o.useState(""),[f,j]=o.useState("var(--nice-text, #333333)"),[w,N]=o.useState("var(--nice-bg, #fff)"),[S,$]=o.useState(null),{analyzeHTML:k,checkContrast:P,suggestAccessibleCode:h,loading:d,lastAudit:v,isConfigured:C}=_a({config:i,wcagLevel:a,onAuditComplete:t}),p=async()=>{!c.trim()||d||await k(c)},_=()=>{const u=P(f,w);$(u)},b=async()=>{if(!c.trim())return;const u=await h(c);g(u)};return C?e.jsxs("div",{className:`nice-a11y-ai ${n||""}`,style:s,children:[r&&e.jsxs("div",{className:"nice-a11y-ai__contrast",children:[e.jsx("h3",{children:"Color Contrast Checker"}),e.jsxs("div",{className:"nice-a11y-ai__contrast-inputs",children:[e.jsxs("label",{children:["Foreground",e.jsx("input",{type:"color",value:f,onChange:u=>j(u.target.value)}),e.jsx("input",{type:"text",value:f,onChange:u=>j(u.target.value)})]}),e.jsxs("label",{children:["Background",e.jsx("input",{type:"color",value:w,onChange:u=>N(u.target.value)}),e.jsx("input",{type:"text",value:w,onChange:u=>N(u.target.value)})]}),e.jsx("button",{type:"button",onClick:_,children:"Check"})]}),S&&e.jsxs("div",{className:"nice-a11y-ai__contrast-result",children:[e.jsx("div",{className:"nice-a11y-ai__contrast-preview",style:{color:f,background:w},children:"Sample Text Aa"}),e.jsxs("div",{className:"nice-a11y-ai__contrast-ratio",children:[e.jsxs("span",{className:"nice-a11y-ai__ratio-value",children:[S.ratio,":1"]}),e.jsxs("div",{className:"nice-a11y-ai__passes",children:[e.jsxs("span",{className:S.passesAA?"pass":"fail",children:["AA: ",S.passesAA?"✅":"❌"]}),e.jsxs("span",{className:S.passesAALarge?"pass":"fail",children:["AA Large: ",S.passesAALarge?"✅":"❌"]}),e.jsxs("span",{className:S.passesAAA?"pass":"fail",children:["AAA: ",S.passesAAA?"✅":"❌"]})]})]}),S.suggestions&&S.suggestions.length>0&&e.jsx("div",{className:"nice-a11y-ai__suggestions",children:S.suggestions.map((u,y)=>e.jsx("div",{children:u},y))})]})]}),e.jsxs("div",{className:"nice-a11y-ai__analyzer",children:[e.jsxs("h3",{children:["HTML Accessibility Analyzer (WCAG ",a,")"]}),e.jsx("textarea",{value:c,onChange:u=>g(u.target.value),placeholder:"Paste HTML code to analyze...",className:"nice-a11y-ai__input",rows:8,disabled:d}),e.jsxs("div",{className:"nice-a11y-ai__actions",children:[e.jsx("button",{type:"button",onClick:p,disabled:d||!c.trim(),children:d?e.jsx("span",{className:"nice-a11y-ai__spinner"}):"🔍 Analyze"}),e.jsx("button",{type:"button",onClick:b,disabled:d||!c.trim(),children:"🔧 Auto-Fix"})]})]}),v&&e.jsxs("div",{className:"nice-a11y-ai__audit",children:[e.jsxs("div",{className:"nice-a11y-ai__audit-header",children:[e.jsxs("div",{className:"nice-a11y-ai__score",children:[e.jsx("span",{className:"nice-a11y-ai__score-value",children:v.score}),e.jsx("span",{className:"nice-a11y-ai__score-label",children:"Score"})]}),e.jsxs("div",{className:"nice-a11y-ai__summary",children:[e.jsxs("span",{className:"critical",children:[v.summary.critical," Critical"]}),e.jsxs("span",{className:"serious",children:[v.summary.serious," Serious"]}),e.jsxs("span",{className:"moderate",children:[v.summary.moderate," Moderate"]}),e.jsxs("span",{className:"minor",children:[v.summary.minor," Minor"]})]})]}),e.jsx("div",{className:"nice-a11y-ai__issues",children:v.issues.map(u=>m?m(u):e.jsxs("div",{className:"nice-a11y-ai__issue",style:{background:be[u.severity].bg,borderLeftColor:be[u.severity].color},children:[e.jsxs("div",{className:"nice-a11y-ai__issue-header",children:[e.jsx("span",{className:"nice-a11y-ai__issue-icon",children:be[u.severity].icon}),e.jsx("span",{className:"nice-a11y-ai__issue-title",children:u.title}),e.jsxs("span",{className:"nice-a11y-ai__issue-wcag",children:["WCAG ",u.wcagCriteria," (",u.wcagLevel,")"]})]}),e.jsx("p",{className:"nice-a11y-ai__issue-desc",children:u.description}),u.element&&e.jsx("code",{className:"nice-a11y-ai__issue-element",children:u.element}),e.jsxs("div",{className:"nice-a11y-ai__issue-suggestion",children:[e.jsx("strong",{children:"Fix:"})," ",u.suggestion]}),u.codeExample&&e.jsx("pre",{className:"nice-a11y-ai__issue-example",children:u.codeExample})]},u.id))}),v.recommendations.length>0&&e.jsxs("div",{className:"nice-a11y-ai__recommendations",children:[e.jsx("h4",{children:"General Recommendations"}),e.jsx("ul",{children:v.recommendations.map((u,y)=>e.jsx("li",{children:u},y))})]})]}),e.jsx("style",{children:`
|
|
2917
2917
|
.nice-a11y-ai {
|
|
2918
2918
|
font-family: var(--nice-font-family, system-ui, sans-serif);
|
|
2919
2919
|
}
|
|
2920
2920
|
|
|
2921
2921
|
.nice-a11y-ai--disabled {
|
|
2922
|
-
padding: 20px;
|
|
2922
|
+
padding: var(--nice-space-5, 20px);
|
|
2923
2923
|
background: var(--nice-disabled-bg, #f5f5f5);
|
|
2924
|
-
border-radius: 8px;
|
|
2924
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2925
2925
|
color: var(--nice-text-muted, #666);
|
|
2926
2926
|
}
|
|
2927
2927
|
|
|
2928
2928
|
.nice-a11y-ai__contrast {
|
|
2929
|
-
padding: 20px;
|
|
2929
|
+
padding: var(--nice-space-5, 20px);
|
|
2930
2930
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
2931
|
-
border-radius: 8px;
|
|
2932
|
-
margin-bottom: 20px;
|
|
2931
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2932
|
+
margin-bottom: var(--nice-space-5, 20px);
|
|
2933
2933
|
}
|
|
2934
2934
|
|
|
2935
2935
|
.nice-a11y-ai__contrast h3 {
|
|
2936
|
-
margin: 0 0 16px;
|
|
2936
|
+
margin: 0 0 var(--nice-space-4, 16px);
|
|
2937
2937
|
font-size: 16px;
|
|
2938
2938
|
}
|
|
2939
2939
|
|
|
2940
2940
|
.nice-a11y-ai__contrast-inputs {
|
|
2941
2941
|
display: flex;
|
|
2942
|
-
gap: 20px;
|
|
2942
|
+
gap: var(--nice-space-5, 20px);
|
|
2943
2943
|
align-items: flex-end;
|
|
2944
2944
|
}
|
|
2945
2945
|
|
|
2946
2946
|
.nice-a11y-ai__contrast-inputs label {
|
|
2947
2947
|
display: flex;
|
|
2948
2948
|
flex-direction: column;
|
|
2949
|
-
gap: 6px;
|
|
2949
|
+
gap: var(--nice-space-1-5, 6px);
|
|
2950
2950
|
font-size: 13px;
|
|
2951
2951
|
}
|
|
2952
2952
|
|
|
2953
2953
|
.nice-a11y-ai__contrast-inputs input[type="color"] {
|
|
2954
2954
|
width: 40px;
|
|
2955
2955
|
height: 30px;
|
|
2956
|
-
border: 1px solid #ddd;
|
|
2957
|
-
border-radius: 4px;
|
|
2956
|
+
border: 1px solid var(--nice-border, #ddd);
|
|
2957
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
2958
2958
|
cursor: pointer;
|
|
2959
2959
|
}
|
|
2960
2960
|
|
|
2961
2961
|
.nice-a11y-ai__contrast-inputs input[type="text"] {
|
|
2962
2962
|
width: 80px;
|
|
2963
|
-
padding: 6px;
|
|
2964
|
-
border: 1px solid #ddd;
|
|
2965
|
-
border-radius: 4px;
|
|
2963
|
+
padding: var(--nice-space-1-5, 6px);
|
|
2964
|
+
border: 1px solid var(--nice-border, #ddd);
|
|
2965
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
2966
2966
|
font-family: monospace;
|
|
2967
2967
|
}
|
|
2968
2968
|
|
|
2969
2969
|
.nice-a11y-ai__contrast-inputs button {
|
|
2970
|
-
padding: 8px 20px;
|
|
2970
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-5, 20px);
|
|
2971
2971
|
background: var(--nice-primary, #0066cc);
|
|
2972
2972
|
color: white;
|
|
2973
2973
|
border: none;
|
|
2974
|
-
border-radius: 6px;
|
|
2974
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
2975
2975
|
cursor: pointer;
|
|
2976
2976
|
}
|
|
2977
2977
|
|
|
2978
2978
|
.nice-a11y-ai__contrast-result {
|
|
2979
|
-
margin-top: 16px;
|
|
2979
|
+
margin-top: var(--nice-space-4, 16px);
|
|
2980
2980
|
display: flex;
|
|
2981
|
-
gap: 20px;
|
|
2981
|
+
gap: var(--nice-space-5, 20px);
|
|
2982
2982
|
align-items: center;
|
|
2983
2983
|
}
|
|
2984
2984
|
|
|
2985
2985
|
.nice-a11y-ai__contrast-preview {
|
|
2986
|
-
padding: 20px 30px;
|
|
2987
|
-
border-radius: 8px;
|
|
2986
|
+
padding: var(--nice-space-5, 20px) 30px;
|
|
2987
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
2988
2988
|
font-size: 18px;
|
|
2989
2989
|
font-weight: 500;
|
|
2990
|
-
border: 1px solid #ddd;
|
|
2990
|
+
border: 1px solid var(--nice-border, #ddd);
|
|
2991
2991
|
}
|
|
2992
2992
|
|
|
2993
2993
|
.nice-a11y-ai__contrast-ratio {
|
|
2994
2994
|
display: flex;
|
|
2995
2995
|
flex-direction: column;
|
|
2996
|
-
gap: 8px;
|
|
2996
|
+
gap: var(--nice-space-2, 8px);
|
|
2997
2997
|
}
|
|
2998
2998
|
|
|
2999
2999
|
.nice-a11y-ai__ratio-value {
|
|
@@ -3003,7 +3003,7 @@ ${d}`}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:y.message)==nu
|
|
|
3003
3003
|
|
|
3004
3004
|
.nice-a11y-ai__passes {
|
|
3005
3005
|
display: flex;
|
|
3006
|
-
gap: 12px;
|
|
3006
|
+
gap: var(--nice-space-3, 12px);
|
|
3007
3007
|
font-size: 13px;
|
|
3008
3008
|
}
|
|
3009
3009
|
|
|
@@ -3011,44 +3011,44 @@ ${d}`}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:y.message)==nu
|
|
|
3011
3011
|
.nice-a11y-ai__passes .fail { color: var(--nice-error, #c62828); }
|
|
3012
3012
|
|
|
3013
3013
|
.nice-a11y-ai__suggestions {
|
|
3014
|
-
padding: 12px;
|
|
3014
|
+
padding: var(--nice-space-3, 12px);
|
|
3015
3015
|
background: var(--nice-warning-light, #fff8e1);
|
|
3016
|
-
border-radius: 6px;
|
|
3016
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
3017
3017
|
font-size: 13px;
|
|
3018
3018
|
}
|
|
3019
3019
|
|
|
3020
3020
|
.nice-a11y-ai__analyzer {
|
|
3021
|
-
padding: 20px;
|
|
3021
|
+
padding: var(--nice-space-5, 20px);
|
|
3022
3022
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
3023
|
-
border-radius: 8px;
|
|
3024
|
-
margin-bottom: 20px;
|
|
3023
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
3024
|
+
margin-bottom: var(--nice-space-5, 20px);
|
|
3025
3025
|
}
|
|
3026
3026
|
|
|
3027
3027
|
.nice-a11y-ai__analyzer h3 {
|
|
3028
|
-
margin: 0 0 16px;
|
|
3028
|
+
margin: 0 0 var(--nice-space-4, 16px);
|
|
3029
3029
|
font-size: 16px;
|
|
3030
3030
|
}
|
|
3031
3031
|
|
|
3032
3032
|
.nice-a11y-ai__input {
|
|
3033
3033
|
width: 100%;
|
|
3034
|
-
padding: 12px;
|
|
3034
|
+
padding: var(--nice-space-3, 12px);
|
|
3035
3035
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
3036
|
-
border-radius: 8px;
|
|
3036
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
3037
3037
|
font-family: monospace;
|
|
3038
3038
|
font-size: 13px;
|
|
3039
3039
|
resize: vertical;
|
|
3040
|
-
margin-bottom: 12px;
|
|
3040
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
3041
3041
|
}
|
|
3042
3042
|
|
|
3043
3043
|
.nice-a11y-ai__actions {
|
|
3044
3044
|
display: flex;
|
|
3045
|
-
gap: 12px;
|
|
3045
|
+
gap: var(--nice-space-3, 12px);
|
|
3046
3046
|
}
|
|
3047
3047
|
|
|
3048
3048
|
.nice-a11y-ai__actions button {
|
|
3049
|
-
padding: 10px 24px;
|
|
3049
|
+
padding: var(--nice-space-2-5, 10px) var(--nice-space-6, 24px);
|
|
3050
3050
|
border: none;
|
|
3051
|
-
border-radius: 6px;
|
|
3051
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
3052
3052
|
font-weight: 500;
|
|
3053
3053
|
cursor: pointer;
|
|
3054
3054
|
}
|
|
@@ -3071,9 +3071,9 @@ ${d}`}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:y.message)==nu
|
|
|
3071
3071
|
display: inline-block;
|
|
3072
3072
|
width: 16px;
|
|
3073
3073
|
height: 16px;
|
|
3074
|
-
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
3074
|
+
border: 2px solid var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3));
|
|
3075
3075
|
border-top-color: white;
|
|
3076
|
-
border-radius: 50
|
|
3076
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
3077
3077
|
animation: nice-spin 0.8s linear infinite;
|
|
3078
3078
|
}
|
|
3079
3079
|
|
|
@@ -3082,9 +3082,9 @@ ${d}`}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:y.message)==nu
|
|
|
3082
3082
|
}
|
|
3083
3083
|
|
|
3084
3084
|
.nice-a11y-ai__audit {
|
|
3085
|
-
padding: 20px;
|
|
3085
|
+
padding: var(--nice-space-5, 20px);
|
|
3086
3086
|
background: white;
|
|
3087
|
-
border-radius: 8px;
|
|
3087
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
3088
3088
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
3089
3089
|
}
|
|
3090
3090
|
|
|
@@ -3092,8 +3092,8 @@ ${d}`}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:y.message)==nu
|
|
|
3092
3092
|
display: flex;
|
|
3093
3093
|
justify-content: space-between;
|
|
3094
3094
|
align-items: center;
|
|
3095
|
-
margin-bottom: 20px;
|
|
3096
|
-
padding-bottom: 16px;
|
|
3095
|
+
margin-bottom: var(--nice-space-5, 20px);
|
|
3096
|
+
padding-bottom: var(--nice-space-4, 16px);
|
|
3097
3097
|
border-bottom: 1px solid var(--nice-border-color, #e0e0e0);
|
|
3098
3098
|
}
|
|
3099
3099
|
|
|
@@ -3116,38 +3116,38 @@ ${d}`}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:y.message)==nu
|
|
|
3116
3116
|
|
|
3117
3117
|
.nice-a11y-ai__summary {
|
|
3118
3118
|
display: flex;
|
|
3119
|
-
gap: 16px;
|
|
3119
|
+
gap: var(--nice-space-4, 16px);
|
|
3120
3120
|
}
|
|
3121
3121
|
|
|
3122
3122
|
.nice-a11y-ai__summary span {
|
|
3123
|
-
padding: 6px 12px;
|
|
3124
|
-
border-radius: 6px;
|
|
3123
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-3, 12px);
|
|
3124
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
3125
3125
|
font-size: 13px;
|
|
3126
3126
|
font-weight: 500;
|
|
3127
3127
|
}
|
|
3128
3128
|
|
|
3129
|
-
.nice-a11y-ai__summary .critical { background: #ffebee; color: #c62828; }
|
|
3130
|
-
.nice-a11y-ai__summary .serious { background: #fff3e0; color: #e65100; }
|
|
3131
|
-
.nice-a11y-ai__summary .moderate { background: #fff8e1; color: #f57f17; }
|
|
3132
|
-
.nice-a11y-ai__summary .minor { background: #e3f2fd; color: #1565c0; }
|
|
3129
|
+
.nice-a11y-ai__summary .critical { background: var(--nice-danger-bg, #ffebee); color: var(--nice-danger-dark, #c62828); }
|
|
3130
|
+
.nice-a11y-ai__summary .serious { background: var(--nice-warning-bg, #fff3e0); color: var(--nice-warning-dark, #e65100); }
|
|
3131
|
+
.nice-a11y-ai__summary .moderate { background: var(--nice-warning-bg, #fff8e1); color: var(--nice-warning-dark, #f57f17); }
|
|
3132
|
+
.nice-a11y-ai__summary .minor { background: var(--nice-primary-bg, #e3f2fd); color: var(--nice-primary-dark, #1565c0); }
|
|
3133
3133
|
|
|
3134
3134
|
.nice-a11y-ai__issues {
|
|
3135
3135
|
display: flex;
|
|
3136
3136
|
flex-direction: column;
|
|
3137
|
-
gap: 12px;
|
|
3137
|
+
gap: var(--nice-space-3, 12px);
|
|
3138
3138
|
}
|
|
3139
3139
|
|
|
3140
3140
|
.nice-a11y-ai__issue {
|
|
3141
|
-
padding: 16px;
|
|
3142
|
-
border-radius: 8px;
|
|
3141
|
+
padding: var(--nice-space-4, 16px);
|
|
3142
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
3143
3143
|
border-left: 4px solid;
|
|
3144
3144
|
}
|
|
3145
3145
|
|
|
3146
3146
|
.nice-a11y-ai__issue-header {
|
|
3147
3147
|
display: flex;
|
|
3148
3148
|
align-items: center;
|
|
3149
|
-
gap: 8px;
|
|
3150
|
-
margin-bottom: 8px;
|
|
3149
|
+
gap: var(--nice-space-2, 8px);
|
|
3150
|
+
margin-bottom: var(--nice-space-2, 8px);
|
|
3151
3151
|
}
|
|
3152
3152
|
|
|
3153
3153
|
.nice-a11y-ai__issue-title {
|
|
@@ -3157,23 +3157,23 @@ ${d}`}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:y.message)==nu
|
|
|
3157
3157
|
|
|
3158
3158
|
.nice-a11y-ai__issue-wcag {
|
|
3159
3159
|
font-size: 12px;
|
|
3160
|
-
padding: 2px 8px;
|
|
3161
|
-
background: rgba(0, 0, 0, 0.1);
|
|
3162
|
-
border-radius: 4px;
|
|
3160
|
+
padding: var(--nice-space-0-5, 2px) var(--nice-space-2, 8px);
|
|
3161
|
+
background: var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
|
|
3162
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
3163
3163
|
}
|
|
3164
3164
|
|
|
3165
3165
|
.nice-a11y-ai__issue-desc {
|
|
3166
|
-
margin: 0 0 8px;
|
|
3166
|
+
margin: 0 0 var(--nice-space-2, 8px);
|
|
3167
3167
|
font-size: 14px;
|
|
3168
3168
|
}
|
|
3169
3169
|
|
|
3170
3170
|
.nice-a11y-ai__issue-element {
|
|
3171
3171
|
display: block;
|
|
3172
|
-
padding: 8px;
|
|
3173
|
-
background: rgba(0, 0, 0, 0.05);
|
|
3174
|
-
border-radius: 4px;
|
|
3172
|
+
padding: var(--nice-space-2, 8px);
|
|
3173
|
+
background: var(--nice-overlay-5, rgba(0, 0, 0, 0.05));
|
|
3174
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
3175
3175
|
font-size: 12px;
|
|
3176
|
-
margin-bottom: 8px;
|
|
3176
|
+
margin-bottom: var(--nice-space-2, 8px);
|
|
3177
3177
|
overflow-x: auto;
|
|
3178
3178
|
}
|
|
3179
3179
|
|
|
@@ -3183,42 +3183,42 @@ ${d}`}],temperature:.3,maxTokens:2048})).choices[0])==null?void 0:y.message)==nu
|
|
|
3183
3183
|
}
|
|
3184
3184
|
|
|
3185
3185
|
.nice-a11y-ai__issue-example {
|
|
3186
|
-
margin: 8px 0 0;
|
|
3187
|
-
padding: 12px;
|
|
3186
|
+
margin: var(--nice-space-2, 8px) 0 0;
|
|
3187
|
+
padding: var(--nice-space-3, 12px);
|
|
3188
3188
|
background: var(--nice-code-bg, #1e1e1e);
|
|
3189
3189
|
color: var(--nice-code-color, #d4d4d4);
|
|
3190
|
-
border-radius: 6px;
|
|
3190
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
3191
3191
|
font-size: 12px;
|
|
3192
3192
|
overflow-x: auto;
|
|
3193
3193
|
}
|
|
3194
3194
|
|
|
3195
3195
|
.nice-a11y-ai__recommendations {
|
|
3196
|
-
margin-top: 20px;
|
|
3197
|
-
padding-top: 16px;
|
|
3196
|
+
margin-top: var(--nice-space-5, 20px);
|
|
3197
|
+
padding-top: var(--nice-space-4, 16px);
|
|
3198
3198
|
border-top: 1px solid var(--nice-border-color, #e0e0e0);
|
|
3199
3199
|
}
|
|
3200
3200
|
|
|
3201
3201
|
.nice-a11y-ai__recommendations h4 {
|
|
3202
|
-
margin: 0 0 12px;
|
|
3202
|
+
margin: 0 0 var(--nice-space-3, 12px);
|
|
3203
3203
|
}
|
|
3204
3204
|
|
|
3205
3205
|
.nice-a11y-ai__recommendations ul {
|
|
3206
3206
|
margin: 0;
|
|
3207
|
-
padding-left: 20px;
|
|
3207
|
+
padding-left: var(--nice-space-5, 20px);
|
|
3208
3208
|
}
|
|
3209
3209
|
|
|
3210
3210
|
.nice-a11y-ai__recommendations li {
|
|
3211
|
-
margin-bottom: 6px;
|
|
3211
|
+
margin-bottom: var(--nice-space-1-5, 6px);
|
|
3212
3212
|
font-size: 14px;
|
|
3213
3213
|
}
|
|
3214
|
-
`})]}):e.jsx("div",{className:`nice-a11y-ai nice-a11y-ai--disabled ${n||""}`,style:s,children:e.jsx("p",{children:"AI not configured. Please provide config or wrap in NiceAIProvider."})})}const ye=[{name:"home",category:"navigation",keywords:["home","house","start","main"],svgPath:"M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"},{name:"menu",category:"navigation",keywords:["menu","hamburger","nav","bars"],svgPath:"M4 6h16M4 12h16M4 18h16"},{name:"arrow-left",category:"navigation",keywords:["back","previous","left","arrow"],svgPath:"M10 19l-7-7m0 0l7-7m-7 7h18"},{name:"arrow-right",category:"navigation",keywords:["next","forward","right","arrow"],svgPath:"M14 5l7 7m0 0l-7 7m7-7H3"},{name:"chevron-down",category:"navigation",keywords:["expand","dropdown","down","chevron"],svgPath:"M19 9l-7 7-7-7"},{name:"chevron-up",category:"navigation",keywords:["collapse","up","chevron"],svgPath:"M5 15l7-7 7 7"},{name:"plus",category:"action",keywords:["add","create","new","plus"],svgPath:"M12 4v16m8-8H4"},{name:"minus",category:"action",keywords:["remove","subtract","minus"],svgPath:"M20 12H4"},{name:"x",category:"action",keywords:["close","cancel","delete","remove","x"],svgPath:"M6 18L18 6M6 6l12 12"},{name:"check",category:"action",keywords:["done","complete","success","check","tick"],svgPath:"M5 13l4 4L19 7"},{name:"edit",category:"action",keywords:["edit","modify","pencil","write"],svgPath:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"},{name:"trash",category:"action",keywords:["delete","remove","trash","bin"],svgPath:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"},{name:"search",category:"action",keywords:["search","find","magnify","lookup"],svgPath:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"},{name:"filter",category:"action",keywords:["filter","sort","funnel"],svgPath:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"},{name:"download",category:"action",keywords:["download","save","export"],svgPath:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"},{name:"upload",category:"action",keywords:["upload","import","send"],svgPath:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"},{name:"refresh",category:"action",keywords:["refresh","reload","sync"],svgPath:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"},{name:"copy",category:"action",keywords:["copy","duplicate","clone"],svgPath:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"},{name:"mail",category:"communication",keywords:["email","mail","message","envelope"],svgPath:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"},{name:"phone",category:"communication",keywords:["phone","call","telephone","contact"],svgPath:"M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"},{name:"chat",category:"communication",keywords:["chat","message","comment","bubble"],svgPath:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"},{name:"bell",category:"notification",keywords:["notification","bell","alert","alarm"],svgPath:"M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"},{name:"file",category:"file",keywords:["file","document","page"],svgPath:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"},{name:"folder",category:"file",keywords:["folder","directory","category"],svgPath:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"},{name:"image",category:"image",keywords:["image","photo","picture","gallery"],svgPath:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"},{name:"video",category:"av",keywords:["video","movie","film","camera"],svgPath:"M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"},{name:"user",category:"social",keywords:["user","person","account","profile"],svgPath:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"},{name:"users",category:"social",keywords:["users","group","team","people"],svgPath:"M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"},{name:"settings",category:"action",keywords:["settings","config","gear","cog","preferences"],svgPath:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z M15 12a3 3 0 11-6 0 3 3 0 016 0z"},{name:"calendar",category:"business",keywords:["calendar","date","schedule","event"],svgPath:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"},{name:"clock",category:"business",keywords:["time","clock","schedule","hour"],svgPath:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"},{name:"credit-card",category:"finance",keywords:["payment","card","credit","money"],svgPath:"M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"},{name:"chart",category:"business",keywords:["chart","graph","analytics","statistics"],svgPath:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"},{name:"lock",category:"security",keywords:["lock","secure","private","password"],svgPath:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"},{name:"unlock",category:"security",keywords:["unlock","open","access"],svgPath:"M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"},{name:"shield",category:"security",keywords:["shield","security","protect","safe"],svgPath:"M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"},{name:"eye",category:"action",keywords:["view","show","visible","eye","visibility"],svgPath:"M15 12a3 3 0 11-6 0 3 3 0 016 0z M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"},{name:"eye-off",category:"action",keywords:["hide","invisible","hidden","eye-off"],svgPath:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"},{name:"info",category:"alert",keywords:["info","information","help","about"],svgPath:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"},{name:"warning",category:"alert",keywords:["warning","caution","alert","attention"],svgPath:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"},{name:"error",category:"alert",keywords:["error","danger","fail","problem"],svgPath:"M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"},{name:"success",category:"alert",keywords:["success","done","complete","check-circle"],svgPath:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"},{name:"star",category:"action",keywords:["star","favorite","bookmark","rating"],svgPath:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"},{name:"heart",category:"social",keywords:["heart","love","like","favorite"],svgPath:"M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"},{name:"share",category:"social",keywords:["share","send","forward"],svgPath:"M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"},{name:"link",category:"action",keywords:["link","url","chain","hyperlink"],svgPath:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"},{name:"external-link",category:"action",keywords:["external","open","new-window"],svgPath:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"}];function wt(a={}){const{config:t,defaultLibrary:i="lucide",defaultStyle:r="outline",maxSuggestions:n=10,onSuggestion:s,onError:p}=a,o=X(),[g,f]=c.useState(!1),[j,w]=c.useState(null),N=c.useRef(null),S=t||(o==null?void 0:o.config),$=c.useCallback(C=>{const m=C.toLowerCase(),_=m.split(/\s+/);return ye.map(b=>{let u=0;return b.name===m?u+=100:b.name.includes(m)&&(u+=50),_.forEach(v=>{b.keywords.forEach(A=>{A===v?u+=30:(A.includes(v)||v.includes(A))&&(u+=15)})}),b.category===m&&(u+=20),{id:`icon_${b.name}`,name:b.name,displayName:b.name.replace(/-/g," ").replace(/\b\w/g,v=>v.toUpperCase()),category:b.category,style:r,library:i,relevanceScore:u,keywords:b.keywords,svgPath:b.svgPath}}).filter(b=>b.relevanceScore>0).sort((b,u)=>u.relevanceScore-b.relevanceScore).slice(0,n)},[i,r,n]),k=c.useCallback(async(C,m)=>{var u,v,A,R;const _=performance.now(),b=$(C);if(!S){const l={query:C,suggestions:b,latencyMs:performance.now()-_};return w(l),s==null||s(l),l}f(!0),(u=N.current)==null||u.abort(),N.current=new AbortController;try{const l=G(S),x=m?`
|
|
3214
|
+
`})]}):e.jsx("div",{className:`nice-a11y-ai nice-a11y-ai--disabled ${n||""}`,style:s,children:e.jsx("p",{children:"AI not configured. Please provide config or wrap in NiceAIProvider."})})}const ve=[{name:"home",category:"navigation",keywords:["home","house","start","main"],svgPath:"M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"},{name:"menu",category:"navigation",keywords:["menu","hamburger","nav","bars"],svgPath:"M4 6h16M4 12h16M4 18h16"},{name:"arrow-left",category:"navigation",keywords:["back","previous","left","arrow"],svgPath:"M10 19l-7-7m0 0l7-7m-7 7h18"},{name:"arrow-right",category:"navigation",keywords:["next","forward","right","arrow"],svgPath:"M14 5l7 7m0 0l-7 7m7-7H3"},{name:"chevron-down",category:"navigation",keywords:["expand","dropdown","down","chevron"],svgPath:"M19 9l-7 7-7-7"},{name:"chevron-up",category:"navigation",keywords:["collapse","up","chevron"],svgPath:"M5 15l7-7 7 7"},{name:"plus",category:"action",keywords:["add","create","new","plus"],svgPath:"M12 4v16m8-8H4"},{name:"minus",category:"action",keywords:["remove","subtract","minus"],svgPath:"M20 12H4"},{name:"x",category:"action",keywords:["close","cancel","delete","remove","x"],svgPath:"M6 18L18 6M6 6l12 12"},{name:"check",category:"action",keywords:["done","complete","success","check","tick"],svgPath:"M5 13l4 4L19 7"},{name:"edit",category:"action",keywords:["edit","modify","pencil","write"],svgPath:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"},{name:"trash",category:"action",keywords:["delete","remove","trash","bin"],svgPath:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"},{name:"search",category:"action",keywords:["search","find","magnify","lookup"],svgPath:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"},{name:"filter",category:"action",keywords:["filter","sort","funnel"],svgPath:"M3 4a1 1 0 011-1h16a1 1 0 011 1v2.586a1 1 0 01-.293.707l-6.414 6.414a1 1 0 00-.293.707V17l-4 4v-6.586a1 1 0 00-.293-.707L3.293 7.293A1 1 0 013 6.586V4z"},{name:"download",category:"action",keywords:["download","save","export"],svgPath:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"},{name:"upload",category:"action",keywords:["upload","import","send"],svgPath:"M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-8l-4-4m0 0L8 8m4-4v12"},{name:"refresh",category:"action",keywords:["refresh","reload","sync"],svgPath:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"},{name:"copy",category:"action",keywords:["copy","duplicate","clone"],svgPath:"M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"},{name:"mail",category:"communication",keywords:["email","mail","message","envelope"],svgPath:"M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"},{name:"phone",category:"communication",keywords:["phone","call","telephone","contact"],svgPath:"M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z"},{name:"chat",category:"communication",keywords:["chat","message","comment","bubble"],svgPath:"M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z"},{name:"bell",category:"notification",keywords:["notification","bell","alert","alarm"],svgPath:"M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"},{name:"file",category:"file",keywords:["file","document","page"],svgPath:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"},{name:"folder",category:"file",keywords:["folder","directory","category"],svgPath:"M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"},{name:"image",category:"image",keywords:["image","photo","picture","gallery"],svgPath:"M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"},{name:"video",category:"av",keywords:["video","movie","film","camera"],svgPath:"M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"},{name:"user",category:"social",keywords:["user","person","account","profile"],svgPath:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"},{name:"users",category:"social",keywords:["users","group","team","people"],svgPath:"M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"},{name:"settings",category:"action",keywords:["settings","config","gear","cog","preferences"],svgPath:"M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z M15 12a3 3 0 11-6 0 3 3 0 016 0z"},{name:"calendar",category:"business",keywords:["calendar","date","schedule","event"],svgPath:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"},{name:"clock",category:"business",keywords:["time","clock","schedule","hour"],svgPath:"M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"},{name:"credit-card",category:"finance",keywords:["payment","card","credit","money"],svgPath:"M3 10h18M7 15h1m4 0h1m-7 4h12a3 3 0 003-3V8a3 3 0 00-3-3H6a3 3 0 00-3 3v8a3 3 0 003 3z"},{name:"chart",category:"business",keywords:["chart","graph","analytics","statistics"],svgPath:"M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"},{name:"lock",category:"security",keywords:["lock","secure","private","password"],svgPath:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"},{name:"unlock",category:"security",keywords:["unlock","open","access"],svgPath:"M8 11V7a4 4 0 118 0m-4 8v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2z"},{name:"shield",category:"security",keywords:["shield","security","protect","safe"],svgPath:"M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"},{name:"eye",category:"action",keywords:["view","show","visible","eye","visibility"],svgPath:"M15 12a3 3 0 11-6 0 3 3 0 016 0z M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"},{name:"eye-off",category:"action",keywords:["hide","invisible","hidden","eye-off"],svgPath:"M13.875 18.825A10.05 10.05 0 0112 19c-4.478 0-8.268-2.943-9.543-7a9.97 9.97 0 011.563-3.029m5.858.908a3 3 0 114.243 4.243M9.878 9.878l4.242 4.242M9.88 9.88l-3.29-3.29m7.532 7.532l3.29 3.29M3 3l3.59 3.59m0 0A9.953 9.953 0 0112 5c4.478 0 8.268 2.943 9.543 7a10.025 10.025 0 01-4.132 5.411m0 0L21 21"},{name:"info",category:"alert",keywords:["info","information","help","about"],svgPath:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"},{name:"warning",category:"alert",keywords:["warning","caution","alert","attention"],svgPath:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"},{name:"error",category:"alert",keywords:["error","danger","fail","problem"],svgPath:"M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"},{name:"success",category:"alert",keywords:["success","done","complete","check-circle"],svgPath:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"},{name:"star",category:"action",keywords:["star","favorite","bookmark","rating"],svgPath:"M11.049 2.927c.3-.921 1.603-.921 1.902 0l1.519 4.674a1 1 0 00.95.69h4.915c.969 0 1.371 1.24.588 1.81l-3.976 2.888a1 1 0 00-.363 1.118l1.518 4.674c.3.922-.755 1.688-1.538 1.118l-3.976-2.888a1 1 0 00-1.176 0l-3.976 2.888c-.783.57-1.838-.197-1.538-1.118l1.518-4.674a1 1 0 00-.363-1.118l-3.976-2.888c-.784-.57-.38-1.81.588-1.81h4.914a1 1 0 00.951-.69l1.519-4.674z"},{name:"heart",category:"social",keywords:["heart","love","like","favorite"],svgPath:"M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"},{name:"share",category:"social",keywords:["share","send","forward"],svgPath:"M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"},{name:"link",category:"action",keywords:["link","url","chain","hyperlink"],svgPath:"M13.828 10.172a4 4 0 00-5.656 0l-4 4a4 4 0 105.656 5.656l1.102-1.101m-.758-4.899a4 4 0 005.656 0l4-4a4 4 0 00-5.656-5.656l-1.1 1.1"},{name:"external-link",category:"action",keywords:["external","open","new-window"],svgPath:"M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"}];function wa(i={}){const{config:a,defaultLibrary:t="lucide",defaultStyle:r="outline",maxSuggestions:n=10,onSuggestion:s,onError:m}=i,c=X(),[g,f]=o.useState(!1),[j,w]=o.useState(null),N=o.useRef(null),S=a||(c==null?void 0:c.config),$=o.useCallback(C=>{const p=C.toLowerCase(),_=p.split(/\s+/);return ve.map(b=>{let u=0;return b.name===p?u+=100:b.name.includes(p)&&(u+=50),_.forEach(y=>{b.keywords.forEach(A=>{A===y?u+=30:(A.includes(y)||y.includes(A))&&(u+=15)})}),b.category===p&&(u+=20),{id:`icon_${b.name}`,name:b.name,displayName:b.name.replace(/-/g," ").replace(/\b\w/g,y=>y.toUpperCase()),category:b.category,style:r,library:t,relevanceScore:u,keywords:b.keywords,svgPath:b.svgPath}}).filter(b=>b.relevanceScore>0).sort((b,u)=>u.relevanceScore-b.relevanceScore).slice(0,n)},[t,r,n]),k=o.useCallback(async(C,p)=>{var u,y,A,R;const _=performance.now(),b=$(C);if(!S){const l={query:C,suggestions:b,latencyMs:performance.now()-_};return w(l),s==null||s(l),l}f(!0),(u=N.current)==null||u.abort(),N.current=new AbortController;try{const l=G(S),x=p?`
|
|
3215
3215
|
Context:
|
|
3216
|
-
- Component type: ${
|
|
3217
|
-
- Purpose: ${
|
|
3218
|
-
- Related icons: ${((
|
|
3219
|
-
- Theme: ${
|
|
3220
|
-
- Preferred style: ${
|
|
3221
|
-
- Preferred library: ${
|
|
3216
|
+
- Component type: ${p.componentType||"any"}
|
|
3217
|
+
- Purpose: ${p.purpose||"general"}
|
|
3218
|
+
- Related icons: ${((y=p.relatedIcons)==null?void 0:y.join(", "))||"none"}
|
|
3219
|
+
- Theme: ${p.theme||"light"}
|
|
3220
|
+
- Preferred style: ${p.preferredStyle||r}
|
|
3221
|
+
- Preferred library: ${p.preferredLibrary||t}`:"",D=(((R=(A=(await l.chat({messages:[{role:"system",content:`You are an icon recommendation expert. Suggest icons based on user query.
|
|
3222
3222
|
Return JSON array of 5-10 icon suggestions:
|
|
3223
3223
|
[{
|
|
3224
3224
|
"name": "icon-name",
|
|
@@ -3229,22 +3229,22 @@ Return JSON array of 5-10 icon suggestions:
|
|
|
3229
3229
|
"usage": "Brief usage description"
|
|
3230
3230
|
}]
|
|
3231
3231
|
|
|
3232
|
-
Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Suggest icons for: "${C}"${x}`}],temperature:.5,maxTokens:1024})).choices[0])==null?void 0:A.message)==null?void 0:R.content)||"").match(/\[[\s\S]*\]/);let J=[];if(D)try{J=JSON.parse(D[0]).map((
|
|
3232
|
+
Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Suggest icons for: "${C}"${x}`}],temperature:.5,maxTokens:1024})).choices[0])==null?void 0:A.message)==null?void 0:R.content)||"").match(/\[[\s\S]*\]/);let J=[];if(D)try{J=JSON.parse(D[0]).map((F,q)=>({id:F.id||`ai_icon_${q}`,name:F.name||"unknown",displayName:F.displayName||F.name||"Unknown",category:F.category||"action",style:(p==null?void 0:p.preferredStyle)||r,library:(p==null?void 0:p.preferredLibrary)||t,relevanceScore:F.relevanceScore||50,keywords:F.keywords||[],usage:F.usage}))}catch{}const H=Qt(b,J,n),Y={query:C,suggestions:H,latencyMs:performance.now()-_};return w(Y),s==null||s(Y),Y}catch(l){const x=l instanceof Error?l.message:"Suggestion failed",M={query:C,suggestions:b,latencyMs:performance.now()-_,error:x};return w(M),m==null||m(x),M}finally{f(!1)}},[S,t,r,n,$,s,m]),P=o.useCallback(C=>ve.filter(p=>p.category===C).map(p=>({id:`icon_${p.name}`,name:p.name,displayName:p.name.replace(/-/g," ").replace(/\b\w/g,_=>_.toUpperCase()),category:p.category,style:r,library:t,relevanceScore:100,keywords:p.keywords,svgPath:p.svgPath})),[t,r]),h=o.useMemo(()=>{const C=new Set;return ve.forEach(p=>C.add(p.category)),Array.from(C)},[]),d=o.useCallback(()=>{w(null)},[]),v=o.useCallback(()=>{var C;(C=N.current)==null||C.abort(),f(!1)},[]);return o.useEffect(()=>()=>{var C;(C=N.current)==null||C.abort()},[]),{suggestIcons:k,localSearch:$,getByCategory:P,categories:h,loading:g,lastResult:j,clearResults:d,abort:v,isConfigured:!!S}}function Qt(i,a,t){const r=new Set,n=[];for(const s of i)r.has(s.name)||(r.add(s.name),n.push(s));for(const s of a)!r.has(s.name)&&n.length<t&&(r.add(s.name),n.push(s));return n.slice(0,t)}function Zt({config:i,defaultLibrary:a="lucide",defaultStyle:t="outline",maxSuggestions:r=10,onSelect:n,showCategories:s=!0,showPreview:m=!0,className:c,style:g}){const[f,j]=o.useState(""),[w,N]=o.useState(null),[S,$]=o.useState(null),{suggestIcons:k,getByCategory:P,categories:h,loading:d,lastResult:v}=wa({config:i,defaultLibrary:a,defaultStyle:t,maxSuggestions:r}),C=async()=>{f.trim()&&(N(null),await k(f))},p=y=>{y.key==="Enter"&&C()},_=y=>{w===y?N(null):(N(y),j(""))},b=y=>{$(y),n==null||n(y)},u=w?P(w):(v==null?void 0:v.suggestions)||[];return e.jsxs("div",{className:`nice-icon-ai ${c||""}`,style:g,children:[e.jsxs("div",{className:"nice-icon-ai__search",children:[e.jsx("input",{type:"text",value:f,onChange:y=>j(y.target.value),onKeyDown:p,placeholder:"Search icons... (e.g., 'save', 'notification', 'user profile')",className:"nice-icon-ai__input",disabled:d}),e.jsx("button",{type:"button",onClick:C,className:"nice-icon-ai__search-btn",disabled:d||!f.trim(),children:d?e.jsx("span",{className:"nice-icon-ai__spinner"}):"🔍"})]}),s&&e.jsx("div",{className:"nice-icon-ai__categories",children:h.map(y=>e.jsx("button",{type:"button",className:`nice-icon-ai__category ${w===y?"nice-icon-ai__category--selected":""}`,onClick:()=>_(y),children:y},y))}),u.length>0&&e.jsx("div",{className:"nice-icon-ai__results",children:u.map(y=>e.jsxs("button",{type:"button",className:`nice-icon-ai__icon ${(S==null?void 0:S.id)===y.id?"nice-icon-ai__icon--selected":""}`,onClick:()=>b(y),title:y.displayName,children:[e.jsx(De,{icon:y}),e.jsx("span",{className:"nice-icon-ai__icon-name",children:y.displayName})]},y.id))}),m&&S&&e.jsxs("div",{className:"nice-icon-ai__preview",children:[e.jsx("div",{className:"nice-icon-ai__preview-icon",children:e.jsx(De,{icon:S,size:64})}),e.jsxs("div",{className:"nice-icon-ai__preview-info",children:[e.jsx("div",{className:"nice-icon-ai__preview-name",children:S.displayName}),e.jsxs("div",{className:"nice-icon-ai__preview-details",children:[e.jsxs("span",{children:["Category: ",S.category]}),e.jsxs("span",{children:["Library: ",S.library]})]}),e.jsx("div",{className:"nice-icon-ai__preview-keywords",children:S.keywords.map(y=>e.jsx("span",{className:"nice-icon-ai__keyword",children:y},y))}),S.usage&&e.jsx("div",{className:"nice-icon-ai__preview-usage",children:S.usage}),e.jsxs("div",{className:"nice-icon-ai__preview-actions",children:[e.jsx("button",{type:"button",onClick:()=>n==null?void 0:n(S),children:"✅ Use Icon"}),e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(S.name)},children:"📋 Copy Name"}),S.svgPath&&e.jsx("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(`<svg viewBox="0 0 24 24"><path d="${S.svgPath}" /></svg>`)},children:"📋 Copy SVG"})]})]})]}),e.jsx("style",{children:`
|
|
3233
3233
|
.nice-icon-ai {
|
|
3234
3234
|
font-family: var(--nice-font-family, system-ui, sans-serif);
|
|
3235
3235
|
}
|
|
3236
3236
|
|
|
3237
3237
|
.nice-icon-ai__search {
|
|
3238
3238
|
display: flex;
|
|
3239
|
-
gap: 8px;
|
|
3240
|
-
margin-bottom: 16px;
|
|
3239
|
+
gap: var(--nice-space-2, 8px);
|
|
3240
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
3241
3241
|
}
|
|
3242
3242
|
|
|
3243
3243
|
.nice-icon-ai__input {
|
|
3244
3244
|
flex: 1;
|
|
3245
|
-
padding: 12px 16px;
|
|
3245
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-4, 16px);
|
|
3246
3246
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
3247
|
-
border-radius: 8px;
|
|
3247
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
3248
3248
|
font-size: 14px;
|
|
3249
3249
|
}
|
|
3250
3250
|
|
|
@@ -3254,11 +3254,11 @@ Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Sugges
|
|
|
3254
3254
|
}
|
|
3255
3255
|
|
|
3256
3256
|
.nice-icon-ai__search-btn {
|
|
3257
|
-
padding: 12px 20px;
|
|
3257
|
+
padding: var(--nice-space-3, 12px) var(--nice-space-5, 20px);
|
|
3258
3258
|
background: var(--nice-primary, #0066cc);
|
|
3259
3259
|
color: white;
|
|
3260
3260
|
border: none;
|
|
3261
|
-
border-radius: 8px;
|
|
3261
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
3262
3262
|
cursor: pointer;
|
|
3263
3263
|
font-size: 16px;
|
|
3264
3264
|
}
|
|
@@ -3271,9 +3271,9 @@ Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Sugges
|
|
|
3271
3271
|
display: inline-block;
|
|
3272
3272
|
width: 16px;
|
|
3273
3273
|
height: 16px;
|
|
3274
|
-
border: 2px solid rgba(255, 255, 255, 0.3);
|
|
3274
|
+
border: 2px solid var(--nice-overlay-light-30, rgba(255, 255, 255, 0.3));
|
|
3275
3275
|
border-top-color: white;
|
|
3276
|
-
border-radius: 50
|
|
3276
|
+
border-radius: var(--nice-radius-full, 50%);
|
|
3277
3277
|
animation: nice-spin 0.8s linear infinite;
|
|
3278
3278
|
}
|
|
3279
3279
|
|
|
@@ -3284,14 +3284,14 @@ Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Sugges
|
|
|
3284
3284
|
.nice-icon-ai__categories {
|
|
3285
3285
|
display: flex;
|
|
3286
3286
|
flex-wrap: wrap;
|
|
3287
|
-
gap: 8px;
|
|
3288
|
-
margin-bottom: 16px;
|
|
3287
|
+
gap: var(--nice-space-2, 8px);
|
|
3288
|
+
margin-bottom: var(--nice-space-4, 16px);
|
|
3289
3289
|
}
|
|
3290
3290
|
|
|
3291
3291
|
.nice-icon-ai__category {
|
|
3292
|
-
padding: 6px 12px;
|
|
3292
|
+
padding: var(--nice-space-1-5, 6px) var(--nice-space-3, 12px);
|
|
3293
3293
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
3294
|
-
border-radius: 20px;
|
|
3294
|
+
border-radius: var(--nice-radius-xl, 20px);
|
|
3295
3295
|
background: white;
|
|
3296
3296
|
font-size: 12px;
|
|
3297
3297
|
cursor: pointer;
|
|
@@ -3312,18 +3312,18 @@ Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Sugges
|
|
|
3312
3312
|
.nice-icon-ai__results {
|
|
3313
3313
|
display: grid;
|
|
3314
3314
|
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
|
|
3315
|
-
gap: 12px;
|
|
3316
|
-
margin-bottom: 20px;
|
|
3315
|
+
gap: var(--nice-space-3, 12px);
|
|
3316
|
+
margin-bottom: var(--nice-space-5, 20px);
|
|
3317
3317
|
}
|
|
3318
3318
|
|
|
3319
3319
|
.nice-icon-ai__icon {
|
|
3320
3320
|
display: flex;
|
|
3321
3321
|
flex-direction: column;
|
|
3322
3322
|
align-items: center;
|
|
3323
|
-
gap: 8px;
|
|
3324
|
-
padding: 16px 8px;
|
|
3323
|
+
gap: var(--nice-space-2, 8px);
|
|
3324
|
+
padding: var(--nice-space-4, 16px) var(--nice-space-2, 8px);
|
|
3325
3325
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
3326
|
-
border-radius: 8px;
|
|
3326
|
+
border-radius: var(--nice-radius-lg, 8px);
|
|
3327
3327
|
background: white;
|
|
3328
3328
|
cursor: pointer;
|
|
3329
3329
|
transition: all 0.2s;
|
|
@@ -3332,7 +3332,7 @@ Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Sugges
|
|
|
3332
3332
|
.nice-icon-ai__icon:hover {
|
|
3333
3333
|
border-color: var(--nice-primary, #0066cc);
|
|
3334
3334
|
transform: translateY(-2px);
|
|
3335
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
3335
|
+
box-shadow: 0 4px 12px var(--nice-overlay-10, rgba(0, 0, 0, 0.1));
|
|
3336
3336
|
}
|
|
3337
3337
|
|
|
3338
3338
|
.nice-icon-ai__icon--selected {
|
|
@@ -3349,11 +3349,11 @@ Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Sugges
|
|
|
3349
3349
|
|
|
3350
3350
|
.nice-icon-ai__preview {
|
|
3351
3351
|
display: flex;
|
|
3352
|
-
gap: 24px;
|
|
3353
|
-
padding: 24px;
|
|
3352
|
+
gap: var(--nice-space-6, 24px);
|
|
3353
|
+
padding: var(--nice-space-6, 24px);
|
|
3354
3354
|
background: var(--nice-bg-subtle, #f8f9fa);
|
|
3355
|
-
border-radius: 12px;
|
|
3356
|
-
margin-top: 20px;
|
|
3355
|
+
border-radius: var(--nice-radius-xl, 12px);
|
|
3356
|
+
margin-top: var(--nice-space-5, 20px);
|
|
3357
3357
|
}
|
|
3358
3358
|
|
|
3359
3359
|
.nice-icon-ai__preview-icon {
|
|
@@ -3363,8 +3363,8 @@ Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Sugges
|
|
|
3363
3363
|
width: 100px;
|
|
3364
3364
|
height: 100px;
|
|
3365
3365
|
background: white;
|
|
3366
|
-
border-radius: 12px;
|
|
3367
|
-
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
|
|
3366
|
+
border-radius: var(--nice-radius-xl, 12px);
|
|
3367
|
+
box-shadow: 0 2px 8px var(--nice-overlay-5, rgba(0, 0, 0, 0.05));
|
|
3368
3368
|
}
|
|
3369
3369
|
|
|
3370
3370
|
.nice-icon-ai__preview-info {
|
|
@@ -3374,28 +3374,28 @@ Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Sugges
|
|
|
3374
3374
|
.nice-icon-ai__preview-name {
|
|
3375
3375
|
font-size: 20px;
|
|
3376
3376
|
font-weight: 600;
|
|
3377
|
-
margin-bottom: 8px;
|
|
3377
|
+
margin-bottom: var(--nice-space-2, 8px);
|
|
3378
3378
|
}
|
|
3379
3379
|
|
|
3380
3380
|
.nice-icon-ai__preview-details {
|
|
3381
3381
|
display: flex;
|
|
3382
|
-
gap: 16px;
|
|
3382
|
+
gap: var(--nice-space-4, 16px);
|
|
3383
3383
|
font-size: 13px;
|
|
3384
3384
|
color: var(--nice-text-muted, #666);
|
|
3385
|
-
margin-bottom: 12px;
|
|
3385
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
3386
3386
|
}
|
|
3387
3387
|
|
|
3388
3388
|
.nice-icon-ai__preview-keywords {
|
|
3389
3389
|
display: flex;
|
|
3390
3390
|
flex-wrap: wrap;
|
|
3391
|
-
gap: 6px;
|
|
3392
|
-
margin-bottom: 12px;
|
|
3391
|
+
gap: var(--nice-space-1-5, 6px);
|
|
3392
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
3393
3393
|
}
|
|
3394
3394
|
|
|
3395
3395
|
.nice-icon-ai__keyword {
|
|
3396
|
-
padding: 3px 8px;
|
|
3396
|
+
padding: var(--nice-space-0-75, 3px) var(--nice-space-2, 8px);
|
|
3397
3397
|
background: var(--nice-primary-light, rgba(0, 102, 204, 0.1));
|
|
3398
|
-
border-radius: 4px;
|
|
3398
|
+
border-radius: var(--nice-radius-sm, 4px);
|
|
3399
3399
|
font-size: 11px;
|
|
3400
3400
|
color: var(--nice-primary, #0066cc);
|
|
3401
3401
|
}
|
|
@@ -3404,18 +3404,18 @@ Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Sugges
|
|
|
3404
3404
|
font-size: 13px;
|
|
3405
3405
|
color: var(--nice-text-muted, #666);
|
|
3406
3406
|
font-style: italic;
|
|
3407
|
-
margin-bottom: 12px;
|
|
3407
|
+
margin-bottom: var(--nice-space-3, 12px);
|
|
3408
3408
|
}
|
|
3409
3409
|
|
|
3410
3410
|
.nice-icon-ai__preview-actions {
|
|
3411
3411
|
display: flex;
|
|
3412
|
-
gap: 8px;
|
|
3412
|
+
gap: var(--nice-space-2, 8px);
|
|
3413
3413
|
}
|
|
3414
3414
|
|
|
3415
3415
|
.nice-icon-ai__preview-actions button {
|
|
3416
|
-
padding: 8px 16px;
|
|
3416
|
+
padding: var(--nice-space-2, 8px) var(--nice-space-4, 16px);
|
|
3417
3417
|
border: 1px solid var(--nice-border-color, #e0e0e0);
|
|
3418
|
-
border-radius: 6px;
|
|
3418
|
+
border-radius: var(--nice-radius-md, 6px);
|
|
3419
3419
|
background: white;
|
|
3420
3420
|
font-size: 12px;
|
|
3421
3421
|
cursor: pointer;
|
|
@@ -3426,4 +3426,4 @@ Focus on semantic meaning and common UI patterns.`},{role:"user",content:`Sugges
|
|
|
3426
3426
|
color: white;
|
|
3427
3427
|
border: none;
|
|
3428
3428
|
}
|
|
3429
|
-
`})]})}function De({icon:
|
|
3429
|
+
`})]})}function De({icon:i,size:a=32}){return i.svgPath?e.jsx("svg",{viewBox:"0 0 24 24",width:a,height:a,fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:i.svgPath})}):e.jsx("div",{style:{width:a,height:a,display:"flex",alignItems:"center",justifyContent:"center",background:"var(--nice-bg-secondary, #f0f0f0)",borderRadius:6,fontSize:a*.5,fontWeight:600,color:"var(--nice-text-secondary, #666)"},children:i.name.charAt(0).toUpperCase()})}exports.ACCESSIBILITY_CHECKER_TEMPLATE=ye;exports.AnthropicProvider=ia;exports.AzureOpenAIProvider=ra;exports.CHART_CONFIG_TEMPLATE=ce;exports.CODE_COMPLETION_TEMPLATE=oe;exports.CostTracker=oa;exports.DATA_GRID_FILTER_TEMPLATE=re;exports.DATA_GRID_SORT_TEMPLATE=ne;exports.FORM_BUILDER_TEMPLATE=se;exports.GroqProvider=sa;exports.InMemoryCostStorage=Re;exports.LocalStorageCostStorage=ca;exports.NiceAIHintBubble=ke;exports.NiceAIProvider=ja;exports.NiceAccessibilityAI=Xt;exports.NiceChartAI=vt;exports.NiceCodeEditorAI=Ct;exports.NiceDataGridAI=mt;exports.NiceDataLabeler=tt;exports.NiceFormBuilderAI=gt;exports.NiceIconSuggestorAI=Zt;exports.NiceLayoutAI=Wt;exports.NiceMLStudio=et;exports.NiceModelInference=rt;exports.NiceReportBuilderAI=Ot;exports.NiceThemeGeneratorAI=Ft;exports.NiceWorkflowDesignerAI=Mt;exports.OllamaProvider=na;exports.OpenAIProvider=ta;exports.PROMPT_TEMPLATES=he;exports.REPORT_LAYOUT_TEMPLATE=de;exports.RateLimiter=Be;exports.ResilientLLMClient=la;exports.SUMMARIZE_DATA_TEMPLATE=we;exports.THEME_GENERATOR_TEMPLATE=ue;exports.TRANSLATION_TEMPLATE=_e;exports.WORKFLOW_GENERATOR_TEMPLATE=le;exports.build3DSceneContext=Ke;exports.buildAudioContext=Ve;exports.buildChartContext=Aa;exports.buildCodeEditorContext=We;exports.buildColorPickerContext=Ae;exports.buildDataGridContext=Ta;exports.buildDatePickerContext=Te;exports.buildDiagramLayoutContext=Ze;exports.buildFormFillContext=Ue;exports.buildGameEngineContext=Qe;exports.buildGraphicsContext=Ye;exports.buildHtmlEditorContext=Ge;exports.buildIconSearchContext=Xe;exports.buildNumberInputContext=Ce;exports.buildPresentationGenerateContext=ea;exports.buildSelectContext=Se;exports.buildSlideDesignContext=aa;exports.buildTextInputContext=Ne;exports.buildValidationContext=He;exports.colorControlContext=Qa;exports.compileTemplate=Z;exports.createLLMProvider=ae;exports.createProviderFromConfig=G;exports.createResilientClient=da;exports.createResilientClientWithDefaults=dt;exports.dateControlContext=Xa;exports.getTemplate=nt;exports.getTemplatesByCategory=st;exports.listTemplates=ct;exports.numberControlContext=Ka;exports.parseJSONResponse=qe;exports.parseSSEStream=Je;exports.selectControlContext=Ya;exports.textControlContext=Va;exports.useAI3DHint=Ba;exports.useAIAudioHint=Da;exports.useAICodeHint=Oa;exports.useAIColorHint=Ia;exports.useAIContext=X;exports.useAIDateHint=$a;exports.useAIDiagramLayout=Ua;exports.useAIFormFill=La;exports.useAIGraphicsHint=Fa;exports.useAIHtmlHint=Ea;exports.useAIIconSearch=Ja;exports.useAINpcHint=qa;exports.useAINumberHint=Ma;exports.useAIPresentationGenerate=Ha;exports.useAISelectHint=Pa;exports.useAISlideDesign=Wa;exports.useAITextHint=Ra;exports.useAIValidation=za;exports.useAccessibilityAI=_a;exports.useChartAI=ma;exports.useCodeEditorAI=ha;exports.useCostTracker=ot;exports.useDataGridAI=ua;exports.useFormBuilderAI=pa;exports.useIconSuggestorAI=wa;exports.useLayoutAI=va;exports.useNiceAIHint=V;exports.useReportBuilderAI=fa;exports.useThemeGeneratorAI=ba;exports.useWorkflowDesignerAI=ga;exports.withAIHint=Ga;
|