@xyd-js/components 0.1.0-xyd.1 → 0.1.0-xyd.3

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 (324) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/CTABanner-CAp2EJcY.js +2 -0
  3. package/dist/CTABanner-CAp2EJcY.js.map +1 -0
  4. package/dist/CodeSample-OUrk_l-U.js +2 -0
  5. package/dist/CodeSample-OUrk_l-U.js.map +1 -0
  6. package/dist/HomeView-t6Cljv0B.js +2 -0
  7. package/dist/HomeView-t6Cljv0B.js.map +1 -0
  8. package/dist/UnderlineNav-4pD9CR2B.js +2 -0
  9. package/dist/UnderlineNav-4pD9CR2B.js.map +1 -0
  10. package/dist/_rollupPluginBabelHelpers-CDahOOgk.js +2 -0
  11. package/dist/_rollupPluginBabelHelpers-CDahOOgk.js.map +1 -0
  12. package/dist/brand.d.ts +2 -1
  13. package/dist/brand.js +2 -1
  14. package/dist/brand.js.map +1 -0
  15. package/dist/coder/themes/cosmo-light.d.ts +5 -0
  16. package/dist/coder/themes/cosmo-light.js +2 -0
  17. package/dist/coder/themes/cosmo-light.js.map +1 -0
  18. package/dist/coder.d.ts +50 -3
  19. package/dist/coder.js +2 -1
  20. package/dist/coder.js.map +1 -0
  21. package/dist/content.d.ts +46 -6
  22. package/dist/content.js +2 -1
  23. package/dist/content.js.map +1 -0
  24. package/dist/index-P2Ntn1sE.js +2 -0
  25. package/dist/index-P2Ntn1sE.js.map +1 -0
  26. package/dist/index.css +59 -57
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +1 -0
  29. package/dist/index.js.map +1 -0
  30. package/dist/layouts.d.ts +2 -1
  31. package/dist/layouts.js +2 -1
  32. package/dist/layouts.js.map +1 -0
  33. package/dist/pages.d.ts +2 -1
  34. package/dist/pages.js +2 -1
  35. package/dist/pages.js.map +1 -0
  36. package/dist/{tslib.es6-B1gizQU6.js → tslib.es6-DIxZJ0kO.js} +1 -0
  37. package/dist/tslib.es6-DIxZJ0kO.js.map +1 -0
  38. package/dist/views.d.ts +2 -1
  39. package/dist/views.js +2 -1
  40. package/dist/views.js.map +1 -0
  41. package/dist/writer.d.ts +14 -2
  42. package/dist/writer.js +2 -1
  43. package/dist/writer.js.map +1 -0
  44. package/package.json +13 -8
  45. package/rollup.config.js +35 -9
  46. package/src/coder/Code/Code.styles.tsx +50 -0
  47. package/src/coder/Code/Code.tsx +79 -0
  48. package/src/coder/Code/annotations.tsx +31 -0
  49. package/src/coder/Code/highlight.ts +170 -0
  50. package/src/coder/Code/index.ts +12 -0
  51. package/src/coder/CodeSample/CodeSample.tsx +30 -133
  52. package/src/coder/CodeSample/index.ts +0 -1
  53. package/src/coder/CodeSample/withLocalStored.tsx +1 -1
  54. package/src/coder/{CodeSample/CodeSample.styles.tsx → CodeTabs/CodeTabs.styles.tsx} +0 -48
  55. package/src/coder/CodeTabs/CodeTabs.tsx +82 -0
  56. package/src/coder/CodeTabs/index.ts +6 -0
  57. package/src/coder/CodeTheme/CodeTheme.tsx +78 -0
  58. package/src/coder/CodeTheme/index.ts +8 -0
  59. package/src/coder/index.ts +31 -1
  60. package/src/coder/{CodeSample/default-theme.ts → themes/cosmo-light.ts} +3 -2
  61. package/src/content/Content/Content.tsx +1 -0
  62. package/src/content/Content.tsx +35 -1
  63. package/src/pages/index.ts +1 -0
  64. package/src/views/index.ts +1 -0
  65. package/src/writer/Badge/Badge.styles.tsx +4 -0
  66. package/src/writer/Badge/Badge.tsx +3 -1
  67. package/src/writer/Icon/index.tsx +230 -0
  68. package/dist/CTABanner-CYKba2Vn.js +0 -1
  69. package/dist/CTABanner-hV6NH0Xf.js +0 -1
  70. package/dist/CodeSample-D1QMQt89.js +0 -1
  71. package/dist/CodeSample-DLJNHIaK.js +0 -1
  72. package/dist/CodeSample-DZq0_qWL.js +0 -1
  73. package/dist/Footer-CkBDl828.js +0 -1
  74. package/dist/HomeView-CEgDQeAf.js +0 -1
  75. package/dist/UnderlineNav-BaOK-iez.js +0 -1
  76. package/dist/UnderlineNav-D5zXLK6j.js +0 -1
  77. package/dist/UnderlineNav-DGzjCvkM.js +0 -1
  78. package/dist/abap-DsN9RuMZ.js +0 -1
  79. package/dist/actionscript-3-B1SSyZyS.js +0 -1
  80. package/dist/ada-D_J1lW-E.js +0 -1
  81. package/dist/angular-html-CYREiUrW.js +0 -1
  82. package/dist/angular-ts-DcAOu8WU.js +0 -1
  83. package/dist/apache-CCuSaqCk.js +0 -1
  84. package/dist/apex-DblqgZJW.js +0 -1
  85. package/dist/apl-PFYbmQM7.js +0 -1
  86. package/dist/applescript-CxR8VFYt.js +0 -1
  87. package/dist/ara-DyvEMt1M.js +0 -1
  88. package/dist/asciidoc-CnwoPPuH.js +0 -1
  89. package/dist/asm-CjptKFp1.js +0 -1
  90. package/dist/astro-suE8bk8k.js +0 -1
  91. package/dist/awk-DCM8RPoH.js +0 -1
  92. package/dist/ballerina-Cj78GSWA.js +0 -1
  93. package/dist/bat-DOoDZywo.js +0 -1
  94. package/dist/beancount-t-WR86_8.js +0 -1
  95. package/dist/berry-B4bZSCCn.js +0 -1
  96. package/dist/bibtex-BrVhJY3k.js +0 -1
  97. package/dist/bicep-B9mKM727.js +0 -1
  98. package/dist/blade-C5Z797nx.js +0 -1
  99. package/dist/c-DAjGiO5B.js +0 -1
  100. package/dist/cadence-PrerV_VN.js +0 -1
  101. package/dist/clarity-BHTd5LJm.js +0 -1
  102. package/dist/clojure-CfEyl-7j.js +0 -1
  103. package/dist/cmake-CRA2Enzy.js +0 -1
  104. package/dist/cobol-BnLJxYQT.js +0 -1
  105. package/dist/codeowners-BvrirGey.js +0 -1
  106. package/dist/codeql-B2c2mBK0.js +0 -1
  107. package/dist/coffee-CG62yMWj.js +0 -1
  108. package/dist/common-lisp-CN6bltgb.js +0 -1
  109. package/dist/cpp-BbrQ837u.js +0 -1
  110. package/dist/crystal-rvb5jzSz.js +0 -1
  111. package/dist/csharp-CUz8u4K7.js +0 -1
  112. package/dist/css-JK7NOE59.js +0 -1
  113. package/dist/csv-CA_RykxK.js +0 -1
  114. package/dist/cue-AyD8vP8S.js +0 -1
  115. package/dist/cypher-eVjUZ0JC.js +0 -1
  116. package/dist/d-D1E5UK87.js +0 -1
  117. package/dist/dark-plus-C6xVaa39.js +0 -1
  118. package/dist/dart-DofOkkdM.js +0 -1
  119. package/dist/dax-DqGHRpF4.js +0 -1
  120. package/dist/desktop-j1oT-0Fo.js +0 -1
  121. package/dist/diff-ChebWHqI.js +0 -1
  122. package/dist/docker-BU6yAGy2.js +0 -1
  123. package/dist/dotenv-GyMvMNRw.js +0 -1
  124. package/dist/dracula-DUKRH7Zb.js +0 -1
  125. package/dist/dracula-soft-MlIR18G6.js +0 -1
  126. package/dist/dream-maker-BsQ1dbNp.js +0 -1
  127. package/dist/edge-F-AR7ZfW.js +0 -1
  128. package/dist/elixir-k4xxGl4V.js +0 -1
  129. package/dist/elm-CInOOHq9.js +0 -1
  130. package/dist/emacs-lisp-C6yIvom4.js +0 -1
  131. package/dist/erb-3pxr-NQS.js +0 -1
  132. package/dist/erlang-pmWC-Wee.js +0 -1
  133. package/dist/fennel-DViJm-jY.js +0 -1
  134. package/dist/fish-XcExlNEH.js +0 -1
  135. package/dist/fluent-DuJOAG6K.js +0 -1
  136. package/dist/fortran-fixed-form-Db5I_UFX.js +0 -1
  137. package/dist/fortran-free-form-B2xyqK-y.js +0 -1
  138. package/dist/fsharp-is-Hk3Eq.js +0 -1
  139. package/dist/gdresource-RuRLtBIa.js +0 -1
  140. package/dist/gdscript-pJ_75zwI.js +0 -1
  141. package/dist/gdshader-C5a9x3vh.js +0 -1
  142. package/dist/genie-BQ1oppDb.js +0 -1
  143. package/dist/gherkin-CuOELy7c.js +0 -1
  144. package/dist/git-commit-3zS8hqVZ.js +0 -1
  145. package/dist/git-rebase-DbS4r3GX.js +0 -1
  146. package/dist/github-dark-MxM60tcF.js +0 -1
  147. package/dist/github-dark-dimmed-DDWwGITy.js +0 -1
  148. package/dist/github-from-css-3tseHBGr.js +0 -1
  149. package/dist/github-light-pTwVS4k8.js +0 -1
  150. package/dist/gleam-DNxiWDAA.js +0 -1
  151. package/dist/glimmer-js-BGxcWjEE.js +0 -1
  152. package/dist/glimmer-ts-BB1An-Xq.js +0 -1
  153. package/dist/glsl-DaDHpxzv.js +0 -1
  154. package/dist/gnuplot-B1t-F_Gz.js +0 -1
  155. package/dist/go-BiVONvim.js +0 -1
  156. package/dist/graphql-LpWkIzuc.js +0 -1
  157. package/dist/groovy-DcxmRonw.js +0 -1
  158. package/dist/hack-BCsHcJ0e.js +0 -1
  159. package/dist/haml-CXlzR84c.js +0 -1
  160. package/dist/handlebars-DLTopqNS.js +0 -1
  161. package/dist/haskell-35U1u5gK.js +0 -1
  162. package/dist/haxe-ssN4Oy09.js +0 -1
  163. package/dist/hcl-kzI--7Cv.js +0 -1
  164. package/dist/hjson-pR2iiFsp.js +0 -1
  165. package/dist/hlsl-8PIy5U5-.js +0 -1
  166. package/dist/html-BEHbZ4zc.js +0 -1
  167. package/dist/html-derivative-K5xYNXck.js +0 -1
  168. package/dist/http-Cd2N6YgB.js +0 -1
  169. package/dist/hxml-BiAYlMbG.js +0 -1
  170. package/dist/hy-Cg5rcmur.js +0 -1
  171. package/dist/imba-DIe-G4Fn.js +0 -1
  172. package/dist/index-B7QE1KUr.js +0 -1
  173. package/dist/index-BE4Aq8NU.js +0 -1
  174. package/dist/index-CpFJxv5e.js +0 -1
  175. package/dist/index-DMAgLttD.js +0 -1
  176. package/dist/index-byGIVYaJ.js +0 -1
  177. package/dist/index-eU5so3Si.js +0 -1
  178. package/dist/ini-H0Ga-buI.js +0 -1
  179. package/dist/java-DoE_enjS.js +0 -1
  180. package/dist/javascript-__QKtyFe.js +0 -1
  181. package/dist/jinja-UYHlv864.js +0 -1
  182. package/dist/jison-B9nCySXt.js +0 -1
  183. package/dist/json-B7oi-vA0.js +0 -1
  184. package/dist/json5-BetPwqJO.js +0 -1
  185. package/dist/jsonc-pWWkBlCi.js +0 -1
  186. package/dist/jsonl-B6mt3pJZ.js +0 -1
  187. package/dist/jsonnet-CoMYTNCI.js +0 -1
  188. package/dist/jssm-Cid3TtQ5.js +0 -1
  189. package/dist/jsx-Ckobzlnq.js +0 -1
  190. package/dist/julia-C8xlDV3I.js +0 -1
  191. package/dist/kotlin-DvN1jcCb.js +0 -1
  192. package/dist/kusto-BCF_-dC3.js +0 -1
  193. package/dist/latex-DRFLltbj.js +0 -1
  194. package/dist/lean-DNZ3POMR.js +0 -1
  195. package/dist/less-XiEW6aqg.js +0 -1
  196. package/dist/light-plus-BnkOXVnc.js +0 -1
  197. package/dist/liquid-B40PlvwD.js +0 -1
  198. package/dist/log-xo3MDRlF.js +0 -1
  199. package/dist/logo-DTYzs3BE.js +0 -1
  200. package/dist/lua-BDEQNtpi.js +0 -1
  201. package/dist/luau-B1E5PlN9.js +0 -1
  202. package/dist/make-DtNOxXXX.js +0 -1
  203. package/dist/markdown-B6FKqc-0.js +0 -1
  204. package/dist/marko-mRmYVKe_.js +0 -1
  205. package/dist/material-darker-DFW2iB51.js +0 -1
  206. package/dist/material-default-BFApb2Ag.js +0 -1
  207. package/dist/material-from-css-bTkjEQjF.js +0 -1
  208. package/dist/material-lighter-CYEL5tGv.js +0 -1
  209. package/dist/material-ocean-BhuQqQbt.js +0 -1
  210. package/dist/material-palenight-B_DfQHjY.js +0 -1
  211. package/dist/matlab-BovMnqtG.js +0 -1
  212. package/dist/mdc-DIkT1TyN.js +0 -1
  213. package/dist/mdx-CxAyQTjI.js +0 -1
  214. package/dist/mermaid-i0z8tyOx.js +0 -1
  215. package/dist/min-dark-BE2n4wJj.js +0 -1
  216. package/dist/min-light-BJgErz0d.js +0 -1
  217. package/dist/mojo-C-lVJL5A.js +0 -1
  218. package/dist/monokai-eaa8L1cq.js +0 -1
  219. package/dist/move-C3Zui0bc.js +0 -1
  220. package/dist/narrat-THKEk6T8.js +0 -1
  221. package/dist/nextflow-CtnPKe-i.js +0 -1
  222. package/dist/nginx-CGEFMta9.js +0 -1
  223. package/dist/nim-C8mPZfis.js +0 -1
  224. package/dist/nix-JCk4_G_4.js +0 -1
  225. package/dist/nord-Doy8uXi5.js +0 -1
  226. package/dist/nushell-CX0evzNH.js +0 -1
  227. package/dist/objective-c-CRUJa2eY.js +0 -1
  228. package/dist/objective-cpp-CCYeWv4r.js +0 -1
  229. package/dist/ocaml-DGJqpgv5.js +0 -1
  230. package/dist/one-dark-pro-u8LD4Pzz.js +0 -1
  231. package/dist/pascal-DBmHAUBB.js +0 -1
  232. package/dist/perl-DeqR1cIo.js +0 -1
  233. package/dist/php-DgxB75vC.js +0 -1
  234. package/dist/plsql-7JGOsii8.js +0 -1
  235. package/dist/po-iKcL_E8G.js +0 -1
  236. package/dist/poimandres-CA110GE1.js +0 -1
  237. package/dist/postcss-Da2iRvoL.js +0 -1
  238. package/dist/powerquery-DPeggvzL.js +0 -1
  239. package/dist/powershell-CaJNoU_J.js +0 -1
  240. package/dist/prisma-CJb-Lxak.js +0 -1
  241. package/dist/prolog-DfSRFLOg.js +0 -1
  242. package/dist/proto-CQScmtFO.js +0 -1
  243. package/dist/pug-C812gnD5.js +0 -1
  244. package/dist/puppet-B1xO3kuT.js +0 -1
  245. package/dist/purescript-CNYgFxmJ.js +0 -1
  246. package/dist/python-D9HM-cQI.js +0 -1
  247. package/dist/qml-DJVpVDAW.js +0 -1
  248. package/dist/qmldir-CHfKHU4H.js +0 -1
  249. package/dist/qss-C4aoutlf.js +0 -1
  250. package/dist/r-CqYxKsjx.js +0 -1
  251. package/dist/racket-DUEDYd32.js +0 -1
  252. package/dist/raku-D9-XDqRz.js +0 -1
  253. package/dist/razor-3rNKfrrf.js +0 -1
  254. package/dist/reg-b5Nk8lNx.js +0 -1
  255. package/dist/regexp-DVRafeF7.js +0 -1
  256. package/dist/rel--gRyHcrO.js +0 -1
  257. package/dist/riscv-C8SxbbN2.js +0 -1
  258. package/dist/rose-pine-DPGqNU4b.js +0 -1
  259. package/dist/rose-pine-dawn-DymfQU_V.js +0 -1
  260. package/dist/rose-pine-moon-BQUAYUon.js +0 -1
  261. package/dist/rst-CmHkCKmJ.js +0 -1
  262. package/dist/ruby-Q-VH1uZA.js +0 -1
  263. package/dist/rust-ClS6MAIk.js +0 -1
  264. package/dist/sas-D3oI_z1n.js +0 -1
  265. package/dist/sass-C7IOYsXa.js +0 -1
  266. package/dist/scala-Bo-OrDK4.js +0 -1
  267. package/dist/scheme-CZPOfAv0.js +0 -1
  268. package/dist/scss-CrrfDAqb.js +0 -1
  269. package/dist/shaderlab-BHdRvEKr.js +0 -1
  270. package/dist/shellscript-CGx4lQcC.js +0 -1
  271. package/dist/shellsession-DNVyDTwx.js +0 -1
  272. package/dist/slack-dark-BdYiGGaR.js +0 -1
  273. package/dist/slack-ochin-D47ofNk9.js +0 -1
  274. package/dist/smalltalk-CSwwxfh6.js +0 -1
  275. package/dist/solarized-dark-B_ueb431.js +0 -1
  276. package/dist/solarized-light-ClfNXI7y.js +0 -1
  277. package/dist/solidity-DTxkUBi_.js +0 -1
  278. package/dist/soy-CWDkaEw-.js +0 -1
  279. package/dist/sparql-iRDOfWr5.js +0 -1
  280. package/dist/splunk-BEkc8uO-.js +0 -1
  281. package/dist/sql-BJ_taBmN.js +0 -1
  282. package/dist/ssh-config-Df9b2KGk.js +0 -1
  283. package/dist/stata-D3UR29Ve.js +0 -1
  284. package/dist/stylus-CdDBOxWC.js +0 -1
  285. package/dist/svelte-DyEd0oQk.js +0 -1
  286. package/dist/swift-BxhiGBjX.js +0 -1
  287. package/dist/system-verilog-CetQnQ4g.js +0 -1
  288. package/dist/systemd-BnD0vcw3.js +0 -1
  289. package/dist/tasl-DVvrvOfd.js +0 -1
  290. package/dist/tcl-DLSUI_zn.js +0 -1
  291. package/dist/templ-DSz21pzx.js +0 -1
  292. package/dist/terraform-EK_dQKQM.js +0 -1
  293. package/dist/tex-BM4Fklib.js +0 -1
  294. package/dist/toml-kuUrbkod.js +0 -1
  295. package/dist/ts-tags-By7dzkmj.js +0 -1
  296. package/dist/tslib.es6-CMPV4d4T.js +0 -1
  297. package/dist/tslib.es6-DlLz3CkS.js +0 -1
  298. package/dist/tsv-BCJoRl62.js +0 -1
  299. package/dist/tsx-BjuLHzrJ.js +0 -1
  300. package/dist/turtle-CufS_WpN.js +0 -1
  301. package/dist/twig-JhO6NGAT.js +0 -1
  302. package/dist/txt-C4POgh3W.js +0 -1
  303. package/dist/typescript-B1VYfqvp.js +0 -1
  304. package/dist/typespec-CZzVsQ68.js +0 -1
  305. package/dist/typst-DLkGCZHs.js +0 -1
  306. package/dist/v-DNo0Cbkd.js +0 -1
  307. package/dist/vala-J9aWDLgT.js +0 -1
  308. package/dist/vb-CukbP-ad.js +0 -1
  309. package/dist/verilog-C7Ns4wPb.js +0 -1
  310. package/dist/vhdl-D94Lw1Fr.js +0 -1
  311. package/dist/viml-gaixGh_X.js +0 -1
  312. package/dist/vue-BX9d0W3t.js +0 -1
  313. package/dist/vue-html-CPRiJ8jH.js +0 -1
  314. package/dist/vyper-Ckj8wEzF.js +0 -1
  315. package/dist/wasm-BIwf60De.js +0 -1
  316. package/dist/wenyan-8NGlujRm.js +0 -1
  317. package/dist/wgsl-BcYJIOdN.js +0 -1
  318. package/dist/wikitext-B892rECa.js +0 -1
  319. package/dist/wolfram-CsrnIKPa.js +0 -1
  320. package/dist/xml-bnQL-E2F.js +0 -1
  321. package/dist/xsl-n4ZnN1T3.js +0 -1
  322. package/dist/yaml-8btRgevg.js +0 -1
  323. package/dist/zenscript-C4tShGxI.js +0 -1
  324. package/dist/zig-YA915rBO.js +0 -1
