@hanzo/ui 5.3.19 → 5.3.22

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.
Files changed (229) hide show
  1. package/dist/3d/button.js +298 -1
  2. package/dist/3d/button.mjs +273 -1
  3. package/dist/3d/card.js +234 -1
  4. package/dist/3d/card.mjs +207 -1
  5. package/dist/3d/carousel.js +371 -1
  6. package/dist/3d/carousel.mjs +344 -1
  7. package/dist/3d/grid.js +362 -1
  8. package/dist/3d/grid.mjs +337 -1
  9. package/dist/3d/index.js +1518 -1
  10. package/dist/3d/index.mjs +1472 -1
  11. package/dist/3d/marquee.js +352 -1
  12. package/dist/3d/marquee.mjs +327 -1
  13. package/dist/3d/pin.js +46 -1
  14. package/dist/3d/pin.mjs +24 -1
  15. package/dist/accordion.js +80 -1
  16. package/dist/accordion.mjs +55 -1
  17. package/dist/alert-dialog.js +220 -1
  18. package/dist/alert-dialog.mjs +187 -1
  19. package/dist/alert.js +68 -1
  20. package/dist/alert.mjs +64 -1
  21. package/dist/animation/animated-background.js +424 -1
  22. package/dist/animation/animated-background.mjs +418 -1
  23. package/dist/animation/animated-beam.js +119 -1
  24. package/dist/animation/animated-beam.mjs +97 -1
  25. package/dist/animation/animated-cursor.js +275 -1
  26. package/dist/animation/animated-cursor.mjs +270 -1
  27. package/dist/animation/animated-icon.js +357 -2
  28. package/dist/animation/animated-icon.mjs +351 -2
  29. package/dist/animation/animated-list.js +339 -1
  30. package/dist/animation/animated-list.mjs +333 -1
  31. package/dist/animation/animated-number.js +283 -1
  32. package/dist/animation/animated-number.mjs +277 -1
  33. package/dist/animation/animated-testimonials.js +97 -1
  34. package/dist/animation/animated-testimonials.mjs +75 -1
  35. package/dist/animation/animated-tooltip.js +67 -1
  36. package/dist/animation/animated-tooltip.mjs +45 -1
  37. package/dist/animation/apple-cards-carousel.js +308 -1
  38. package/dist/animation/apple-cards-carousel.mjs +285 -1
  39. package/dist/animation/apple-hello-effect.js +60 -1
  40. package/dist/animation/apple-hello-effect.mjs +38 -1
  41. package/dist/animation/index.js +1952 -2
  42. package/dist/animation/index.mjs +1921 -2
  43. package/dist/avatar.js +71 -1
  44. package/dist/avatar.mjs +47 -1
  45. package/dist/badge.js +66 -1
  46. package/dist/badge.mjs +40 -1
  47. package/dist/blocks/index.js +1665 -2
  48. package/dist/blocks/index.mjs +1626 -2
  49. package/dist/breadcrumb.js +107 -1
  50. package/dist/breadcrumb.mjs +99 -1
  51. package/dist/calendar.js +189 -1
  52. package/dist/calendar.mjs +164 -1
  53. package/dist/carousel.js +278 -1
  54. package/dist/carousel.mjs +249 -1
  55. package/dist/checkbox.js +60 -1
  56. package/dist/checkbox.mjs +35 -1
  57. package/dist/code/block.js +226 -2
  58. package/dist/code/block.mjs +203 -2
  59. package/dist/code/compare.js +445 -5
  60. package/dist/code/compare.mjs +422 -5
  61. package/dist/code/diff.js +430 -12
  62. package/dist/code/diff.mjs +406 -11
  63. package/dist/code/editor.js +243 -1
  64. package/dist/code/editor.mjs +218 -1
  65. package/dist/code/explorer.js +291 -1
  66. package/dist/code/explorer.mjs +268 -1
  67. package/dist/code/index.js +2515 -26
  68. package/dist/code/index.mjs +2472 -24
  69. package/dist/code/preview.js +364 -6
  70. package/dist/code/preview.mjs +341 -6
  71. package/dist/code/snippet.js +274 -2
  72. package/dist/code/snippet.mjs +250 -2
  73. package/dist/code/tabs.js +75 -1
  74. package/dist/code/tabs.mjs +53 -1
  75. package/dist/code/terminal.js +437 -3
  76. package/dist/code/terminal.mjs +414 -3
  77. package/dist/collapsible.js +33 -1
  78. package/dist/collapsible.mjs +9 -1
  79. package/dist/command.js +262 -1
  80. package/dist/command.mjs +232 -1
  81. package/dist/context-menu.js +207 -1
  82. package/dist/context-menu.mjs +171 -1
  83. package/dist/device/index.js +3 -1
  84. package/dist/device/index.mjs +2 -0
  85. package/dist/dialog.js +151 -1
  86. package/dist/dialog.mjs +121 -1
  87. package/dist/dock/basic.js +174 -1
  88. package/dist/dock/basic.mjs +151 -1
  89. package/dist/dock/index.js +628 -1
  90. package/dist/dock/index.mjs +601 -1
  91. package/dist/dock/limelight-nav.js +295 -1
  92. package/dist/dock/limelight-nav.mjs +274 -1
  93. package/dist/dock/macos.js +141 -1
  94. package/dist/dock/macos.mjs +118 -1
  95. package/dist/dock/menu.js +70 -1
  96. package/dist/dock/menu.mjs +48 -1
  97. package/dist/dock/message.js +144 -1
  98. package/dist/dock/message.mjs +122 -1
  99. package/dist/drawer.js +115 -1
  100. package/dist/drawer.mjs +103 -1
  101. package/dist/dropdown-menu.js +202 -1
  102. package/dist/dropdown-menu.mjs +166 -1
  103. package/dist/finance/AdvancedChart.js +48 -2
  104. package/dist/finance/AdvancedChart.mjs +46 -2
  105. package/dist/finance/CompanyProfile.js +48 -2
  106. package/dist/finance/CompanyProfile.mjs +46 -2
  107. package/dist/finance/CryptoScreener.js +45 -2
  108. package/dist/finance/CryptoScreener.mjs +43 -2
  109. package/dist/finance/Financials.js +52 -2
  110. package/dist/finance/Financials.mjs +50 -2
  111. package/dist/finance/ForexScreener.js +46 -2
  112. package/dist/finance/ForexScreener.mjs +44 -2
  113. package/dist/finance/MarketOverview.js +104 -2
  114. package/dist/finance/MarketOverview.mjs +102 -2
  115. package/dist/finance/NewsTimeline.js +44 -2
  116. package/dist/finance/NewsTimeline.mjs +42 -2
  117. package/dist/finance/OrderEntry.js +131 -1
  118. package/dist/finance/OrderEntry.mjs +129 -1
  119. package/dist/finance/OrdersHistory.js +64 -1
  120. package/dist/finance/OrdersHistory.mjs +62 -1
  121. package/dist/finance/PositionsList.js +80 -1
  122. package/dist/finance/PositionsList.mjs +78 -1
  123. package/dist/finance/StockScreener.js +46 -2
  124. package/dist/finance/StockScreener.mjs +44 -2
  125. package/dist/finance/SymbolInfo.js +46 -2
  126. package/dist/finance/SymbolInfo.mjs +44 -2
  127. package/dist/finance/TechnicalAnalysis.js +54 -2
  128. package/dist/finance/TechnicalAnalysis.mjs +52 -2
  129. package/dist/finance/TickerTape.js +56 -2
  130. package/dist/finance/TickerTape.mjs +54 -2
  131. package/dist/finance/TradingPanel.js +191 -1
  132. package/dist/finance/TradingPanel.mjs +189 -1
  133. package/dist/finance/index.js +930 -2
  134. package/dist/finance/index.mjs +914 -2
  135. package/dist/form/index.js +155 -1
  136. package/dist/form/index.mjs +125 -1
  137. package/dist/form.js +172 -1
  138. package/dist/form.mjs +142 -1
  139. package/dist/hover-card.js +58 -1
  140. package/dist/hover-card.mjs +34 -1
  141. package/dist/index.js +8467 -192
  142. package/dist/index.mjs +8087 -192
  143. package/dist/input-otp.js +79 -1
  144. package/dist/input-otp.mjs +54 -1
  145. package/dist/lib/utils.js +28 -1
  146. package/dist/lib/utils.mjs +24 -1
  147. package/dist/navigation/index.js +98 -1
  148. package/dist/navigation/index.mjs +79 -1
  149. package/dist/navigation-menu.js +149 -1
  150. package/dist/navigation-menu.mjs +116 -1
  151. package/dist/pattern/grid-pattern.js +326 -3
  152. package/dist/pattern/grid-pattern.mjs +303 -3
  153. package/dist/pattern/index.js +326 -3
  154. package/dist/pattern/index.mjs +303 -3
  155. package/dist/popover.js +63 -1
  156. package/dist/popover.mjs +37 -1
  157. package/dist/primitives/index.js +8467 -192
  158. package/dist/primitives/index.mjs +8087 -192
  159. package/dist/primitives-export.js +8467 -192
  160. package/dist/primitives-export.mjs +8087 -192
  161. package/dist/progress.js +62 -1
  162. package/dist/progress.mjs +37 -1
  163. package/dist/project/gantt.js +65 -1
  164. package/dist/project/gantt.mjs +43 -1
  165. package/dist/project/index.js +636 -1
  166. package/dist/project/index.mjs +611 -1
  167. package/dist/project/kanban.js +597 -1
  168. package/dist/project/kanban.mjs +572 -1
  169. package/dist/project/list.js +35 -1
  170. package/dist/project/list.mjs +12 -1
  171. package/dist/radio-group.js +68 -1
  172. package/dist/radio-group.mjs +45 -1
  173. package/dist/resizable.js +72 -1
  174. package/dist/resizable.mjs +48 -1
  175. package/dist/scroll-area.js +89 -1
  176. package/dist/scroll-area.mjs +66 -1
  177. package/dist/select.js +140 -1
  178. package/dist/select.mjs +111 -1
  179. package/dist/separator.js +59 -1
  180. package/dist/separator.mjs +34 -1
  181. package/dist/sheet.js +148 -1
  182. package/dist/sheet.mjs +117 -1
  183. package/dist/skeleton.js +32 -1
  184. package/dist/skeleton.mjs +27 -1
  185. package/dist/slider.js +99 -1
  186. package/dist/slider.mjs +73 -1
  187. package/dist/sonner.js +34 -1
  188. package/dist/sonner.mjs +29 -1
  189. package/dist/switch.js +62 -1
  190. package/dist/switch.mjs +37 -1
  191. package/dist/table.js +110 -1
  192. package/dist/table.mjs +101 -1
  193. package/dist/tabs.js +82 -1
  194. package/dist/tabs.mjs +57 -1
  195. package/dist/tailwind/index.js +2023 -1
  196. package/dist/tailwind/index.mjs +2011 -1
  197. package/dist/textarea.js +78 -1
  198. package/dist/textarea.mjs +56 -1
  199. package/dist/toggle-group.js +118 -1
  200. package/dist/toggle-group.mjs +93 -1
  201. package/dist/toggle.js +71 -1
  202. package/dist/toggle.mjs +48 -1
  203. package/dist/tooltip.js +67 -1
  204. package/dist/tooltip.mjs +40 -1
  205. package/dist/types/index.js +57 -1
  206. package/dist/types/index.mjs +51 -1
  207. package/dist/ui/announcement.js +129 -1
  208. package/dist/ui/announcement.mjs +107 -1
  209. package/dist/ui/avatar-group.js +88 -1
  210. package/dist/ui/avatar-group.mjs +65 -1
  211. package/dist/ui/banner.js +85 -1
  212. package/dist/ui/banner.mjs +62 -1
  213. package/dist/ui/cursor.js +78 -1
  214. package/dist/ui/cursor.mjs +56 -1
  215. package/dist/ui/index.js +475 -1
  216. package/dist/ui/index.mjs +442 -1
  217. package/dist/ui/marquee.js +74 -1
  218. package/dist/ui/marquee.mjs +52 -1
  219. package/dist/ui/pill.js +85 -1
  220. package/dist/ui/pill.mjs +62 -1
  221. package/dist/ui/spinner.js +28 -1
  222. package/dist/ui/spinner.mjs +26 -1
  223. package/dist/ui/tags.js +101 -1
  224. package/dist/ui/tags.mjs +79 -1
  225. package/dist/ui/ticker.js +73 -1
  226. package/dist/ui/ticker.mjs +51 -1
  227. package/dist/util/index.js +457 -1
  228. package/dist/util/index.mjs +399 -1
  229. package/package.json +1 -1
