@elastic/isomer-sdk 0.0.0 → 0.2.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 (492) hide show
  1. package/LICENSE.txt +93 -0
  2. package/NOTICE.txt +1861 -0
  3. package/README.md +69 -0
  4. package/THIRD_PARTY_LICENSES.md +957 -0
  5. package/dist/author/authored_fields.d.ts +153 -0
  6. package/dist/author/authored_fields.d.ts.map +1 -0
  7. package/dist/author/authored_fields.js +227 -0
  8. package/dist/author/authored_fields.js.map +1 -0
  9. package/dist/author/authoring_input.d.ts +7 -0
  10. package/dist/author/authoring_input.d.ts.map +1 -0
  11. package/dist/author/authoring_input.js +60 -0
  12. package/dist/author/authoring_input.js.map +1 -0
  13. package/dist/author/authoring_model.d.ts +27 -0
  14. package/dist/author/authoring_model.d.ts.map +1 -0
  15. package/dist/author/authoring_model.js +98 -0
  16. package/dist/author/authoring_model.js.map +1 -0
  17. package/dist/author/declarations.d.ts +13 -0
  18. package/dist/author/declarations.d.ts.map +1 -0
  19. package/dist/author/declarations.js +277 -0
  20. package/dist/author/declarations.js.map +1 -0
  21. package/dist/author/index.d.ts +7 -0
  22. package/dist/author/index.d.ts.map +1 -0
  23. package/dist/author/index.js +12 -0
  24. package/dist/author/index.js.map +1 -0
  25. package/dist/author/jsx.d.ts +21 -0
  26. package/dist/author/jsx.d.ts.map +1 -0
  27. package/dist/author/jsx.js +20 -0
  28. package/dist/author/jsx.js.map +1 -0
  29. package/dist/author/jsx_shim.d.ts +117 -0
  30. package/dist/author/jsx_shim.d.ts.map +1 -0
  31. package/dist/author/jsx_shim.js +270 -0
  32. package/dist/author/jsx_shim.js.map +1 -0
  33. package/dist/author/prompt.d.ts +58 -0
  34. package/dist/author/prompt.d.ts.map +1 -0
  35. package/dist/author/prompt.js +148 -0
  36. package/dist/author/prompt.js.map +1 -0
  37. package/dist/author/schema_to_typescript.d.ts +37 -0
  38. package/dist/author/schema_to_typescript.d.ts.map +1 -0
  39. package/dist/author/schema_to_typescript.js +286 -0
  40. package/dist/author/schema_to_typescript.js.map +1 -0
  41. package/dist/cjs/author/authored_fields.js +233 -0
  42. package/dist/cjs/author/authored_fields.js.map +1 -0
  43. package/dist/cjs/author/authoring_input.js +64 -0
  44. package/dist/cjs/author/authoring_input.js.map +1 -0
  45. package/dist/cjs/author/authoring_model.js +104 -0
  46. package/dist/cjs/author/authoring_model.js.map +1 -0
  47. package/dist/cjs/author/declarations.js +281 -0
  48. package/dist/cjs/author/declarations.js.map +1 -0
  49. package/dist/cjs/author/index.js +25 -0
  50. package/dist/cjs/author/index.js.map +1 -0
  51. package/dist/cjs/author/jsx.js +24 -0
  52. package/dist/cjs/author/jsx.js.map +1 -0
  53. package/dist/cjs/author/jsx_shim.js +276 -0
  54. package/dist/cjs/author/jsx_shim.js.map +1 -0
  55. package/dist/cjs/author/prompt.js +153 -0
  56. package/dist/cjs/author/prompt.js.map +1 -0
  57. package/dist/cjs/author/schema_to_typescript.js +295 -0
  58. package/dist/cjs/author/schema_to_typescript.js.map +1 -0
  59. package/dist/cjs/composition/action_event.js +9 -0
  60. package/dist/cjs/composition/action_event.js.map +1 -0
  61. package/dist/cjs/composition/body_node_base.js +112 -0
  62. package/dist/cjs/composition/body_node_base.js.map +1 -0
  63. package/dist/cjs/composition/composition.js +9 -0
  64. package/dist/cjs/composition/composition.js.map +1 -0
  65. package/dist/cjs/composition/error.js +73 -0
  66. package/dist/cjs/composition/error.js.map +1 -0
  67. package/dist/cjs/composition/index.js +32 -0
  68. package/dist/cjs/composition/index.js.map +1 -0
  69. package/dist/cjs/composition/map_nodes.js +85 -0
  70. package/dist/cjs/composition/map_nodes.js.map +1 -0
  71. package/dist/cjs/composition/named_color.js +20 -0
  72. package/dist/cjs/composition/named_color.js.map +1 -0
  73. package/dist/cjs/composition/node.js +9 -0
  74. package/dist/cjs/composition/node.js.map +1 -0
  75. package/dist/cjs/composition/one_line.js +23 -0
  76. package/dist/cjs/composition/one_line.js.map +1 -0
  77. package/dist/cjs/composition/structured_value.js +21 -0
  78. package/dist/cjs/composition/structured_value.js.map +1 -0
  79. package/dist/cjs/composition/validation_error.js +40 -0
  80. package/dist/cjs/composition/validation_error.js.map +1 -0
  81. package/dist/cjs/define/frame.js +31 -0
  82. package/dist/cjs/define/frame.js.map +1 -0
  83. package/dist/cjs/define/index.js +31 -0
  84. package/dist/cjs/define/index.js.map +1 -0
  85. package/dist/cjs/define/markdown_content.js +12 -0
  86. package/dist/cjs/define/markdown_content.js.map +1 -0
  87. package/dist/cjs/define/primitive_example.js +26 -0
  88. package/dist/cjs/define/primitive_example.js.map +1 -0
  89. package/dist/cjs/define/primitive_icon.js +17 -0
  90. package/dist/cjs/define/primitive_icon.js.map +1 -0
  91. package/dist/cjs/define/primitive_module.js +118 -0
  92. package/dist/cjs/define/primitive_module.js.map +1 -0
  93. package/dist/cjs/define/slack_assets.js +9 -0
  94. package/dist/cjs/define/slack_assets.js.map +1 -0
  95. package/dist/cjs/define/slack_blocks.js +9 -0
  96. package/dist/cjs/define/slack_blocks.js.map +1 -0
  97. package/dist/cjs/define/zod_format.js +122 -0
  98. package/dist/cjs/define/zod_format.js.map +1 -0
  99. package/dist/cjs/define/zod_helpers.js +26 -0
  100. package/dist/cjs/define/zod_helpers.js.map +1 -0
  101. package/dist/cjs/entries/html.js +12 -0
  102. package/dist/cjs/entries/html.js.map +1 -0
  103. package/dist/cjs/entries/index.js +80 -0
  104. package/dist/cjs/entries/index.js.map +1 -0
  105. package/dist/cjs/entries/markdown.js +14 -0
  106. package/dist/cjs/entries/markdown.js.map +1 -0
  107. package/dist/cjs/entries/react.js +20 -0
  108. package/dist/cjs/entries/react.js.map +1 -0
  109. package/dist/cjs/entries/slack.js +25 -0
  110. package/dist/cjs/entries/slack.js.map +1 -0
  111. package/dist/cjs/entries/text.js +12 -0
  112. package/dist/cjs/entries/text.js.map +1 -0
  113. package/dist/cjs/pack/capabilities.js +40 -0
  114. package/dist/cjs/pack/capabilities.js.map +1 -0
  115. package/dist/cjs/pack/compose.js +59 -0
  116. package/dist/cjs/pack/compose.js.map +1 -0
  117. package/dist/cjs/pack/enhancements.js +65 -0
  118. package/dist/cjs/pack/enhancements.js.map +1 -0
  119. package/dist/cjs/pack/index.js +18 -0
  120. package/dist/cjs/pack/index.js.map +1 -0
  121. package/dist/cjs/pack/primitive_pack.js +97 -0
  122. package/dist/cjs/pack/primitive_pack.js.map +1 -0
  123. package/dist/cjs/package.json +3 -0
  124. package/dist/cjs/render/anchors.js +167 -0
  125. package/dist/cjs/render/anchors.js.map +1 -0
  126. package/dist/cjs/render/context_view.js +54 -0
  127. package/dist/cjs/render/context_view.js.map +1 -0
  128. package/dist/cjs/render/format_display_value.js +143 -0
  129. package/dist/cjs/render/format_display_value.js.map +1 -0
  130. package/dist/cjs/render/format_number.js +46 -0
  131. package/dist/cjs/render/format_number.js.map +1 -0
  132. package/dist/cjs/render/html/enhancements.js +30 -0
  133. package/dist/cjs/render/html/enhancements.js.map +1 -0
  134. package/dist/cjs/render/html/envelope.js +218 -0
  135. package/dist/cjs/render/html/envelope.js.map +1 -0
  136. package/dist/cjs/render/html/index.js +12 -0
  137. package/dist/cjs/render/html/index.js.map +1 -0
  138. package/dist/cjs/render/index.js +25 -0
  139. package/dist/cjs/render/index.js.map +1 -0
  140. package/dist/cjs/render/layout_check.js +133 -0
  141. package/dist/cjs/render/layout_check.js.map +1 -0
  142. package/dist/cjs/render/markdown/builder.js +195 -0
  143. package/dist/cjs/render/markdown/builder.js.map +1 -0
  144. package/dist/cjs/render/markdown/envelope.js +33 -0
  145. package/dist/cjs/render/markdown/envelope.js.map +1 -0
  146. package/dist/cjs/render/markdown/format.js +208 -0
  147. package/dist/cjs/render/markdown/format.js.map +1 -0
  148. package/dist/cjs/render/markdown/index.js +15 -0
  149. package/dist/cjs/render/markdown/index.js.map +1 -0
  150. package/dist/cjs/render/measure_dom.js +61 -0
  151. package/dist/cjs/render/measure_dom.js.map +1 -0
  152. package/dist/cjs/render/payload.js +13 -0
  153. package/dist/cjs/render/payload.js.map +1 -0
  154. package/dist/cjs/render/primitive_dispatch.js +173 -0
  155. package/dist/cjs/render/primitive_dispatch.js.map +1 -0
  156. package/dist/cjs/render/react/content.js +44 -0
  157. package/dist/cjs/render/react/content.js.map +1 -0
  158. package/dist/cjs/render/react/enhancements.js +32 -0
  159. package/dist/cjs/render/react/enhancements.js.map +1 -0
  160. package/dist/cjs/render/react/index.js +15 -0
  161. package/dist/cjs/render/react/index.js.map +1 -0
  162. package/dist/cjs/render/slack/assets.js +45 -0
  163. package/dist/cjs/render/slack/assets.js.map +1 -0
  164. package/dist/cjs/render/slack/blocks.js +80 -0
  165. package/dist/cjs/render/slack/blocks.js.map +1 -0
  166. package/dist/cjs/render/slack/envelope.js +551 -0
  167. package/dist/cjs/render/slack/envelope.js.map +1 -0
  168. package/dist/cjs/render/slack/format.js +225 -0
  169. package/dist/cjs/render/slack/format.js.map +1 -0
  170. package/dist/cjs/render/slack/index.js +30 -0
  171. package/dist/cjs/render/slack/index.js.map +1 -0
  172. package/dist/cjs/render/slack/markdown_content.js +409 -0
  173. package/dist/cjs/render/slack/markdown_content.js.map +1 -0
  174. package/dist/cjs/render/text/envelope.js +21 -0
  175. package/dist/cjs/render/text/envelope.js.map +1 -0
  176. package/dist/cjs/render/text/index.js +12 -0
  177. package/dist/cjs/render/text/index.js.map +1 -0
  178. package/dist/cjs/testing/conformance.js +312 -0
  179. package/dist/cjs/testing/conformance.js.map +1 -0
  180. package/dist/cjs/testing/icon.js +248 -0
  181. package/dist/cjs/testing/icon.js.map +1 -0
  182. package/dist/cjs/testing/index.js +18 -0
  183. package/dist/cjs/testing/index.js.map +1 -0
  184. package/dist/cjs/testing/registration.js +142 -0
  185. package/dist/cjs/testing/registration.js.map +1 -0
  186. package/dist/cjs/validate/authoring_schema.js +312 -0
  187. package/dist/cjs/validate/authoring_schema.js.map +1 -0
  188. package/dist/cjs/validate/composition_schema.js +135 -0
  189. package/dist/cjs/validate/composition_schema.js.map +1 -0
  190. package/dist/cjs/validate/index.js +53 -0
  191. package/dist/cjs/validate/index.js.map +1 -0
  192. package/dist/cjs/validate/input_budget.js +156 -0
  193. package/dist/cjs/validate/input_budget.js.map +1 -0
  194. package/dist/cjs/validate/json_schema.js +72 -0
  195. package/dist/cjs/validate/json_schema.js.map +1 -0
  196. package/dist/cjs/validate/node_issues.js +65 -0
  197. package/dist/cjs/validate/node_issues.js.map +1 -0
  198. package/dist/cjs/validate/url.js +116 -0
  199. package/dist/cjs/validate/url.js.map +1 -0
  200. package/dist/cjs/validate/validation.js +165 -0
  201. package/dist/cjs/validate/validation.js.map +1 -0
  202. package/dist/cjs/validate/value_schemas.js +53 -0
  203. package/dist/cjs/validate/value_schemas.js.map +1 -0
  204. package/dist/composition/action_event.d.ts +13 -0
  205. package/dist/composition/action_event.d.ts.map +1 -0
  206. package/dist/composition/action_event.js +8 -0
  207. package/dist/composition/action_event.js.map +1 -0
  208. package/dist/composition/body_node_base.d.ts +72 -0
  209. package/dist/composition/body_node_base.d.ts.map +1 -0
  210. package/dist/composition/body_node_base.js +104 -0
  211. package/dist/composition/body_node_base.js.map +1 -0
  212. package/dist/composition/composition.d.ts +71 -0
  213. package/dist/composition/composition.d.ts.map +1 -0
  214. package/dist/composition/composition.js +8 -0
  215. package/dist/composition/composition.js.map +1 -0
  216. package/dist/composition/error.d.ts +61 -0
  217. package/dist/composition/error.d.ts.map +1 -0
  218. package/dist/composition/error.js +69 -0
  219. package/dist/composition/error.js.map +1 -0
  220. package/dist/composition/index.d.ts +11 -0
  221. package/dist/composition/index.d.ts.map +1 -0
  222. package/dist/composition/index.js +14 -0
  223. package/dist/composition/index.js.map +1 -0
  224. package/dist/composition/map_nodes.d.ts +16 -0
  225. package/dist/composition/map_nodes.d.ts.map +1 -0
  226. package/dist/composition/map_nodes.js +81 -0
  227. package/dist/composition/map_nodes.js.map +1 -0
  228. package/dist/composition/named_color.d.ts +9 -0
  229. package/dist/composition/named_color.d.ts.map +1 -0
  230. package/dist/composition/named_color.js +17 -0
  231. package/dist/composition/named_color.js.map +1 -0
  232. package/dist/composition/node.d.ts +11 -0
  233. package/dist/composition/node.d.ts.map +1 -0
  234. package/dist/composition/node.js +8 -0
  235. package/dist/composition/node.js.map +1 -0
  236. package/dist/composition/one_line.d.ts +7 -0
  237. package/dist/composition/one_line.d.ts.map +1 -0
  238. package/dist/composition/one_line.js +17 -0
  239. package/dist/composition/one_line.js.map +1 -0
  240. package/dist/composition/structured_value.d.ts +27 -0
  241. package/dist/composition/structured_value.d.ts.map +1 -0
  242. package/dist/composition/structured_value.js +18 -0
  243. package/dist/composition/structured_value.js.map +1 -0
  244. package/dist/composition/validation_error.d.ts +33 -0
  245. package/dist/composition/validation_error.d.ts.map +1 -0
  246. package/dist/composition/validation_error.js +35 -0
  247. package/dist/composition/validation_error.js.map +1 -0
  248. package/dist/define/frame.d.ts +155 -0
  249. package/dist/define/frame.d.ts.map +1 -0
  250. package/dist/define/frame.js +27 -0
  251. package/dist/define/frame.js.map +1 -0
  252. package/dist/define/index.d.ts +10 -0
  253. package/dist/define/index.d.ts.map +1 -0
  254. package/dist/define/index.js +13 -0
  255. package/dist/define/index.js.map +1 -0
  256. package/dist/define/markdown_content.d.ts +15 -0
  257. package/dist/define/markdown_content.d.ts.map +1 -0
  258. package/dist/define/markdown_content.js +9 -0
  259. package/dist/define/markdown_content.js.map +1 -0
  260. package/dist/define/primitive_example.d.ts +30 -0
  261. package/dist/define/primitive_example.d.ts.map +1 -0
  262. package/dist/define/primitive_example.js +21 -0
  263. package/dist/define/primitive_example.js.map +1 -0
  264. package/dist/define/primitive_icon.d.ts +11 -0
  265. package/dist/define/primitive_icon.d.ts.map +1 -0
  266. package/dist/define/primitive_icon.js +14 -0
  267. package/dist/define/primitive_icon.js.map +1 -0
  268. package/dist/define/primitive_module.d.ts +435 -0
  269. package/dist/define/primitive_module.d.ts.map +1 -0
  270. package/dist/define/primitive_module.js +112 -0
  271. package/dist/define/primitive_module.js.map +1 -0
  272. package/dist/define/slack_assets.d.ts +28 -0
  273. package/dist/define/slack_assets.d.ts.map +1 -0
  274. package/dist/define/slack_assets.js +8 -0
  275. package/dist/define/slack_assets.js.map +1 -0
  276. package/dist/define/slack_blocks.d.ts +234 -0
  277. package/dist/define/slack_blocks.d.ts.map +1 -0
  278. package/dist/define/slack_blocks.js +8 -0
  279. package/dist/define/slack_blocks.js.map +1 -0
  280. package/dist/define/zod_format.d.ts +33 -0
  281. package/dist/define/zod_format.d.ts.map +1 -0
  282. package/dist/define/zod_format.js +114 -0
  283. package/dist/define/zod_format.js.map +1 -0
  284. package/dist/define/zod_helpers.d.ts +10 -0
  285. package/dist/define/zod_helpers.d.ts.map +1 -0
  286. package/dist/define/zod_helpers.js +22 -0
  287. package/dist/define/zod_helpers.js.map +1 -0
  288. package/dist/entries/html.d.ts +3 -0
  289. package/dist/entries/html.d.ts.map +1 -0
  290. package/dist/entries/html.js +8 -0
  291. package/dist/entries/html.js.map +1 -0
  292. package/dist/entries/index.d.ts +6 -0
  293. package/dist/entries/index.d.ts.map +1 -0
  294. package/dist/entries/index.js +12 -0
  295. package/dist/entries/index.js.map +1 -0
  296. package/dist/entries/markdown.d.ts +3 -0
  297. package/dist/entries/markdown.d.ts.map +1 -0
  298. package/dist/entries/markdown.js +8 -0
  299. package/dist/entries/markdown.js.map +1 -0
  300. package/dist/entries/react.d.ts +5 -0
  301. package/dist/entries/react.d.ts.map +1 -0
  302. package/dist/entries/react.js +11 -0
  303. package/dist/entries/react.js.map +1 -0
  304. package/dist/entries/slack.d.ts +2 -0
  305. package/dist/entries/slack.d.ts.map +1 -0
  306. package/dist/entries/slack.js +8 -0
  307. package/dist/entries/slack.js.map +1 -0
  308. package/dist/entries/text.d.ts +2 -0
  309. package/dist/entries/text.d.ts.map +1 -0
  310. package/dist/entries/text.js +8 -0
  311. package/dist/entries/text.js.map +1 -0
  312. package/dist/pack/capabilities.d.ts +41 -0
  313. package/dist/pack/capabilities.d.ts.map +1 -0
  314. package/dist/pack/capabilities.js +36 -0
  315. package/dist/pack/capabilities.js.map +1 -0
  316. package/dist/pack/compose.d.ts +24 -0
  317. package/dist/pack/compose.d.ts.map +1 -0
  318. package/dist/pack/compose.js +55 -0
  319. package/dist/pack/compose.js.map +1 -0
  320. package/dist/pack/enhancements.d.ts +65 -0
  321. package/dist/pack/enhancements.d.ts.map +1 -0
  322. package/dist/pack/enhancements.js +59 -0
  323. package/dist/pack/enhancements.js.map +1 -0
  324. package/dist/pack/index.d.ts +5 -0
  325. package/dist/pack/index.d.ts.map +1 -0
  326. package/dist/pack/index.js +11 -0
  327. package/dist/pack/index.js.map +1 -0
  328. package/dist/pack/primitive_pack.d.ts +164 -0
  329. package/dist/pack/primitive_pack.d.ts.map +1 -0
  330. package/dist/pack/primitive_pack.js +92 -0
  331. package/dist/pack/primitive_pack.js.map +1 -0
  332. package/dist/render/anchors.d.ts +82 -0
  333. package/dist/render/anchors.d.ts.map +1 -0
  334. package/dist/render/anchors.js +153 -0
  335. package/dist/render/anchors.js.map +1 -0
  336. package/dist/render/context_view.d.ts +10 -0
  337. package/dist/render/context_view.d.ts.map +1 -0
  338. package/dist/render/context_view.js +49 -0
  339. package/dist/render/context_view.js.map +1 -0
  340. package/dist/render/format_display_value.d.ts +20 -0
  341. package/dist/render/format_display_value.d.ts.map +1 -0
  342. package/dist/render/format_display_value.js +137 -0
  343. package/dist/render/format_display_value.js.map +1 -0
  344. package/dist/render/format_number.d.ts +9 -0
  345. package/dist/render/format_number.d.ts.map +1 -0
  346. package/dist/render/format_number.js +42 -0
  347. package/dist/render/format_number.js.map +1 -0
  348. package/dist/render/html/enhancements.d.ts +10 -0
  349. package/dist/render/html/enhancements.d.ts.map +1 -0
  350. package/dist/render/html/enhancements.js +25 -0
  351. package/dist/render/html/enhancements.js.map +1 -0
  352. package/dist/render/html/envelope.d.ts +182 -0
  353. package/dist/render/html/envelope.d.ts.map +1 -0
  354. package/dist/render/html/envelope.js +214 -0
  355. package/dist/render/html/envelope.js.map +1 -0
  356. package/dist/render/html/index.d.ts +3 -0
  357. package/dist/render/html/index.d.ts.map +1 -0
  358. package/dist/render/html/index.js +8 -0
  359. package/dist/render/html/index.js.map +1 -0
  360. package/dist/render/index.d.ts +6 -0
  361. package/dist/render/index.d.ts.map +1 -0
  362. package/dist/render/index.js +11 -0
  363. package/dist/render/index.js.map +1 -0
  364. package/dist/render/layout_check.d.ts +43 -0
  365. package/dist/render/layout_check.d.ts.map +1 -0
  366. package/dist/render/layout_check.js +129 -0
  367. package/dist/render/layout_check.js.map +1 -0
  368. package/dist/render/markdown/builder.d.ts +46 -0
  369. package/dist/render/markdown/builder.d.ts.map +1 -0
  370. package/dist/render/markdown/builder.js +190 -0
  371. package/dist/render/markdown/builder.js.map +1 -0
  372. package/dist/render/markdown/envelope.d.ts +20 -0
  373. package/dist/render/markdown/envelope.d.ts.map +1 -0
  374. package/dist/render/markdown/envelope.js +29 -0
  375. package/dist/render/markdown/envelope.js.map +1 -0
  376. package/dist/render/markdown/format.d.ts +10 -0
  377. package/dist/render/markdown/format.d.ts.map +1 -0
  378. package/dist/render/markdown/format.js +202 -0
  379. package/dist/render/markdown/format.js.map +1 -0
  380. package/dist/render/markdown/index.d.ts +3 -0
  381. package/dist/render/markdown/index.d.ts.map +1 -0
  382. package/dist/render/markdown/index.js +9 -0
  383. package/dist/render/markdown/index.js.map +1 -0
  384. package/dist/render/measure_dom.d.ts +10 -0
  385. package/dist/render/measure_dom.d.ts.map +1 -0
  386. package/dist/render/measure_dom.js +57 -0
  387. package/dist/render/measure_dom.js.map +1 -0
  388. package/dist/render/payload.d.ts +16 -0
  389. package/dist/render/payload.d.ts.map +1 -0
  390. package/dist/render/payload.js +9 -0
  391. package/dist/render/payload.js.map +1 -0
  392. package/dist/render/primitive_dispatch.d.ts +72 -0
  393. package/dist/render/primitive_dispatch.d.ts.map +1 -0
  394. package/dist/render/primitive_dispatch.js +169 -0
  395. package/dist/render/primitive_dispatch.js.map +1 -0
  396. package/dist/render/react/content.d.ts +40 -0
  397. package/dist/render/react/content.d.ts.map +1 -0
  398. package/dist/render/react/content.js +39 -0
  399. package/dist/render/react/content.js.map +1 -0
  400. package/dist/render/react/enhancements.d.ts +15 -0
  401. package/dist/render/react/enhancements.d.ts.map +1 -0
  402. package/dist/render/react/enhancements.js +28 -0
  403. package/dist/render/react/enhancements.js.map +1 -0
  404. package/dist/render/react/index.d.ts +3 -0
  405. package/dist/render/react/index.d.ts.map +1 -0
  406. package/dist/render/react/index.js +9 -0
  407. package/dist/render/react/index.js.map +1 -0
  408. package/dist/render/slack/assets.d.ts +16 -0
  409. package/dist/render/slack/assets.d.ts.map +1 -0
  410. package/dist/render/slack/assets.js +40 -0
  411. package/dist/render/slack/assets.js.map +1 -0
  412. package/dist/render/slack/blocks.d.ts +72 -0
  413. package/dist/render/slack/blocks.d.ts.map +1 -0
  414. package/dist/render/slack/blocks.js +77 -0
  415. package/dist/render/slack/blocks.js.map +1 -0
  416. package/dist/render/slack/envelope.d.ts +52 -0
  417. package/dist/render/slack/envelope.d.ts.map +1 -0
  418. package/dist/render/slack/envelope.js +547 -0
  419. package/dist/render/slack/envelope.js.map +1 -0
  420. package/dist/render/slack/format.d.ts +70 -0
  421. package/dist/render/slack/format.d.ts.map +1 -0
  422. package/dist/render/slack/format.js +209 -0
  423. package/dist/render/slack/format.js.map +1 -0
  424. package/dist/render/slack/index.d.ts +6 -0
  425. package/dist/render/slack/index.d.ts.map +1 -0
  426. package/dist/render/slack/index.js +12 -0
  427. package/dist/render/slack/index.js.map +1 -0
  428. package/dist/render/slack/markdown_content.d.ts +17 -0
  429. package/dist/render/slack/markdown_content.d.ts.map +1 -0
  430. package/dist/render/slack/markdown_content.js +404 -0
  431. package/dist/render/slack/markdown_content.js.map +1 -0
  432. package/dist/render/text/envelope.d.ts +15 -0
  433. package/dist/render/text/envelope.d.ts.map +1 -0
  434. package/dist/render/text/envelope.js +17 -0
  435. package/dist/render/text/envelope.js.map +1 -0
  436. package/dist/render/text/index.d.ts +2 -0
  437. package/dist/render/text/index.d.ts.map +1 -0
  438. package/dist/render/text/index.js +8 -0
  439. package/dist/render/text/index.js.map +1 -0
  440. package/dist/testing/conformance.d.ts +145 -0
  441. package/dist/testing/conformance.d.ts.map +1 -0
  442. package/dist/testing/conformance.js +303 -0
  443. package/dist/testing/conformance.js.map +1 -0
  444. package/dist/testing/icon.d.ts +11 -0
  445. package/dist/testing/icon.d.ts.map +1 -0
  446. package/dist/testing/icon.js +244 -0
  447. package/dist/testing/icon.js.map +1 -0
  448. package/dist/testing/index.d.ts +4 -0
  449. package/dist/testing/index.d.ts.map +1 -0
  450. package/dist/testing/index.js +10 -0
  451. package/dist/testing/index.js.map +1 -0
  452. package/dist/testing/registration.d.ts +32 -0
  453. package/dist/testing/registration.d.ts.map +1 -0
  454. package/dist/testing/registration.js +105 -0
  455. package/dist/testing/registration.js.map +1 -0
  456. package/dist/validate/authoring_schema.d.ts +33 -0
  457. package/dist/validate/authoring_schema.d.ts.map +1 -0
  458. package/dist/validate/authoring_schema.js +306 -0
  459. package/dist/validate/authoring_schema.js.map +1 -0
  460. package/dist/validate/composition_schema.d.ts +80 -0
  461. package/dist/validate/composition_schema.d.ts.map +1 -0
  462. package/dist/validate/composition_schema.js +127 -0
  463. package/dist/validate/composition_schema.js.map +1 -0
  464. package/dist/validate/index.d.ts +9 -0
  465. package/dist/validate/index.d.ts.map +1 -0
  466. package/dist/validate/index.js +15 -0
  467. package/dist/validate/index.js.map +1 -0
  468. package/dist/validate/input_budget.d.ts +35 -0
  469. package/dist/validate/input_budget.d.ts.map +1 -0
  470. package/dist/validate/input_budget.js +151 -0
  471. package/dist/validate/input_budget.js.map +1 -0
  472. package/dist/validate/json_schema.d.ts +32 -0
  473. package/dist/validate/json_schema.d.ts.map +1 -0
  474. package/dist/validate/json_schema.js +68 -0
  475. package/dist/validate/json_schema.js.map +1 -0
  476. package/dist/validate/node_issues.d.ts +12 -0
  477. package/dist/validate/node_issues.d.ts.map +1 -0
  478. package/dist/validate/node_issues.js +61 -0
  479. package/dist/validate/node_issues.js.map +1 -0
  480. package/dist/validate/url.d.ts +50 -0
  481. package/dist/validate/url.d.ts.map +1 -0
  482. package/dist/validate/url.js +107 -0
  483. package/dist/validate/url.js.map +1 -0
  484. package/dist/validate/validation.d.ts +95 -0
  485. package/dist/validate/validation.d.ts.map +1 -0
  486. package/dist/validate/validation.js +157 -0
  487. package/dist/validate/validation.js.map +1 -0
  488. package/dist/validate/value_schemas.d.ts +53 -0
  489. package/dist/validate/value_schemas.d.ts.map +1 -0
  490. package/dist/validate/value_schemas.js +50 -0
  491. package/dist/validate/value_schemas.js.map +1 -0
  492. package/package.json +119 -5