@@ -0,0 +1,79 @@
1
+ import React, {Suspense} from "react";
2
+ import type {HighlightedCode, AnnotationHandler} from "codehike/code";
3
+ import {InnerLine, Pre} from "codehike/code";
4
+ import {Theme} from "@code-hike/lighter";
5
+
6
+ import {CodeTheme, type CodeThemeBlockProps} from "../CodeTheme";
7
+ import {$lineNumber, $mark, $code} from "./Code.styles.tsx";
8
+
9
+ export interface CodeProps {
10
+ codeblocks: CodeThemeBlockProps[];
11
+ theme?: Theme
12
+ children: React.ReactNode
13
+ }
14
+
15
+ export function Code(props: CodeProps) {
16
+ return <Suspense fallback={<$Loading/>}>
17
+ <CodeTheme codeblocks={props.codeblocks} theme={props.theme}>
18
+ {props.children}
19
+ </CodeTheme>
20
+ </Suspense>
21
+ }
22
+
23
+ function $Loading() {
24
+ return <>
25
+ loading...
26
+ </>
27
+ }
28
+
29
+ // TODO: fix any
30
+ Code.LineNumber = function LineNumber(props: any) {
31
+ if (!props.children || !props.children.length) {
32
+ return null
33
+ }
34
+ return (
35
+ <>
36
+ <span
37
+ style={{minWidth: `${props.width}ch`}}
38
+ className={$lineNumber.host}
39
+ >
40
+ {props.lineNumber}
41
+ </span>
42
+ <InnerLine merge={props}/>
43
+ </>
44
+ )
45
+ }
46
+
47
+ // TODO: fix any
48
+ Code.Mark = function Mark(props: any) {
49
+ return <div className={`${$mark.host} ${props.annotation && $mark.$$annotated}`}>
50
+ <InnerLine
51
+ merge={props}
52
+ className={$mark.line}
53
+ />
54
+ </div>
55
+ }
56
+
57
+ // TODO: fix any
58
+ Code.Bg = function CodeLine(props: any) {
59
+ return <span className={`${props.annotation && $mark.$$annotated}`}>
60
+ {props.children}
61
+ </span>
62
+ }
63
+
64
+ Code.Pre = function CodePre(props: {
65
+ codeblock: HighlightedCode,
66
+ size?: "full",
67
+ handlers: AnnotationHandler[]
68
+ }
69
+ ) {
70
+ return <Pre
71
+ className={`
72
+ ${$code.host}
73
+ ${props?.size === "full" && $code.host$$full}
74
+ `}
75
+ style={props.codeblock?.style || props.codeblock?.style}
76
+ code={props.codeblock}
77
+ handlers={props.handlers}
78
+ />
79
+ }
@@ -0,0 +1,31 @@
1
+ import React from "react";
2
+ import {AnnotationHandler} from "codehike/code";
3
+
4
+ import {Code} from "./Code.tsx";
5
+
6
+ const markAnnotation: AnnotationHandler = {
7
+ name: "mark",
8
+ Line: (props) => {
9
+ return <Code.Mark {...props}/>
10
+ }
11
+ }
12
+
13
+ const bgAnnotation: AnnotationHandler = {
14
+ name: "bg",
15
+ Inline: (props) => {
16
+ return <Code.Bg {...props}/>
17
+ }
18
+ }
19
+
20
+ const lineNumberAnnotation: AnnotationHandler = {
21
+ name: "line-numbers",
22
+ Line: ({annotation, ...props}) => {
23
+ return <Code.LineNumber {...props}/>
24
+ },
25
+ }
26
+
27
+ export const annotations = {
28
+ mark: markAnnotation,
29
+ bg: bgAnnotation,
30
+ lineNumbers: lineNumberAnnotation
31
+ }
@@ -0,0 +1,170 @@
1
+ import {
2
+ type CodeAnnotation,
3
+ type RawCode,
4
+ type HighlightedCode,
5
+ type Token
6
+ } from 'codehike/code';
7
+ import {
8
+ type Lines,
9
+ type Tokens,
10
+ highlightSync as lighter,
11
+ LANG_NAMES,
12
+ type Theme
13
+ } from '@code-hike/lighter';
14
+
15
+ type Whitespace = string
16
+
17
+ type AnyToken = Token | Whitespace
18
+
19
+ function isWhitespace(token: Token | Whitespace): token is Whitespace {
20
+ return typeof token === 'string';
21
+ }
22
+
23
+ export function highlight(
24
+ data: RawCode,
25
+ theme: Theme,
26
+ lang: string
27
+ ): HighlightedCode {
28
+ if (!LANG_NAMES.includes(lang)) {
29
+ console.warn(`Unknown language "${lang}"`);
30
+ lang = 'txt';
31
+ }
32
+
33
+ const {
34
+ lines,
35
+ lang: lighterLang,
36
+ style
37
+ } = lighter(data.value, lang, theme as any, {
38
+ annotations: [],
39
+ scopes: false // true for better token transitions, but breaks css themes
40
+ });
41
+
42
+ const tokens = joinLines(lines);
43
+ // split surrounding whitespace for each token
44
+ const splitTokens = splitWhitespace(tokens);
45
+ // join consecutive whitespace tokens
46
+ const joinedTokens = joinWhitespace(splitTokens);
47
+
48
+ return {
49
+ ...data,
50
+ code: data.value,
51
+ tokens: joinedTokens,
52
+ lang: lighterLang,
53
+ annotations: [], // TODO: in the future
54
+ // annotations: compatAnnotations(annotations),
55
+ themeName: typeof theme === 'string' ? theme : theme?.name || 'unknown',
56
+ style
57
+ };
58
+ }
59
+
60
+ function compatAnnotations(annotations: any[]): CodeAnnotation[] {
61
+ const newAnnotations: CodeAnnotation[] = [];
62
+ for (const a of annotations) {
63
+ const {name, query, ranges} = a;
64
+ for (const r of ranges) {
65
+ if (r.lineNumber) {
66
+ const {lineNumber, fromColumn, toColumn} = r;
67
+ newAnnotations.push({
68
+ name,
69
+ query,
70
+ lineNumber,
71
+ fromColumn,
72
+ toColumn
73
+ });
74
+ } else {
75
+ const {fromLineNumber, toLineNumber} = r;
76
+ newAnnotations.push({
77
+ name,
78
+ query,
79
+ fromLineNumber,
80
+ toLineNumber
81
+ });
82
+ }
83
+ }
84
+ }
85
+ return newAnnotations;
86
+ }
87
+
88
+ // group the Lines into one array
89
+ function joinLines(lines: Lines): AnyToken[] {
90
+ const joinedTokens: AnyToken[] = [];
91
+ lines.forEach((lineOrGroup, i) => {
92
+ if ('lines' in lineOrGroup) {
93
+ throw new Error('Shouldnt be groups');
94
+ } else {
95
+ const tokens = joinTokens(lineOrGroup.tokens);
96
+ joinedTokens.push(...tokens);
97
+ if (i < lines.length - 1) {
98
+ joinedTokens.push('\n');
99
+ }
100
+ }
101
+ });
102
+ return joinedTokens;
103
+ }
104
+
105
+ function joinTokens(tokens: Tokens): AnyToken[] {
106
+ return tokens.map((tokenOrGroup) => {
107
+ if ('tokens' in tokenOrGroup) {
108
+ throw new Error('Shouldnt be groups');
109
+ } else {
110
+ const t = [tokenOrGroup.content] as Token;
111
+ const {color, ...rest} = tokenOrGroup.style || {};
112
+ t.push(color);
113
+ if (Object.keys(rest).length) {
114
+ t.push(rest);
115
+ }
116
+ return t;
117
+ }
118
+ });
119
+ }
120
+
121
+ function splitWhitespace(tokens: AnyToken[]) {
122
+ const ejected: AnyToken[] = [];
123
+ tokens.forEach((tokenOrGroup) => {
124
+ if (isWhitespace(tokenOrGroup)) {
125
+ ejected.push(tokenOrGroup);
126
+ } else {
127
+ const [before, content, after] = splitSurroundingWhitespace(
128
+ tokenOrGroup[0]
129
+ );
130
+ if (before?.length) {
131
+ ejected.push(before);
132
+ }
133
+ if (content.length) {
134
+ const copy = [...tokenOrGroup] as Token;
135
+ copy[0] = content;
136
+ ejected.push(copy);
137
+ }
138
+ if (after?.length) {
139
+ ejected.push(after);
140
+ }
141
+ }
142
+ });
143
+ return ejected;
144
+ }
145
+
146
+ function joinWhitespace(tokens: AnyToken[]) {
147
+ const joinedTokens: AnyToken[] = [];
148
+ tokens.forEach((tokenOrGroup) => {
149
+ if (isWhitespace(tokenOrGroup)) {
150
+ let last = joinedTokens[joinedTokens.length - 1];
151
+ if (last && isWhitespace(last)) {
152
+ joinedTokens[joinedTokens.length - 1] += tokenOrGroup;
153
+ } else if (tokenOrGroup !== '') {
154
+ joinedTokens.push(tokenOrGroup);
155
+ }
156
+ } else if (tokenOrGroup[0].length > 0) {
157
+ joinedTokens.push(tokenOrGroup);
158
+ }
159
+ });
160
+ return joinedTokens;
161
+ }
162
+
163
+ // splits " \t foo bar \n" into [" \t ","foo bar"," \n"]
164
+ // "foo bar" -> ["","foo bar",""]
165
+ function splitSurroundingWhitespace(content: string) {
166
+ const trimmed = content.trim();
167
+ const before = content.slice(0, content.indexOf(trimmed));
168
+ const after = content.slice(content.indexOf(trimmed) + trimmed.length);
169
+ return [before, trimmed, after];
170
+ }
@@ -0,0 +1,12 @@
1
+ export {
2
+ annotations
3
+ } from "./annotations"
4
+ export type {
5
+ CodeProps
6
+ } from "./Code"
7
+ export {
8
+ Code
9
+ } from "./Code"
10
+ export {
11
+ highlight
12
+ } from "./highlight"
@@ -1,150 +1,47 @@
1
- import React, {useEffect, useState} from "react";
2
- import * as TabsPrimitive from "@radix-ui/react-tabs"; // TODO: remove and use separation
3
- import {
4
- AnnotationHandler,
5
- InnerLine,
6
- Pre,
7
- highlight,
8
- HighlightedCode,
9
- } from "codehike/code"
1
+ import React from "react";
2
+ import {Theme} from "@code-hike/lighter";
3
+
4
+ import type {CodeThemeBlockProps} from "../CodeTheme";
10
5
 
