@elastic/isomer-studio 0.0.0 → 0.4.0

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 (406) hide show
  1. package/LICENSE.txt +93 -0
  2. package/NOTICE.txt +17329 -0
  3. package/README.md +64 -0
  4. package/THIRD_PARTY_LICENSES.md +404 -0
  5. package/bin/isomer-studio.js +10 -0
  6. package/dist/app/assets/codicon-5T574S7B.ttf +0 -0
  7. package/dist/app/assets/editor.worker.js +11 -0
  8. package/dist/app/assets/esbuild.wasm +0 -0
  9. package/dist/app/assets/json.worker.js +47 -0
  10. package/dist/app/assets/slack.css +1 -0
  11. package/dist/app/assets/studio.css +11 -0
  12. package/dist/app/assets/ts.worker.js +37029 -0
  13. package/dist/app/index.html +16 -0
  14. package/dist/apps/app_host.d.ts +8 -0
  15. package/dist/apps/app_host.d.ts.map +1 -0
  16. package/dist/apps/app_host.js +73 -0
  17. package/dist/apps/app_host.js.map +1 -0
  18. package/dist/browser/dev_host.d.ts +5 -0
  19. package/dist/browser/dev_host.d.ts.map +1 -0
  20. package/dist/browser/dev_host.js +46 -0
  21. package/dist/browser/dev_host.js.map +1 -0
  22. package/dist/browser/mount.d.ts +16 -0
  23. package/dist/browser/mount.d.ts.map +1 -0
  24. package/dist/browser/mount.js +37 -0
  25. package/dist/browser/mount.js.map +1 -0
  26. package/dist/browser/static_host.d.ts +5 -0
  27. package/dist/browser/static_host.d.ts.map +1 -0
  28. package/dist/browser/static_host.js +55 -0
  29. package/dist/browser/static_host.js.map +1 -0
  30. package/dist/chrome/accent.d.ts +14 -0
  31. package/dist/chrome/accent.d.ts.map +1 -0
  32. package/dist/chrome/accent.js +31 -0
  33. package/dist/chrome/accent.js.map +1 -0
  34. package/dist/chrome/app_pages.d.ts +13 -0
  35. package/dist/chrome/app_pages.d.ts.map +1 -0
  36. package/dist/chrome/app_pages.js +33 -0
  37. package/dist/chrome/app_pages.js.map +1 -0
  38. package/dist/chrome/color_mode.d.ts +10 -0
  39. package/dist/chrome/color_mode.d.ts.map +1 -0
  40. package/dist/chrome/color_mode.js +45 -0
  41. package/dist/chrome/color_mode.js.map +1 -0
  42. package/dist/chrome/dev_tint.d.ts +7 -0
  43. package/dist/chrome/dev_tint.d.ts.map +1 -0
  44. package/dist/chrome/dev_tint.js +31 -0
  45. package/dist/chrome/dev_tint.js.map +1 -0
  46. package/dist/chrome/header.d.ts +20 -0
  47. package/dist/chrome/header.d.ts.map +1 -0
  48. package/dist/chrome/header.js +124 -0
  49. package/dist/chrome/header.js.map +1 -0
  50. package/dist/chrome/icon_data_uri.d.ts +12 -0
  51. package/dist/chrome/icon_data_uri.d.ts.map +1 -0
  52. package/dist/chrome/icon_data_uri.js +21 -0
  53. package/dist/chrome/icon_data_uri.js.map +1 -0
  54. package/dist/chrome/isomer_mark.d.ts +17 -0
  55. package/dist/chrome/isomer_mark.d.ts.map +1 -0
  56. package/dist/chrome/isomer_mark.js +46 -0
  57. package/dist/chrome/isomer_mark.js.map +1 -0
  58. package/dist/chrome/nav.d.ts +22 -0
  59. package/dist/chrome/nav.d.ts.map +1 -0
  60. package/dist/chrome/nav.js +306 -0
  61. package/dist/chrome/nav.js.map +1 -0
  62. package/dist/chrome/nav_groups.d.ts +6 -0
  63. package/dist/chrome/nav_groups.d.ts.map +1 -0
  64. package/dist/chrome/nav_groups.js +48 -0
  65. package/dist/chrome/nav_groups.js.map +1 -0
  66. package/dist/chrome/nav_sections.d.ts +29 -0
  67. package/dist/chrome/nav_sections.d.ts.map +1 -0
  68. package/dist/chrome/nav_sections.js +55 -0
  69. package/dist/chrome/nav_sections.js.map +1 -0
  70. package/dist/chrome/oklch.d.ts +10 -0
  71. package/dist/chrome/oklch.d.ts.map +1 -0
  72. package/dist/chrome/oklch.js +61 -0
  73. package/dist/chrome/oklch.js.map +1 -0
  74. package/dist/chrome/primitive_glyph.d.ts +14 -0
  75. package/dist/chrome/primitive_glyph.d.ts.map +1 -0
  76. package/dist/chrome/primitive_glyph.js +48 -0
  77. package/dist/chrome/primitive_glyph.js.map +1 -0
  78. package/dist/chrome/primitive_heading.d.ts +14 -0
  79. package/dist/chrome/primitive_heading.d.ts.map +1 -0
  80. package/dist/chrome/primitive_heading.js +32 -0
  81. package/dist/chrome/primitive_heading.js.map +1 -0
  82. package/dist/chrome/primitive_peek.d.ts +8 -0
  83. package/dist/chrome/primitive_peek.d.ts.map +1 -0
  84. package/dist/chrome/primitive_peek.js +51 -0
  85. package/dist/chrome/primitive_peek.js.map +1 -0
  86. package/dist/chrome/primitive_search.d.ts +9 -0
  87. package/dist/chrome/primitive_search.d.ts.map +1 -0
  88. package/dist/chrome/primitive_search.js +93 -0
  89. package/dist/chrome/primitive_search.js.map +1 -0
  90. package/dist/chrome/route.d.ts +48 -0
  91. package/dist/chrome/route.d.ts.map +1 -0
  92. package/dist/chrome/route.js +136 -0
  93. package/dist/chrome/route.js.map +1 -0
  94. package/dist/cli/args.d.ts +39 -0
  95. package/dist/cli/args.d.ts.map +1 -0
  96. package/dist/cli/args.js +171 -0
  97. package/dist/cli/args.js.map +1 -0
  98. package/dist/cli/run.d.ts +15 -0
  99. package/dist/cli/run.d.ts.map +1 -0
  100. package/dist/cli/run.js +113 -0
  101. package/dist/cli/run.js.map +1 -0
  102. package/dist/cli.d.ts +2 -0
  103. package/dist/cli.d.ts.map +1 -0
  104. package/dist/cli.js +22 -0
  105. package/dist/cli.js.map +1 -0
  106. package/dist/config.d.ts +118 -0
  107. package/dist/config.d.ts.map +1 -0
  108. package/dist/config.js +11 -0
  109. package/dist/config.js.map +1 -0
  110. package/dist/dev/code_editor.d.ts +10 -0
  111. package/dist/dev/code_editor.d.ts.map +1 -0
  112. package/dist/dev/code_editor.js +22 -0
  113. package/dist/dev/code_editor.js.map +1 -0
  114. package/dist/dev/dev_view.d.ts +9 -0
  115. package/dist/dev/dev_view.d.ts.map +1 -0
  116. package/dist/dev/dev_view.js +65 -0
  117. package/dist/dev/dev_view.js.map +1 -0
  118. package/dist/dev/editor_panel.d.ts +17 -0
  119. package/dist/dev/editor_panel.d.ts.map +1 -0
  120. package/dist/dev/editor_panel.js +51 -0
  121. package/dist/dev/editor_panel.js.map +1 -0
  122. package/dist/dev/monaco_editor.d.ts +15 -0
  123. package/dist/dev/monaco_editor.d.ts.map +1 -0
  124. package/dist/dev/monaco_editor.js +159 -0
  125. package/dist/dev/monaco_editor.js.map +1 -0
  126. package/dist/dev/preview_panel.d.ts +10 -0
  127. package/dist/dev/preview_panel.d.ts.map +1 -0
  128. package/dist/dev/preview_panel.js +45 -0
  129. package/dist/dev/preview_panel.js.map +1 -0
  130. package/dist/dev/prop_reference.d.ts +9 -0
  131. package/dist/dev/prop_reference.d.ts.map +1 -0
  132. package/dist/dev/prop_reference.js +134 -0
  133. package/dist/dev/prop_reference.js.map +1 -0
  134. package/dist/dev/tsx_language.d.ts +10 -0
  135. package/dist/dev/tsx_language.d.ts.map +1 -0
  136. package/dist/dev/tsx_language.js +283 -0
  137. package/dist/dev/tsx_language.js.map +1 -0
  138. package/dist/dev/use_editor.d.ts +23 -0
  139. package/dist/dev/use_editor.d.ts.map +1 -0
  140. package/dist/dev/use_editor.js +124 -0
  141. package/dist/dev/use_editor.js.map +1 -0
  142. package/dist/docs/docs_view.d.ts +10 -0
  143. package/dist/docs/docs_view.d.ts.map +1 -0
  144. package/dist/docs/docs_view.js +80 -0
  145. package/dist/docs/docs_view.js.map +1 -0
  146. package/dist/docs/example_source.d.ts +7 -0
  147. package/dist/docs/example_source.d.ts.map +1 -0
  148. package/dist/docs/example_source.js +56 -0
  149. package/dist/docs/example_source.js.map +1 -0
  150. package/dist/docs/examples_panel.d.ts +10 -0
  151. package/dist/docs/examples_panel.d.ts.map +1 -0
  152. package/dist/docs/examples_panel.js +51 -0
  153. package/dist/docs/examples_panel.js.map +1 -0
  154. package/dist/docs/gallery_view.d.ts +9 -0
  155. package/dist/docs/gallery_view.d.ts.map +1 -0
  156. package/dist/docs/gallery_view.js +98 -0
  157. package/dist/docs/gallery_view.js.map +1 -0
  158. package/dist/docs/inline_code.d.ts +11 -0
  159. package/dist/docs/inline_code.d.ts.map +1 -0
  160. package/dist/docs/inline_code.js +24 -0
  161. package/dist/docs/inline_code.js.map +1 -0
  162. package/dist/docs/on_this_page.d.ts +17 -0
  163. package/dist/docs/on_this_page.d.ts.map +1 -0
  164. package/dist/docs/on_this_page.js +77 -0
  165. package/dist/docs/on_this_page.js.map +1 -0
  166. package/dist/docs/props_table.d.ts +14 -0
  167. package/dist/docs/props_table.d.ts.map +1 -0
  168. package/dist/docs/props_table.js +34 -0
  169. package/dist/docs/props_table.js.map +1 -0
  170. package/dist/home/apps_section.d.ts +6 -0
  171. package/dist/home/apps_section.d.ts.map +1 -0
  172. package/dist/home/apps_section.js +44 -0
  173. package/dist/home/apps_section.js.map +1 -0
  174. package/dist/home/featured_strip.d.ts +12 -0
  175. package/dist/home/featured_strip.d.ts.map +1 -0
  176. package/dist/home/featured_strip.js +176 -0
  177. package/dist/home/featured_strip.js.map +1 -0
  178. package/dist/home/home_view.d.ts +11 -0
  179. package/dist/home/home_view.d.ts.map +1 -0
  180. package/dist/home/home_view.js +261 -0
  181. package/dist/home/home_view.js.map +1 -0
  182. package/dist/home/links.d.ts +8 -0
  183. package/dist/home/links.d.ts.map +1 -0
  184. package/dist/home/links.js +14 -0
  185. package/dist/home/links.js.map +1 -0
  186. package/dist/home/loaded_panel.d.ts +6 -0
  187. package/dist/home/loaded_panel.d.ts.map +1 -0
  188. package/dist/home/loaded_panel.js +116 -0
  189. package/dist/home/loaded_panel.js.map +1 -0
  190. package/dist/home/surface_chart.d.ts +6 -0
  191. package/dist/home/surface_chart.d.ts.map +1 -0
  192. package/dist/home/surface_chart.js +263 -0
  193. package/dist/home/surface_chart.js.map +1 -0
  194. package/dist/home/tokens.d.ts +49 -0
  195. package/dist/home/tokens.d.ts.map +1 -0
  196. package/dist/home/tokens.js +171 -0
  197. package/dist/home/tokens.js.map +1 -0
  198. package/dist/index.d.ts +6 -0
  199. package/dist/index.d.ts.map +1 -0
  200. package/dist/index.js +9 -0
  201. package/dist/index.js.map +1 -0
  202. package/dist/model/app_problems.d.ts +4 -0
  203. package/dist/model/app_problems.d.ts.map +1 -0
  204. package/dist/model/app_problems.js +90 -0
  205. package/dist/model/app_problems.js.map +1 -0
  206. package/dist/model/authoring_types.d.ts +23 -0
  207. package/dist/model/authoring_types.d.ts.map +1 -0
  208. package/dist/model/authoring_types.js +35 -0
  209. package/dist/model/authoring_types.js.map +1 -0
  210. package/dist/model/compile_jsx.d.ts +19 -0
  211. package/dist/model/compile_jsx.d.ts.map +1 -0
  212. package/dist/model/compile_jsx.js +55 -0
  213. package/dist/model/compile_jsx.js.map +1 -0
  214. package/dist/model/compose_example.d.ts +9 -0
  215. package/dist/model/compose_example.d.ts.map +1 -0
  216. package/dist/model/compose_example.js +24 -0
  217. package/dist/model/compose_example.js.map +1 -0
  218. package/dist/model/composition_key.d.ts +6 -0
  219. package/dist/model/composition_key.d.ts.map +1 -0
  220. package/dist/model/composition_key.js +26 -0
  221. package/dist/model/composition_key.js.map +1 -0
  222. package/dist/model/describe_runtime.d.ts +33 -0
  223. package/dist/model/describe_runtime.d.ts.map +1 -0
  224. package/dist/model/describe_runtime.js +77 -0
  225. package/dist/model/describe_runtime.js.map +1 -0
  226. package/dist/model/featured.d.ts +11 -0
  227. package/dist/model/featured.d.ts.map +1 -0
  228. package/dist/model/featured.js +70 -0
  229. package/dist/model/featured.js.map +1 -0
  230. package/dist/model/jsx_transform.d.ts +10 -0
  231. package/dist/model/jsx_transform.d.ts.map +1 -0
  232. package/dist/model/jsx_transform.js +31 -0
  233. package/dist/model/jsx_transform.js.map +1 -0
  234. package/dist/model/png_manifest.d.ts +23 -0
  235. package/dist/model/png_manifest.d.ts.map +1 -0
  236. package/dist/model/png_manifest.js +26 -0
  237. package/dist/model/png_manifest.js.map +1 -0
  238. package/dist/model/read_examples.d.ts +12 -0
  239. package/dist/model/read_examples.d.ts.map +1 -0
  240. package/dist/model/read_examples.js +43 -0
  241. package/dist/model/read_examples.js.map +1 -0
  242. package/dist/model/search.d.ts +4 -0
  243. package/dist/model/search.d.ts.map +1 -0
  244. package/dist/model/search.js +29 -0
  245. package/dist/model/search.js.map +1 -0
  246. package/dist/model/sha256.d.ts +3 -0
  247. package/dist/model/sha256.d.ts.map +1 -0
  248. package/dist/model/sha256.js +72 -0
  249. package/dist/model/sha256.js.map +1 -0
  250. package/dist/model/slack_limits.d.ts +9 -0
  251. package/dist/model/slack_limits.d.ts.map +1 -0
  252. package/dist/model/slack_limits.js +213 -0
  253. package/dist/model/slack_limits.js.map +1 -0
  254. package/dist/node/app_bundle.d.ts +45 -0
  255. package/dist/node/app_bundle.d.ts.map +1 -0
  256. package/dist/node/app_bundle.js +212 -0
  257. package/dist/node/app_bundle.js.map +1 -0
  258. package/dist/node/build_site.d.ts +28 -0
  259. package/dist/node/build_site.d.ts.map +1 -0
  260. package/dist/node/build_site.js +90 -0
  261. package/dist/node/build_site.js.map +1 -0
  262. package/dist/node/check.d.ts +40 -0
  263. package/dist/node/check.d.ts.map +1 -0
  264. package/dist/node/check.js +162 -0
  265. package/dist/node/check.js.map +1 -0
  266. package/dist/node/dev_bundle.d.ts +21 -0
  267. package/dist/node/dev_bundle.d.ts.map +1 -0
  268. package/dist/node/dev_bundle.js +121 -0
  269. package/dist/node/dev_bundle.js.map +1 -0
  270. package/dist/node/dev_server.d.ts +16 -0
  271. package/dist/node/dev_server.d.ts.map +1 -0
  272. package/dist/node/dev_server.js +291 -0
  273. package/dist/node/dev_server.js.map +1 -0
  274. package/dist/node/init_config.d.ts +30 -0
  275. package/dist/node/init_config.d.ts.map +1 -0
  276. package/dist/node/init_config.js +158 -0
  277. package/dist/node/init_config.js.map +1 -0
  278. package/dist/node/load_config.d.ts +34 -0
  279. package/dist/node/load_config.d.ts.map +1 -0
  280. package/dist/node/load_config.js +246 -0
  281. package/dist/node/load_config.js.map +1 -0
  282. package/dist/node/project_resolution.d.ts +17 -0
  283. package/dist/node/project_resolution.d.ts.map +1 -0
  284. package/dist/node/project_resolution.js +66 -0
  285. package/dist/node/project_resolution.js.map +1 -0
  286. package/dist/node/rasterize.d.ts +23 -0
  287. package/dist/node/rasterize.d.ts.map +1 -0
  288. package/dist/node/rasterize.js +79 -0
  289. package/dist/node/rasterize.js.map +1 -0
  290. package/dist/node/report.d.ts +8 -0
  291. package/dist/node/report.d.ts.map +1 -0
  292. package/dist/node/report.js +57 -0
  293. package/dist/node/report.js.map +1 -0
  294. package/dist/node/resolve_hooks.d.ts +16 -0
  295. package/dist/node/resolve_hooks.d.ts.map +1 -0
  296. package/dist/node/resolve_hooks.js +104 -0
  297. package/dist/node/resolve_hooks.js.map +1 -0
  298. package/dist/studio.d.ts +4 -0
  299. package/dist/studio.d.ts.map +1 -0
  300. package/dist/studio.js +188 -0
  301. package/dist/studio.js.map +1 -0
  302. package/dist/studio_context.d.ts +27 -0
  303. package/dist/studio_context.d.ts.map +1 -0
  304. package/dist/studio_context.js +17 -0
  305. package/dist/studio_context.js.map +1 -0
  306. package/dist/surfaces/adopt_stylesheet.d.ts +7 -0
  307. package/dist/surfaces/adopt_stylesheet.d.ts.map +1 -0
  308. package/dist/surfaces/adopt_stylesheet.js +64 -0
  309. package/dist/surfaces/adopt_stylesheet.js.map +1 -0
  310. package/dist/surfaces/app_preview.d.ts +4 -0
  311. package/dist/surfaces/app_preview.d.ts.map +1 -0
  312. package/dist/surfaces/app_preview.js +28 -0
  313. package/dist/surfaces/app_preview.js.map +1 -0
  314. package/dist/surfaces/app_surface.d.ts +9 -0
  315. package/dist/surfaces/app_surface.d.ts.map +1 -0
  316. package/dist/surfaces/app_surface.js +27 -0
  317. package/dist/surfaces/app_surface.js.map +1 -0
  318. package/dist/surfaces/applicable_enhancements.d.ts +4 -0
  319. package/dist/surfaces/applicable_enhancements.d.ts.map +1 -0
  320. package/dist/surfaces/applicable_enhancements.js +16 -0
  321. package/dist/surfaces/applicable_enhancements.js.map +1 -0
  322. package/dist/surfaces/enhancement_select.d.ts +10 -0
  323. package/dist/surfaces/enhancement_select.d.ts.map +1 -0
  324. package/dist/surfaces/enhancement_select.js +28 -0
  325. package/dist/surfaces/enhancement_select.js.map +1 -0
  326. package/dist/surfaces/example_picker.d.ts +11 -0
  327. package/dist/surfaces/example_picker.d.ts.map +1 -0
  328. package/dist/surfaces/example_picker.js +44 -0
  329. package/dist/surfaces/example_picker.js.map +1 -0
  330. package/dist/surfaces/format_source.d.ts +4 -0
  331. package/dist/surfaces/format_source.d.ts.map +1 -0
  332. package/dist/surfaces/format_source.js +30 -0
  333. package/dist/surfaces/format_source.js.map +1 -0
  334. package/dist/surfaces/html_surface.d.ts +14 -0
  335. package/dist/surfaces/html_surface.d.ts.map +1 -0
  336. package/dist/surfaces/html_surface.js +122 -0
  337. package/dist/surfaces/html_surface.js.map +1 -0
  338. package/dist/surfaces/png_surface.d.ts +13 -0
  339. package/dist/surfaces/png_surface.d.ts.map +1 -0
  340. package/dist/surfaces/png_surface.js +68 -0
  341. package/dist/surfaces/png_surface.js.map +1 -0
  342. package/dist/surfaces/react_surface.d.ts +11 -0
  343. package/dist/surfaces/react_surface.d.ts.map +1 -0
  344. package/dist/surfaces/react_surface.js +55 -0
  345. package/dist/surfaces/react_surface.js.map +1 -0
  346. package/dist/surfaces/render_output.d.ts +31 -0
  347. package/dist/surfaces/render_output.d.ts.map +1 -0
  348. package/dist/surfaces/render_output.js +119 -0
  349. package/dist/surfaces/render_output.js.map +1 -0
  350. package/dist/surfaces/scaled_preview.d.ts +17 -0
  351. package/dist/surfaces/scaled_preview.d.ts.map +1 -0
  352. package/dist/surfaces/scaled_preview.js +74 -0
  353. package/dist/surfaces/scaled_preview.js.map +1 -0
  354. package/dist/surfaces/shadow_root.d.ts +8 -0
  355. package/dist/surfaces/shadow_root.d.ts.map +1 -0
  356. package/dist/surfaces/shadow_root.js +41 -0
  357. package/dist/surfaces/shadow_root.js.map +1 -0
  358. package/dist/surfaces/slack_surface.d.ts +12 -0
  359. package/dist/surfaces/slack_surface.d.ts.map +1 -0
  360. package/dist/surfaces/slack_surface.js +27 -0
  361. package/dist/surfaces/slack_surface.js.map +1 -0
  362. package/dist/surfaces/snapshot_surface.d.ts +6 -0
  363. package/dist/surfaces/snapshot_surface.d.ts.map +1 -0
  364. package/dist/surfaces/snapshot_surface.js +5 -0
  365. package/dist/surfaces/snapshot_surface.js.map +1 -0
  366. package/dist/surfaces/surface_board.d.ts +19 -0
  367. package/dist/surfaces/surface_board.d.ts.map +1 -0
  368. package/dist/surfaces/surface_board.js +128 -0
  369. package/dist/surfaces/surface_board.js.map +1 -0
  370. package/dist/surfaces/surface_frame.d.ts +8 -0
  371. package/dist/surfaces/surface_frame.d.ts.map +1 -0
  372. package/dist/surfaces/surface_frame.js +4 -0
  373. package/dist/surfaces/surface_frame.js.map +1 -0
  374. package/dist/surfaces/surface_logos.d.ts +9 -0
  375. package/dist/surfaces/surface_logos.d.ts.map +1 -0
  376. package/dist/surfaces/surface_logos.js +21 -0
  377. package/dist/surfaces/surface_logos.js.map +1 -0
  378. package/dist/surfaces/surface_preview.d.ts +32 -0
  379. package/dist/surfaces/surface_preview.d.ts.map +1 -0
  380. package/dist/surfaces/surface_preview.js +66 -0
  381. package/dist/surfaces/surface_preview.js.map +1 -0
  382. package/dist/surfaces/surface_select.d.ts +34 -0
  383. package/dist/surfaces/surface_select.d.ts.map +1 -0
  384. package/dist/surfaces/surface_select.js +119 -0
  385. package/dist/surfaces/surface_select.js.map +1 -0
  386. package/dist/surfaces/text_surfaces.d.ts +14 -0
  387. package/dist/surfaces/text_surfaces.d.ts.map +1 -0
  388. package/dist/surfaces/text_surfaces.js +31 -0
  389. package/dist/surfaces/text_surfaces.js.map +1 -0
  390. package/dist/surfaces/zoom_select.d.ts +9 -0
  391. package/dist/surfaces/zoom_select.d.ts.map +1 -0
  392. package/dist/surfaces/zoom_select.js +32 -0
  393. package/dist/surfaces/zoom_select.js.map +1 -0
  394. package/dist/types.d.ts +32 -0
  395. package/dist/types.d.ts.map +1 -0
  396. package/dist/types.js +9 -0
  397. package/dist/types.js.map +1 -0
  398. package/docs/ci.md +55 -0
  399. package/docs/commands.md +167 -0
  400. package/docs/config.md +192 -0
  401. package/docs/images/home.png +0 -0
  402. package/docs/images/reference.png +0 -0
  403. package/docs/images/workbench.png +0 -0
  404. package/docs/index.md +96 -0
  405. package/docs/toc.yml +10 -0
  406. package/package.json +89 -5