@@ -1,12 +1,407 @@
1
- import*as a from'react';import {cva}from'class-variance-authority';import {GitCompare,Plus,Minus,Square,SplitSquareHorizontal,Check,Copy}from'lucide-react';import {codeToHtml}from'shiki';import {cn}from'@hanzo/ui/lib/utils';import {Badge}from'@hanzo/ui/badge';import {Button}from'@hanzo/ui/button';import {Skeleton}from'@hanzo/ui/skeleton';import {ToggleGroup,ToggleGroupItem}from'@hanzo/ui/toggle-group';import {jsx,jsxs,Fragment}from'react/jsx-runtime';var ee=Object.defineProperty;var x=(f,p)=>ee(f,"name",{value:p,configurable:true});var me=cva("relative overflow-hidden rounded-lg border bg-muted/50",{variants:{theme:{dark:"bg-slate-950 border-slate-800",light:"bg-slate-50 border-slate-200",github:"bg-white border-slate-200","github-dark":"bg-slate-900 border-slate-700"},size:{sm:"text-xs",default:"text-sm",lg:"text-base"}},defaultVariants:{theme:"dark",size:"default"}}),C=a.memo(({change:f,showLineNumbers:p,isUnified:g=false,highlightedContent:u})=>{let l=x(()=>{let i="group relative flex min-h-[1.5rem] items-center py-0.5";if(g)switch(f.type){case "add":return cn(i,"bg-green-500/10 border-l-2 border-l-green-500");case "remove":return cn(i,"bg-red-500/10 border-l-2 border-l-red-500");default:return cn(i,"hover:bg-muted/50")}return cn(i,"hover:bg-muted/50")},"getLineClasses"),o=x(()=>{if(!g)return null;switch(f.type){case "add":return jsx(Plus,{className:"h-3 w-3 text-green-500 mr-2 flex-shrink-0"});case "remove":return jsx(Minus,{className:"h-3 w-3 text-red-500 mr-2 flex-shrink-0"});default:return jsx("span",{className:"w-3 mr-2 flex-shrink-0"})}},"getLinePrefix");return jsx("div",{className:l(),children:jsxs("div",{className:"flex items-center px-4 w-full",children:[p&&jsx("div",{className:"flex items-center gap-2 mr-4",children:g?jsx("span",{className:"inline-block w-8 select-none text-right text-xs text-muted-foreground",children:f.lineNumber}):jsxs(Fragment,{children:[jsx("span",{className:"inline-block w-8 select-none text-right text-xs text-muted-foreground",children:f.oldLineNumber||""}),jsx("span",{className:"inline-block w-8 select-none text-right text-xs text-muted-foreground",children:f.newLineNumber||""})]})}),o(),jsx("div",{className:"flex-1 overflow-x-auto font-mono",dangerouslySetInnerHTML:{__html:u||f.content}})]})})});C.displayName="DiffLine";function B(f,p){let g=f.split(`
2
- `),u=p.split(`
3
- `),l=[],o=0,i=0,h=1;for(;o<g.length||i<u.length;){let N=g[o],v=u[i];o>=g.length?(l.push({type:"add",lineNumber:h++,content:v,newLineNumber:i+1}),i++):i>=u.length?(l.push({type:"remove",lineNumber:h++,content:N,oldLineNumber:o+1}),o++):N===v?(l.push({type:"unchanged",lineNumber:h++,content:N,oldLineNumber:o+1,newLineNumber:i+1}),o++,i++):(l.push({type:"remove",lineNumber:h++,content:N,oldLineNumber:o+1}),l.push({type:"add",lineNumber:h++,content:v,newLineNumber:i+1}),o++,i++);}return l}x(B,"generateDiff");var ce=a.forwardRef(({className:f,theme:p,size:g,oldCode:u,newCode:l,language:o="text",filename:i,oldFilename:h,newFilename:N,showLineNumbers:v=true,showCopyButton:_=true,maxHeight:A="500px",defaultView:U="unified",collapseUnchanged:k=false,contextLines:y=3,...F},J)=>{let[L,K]=a.useState(U),[D,S]=a.useState(false),[Q,T]=a.useState(true),[R,H]=a.useState(""),[M,V]=a.useState(""),[m,P]=a.useState([]),$={dark:"github-dark",light:"github-light",github:"github-light","github-dark":"github-dark"};a.useEffect(()=>{x(async()=>{T(true);try{let[n,t]=await Promise.all([codeToHtml(u,{lang:o,theme:$[p||"dark"]}),codeToHtml(l,{lang:o,theme:$[p||"dark"]})]),r=x(c=>{let E=document.createElement("div");return E.innerHTML=c,E.querySelector("code")?.innerHTML||c},"extractContent");H(r(n)),V(r(t));let b=B(u,l);P(b);}catch(n){console.error("Failed to highlight code:",n),H(u),V(l),P(B(u,l));}finally{T(false);}},"highlightCode")();},[u,l,o,p]);let W=a.useCallback(async()=>{try{let s=L==="unified"?m.map(n=>`${n.type==="add"?"+":n.type==="remove"?"-":" "}${n.content}`).join(`
4
- `):`--- ${h||"old"}
5
- +++ ${N||"new"}
6
- ${u}
1
+ "use client";
2
+ import * as React from 'react';
3
+ import { cva } from 'class-variance-authority';
4
+ import { GitCompare, Plus, Minus, Square, SplitSquareHorizontal, Check, Copy } from 'lucide-react';
5
+ import { codeToHtml } from 'shiki';
6
+ import { cn } from '@hanzo/ui/lib/utils';
7
+ import { Badge } from '@hanzo/ui/badge';
8
+ import { Button } from '@hanzo/ui/button';
9
+ import { Skeleton } from '@hanzo/ui/skeleton';
10
+ import { ToggleGroup, ToggleGroupItem } from '@hanzo/ui/toggle-group';
11
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
12
 
8
- ${l}`;await navigator.clipboard.writeText(s),S(!0),setTimeout(()=>S(!1),2e3);}catch(s){console.error("Failed to copy diff:",s);}},[m,L,u,l,h,N]),X=a.useMemo(()=>{if(!k)return m;let s=[],n=0;for(;n<m.length;){let t=m[n];if(t.type!=="unchanged"){s.push(t),n++;continue}let r=n;for(;n<m.length&&m[n].type==="unchanged";)n++;let b=n-r;if(b<=y*2)for(let c=r;c<n;c++)s.push(m[c]);else {for(let c=r;c<r+y;c++)s.push(m[c]);s.push({type:"unchanged",lineNumber:-1,content:`... ${b-y*2} unchanged lines ...`});for(let c=n-y;c<n;c++)s.push(m[c]);}}return s},[m,k,y]),I=a.useMemo(()=>{let s=m.filter(t=>t.type==="add").length,n=m.filter(t=>t.type==="remove").length;return {additions:s,deletions:n}},[m]),Y=x(()=>{let s=R.split(`
9
- `),n=M.split(`
10
- `);return jsx("div",{className:"font-mono",children:X.map((t,r)=>{if(t.lineNumber===-1)return jsx("div",{className:"flex items-center justify-center py-2 text-muted-foreground bg-muted/30",children:jsx("span",{className:"text-xs",children:t.content})},r);let b=t.content;return t.type==="add"&&t.newLineNumber?b=n[t.newLineNumber-1]||t.content:(t.type==="remove"&&t.oldLineNumber||t.type==="unchanged"&&t.oldLineNumber)&&(b=s[t.oldLineNumber-1]||t.content),jsx(C,{change:t,showLineNumbers:v,isUnified:true,highlightedContent:b},r)})})},"renderUnifiedView"),Z=x(()=>{let s=R.split(`
11
- `),n=M.split(`
12
- `);return jsxs("div",{className:"grid grid-cols-2 gap-0",children:[jsxs("div",{className:"border-r",children:[jsx("div",{className:"border-b px-4 py-2 bg-red-500/10",children:jsx("span",{className:"text-sm font-medium text-red-600 dark:text-red-400",children:h||i||"Old"})}),jsx("div",{className:"font-mono",children:s.map((t,r)=>jsx(C,{change:{type:"remove",lineNumber:r+1,content:t,oldLineNumber:r+1},showLineNumbers:v,highlightedContent:t},`old-${r}`))})]}),jsxs("div",{children:[jsx("div",{className:"border-b px-4 py-2 bg-green-500/10",children:jsx("span",{className:"text-sm font-medium text-green-600 dark:text-green-400",children:N||i||"New"})}),jsx("div",{className:"font-mono",children:n.map((t,r)=>jsx(C,{change:{type:"add",lineNumber:r+1,content:t,newLineNumber:r+1},showLineNumbers:v,highlightedContent:t},`new-${r}`))})]})]})},"renderSplitView");return jsxs("div",{ref:J,className:cn(me({theme:p,size:g,className:f})),...F,children:[jsxs("div",{className:"flex items-center justify-between border-b px-4 py-2",children:[jsxs("div",{className:"flex items-center gap-4",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx(GitCompare,{className:"h-4 w-4 text-muted-foreground"}),i&&jsx("span",{className:"text-sm font-medium",children:i}),o&&jsx(Badge,{variant:"secondary",className:"text-xs",children:o})]}),jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[jsxs("span",{className:"flex items-center gap-1",children:[jsx(Plus,{className:"h-3 w-3 text-green-500"}),I.additions]}),jsxs("span",{className:"flex items-center gap-1",children:[jsx(Minus,{className:"h-3 w-3 text-red-500"}),I.deletions]})]})]}),jsxs("div",{className:"flex items-center gap-2",children:[jsxs(ToggleGroup,{type:"single",value:L,onValueChange:s=>s&&K(s),size:"sm",children:[jsx(ToggleGroupItem,{value:"unified","aria-label":"Unified view",children:jsx(Square,{className:"h-3 w-3"})}),jsx(ToggleGroupItem,{value:"split","aria-label":"Split view",children:jsx(SplitSquareHorizontal,{className:"h-3 w-3"})})]}),_&&jsxs(Button,{variant:"ghost",size:"sm",onClick:W,className:"h-8 w-8 p-0",children:[D?jsx(Check,{className:"h-3.5 w-3.5 text-green-500"}):jsx(Copy,{className:"h-3.5 w-3.5"}),jsx("span",{className:"sr-only",children:D?"Copied":"Copy diff"})]})]})]}),jsx("div",{className:"overflow-auto",style:{maxHeight:A},children:Q?jsx("div",{className:"p-4 space-y-2",children:Array.from({length:10}).map((s,n)=>jsxs("div",{className:"flex items-center gap-4",children:[v&&jsx(Skeleton,{className:"h-4 w-8"}),jsx(Skeleton,{className:"h-4 flex-1"})]},n))}):L==="unified"?Y():Z()})]})});ce.displayName="CodeDiff";export{ce as CodeDiff,me as codeDiffVariants};
13
+ var __defProp = Object.defineProperty;
14
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
15
+ var codeDiffVariants = cva(
16
+ "relative overflow-hidden rounded-lg border bg-muted/50",
17
+ {
18
+ variants: {
19
+ theme: {
20
+ dark: "bg-slate-950 border-slate-800",
21
+ light: "bg-slate-50 border-slate-200",
22
+ github: "bg-white border-slate-200",
23
+ "github-dark": "bg-slate-900 border-slate-700"
24
+ },
25
+ size: {
26
+ sm: "text-xs",
27
+ default: "text-sm",
28
+ lg: "text-base"
29
+ }
30
+ },
31
+ defaultVariants: {
32
+ theme: "dark",
33
+ size: "default"
34
+ }
35
+ }
36
+ );
37
+ var DiffLine = React.memo(
38
+ ({
39
+ change,
40
+ showLineNumbers,
41
+ isUnified = false,
42
+ highlightedContent
43
+ }) => {
44
+ const getLineClasses = /* @__PURE__ */ __name(() => {
45
+ const base = "group relative flex min-h-[1.5rem] items-center py-0.5";
46
+ if (isUnified) {
47
+ switch (change.type) {
48
+ case "add":
49
+ return cn(base, "bg-green-500/10 border-l-2 border-l-green-500");
50
+ case "remove":
51
+ return cn(base, "bg-red-500/10 border-l-2 border-l-red-500");
52
+ default:
53
+ return cn(base, "hover:bg-muted/50");
54
+ }
55
+ }
56
+ return cn(base, "hover:bg-muted/50");
57
+ }, "getLineClasses");
58
+ const getLinePrefix = /* @__PURE__ */ __name(() => {
59
+ if (!isUnified) return null;
60
+ switch (change.type) {
61
+ case "add":
62
+ return /* @__PURE__ */ jsx(Plus, { className: "h-3 w-3 text-green-500 mr-2 flex-shrink-0" });
63
+ case "remove":
64
+ return /* @__PURE__ */ jsx(Minus, { className: "h-3 w-3 text-red-500 mr-2 flex-shrink-0" });
65
+ default:
66
+ return /* @__PURE__ */ jsx("span", { className: "w-3 mr-2 flex-shrink-0" });
67
+ }
68
+ }, "getLinePrefix");
69
+ return /* @__PURE__ */ jsx("div", { className: getLineClasses(), children: /* @__PURE__ */ jsxs("div", { className: "flex items-center px-4 w-full", children: [
70
+ showLineNumbers && /* @__PURE__ */ jsx("div", { className: "flex items-center gap-2 mr-4", children: !isUnified ? /* @__PURE__ */ jsxs(Fragment, { children: [
71
+ /* @__PURE__ */ jsx("span", { className: "inline-block w-8 select-none text-right text-xs text-muted-foreground", children: change.oldLineNumber || "" }),
72
+ /* @__PURE__ */ jsx("span", { className: "inline-block w-8 select-none text-right text-xs text-muted-foreground", children: change.newLineNumber || "" })
73
+ ] }) : /* @__PURE__ */ jsx("span", { className: "inline-block w-8 select-none text-right text-xs text-muted-foreground", children: change.lineNumber }) }),
74
+ getLinePrefix(),
75
+ /* @__PURE__ */ jsx(
76
+ "div",
77
+ {
78
+ className: "flex-1 overflow-x-auto font-mono",
79
+ dangerouslySetInnerHTML: {
80
+ __html: highlightedContent || change.content
81
+ }
82
+ }
83
+ )
84
+ ] }) });
85
+ }
86
+ );
87
+ DiffLine.displayName = "DiffLine";
88
+ function generateDiff(oldCode, newCode) {
89
+ const oldLines = oldCode.split("\n");
90
+ const newLines = newCode.split("\n");
91
+ const changes = [];
92
+ let oldIndex = 0;
93
+ let newIndex = 0;
94
+ let lineNumber = 1;
95
+ while (oldIndex < oldLines.length || newIndex < newLines.length) {
96
+ const oldLine = oldLines[oldIndex];
97
+ const newLine = newLines[newIndex];
98
+ if (oldIndex >= oldLines.length) {
99
+ changes.push({
100
+ type: "add",
101
+ lineNumber: lineNumber++,
102
+ content: newLine,
103
+ newLineNumber: newIndex + 1
104
+ });
105
+ newIndex++;
106
+ } else if (newIndex >= newLines.length) {
107
+ changes.push({
108
+ type: "remove",
109
+ lineNumber: lineNumber++,
110
+ content: oldLine,
111
+ oldLineNumber: oldIndex + 1
112
+ });
113
+ oldIndex++;
114
+ } else if (oldLine === newLine) {
115
+ changes.push({
116
+ type: "unchanged",
117
+ lineNumber: lineNumber++,
118
+ content: oldLine,
119
+ oldLineNumber: oldIndex + 1,
120
+ newLineNumber: newIndex + 1
121
+ });
122
+ oldIndex++;
123
+ newIndex++;
124
+ } else {
125
+ changes.push({
126
+ type: "remove",
127
+ lineNumber: lineNumber++,
128
+ content: oldLine,
129
+ oldLineNumber: oldIndex + 1
130
+ });
131
+ changes.push({
132
+ type: "add",
133
+ lineNumber: lineNumber++,
134
+ content: newLine,
135
+ newLineNumber: newIndex + 1
136
+ });
137
+ oldIndex++;
138
+ newIndex++;
139
+ }
140
+ }
141
+ return changes;
142
+ }
143
+ __name(generateDiff, "generateDiff");
144
+ var CodeDiff = React.forwardRef(
145
+ ({
146
+ className,
147
+ theme,
148
+ size,
149
+ oldCode,
150
+ newCode,
151
+ language = "text",
152
+ filename,
153
+ oldFilename,
154
+ newFilename,
155
+ showLineNumbers = true,
156
+ showCopyButton = true,
157
+ maxHeight = "500px",
158
+ defaultView = "unified",
159
+ collapseUnchanged = false,
160
+ contextLines = 3,
161
+ ...props
162
+ }, ref) => {
163
+ const [view, setView] = React.useState(defaultView);
164
+ const [copied, setCopied] = React.useState(false);
165
+ const [isLoading, setIsLoading] = React.useState(true);
166
+ const [highlightedOldCode, setHighlightedOldCode] = React.useState("");
167
+ const [highlightedNewCode, setHighlightedNewCode] = React.useState("");
168
+ const [changes, setChanges] = React.useState([]);
169
+ const themeMap = {
170
+ dark: "github-dark",
171
+ light: "github-light",
172
+ github: "github-light",
173
+ "github-dark": "github-dark"
174
+ };
175
+ React.useEffect(() => {
176
+ const highlightCode = /* @__PURE__ */ __name(async () => {
177
+ setIsLoading(true);
178
+ try {
179
+ const [oldHighlighted, newHighlighted] = await Promise.all([
180
+ codeToHtml(oldCode, {
181
+ lang: language,
182
+ theme: themeMap[theme || "dark"]
183
+ }),
184
+ codeToHtml(newCode, {
185
+ lang: language,
186
+ theme: themeMap[theme || "dark"]
187
+ })
188
+ ]);
189
+ const extractContent = /* @__PURE__ */ __name((html) => {
190
+ const tempDiv = document.createElement("div");
191
+ tempDiv.innerHTML = html;
192
+ const codeElement = tempDiv.querySelector("code");
193
+ return codeElement?.innerHTML || html;
194
+ }, "extractContent");
195
+ setHighlightedOldCode(extractContent(oldHighlighted));
196
+ setHighlightedNewCode(extractContent(newHighlighted));
197
+ const diffChanges = generateDiff(oldCode, newCode);
198
+ setChanges(diffChanges);
199
+ } catch (error) {
200
+ console.error("Failed to highlight code:", error);
201
+ setHighlightedOldCode(oldCode);
202
+ setHighlightedNewCode(newCode);
203
+ setChanges(generateDiff(oldCode, newCode));
204
+ } finally {
205
+ setIsLoading(false);
206
+ }
207
+ }, "highlightCode");
208
+ highlightCode();
209
+ }, [oldCode, newCode, language, theme]);
210
+ const copyToClipboard = React.useCallback(async () => {
211
+ try {
212
+ const diffText = view === "unified" ? changes.map((change) => {
213
+ const prefix = change.type === "add" ? "+" : change.type === "remove" ? "-" : " ";
214
+ return `${prefix}${change.content}`;
215
+ }).join("\n") : `--- ${oldFilename || "old"}
216
+ +++ ${newFilename || "new"}
217
+ ${oldCode}
218
+
219
+ ${newCode}`;
220
+ await navigator.clipboard.writeText(diffText);
221
+ setCopied(true);
222
+ setTimeout(() => setCopied(false), 2e3);
223
+ } catch (error) {
224
+ console.error("Failed to copy diff:", error);
225
+ }
226
+ }, [changes, view, oldCode, newCode, oldFilename, newFilename]);
227
+ const filteredChanges = React.useMemo(() => {
228
+ if (!collapseUnchanged) return changes;
229
+ const result = [];
230
+ let i = 0;
231
+ while (i < changes.length) {
232
+ const change = changes[i];
233
+ if (change.type !== "unchanged") {
234
+ result.push(change);
235
+ i++;
236
+ continue;
237
+ }
238
+ const unchangedStart = i;
239
+ while (i < changes.length && changes[i].type === "unchanged") {
240
+ i++;
241
+ }
242
+ const unchangedCount = i - unchangedStart;
243
+ if (unchangedCount <= contextLines * 2) {
244
+ for (let j = unchangedStart; j < i; j++) {
245
+ result.push(changes[j]);
246
+ }
247
+ } else {
248
+ for (let j = unchangedStart; j < unchangedStart + contextLines; j++) {
249
+ result.push(changes[j]);
250
+ }
251
+ result.push({
252
+ type: "unchanged",
253
+ lineNumber: -1,
254
+ content: `... ${unchangedCount - contextLines * 2} unchanged lines ...`
255
+ });
256
+ for (let j = i - contextLines; j < i; j++) {
257
+ result.push(changes[j]);
258
+ }
259
+ }
260
+ }
261
+ return result;
262
+ }, [changes, collapseUnchanged, contextLines]);
263
+ const stats = React.useMemo(() => {
264
+ const additions = changes.filter((c) => c.type === "add").length;
265
+ const deletions = changes.filter((c) => c.type === "remove").length;
266
+ return { additions, deletions };
267
+ }, [changes]);
268
+ const renderUnifiedView = /* @__PURE__ */ __name(() => {
269
+ const oldLines = highlightedOldCode.split("\n");
270
+ const newLines = highlightedNewCode.split("\n");
271
+ return /* @__PURE__ */ jsx("div", { className: "font-mono", children: filteredChanges.map((change, index) => {
272
+ if (change.lineNumber === -1) {
273
+ return /* @__PURE__ */ jsx(
274
+ "div",
275
+ {
276
+ className: "flex items-center justify-center py-2 text-muted-foreground bg-muted/30",
277
+ children: /* @__PURE__ */ jsx("span", { className: "text-xs", children: change.content })
278
+ },
279
+ index
280
+ );
281
+ }
282
+ let highlightedContent = change.content;
283
+ if (change.type === "add" && change.newLineNumber) {
284
+ highlightedContent = newLines[change.newLineNumber - 1] || change.content;
285
+ } else if (change.type === "remove" && change.oldLineNumber) {
286
+ highlightedContent = oldLines[change.oldLineNumber - 1] || change.content;
287
+ } else if (change.type === "unchanged" && change.oldLineNumber) {
288
+ highlightedContent = oldLines[change.oldLineNumber - 1] || change.content;
289
+ }
290
+ return /* @__PURE__ */ jsx(
291
+ DiffLine,
292
+ {
293
+ change,
294
+ showLineNumbers,
295
+ isUnified: true,
296
+ highlightedContent
297
+ },
298
+ index
299
+ );
300
+ }) });
301
+ }, "renderUnifiedView");
302
+ const renderSplitView = /* @__PURE__ */ __name(() => {
303
+ const oldLines = highlightedOldCode.split("\n");
304
+ const newLines = highlightedNewCode.split("\n");
305
+ return /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-2 gap-0", children: [
306
+ /* @__PURE__ */ jsxs("div", { className: "border-r", children: [
307
+ /* @__PURE__ */ jsx("div", { className: "border-b px-4 py-2 bg-red-500/10", children: /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-red-600 dark:text-red-400", children: oldFilename || filename || "Old" }) }),
308
+ /* @__PURE__ */ jsx("div", { className: "font-mono", children: oldLines.map((line, index) => /* @__PURE__ */ jsx(
309
+ DiffLine,
310
+ {
311
+ change: {
312
+ type: "remove",
313
+ lineNumber: index + 1,
314
+ content: line,
315
+ oldLineNumber: index + 1
316
+ },
317
+ showLineNumbers,
318
+ highlightedContent: line
319
+ },
320
+ `old-${index}`
321
+ )) })
322
+ ] }),
323
+ /* @__PURE__ */ jsxs("div", { children: [
324
+ /* @__PURE__ */ jsx("div", { className: "border-b px-4 py-2 bg-green-500/10", children: /* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-green-600 dark:text-green-400", children: newFilename || filename || "New" }) }),
325
+ /* @__PURE__ */ jsx("div", { className: "font-mono", children: newLines.map((line, index) => /* @__PURE__ */ jsx(
326
+ DiffLine,
327
+ {
328
+ change: {
329
+ type: "add",
330
+ lineNumber: index + 1,
331
+ content: line,
332
+ newLineNumber: index + 1
333
+ },
334
+ showLineNumbers,
335
+ highlightedContent: line
336
+ },
337
+ `new-${index}`
338
+ )) })
339
+ ] })
340
+ ] });
341
+ }, "renderSplitView");
342
+ return /* @__PURE__ */ jsxs(
343
+ "div",
344
+ {
345
+ ref,
346
+ className: cn(codeDiffVariants({ theme, size, className })),
347
+ ...props,
348
+ children: [
349
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between border-b px-4 py-2", children: [
350
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
351
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
352
+ /* @__PURE__ */ jsx(GitCompare, { className: "h-4 w-4 text-muted-foreground" }),
353
+ filename && /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: filename }),
354
+ language && /* @__PURE__ */ jsx(Badge, { variant: "secondary", className: "text-xs", children: language })
355
+ ] }),
356
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 text-xs text-muted-foreground", children: [
357
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1", children: [
358
+ /* @__PURE__ */ jsx(Plus, { className: "h-3 w-3 text-green-500" }),
359
+ stats.additions
360
+ ] }),
361
+ /* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1", children: [
362
+ /* @__PURE__ */ jsx(Minus, { className: "h-3 w-3 text-red-500" }),
363
+ stats.deletions
364
+ ] })
365
+ ] })
366
+ ] }),
367
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
368
+ /* @__PURE__ */ jsxs(
369
+ ToggleGroup,
370
+ {
371
+ type: "single",
372
+ value: view,
373
+ onValueChange: (value) => value && setView(value),
374
+ size: "sm",
375
+ children: [
376
+ /* @__PURE__ */ jsx(ToggleGroupItem, { value: "unified", "aria-label": "Unified view", children: /* @__PURE__ */ jsx(Square, { className: "h-3 w-3" }) }),
377
+ /* @__PURE__ */ jsx(ToggleGroupItem, { value: "split", "aria-label": "Split view", children: /* @__PURE__ */ jsx(SplitSquareHorizontal, { className: "h-3 w-3" }) })
378
+ ]
379
+ }
380
+ ),
381
+ showCopyButton && /* @__PURE__ */ jsxs(
382
+ Button,
383
+ {
384
+ variant: "ghost",
385
+ size: "sm",
386
+ onClick: copyToClipboard,
387
+ className: "h-8 w-8 p-0",
388
+ children: [
389
+ copied ? /* @__PURE__ */ jsx(Check, { className: "h-3.5 w-3.5 text-green-500" }) : /* @__PURE__ */ jsx(Copy, { className: "h-3.5 w-3.5" }),
390
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: copied ? "Copied" : "Copy diff" })
391
+ ]
392
+ }
393
+ )
394
+ ] })
395
+ ] }),
396
+ /* @__PURE__ */ jsx("div", { className: "overflow-auto", style: { maxHeight }, children: isLoading ? /* @__PURE__ */ jsx("div", { className: "p-4 space-y-2", children: Array.from({ length: 10 }).map((_, i) => /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-4", children: [
397
+ showLineNumbers && /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-8" }),
398
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-4 flex-1" })
399
+ ] }, i)) }) : view === "unified" ? renderUnifiedView() : renderSplitView() })
400
+ ]
401
+ }
402
+ );
403
+ }
404
+ );
405
+ CodeDiff.displayName = "CodeDiff";
406
+
407
+ export { CodeDiff, codeDiffVariants };