11
6
  import {
12
- CodeCopy,
13
- } from "../CodeCopy";
14
- import {theme as defaultTheme} from "./default-theme" // TODO: support multiple themes
15
- import {withLocalStored} from "./withLocalStored";
7
+ Code,
8
+ annotations,
9
+ } from "../Code"
16
10
  import {
17
- $sample,
18
- $languages,
19
- $code,
20
- $mark,
21
- $lineNumber
22
- } from "./CodeSample.styles";
23
-
24
- // TODO: try to use codehiki in build time / ASYNC !!! - we need rr server-components
25
- // TODO: separate highlight
26
-
27
- export interface MDXCodeSampleBlock {
28
- /** This is the raw code. May include annotation comments. */
29
- value: string;
30
- /** The programming language. */
31
- lang: string;
32
- /** Metadata string (the content after the language name in a markdown codeblock). */
33
- meta: string;
34
- }
11
+ withCodeTabs
12
+ } from "../CodeTabs";
13
+ import {useCodeTheme} from "../CodeTheme";
35
14
 
36
15
  export interface CodeSampleProps {
37
16
  name: string;
38
17
  description: string;
39
- codeblocks: MDXCodeSampleBlock[];
18
+ codeblocks: CodeThemeBlockProps[];
40
19
  size?: "full"
20
+ theme?: Theme
41
21
  }