@@ -0,0 +1,92 @@
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
+ // A primitive pack as a value: a vocabulary, and the optional surfaces every
8
+ // primitive in it implements. Additive: a runtime composes any number of packs,
9
+ // and nothing about a pack decides how a composition is framed.
10
+ import { IsomerError } from '../composition/error.js';
11
+ /**
12
+ * Builds a {@link PrimitivePack}.
13
+ *
14
+ * `TTheme` is the palette a frame must supply for this pack's nodes to be drawn
15
+ * on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is
16
+ * `unknown`, which requires nothing.
17
+ */
18
+ export const definePrimitivePack = (input) => {
19
+ if (input.primitives.length === 0) {
20
+ throw new IsomerError('EMPTY_PACK', `primitive pack "${input.id}": at least one primitive is required`);
21
+ }
22
+ assertUniquePrimitiveTypes(input.id, input.primitives);
23
+ assertUniqueEnhancementIds(input.id, input.enhancements ?? []);
24
+ const types = new Set(input.primitives.map((definition) => definition.type));
25
+ assertGroupedOnce(input.id, input.authoring?.groups ?? [], types);
26
+ for (const type of input.slackAssetTypes ?? []) {
27
+ if (!types.has(type)) {
28
+ throw new IsomerError('UNKNOWN_PRIMITIVE_TYPE', `primitive pack "${input.id}": slackAssetTypes names primitive type "${type}", which the pack does not register`);
29
+ }
30
+ }
31
+ const styleCollector = input.styleCollector ?? input.styleAdapter?.styleCollector;
32
+ return {
33
+ id: input.id,
34
+ surfaces: input.surfaces ?? [],
35
+ primitives: input.primitives,
36
+ types,
37
+ icons: iconsByType(input.primitives),
38
+ enhancements: input.enhancements ?? [],
39
+ slackAssetTypes: new Set(input.slackAssetTypes ?? []),
40
+ ...(input.styleAdapter !== undefined
41
+ ? { styleAdapter: input.styleAdapter }
42
+ : {}),
43
+ ...(styleCollector !== undefined ? { styleCollector } : {}),
44
+ ...(input.authoring !== undefined ? { authoring: input.authoring } : {}),
45
+ };
46
+ };
47
+ /** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */
48
+ export const iconsByType = (primitives) => {
49
+ const icons = Object.create(null);
50
+ for (const { type, icon } of primitives) {
51
+ if (icon !== undefined) {
52
+ icons[type] = icon;
53
+ }
54
+ }
55
+ return Object.freeze(icons);
56
+ };
57
+ /** Throws if `primitives` repeats a type. */
58
+ const assertUniquePrimitiveTypes = (id, primitives) => {
59
+ const seen = new Set();
60
+ for (const { type } of primitives) {
61
+ if (seen.has(type)) {
62
+ throw new IsomerError('DUPLICATE_PRIMITIVE_TYPE', `primitive pack "${id}": primitive type "${type}" registered twice`);
63
+ }
64
+ seen.add(type);
65
+ }
66
+ };
67
+ /** Throws if a group names a type outside `types`, or two groups share a type. */
68
+ const assertGroupedOnce = (id, groups, types) => {
69
+ const grouped = new Set();
70
+ for (const { title, types: members } of groups) {
71
+ for (const type of members) {
72
+ if (!types.has(type)) {
73
+ throw new IsomerError('UNKNOWN_PRIMITIVE_TYPE', `primitive pack "${id}": group "${title}" names primitive type "${type}", which the pack does not register`);
74
+ }
75
+ if (grouped.has(type)) {
76
+ throw new IsomerError('DUPLICATE_PRIMITIVE_TYPE', `primitive pack "${id}": primitive type "${type}" is in two groups`);
77
+ }
78
+ grouped.add(type);
79
+ }
80
+ }
81
+ };
82
+ /** Throws if this pack registers the same enhancement id twice. */
83
+ const assertUniqueEnhancementIds = (id, enhancements) => {
84
+ const seen = new Set();
85
+ for (const definition of enhancements) {
86
+ if (seen.has(definition.id)) {
87
+ throw new IsomerError('DUPLICATE_ENHANCEMENT', `primitive pack "${id}": enhancement "${definition.id}" registered twice`);
88
+ }
89
+ seen.add(definition.id);
90
+ }
91
+ };
92
+ //# sourceMappingURL=primitive_pack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitive_pack.js","sourceRoot":"","sources":["../../src/pack/primitive_pack.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,6EAA6E;AAC7E,gFAAgF;AAChF,gEAAgE;AAEhE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAsKnD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,KAAyB,EACF,EAAE;IACzB,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,WAAW,CACnB,YAAY,EACZ,mBAAmB,KAAK,CAAC,EAAE,uCAAuC,CACnE,CAAC;IACJ,CAAC;IACD,0BAA0B,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;IACvD,0BAA0B,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAC7E,iBAAiB,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,CAAC,SAAS,EAAE,MAAM,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;IAClE,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,eAAe,IAAI,EAAE,EAAE,CA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,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF,mEAAmE;AACnE,MAAM,0BAA0B,GAAG,CACjC,EAAU,EACV,YAA8C,EACxC,EAAE;IACR,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,UAAU,IAAI,YAAY,EAAE,CAAC;QACtC,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE,CAAC;YAC5B,MAAM,IAAI,WAAW,CACnB,uBAAuB,EACvB,mBAAmB,EAAE,mBAAmB,UAAU,CAAC,EAAE,oBAAoB,CAC1E,CAAC;QACJ,CAAC;QACD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1B,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\n// A primitive pack as a value: a vocabulary, and the optional surfaces every\n// primitive in it implements. Additive: a runtime composes any number of packs,\n// and nothing about a pack decides how a composition is framed.\n\nimport { IsomerError } from '../composition/error';\nimport type { PrimitiveIcon } from '../define/primitive_icon';\nimport type {\n AnyPrimitiveDefinition,\n OptionalSurface,\n StyleHandle,\n} from '../define/primitive_module';\n\nimport type { EnhancementDefinition } from './enhancements';\n\n/**\n * The authoring-schema material a pack contributes for its own primitives.\n *\n * A subset of `AuthoringJsonSchemaOptions`: `$id`, `title`, `description`, and\n * `composition` describe the whole authoring schema a runtime builds, which is\n * a host decision, not a pack one. `pack/` does not import `validate/` for\n * this, so the shape is declared here rather than reused by reference.\n */\nexport interface PackAuthoringOptions {\n /** `$def` id to `description`, for this pack's own primitives. */\n describe?: Readonly<Record<string, string>>;\n /** `$defId.property` paths to drop, from this pack's own primitives. */\n omitProperties?: readonly string[];\n /** Headings an index catalog sorts this pack's primitives under, in order. */\n groups?: readonly PrimitiveGroup[];\n}\n\n/** A titled set of primitive types, listed together in an index catalog. */\nexport interface PrimitiveGroup {\n title: string;\n types: readonly string[];\n}\n\n/**\n * The HTML style-adapter hooks a pack may declare. Typed loosely here so `pack/` does not import `render/`.\n */\nexport type PackStyleAdapter = {\n /** See {@link PrimitivePackInput.styleCollector}. */\n styleCollector?: string;\n /** The hooks of `HTMLStyleAdapter` from `./html`, erased: a fresh collector per render, the context renderers receive, and the stylesheet the collector produced. */\n createCollector: (...args: never[]) => object;\n createRenderContext: (...args: never[]) => unknown;\n renderStyles: (...args: never[]) => string;\n /**\n * Whether `handle` belongs to this adapter's stylesheet. Required for a runtime to combine several packs' CSS: without it their handles cannot be routed and the host must pick one adapter.\n */\n ownsHandle?: (handle: StyleHandle) => boolean;\n};\n\n/** What a pack author passes to {@link definePrimitivePack}. */\nexport interface PrimitivePackInput {\n /** Stable identifier, used in capability reports and error messages. */\n id: string;\n /**\n * The optional surfaces this pack's primitives implement.\n *\n * Only `slack`, and it stays optional per primitive: the dispatcher converts\n * the mandatory markdown to Block Kit, so declaring it reports an intent\n * rather than imposing a requirement. Omit it entirely for a pack that\n * renders Slack through that fallback.\n */\n surfaces?: readonly OptionalSurface[];\n /** This pack's vocabulary. Node types must be unique within it, or construction throws. */\n primitives: readonly AnyPrimitiveDefinition[];\n /**\n * Progressive enhancements this pack's primitives can apply, by id.\n *\n * Declared by the pack because an enhancement is a fact about its\n * vocabulary — a sortable table, a copyable code block — and a host\n * composing packs it did not write cannot be expected to know the ids.\n * The runtime flattens these across packs; duplicate ids are rejected.\n */\n enhancements?: readonly EnhancementDefinition[];\n /**\n * Types that render as a self-contained picture rather than as text.\n *\n * A channel that cannot draw them inline uploads an image instead: the Slack\n * dispatcher swaps such a node for an `image` block and an upload request, so\n * a chart arrives as a PNG rather than as a markdown approximation of one.\n *\n * Declared by the pack because it is a fact about the vocabulary, and a host\n * composing packs it did not write cannot be expected to know it.\n */\n slackAssetTypes?: readonly string[];\n /**\n * Default HTML style adapter for this pack. A runtime that omits\n * `styleAdapter` runs the packs' own adapters, combined when more than one\n * pack declares one and each answers `ownsHandle`. Pass `styleAdapter` on\n * the runtime to replace them all.\n */\n styleAdapter?: PackStyleAdapter;\n /**\n * Names the collector shape this pack's `collectStyles` hooks mutate, so a\n * runtime can reject a pack paired with an adapter of a different tag.\n * Defaults to `styleAdapter.styleCollector`; a pack with neither opts out of\n * the check.\n */\n styleCollector?: string;\n /**\n * This pack's own contribution to the runtime's authoring JSON Schema.\n *\n * Merged across every composed pack, so a host does not hand-merge each\n * pack's `describe`/`omitProperties` into one options object itself. The\n * runtime-level `authoring` option is merged in last and wins on conflict.\n */\n authoring?: PackAuthoringOptions;\n}\n\n/**\n * A pack as the runtime sees it.\n *\n * `TTheme` is the palette this pack's `react` renderers read as `env.theme`\n * when drawn through the `snapshot` surface — a *lower bound* on whatever theme\n * the runtime holding it supplies. It is carried by\n * {@link PrimitivePack.__theme} rather than by any real field, because\n * `primitives` is erased to `AnyPrimitiveDefinition[]` and a heterogeneous\n * inventory has no single node type to be generic over.\n *\n * The bound is declared, not derived: nothing checks it against what the\n * renderers actually read. State it at the definition as\n * `definePrimitivePack<T>(input)`.\n * Bare `PrimitivePack` requires nothing and fits any runtime; a slot that must\n * hold packs of every palette is typed {@link AnyPrimitivePack}.\n */\nexport interface PrimitivePack<TTheme = unknown> {\n /** Unique among the packs a runtime composes, and used in error messages. */\n readonly id: string;\n /** See {@link PrimitivePackInput.surfaces}. */\n readonly surfaces: readonly OptionalSurface[];\n /** See {@link PrimitivePackInput.primitives}. */\n readonly primitives: readonly AnyPrimitiveDefinition[];\n /** Node types this pack owns, for duplicate detection across packs. */\n readonly types: ReadonlySet<string>;\n /**\n * Each primitive's `icon` by type, for the primitives that declare one, so a host listing them need not walk `primitives`.\n *\n * A frozen null-prototype dictionary: an absent type reads `undefined`, even `constructor`. Absent on a pack built by an SDK that predates icons; {@link iconsByType} derives it from `primitives`.\n */\n readonly icons?: Readonly<Record<string, PrimitiveIcon>>;\n /** See {@link PrimitivePackInput.enhancements}. */\n readonly enhancements: readonly EnhancementDefinition[];\n /** See {@link PrimitivePackInput.slackAssetTypes}. */\n readonly slackAssetTypes: ReadonlySet<string>;\n /** See {@link PrimitivePackInput.styleAdapter}. */\n readonly styleAdapter?: PackStyleAdapter;\n /** See {@link PrimitivePackInput.styleCollector}. */\n readonly styleCollector?: string;\n /** See {@link PrimitivePackInput.authoring}. */\n readonly authoring?: PackAuthoringOptions;\n /**\n * Phantom: never present at runtime, never read.\n *\n * A property rather than a method so `strictFunctionTypes` checks it\n * contravariantly. A method signature is bivariant, which would let a pack\n * needing richer tokens sit in a slot supplying fewer and then read a field\n * nothing supplies — the exact failure this marker exists to prevent.\n */\n readonly __theme?: (theme: TTheme) => void;\n}\n\n/**\n * A pack of any palette, for storage positions: `never` is assignable to every\n * requirement, so a slot typed this way holds every pack.\n */\nexport type AnyPrimitivePack = PrimitivePack<never>;\n\n/**\n * Builds a {@link PrimitivePack}.\n *\n * `TTheme` is the palette a frame must supply for this pack's nodes to be drawn\n * on the `snapshot` surface: `definePrimitivePack<CoreTokens>(input)`. Omitted, it is\n * `unknown`, which requires nothing.\n */\nexport const definePrimitivePack = <TTheme = unknown>(\n input: PrimitivePackInput\n): PrimitivePack<TTheme> => {\n if (input.primitives.length === 0) {\n throw new IsomerError(\n 'EMPTY_PACK',\n `primitive pack \"${input.id}\": at least one primitive is required`\n );\n }\n assertUniquePrimitiveTypes(input.id, input.primitives);\n assertUniqueEnhancementIds(input.id, input.enhancements ?? []);\n const types = new Set(input.primitives.map((definition) => definition.type));\n assertGroupedOnce(input.id, input.authoring?.groups ?? [], types);\n for (const type of input.slackAssetTypes ?? []) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${input.id}\": slackAssetTypes names primitive type \"${type}\", which the pack does not register`\n );\n }\n }\n const styleCollector =\n input.styleCollector ?? input.styleAdapter?.styleCollector;\n\n return {\n id: input.id,\n surfaces: input.surfaces ?? [],\n primitives: input.primitives,\n types,\n icons: iconsByType(input.primitives),\n enhancements: input.enhancements ?? [],\n slackAssetTypes: new Set(input.slackAssetTypes ?? []),\n ...(input.styleAdapter !== undefined\n ? { styleAdapter: input.styleAdapter }\n : {}),\n ...(styleCollector !== undefined ? { styleCollector } : {}),\n ...(input.authoring !== undefined ? { authoring: input.authoring } : {}),\n };\n};\n\n/** Each definition's `icon` by type, null-prototype so a type such as `__proto__` is an ordinary key. */\nexport const iconsByType = (\n primitives: readonly AnyPrimitiveDefinition[]\n): Readonly<Record<string, PrimitiveIcon>> => {\n const icons = Object.create(null) as Record<string, PrimitiveIcon>;\n for (const { type, icon } of primitives) {\n if (icon !== undefined) {\n icons[type] = icon;\n }\n }\n return Object.freeze(icons);\n};\n\n/** Throws if `primitives` repeats a type. */\nconst assertUniquePrimitiveTypes = (\n id: string,\n primitives: readonly AnyPrimitiveDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const { type } of primitives) {\n if (seen.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" registered twice`\n );\n }\n seen.add(type);\n }\n};\n\n/** Throws if a group names a type outside `types`, or two groups share a type. */\nconst assertGroupedOnce = (\n id: string,\n groups: readonly PrimitiveGroup[],\n types: ReadonlySet<string>\n): void => {\n const grouped = new Set<string>();\n for (const { title, types: members } of groups) {\n for (const type of members) {\n if (!types.has(type)) {\n throw new IsomerError(\n 'UNKNOWN_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": group \"${title}\" names primitive type \"${type}\", which the pack does not register`\n );\n }\n if (grouped.has(type)) {\n throw new IsomerError(\n 'DUPLICATE_PRIMITIVE_TYPE',\n `primitive pack \"${id}\": primitive type \"${type}\" is in two groups`\n );\n }\n grouped.add(type);\n }\n }\n};\n\n/** Throws if this pack registers the same enhancement id twice. */\nconst assertUniqueEnhancementIds = (\n id: string,\n enhancements: readonly EnhancementDefinition[]\n): void => {\n const seen = new Set<string>();\n for (const definition of enhancements) {\n if (seen.has(definition.id)) {\n throw new IsomerError(\n 'DUPLICATE_ENHANCEMENT',\n `primitive pack \"${id}\": enhancement \"${definition.id}\" registered twice`\n );\n }\n seen.add(definition.id);\n }\n};\n"]}
@@ -0,0 +1,82 @@
1
+ import { type ChildNodeWalker } from '../composition/body_node_base.js';
2
+ /** The attribute {@link nodeAnchor} sets to a node's type, escaped so HTML parsing leaves it unchanged. */
3
+ export declare const NODE_ANCHOR_ATTRIBUTE = "data-isomer-node";
4
+ /**
5
+ * A node type as its anchor carries it. Every character outside `[A-Za-z0-9_-]`
6
+ * becomes `%<hex code point>;`, so the value survives HTML serialization and
7
+ * parsing unchanged and never throws. A plain identifier stays as it is.
8
+ */
9
+ export declare const anchorValue: (type: string) => string;
10
+ /**
11
+ * Runs `render` with anchors on or off for every {@link nodeAnchor} it reaches,
12
+ * whatever each render context says. The render must be synchronous; the
13
+ * previous state comes back afterwards, even if it throws.
14
+ */
15
+ export declare const withAnchors: <TResult>(on: boolean, render: () => TResult) => TResult;
16
+ /**
17
+ * `context` for content a renderer draws that is not one of its `children`,
18
+ * such as an embedded composition: nothing under it renders an anchor.
19
+ *
20
+ * The result is a view of `context`, not a copy: reads go to `context` itself,
21
+ * with methods bound to it, so getters, methods, private state, and
22
+ * `instanceof` behave as before. The mark survives a context derived from it
23
+ * by spreading. A context that is neither an object nor a function is
24
+ * returned as it is.
25
+ */
26
+ export declare const withoutAnchors: <TContext>(context: TContext) => TContext;
27
+ /**
28
+ * `context` with node anchors on, as an enhancement declaring `anchors: true`
29
+ * turns them on. A view like {@link withoutAnchors}, which still wins.
30
+ */
31
+ export declare const withNodeAnchors: <TContext>(context: TContext) => TContext;
32
+ /**
33
+ * Props a `react` renderer spreads on its root element so runtime code can find
34
+ * the node with {@link findNodeElementPairs}. Inside an HTML surface render the
35
+ * surface decides; elsewhere, on the React and `snapshot` surfaces, `context.anchors`
36
+ * does. Always empty under {@link withoutAnchors}.
37
+ */
38
+ export declare const nodeAnchor: (context: unknown, { type }: {
39
+ type: string;
40
+ }) => Readonly<Record<string, string>>;
41
+ /** The attribute {@link layoutRoom} sets. */
42
+ export declare const LAYOUT_ROOM_ATTRIBUTE = "data-isomer-room";
43
+ /**
44
+ * Props a renderer spreads on an element inside its node that bounds the nodes
45
+ * nested in it, such as a frame's body, so `checkLayout` measures them against
46
+ * it. Rendered when {@link nodeAnchor} would be.
47
+ */
48
+ export declare const layoutRoom: (context: unknown) => Readonly<Record<string, string>>;
49
+ /**
50
+ * The nodes of `body` a render on `surface` draws, pre-order, each with its
51
+ * path in validation's `body[0].items[1]` form. Nested nodes follow `react`,
52
+ * as a container renders them through `renderReact` on either surface.
53
+ */
54
+ export declare const anchoredNodePaths: (body: readonly unknown[], walk: ChildNodeWalker, surface?: "react" | "snapshot") => {
55
+ node: unknown;
56
+ path: string;
57
+ }[];
58
+ /** The `react`-visible nodes of `body`, pre-order: the order their anchors render in. */
59
+ export declare const anchoredNodes: (body: readonly unknown[], walk: ChildNodeWalker) => unknown[];
60
+ /** A node's `type`, when it has one. */
61
+ export declare const nodeType: (node: unknown) => string | undefined;
62
+ /**
63
+ * The item each of `nodes` pairs with, from `anchored` in document order: the
64
+ * k-th node of a type pairs with the k-th item whose anchor value is that
65
+ * type's. A type whose node and item counts disagree pairs with nothing.
66
+ */
67
+ export declare const pairAnchors: <TItem>(anchored: Iterable<readonly [value: string, item: TItem]>, nodes: readonly unknown[]) => (TItem | undefined)[];
68
+ /**
69
+ * Every `react`-visible node of `body`, walked pre-order, with the element
70
+ * its anchor marks under `root`, paired by {@link pairAnchors}. `root` holds
71
+ * one render.
72
+ *
73
+ * Pairing holds because every renderer draws its `children` in the order its
74
+ * definition's `children` returns them. A node that rendered nothing leaves
75
+ * its type unpaired. A node object that appears twice appears twice here,
76
+ * each time with its own element.
77
+ */
78
+ export declare const findNodeElementPairs: (root: ParentNode, body: readonly unknown[], walk: ChildNodeWalker) => {
79
+ node: unknown;
80
+ element: Element | undefined;
81
+ }[];
82
+ //# sourceMappingURL=anchors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchors.d.ts","sourceRoot":"","sources":["../../src/render/anchors.ts"],"names":[],"mappings":"AAOA,OAAO,EAEL,KAAK,eAAe,EAErB,MAAM,+BAA+B,CAAC;AAIvC,2GAA2G;AAC3G,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,MACmC,CAAC;AAgB/E;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,EACjC,IAAI,OAAO,EACX,QAAQ,MAAM,OAAO,KACpB,OAaF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAAI,QAAQ,EAAE,SAAS,QAAQ,KAAG,QACrB,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,EAAE,SAAS,QAAQ,KAAG,QACvB,CAAC;AAaxC;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GACrB,SAAS,OAAO,EAChB,UAAU;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,KACzB,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CACwC,CAAC;AAE3E,6CAA6C;AAC7C,eAAO,MAAM,qBAAqB,qBAAqB,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,UAAU,GACrB,SAAS,OAAO,KACf,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CACyB,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,SAAS,OAAO,EAAE,EACxB,MAAM,eAAe,EACrB,UAAS,OAAO,GAAG,UAAoB,KACtC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,EAejC,CAAC;AAEF,yFAAyF;AACzF,eAAO,MAAM,aAAa,GACxB,MAAM,SAAS,OAAO,EAAE,EACxB,MAAM,eAAe,KACpB,OAAO,EAA2D,CAAC;AAEtE,wCAAwC;AACxC,eAAO,MAAM,QAAQ,GAAI,MAAM,OAAO,KAAG,MAAM,GAAG,SAGjD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,EAC/B,UAAU,QAAQ,CAAC,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,EACzD,OAAO,SAAS,OAAO,EAAE,KACxB,CAAC,KAAK,GAAG,SAAS,CAAC,EAyBrB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,UAAU,EAChB,MAAM,SAAS,OAAO,EAAE,EACxB,MAAM,eAAe,KACpB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAA;CAAE,EAYjD,CAAC"}
@@ -0,0 +1,153 @@
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 { childNodePath, isVisibleOnSurface, } from '../composition/body_node_base.js';
8
+ import { contextWith, isObjectLike } from './context_view.js';
9
+ /** The attribute {@link nodeAnchor} sets to a node's type, escaped so HTML parsing leaves it unchanged. */
10
+ export const NODE_ANCHOR_ATTRIBUTE = 'data-isomer-node';
11
+ /**
12
+ * A node type as its anchor carries it. Every character outside `[A-Za-z0-9_-]`
13
+ * becomes `%<hex code point>;`, so the value survives HTML serialization and
14
+ * parsing unchanged and never throws. A plain identifier stays as it is.
15
+ */
16
+ export const anchorValue = (type) => type.replace(/[^\w-]/gu, (char) => `%${char.codePointAt(0).toString(16)};`);
17
+ /** Marks a context whose subtree renders no anchors; see {@link withoutAnchors}. */
18
+ const NO_ANCHORS = Symbol.for('elastic.isomer.anchors_off');
19
+ /**
20
+ * Where an HTML render keeps its anchor decision while it runs. On `globalThis`
21
+ * under a `Symbol.for` key, so an ESM and a CommonJS copy of the SDK share it.
22
+ */
23
+ const ACTIVE = Symbol.for('elastic.isomer.anchors_active');
24
+ const activeAnchors = () => globalThis[ACTIVE];
25
+ /**
26
+ * Runs `render` with anchors on or off for every {@link nodeAnchor} it reaches,
27
+ * whatever each render context says. The render must be synchronous; the
28
+ * previous state comes back afterwards, even if it throws.
29
+ */
30
+ export const withAnchors = (on, render) => {
31
+ const scope = globalThis;
32
+ const outer = scope[ACTIVE];
33
+ scope[ACTIVE] = on;
34
+ try {
35
+ return render();
36
+ }
37
+ finally {
38
+ if (outer === undefined) {
39
+ delete scope[ACTIVE];
40
+ }
41
+ else {
42
+ scope[ACTIVE] = outer;
43
+ }
44
+ }
45
+ };
46
+ /**
47
+ * `context` for content a renderer draws that is not one of its `children`,
48
+ * such as an embedded composition: nothing under it renders an anchor.
49
+ *
50
+ * The result is a view of `context`, not a copy: reads go to `context` itself,
51
+ * with methods bound to it, so getters, methods, private state, and
52
+ * `instanceof` behave as before. The mark survives a context derived from it
53
+ * by spreading. A context that is neither an object nor a function is
54
+ * returned as it is.
55
+ */
56
+ export const withoutAnchors = (context) => contextWith(context, NO_ANCHORS, true);
57
+ /**
58
+ * `context` with node anchors on, as an enhancement declaring `anchors: true`
59
+ * turns them on. A view like {@link withoutAnchors}, which still wins.
60
+ */
61
+ export const withNodeAnchors = (context) => contextWith(context, 'anchors', true);
62
+ const anchorsOn = (context) => {
63
+ const carries = isObjectLike(context);
64
+ if (carries && Reflect.get(context, NO_ANCHORS) === true) {
65
+ return false;
66
+ }
67
+ return (activeAnchors() ??
68
+ (carries && context.anchors === true));
69
+ };
70
+ /**
71
+ * Props a `react` renderer spreads on its root element so runtime code can find
72
+ * the node with {@link findNodeElementPairs}. Inside an HTML surface render the
73
+ * surface decides; elsewhere, on the React and `snapshot` surfaces, `context.anchors`
74
+ * does. Always empty under {@link withoutAnchors}.
75
+ */
76
+ export const nodeAnchor = (context, { type }) => anchorsOn(context) ? { [NODE_ANCHOR_ATTRIBUTE]: anchorValue(type) } : {};
77
+ /** The attribute {@link layoutRoom} sets. */
78
+ export const LAYOUT_ROOM_ATTRIBUTE = 'data-isomer-room';
79
+ /**
80
+ * Props a renderer spreads on an element inside its node that bounds the nodes
81
+ * nested in it, such as a frame's body, so `checkLayout` measures them against
82
+ * it. Rendered when {@link nodeAnchor} would be.
83
+ */
84
+ export const layoutRoom = (context) => anchorsOn(context) ? { [LAYOUT_ROOM_ATTRIBUTE]: '' } : {};
85
+ /**
86
+ * The nodes of `body` a render on `surface` draws, pre-order, each with its
87
+ * path in validation's `body[0].items[1]` form. Nested nodes follow `react`,
88
+ * as a container renders them through `renderReact` on either surface.
89
+ */
90
+ export const anchoredNodePaths = (body, walk, surface = 'react') => {
91
+ const visit = (node, path) => [
92
+ { node, path },
93
+ ...walk(node).flatMap((child) => isVisibleOnSurface(child.node, 'react')
94
+ ? visit(child.node, childNodePath(path, child.path))
95
+ : []),
96
+ ];
97
+ return body.flatMap((node, index) => isVisibleOnSurface(node, surface) ? visit(node, `body[${index}]`) : []);
98
+ };
99
+ /** The `react`-visible nodes of `body`, pre-order: the order their anchors render in. */
100
+ export const anchoredNodes = (body, walk) => anchoredNodePaths(body, walk).map(({ node }) => node);
101
+ /** A node's `type`, when it has one. */
102
+ export const nodeType = (node) => {
103
+ const { type } = node;
104
+ return typeof type === 'string' ? type : undefined;
105
+ };
106
+ /**
107
+ * The item each of `nodes` pairs with, from `anchored` in document order: the
108
+ * k-th node of a type pairs with the k-th item whose anchor value is that
109
+ * type's. A type whose node and item counts disagree pairs with nothing.
110
+ */
111
+ export const pairAnchors = (anchored, nodes) => {
112
+ const itemsByValue = new Map();
113
+ for (const [value, item] of anchored) {
114
+ const items = itemsByValue.get(value) ?? [];
115
+ items.push(item);
116
+ itemsByValue.set(value, items);
117
+ }
118
+ const counts = new Map();
119
+ for (const node of nodes) {
120
+ const type = nodeType(node);
121
+ if (type !== undefined) {
122
+ counts.set(type, (counts.get(type) ?? 0) + 1);
123
+ }
124
+ }
125
+ const seen = new Map();
126
+ return nodes.map((node) => {
127
+ const type = nodeType(node);
128
+ if (type === undefined) {
129
+ return undefined;
130
+ }
131
+ const index = seen.get(type) ?? 0;
132
+ seen.set(type, index + 1);
133
+ const items = itemsByValue.get(anchorValue(type)) ?? [];
134
+ return items.length === counts.get(type) ? items[index] : undefined;
135
+ });
136
+ };
137
+ /**
138
+ * Every `react`-visible node of `body`, walked pre-order, with the element
139
+ * its anchor marks under `root`, paired by {@link pairAnchors}. `root` holds
140
+ * one render.
141
+ *
142
+ * Pairing holds because every renderer draws its `children` in the order its
143
+ * definition's `children` returns them. A node that rendered nothing leaves
144
+ * its type unpaired. A node object that appears twice appears twice here,
145
+ * each time with its own element.
146
+ */
147
+ export const findNodeElementPairs = (root, body, walk) => {
148
+ const nodes = anchoredNodes(body, walk);
149
+ // Read by attribute value, so a type is never read as selector syntax.
150
+ const elements = pairAnchors(Array.from(root.querySelectorAll(`[${NODE_ANCHOR_ATTRIBUTE}]`), (element) => [element.getAttribute(NODE_ANCHOR_ATTRIBUTE) ?? '', element]), nodes);
151
+ return nodes.map((node, index) => ({ node, element: elements[index] }));
152
+ };
153
+ //# sourceMappingURL=anchors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchors.js","sourceRoot":"","sources":["../../src/render/anchors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,aAAa,EAEb,kBAAkB,GACnB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE3D,2GAA2G;AAC3G,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAExD;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAA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C,IAAI,CACR,IAAI,CAAC,gBAAgB,CAAC,IAAI,qBAAqB,GAAG,CAAC,EACnD,CAAC,OAAO,EAAE,EAAE,CACV,CAAC,OAAO,CAAC,YAAY,CAAC,qBAAqB,CAAC,IAAI,EAAE,EAAE,OAAO,CAAU,CACxE,EACD,KAAK,CACN,CAAC;IACF,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1E,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 {\n childNodePath,\n type ChildNodeWalker,\n isVisibleOnSurface,\n} from '../composition/body_node_base';\n\nimport { contextWith, isObjectLike } from './context_view';\n\n/** The attribute {@link nodeAnchor} sets to a node's type, escaped so HTML parsing leaves it unchanged. */\nexport const NODE_ANCHOR_ATTRIBUTE = 'data-isomer-node';\n\n/**\n * A node type as its anchor carries it. Every character outside `[A-Za-z0-9_-]`\n * becomes `%<hex code point>;`, so the value survives HTML serialization and\n * parsing unchanged and never throws. A plain identifier stays as it is.\n */\nexport const anchorValue = (type: string): string =>\n type.replace(/[^\\w-]/gu, (char) => `%${char.codePointAt(0)!.toString(16)};`);\n\n/** Marks a context whose subtree renders no anchors; see {@link withoutAnchors}. */\nconst NO_ANCHORS = Symbol.for('elastic.isomer.anchors_off');\n\n/**\n * Where an HTML render keeps its anchor decision while it runs. On `globalThis`\n * under a `Symbol.for` key, so an ESM and a CommonJS copy of the SDK share it.\n */\nconst ACTIVE = Symbol.for('elastic.isomer.anchors_active');\n\ntype AnchorScope = { [ACTIVE]?: boolean };\n\nconst activeAnchors = (): boolean | undefined =>\n (globalThis as AnchorScope)[ACTIVE];\n\n/**\n * Runs `render` with anchors on or off for every {@link nodeAnchor} it reaches,\n * whatever each render context says. The render must be synchronous; the\n * previous state comes back afterwards, even if it throws.\n */\nexport const withAnchors = <TResult>(\n on: boolean,\n render: () => TResult\n): TResult => {\n const scope = globalThis as AnchorScope;\n const outer = scope[ACTIVE];\n scope[ACTIVE] = on;\n try {\n return render();\n } finally {\n if (outer === undefined) {\n delete scope[ACTIVE];\n } else {\n scope[ACTIVE] = outer;\n }\n }\n};\n\n/**\n * `context` for content a renderer draws that is not one of its `children`,\n * such as an embedded composition: nothing under it renders an anchor.\n *\n * The result is a view of `context`, not a copy: reads go to `context` itself,\n * with methods bound to it, so getters, methods, private state, and\n * `instanceof` behave as before. The mark survives a context derived from it\n * by spreading. A context that is neither an object nor a function is\n * returned as it is.\n */\nexport const withoutAnchors = <TContext>(context: TContext): TContext =>\n contextWith(context, NO_ANCHORS, true);\n\n/**\n * `context` with node anchors on, as an enhancement declaring `anchors: true`\n * turns them on. A view like {@link withoutAnchors}, which still wins.\n */\nexport const withNodeAnchors = <TContext>(context: TContext): TContext =>\n contextWith(context, 'anchors', true);\n\nconst anchorsOn = (context: unknown): boolean => {\n const carries = isObjectLike(context);\n if (carries && Reflect.get(context, NO_ANCHORS) === true) {\n return false;\n }\n return (\n activeAnchors() ??\n (carries && (context as { anchors?: unknown }).anchors === true)\n );\n};\n\n/**\n * Props a `react` renderer spreads on its root element so runtime code can find\n * the node with {@link findNodeElementPairs}. Inside an HTML surface render the\n * surface decides; elsewhere, on the React and `snapshot` surfaces, `context.anchors`\n * does. Always empty under {@link withoutAnchors}.\n */\nexport const nodeAnchor = (\n context: unknown,\n { type }: { type: string }\n): Readonly<Record<string, string>> =>\n anchorsOn(context) ? { [NODE_ANCHOR_ATTRIBUTE]: anchorValue(type) } : {};\n\n/** The attribute {@link layoutRoom} sets. */\nexport const LAYOUT_ROOM_ATTRIBUTE = 'data-isomer-room';\n\n/**\n * Props a renderer spreads on an element inside its node that bounds the nodes\n * nested in it, such as a frame's body, so `checkLayout` measures them against\n * it. Rendered when {@link nodeAnchor} would be.\n */\nexport const layoutRoom = (\n context: unknown\n): Readonly<Record<string, string>> =>\n anchorsOn(context) ? { [LAYOUT_ROOM_ATTRIBUTE]: '' } : {};\n\n/**\n * The nodes of `body` a render on `surface` draws, pre-order, each with its\n * path in validation's `body[0].items[1]` form. Nested nodes follow `react`,\n * as a container renders them through `renderReact` on either surface.\n */\nexport const anchoredNodePaths = (\n body: readonly unknown[],\n walk: ChildNodeWalker,\n surface: 'react' | 'snapshot' = 'react'\n): { node: unknown; path: string }[] => {\n const visit = (\n node: unknown,\n path: string\n ): { node: unknown; path: string }[] => [\n { node, path },\n ...walk(node).flatMap((child) =>\n isVisibleOnSurface(child.node, 'react')\n ? visit(child.node, childNodePath(path, child.path))\n : []\n ),\n ];\n return body.flatMap((node, index) =>\n isVisibleOnSurface(node, surface) ? visit(node, `body[${index}]`) : []\n );\n};\n\n/** The `react`-visible nodes of `body`, pre-order: the order their anchors render in. */\nexport const anchoredNodes = (\n body: readonly unknown[],\n walk: ChildNodeWalker\n): unknown[] => anchoredNodePaths(body, walk).map(({ node }) => node);\n\n/** A node's `type`, when it has one. */\nexport const nodeType = (node: unknown): string | undefined => {\n const { type } = node as { type?: unknown };\n return typeof type === 'string' ? type : undefined;\n};\n\n/**\n * The item each of `nodes` pairs with, from `anchored` in document order: the\n * k-th node of a type pairs with the k-th item whose anchor value is that\n * type's. A type whose node and item counts disagree pairs with nothing.\n */\nexport const pairAnchors = <TItem>(\n anchored: Iterable<readonly [value: string, item: TItem]>,\n nodes: readonly unknown[]\n): (TItem | undefined)[] => {\n const itemsByValue = new Map<string, TItem[]>();\n for (const [value, item] of anchored) {\n const items = itemsByValue.get(value) ?? [];\n items.push(item);\n itemsByValue.set(value, items);\n }\n const counts = new Map<string, number>();\n for (const node of nodes) {\n const type = nodeType(node);\n if (type !== undefined) {\n counts.set(type, (counts.get(type) ?? 0) + 1);\n }\n }\n const seen = new Map<string, number>();\n return nodes.map((node) => {\n const type = nodeType(node);\n if (type === undefined) {\n return undefined;\n }\n const index = seen.get(type) ?? 0;\n seen.set(type, index + 1);\n const items = itemsByValue.get(anchorValue(type)) ?? [];\n return items.length === counts.get(type) ? items[index] : undefined;\n });\n};\n\n/**\n * Every `react`-visible node of `body`, walked pre-order, with the element\n * its anchor marks under `root`, paired by {@link pairAnchors}. `root` holds\n * one render.\n *\n * Pairing holds because every renderer draws its `children` in the order its\n * definition's `children` returns them. A node that rendered nothing leaves\n * its type unpaired. A node object that appears twice appears twice here,\n * each time with its own element.\n */\nexport const findNodeElementPairs = (\n root: ParentNode,\n body: readonly unknown[],\n walk: ChildNodeWalker\n): { node: unknown; element: Element | undefined }[] => {\n const nodes = anchoredNodes(body, walk);\n // Read by attribute value, so a type is never read as selector syntax.\n const elements = pairAnchors(\n Array.from(\n root.querySelectorAll(`[${NODE_ANCHOR_ATTRIBUTE}]`),\n (element) =>\n [element.getAttribute(NODE_ANCHOR_ATTRIBUTE) ?? '', element] as const\n ),\n nodes\n );\n return nodes.map((node, index) => ({ node, element: elements[index] }));\n};\n"]}
@@ -0,0 +1,10 @@
1
+ /** Whether `value` can carry properties: a non-null object or a function. */
2
+ export declare const isObjectLike: (value: unknown) => value is object;
3
+ /**
4
+ * A view of `context` that reads `key` as `value` and everything else from
5
+ * `context`, with methods bound to it, so getters, private state, and
6
+ * `instanceof` behave as before, and a callable context stays callable. A
7
+ * context that is neither an object nor a function is returned as it is.
8
+ */
9
+ export declare const contextWith: <TContext>(context: TContext, key: string | symbol, value: unknown) => TContext;
10
+ //# sourceMappingURL=context_view.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context_view.d.ts","sourceRoot":"","sources":["../../src/render/context_view.ts"],"names":[],"mappings":"AAOA,6EAA6E;AAC7E,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MACuB,CAAC;AAE/E;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,QAAQ,EAClC,SAAS,QAAQ,EACjB,KAAK,MAAM,GAAG,MAAM,EACpB,OAAO,OAAO,KACb,QAoCF,CAAC"}
@@ -0,0 +1,49 @@
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
+ /** Whether `value` can carry properties: a non-null object or a function. */
8
+ export const isObjectLike = (value) => (typeof value === 'object' && value !== null) || typeof value === 'function';
9
+ /**
10
+ * A view of `context` that reads `key` as `value` and everything else from
11
+ * `context`, with methods bound to it, so getters, private state, and
12
+ * `instanceof` behave as before, and a callable context stays callable. A
13
+ * context that is neither an object nor a function is returned as it is.
14
+ */
15
+ export const contextWith = (context, key, value) => {
16
+ if (!isObjectLike(context)) {
17
+ return context;
18
+ }
19
+ const original = context;
20
+ // An extensible stand-in, so a frozen context cannot trip the proxy invariants. An arrow function has no non-configurable own keys.
21
+ const prototype = Object.getPrototypeOf(original);
22
+ const standIn = (typeof original === 'function'
23
+ ? Object.setPrototypeOf(() => undefined, prototype)
24
+ : Object.create(prototype));
25
+ return new Proxy(standIn, {
26
+ apply: (_, self, args) => Reflect.apply(original, self, args),
27
+ get: (_, read) => {
28
+ if (read === key) {
29
+ return value;
30
+ }
31
+ const found = Reflect.get(original, read, original);
32
+ return typeof found === 'function'
33
+ ? found.bind(original)
34
+ : found;
35
+ },
36
+ set: (_, write, next) => Reflect.set(original, write, next, original),
37
+ has: (_, read) => read === key || Reflect.has(original, read),
38
+ ownKeys: () => [...new Set([...Reflect.ownKeys(original), key])],
39
+ getOwnPropertyDescriptor: (_, read) => {
40
+ if (read === key) {
41
+ return { value, enumerable: true, configurable: true, writable: true };
42
+ }
43
+ const descriptor = Reflect.getOwnPropertyDescriptor(original, read);
44
+ return descriptor && { ...descriptor, configurable: true };
45
+ },
46
+ getPrototypeOf: () => Object.getPrototypeOf(original),
47
+ });
48
+ };
49
+ //# sourceMappingURL=context_view.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context_view.js","sourceRoot":"","sources":["../../src/render/context_view.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAc,EAAmB,EAAE,CAC9D,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,OAAiB,EACjB,GAAoB,EACpB,KAAc,EACJ,EAAE;IACZ,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3B,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC;IACzB,oIAAoI;IACpI,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAkB,CAAC;IACnE,MAAM,OAAO,GAAG,CACd,OAAO,QAAQ,KAAK,UAAU;QAC5B,CAAC,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC;QACnD,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CACnB,CAAC;IACZ,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE;QACxB,KAAK,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAe,EAAE,EAAE,CAClC,OAAO,CAAC,KAAK,CAAC,QAA2C,EAAE,IAAI,EAAE,IAAI,CAAC;QACxE,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;YACf,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;gBACjB,OAAO,KAAK,CAAC;YACf,CAAC;YACD,MAAM,KAAK,GAAY,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;YAC7D,OAAO,OAAO,KAAK,KAAK,UAAU;gBAChC,CAAC,CAAE,KAAyC,CAAC,IAAI,CAAC,QAAQ,CAAC;gBAC3D,CAAC,CAAC,KAAK,CAAC;QACZ,CAAC;QACD,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC;QACrE,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC;QAC7D,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;QAChE,wBAAwB,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE;YACpC,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;gBACjB,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;YACzE,CAAC;YACD,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YACpE,OAAO,UAAU,IAAI,EAAE,GAAG,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;QAC7D,CAAC;QACD,cAAc,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,QAAQ,CAAkB;KACvE,CAAa,CAAC;AACjB,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\n/** Whether `value` can carry properties: a non-null object or a function. */\nexport const isObjectLike = (value: unknown): value is object =>\n (typeof value === 'object' && value !== null) || typeof value === 'function';\n\n/**\n * A view of `context` that reads `key` as `value` and everything else from\n * `context`, with methods bound to it, so getters, private state, and\n * `instanceof` behave as before, and a callable context stays callable. A\n * context that is neither an object nor a function is returned as it is.\n */\nexport const contextWith = <TContext>(\n context: TContext,\n key: string | symbol,\n value: unknown\n): TContext => {\n if (!isObjectLike(context)) {\n return context;\n }\n const original = context;\n // An extensible stand-in, so a frozen context cannot trip the proxy invariants. An arrow function has no non-configurable own keys.\n const prototype = Object.getPrototypeOf(original) as object | null;\n const standIn = (\n typeof original === 'function'\n ? Object.setPrototypeOf(() => undefined, prototype)\n : Object.create(prototype)\n ) as object;\n return new Proxy(standIn, {\n apply: (_, self, args: unknown[]) =>\n Reflect.apply(original as (...rest: unknown[]) => unknown, self, args),\n get: (_, read) => {\n if (read === key) {\n return value;\n }\n const found: unknown = Reflect.get(original, read, original);\n return typeof found === 'function'\n ? (found as (...args: unknown[]) => unknown).bind(original)\n : found;\n },\n set: (_, write, next) => Reflect.set(original, write, next, original),\n has: (_, read) => read === key || Reflect.has(original, read),\n ownKeys: () => [...new Set([...Reflect.ownKeys(original), key])],\n getOwnPropertyDescriptor: (_, read) => {\n if (read === key) {\n return { value, enumerable: true, configurable: true, writable: true };\n }\n const descriptor = Reflect.getOwnPropertyDescriptor(original, read);\n return descriptor && { ...descriptor, configurable: true };\n },\n getPrototypeOf: () => Object.getPrototypeOf(original) as object | null,\n }) as TContext;\n};\n"]}
@@ -0,0 +1,20 @@
1
+ import type { DisplayValue, StructuredValue } from '../composition/structured_value.js';
2
+ /** Options for {@link formatDisplayValue}. */
3
+ export interface FormatDisplayValueOptions {
4
+ /** Reference instant for `relativeTime`; defaults to the render time. */
5
+ now?: Date;
6
+ }
7
+ /** Narrows a {@link DisplayValue} to the object form. */
8
+ export declare const isStructuredValue: (value: DisplayValue) => value is StructuredValue;
9
+ /** The unformatted value behind a {@link DisplayValue}. */
10
+ export declare const rawDisplayValue: (value: DisplayValue) => number | string;
11
+ /**
12
+ * Renders a {@link DisplayValue} for display. A bare string passes through; a
13
+ * {@link StructuredValue} is formatted per its `format`.
14
+ *
15
+ * Numeric formats fall back to `String(raw)` for a string `raw` rather than
16
+ * erroring. Locale is fixed to `en-US` and dates render in UTC so the same
17
+ * composition formats identically on every host.
18
+ */
19
+ export declare const formatDisplayValue: (value: DisplayValue, options?: FormatDisplayValueOptions) => string;
20
+ //# sourceMappingURL=format_display_value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format_display_value.d.ts","sourceRoot":"","sources":["../../src/render/format_display_value.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,YAAY,EACZ,eAAe,EAChB,MAAM,iCAAiC,CAAC;AAIzC,8CAA8C;AAC9C,MAAM,WAAW,yBAAyB;IACxC,yEAAyE;IACzE,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAED,yDAAyD;AACzD,eAAO,MAAM,iBAAiB,GAC5B,OAAO,YAAY,KAClB,KAAK,IAAI,eACmD,CAAC;AAEhE,2DAA2D;AAC3D,eAAO,MAAM,eAAe,GAAI,OAAO,YAAY,KAAG,MAAM,GAAG,MACjB,CAAC;AAE/C;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAC7B,OAAO,YAAY,EACnB,UAAS,yBAA8B,KACtC,MAqCF,CAAC"}
@@ -0,0 +1,137 @@
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 { formatCompactNumber } from './format_number.js';
8
+ /** Narrows a {@link DisplayValue} to the object form. */
9
+ export const isStructuredValue = (value) => typeof value === 'object' && value !== null && 'raw' in value;
10
+ /** The unformatted value behind a {@link DisplayValue}. */
11
+ export const rawDisplayValue = (value) => isStructuredValue(value) ? value.raw : value;
12
+ /**
13
+ * Renders a {@link DisplayValue} for display. A bare string passes through; a
14
+ * {@link StructuredValue} is formatted per its `format`.
15
+ *
16
+ * Numeric formats fall back to `String(raw)` for a string `raw` rather than
17
+ * erroring. Locale is fixed to `en-US` and dates render in UTC so the same
18
+ * composition formats identically on every host.
19
+ */
20
+ export const formatDisplayValue = (value, options = {}) => {
21
+ if (!isStructuredValue(value)) {
22
+ return value;
23
+ }
24
+ const { raw, format, precision, currency } = value;
25
+ switch (format) {
26
+ case 'compact':
27
+ return typeof raw === 'number'
28
+ ? formatCompactNumber(raw, '', precision)
29
+ : String(raw);
30
+ case 'percent':
31
+ return typeof raw === 'number'
32
+ ? intlNumber(raw, precision, { style: 'percent' })
33
+ : String(raw);
34
+ case 'currency':
35
+ return typeof raw === 'number'
36
+ ? intlNumber(raw, precision ?? 2, {
37
+ style: 'currency',
38
+ currency: currency ?? 'USD',
39
+ })
40
+ : String(raw);
41
+ case 'bytes':
42
+ return typeof raw === 'number'
43
+ ? formatBytes(raw, precision)
44
+ : String(raw);
45
+ case 'duration':
46
+ return typeof raw === 'number' ? formatDuration(raw) : String(raw);
47
+ case 'date':
48
+ return formatDate(raw);
49
+ case 'relativeTime':
50
+ return formatRelativeTime(raw, options.now ?? new Date());
51
+ case 'number':
52
+ default:
53
+ return typeof raw === 'number'
54
+ ? intlNumber(raw, precision, {})
55
+ : String(raw);
56
+ }
57
+ };
58
+ const intlNumber = (value, precision, options) => new Intl.NumberFormat('en-US', {
59
+ ...options,
60
+ ...(precision === undefined
61
+ ? { maximumFractionDigits: 2 }
62
+ : {
63
+ minimumFractionDigits: precision,
64
+ maximumFractionDigits: precision,
65
+ }),
66
+ }).format(value);
67
+ const BYTE_UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
68
+ const formatBytes = (bytes, precision) => {
69
+ let scaled = Math.abs(bytes);
70
+ let unit = 0;
71
+ while (scaled >= 1024 && unit < BYTE_UNITS.length - 1) {
72
+ scaled /= 1024;
73
+ unit += 1;
74
+ }
75
+ const sign = bytes < 0 ? '-' : '';
76
+ const digits = unit === 0 ? 0 : (precision ?? 1);
77
+ return `${sign}${trimFixed(scaled, digits)} ${BYTE_UNITS[unit]}`;
78
+ };
79
+ const formatDuration = (seconds) => {
80
+ const abs = Math.abs(seconds);
81
+ const sign = seconds < 0 ? '-' : '';
82
+ if (abs < 1) {
83
+ return `${sign}${trimFixed(abs * 1000, 1)}ms`;
84
+ }
85
+ if (abs < 60) {
86
+ return `${sign}${trimFixed(abs, 1)}s`;
87
+ }
88
+ const pairs = [
89
+ [86400, 'd', 3600, 'h'],
90
+ [3600, 'h', 60, 'm'],
91
+ [60, 'm', 1, 's'],
92
+ ];
93
+ for (const [major, majorUnit, minor, minorUnit] of pairs) {
94
+ if (abs >= major) {
95
+ const majorCount = Math.floor(abs / major);
96
+ const minorCount = Math.floor((abs % major) / minor);
97
+ return minorCount > 0
98
+ ? `${sign}${majorCount}${majorUnit} ${minorCount}${minorUnit}`
99
+ : `${sign}${majorCount}${majorUnit}`;
100
+ }
101
+ }
102
+ return `${sign}${trimFixed(abs, 1)}s`;
103
+ };
104
+ const formatDate = (raw) => {
105
+ const date = new Date(raw);
106
+ if (Number.isNaN(date.getTime())) {
107
+ return String(raw);
108
+ }
109
+ return new Intl.DateTimeFormat('en-US', {
110
+ dateStyle: 'medium',
111
+ timeStyle: 'short',
112
+ timeZone: 'UTC',
113
+ }).format(date);
114
+ };
115
+ const formatRelativeTime = (raw, now) => {
116
+ const date = new Date(raw);
117
+ if (Number.isNaN(date.getTime())) {
118
+ return String(raw);
119
+ }
120
+ const deltaSeconds = Math.round((date.getTime() - now.getTime()) / 1000);
121
+ const abs = Math.abs(deltaSeconds);
122
+ if (abs < 45) {
123
+ return 'just now';
124
+ }
125
+ const unit = abs < 60 * 45
126
+ ? [Math.max(1, Math.round(abs / 60)), 'm']
127
+ : abs < 3600 * 22
128
+ ? [Math.max(1, Math.round(abs / 3600)), 'h']
129
+ : [Math.max(1, Math.round(abs / 86400)), 'd'];
130
+ const phrase = `${unit[0]}${unit[1]}`;
131
+ return deltaSeconds < 0 ? `${phrase} ago` : `in ${phrase}`;
132
+ };
133
+ const trimFixed = (value, digits) => {
134
+ const fixed = value.toFixed(digits);
135
+ return fixed.includes('.') ? fixed.replace(/\.?0+$/, '') : fixed;
136
+ };
137
+ //# sourceMappingURL=format_display_value.js.map