@@ -0,0 +1,93 @@
1
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
2
+ /*
3
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
4
+ * or more contributor license agreements. Licensed under the Elastic License
5
+ * 2.0; you may not use this file except in compliance with the Elastic License
6
+ * 2.0.
7
+ */
8
+ import { useEffect, useMemo, useRef } from 'react';
9
+ import { EuiSelectableTemplateSitewide } from '@elastic/eui';
10
+ import { css } from '@emotion/react';
11
+ import { HOME } from '../home/tokens.js';
12
+ import { useStudio } from '../studio_context.js';
13
+ /** Every primitive by name, purpose and guidance, with ⌘K / Ctrl+K focusing the field. */
14
+ export const PrimitiveSearch = ({ onSelectPrimitive, size = 'compressed', placeholder = 'Search names and descriptions', }) => {
15
+ const { docs: { primitives }, } = useStudio();
16
+ const input = useRef(null);
17
+ useEffect(() => {
18
+ const onKeyDown = (event) => {
19
+ // Editors claim Cmd/Ctrl+K chords by preventing the default.
20
+ if (!event.defaultPrevented &&
21
+ (event.metaKey || event.ctrlKey) &&
22
+ event.key.toLowerCase() === 'k') {
23
+ event.preventDefault();
24
+ input.current?.focus();
25
+ }
26
+ };
27
+ window.addEventListener('keydown', onKeyDown);
28
+ return () => window.removeEventListener('keydown', onKeyDown);
29
+ }, []);
30
+ const options = useMemo(() => primitives.map(({ type, label, group, purpose, useWhen, avoidWhen }) => ({
31
+ key: type,
32
+ label,
33
+ searchableLabel: [type, label, purpose, ...useWhen, ...avoidWhen].join(' '),
34
+ meta: [{ text: group, type: 'application' }, { text: purpose }],
35
+ })), [primitives]);
36
+ const large = size === 'large';
37
+ return (_jsx(EuiSelectableTemplateSitewide, { options: options, onChange: (updated) => {
38
+ const selected = updated.find(({ checked }) => checked === 'on');
39
+ if (selected?.key) {
40
+ onSelectPrimitive(selected.key);
41
+ }
42
+ }, searchProps: {
43
+ placeholder,
44
+ append: '⌘K',
45
+ compressed: !large,
46
+ fullWidth: large,
47
+ inputRef: (element) => {
48
+ input.current = element;
49
+ },
50
+ 'aria-label': 'Search primitives',
51
+ }, popoverProps: { width: large ? 620 : 420 }, css: large
52
+ ? css `
53
+ width: 100%;
54
+ .euiFormControlLayout,
55
+ .euiFieldSearch {
56
+ block-size: 52px;
57
+ }
58
+ .euiFormControlLayout {
59
+ background-color: ${HOME.field};
60
+ }
61
+ .euiFormControlLayout:not(:focus-within)::after {
62
+ border-color: ${HOME.line3};
63
+ }
64
+ .euiFieldSearch {
65
+ background-color: transparent;
66
+ color: ${HOME.fg};
67
+ }
68
+ .euiFieldSearch::placeholder {
69
+ color: ${HOME.fg3};
70
+ }
71
+ .euiFormControlLayoutIcons,
72
+ .euiFormControlLayout__append {
73
+ color: ${HOME.fg2};
74
+ }
75
+ .euiFormControlLayoutIcons {
76
+ max-block-size: none;
77
+ }
78
+ .euiFieldSearch {
79
+ font-size: 15px;
80
+ }
81
+ `
82
+ : css `
83
+ flex: 0 1 280px;
84
+ width: 280px;
85
+ min-width: 72px;
86
+ @media (max-width: 480px) {
87
+ .euiFormControlLayout__append {
88
+ display: none;
89
+ }
90
+ }
91
+ ` }));
92
+ };
93
+ //# sourceMappingURL=primitive_search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive_search.js","sourceRoot":"","sources":["../../src/chrome/primitive_search.tsx"],"names":[],"mappings":";AAAA;;;;;GAKG;AAEH,OAAc,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE1D,OAAO,EAAE,6BAA6B,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,GAAG,EA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F,GAEP,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport React, { useEffect, useMemo, useRef } from 'react';\nimport type { EuiSelectableTemplateSitewideOption } from '@elastic/eui';\nimport { EuiSelectableTemplateSitewide } from '@elastic/eui';\nimport { css } from '@emotion/react';\n\nimport { HOME } from '../home/tokens';\nimport { useStudio } from '../studio_context';\n\nexport interface PrimitiveSearchProps {\n onSelectPrimitive: (type: string) => void;\n /** `compressed` fits the header; `large` is the Home page's search. */\n size?: 'compressed' | 'large' | undefined;\n placeholder?: string | undefined;\n}\n\n/** Every primitive by name, purpose and guidance, with ⌘K / Ctrl+K focusing the field. */\nexport const PrimitiveSearch = ({\n onSelectPrimitive,\n size = 'compressed',\n placeholder = 'Search names and descriptions',\n}: PrimitiveSearchProps) => {\n const {\n docs: { primitives },\n } = useStudio();\n const input = useRef<HTMLInputElement | null>(null);\n\n useEffect(() => {\n const onKeyDown = (event: KeyboardEvent) => {\n // Editors claim Cmd/Ctrl+K chords by preventing the default.\n if (\n !event.defaultPrevented &&\n (event.metaKey || event.ctrlKey) &&\n event.key.toLowerCase() === 'k'\n ) {\n event.preventDefault();\n input.current?.focus();\n }\n };\n window.addEventListener('keydown', onKeyDown);\n return () => window.removeEventListener('keydown', onKeyDown);\n }, []);\n\n const options = useMemo(\n (): EuiSelectableTemplateSitewideOption[] =>\n primitives.map(({ type, label, group, purpose, useWhen, avoidWhen }) => ({\n key: type,\n label,\n searchableLabel: [type, label, purpose, ...useWhen, ...avoidWhen].join(\n ' '\n ),\n meta: [{ text: group, type: 'application' }, { text: purpose }],\n })),\n [primitives]\n );\n\n const large = size === 'large';\n\n return (\n <EuiSelectableTemplateSitewide\n options={options}\n onChange={(updated) => {\n const selected = updated.find(({ checked }) => checked === 'on');\n if (selected?.key) {\n onSelectPrimitive(selected.key);\n }\n }}\n searchProps={{\n placeholder,\n append: '⌘K',\n compressed: !large,\n fullWidth: large,\n inputRef: (element: HTMLInputElement | null) => {\n input.current = element;\n },\n 'aria-label': 'Search primitives',\n }}\n popoverProps={{ width: large ? 620 : 420 }}\n css={\n large\n ? css`\n width: 100%;\n .euiFormControlLayout,\n .euiFieldSearch {\n block-size: 52px;\n }\n .euiFormControlLayout {\n background-color: ${HOME.field};\n }\n .euiFormControlLayout:not(:focus-within)::after {\n border-color: ${HOME.line3};\n }\n .euiFieldSearch {\n background-color: transparent;\n color: ${HOME.fg};\n }\n .euiFieldSearch::placeholder {\n color: ${HOME.fg3};\n }\n .euiFormControlLayoutIcons,\n .euiFormControlLayout__append {\n color: ${HOME.fg2};\n }\n .euiFormControlLayoutIcons {\n max-block-size: none;\n }\n .euiFieldSearch {\n font-size: 15px;\n }\n `\n : css`\n flex: 0 1 280px;\n width: 280px;\n min-width: 72px;\n @media (max-width: 480px) {\n .euiFormControlLayout__append {\n display: none;\n }\n }\n `\n }\n />\n );\n};\n"]}
@@ -0,0 +1,48 @@
1
+ import type { RuntimeDocs } from '../model/describe_runtime.js';
2
+ export type StudioMode = 'dev' | 'docs';
3
+ export interface StudioRoute {
4
+ mode: StudioMode;
5
+ /** A primitive `type`, or `gallery` in docs mode. */
6
+ page: string;
7
+ example: number;
8
+ /** A group title the gallery scrolls to, from `#/docs/gallery/<group>`. */
9
+ group?: string | undefined;
10
+ }
11
+ export interface AppRoute {
12
+ app: string;
13
+ /** Everything after `#/app/<id>/`, which may contain slashes. */
14
+ path: string;
15
+ }
16
+ /** The landing page, at `#/home`, which an empty or unknown hash also opens. */
17
+ export interface HomeRoute {
18
+ home: true;
19
+ }
20
+ export type StudioLocation = StudioRoute | AppRoute | HomeRoute;
21
+ export declare const GALLERY = "gallery";
22
+ export declare const HOME: HomeRoute;
23
+ export declare const isAppRoute: (location: StudioLocation) => location is AppRoute;
24
+ export declare const isHomeRoute: (location: StudioLocation) => location is HomeRoute;
25
+ export declare const isPrimitiveRoute: (location: StudioLocation) => location is StudioRoute;
26
+ /** Reads `#/dev/callout/0`, `#/docs/statGroup`, `#/docs/gallery` or `#/docs/gallery/Text`, falling back to the first primitive. */
27
+ export declare const parseRoute: (hash: string, { primitives, groups }: RuntimeDocs) => StudioRoute;
28
+ /**
29
+ * {@link parseRoute} for `#/dev/...` and `#/docs/...`, `#/app/<id>/<path>` for an id in `appIds`, and
30
+ * {@link HOME} for an empty hash, `#/home`, an unknown app, or any other first segment.
31
+ */
32
+ export declare const parseLocation: (hash: string, docs: RuntimeDocs, appIds: readonly string[]) => StudioLocation;
33
+ export declare const formatRoute: ({ mode, page, example, group, }: StudioRoute) => string;
34
+ export declare const formatLocation: (location: StudioLocation) => string;
35
+ export interface StudioRouter {
36
+ location: StudioLocation;
37
+ /** The current primitive route, or the last one before an app or Home opened. */
38
+ route: StudioRoute;
39
+ /** Moves to a primitive route, merging `next` into {@link StudioRouter.route}. */
40
+ navigate: (next: Partial<StudioRoute>) => void;
41
+ /** `path` is percent-encoded in the hash, segment by segment, and decoded when read back. */
42
+ openApp: (id: string, path?: string) => void;
43
+ /** Opens `#/home`. */
44
+ goHome: () => void;
45
+ }
46
+ /** The location in the URL hash, re-checked whenever the primitives or apps change. */
47
+ export declare const useStudioRoute: (docs: RuntimeDocs, appIds: readonly string[]) => StudioRouter;
48
+ //# sourceMappingURL=route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../src/chrome/route.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAE7D,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,CAAC;AAExC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,KA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KAAK,IAAI,CAAC;IAC7C,sBAAsB;IACtB,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB;AAED,uFAAuF;AACvF,eAAO,MAAM,cAAc,GACzB,MAAM,WAAW,EACjB,QAAQ,SAAS,MAAM,EAAE,KACxB,YAsFF,CAAC"}
@@ -0,0 +1,136 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { useCallback, useEffect, useRef, useState } from 'react';
8
+ export const GALLERY = 'gallery';
9
+ const APP_SEGMENT = 'app';
10
+ const HOME_SEGMENT = 'home';
11
+ export const HOME = { home: true };
12
+ /** A segment as written, when it is not valid percent-encoding. */
13
+ const decodeSegment = (segment) => {
14
+ try {
15
+ return decodeURIComponent(segment);
16
+ }
17
+ catch {
18
+ return segment;
19
+ }
20
+ };
21
+ export const isAppRoute = (location) => 'app' in location;
22
+ export const isHomeRoute = (location) => 'home' in location;
23
+ export const isPrimitiveRoute = (location) => 'mode' in location;
24
+ /** Reads `#/dev/callout/0`, `#/docs/statGroup`, `#/docs/gallery` or `#/docs/gallery/Text`, falling back to the first primitive. */
25
+ export const parseRoute = (hash, { primitives, groups }) => {
26
+ const [mode, page, example] = hash.replace(/^#\/?/, '').split('/');
27
+ const first = groups[0]?.types[0] ?? primitives[0]?.type ?? '';
28
+ const resolvedMode = mode === 'docs' ? 'docs' : 'dev';
29
+ const doc = primitives.find(({ type }) => type === page);
30
+ const index = Number(example);
31
+ if (!doc && resolvedMode === 'docs' && page === GALLERY) {
32
+ const title = example === undefined ? undefined : decodeSegment(example);
33
+ const group = groups.find((candidate) => candidate.title === title);
34
+ return {
35
+ mode: resolvedMode,
36
+ page: GALLERY,
37
+ example: 0,
38
+ ...(group ? { group: group.title } : {}),
39
+ };
40
+ }
41
+ return {
42
+ mode: resolvedMode,
43
+ page: doc ? doc.type : first,
44
+ example: doc &&
45
+ Number.isInteger(index) &&
46
+ index >= 0 &&
47
+ index < doc.examples.length
48
+ ? index
49
+ : 0,
50
+ };
51
+ };
52
+ /**
53
+ * {@link parseRoute} for `#/dev/...` and `#/docs/...`, `#/app/<id>/<path>` for an id in `appIds`, and
54
+ * {@link HOME} for an empty hash, `#/home`, an unknown app, or any other first segment.
55
+ */
56
+ export const parseLocation = (hash, docs, appIds) => {
57
+ const [segment, id, ...rest] = hash.replace(/^#\/?/, '').split('/');
58
+ if (segment === APP_SEGMENT) {
59
+ return id !== undefined && appIds.includes(id)
60
+ ? { app: id, path: rest.map(decodeSegment).join('/') }
61
+ : HOME;
62
+ }
63
+ if (segment === 'dev' || segment === 'docs') {
64
+ return parseRoute(hash, docs);
65
+ }
66
+ return HOME;
67
+ };
68
+ export const formatRoute = ({ mode, page, example, group, }) => page === GALLERY
69
+ ? group === undefined
70
+ ? `#/${mode}/${GALLERY}`
71
+ : `#/${mode}/${GALLERY}/${encodeURIComponent(group)}`
72
+ : `#/${mode}/${page}/${example}`;
73
+ export const formatLocation = (location) => isHomeRoute(location)
74
+ ? `#/${HOME_SEGMENT}`
75
+ : isAppRoute(location)
76
+ ? `#/${APP_SEGMENT}/${location.app}/${location.path.split('/').map(encodeURIComponent).join('/')}`
77
+ : formatRoute(location);
78
+ /** The location in the URL hash, re-checked whenever the primitives or apps change. */
79
+ export const useStudioRoute = (docs, appIds) => {
80
+ const appKey = appIds.join('/');
81
+ const ids = useRef(appIds);
82
+ ids.current = appIds;
83
+ const [location, setLocation] = useState(() => parseLocation(window.location.hash, docs, appIds));
84
+ const [route, setRoute] = useState(() => isPrimitiveRoute(location) ? location : parseRoute('', docs));
85
+ const current = useRef(route);
86
+ current.current = route;
87
+ const shown = useRef(location);
88
+ shown.current = location;
89
+ const show = useCallback((next) => {
90
+ setLocation(next);
91
+ if (isPrimitiveRoute(next)) {
92
+ setRoute(next);
93
+ }
94
+ }, []);
95
+ useEffect(() => {
96
+ const onHashChange = () => show(parseLocation(window.location.hash, docs, ids.current));
97
+ window.addEventListener('hashchange', onHashChange);
98
+ return () => window.removeEventListener('hashchange', onHashChange);
99
+ }, [docs, show]);
100
+ const checked = useRef({ docs, appKey });
101
+ useEffect(() => {
102
+ if (checked.current.docs === docs && checked.current.appKey === appKey) {
103
+ return;
104
+ }
105
+ checked.current = { docs, appKey };
106
+ const remembered = parseRoute(formatRoute(current.current), docs);
107
+ if (formatRoute(remembered) !== formatRoute(current.current)) {
108
+ setRoute(remembered);
109
+ }
110
+ const next = parseLocation(window.location.hash, docs, ids.current);
111
+ const hash = formatLocation(next);
112
+ if (hash === formatLocation(shown.current)) {
113
+ return;
114
+ }
115
+ window.history.replaceState(null, '', hash);
116
+ show(next);
117
+ }, [docs, appKey, show]);
118
+ const go = useCallback((next) => {
119
+ const hash = formatLocation(next);
120
+ if (window.location.hash !== hash) {
121
+ window.history.pushState(null, '', hash);
122
+ }
123
+ show(next);
124
+ }, [show]);
125
+ const navigate = useCallback((next) => {
126
+ const { mode, page, example } = current.current;
127
+ const merged = { mode, page, example, ...next };
128
+ go(parseRoute(formatRoute(merged.mode === 'dev' && merged.page === GALLERY
129
+ ? { ...merged, page: '' }
130
+ : merged), docs));
131
+ }, [docs, go]);
132
+ const openApp = useCallback((id, path = '') => go({ app: id, path }), [go]);
133
+ const goHome = useCallback(() => go(HOME), [go]);
134
+ return { location, route, navigate, openApp, goHome };
135
+ };
136
+ //# sourceMappingURL=route.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route.js","sourceRoot":"","sources":["../../src/chrome/route.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA4BjE,MAAM,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC;AAEjC,MAAM,WAAW,GAAG,KAAK,CAAC;AAC1B,MAAM,YAAY,GAAG,MAAM,CAAC;AAE5B,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Q,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAClC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;QAC3C,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,CAAC;IACb,CAAC,EACD,CAAC,IAAI,CAAC,CACP,CAAC;IAEF,MAAM,QAAQ,GAAG,WAAW,CAC1B,CAAC,IAA0B,EAAE,EAAE;QAC7B,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QAChD,MAAM,MAAM,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,CAAC;QAChD,EAAE,CACA,UAAU,CACR,WAAW,CACT,MAAM,CAAC,IAAI,KAAK,KAAK,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO;YAC9C,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE;YACzB,CAAC,CAAC,MAAM,CACX,EACD,IAAI,CACL,CACF,CAAC;IACJ,CAAC,EACD,CAAC,IAAI,EAAE,EAAE,CAAC,CACX,CAAC;IAEF,MAAM,OAAO,GAAG,WAAW,CACzB,CAAC,EAAU,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,EAChD,CAAC,EAAE,CAAC,CACL,CAAC;IAEF,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;IAEjD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACxD,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport type { RuntimeDocs } from '../model/describe_runtime';\n\nexport type StudioMode = 'dev' | 'docs';\n\nexport interface StudioRoute {\n mode: StudioMode;\n /** A primitive `type`, or `gallery` in docs mode. */\n page: string;\n example: number;\n /** A group title the gallery scrolls to, from `#/docs/gallery/<group>`. */\n group?: string | undefined;\n}\n\nexport interface AppRoute {\n app: string;\n /** Everything after `#/app/<id>/`, which may contain slashes. */\n path: string;\n}\n\n/** The landing page, at `#/home`, which an empty or unknown hash also opens. */\nexport interface HomeRoute {\n home: true;\n}\n\nexport type StudioLocation = StudioRoute | AppRoute | HomeRoute;\n\nexport const GALLERY = 'gallery';\n\nconst APP_SEGMENT = 'app';\nconst HOME_SEGMENT = 'home';\n\nexport const HOME: HomeRoute = { home: true };\n\n/** A segment as written, when it is not valid percent-encoding. */\nconst decodeSegment = (segment: string): string => {\n try {\n return decodeURIComponent(segment);\n } catch {\n return segment;\n }\n};\n\nexport const isAppRoute = (location: StudioLocation): location is AppRoute =>\n 'app' in location;\n\nexport const isHomeRoute = (location: StudioLocation): location is HomeRoute =>\n 'home' in location;\n\nexport const isPrimitiveRoute = (\n location: StudioLocation\n): location is StudioRoute => 'mode' in location;\n\n/** Reads `#/dev/callout/0`, `#/docs/statGroup`, `#/docs/gallery` or `#/docs/gallery/Text`, falling back to the first primitive. */\nexport const parseRoute = (\n hash: string,\n { primitives, groups }: RuntimeDocs\n): StudioRoute => {\n const [mode, page, example] = hash.replace(/^#\\/?/, '').split('/');\n const first = groups[0]?.types[0] ?? primitives[0]?.type ?? '';\n const resolvedMode: StudioMode = mode === 'docs' ? 'docs' : 'dev';\n const doc = primitives.find(({ type }) => type === page);\n const index = Number(example);\n\n if (!doc && resolvedMode === 'docs' && page === GALLERY) {\n const title = example === undefined ? undefined : decodeSegment(example);\n const group = groups.find((candidate) => candidate.title === title);\n return {\n mode: resolvedMode,\n page: GALLERY,\n example: 0,\n ...(group ? { group: group.title } : {}),\n };\n }\n\n return {\n mode: resolvedMode,\n page: doc ? doc.type : first,\n example:\n doc &&\n Number.isInteger(index) &&\n index >= 0 &&\n index < doc.examples.length\n ? index\n : 0,\n };\n};\n\n/**\n * {@link parseRoute} for `#/dev/...` and `#/docs/...`, `#/app/<id>/<path>` for an id in `appIds`, and\n * {@link HOME} for an empty hash, `#/home`, an unknown app, or any other first segment.\n */\nexport const parseLocation = (\n hash: string,\n docs: RuntimeDocs,\n appIds: readonly string[]\n): StudioLocation => {\n const [segment, id, ...rest] = hash.replace(/^#\\/?/, '').split('/');\n if (segment === APP_SEGMENT) {\n return id !== undefined && appIds.includes(id)\n ? { app: id, path: rest.map(decodeSegment).join('/') }\n : HOME;\n }\n if (segment === 'dev' || segment === 'docs') {\n return parseRoute(hash, docs);\n }\n return HOME;\n};\n\nexport const formatRoute = ({\n mode,\n page,\n example,\n group,\n}: StudioRoute): string =>\n page === GALLERY\n ? group === undefined\n ? `#/${mode}/${GALLERY}`\n : `#/${mode}/${GALLERY}/${encodeURIComponent(group)}`\n : `#/${mode}/${page}/${example}`;\n\nexport const formatLocation = (location: StudioLocation): string =>\n isHomeRoute(location)\n ? `#/${HOME_SEGMENT}`\n : isAppRoute(location)\n ? `#/${APP_SEGMENT}/${location.app}/${location.path.split('/').map(encodeURIComponent).join('/')}`\n : formatRoute(location);\n\nexport interface StudioRouter {\n location: StudioLocation;\n /** The current primitive route, or the last one before an app or Home opened. */\n route: StudioRoute;\n /** Moves to a primitive route, merging `next` into {@link StudioRouter.route}. */\n navigate: (next: Partial<StudioRoute>) => void;\n /** `path` is percent-encoded in the hash, segment by segment, and decoded when read back. */\n openApp: (id: string, path?: string) => void;\n /** Opens `#/home`. */\n goHome: () => void;\n}\n\n/** The location in the URL hash, re-checked whenever the primitives or apps change. */\nexport const useStudioRoute = (\n docs: RuntimeDocs,\n appIds: readonly string[]\n): StudioRouter => {\n const appKey = appIds.join('/');\n const ids = useRef(appIds);\n ids.current = appIds;\n\n const [location, setLocation] = useState(() =>\n parseLocation(window.location.hash, docs, appIds)\n );\n const [route, setRoute] = useState(() =>\n isPrimitiveRoute(location) ? location : parseRoute('', docs)\n );\n const current = useRef(route);\n current.current = route;\n const shown = useRef(location);\n shown.current = location;\n\n const show = useCallback((next: StudioLocation) => {\n setLocation(next);\n if (isPrimitiveRoute(next)) {\n setRoute(next);\n }\n }, []);\n\n useEffect(() => {\n const onHashChange = () =>\n show(parseLocation(window.location.hash, docs, ids.current));\n window.addEventListener('hashchange', onHashChange);\n return () => window.removeEventListener('hashchange', onHashChange);\n }, [docs, show]);\n\n const checked = useRef({ docs, appKey });\n useEffect(() => {\n if (checked.current.docs === docs && checked.current.appKey === appKey) {\n return;\n }\n checked.current = { docs, appKey };\n const remembered = parseRoute(formatRoute(current.current), docs);\n if (formatRoute(remembered) !== formatRoute(current.current)) {\n setRoute(remembered);\n }\n const next = parseLocation(window.location.hash, docs, ids.current);\n const hash = formatLocation(next);\n if (hash === formatLocation(shown.current)) {\n return;\n }\n window.history.replaceState(null, '', hash);\n show(next);\n }, [docs, appKey, show]);\n\n const go = useCallback(\n (next: StudioLocation) => {\n const hash = formatLocation(next);\n if (window.location.hash !== hash) {\n window.history.pushState(null, '', hash);\n }\n show(next);\n },\n [show]\n );\n\n const navigate = useCallback(\n (next: Partial<StudioRoute>) => {\n const { mode, page, example } = current.current;\n const merged = { mode, page, example, ...next };\n go(\n parseRoute(\n formatRoute(\n merged.mode === 'dev' && merged.page === GALLERY\n ? { ...merged, page: '' }\n : merged\n ),\n docs\n )\n );\n },\n [docs, go]\n );\n\n const openApp = useCallback(\n (id: string, path = '') => go({ app: id, path }),\n [go]\n );\n\n const goHome = useCallback(() => go(HOME), [go]);\n\n return { location, route, navigate, openApp, goHome };\n};\n"]}
@@ -0,0 +1,39 @@
1
+ import type { StudioSurface } from '../model/describe_runtime.js';
2
+ import type { ConfigLoader } from '../node/load_config.js';
3
+ import type { ReportFormat } from '../node/report.js';
4
+ export declare const DEFAULT_PORT = 5179;
5
+ interface SharedArgs {
6
+ /** Absolute; `--config` and `--out` resolve against it. */
7
+ cwd: string;
8
+ config?: string | undefined;
9
+ loader: ConfigLoader;
10
+ }
11
+ export type CliArgs = {
12
+ command: 'help';
13
+ } | (SharedArgs & {
14
+ command: 'init';
15
+ }) | (SharedArgs & {
16
+ command: 'dev';
17
+ port: number;
18
+ open: boolean;
19
+ }) | (SharedArgs & {
20
+ command: 'build';
21
+ out: string;
22
+ base: string;
23
+ }) | (SharedArgs & {
24
+ command: 'check';
25
+ report?: string | undefined;
26
+ format: ReportFormat;
27
+ png: boolean;
28
+ surfaces?: StudioSurface[] | undefined;
29
+ });
30
+ export declare const USAGE = "Usage: isomer-studio [command] [options]\n\nCommands:\n dev Serve the Studio with live reload. The default.\n build Write the Studio as a static site.\n check Render every example on every surface, and exit 1 on a failure.\n init Write a config for the packs the project exports: isomer-studio.config.ts\n beside a tsconfig.json, isomer-studio.config.js otherwise.\n\nOptions for every command:\n --cwd <dir> The project; resolves --config, --out and --report. Default: the current directory.\n --loader tsx|none How the config is imported in Node. Default: tsx.\n\ndev, build and check:\n --config <file> Default: isomer-studio.config.{ts,tsx,js} in --cwd.\n\ndev:\n --port <number> Default: 5179.\n --open Open the Studio in a browser.\n\nbuild:\n --out <dir> Default: dist/studio.\n --base <path> The URL path the site is served from. Default: ./\n\ncheck:\n --report <file> Also write the report to a file.\n --format json|junit The report's format. Default: json.\n --png Also rasterize every example.\n --surfaces <list> Comma-separated surfaces to render. Default: every surface the runtime has.\n";
31
+ /** Bad command-line input. Identify it by `name`. */
32
+ export declare class UsageError extends Error {
33
+ readonly name = "UsageError";
34
+ }
35
+ /** A trailing slash, so asset URLs resolve inside the base rather than beside it. */
36
+ export declare const normalizeBase: (base: string) => string;
37
+ export declare const parseCliArgs: (argv: readonly string[], processCwd?: string) => CliArgs;
38
+ export {};
39
+ //# sourceMappingURL=args.d.ts.map
@@ -0,0 +1 @@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AG,MACL,CAAC;AA6BzC,eAAO,MAAM,YAAY,GACvB,MAAM,SAAS,MAAM,EAAE,EACvB,aAAY,MAAsB,KACjC,OAoEF,CAAC"}
@@ -0,0 +1,171 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License
4
+ * 2.0; you may not use this file except in compliance with the Elastic License
5
+ * 2.0.
6
+ */
7
+ import { resolve } from 'node:path';
8
+ import { parseArgs } from 'node:util';
9
+ import { SURFACE_LABELS } from '../model/describe_runtime.js';
10
+ export const DEFAULT_PORT = 5179;
11
+ export const USAGE = `Usage: isomer-studio [command] [options]
12
+
13
+ Commands:
14
+ dev Serve the Studio with live reload. The default.
15
+ build Write the Studio as a static site.
16
+ check Render every example on every surface, and exit 1 on a failure.
17
+ init Write a config for the packs the project exports: isomer-studio.config.ts
18
+ beside a tsconfig.json, isomer-studio.config.js otherwise.
19
+
20
+ Options for every command:
21
+ --cwd <dir> The project; resolves --config, --out and --report. Default: the current directory.
22
+ --loader tsx|none How the config is imported in Node. Default: tsx.
23
+
24
+ dev, build and check:
25
+ --config <file> Default: isomer-studio.config.{ts,tsx,js} in --cwd.
26
+
27
+ dev:
28
+ --port <number> Default: ${DEFAULT_PORT}.
29
+ --open Open the Studio in a browser.
30
+
31
+ build:
32
+ --out <dir> Default: dist/studio.
33
+ --base <path> The URL path the site is served from. Default: ./
34
+
35
+ check:
36
+ --report <file> Also write the report to a file.
37
+ --format json|junit The report's format. Default: json.
38
+ --png Also rasterize every example.
39
+ --surfaces <list> Comma-separated surfaces to render. Default: every surface the runtime has.
40
+ `;
41
+ /** Bad command-line input. Identify it by `name`. */
42
+ export class UsageError extends Error {
43
+ name = 'UsageError';
44
+ }
45
+ const COMMANDS = ['dev', 'build', 'check', 'init'];
46
+ const isCommand = (value) => COMMANDS.some((command) => command === value);
47
+ const isSurface = (value) => Object.hasOwn(SURFACE_LABELS, value);
48
+ const oneOf = (flag, value, allowed, fallback) => {
49
+ if (value === undefined) {
50
+ return fallback;
51
+ }
52
+ const match = allowed.find((candidate) => candidate === value);
53
+ if (match === undefined) {
54
+ throw new UsageError(`--${flag} must be one of ${allowed.join(', ')}; got ${value}.`);
55
+ }
56
+ return match;
57
+ };
58
+ const parsePort = (value) => {
59
+ if (value === undefined) {
60
+ return DEFAULT_PORT;
61
+ }
62
+ const port = Number(value);
63
+ if (!Number.isInteger(port) || port < 0 || port > 65_535) {
64
+ throw new UsageError(`--port must be a port number; got ${value}.`);
65
+ }
66
+ return port;
67
+ };
68
+ const parseSurfaces = (value) => {
69
+ if (value === undefined) {
70
+ return undefined;
71
+ }
72
+ const names = value
73
+ .split(',')
74
+ .map((name) => name.trim())
75
+ .filter(Boolean);
76
+ const unknown = names.filter((name) => !isSurface(name));
77
+ if (unknown.length) {
78
+ throw new UsageError(`--surfaces has unknown surfaces: ${unknown.join(', ')}. Known: ${Object.keys(SURFACE_LABELS).join(', ')}.`);
79
+ }
80
+ return names.filter(isSurface);
81
+ };
82
+ /** A trailing slash, so asset URLs resolve inside the base rather than beside it. */
83
+ export const normalizeBase = (base) => base.endsWith('/') ? base : `${base}/`;
84
+ const OPTIONS = {
85
+ config: { type: 'string' },
86
+ cwd: { type: 'string' },
87
+ loader: { type: 'string' },
88
+ port: { type: 'string' },
89
+ open: { type: 'boolean' },
90
+ out: { type: 'string' },
91
+ base: { type: 'string' },
92
+ report: { type: 'string' },
93
+ format: { type: 'string' },
94
+ png: { type: 'boolean' },
95
+ surfaces: { type: 'string' },
96
+ help: { type: 'boolean', short: 'h' },
97
+ };
98
+ const ONLY = {
99
+ config: ['dev', 'build', 'check'],
100
+ port: ['dev'],
101
+ open: ['dev'],
102
+ out: ['build'],
103
+ base: ['build'],
104
+ report: ['check'],
105
+ format: ['check'],
106
+ png: ['check'],
107
+ surfaces: ['check'],
108
+ };
109
+ export const parseCliArgs = (argv, processCwd = process.cwd()) => {
110
+ let parsed;
111
+ try {
112
+ parsed = parseArgs({
113
+ args: [...argv],
114
+ options: OPTIONS,
115
+ allowPositionals: true,
116
+ });
117
+ }
118
+ catch (error) {
119
+ throw new UsageError(error instanceof Error ? error.message : String(error));
120
+ }
121
+ const { values, positionals } = parsed;
122
+ const [command = 'dev', ...extra] = positionals;
123
+ if (values.help || command === 'help') {
124
+ return { command: 'help' };
125
+ }
126
+ if (!isCommand(command)) {
127
+ throw new UsageError(`Unknown command: ${command}.`);
128
+ }
129
+ if (extra.length) {
130
+ throw new UsageError(`Unexpected arguments: ${extra.join(' ')}.`);
131
+ }
132
+ const misplaced = Object.keys(values).filter((flag) => ONLY[flag] !== undefined && !ONLY[flag].includes(command));
133
+ if (misplaced.length) {
134
+ throw new UsageError(`${misplaced.map((flag) => `--${flag}`).join(', ')} does not apply to ${command}.`);
135
+ }
136
+ const shared = {
137
+ cwd: resolve(processCwd, values.cwd ?? '.'),
138
+ config: values.config,
139
+ loader: oneOf('loader', values.loader, ['tsx', 'none'], 'tsx'),
140
+ };
141
+ switch (command) {
142
+ case 'init':
143
+ return { ...shared, command };
144
+ case 'dev':
145
+ return {
146
+ ...shared,
147
+ command,
148
+ port: parsePort(values.port),
149
+ open: values.open ?? false,
150
+ };
151
+ case 'build':
152
+ return {
153
+ ...shared,
154
+ command,
155
+ out: resolve(shared.cwd, values.out ?? 'dist/studio'),
156
+ base: normalizeBase(values.base ?? './'),
157
+ };
158
+ case 'check':
159
+ return {
160
+ ...shared,
161
+ command,
162
+ report: values.report === undefined
163
+ ? undefined
164
+ : resolve(shared.cwd, values.report),
165
+ format: oneOf('format', values.format, ['json', 'junit'], 'json'),
166
+ png: values.png ?? false,
167
+ surfaces: parseSurfaces(values.surfaces),
168
+ };
169
+ }
170
+ };
171
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources":["../../src/cli/args.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW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AC,QAAQ,CAAC;aACzC,CAAC;IACN,CAAC;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one\n * or more contributor license agreements. Licensed under the Elastic License\n * 2.0; you may not use this file except in compliance with the Elastic License\n * 2.0.\n */\n\nimport { resolve } from 'node:path';\nimport { parseArgs } from 'node:util';\n\nimport type { StudioSurface } from '../model/describe_runtime';\nimport { SURFACE_LABELS } from '../model/describe_runtime';\nimport type { ConfigLoader } from '../node/load_config';\nimport type { ReportFormat } from '../node/report';\n\nexport const DEFAULT_PORT = 5179;\n\ninterface SharedArgs {\n /** Absolute; `--config` and `--out` resolve against it. */\n cwd: string;\n config?: string | undefined;\n loader: ConfigLoader;\n}\n\nexport type CliArgs =\n | { command: 'help' }\n | (SharedArgs & { command: 'init' })\n | (SharedArgs & { command: 'dev'; port: number; open: boolean })\n | (SharedArgs & { command: 'build'; out: string; base: string })\n | (SharedArgs & {\n command: 'check';\n report?: string | undefined;\n format: ReportFormat;\n png: boolean;\n surfaces?: StudioSurface[] | undefined;\n });\n\nexport const USAGE = `Usage: isomer-studio [command] [options]\n\nCommands:\n dev Serve the Studio with live reload. The default.\n build Write the Studio as a static site.\n check Render every example on every surface, and exit 1 on a failure.\n init Write a config for the packs the project exports: isomer-studio.config.ts\n beside a tsconfig.json, isomer-studio.config.js otherwise.\n\nOptions for every command:\n --cwd <dir> The project; resolves --config, --out and --report. Default: the current directory.\n --loader tsx|none How the config is imported in Node. Default: tsx.\n\ndev, build and check:\n --config <file> Default: isomer-studio.config.{ts,tsx,js} in --cwd.\n\ndev:\n --port <number> Default: ${DEFAULT_PORT}.\n --open Open the Studio in a browser.\n\nbuild:\n --out <dir> Default: dist/studio.\n --base <path> The URL path the site is served from. Default: ./\n\ncheck:\n --report <file> Also write the report to a file.\n --format json|junit The report's format. Default: json.\n --png Also rasterize every example.\n --surfaces <list> Comma-separated surfaces to render. Default: every surface the runtime has.\n`;\n\n/** Bad command-line input. Identify it by `name`. */\nexport class UsageError extends Error {\n override readonly name = 'UsageError';\n}\n\nconst COMMANDS = ['dev', 'build', 'check', 'init'] as const;\n\nconst isCommand = (value: string): value is (typeof COMMANDS)[number] =>\n COMMANDS.some((command) => command === value);\n\nconst isSurface = (value: string): value is StudioSurface =>\n Object.hasOwn(SURFACE_LABELS, value);\n\nconst oneOf = <T extends string>(\n flag: string,\n value: string | undefined,\n allowed: readonly T[],\n fallback: T\n): T => {\n if (value === undefined) {\n return fallback;\n }\n const match = allowed.find((candidate) => candidate === value);\n if (match === undefined) {\n throw new UsageError(\n `--${flag} must be one of ${allowed.join(', ')}; got ${value}.`\n );\n }\n return match;\n};\n\nconst parsePort = (value: string | undefined): number => {\n if (value === undefined) {\n return DEFAULT_PORT;\n }\n const port = Number(value);\n if (!Number.isInteger(port) || port < 0 || port > 65_535) {\n throw new UsageError(`--port must be a port number; got ${value}.`);\n }\n return port;\n};\n\nconst parseSurfaces = (\n value: string | undefined\n): StudioSurface[] | undefined => {\n if (value === undefined) {\n return undefined;\n }\n const names = value\n .split(',')\n .map((name) => name.trim())\n .filter(Boolean);\n const unknown = names.filter((name) => !isSurface(name));\n if (unknown.length) {\n throw new UsageError(\n `--surfaces has unknown surfaces: ${unknown.join(', ')}. Known: ${Object.keys(SURFACE_LABELS).join(', ')}.`\n );\n }\n return names.filter(isSurface);\n};\n\n/** A trailing slash, so asset URLs resolve inside the base rather than beside it. */\nexport const normalizeBase = (base: string): string =>\n base.endsWith('/') ? base : `${base}/`;\n\nconst OPTIONS = {\n config: { type: 'string' },\n cwd: { type: 'string' },\n loader: { type: 'string' },\n port: { type: 'string' },\n open: { type: 'boolean' },\n out: { type: 'string' },\n base: { type: 'string' },\n report: { type: 'string' },\n format: { type: 'string' },\n png: { type: 'boolean' },\n surfaces: { type: 'string' },\n help: { type: 'boolean', short: 'h' },\n} as const;\n\nconst ONLY: Readonly<Record<string, readonly string[]>> = {\n config: ['dev', 'build', 'check'],\n port: ['dev'],\n open: ['dev'],\n out: ['build'],\n base: ['build'],\n report: ['check'],\n format: ['check'],\n png: ['check'],\n surfaces: ['check'],\n};\n\nexport const parseCliArgs = (\n argv: readonly string[],\n processCwd: string = process.cwd()\n): CliArgs => {\n let parsed;\n try {\n parsed = parseArgs({\n args: [...argv],\n options: OPTIONS,\n allowPositionals: true,\n });\n } catch (error) {\n throw new UsageError(\n error instanceof Error ? error.message : String(error)\n );\n }\n const { values, positionals } = parsed;\n const [command = 'dev', ...extra] = positionals;\n if (values.help || command === 'help') {\n return { command: 'help' };\n }\n if (!isCommand(command)) {\n throw new UsageError(`Unknown command: ${command}.`);\n }\n if (extra.length) {\n throw new UsageError(`Unexpected arguments: ${extra.join(' ')}.`);\n }\n const misplaced = Object.keys(values).filter(\n (flag) => ONLY[flag] !== undefined && !ONLY[flag].includes(command)\n );\n if (misplaced.length) {\n throw new UsageError(\n `${misplaced.map((flag) => `--${flag}`).join(', ')} does not apply to ${command}.`\n );\n }\n\n const shared: SharedArgs = {\n cwd: resolve(processCwd, values.cwd ?? '.'),\n config: values.config,\n loader: oneOf('loader', values.loader, ['tsx', 'none'], 'tsx'),\n };\n switch (command) {\n case 'init':\n return { ...shared, command };\n case 'dev':\n return {\n ...shared,\n command,\n port: parsePort(values.port),\n open: values.open ?? false,\n };\n case 'build':\n return {\n ...shared,\n command,\n out: resolve(shared.cwd, values.out ?? 'dist/studio'),\n base: normalizeBase(values.base ?? './'),\n };\n case 'check':\n return {\n ...shared,\n command,\n report:\n values.report === undefined\n ? undefined\n : resolve(shared.cwd, values.report),\n format: oneOf('format', values.format, ['json', 'junit'], 'json'),\n png: values.png ?? false,\n surfaces: parseSurfaces(values.surfaces),\n };\n }\n};\n"]}
@@ -0,0 +1,15 @@
1
+ import type { DevServer } from '../node/dev_server.js';
2
+ export interface CliIo {
3
+ cwd: string;
4
+ stdout: (text: string) => void;
5
+ stderr: (text: string) => void;
6
+ /** Called with the running dev server, which keeps the process alive until it closes. */
7
+ onDevServer?: ((server: DevServer) => void) | undefined;
8
+ /** Called with the config before it loads; the binary passes `registerProjectResolution`. */
9
+ onConfig?: ((configPath: string) => void) | undefined;
10
+ }
11
+ /** Opens `url` in the default browser, reporting a missing or failing opener to `onError`. */
12
+ export declare const openBrowser: (url: string, onError: (error: Error) => void, command?: string) => void;
13
+ /** Runs one CLI invocation and resolves its exit code: 0, 1 on a failure, 2 on bad usage. */
14
+ export declare const runCli: (argv: readonly string[], io: CliIo) => Promise<number>;
15
+ //# sourceMappingURL=run.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAepD,MAAM,WAAW,KAAK;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,yFAAyF;IACzF,WAAW,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACxD,6FAA6F;IAC7F,QAAQ,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;CACvD;AAOD,8FAA8F;AAC9F,eAAO,MAAM,WAAW,GACtB,KAAK,MAAM,EACX,SAAS,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,EAC/B,gBAAiD,KAChD,IAIF,CAAC;AAqFF,6FAA6F;AAC7F,eAAO,MAAM,MAAM,GACjB,MAAM,SAAS,MAAM,EAAE,EACvB,IAAI,KAAK,KACR,OAAO,CAAC,MAAM,CAkBhB,CAAC"}