42
22
 
43
23
  export function CodeSample(props: CodeSampleProps) {
44
- const [highlighted, setHighlighted] = useState<HighlightedCode[]>([]);
45
-
46
- useEffect(() => {
47
- async function fetchHighlight() {
48
- const result = await Promise.all(
49
- props.codeblocks?.map((codeblock) => highlight(codeblock, defaultTheme))
50
- );
51
-
52
- setHighlighted(result);
53
- }
54
-
55
- fetchHighlight();
56
- }, [props.codeblocks]);
57
-
58
- if (highlighted.length === 0) {
59
- return <div>Loading</div>;
60
- }
61
-
62
- if (!highlighted) {
63
- return <div>Loading</div>;
64
- }
65
-
66
- return (
67
- <TabsPrimitive.Root
68
- className={$sample.host}
69
- style={highlighted[0]?.style}
70
- defaultValue={highlighted[0]?.meta}
71
- // localStorageKey={`preferredLanguage[${name}]`}
72
- >
73
- <div className={$languages.host}>
74
- <$Description description={props.description}/>
75
-
76
- <TabsPrimitive.List className={$languages.list}>
77
- {props.codeblocks?.map(({meta}, i) => (
78
- <TabsPrimitive.Trigger value={meta!} key={i} className={$languages.button}>
79
- {meta}
80
- </TabsPrimitive.Trigger>
81
- ))}
82
- </TabsPrimitive.List>
83
-
84
- <div className={$languages.copy}>
85
- {props.codeblocks?.map((codeblock, i) => (
86
- <TabsPrimitive.Content value={codeblock.meta!} asChild key={i}>
87
- <CodeCopy text={codeblock.value}/>
88
- </TabsPrimitive.Content>
89
- ))}
90
- </div>
91
- </div>
92
-
93
- {highlighted?.map((codeblock, i) => (
94
- <TabsPrimitive.Content value={codeblock.meta} key={i}>
95
- <Pre
96
- className={`
97
- ${$code.host}
98
- ${props?.size === "full" && $code.host$$full}
99
- `}
100
- style={codeblock?.style || codeblock?.style}
101
- code={codeblock}
102
- handlers={[mark, lineNumber]}
103
- />
104
- </TabsPrimitive.Content>
105
- ))}
106
- </TabsPrimitive.Root>
107
- )
24
+ return <Code codeblocks={props.codeblocks} theme={props.theme}>
25
+ <$ThemedCodeSample {...props}/>
26
+ </Code>
108
27
  }
