product-doc 0.13.2 → 0.14.1

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 (304) hide show
  1. package/README.md +31 -22
  2. package/guide/previews.md +64 -0
  3. package/guide/ui.md +13 -0
  4. package/guide.md +20 -17
  5. package/lib/changes.d.ts +4 -0
  6. package/lib/changes.js +5 -0
  7. package/lib/cli.js +99 -12
  8. package/lib/diffmapConfig.d.ts +41 -0
  9. package/lib/diffmapConfig.js +71 -0
  10. package/lib/git.d.ts +9 -4
  11. package/lib/git.js +42 -7
  12. package/lib/github/route.d.ts +1 -0
  13. package/lib/github/route.js +14 -5
  14. package/lib/parseFence.d.ts +30 -0
  15. package/lib/parseFence.js +62 -0
  16. package/lib/parseViewer.js +15 -0
  17. package/lib/preview/PreviewRoute.d.ts +20 -0
  18. package/lib/preview/PreviewRoute.js +279 -0
  19. package/lib/preview/index.d.ts +3 -0
  20. package/lib/preview/index.js +2 -0
  21. package/lib/preview/protocol.d.ts +85 -0
  22. package/lib/preview/protocol.js +114 -0
  23. package/lib/readDiffmapConfig.d.ts +12 -0
  24. package/lib/readDiffmapConfig.js +25 -0
  25. package/lib/serve.d.ts +2 -0
  26. package/lib/serve.js +41 -7
  27. package/lib/share.js +5 -1
  28. package/package.json +21 -4
  29. package/viewer-dist/assets/angular-html-C4LeXCe-.js +1 -0
  30. package/viewer-dist/assets/angular-ts-CRxW7p1W.js +1 -0
  31. package/viewer-dist/assets/{apl-Dio8Ke0X.js → apl-D60kkz--.js} +1 -1
  32. package/viewer-dist/assets/astro-3Zgg9XqN.js +1 -0
  33. package/viewer-dist/assets/{bat-HFWzIrao.js → bat-qdxAdBWQ.js} +1 -1
  34. package/viewer-dist/assets/{bibtex-Conh3HYz.js → bibtex-Ci_nEsc7.js} +1 -1
  35. package/viewer-dist/assets/blade-B5YUZNEG.js +1 -0
  36. package/viewer-dist/assets/bsl-_VjlB9mv.js +1 -0
  37. package/viewer-dist/assets/c-BNQJhXlP.js +1 -0
  38. package/viewer-dist/assets/cairo-DLTphjLi.js +1 -0
  39. package/viewer-dist/assets/{chapel-C1sUNn9S.js → chapel-CFMD-Djs.js} +1 -1
  40. package/viewer-dist/assets/{clojure-zIjcJonk.js → clojure-DqKBuwfJ.js} +1 -1
  41. package/viewer-dist/assets/{cmake-T_kMSWuN.js → cmake-Bj61d0ZC.js} +1 -1
  42. package/viewer-dist/assets/{cobol-BvqUwMCV.js → cobol-DY6IFdmX.js} +1 -1
  43. package/viewer-dist/assets/{coffee-BSYIIMkB.js → coffee-BP03ytLP.js} +1 -1
  44. package/viewer-dist/assets/{core-A38CGsfQ.js → core-BkcJpkJE.js} +2 -2
  45. package/viewer-dist/assets/cpp-CUBNVKxn.js +1 -0
  46. package/viewer-dist/assets/{crystal-D0XIDmeW.js → crystal-NSr8mDkd.js} +1 -1
  47. package/viewer-dist/assets/{csharp-B3DbjJyj.js → csharp-dmMxLVLW.js} +1 -1
  48. package/viewer-dist/assets/css-BiJUKRHp.js +1 -0
  49. package/viewer-dist/assets/{csv-B_R7vXwK.js → csv-Dx-8-gkx.js} +1 -1
  50. package/viewer-dist/assets/{dart-_dH3dQdM.js → dart-CHZY9Xhz.js} +1 -1
  51. package/viewer-dist/assets/{diff-CR4ZX0DC.js → diff-woXpYk--.js} +1 -1
  52. package/viewer-dist/assets/{docker-CAzcIhYn.js → docker-IyjqRm3v.js} +1 -1
  53. package/viewer-dist/assets/edge-DznSXZdq.js +1 -0
  54. package/viewer-dist/assets/{elixir-BL8v4QDr.js → elixir-D1HcpP2u.js} +1 -1
  55. package/viewer-dist/assets/{elm-CC1TmzeR.js → elm-Bmx6Fs0i.js} +1 -1
  56. package/viewer-dist/assets/{erb-CHbMJpQy.js → erb-CdvLbCTI.js} +1 -1
  57. package/viewer-dist/assets/erlang-Cphh6RMH.js +1 -0
  58. package/viewer-dist/assets/fortran-fixed-form-DEKoE2YW.js +1 -0
  59. package/viewer-dist/assets/{fortran-free-form-uHOymLAb.js → fortran-free-form-CYNrtFtB.js} +1 -1
  60. package/viewer-dist/assets/fsharp-D13ZGOAj.js +1 -0
  61. package/viewer-dist/assets/gdresource-xMC7jr7x.js +1 -0
  62. package/viewer-dist/assets/{gdscript-DJFPOtzS.js → gdscript-DYvRD3hg.js} +1 -1
  63. package/viewer-dist/assets/{gdshader-kiBtQlv1.js → gdshader-CBce3t8t.js} +1 -1
  64. package/viewer-dist/assets/git-commit-BSykSTBG.js +1 -0
  65. package/viewer-dist/assets/{git-rebase-Bh7mDoAc.js → git-rebase-C-RR1FSc.js} +1 -1
  66. package/viewer-dist/assets/{glimmer-js-CIdbWayl.js → glimmer-js-BUse42ki.js} +1 -1
  67. package/viewer-dist/assets/{glimmer-ts-B16xCo2k.js → glimmer-ts-zH_nSjyx.js} +1 -1
  68. package/viewer-dist/assets/glsl-CyFpZtQv.js +1 -0
  69. package/viewer-dist/assets/{go-CFMhVTkq.js → go-rLFTqkRN.js} +1 -1
  70. package/viewer-dist/assets/graphql-BIyAKkG2.js +1 -0
  71. package/viewer-dist/assets/{groovy-Dj7WCBJM.js → groovy-CacY0gHj.js} +1 -1
  72. package/viewer-dist/assets/{hack-C30D-q0p.js → hack-qk6BiceN.js} +1 -1
  73. package/viewer-dist/assets/haml-BkBm6IgF.js +1 -0
  74. package/viewer-dist/assets/{handlebars-g-3gLrXt.js → handlebars-FMeV8O-Z.js} +1 -1
  75. package/viewer-dist/assets/{haxe-CD8O8Ul0.js → haxe-C8oCnwJJ.js} +1 -1
  76. package/viewer-dist/assets/{highlights-B57wCzB5.js → highlights-NUSPeu9U.js} +2 -2
  77. package/viewer-dist/assets/{hlsl-ajL2FB-w.js → hlsl-Cvrh5tZx.js} +1 -1
  78. package/viewer-dist/assets/html-CvoVzlT3.js +1 -0
  79. package/viewer-dist/assets/{html-derivative-DyzJkWO6.js → html-derivative-CmO0_REm.js} +1 -1
  80. package/viewer-dist/assets/{http-BjrBtiM6.js → http-c4_vT9ST.js} +1 -1
  81. package/viewer-dist/assets/{hurl-B4P9s9G3.js → hurl-BqZA9I9Q.js} +1 -1
  82. package/viewer-dist/assets/hxml-Dcm88srW.js +1 -0
  83. package/viewer-dist/assets/index-C8Oxwcs8.js +264 -0
  84. package/viewer-dist/assets/{ini-0B7NLFlx.js → ini-B5eOa1yu.js} +1 -1
  85. package/viewer-dist/assets/java-D7h0NA_A.js +1 -0
  86. package/viewer-dist/assets/javascript-DcMHgNcu.js +1 -0
  87. package/viewer-dist/assets/{jinja-dRcm23Ea.js → jinja-IxhZJXij.js} +1 -1
  88. package/viewer-dist/assets/{jison-D3aJooqo.js → jison-Ru_S5AEn.js} +1 -1
  89. package/viewer-dist/assets/json-DePJdKYk.js +1 -0
  90. package/viewer-dist/assets/{jsonc-dcnCvL0G.js → jsonc-CYpm1nAK.js} +1 -1
  91. package/viewer-dist/assets/jsx-BUUYi3qs.js +1 -0
  92. package/viewer-dist/assets/julia-BuaSHoYZ.js +1 -0
  93. package/viewer-dist/assets/just-BJW1YJYB.js +1 -0
  94. package/viewer-dist/assets/langs-Di6vPLUk.js +2 -0
  95. package/viewer-dist/assets/{latex-B_Ztlc7G.js → latex-B6yY1rfM.js} +1 -1
  96. package/viewer-dist/assets/{less-B64L-FWb.js → less-DVTAwKKz.js} +1 -1
  97. package/viewer-dist/assets/{liquid-CQNtsgCr.js → liquid-DNgNMjPq.js} +1 -1
  98. package/viewer-dist/assets/loader-Cvp9wZb2.js +1 -0
  99. package/viewer-dist/assets/{log-BvtJ4bSl.js → log-BNLmms1o.js} +1 -1
  100. package/viewer-dist/assets/lua-Z49wBRLR.js +1 -0
  101. package/viewer-dist/assets/{make-URElk0GJ.js → make-Dixweg8N.js} +1 -1
  102. package/viewer-dist/assets/{markdown-CboqBxpY.js → markdown-BYOwaDjH.js} +1 -1
  103. package/viewer-dist/assets/marko-i5cBncq8.js +1 -0
  104. package/viewer-dist/assets/mdc-C3wRYKz5.js +1 -0
  105. package/viewer-dist/assets/nextflow-CSgcYZcx.js +1 -0
  106. package/viewer-dist/assets/{nextflow-groovy-C770ykRh.js → nextflow-groovy-D7IRt6Pp.js} +1 -1
  107. package/viewer-dist/assets/{nginx-BxRBJ-Af.js → nginx-BrbrEdla.js} +1 -1
  108. package/viewer-dist/assets/nim-BCe7ZKXY.js +1 -0
  109. package/viewer-dist/assets/{objective-c-D_ECFp-D.js → objective-c-D1A_Heim.js} +1 -1
  110. package/viewer-dist/assets/{ocaml-D6dNsUd0.js → ocaml-O90oeIOV.js} +1 -1
  111. package/viewer-dist/assets/org-DDCXkPsd.js +1 -0
  112. package/viewer-dist/assets/{perl-sgZsTtaf.js → perl-DLhC7S_Q.js} +1 -1
  113. package/viewer-dist/assets/{php-D9QpVhjP.js → php-CDzTReqR.js} +1 -1
  114. package/viewer-dist/assets/{postcss-D_Wz94rJ.js → postcss-BXeXVLqQ.js} +1 -1
  115. package/viewer-dist/assets/{powershell-CItYMEtV.js → powershell-QtSnmXcu.js} +1 -1
  116. package/viewer-dist/assets/{pug-nGRwXpob.js → pug-COoI2o4U.js} +1 -1
  117. package/viewer-dist/assets/{python-CzFU0dpx.js → python-gzcpVVnB.js} +1 -1
  118. package/viewer-dist/assets/{qml-BxleM7bJ.js → qml-g4UDed-8.js} +1 -1
  119. package/viewer-dist/assets/r-CvCSiWB_.js +1 -0
  120. package/viewer-dist/assets/{raku-BtFKomnU.js → raku-B3gFvitq.js} +1 -1
  121. package/viewer-dist/assets/{razor-UAq-8THt.js → razor-BRLDaw7i.js} +1 -1
  122. package/viewer-dist/assets/regexp-I2jnduhj.js +1 -0
  123. package/viewer-dist/assets/rst-BEQnCgL0.js +1 -0
  124. package/viewer-dist/assets/{ruby-B6sU6EpJ.js → ruby-COXzLN2W.js} +1 -1
  125. package/viewer-dist/assets/{rust-DBZE5Si3.js → rust-DpiIf5JO.js} +1 -1
  126. package/viewer-dist/assets/{sas-BowjnAvi.js → sas-Cr47JhdL.js} +1 -1
  127. package/viewer-dist/assets/{scala-o2NiCLJc.js → scala-BiFt_7mu.js} +1 -1
  128. package/viewer-dist/assets/scss-BuNb6cgZ.js +1 -0
  129. package/viewer-dist/assets/{sdbl-CpzYUp7e.js → sdbl-bTVj8UrX.js} +1 -1
  130. package/viewer-dist/assets/shaderlab-TOUzSsQk.js +1 -0
  131. package/viewer-dist/assets/shellscript-B51zB43X.js +1 -0
  132. package/viewer-dist/assets/{shellsession-DDrivR0a.js → shellsession-B-KBpmJs.js} +1 -1
  133. package/viewer-dist/assets/shiki-CTIyHrkn.js +2 -0
  134. package/viewer-dist/assets/{soy-CUUUw2U6.js → soy-B-X4e_cm.js} +1 -1
  135. package/viewer-dist/assets/sparql-D_iOobhT.js +1 -0
  136. package/viewer-dist/assets/sql-CrePkbX5.js +1 -0
  137. package/viewer-dist/assets/{stata-Dj4sbAEx.js → stata-LQMPNdRb.js} +1 -1
  138. package/viewer-dist/assets/{stream-tokenizer-a_hv0fYK.js → stream-tokenizer-8imCpDcl.js} +2 -2
  139. package/viewer-dist/assets/{stylus-LiTfbrWi.js → stylus-B6D30XZt.js} +1 -1
  140. package/viewer-dist/assets/{surrealql-NoXzmj18.js → surrealql-DalIYx4r.js} +1 -1
  141. package/viewer-dist/assets/svelte-CutSaB0m.js +1 -0
  142. package/viewer-dist/assets/{swift-DQ24oLw9.js → swift-CyEgAFGc.js} +1 -1
  143. package/viewer-dist/assets/{system-verilog-Dp2k_mze.js → system-verilog-Dh5ihWbf.js} +1 -1
  144. package/viewer-dist/assets/templ-STIZV9cS.js +1 -0
  145. package/viewer-dist/assets/tex-JPaUWOrn.js +1 -0
  146. package/viewer-dist/assets/themes-CGzFOfgV.js +2 -0
  147. package/viewer-dist/assets/{ts-tags-DLz2GTd3.js → ts-tags-DugY2c1f.js} +1 -1
  148. package/viewer-dist/assets/tsx-DvWhG4dC.js +1 -0
  149. package/viewer-dist/assets/{turtle-CcN57yC0.js → turtle-ByJddavk.js} +1 -1
  150. package/viewer-dist/assets/twig-CAQ2meH1.js +1 -0
  151. package/viewer-dist/assets/typescript-BTGs5etX.js +1 -0
  152. package/viewer-dist/assets/typst-D2auzO0m.js +1 -0
  153. package/viewer-dist/assets/{vb-3nVziYZS.js → vb-DOwzaHZ0.js} +1 -1
  154. package/viewer-dist/assets/{verilog-kL8Dwv27.js → verilog-B2gwz-sJ.js} +1 -1
  155. package/viewer-dist/assets/vue-Bu9nv_eN.js +1 -0
  156. package/viewer-dist/assets/{vue-html-CGMs_6qn.js → vue-html-BXjKVtKk.js} +1 -1
  157. package/viewer-dist/assets/vue-vine-Ci2qndh_.js +1 -0
  158. package/viewer-dist/assets/xml-C01ajBW7.js +1 -0
  159. package/viewer-dist/assets/{xsl-Czhm44Ae.js → xsl-CCLNyvR3.js} +1 -1
  160. package/viewer-dist/assets/yaml-BWCS3NLV.js +1 -0
  161. package/viewer-dist/assets/{zig-B7sSDI6F.js → zig-CMLA9XwU.js} +1 -1
  162. package/viewer-dist/index.html +1 -7
  163. package/viewer-dist/assets/angular-html-BswFT_28.js +0 -1
  164. package/viewer-dist/assets/angular-html-Cwa-lTMy.js +0 -1
  165. package/viewer-dist/assets/angular-ts-DOMhGxLQ.js +0 -1
  166. package/viewer-dist/assets/appendItems-BRdTC5zu.js +0 -3
  167. package/viewer-dist/assets/astro-CN6YWUG3.js +0 -1
  168. package/viewer-dist/assets/bat-Di-EdOIU.js +0 -1
  169. package/viewer-dist/assets/bibtex-CimSBJhw.js +0 -1
  170. package/viewer-dist/assets/blade-BrDpNfUX.js +0 -1
  171. package/viewer-dist/assets/bsl-gRq8cI6V.js +0 -1
  172. package/viewer-dist/assets/c-DWGmR78Y.js +0 -1
  173. package/viewer-dist/assets/c-SSSlmE39.js +0 -1
  174. package/viewer-dist/assets/cairo-D66nqRlU.js +0 -1
  175. package/viewer-dist/assets/clojure-BrC3BItl.js +0 -1
  176. package/viewer-dist/assets/cmake-BRht3inD.js +0 -1
  177. package/viewer-dist/assets/coffee-drHG6SJT.js +0 -1
  178. package/viewer-dist/assets/constants-CmGPilXJ.js +0 -1
  179. package/viewer-dist/assets/core-B86SFyc0.js +0 -1
  180. package/viewer-dist/assets/cpp-BDT6bThX.js +0 -1
  181. package/viewer-dist/assets/cpp-CcLCVKG_.js +0 -1
  182. package/viewer-dist/assets/csharp-DtuFCOLR.js +0 -1
  183. package/viewer-dist/assets/css-BGIxQoYs.js +0 -1
  184. package/viewer-dist/assets/css-DUjzNfgv.js +0 -1
  185. package/viewer-dist/assets/csv-D6mwZ2PH.js +0 -1
  186. package/viewer-dist/assets/dart-B8JJT_EX.js +0 -1
  187. package/viewer-dist/assets/diff-B0S3HUPm.js +0 -1
  188. package/viewer-dist/assets/docker-B3DZKTds.js +0 -1
  189. package/viewer-dist/assets/edge-B_SBzXGF.js +0 -1
  190. package/viewer-dist/assets/elixir-B0EKSUNS.js +0 -1
  191. package/viewer-dist/assets/erlang-CCXss5H6.js +0 -1
  192. package/viewer-dist/assets/erlang-DAWODyxE.js +0 -1
  193. package/viewer-dist/assets/formatCSSVariablePrefix-KRh9vnZf.js +0 -1
  194. package/viewer-dist/assets/fortran-fixed-form-1cK5gXa1.js +0 -1
  195. package/viewer-dist/assets/fortran-free-form-9zh5t3u2.js +0 -1
  196. package/viewer-dist/assets/fsharp-C37UASp4.js +0 -1
  197. package/viewer-dist/assets/fsharp-D8ZPuVlk.js +0 -1
  198. package/viewer-dist/assets/gdresource-LxjHb83i.js +0 -1
  199. package/viewer-dist/assets/gdscript-C2iVvkL_.js +0 -1
  200. package/viewer-dist/assets/gdshader-BpaOOKdG.js +0 -1
  201. package/viewer-dist/assets/git-commit-BAuDFD-1.js +0 -1
  202. package/viewer-dist/assets/git-commit-rNeRxB9Y.js +0 -1
  203. package/viewer-dist/assets/git-rebase-Cpv8mbcu.js +0 -1
  204. package/viewer-dist/assets/glsl-CaPTrB3a.js +0 -1
  205. package/viewer-dist/assets/glsl-ThNHWs2E.js +0 -1
  206. package/viewer-dist/assets/go-BrE3Phef.js +0 -1
  207. package/viewer-dist/assets/graphql-DAzSVzvB.js +0 -1
  208. package/viewer-dist/assets/graphql-DEIChqxY.js +0 -1
  209. package/viewer-dist/assets/groovy-D_Q3n-An.js +0 -1
  210. package/viewer-dist/assets/haml-C1zHJAQt.js +0 -1
  211. package/viewer-dist/assets/haml-mwfMQlUs.js +0 -1
  212. package/viewer-dist/assets/handlebars-CEZndQNl.js +0 -1
  213. package/viewer-dist/assets/haxe-j5FdAS1V.js +0 -1
  214. package/viewer-dist/assets/hlsl-C3sg_olF.js +0 -1
  215. package/viewer-dist/assets/html-DSw1lh5G.js +0 -1
  216. package/viewer-dist/assets/html-WQKKblVZ.js +0 -1
  217. package/viewer-dist/assets/html-derivative-CjJKezcp.js +0 -1
  218. package/viewer-dist/assets/hxml-DPF7XkXa.js +0 -1
  219. package/viewer-dist/assets/index-CVKGwJkR.js +0 -255
  220. package/viewer-dist/assets/ini-DxURaTxO.js +0 -1
  221. package/viewer-dist/assets/java-BtIQNnN0.js +0 -1
  222. package/viewer-dist/assets/java-DxlWrXwe.js +0 -1
  223. package/viewer-dist/assets/javascript-BzbQS41l.js +0 -1
  224. package/viewer-dist/assets/javascript-Yelw-5ZN.js +0 -1
  225. package/viewer-dist/assets/json-B88Oqtu5.js +0 -1
  226. package/viewer-dist/assets/json-CaljABEy.js +0 -1
  227. package/viewer-dist/assets/jsonc-CTI_jrid.js +0 -1
  228. package/viewer-dist/assets/jsx-D3KKoC5L.js +0 -1
  229. package/viewer-dist/assets/jsx-hEbJ82HF.js +0 -1
  230. package/viewer-dist/assets/julia-BCOw4cyx.js +0 -1
  231. package/viewer-dist/assets/julia-hqywDEUR.js +0 -1
  232. package/viewer-dist/assets/just-Br47BmIC.js +0 -1
  233. package/viewer-dist/assets/langs-JgP7EaER.js +0 -2
  234. package/viewer-dist/assets/latex-Djh9Fg1h.js +0 -1
  235. package/viewer-dist/assets/less-GWsDhusf.js +0 -1
  236. package/viewer-dist/assets/lib-IuaA1a0_.js +0 -9
  237. package/viewer-dist/assets/loader-D4gJynmd.js +0 -1
  238. package/viewer-dist/assets/log-DSUv6hjM.js +0 -1
  239. package/viewer-dist/assets/lua-BJObVtAx.js +0 -1
  240. package/viewer-dist/assets/lua-DjuecEsk.js +0 -1
  241. package/viewer-dist/assets/make-BLT6fICl.js +0 -1
  242. package/viewer-dist/assets/markdown-Cla8Gbs6.js +0 -1
  243. package/viewer-dist/assets/marko-DPS0EkZ1.js +0 -1
  244. package/viewer-dist/assets/mdc-C6srEd4p.js +0 -1
  245. package/viewer-dist/assets/nextflow-groovy-1acFxZ7Y.js +0 -1
  246. package/viewer-dist/assets/nextflow-uA5IJerx.js +0 -1
  247. package/viewer-dist/assets/nim-Dr8hIC6Y.js +0 -1
  248. package/viewer-dist/assets/nim-ZjzS1dcU.js +0 -1
  249. package/viewer-dist/assets/objective-c-DMLMCfZd.js +0 -1
  250. package/viewer-dist/assets/ocaml-oSZO9LTw.js +0 -1
  251. package/viewer-dist/assets/org-B3Y3gBCc.js +0 -1
  252. package/viewer-dist/assets/perl-Di9CLCS0.js +0 -1
  253. package/viewer-dist/assets/php-DXPvgw5o.js +0 -1
  254. package/viewer-dist/assets/postcss-e3XvZOFQ.js +0 -1
  255. package/viewer-dist/assets/powershell-DyPZnz5v.js +0 -1
  256. package/viewer-dist/assets/preload-helper-BZ1Pz5am.js +0 -1
  257. package/viewer-dist/assets/pug-BlofpNpK.js +0 -1
  258. package/viewer-dist/assets/python-ORI17Sev.js +0 -1
  259. package/viewer-dist/assets/r-DWzjseEo.js +0 -1
  260. package/viewer-dist/assets/r-Dr1JUpHl.js +0 -1
  261. package/viewer-dist/assets/raku-B6hKIqfP.js +0 -1
  262. package/viewer-dist/assets/regexp-B4pBNbU3.js +0 -1
  263. package/viewer-dist/assets/regexp-BWpGejPw.js +0 -1
  264. package/viewer-dist/assets/rst-DT-C-5fA.js +0 -1
  265. package/viewer-dist/assets/ruby-BwIxDKXu.js +0 -1
  266. package/viewer-dist/assets/rust-tUOVui2B.js +0 -1
  267. package/viewer-dist/assets/scala-Dcd77NNm.js +0 -1
  268. package/viewer-dist/assets/scss-CWs8DVSa.js +0 -1
  269. package/viewer-dist/assets/scss-Dec6wfVg.js +0 -1
  270. package/viewer-dist/assets/sdbl-DFPhMlBm.js +0 -1
  271. package/viewer-dist/assets/shaderlab-DY7g_Ava.js +0 -1
  272. package/viewer-dist/assets/shellscript-BiGZg9Om.js +0 -1
  273. package/viewer-dist/assets/shellscript-CqHdAlCp.js +0 -1
  274. package/viewer-dist/assets/shiki-BYYByAlk.js +0 -2
  275. package/viewer-dist/assets/sparql-Dy5Sx-zJ.js +0 -1
  276. package/viewer-dist/assets/sql-BOsskAmu.js +0 -1
  277. package/viewer-dist/assets/sql-CNu3Or2W.js +0 -1
  278. package/viewer-dist/assets/stylus-BOYZFyl7.js +0 -1
  279. package/viewer-dist/assets/svelte-BaCIHHWd.js +0 -1
  280. package/viewer-dist/assets/swift-CpxeRS9H.js +0 -1
  281. package/viewer-dist/assets/system-verilog-CIGW6CHD.js +0 -1
  282. package/viewer-dist/assets/templ-BfgLc4ra.js +0 -1
  283. package/viewer-dist/assets/tex-C9L8xJex.js +0 -1
  284. package/viewer-dist/assets/tex-CeakZqzU.js +0 -1
  285. package/viewer-dist/assets/themes-DP0gt5jG.js +0 -2
  286. package/viewer-dist/assets/tsx-5f3ulCja.js +0 -1
  287. package/viewer-dist/assets/tsx-BOvsFOI6.js +0 -1
  288. package/viewer-dist/assets/turtle-B2uMLKuz.js +0 -1
  289. package/viewer-dist/assets/twig-BuizuR2K.js +0 -1
  290. package/viewer-dist/assets/twig-p9meEoSL.js +0 -1
  291. package/viewer-dist/assets/typescript-Utq2Cl8c.js +0 -1
  292. package/viewer-dist/assets/typescript-j_1H8WHN.js +0 -1
  293. package/viewer-dist/assets/typst-qZ7a-KdK.js +0 -1
  294. package/viewer-dist/assets/unwrapDefault-ByDmBtHB.js +0 -1
  295. package/viewer-dist/assets/vb-Dcr14nCw.js +0 -1
  296. package/viewer-dist/assets/verilog-DUw2aqD4.js +0 -1
  297. package/viewer-dist/assets/vue-qH43U_rv.js +0 -1
  298. package/viewer-dist/assets/vue-vine-6XI2pIvQ.js +0 -1
  299. package/viewer-dist/assets/xml-CoDIzWF0.js +0 -1
  300. package/viewer-dist/assets/xml-WY0zc4PG.js +0 -1
  301. package/viewer-dist/assets/xsl-ChYNfH-b.js +0 -1
  302. package/viewer-dist/assets/yaml-CxbubiML.js +0 -1
  303. package/viewer-dist/assets/yaml-DijMHRDA.js +0 -1
  304. package/viewer-dist/assets/zig-VWdiCTxG.js +0 -1