109
28
 
110
- function $Description(props: { description: string }) {
111
- return <div className={$languages.description}>
112
- <div className={$languages.description$item}>
113
- {props.description}
114
- </div>
115
- </div>
116
- }
29
+ function $ThemedCodeSample(props: CodeSampleProps) {
30
+ const {highlighted} = useCodeTheme()
117
31
 
118
- const mark: AnnotationHandler = {
119
- name: "Mark",
120
- Line: ({annotation, ...props}) => {
121
- return (
122
- <div className={`${$mark.host} ${annotation && $mark.$$annotated}`}>
123
- <InnerLine
124
- merge={props}
125
- className={$mark.line}
126
- />
127
- </div>
128
- )
129
- },
32
+ return <$CodeSampleTabs
33
+ description={props.description}
34
+ highlighted={highlighted}
35
+ size={props.size}
36
+ />
130
37
  }
131
38
 
132
- const lineNumber: AnnotationHandler = {
133
- name: "LineNumber",
134
- Line: ({annotation, ...props}) => {
135
- const width = props.totalLines.toString().length + 1
136
-
137
- return (
138
- <>
139
- <span
140
- style={{minWidth: `${width}ch`}}
141
- className={$lineNumber.host}
142
- >
143
- {props.lineNumber}
144
- </span>
145
- <InnerLine merge={props}/>
146
- </>
147
- )
148
- },
149
- }
39
+ const $CodeSampleTabs = withCodeTabs((props) => <Code.Pre
40
+ {...props}
41
+ handlers={[
42
+ annotations.mark,
43
+ annotations.bg,
44
+ annotations.lineNumbers
45
+ ]}
46
+ />)
150
47
 
@@ -8,5 +8,4 @@ export {
8
8
 
9
9
  export type {
10
10
  CodeSampleProps,
11
- MDXCodeSampleBlock,
12
11
  } from "./CodeSample";
@@ -7,7 +7,7 @@ export interface CodeTabsProps {
7
7
  children: React.ReactNode
8
8
  }
9
9
 
10
- // TODO: interface
10
+ // TODO: move to CodeTabs?
11
11
  export function withLocalStored(Component: any) {
12
12
  return function LocalStored(props: CodeTabsProps) {
13
13
  const [value, setValue] = useState(
@@ -87,51 +87,3 @@ export const $languages = {
87
87
  `
88
88
  }
89
89
 
90
- export const $code = {
91
- host: css`
92
- max-height: 400px;
93
- background: linear-gradient(45deg, rgb(247, 247, 248) 0%, rgb(247, 247, 248) 100%) !important;
94
-
95
- margin: 0;
96
- padding: 8px 16px;
97
-
98
- border-top: 1px solid rgb(236, 236, 241);
99
- border-bottom-left-radius: 10px;
100
- border-bottom-right-radius: 10px;
101
-
102
- font-size: 12px;
103
- line-height: 20px;
104
- white-space: pre-wrap;
105
- word-break: break-all;
106
-
107
- overflow-y: scroll;
108
- `,
109
- host$$full: css`
110
- max-height: 100%;
111
- `
112
- }
113
-
114
- export const $mark = {
115
- host: css`
116
- display: flex;
117
- border-left-width: 4px;
118
- border-color: transparent;
119
- margin: 4px 0;
120
- `,
121
- line: css`
122
- flex: 1 1 0%;
123
- `,
124
- $$annotated: css`
125
- border-color: #60A5FA;
126
- background-color: #EEF2FF;
127
- `
128
- }
129
-
130
- export const $lineNumber = {
131
- host: css`
132
- margin: 0 4px;
133
- //text-align: right;
134
- user-select: none;
135
- opacity: 0.5;
136
- `
137
- }
@@ -0,0 +1,82 @@
1
+ import React, {} from "react";
2
+ import * as TabsPrimitive from "@radix-ui/react-tabs";
3
+ import {
4
+ HighlightedCode,
5
+ } from "codehike/code"
6
+
7
+ import {
8
+ CodeCopy,
9
+ } from "../CodeCopy";
10
+ import {
11
+ $sample,
12
+ $languages,
13
+ } from "./CodeTabs.styles.tsx"; // TODO: style by highlighted?
14
+
15
+ export interface CodeTabsProps {
16
+ description: string;
17
+ highlighted: HighlightedCode[]
18
+ size?: "full"
19
+ }
20
+
21
+ export function withCodeTabs(PreComponent) {
22
+ return function CodeTabs(props: CodeTabsProps) {
23
+ return (
24
+ <TabsPrimitive.Root
25
+ className={$sample.host}
26
+ style={props.highlighted[0]?.style}
27
+ defaultValue={props.highlighted[0]?.meta}
28
+ >
29
+ <$LanguageTabSwitcher
30
+ description={props.description}
31
+ highlighted={props.highlighted}
32
+ />
33
+
34
+ {props.highlighted?.map((codeblock, i) => (
35
+ <TabsPrimitive.Content value={codeblock.meta} key={i}>
36
+ <PreComponent
37
+ style={codeblock?.style || codeblock?.style}
38
+ codeblock={codeblock}
39
+ />
40
+ </TabsPrimitive.Content>
41
+ ))}
42
+ </TabsPrimitive.Root>
43
+ )
44
+ }
45
+ }
46
+
47
+ interface LanguageTabSwitcherProps {
48
+ description: string;
49
+ highlighted: HighlightedCode[]
50
+ }
51
+
52
+ function $LanguageTabSwitcher(props: LanguageTabSwitcherProps) {
53
+ return <div className={$languages.host}>
54
+ <$Description description={props.description}/>
55
+
56
+ <TabsPrimitive.List className={$languages.list}>
57
+ {props.highlighted?.map(({meta}, i) => (
58
+ <TabsPrimitive.Trigger value={meta!} key={i} className={$languages.button}>
59
+ {meta}
60
+ </TabsPrimitive.Trigger>
61
+ ))}
62
+ </TabsPrimitive.List>
63
+
64
+ <div className={$languages.copy}>
65
+ {props.highlighted?.map((codeblock, i) => (
66
+ <TabsPrimitive.Content value={codeblock.meta!} asChild key={i}>
67
+ <CodeCopy text={codeblock.value}/>
68
+ </TabsPrimitive.Content>
69
+ ))}
70
+ </div>
71
+ </div>
72
+ }
73
+
74
+ function $Description(props: { description: string }) {
75
+ return <div className={$languages.description}>
76
+ <div className={$languages.description$item}>
77
+ {props.description}
78
+ </div>
79
+ </div>
80
+ }
81
+
82
+
@@ -0,0 +1,6 @@
1
+ export type {
2
+ CodeTabsProps
3
+ } from "./CodeTabs";
4
+ export {
5
+ withCodeTabs
6
+ } from "./CodeTabs";