package/lib/git.js CHANGED
@@ -403,10 +403,37 @@ function totals(entries) {
403
403
  deletions: sum.deletions + entry.deletions,
404
404
  }), { additions: 0, deletions: 0 });
405
405
  }
406
- /**
407
- * Loads every commit rev a document uses and checks that each commit
408
- * reference names a changed file and a range inside its new version.
409
- */
406
+ /** Read a text file at a commit (or a commit range's destination), never the worktree. */
407
+ export async function readSnapshotReference(root, reference) {
408
+ const { rev, path: file } = reference;
409
+ if (!isCommitRev(rev))
410
+ return new DiffmapGitError({ reason: `Invalid snapshot rev: ${rev}.` });
411
+ if (!file ||
412
+ !path.resolve(root, file).startsWith(path.resolve(root) + path.sep))
413
+ return new DiffmapGitError({ reason: "Path escapes the workspace." });
414
+ const commit = await resolveCommit(root, rev.split("..").at(-1));
415
+ if (commit instanceof Error)
416
+ return commit;
417
+ const contents = await git(root, ["cat-file", "blob", `${commit}:./${file}`]);
418
+ if (contents instanceof Error)
419
+ return new DiffmapGitError({ reason: `${file} does not exist at ${rev}.` });
420
+ if (contents.includes("\0"))
421
+ return new DiffmapGitError({ reason: `${file} is binary at ${rev}.` });
422
+ const lines = countLines(contents);
423
+ const start = reference.start ?? 1;
424
+ const end = reference.end ?? Math.max(1, lines);
425
+ if (reference.end !== undefined && end > lines)
426
+ return new DiffmapGitError({
427
+ reason: `[[${rev}:${file}]]: line ${String(end)} is past the end of ${file} (${String(lines)} lines) after ${rev}.`,
428
+ });
429
+ if (!Number.isSafeInteger(start) ||
430
+ !Number.isSafeInteger(end) ||
431
+ start < 1 ||
432
+ end < start)
433
+ return new DiffmapGitError({ reason: `Invalid line range for ${file}.` });
434
+ return { path: file, contents, start, end };
435
+ }
436
+ /** Load commit diffs and snapshot any unchanged supporting references. */
410
437
  export async function readDocumentChanges(root, document) {
411
438
  // Uncommitted revs are read live; only commits are checked and snapshotted.
412
439
  const commitCards = document.changeCards.filter((card) => isCommitRev(card.rev));
@@ -437,10 +464,18 @@ export async function readDocumentChanges(root, document) {
437
464
  .get(reference.rev)
438
465
  .files.find((item) => item.path === reference.path);
439
466
  const label = `[[${reference.rev}:${reference.path}]]`;
440
- if (file === undefined)
441
- return new DiffmapGitError({
442
- reason: `${label}: ${reference.path} is not changed in ${reference.rev}.`,
467
+ if (file === undefined) {
468
+ const snapshot = await readSnapshotReference(root, {
469
+ ...reference,
470
+ rev: reference.rev,
443
471
  });
472
+ if (snapshot instanceof Error)
473
+ return snapshot;
474
+ const changes = loaded.get(reference.rev);
475
+ changes.sources ??= {};
476
+ changes.sources[reference.path] = snapshot.contents;
477
+ continue;
478
+ }
444
479
  if (reference.end === undefined)
445
480
  continue;
446
481
  const lines = file.contents?.new === undefined ? 0 : countLines(file.contents.new);
@@ -26,3 +26,4 @@ export declare function githubViewerUrl(owner: string, repo: string, pin: {
26
26
  }, filePath: string, origin?: string): string;
27
27
  export declare function githubBlobUrl(owner: string, repo: string, sha: string, filePath: string): string;
28
28
  export declare function githubPullUrl(owner: string, repo: string, pull: number): string;
29
+ export declare function githubCommitUrl(owner: string, repo: string, sha: string): string;
@@ -35,7 +35,10 @@ export function parseGitHubPath(pathname) {
35
35
  const specPath = parts.slice(4).map(decodePathSegment).join("/");
36
36
  if (kind === "pull") {
37
37
  if (!PULL_PATTERN.test(id)) {
38
- return { kind: "github-invalid", message: "Not a pull request number." };
38
+ return {
39
+ kind: "github-invalid",
40
+ message: "The part after pull/ isn't a pull request number.",
41
+ };
39
42
  }
40
43
  const pathError = specPathError(specPath);
41
44
  if (pathError !== undefined)
@@ -49,7 +52,10 @@ export function parseGitHubPath(pathname) {
49
52
  };
50
53
  }
51
54
  if (!SHA_PATTERN.test(id)) {
52
- return { kind: "github-invalid", message: "Not a git commit SHA." };
55
+ return {
56
+ kind: "github-invalid",
57
+ message: "The part after commit/ isn't a commit SHA.",
58
+ };
53
59
  }
54
60
  const pathError = specPathError(specPath);
55
61
  if (pathError !== undefined)
@@ -83,6 +89,9 @@ export function githubBlobUrl(owner, repo, sha, filePath) {
83
89
  export function githubPullUrl(owner, repo, pull) {
84
90
  return `https://github.com/${owner}/${repo}/pull/${String(pull)}`;
85
91
  }
92
+ export function githubCommitUrl(owner, repo, sha) {
93
+ return `https://github.com/${owner}/${repo}/commit/${sha}`;
94
+ }
86
95
  function isRepoName(value) {
87
96
  return (NAME_PATTERN.test(value) &&
88
97
  value !== "." &&
@@ -91,14 +100,14 @@ function isRepoName(value) {
91
100
  }
92
101
  function specPathError(specPath) {
93
102
  if (specPath.length === 0) {
94
- return "A hosted spec URL needs a spec directory or markdown file after the pull or commit.";
103
+ return "The link needs a spec's directory or Markdown file after the pull request or commit.";
95
104
  }
96
105
  if (specPath.split("/").some((part) => part === "." || part === "..")) {
97
- return "Spec path is not a repository file.";
106
+ return "The spec path isn't a file in the repository.";
98
107
  }
99
108
  const name = specPath.slice(specPath.lastIndexOf("/") + 1);
100
109
  if (name.includes(".", 1) && !MARKDOWN_EXT.test(name)) {
101
- return "Spec path must be a .md or .mdx file, or a spec's directory.";
110
+ return "The link must end in a spec's directory or a .md or .mdx file.";
102
111
  }
103
112
  return undefined;
104
113
  }
@@ -48,6 +48,20 @@ export type Fence = {
48
48
  /** Paths after an `ignore:` line: changed files a reviewer can skip. */
49
49
  ignore: string[];
50
50
  source: string;
51
+ } | {
52
+ kind: "preview";
53
+ /** Storybook story IDs, one per line. */
54
+ stories: string[];
55
+ title: string | undefined;
56
+ source: string;
57
+ } | {
58
+ kind: "flow";
59
+ /** The states in source order; the first is where the flow starts. */
60
+ states: FlowState[];
61
+ /** Why the tree is malformed; parseViewerDocument reports it. */
62
+ problem: string | undefined;
63
+ title: string | undefined;
64
+ source: string;
51
65
  } | {
52
66
  kind: "file";
53
67
  path: string;
@@ -69,8 +83,24 @@ export type Fence = {
69
83
  /** From the info string, as in ```ts [src/request.ts]. */
70
84
  title: string | undefined;
71
85
  };
86
+ export type FlowState = {
87
+ /** The Storybook story ID whose play function reaches this state from its parent. */
88
+ story: string;
89
+ /** The index of the state this one follows, or undefined for the first. */
90
+ parent: number | undefined;
91
+ /** What the person does to get here, as in "Log in". */
92
+ action: string | undefined;
93
+ };
72
94
  export declare function isCallStackSource(source: string): boolean;
73
95
  export declare function pathFromDiffSource(source: string): string | undefined;
74
96
  export declare function parseFence(lang: string, source: string, highlights?: number[], title?: string,
75
97
  /** The info string after the language and highlights, as in ```mermaid diff. */
76
98
  meta?: string): Fence;
99
+ /**
100
+ * Each line is a story ID, indented under the state it follows, with the action that leads to it after a colon:
101
+ * `auth-log-in--wrong-password: Log in`. The first line is the start and has no action.
102
+ */
103
+ export declare function parseFlow(source: string): {
104
+ states: FlowState[];
105
+ problem: string | undefined;
106
+ };
package/lib/parseFence.js CHANGED
@@ -37,6 +37,18 @@ meta) {
37
37
  return { kind: "html", source: trimmed };
38
38
  if (lang === "callstack")
39
39
  return callStackFence(trimmed, highlights, title);
40
+ if (lang === "preview")
41
+ return {
42
+ kind: "preview",
43
+ stories: trimmed
44
+ .split("\n")
45
+ .map((line) => line.trim())
46
+ .filter((line) => line.length > 0),
47
+ title,
48
+ source: trimmed,
49
+ };
50
+ if (lang === "flow")
51
+ return { kind: "flow", ...parseFlow(trimmed), title, source: trimmed };
40
52
  // The first line is the rev (blank for uncommitted); each later line is a path to review, or to ignore after an `ignore:` line.
41
53
  if (lang === "changes") {
42
54
  const [rev = "", ...lines] = trimmed.split("\n").map((line) => line.trim());
@@ -124,6 +136,56 @@ function mermaidFence(source, diff, title) {
124
136
  title,
125
137
  };
126
138
  }
139
+ /**
140
+ * Each line is a story ID, indented under the state it follows, with the action that leads to it after a colon:
141
+ * `auth-log-in--wrong-password: Log in`. The first line is the start and has no action.
142
+ */
143
+ export function parseFlow(source) {
144
+ const states = [];
145
+ const open = [];
146
+ for (const [offset, line] of source.split("\n").entries()) {
147
+ if (line.trim().length === 0)
148
+ continue;
149
+ const where = `flow line ${offset + 1}`;
150
+ const indent = line.length - line.trimStart().length;
151
+ const colon = line.indexOf(":");
152
+ const story = (colon === -1 ? line : line.slice(0, colon)).trim();
153
+ const action = colon === -1 ? undefined : line.slice(colon + 1).trim();
154
+ while (open.length > 0 && open.at(-1).indent >= indent)
155
+ open.pop();
156
+ const parent = open.at(-1)?.index;
157
+ if (states.length > 0 && parent === undefined)
158
+ return {
159
+ states,
160
+ problem: `${where} is not indented under a state. A flow has one starting state; indent each later state under the one it follows`,
161
+ };
162
+ if (parent === undefined && action !== undefined)
163
+ return {
164
+ states,
165
+ problem: `${where} is the starting state, so it has no action. Write only its story ID`,
166
+ };
167
+ if (parent !== undefined && (action === undefined || action === ""))
168
+ return {
169
+ states,
170
+ problem: `${where} needs the action that leads to it, as in "${story}: Log in"`,
171
+ };
172
+ if (!/^[a-z0-9-]+--[a-z0-9-]+$/.test(story))
173
+ return {
174
+ states,
175
+ problem: `${where}: "${story}" is not a Storybook story ID, which looks like auth-log-in--wrong-password`,
176
+ };
177
+ if (states.some((state) => state.story === story))
178
+ return {
179
+ states,
180
+ problem: `${where} lists ${story} twice. Each state's story is one step from the state above it, so it appears once`,
181
+ };
182
+ states.push({ story, parent, action });
183
+ open.push({ indent, index: states.length - 1 });
184
+ }
185
+ if (states.length === 0)
186
+ return { states, problem: "a flow lists at least its starting story" };
187
+ return { states, problem: undefined };
188
+ }
127
189
  function callStackFence(source, highlights, title) {
128
190
  const { code, notes } = parseCodeNotes(source);
129
191
  return {
@@ -40,6 +40,21 @@ export function parseViewerDocument(source, path = "spec") {
40
40
  return new DiffmapAnnotationError({ reason: problem });
41
41
  continue;
42
42
  }
43
+ if (fence.kind === "preview") {
44
+ const invalid = fence.stories.find((story) => !/^[a-z0-9-]+--[a-z0-9-]+$/.test(story));
45
+ if (fence.stories.length === 0 || invalid !== undefined)
46
+ return new DiffmapAnnotationError({
47
+ reason: invalid === undefined
48
+ ? "a preview fence lists at least one Storybook story ID, one per line"
49
+ : `preview "${invalid}" is not a Storybook story ID, which looks like design-button--primary`,
50
+ });
51
+ continue;
52
+ }
53
+ if (fence.kind === "flow") {
54
+ if (fence.problem !== undefined)
55
+ return new DiffmapAnnotationError({ reason: fence.problem });
56
+ continue;
57
+ }
43
58
  if (fence.kind !== "changes")
44
59
  continue;
45
60
  if (!isRev(fence.rev)) {
@@ -0,0 +1,20 @@
1
+ import { type RefObject } from "react";
2
+ import { type StoryCatalog, type StoryModules } from "./protocol.js";
3
+ /**
4
+ * Renders the story named by `?story=` with Storybook's portable stories API, inside the app's own build.
5
+ * The app applies its Storybook preview with `setProjectAnnotations` first, so decorators and providers wrap each story.
6
+ * Framed by a diffmap viewer, it also answers the viewer's messages and reports each story it shows.
7
+ *
8
+ * A flow state comes with its path, the stories from the flow's first story to it. Each story after the first is one step:
9
+ * its play function starts from what the story before it shows. To reach a state the page renders the first story and
10
+ * plays each step; to move to a child of the state it shows, it plays only the child's step on the UI already there.
11
+ */
12
+ export declare function PreviewRoute({ stories }: {
13
+ stories: StoryModules;
14
+ }): import("react").JSX.Element | undefined;
15
+ export declare function PreviewView({ catalog, storyId, renderKey, containerRef, }: {
16
+ catalog: StoryCatalog;
17
+ storyId: string | undefined;
18
+ renderKey?: number;
19
+ containerRef?: RefObject<HTMLDivElement | null>;
20
+ }): import("react").JSX.Element;
@@ -0,0 +1,279 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { composeStories } from "@storybook/react";
3
+ import { userEvent, within } from "storybook/test";
4
+ import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
5
+ import { PREVIEW_PROTOCOL, errorMessage, fingerprint, isViewerOrigin, parsePath, parseViewerMessage, resolveStories, storyInfo, } from "./protocol.js";
6
+ /** In the live frame a step's typing and clicks are paced so a reader can follow them; replays and thumbnails run at once. */
7
+ const PACED_DELAY_MS = 35;
8
+ /**
9
+ * Renders the story named by `?story=` with Storybook's portable stories API, inside the app's own build.
10
+ * The app applies its Storybook preview with `setProjectAnnotations` first, so decorators and providers wrap each story.
11
+ * Framed by a diffmap viewer, it also answers the viewer's messages and reports each story it shows.
12
+ *
13
+ * A flow state comes with its path, the stories from the flow's first story to it. Each story after the first is one step:
14
+ * its play function starts from what the story before it shows. To reach a state the page renders the first story and
15
+ * plays each step; to move to a child of the state it shows, it plays only the child's step on the UI already there.
16
+ */
17
+ export function PreviewRoute({ stories }) {
18
+ const catalog = useMemo(() => resolveStories(stories, composeStories), [stories]);
19
+ const [initial] = useState(() => {
20
+ const params = new URLSearchParams(window.location.search);
21
+ const story = params.get("story") ?? undefined;
22
+ if (story === undefined)
23
+ return undefined;
24
+ return parsePath(params.get("path")?.split(","), story) ?? [story];
25
+ });
26
+ const [requested, setRequested] = useState(initial?.at(-1));
27
+ const [shown, setShown] = useState(undefined);
28
+ const containerRef = useRef(null);
29
+ const viewerOrigin = useRef(undefined);
30
+ const lastSize = useRef("");
31
+ const lastState = useRef("");
32
+ const runCount = useRef(0);
33
+ /** The path the UI has reached, once every step of it played. */
34
+ const reached = useRef(undefined);
35
+ const live = useRef(true);
36
+ const post = useCallback((message) => {
37
+ if (viewerOrigin.current === undefined || window.parent === window)
38
+ return;
39
+ window.parent.postMessage(message, viewerOrigin.current);
40
+ }, []);
41
+ const reportSize = useCallback(() => {
42
+ const container = containerRef.current;
43
+ if (container === null)
44
+ return;
45
+ const width = container.offsetWidth;
46
+ const height = container.offsetHeight;
47
+ const size = `${width}x${height}`;
48
+ if (size === lastSize.current)
49
+ return;
50
+ lastSize.current = size;
51
+ post({ type: "preview-size", width, height });
52
+ }, [post]);
53
+ const reportState = useCallback(() => {
54
+ const container = containerRef.current;
55
+ const story = reached.current?.path.at(-1);
56
+ if (story === undefined || container === null)
57
+ return;
58
+ const state = { story, fingerprint: fingerprint(container.innerHTML) };
59
+ const key = `${state.story} ${state.fingerprint}`;
60
+ if (key === lastState.current)
61
+ return;
62
+ lastState.current = key;
63
+ post({ type: "preview-state", ...state });
64
+ }, [post]);
65
+ const playStep = useCallback(async (id, paced) => {
66
+ const story = catalog.stories.get(id).Story;
67
+ const container = containerRef.current;
68
+ if (story.play === undefined || container === null)
69
+ return;
70
+ const play = () => story.play({
71
+ canvasElement: container,
72
+ canvas: within(container),
73
+ // oxlint-disable-next-line unicorn/no-null -- user-event's own value for no delay.
74
+ userEvent: userEvent.setup({ delay: paced ? PACED_DELAY_MS : null }),
75
+ });
76
+ await (paced ? play() : withoutScrollingToFocus(play));
77
+ }, [catalog]);
78
+ const show = useCallback(async (path, how) => {
79
+ const missing = path.find((id) => !catalog.stories.has(id));
80
+ if (missing !== undefined) {
81
+ post({
82
+ type: "preview-error",
83
+ message: `There is no story "${missing}".`,
84
+ });
85
+ return;
86
+ }
87
+ const count = ++runCount.current;
88
+ const target = path.at(-1);
89
+ const from = reached.current;
90
+ if (how === "play" &&
91
+ from !== undefined &&
92
+ from.path.length === path.length - 1 &&
93
+ from.path.every((id, index) => path[index] === id)) {
94
+ reached.current = undefined;
95
+ try {
96
+ await catalog.stories.get(target).Story.load();
97
+ if (count !== runCount.current)
98
+ return;
99
+ await playStep(target, live.current);
100
+ if (count !== runCount.current)
101
+ return;
102
+ reached.current = { path, key: from.key };
103
+ setUrl(path);
104
+ requestAnimationFrame(reportState);
105
+ return;
106
+ }
107
+ catch (error) {
108
+ post({
109
+ type: "preview-error",
110
+ message: `The step to "${target}" threw, so it was rendered from the start: ${errorMessage(error)}`,
111
+ });
112
+ }
113
+ }
114
+ try {
115
+ await catalog.stories.get(path[0]).Story.load();
116
+ }
117
+ catch (error) {
118
+ post({
119
+ type: "preview-error",
120
+ message: `Loading "${path[0]}" failed: ${errorMessage(error)}`,
121
+ });
122
+ return;
123
+ }
124
+ if (count !== runCount.current)
125
+ return;
126
+ reached.current = undefined;
127
+ setShown({ path, key: count });
128
+ setUrl(path);
129
+ }, [catalog, playStep, post, reportState]);
130
+ useEffect(() => {
131
+ if (initial !== undefined && initial.every((id) => catalog.stories.has(id)))
132
+ void show(initial, "render");
133
+ }, [catalog, initial, show]);
134
+ useEffect(() => {
135
+ // Storybook runs a story's play function once it has rendered, so a story defined by interactions reaches its state.
136
+ if (shown === undefined)
137
+ return;
138
+ const container = containerRef.current;
139
+ if (container === null)
140
+ return;
141
+ const observer = new ResizeObserver(reportSize);
142
+ observer.observe(container);
143
+ let current = true;
144
+ void (async () => {
145
+ for (const [index, id] of shown.path.entries()) {
146
+ if (!current)
147
+ return;
148
+ try {
149
+ if (index > 0)
150
+ await catalog.stories.get(id).Story.load();
151
+ if (!current)
152
+ return;
153
+ await playStep(id, false);
154
+ }
155
+ catch (error) {
156
+ if (!current)
157
+ return;
158
+ post({
159
+ type: "preview-error",
160
+ message: `The play function of "${id}" threw: ${errorMessage(error)}`,
161
+ });
162
+ break;
163
+ }
164
+ }
165
+ if (!current)
166
+ return;
167
+ reached.current = { path: shown.path, key: shown.key };
168
+ requestAnimationFrame(reportState);
169
+ })();
170
+ return () => {
171
+ current = false;
172
+ observer.disconnect();
173
+ };
174
+ }, [catalog, playStep, post, reportSize, reportState, shown]);
175
+ useEffect(() => {
176
+ function onMessage(event) {
177
+ if (event.source !== window.parent || !isViewerOrigin(event.origin))
178
+ return;
179
+ const message = parseViewerMessage(event.data);
180
+ if (message === undefined)
181
+ return;
182
+ if (message.type === "preview-connect") {
183
+ viewerOrigin.current = event.origin;
184
+ lastSize.current = "";
185
+ lastState.current = "";
186
+ post({
187
+ type: "preview-ready",
188
+ protocol: PREVIEW_PROTOCOL,
189
+ stories: [...catalog.stories.values()].map(storyInfo),
190
+ });
191
+ if (requested !== undefined && !catalog.stories.has(requested))
192
+ post({
193
+ type: "preview-error",
194
+ message: `There is no story "${requested}".`,
195
+ });
196
+ reportSize();
197
+ reportState();
198
+ return;
199
+ }
200
+ if (event.origin !== viewerOrigin.current)
201
+ return;
202
+ if (message.type === "preview-show") {
203
+ setRequested(message.story);
204
+ void show(message.path ?? [message.story], message.how);
205
+ }
206
+ else {
207
+ live.current = message.mode === "live";
208
+ document.documentElement.dataset.previewMode = message.mode;
209
+ }
210
+ }
211
+ window.addEventListener("message", onMessage);
212
+ return () => window.removeEventListener("message", onMessage);
213
+ }, [catalog, post, reportSize, reportState, requested, show]);
214
+ useEffect(() => {
215
+ // The viewer's preview-connect can arrive before React mounts the listener, so the page asks for it once it listens.
216
+ // The hello goes to any parent because it carries nothing; the catalog only goes to a viewer origin that connects.
217
+ if (window.parent !== window)
218
+ window.parent.postMessage({
219
+ type: "preview-hello",
220
+ protocol: PREVIEW_PROTOCOL,
221
+ }, "*");
222
+ }, []);
223
+ if (requested !== undefined &&
224
+ shown === undefined &&
225
+ catalog.stories.has(requested))
226
+ return undefined;
227
+ return (_jsx(PreviewView, { catalog: catalog, storyId: shown?.path[0] ?? requested, renderKey: shown?.key, containerRef: containerRef }));
228
+ }
229
+ function setUrl(path) {
230
+ const url = new URL(window.location.href);
231
+ url.searchParams.set("story", path.at(-1));
232
+ if (path.length > 1)
233
+ url.searchParams.set("path", path.join(","));
234
+ else
235
+ url.searchParams.delete("path");
236
+ window.history.replaceState(window.history.state, "", url);
237
+ }
238
+ export function PreviewView({ catalog, storyId, renderKey, containerRef, }) {
239
+ if (catalog.problems.length > 0)
240
+ return (_jsx(Notice, { title: "Fix these story files", children: _jsx("ul", { children: catalog.problems.map((problem) => (_jsx("li", { children: problem }, problem))) }) }));
241
+ const story = storyId === undefined ? undefined : catalog.stories.get(storyId);
242
+ if (story === undefined)
243
+ return (_jsx(Notice, { title: storyId === undefined
244
+ ? "Pick a story"
245
+ : `There is no story "${storyId}".`, children: _jsx(StoryIndex, { catalog: catalog }) }));
246
+ const { Story } = story;
247
+ return (_jsx("div", { ref: containerRef, "data-preview-story": story.id, style: { display: "flow-root" }, children: _jsx(Story, {}) }, renderKey));
248
+ }
249
+ function StoryIndex({ catalog }) {
250
+ if (catalog.stories.size === 0)
251
+ return _jsx("p", { children: "No stories yet. Add a *.stories.tsx file with a title." });
252
+ const byTitle = new Map();
253
+ for (const story of catalog.stories.values())
254
+ byTitle.set(story.title, [...(byTitle.get(story.title) ?? []), story]);
255
+ return (_jsx("ul", { children: [...byTitle].map(([title, stories]) => (_jsxs("li", { children: [title, _jsx("ul", { children: stories.map((story) => (_jsx("li", { children: _jsx("a", { href: `?${new URLSearchParams({ story: story.id })}`, children: story.name }) }, story.id))) })] }, title))) }));
256
+ }
257
+ const noticeStyle = {
258
+ margin: 16,
259
+ padding: 16,
260
+ border: "1px solid currentColor",
261
+ borderRadius: 8,
262
+ font: "14px/1.5 system-ui, sans-serif",
263
+ };
264
+ function Notice({ title, children }) {
265
+ return (_jsxs("div", { role: "alert", "data-preview-notice": "", style: noticeStyle, children: [_jsx("strong", { children: title }), children] }));
266
+ }
267
+ /** Replaying steps focuses inputs, and focusing inside a frame scrolls the viewer to it; an instant replay is not something the reader asked to watch. */
268
+ async function withoutScrollingToFocus(run) {
269
+ const focus = HTMLElement.prototype.focus;
270
+ HTMLElement.prototype.focus = function (options) {
271
+ focus.call(this, { ...options, preventScroll: true });
272
+ };
273
+ try {
274
+ await run();
275
+ }
276
+ finally {
277
+ HTMLElement.prototype.focus = focus;
278
+ }
279
+ }
@@ -0,0 +1,3 @@
1
+ export { PreviewRoute } from "./PreviewRoute.js";
2
+ export { isViewerOrigin, PREVIEW_PROTOCOL, previewFrameAncestors, } from "./protocol.js";
3
+ export type { PreviewRouteMessage, PreviewStoryInfo, PreviewViewerMessage, StoryModules, } from "./protocol.js";
@@ -0,0 +1,2 @@
1
+ export { PreviewRoute } from "./PreviewRoute.js";
2
+ export { isViewerOrigin, PREVIEW_PROTOCOL, previewFrameAncestors, } from "./protocol.js";
@@ -0,0 +1,85 @@
1
+ import type { ComponentType } from "react";
2
+ export declare const PREVIEW_PROTOCOL = 1;
3
+ /** A story as the page sends it to the viewer. */
4
+ export type PreviewStoryInfo = {
5
+ id: string;
6
+ title: string;
7
+ name: string;
8
+ /** The story's `parameters.docs.description.story`, which Storybook's docs also show. */
9
+ description?: string;
10
+ hasPlay: boolean;
11
+ };
12
+ export type PreviewRouteMessage = {
13
+ type: "preview-hello";
14
+ protocol: typeof PREVIEW_PROTOCOL;
15
+ } | {
16
+ type: "preview-ready";
17
+ protocol: typeof PREVIEW_PROTOCOL;
18
+ stories: PreviewStoryInfo[];
19
+ } | {
20
+ type: "preview-size";
21
+ width: number;
22
+ height: number;
23
+ } | {
24
+ type: "preview-state";
25
+ story: string;
26
+ fingerprint: string;
27
+ } | {
28
+ type: "preview-error";
29
+ message: string;
30
+ };
31
+ export type PreviewViewerMessage = {
32
+ type: "preview-connect";
33
+ } | {
34
+ type: "preview-show";
35
+ story: string;
36
+ how: "render" | "play";
37
+ /** A flow state's stories from the flow's first story to `story`; see PreviewRoute. */
38
+ path?: string[];
39
+ } | {
40
+ type: "preview-mode";
41
+ mode: "live" | "thumbnail";
42
+ };
43
+ /** The pages that may frame the page: the local viewer, which listens on any port, and diffmap.dev. */
44
+ export declare function isViewerOrigin(origin: string): boolean;
45
+ /** The `Content-Security-Policy` the page should be served with, so only the viewer can frame it. */
46
+ export declare const previewFrameAncestors = "frame-ancestors 'self' http://127.0.0.1:* http://localhost:* https://www.diffmap.dev";
47
+ export declare function parseViewerMessage(data: unknown): PreviewViewerMessage | undefined;
48
+ /** A path is kept only when it is a list of story IDs that ends at `story`. */
49
+ export declare function parsePath(value: unknown, story: string): string[] | undefined;
50
+ /** FNV-1a of the story's rendered HTML: it changes when the markup or its classes do, so review marks can tell a story changed. */
51
+ export declare function fingerprint(html: string): string;
52
+ /** The parts of a story composed by Storybook's `composeStories` that the page uses. */
53
+ export type ComposedPreviewStory = ComponentType & {
54
+ id: string;
55
+ storyName: string;
56
+ parameters: Record<string, unknown>;
57
+ load: () => Promise<void>;
58
+ /** Storybook's composed play merges the context it is given, so the page supplies `canvas` and a paced `userEvent`. */
59
+ play?: (context: {
60
+ canvasElement: HTMLElement;
61
+ canvas?: unknown;
62
+ userEvent?: unknown;
63
+ }) => Promise<void>;
64
+ };
65
+ export type CatalogStory = PreviewStoryInfo & {
66
+ Story: ComposedPreviewStory;
67
+ };
68
+ export type StoryCatalog = {
69
+ stories: Map<string, CatalogStory>;
70
+ /** Mistakes in the story files, shown in place of any story so the agent fixes them first. */
71
+ problems: string[];
72
+ };
73
+ /** What `import.meta.glob("../**\/*.stories.tsx", { eager: true })` returns. */
74
+ export type StoryModules = Record<string, unknown>;
75
+ export type ComposeStories = (module: Record<string, unknown>) => Record<string, ComposedPreviewStory>;
76
+ export declare function resolveStories(modules: StoryModules, composeStories: ComposeStories): StoryCatalog;
77
+ export declare function storyInfo({ Story: _Story, ...info }: CatalogStory): {
78
+ id: string;
79
+ title: string;
80
+ name: string;
81
+ /** The story's `parameters.docs.description.story`, which Storybook's docs also show. */
82
+ description?: string;
83
+ hasPlay: boolean;
84
+ };
85
+ export declare function errorMessage(error: unknown): string;